Merge pull request #201 from kyzentun/FixSetFail

Fix global fail setting overriding song options.
This commit is contained in:
kyzentun
2014-06-26 22:25:21 -06:00
8 changed files with 90 additions and 48 deletions
+1
View File
@@ -824,6 +824,7 @@
<Function name='SetCurrentSong'/>
<Function name='SetCurrentSteps'/>
<Function name='SetCurrentTrail'/>
<Function name='SetFailTypeExplicitlySet'/>
<Function name='SetJukeboxUsesModifiers'/>
<Function name='SetMultiplayer'/>
<Function name='SetNumMultiplayerNoteFields'/>
+3
View File
@@ -2470,6 +2470,9 @@ save yourself some time, copy this for undocumented things:
<Function name='SetCurrentTrail' return='void' arguments='Trail trail'>
Sets the current Trail to <code>trail</code>.
</Function>
<Function name='SetFailTypeExplicitlySet' return='void' arguments=''>
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.
</Function>
<Function name='SetJukeboxUsesModifiers' return='void' arguments='bool bUseMods'>
Sets if the Jukebox should use modifiers.
</Function>
+13 -10
View File
@@ -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()
@@ -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
+3 -2
View File
@@ -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"
+9 -2
View File
@@ -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<PlayerNumber>(L, 1), SArg(2));
@@ -2703,6 +2709,7 @@ public:
ADD_METHOD( SaveProfiles );
ADD_METHOD( HaveProfileToLoad );
ADD_METHOD( HaveProfileToSave );
ADD_METHOD( SetFailTypeExplicitlySet );
ADD_METHOD( StoreRankingName );
}
};
+1 -1
View File
@@ -176,7 +176,7 @@ public:
BroadcastOnChange<RString> m_sPreferredSongGroup; // GROUP_ALL denotes no preferred group
BroadcastOnChange<RString> 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<StepsType> m_PreferredStepsType;
BroadcastOnChange1D<Difficulty,NUM_PLAYERS> m_PreferredDifficulty;
BroadcastOnChange1D<CourseDifficulty,NUM_PLAYERS> m_PreferredCourseDifficulty;// used in nonstop
+3 -1
View File
@@ -30,7 +30,9 @@ void ScreenSongOptions::ExportOptions( int iRow, const vector<PlayerNumber> &vpn
ScreenOptionsMaster::ExportOptions( iRow, vpns );
if( ft != pPS->m_PlayerOptions.GetPreferred().m_FailType )
GAMESTATE->m_bChangedFailTypeOnScreenSongOptions = true;
{
GAMESTATE->m_bFailTypeWasExplicitlySet = true;
}
}
/*