Skip to content

Commit

Permalink
fix ScreenSelectProfile for USB memorycards
Browse files Browse the repository at this point in the history
SL 4.8.5 added support for not being forced to use a local profile on ScreenSelectProfile as this feature has been requested since at least v4.8.0.

That (as far I could tell) required me to detangle _fallback's ActorScroller from its input handling from the way it set/unset local profiles and I opted to just swap the entire thing out for a Lua-based sick_wheel scroller.  Three days in, I got a no-profile choice working and failed to remember to check USB profiles in my bleary-eyed joy.

I had, of course, broken support for USB memorycards on ScreenSelectProfile.  This commit fixes it to work as well as it did before.  I could probably try to add more logic to handle (memorycard is present but there was card read error) but this is good enough for now.
  • Loading branch information
quietly-turning committed Sep 26, 2019
1 parent ddb2f79 commit 537b0ca
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
11 changes: 4 additions & 7 deletions BGAnimations/ScreenSelectProfile underlay/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,12 @@ Handle.Start = function(event)
-- we only bother checking scrollers to see if both players are
-- trying to choose the same profile if there are scrollers because
-- there are local profiles. If there are no local profiles, there are
-- no scrollers to compared.
-- no scrollers to compare.
if PROFILEMAN:GetNumLocalProfiles() > 0
-- and if both players have joined
and #GAMESTATE:GetHumanPlayers() > 1 then
-- and if both players have joined and neither is using a memorycard
and #GAMESTATE:GetHumanPlayers() > 1 and not GAMESTATE:IsAnyHumanPlayerUsingMemoryCard() then
-- and both players are trying to choose the same profile
if scrollers[PLAYER_1]:get_info_at_focus_pos().index == scrollers[PLAYER_2]:get_info_at_focus_pos().index
and not (scrollers[PLAYER_1]:get_info_at_focus_pos().index == 0)
and not (MEMCARDMAN:GetCardState(PLAYER_1)~='MemoryCardState_none' and MEMCARDMAN:GetCardState(PLAYER_2)~='MemoryCardState_none')
then
if scrollers[PLAYER_1]:get_info_at_focus_pos().index == scrollers[PLAYER_2]:get_info_at_focus_pos().index then
-- broadcast an InvalidChoice message to play the "Common invalid" sound
-- and "shake" the playerframe for the player that just pressed start
MESSAGEMAN:Broadcast("InvalidChoice", {PlayerNumber=event.PlayerNumber})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- the metatable for an item in ScreenSelectProfile's sick_wheel scroller
-- this is just a given profile's DisplayName
-- for the scrollers in ScreenSelectProfile, this is just each profile's DisplayName
return {
__index = {
create_actors = function(self, name)
Expand Down
24 changes: 17 additions & 7 deletions BGAnimations/ScreenSelectProfile underlay/default.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,26 @@ local t = Def.ActorFrame {
-- set index to 0 if so to indicate that "[Guest]" was chosen (because it was the only choice)
local index = type(info)=="table" and info.index or 0

-- if the index greater than 0, it indicates the player wants to use a local profile
if index > 0 then
-- so use the index to associate this ProfileIndex with this player
-- this screen's SetProfileIndex() method expects local profiles to use index values that are > 0
-- it also uses the following hardcoded values:
-- 0: use the USB memory card associated with this player
-- -1: join the player and play the theme's start sound effect
-- -2: unjoin the player, unlock their memorycard, and unmount their memorycard

-- check for and handle USB memorycards first
if MEMCARDMAN:GetCardState(player) ~= 'MemoryCardState_none' then
SCREENMAN:GetTopScreen():SetProfileIndex(player, 0)

-- local profile
elseif index > 0 then
SCREENMAN:GetTopScreen():SetProfileIndex(player, index)

-- if the index is 0 (or, uh, negative, but that shouldn't happen given the way I set this up)
-- it indicates the player wanted to not use a profile; they selected the first "[Guest]" option.
else
-- 0 here is my own stupid hardcoded number, defined over in PlayerFrame.lua for use with the "[Guest]" choice
-- In this case, 0 is the index of the choice in the scroller. It should not be confused the 0 passed to
-- SetProfileIndex() to use a USB memorycard.
elseif index == 0 then
-- Passing a -2 to SetProfileIndex() will unjoin the player.
-- Unjoining like this is (studid, but) necessary to get us past this screen onto the next
-- Unjoining like this is (stupid, but) necessary to get us past this screen onto the next
-- because ScreenSelectProfile needs all human players to have profiles assigned to them.
SCREENMAN:GetTopScreen():SetProfileIndex(player, -2)

Expand Down

0 comments on commit 537b0ca

Please sign in to comment.