From 4a246546a910d865132ba078578db46db0a6e132 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 14 Nov 2004 05:24:37 +0000 Subject: [PATCH] Save profile modifiers per gametype. Only reset saved modifiers when loading profile modifiers, so we don't wipe out modifiers that aren't saved. UsingProfileDefaultModifiers is gone; if an entry exists in the DefaultModifiers list at all, UsingProfileDefaultModifiers is true. --- stepmania/src/GameState.cpp | 14 ++++++---- stepmania/src/Profile.cpp | 51 ++++++++++++++++++++++++++++++++----- stepmania/src/Profile.h | 6 +++-- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 73c9d7396f..aae21d1326 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -246,10 +246,15 @@ void GameState::PlayersFinalized() Profile* pProfile = PROFILEMAN->GetProfile(pn); - if( pProfile->m_bUsingProfileDefaultModifiers ) + CString sModifiers; + if( pProfile->GetDefaultModifiers( this->m_pCurGame, sModifiers ) ) { - GAMESTATE->m_PlayerOptions[pn].Init(); - GAMESTATE->ApplyModifiers( pn, pProfile->m_sDefaultModifiers ); + /* We don't save negative preferences (eg. "no reverse"). If the theme + * sets a default of "reverse", and the player turns it off, we should + * set it off. However, don't reset modifiers that aren't saved by the + * profile, so we don't ignore unsaved modifiers when a profile is in use. */ + GAMESTATE->m_PlayerOptions[pn].ResetSavedPrefs(); + GAMESTATE->ApplyModifiers( pn, sModifiers ); } // Only set the sort order if it wasn't already set by a ModeChoice (or by an earlier profile) if( m_SortOrder == SORT_INVALID && pProfile->m_SortOrder != SORT_INVALID ) @@ -386,8 +391,7 @@ void GameState::SaveCurrentSettingsToProfile( PlayerNumber pn ) Profile* pProfile = PROFILEMAN->GetProfile(pn); - pProfile->m_bUsingProfileDefaultModifiers = true; - pProfile->m_sDefaultModifiers = m_PlayerOptions[pn].GetSavedPrefsString(); + pProfile->SetDefaultModifiers( this->m_pCurGame, m_PlayerOptions[pn].GetSavedPrefsString() ); if( IsSongSort(m_SortOrder) ) pProfile->m_SortOrder = m_SortOrder; if( m_PreferredDifficulty[pn] != DIFFICULTY_INVALID ) diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index c1981b527d..b85e2d774c 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -22,6 +22,7 @@ #include "Foreach.h" #include "CatalogXml.h" #include "Bookkeeper.h" +#include "Game.h" // // Old file versions for backward compatibility @@ -72,8 +73,6 @@ void Profile::InitGeneralData() } - m_bUsingProfileDefaultModifiers = false; - m_sDefaultModifiers = ""; m_SortOrder = SORT_INVALID; m_LastDifficulty = DIFFICULTY_INVALID; m_LastCourseDifficulty = DIFFICULTY_INVALID; @@ -393,6 +392,33 @@ int Profile::GetSongNumTimesPlayed( const SongID& songID ) const return iTotalNumTimesPlayed; } +/* + * Get the profile default modifiers. Return true if set, in which case sModifiersOut + * will be set. Return false if no modifier string is set, in which case the theme + * defaults should be used. Note that the null string means "no modifiers are active", + * which is distinct from no modifier string being set at all. + * + * In practice, we get the default modifiers from the theme the first time a game + * is played, and from the profile every time thereafter. + */ +bool Profile::GetDefaultModifiers( const Game* pGameType, CString &sModifiersOut ) const +{ + map::const_iterator it; + it = m_sDefaultModifiers.find( pGameType->m_szName ); + if( it == m_sDefaultModifiers.end() ) + return false; + sModifiersOut = it->second; + return true; +} + +void Profile::SetDefaultModifiers( const Game* pGameType, const CString &sModifiers ) +{ + if( sModifiers == "" ) + m_sDefaultModifiers.erase( pGameType->m_szName ); + else + m_sDefaultModifiers[pGameType->m_szName] = sModifiers; +} + // // Steps high scores // @@ -733,8 +759,6 @@ XNode* Profile::SaveGeneralDataCreateNode() const pGeneralDataNode->AppendChild( "IsMachine", IsMachine() ); pGeneralDataNode->AppendChild( "Guid", m_sGuid ); - pGeneralDataNode->AppendChild( "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers ); - pGeneralDataNode->AppendChild( "DefaultModifiers", m_sDefaultModifiers ); pGeneralDataNode->AppendChild( "SortOrder", SortOrderToString(m_SortOrder) ); pGeneralDataNode->AppendChild( "LastDifficulty", DifficultyToString(m_LastDifficulty) ); pGeneralDataNode->AppendChild( "LastCourseDifficulty", CourseDifficultyToString(m_LastCourseDifficulty) ); @@ -761,6 +785,12 @@ XNode* Profile::SaveGeneralDataCreateNode() const // accidentally used where they're not intended. There's a lot of // copying and pasting in this code. + { + XNode* pDefaultModifiers = pGeneralDataNode->AppendChild("DefaultModifiers"); + for( map::const_iterator it = m_sDefaultModifiers.begin(); it != m_sDefaultModifiers.end(); ++it ) + pDefaultModifiers->AppendChild( it->first, it->second ); + } + { XNode* pUnlockedSongs = pGeneralDataNode->AppendChild("UnlockedSongs"); for( set::const_iterator it = m_UnlockedSongs.begin(); it != m_UnlockedSongs.end(); ++it ) @@ -878,8 +908,6 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode ) const XNode* pTemp; pNode->GetChildValue( "Guid", m_sGuid ); - pNode->GetChildValue( "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers ); - pNode->GetChildValue( "DefaultModifiers", m_sDefaultModifiers ); pNode->GetChildValue( "SortOrder", s ); m_SortOrder = StringToSortOrder( s ); pNode->GetChildValue( "LastDifficulty", s ); m_LastDifficulty = StringToDifficulty( s ); pNode->GetChildValue( "LastCourseDifficulty", s ); m_LastCourseDifficulty = StringToCourseDifficulty( s ); @@ -902,6 +930,17 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode ) pNode->GetChildValue( "TotalMines", m_iTotalMines ); pNode->GetChildValue( "TotalHands", m_iTotalHands ); + { + const XNode* pDefaultModifiers = pNode->GetChild("DefaultModifiers"); + if( pDefaultModifiers ) + { + FOREACH_Node( pDefaultModifiers, game_type ) + { + m_sDefaultModifiers[game_type->name] = game_type->value; + } + } + } + { const XNode* pUnlockedSongs = pNode->GetChild("UnlockedSongs"); if( pUnlockedSongs ) diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 726d63022d..8075953726 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -46,6 +46,7 @@ class Style; class Song; class Steps; class Course; +class Game; class Profile { @@ -72,6 +73,8 @@ public: static CString GetProfileDisplayNameFromDir( CString sDir ); int GetSongNumTimesPlayed( const Song* pSong ) const; int GetSongNumTimesPlayed( const SongID& songID ) const; + bool GetDefaultModifiers( const Game* pGameType, CString &sModifiersOut ) const; + void SetDefaultModifiers( const Game* pGameType, const CString &sModifiers ); void AddStepTotals( int iNumTapsAndHolds, int iNumJumps, int iNumHolds, int iNumMines, int iNumHands ); @@ -88,8 +91,7 @@ public: // General data // CString m_sGuid; - bool m_bUsingProfileDefaultModifiers; - CString m_sDefaultModifiers; + map m_sDefaultModifiers; SortOrder m_SortOrder; Difficulty m_LastDifficulty; CourseDifficulty m_LastCourseDifficulty;