From 3a788651e5349c38d63fed2f8014be6d7467792c Mon Sep 17 00:00:00 2001 From: Kyzentun Date: Fri, 20 Jun 2014 13:54:56 -0600 Subject: [PATCH] Fixed bug that caused global fail setting to override setting the fail type from song options. Added GAMESTATE:SetFailTypeExplicitlySet so that a theme with a custom song options screen can protect its fail setting from being overridden the same way the engine ScreenSongOptions does. --- Docs/Luadoc/Lua.xml | 1 + Docs/Luadoc/LuaDocumentation.xml | 3 + Themes/_fallback/Scripts/02 StageMods.lua | 23 ++--- .../Scripts/03 ThemeAndGamePrefs.lua | 89 ++++++++++++------- Themes/_fallback/metrics.ini | 5 +- src/GameState.cpp | 11 ++- src/GameState.h | 2 +- src/ScreenSongOptions.cpp | 4 +- 8 files changed, 90 insertions(+), 48 deletions(-) diff --git a/Docs/Luadoc/Lua.xml b/Docs/Luadoc/Lua.xml index 28ed64add2..62ef23ff0d 100644 --- a/Docs/Luadoc/Lua.xml +++ b/Docs/Luadoc/Lua.xml @@ -823,6 +823,7 @@ + diff --git a/Docs/Luadoc/LuaDocumentation.xml b/Docs/Luadoc/LuaDocumentation.xml index 34ba687243..cd63c8abbb 100644 --- a/Docs/Luadoc/LuaDocumentation.xml +++ b/Docs/Luadoc/LuaDocumentation.xml @@ -2466,6 +2466,9 @@ save yourself some time, copy this for undocumented things: Sets the current Trail to trail. + + Tells the engine that the theme explicitly set the fail type for the players so that it won't override it with the easier settings for beginner or easy. + Sets if the Jukebox should use modifiers. diff --git a/Themes/_fallback/Scripts/02 StageMods.lua b/Themes/_fallback/Scripts/02 StageMods.lua index 2dcedadaac..0dc51d8cba 100644 --- a/Themes/_fallback/Scripts/02 StageMods.lua +++ b/Themes/_fallback/Scripts/02 StageMods.lua @@ -10,23 +10,26 @@ function AreStageSongModsForced() return GAMESTATE:IsAnExtraStage() or bOni or bBattle or bRave end +local default_fail_applied= {} + +function ResetDefaultFail() + default_fail_applied= {} +end + function SetFail() local sFail = "" - if GetGamePref("DefaultFail") then - sFail = string.format("Fail%s", GetGamePref("DefaultFail")) + sFail = string.format("FailType_%s", GetGamePref("DefaultFail")) else - sFail = "FailOff" + sFail = "FailType_Off" end - - sFail = tostring(sFail) - for pn in ivalues(GAMESTATE:GetHumanPlayers()) do - MESSAGEMAN:Broadcast( "PlayerOptionsChanged", {PlayerNumber = pn} ) + if not default_fail_applied[pn] then + GAMESTATE:GetPlayerState(pn):GetPlayerOptions("ModsLevel_Preferred"):FailSetting(sFail) + default_fail_applied[pn]= true + MESSAGEMAN:Broadcast( "PlayerOptionsChanged", {PlayerNumber = pn} ) + end end - - GAMESTATE:ApplyGameCommand( "mod," .. sFail) - MESSAGEMAN:Broadcast( "SongOptionsChanged" ) end function ScreenSelectMusic:setupmusicstagemods() diff --git a/Themes/_fallback/Scripts/03 ThemeAndGamePrefs.lua b/Themes/_fallback/Scripts/03 ThemeAndGamePrefs.lua index d2bf26e575..fb26f0912a 100644 --- a/Themes/_fallback/Scripts/03 ThemeAndGamePrefs.lua +++ b/Themes/_fallback/Scripts/03 ThemeAndGamePrefs.lua @@ -151,57 +151,82 @@ end; --[[ end themeoption rows ]] --[[ game option rows ]] +local fail_choices= { "Immediate","ImmediateContinue", "EndOfSong", "Off" } function GamePrefDefaultFail() - local t = { + return { Name = "GamePrefDefaultFail"; LayoutType = "ShowAllInRow"; SelectType = "SelectOne"; OneChoiceForAllPlayers = true; ExportOnChange = false; - Choices = { "Immediate","ImmediateContinue", "AtEnd", "Off" }; + Choices = fail_choices; LoadSelections = function(self, list, pn) if ReadGamePrefFromFile("DefaultFail") ~= nil then - if GetGamePref("DefaultFail") then - if GetGamePref("DefaultFail") == "Immediate" then - list[1] = true; - elseif GetGamePref("DefaultFail") == "ImmediateContinue" then - list[2] = true; - elseif GetGamePref("DefaultFail") == "AtEnd" then - list[3] = true; - elseif GetGamePref("DefaultFail") == "Off" then - list[4] = true; + local default= GetGamePref("DefaultFail") + if default then + if default == "Immediate" then + list[1] = true + elseif default == "ImmediateContinue" then + list[2] = true + elseif default == "EndOfSong" or default == "AtEnd" then + list[3] = true + elseif default == "Off" then + list[4] = true else - list[1] = true; + list[1] = true end - -- list[table.find( list, GetGamePref("DefaultFail") )] = true; else - list[1] = true; - end; + list[1] = true + end else - WriteGamePrefToFile("DefaultFail","Immediate"); - list[1] = true; - end; + WriteGamePrefToFile("DefaultFail","Immediate") + list[1] = true + end end; SaveSelections = function(self, list, pn) - -- This is so stupid. - local tChoices = { "Immediate","ImmediateContinue", "AtEnd", "Off" }; - local val; + local val if list[1] then - val = tChoices[1]; + val = fail_choices[1] elseif list[2] then - val = tChoices[2]; + val = fail_choices[2] elseif list[3] then - val = tChoices[3]; + val = fail_choices[3] elseif list[4] then - val = tChoices[4]; + val = fail_choices[4] else - val = tChoices[1]; + val = fail_choices[1] end - WriteGamePrefToFile("DefaultFail",val); - MESSAGEMAN:Broadcast("PreferenceSet", { Message == "Set Preference" } ); - THEME:ReloadMetrics(); + WriteGamePrefToFile("DefaultFail",val) + MESSAGEMAN:Broadcast("PreferenceSet", { Message == "Set Preference" } ) + THEME:ReloadMetrics() end; - }; - setmetatable( t, t ); - return t; + } +end + +function SongPrefFail() + -- Apply the default fail type to any players that haven't had it applied. + SetFail() + return { + Name= "Fail", + LayoutType= "ShowAllInRow", + SelectType= "SelectOne", + OneChoiceForAllPlayers= false, + ExportOnChange= false, + Choices= fail_choices, + LoadSelections= function(self, list, pn) + local fail= GAMESTATE:GetPlayerState(pn):GetPlayerOptions("ModsLevel_Preferred"):FailSetting():sub(10) + for i, c in ipairs(self.Choices) do + if c == fail then + list[i]= true + end + end + end, + SaveSelections= function(self, list, pn) + for i, c in ipairs(self.Choices) do + if list[i] then + GAMESTATE:GetPlayerState(pn):GetPlayerOptions("ModsLevel_Preferred"):FailSetting("FailType_" .. c) + end + end + end + } end diff --git a/Themes/_fallback/metrics.ini b/Themes/_fallback/metrics.ini index dad21231b0..ffd8d8d3e6 100644 --- a/Themes/_fallback/metrics.ini +++ b/Themes/_fallback/metrics.ini @@ -1809,6 +1809,7 @@ Fallback="ScreenSelectMaster" PrevScreen="ScreenInit" NextScreen="ScreenInit" # +ScreenBeginCommand=%ResetDefaultFail StopMusicOnBack=true # CoinModeChangeScreen=Branch.TitleMenu() @@ -2222,7 +2223,7 @@ TimerMetricsGroup="MenuTimerNoSound" WaitForChildrenBeforeTweeningOut=true TimerSeconds=1 # -ScreenBeginCommand=%SetFail +ScreenBeginCommand= [ScreenOptions] Fallback="ScreenWithMenuElements" @@ -3130,7 +3131,7 @@ Line8="list,AutoAdjust" Line9="list,Background" Line10="list,SaveScores" Line11="list,SaveReplays" -Line4="list,Fail" +Line4="lua,SongPrefFail()" [ScreenSplash] Class="ScreenSplash" diff --git a/src/GameState.cpp b/src/GameState.cpp index 715922d2b4..b1c5eb90c2 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -292,7 +292,7 @@ void GameState::Reset() *m_Environment = LuaTable(); m_sPreferredSongGroup.Set( GROUP_ALL ); m_sPreferredCourseGroup.Set( GROUP_ALL ); - m_bChangedFailTypeOnScreenSongOptions = false; + m_bFailTypeWasExplicitlySet = false; m_SortOrder.Set( SortOrder_Invalid ); m_PreferredSortOrder = GetDefaultSort(); m_PlayMode.Set( PlayMode_Invalid ); @@ -1540,7 +1540,7 @@ FailType GameState::GetPlayerFailType( const PlayerState *pPlayerState ) const FailType ft = pPlayerState->m_PlayerOptions.GetCurrent().m_FailType; // If the player changed the fail mode explicitly, leave it alone. - if( m_bChangedFailTypeOnScreenSongOptions ) + if( m_bFailTypeWasExplicitlySet ) return ft; if( IsCourseMode() ) @@ -2579,6 +2579,12 @@ public: return 0; } + static int SetFailTypeExplicitlySet(T* p, lua_State* L) + { + p->m_bFailTypeWasExplicitlySet= true; + return 0; + } + static int StoreRankingName( T* p, lua_State *L ) { p->StoreRankingName(Enum::Check(L, 1), SArg(2)); @@ -2703,6 +2709,7 @@ public: ADD_METHOD( SaveProfiles ); ADD_METHOD( HaveProfileToLoad ); ADD_METHOD( HaveProfileToSave ); + ADD_METHOD( SetFailTypeExplicitlySet ); ADD_METHOD( StoreRankingName ); } }; diff --git a/src/GameState.h b/src/GameState.h index 2b971b6f32..58eee84f07 100644 --- a/src/GameState.h +++ b/src/GameState.h @@ -176,7 +176,7 @@ public: BroadcastOnChange m_sPreferredSongGroup; // GROUP_ALL denotes no preferred group BroadcastOnChange m_sPreferredCourseGroup; // GROUP_ALL denotes no preferred group - bool m_bChangedFailTypeOnScreenSongOptions; // true if FailType was changed in the song options screen + bool m_bFailTypeWasExplicitlySet; // true if FailType was changed in the song options screen BroadcastOnChange m_PreferredStepsType; BroadcastOnChange1D m_PreferredDifficulty; BroadcastOnChange1D m_PreferredCourseDifficulty;// used in nonstop diff --git a/src/ScreenSongOptions.cpp b/src/ScreenSongOptions.cpp index c9ca58732e..1c105c9b13 100644 --- a/src/ScreenSongOptions.cpp +++ b/src/ScreenSongOptions.cpp @@ -30,7 +30,9 @@ void ScreenSongOptions::ExportOptions( int iRow, const vector &vpn ScreenOptionsMaster::ExportOptions( iRow, vpns ); if( ft != pPS->m_PlayerOptions.GetPreferred().m_FailType ) - GAMESTATE->m_bChangedFailTypeOnScreenSongOptions = true; + { + GAMESTATE->m_bFailTypeWasExplicitlySet = true; + } } /*