move game prefs into PrefsManager

This commit is contained in:
Chris Danford
2005-10-27 04:54:45 +00:00
parent cdb7215971
commit 5d7885c764
15 changed files with 95 additions and 86 deletions
+1 -1
View File
@@ -253,7 +253,7 @@ bool CodeDetector::DetectAndAdjustMusicOptions( GameController controller )
case CODE_MINES: TOGGLE( po.m_bTransforms[PlayerOptions::TRANSFORM_NOMINES], true, false ); break; case CODE_MINES: TOGGLE( po.m_bTransforms[PlayerOptions::TRANSFORM_NOMINES], true, false ); break;
case CODE_DARK: FLOAT_TOGGLE( po.m_fDark ); break; case CODE_DARK: FLOAT_TOGGLE( po.m_fDark ); break;
case CODE_CANCEL_ALL: po.Init(); case CODE_CANCEL_ALL: po.Init();
po.FromString( PREFSMAN->m_sDefaultModifiers ); break; po.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers ); break;
case CODE_HIDDEN: TOGGLE_HIDDEN; break; case CODE_HIDDEN: TOGGLE_HIDDEN; break;
case CODE_RANDOMVANISH: TOGGLE_RANDOMVANISH; break; case CODE_RANDOMVANISH: TOGGLE_RANDOMVANISH; break;
+2 -2
View File
@@ -1103,8 +1103,8 @@ void GameCommand::ApplySelf( const vector<PlayerNumber> &vpns ) const
if( m_bApplyDefaultOptions ) if( m_bApplyDefaultOptions )
{ {
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.FromString( PREFSMAN->m_sDefaultModifiers ); GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
GAMESTATE->m_SongOptions.FromString( PREFSMAN->m_sDefaultModifiers ); GAMESTATE->m_SongOptions.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
} }
// HACK: Set life type to BATTERY just once here so it happens once and // HACK: Set life type to BATTERY just once here so it happens once and
// we don't override the user's changes if they back out. // we don't override the user's changes if they back out.
+4 -4
View File
@@ -244,7 +244,7 @@ void GameState::Reset()
// could be done in the title menu GameCommand, but then it wouldn't // could be done in the title menu GameCommand, but then it wouldn't
// affect demo, and other non-gameplay things ...) -glenn // affect demo, and other non-gameplay things ...) -glenn
ApplyModifiers( p, DEFAULT_MODIFIERS ); ApplyModifiers( p, DEFAULT_MODIFIERS );
ApplyModifiers( p, PREFSMAN->m_sDefaultModifiers ); ApplyModifiers( p, PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
} }
FOREACH_PlayerNumber(p) FOREACH_PlayerNumber(p)
@@ -1036,10 +1036,10 @@ void GameState::ResetCurrentOptions()
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
{ {
m_pPlayerState[p]->m_PlayerOptions.Init(); m_pPlayerState[p]->m_PlayerOptions.Init();
m_pPlayerState[p]->m_PlayerOptions.FromString( PREFSMAN->m_sDefaultModifiers ); m_pPlayerState[p]->m_PlayerOptions.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
} }
m_SongOptions.Init(); m_SongOptions.Init();
m_SongOptions.FromString( PREFSMAN->m_sDefaultModifiers ); m_SongOptions.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
} }
bool GameState::IsDisqualified( PlayerNumber pn ) bool GameState::IsDisqualified( PlayerNumber pn )
@@ -1887,7 +1887,7 @@ bool GameState::IsSyncDataChanged()
void GameState::SaveSyncChanges() void GameState::SaveSyncChanges()
{ {
GAMESTATE->m_pCurSong->Save(); GAMESTATE->m_pCurSong->Save();
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SavePrefsToDisk();
ResetOriginalSyncData(); ResetOriginalSyncData();
} }
+39 -16
View File
@@ -12,9 +12,9 @@
#include "Preference.h" #include "Preference.h"
#include "RageLog.h" #include "RageLog.h"
#define DEFAULTS_INI_PATH "Data/Defaults.ini" // these can be overridden const CString DEFAULTS_INI_PATH = "Data/Defaults.ini"; // these can be overridden
#define STEPMANIA_INI_PATH "Data/" PRODUCT_NAME ".ini" // overlay on Defaults.ini, contains the user's choices const CString STEPMANIA_INI_PATH = "Data/" PRODUCT_NAME ".ini"; // overlay on Defaults.ini, contains the user's choices
#define STATIC_INI_PATH "Data/Static.ini" // overlay on the 2 above, can't be overridden const CString STATIC_INI_PATH = "Data/Static.ini"; // overlay on the 2 above, can't be overridden
PrefsManager* PREFSMAN = NULL; // global and accessable from anywhere in our program PrefsManager* PREFSMAN = NULL; // global and accessable from anywhere in our program
@@ -241,7 +241,8 @@ void MemoryCardUsbLevelInit( size_t /*PlayerNumber*/ i, CString &sNameOut, int &
PrefsManager::PrefsManager() : PrefsManager::PrefsManager() :
m_bWindowed ( "Windowed", TRUE_IF_DEBUG), m_sCurrentGame ( "CurrentGame", "" ),
m_bWindowed ( "Windowed", TRUE_IF_DEBUG ),
m_iDisplayWidth ( "DisplayWidth", 640 ), m_iDisplayWidth ( "DisplayWidth", 640 ),
m_iDisplayHeight ( "DisplayHeight", 480 ), m_iDisplayHeight ( "DisplayHeight", 480 ),
m_iDisplayColorDepth ( "DisplayColorDepth", 16 ), m_iDisplayColorDepth ( "DisplayColorDepth", 16 ),
@@ -421,10 +422,7 @@ PrefsManager::PrefsManager() :
m_bShowLogOutput ( "ShowLogOutput", false ), m_bShowLogOutput ( "ShowLogOutput", false ),
m_bLogSkips ( "LogSkips", false ), m_bLogSkips ( "LogSkips", false ),
m_bLogCheckpoints ( "LogCheckpoints", false ), m_bLogCheckpoints ( "LogCheckpoints", false ),
m_bShowLoadingWindow ( "ShowLoadingWindow", true ), m_bShowLoadingWindow ( "ShowLoadingWindow", true )
/* Game-specific prefs: */
m_sDefaultModifiers ( "DefaultModifiers", "" )
#if defined(XBOX) #if defined(XBOX)
, ,
@@ -442,7 +440,7 @@ PrefsManager::PrefsManager() :
{ {
Init(); Init();
ReadGlobalPrefsFromDisk(); ReadPrefsFromDisk();
} }
#undef TRUE_IF_DEBUG #undef TRUE_IF_DEBUG
@@ -456,7 +454,7 @@ PrefsManager::~PrefsManager()
{ {
} }
void PrefsManager::ReadGlobalPrefsFromDisk() void PrefsManager::ReadPrefsFromDisk()
{ {
ReadPrefsFromFile( DEFAULTS_INI_PATH ); ReadPrefsFromFile( DEFAULTS_INI_PATH );
ReadPrefsFromFile( STEPMANIA_INI_PATH ); ReadPrefsFromFile( STEPMANIA_INI_PATH );
@@ -470,7 +468,7 @@ void PrefsManager::ResetToFactoryDefaults()
ReadPrefsFromFile( DEFAULTS_INI_PATH ); ReadPrefsFromFile( DEFAULTS_INI_PATH );
ReadPrefsFromFile( STATIC_INI_PATH ); ReadPrefsFromFile( STATIC_INI_PATH );
SaveGlobalPrefsToDisk(); SavePrefsToDisk();
} }
void PrefsManager::ReadPrefsFromFile( CString sIni ) void PrefsManager::ReadPrefsFromFile( CString sIni )
@@ -479,10 +477,12 @@ void PrefsManager::ReadPrefsFromFile( CString sIni )
if( !ini.ReadFile(sIni) ) if( !ini.ReadFile(sIni) )
return; return;
ReadGlobalPrefsFromIni( ini ); ReadPrefsFromIni( ini );
} }
void PrefsManager::ReadGlobalPrefsFromIni( const IniFile &ini ) static const CString GAME_SECTION_PREFIX = "Game-";
void PrefsManager::ReadPrefsFromIni( const IniFile &ini )
{ {
FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p ) FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p )
(*p)->ReadFrom( ini ); (*p)->ReadFrom( ini );
@@ -492,19 +492,42 @@ void PrefsManager::ReadGlobalPrefsFromIni( const IniFile &ini )
FOREACH_PlayerNumber( pn ) FOREACH_PlayerNumber( pn )
m_sMemoryCardOsMountPoint[pn].Set( FixSlashes(m_sMemoryCardOsMountPoint[pn]) ); m_sMemoryCardOsMountPoint[pn].Set( FixSlashes(m_sMemoryCardOsMountPoint[pn]) );
m_BackgroundMode.Set( (BackgroundMode)clamp((int)m_BackgroundMode.Get(),0,(int)NUM_BackgroundMode-1) ); m_BackgroundMode.Set( (BackgroundMode)clamp((int)m_BackgroundMode.Get(),0,(int)NUM_BackgroundMode-1) );
FOREACH_CONST_Child( &ini, section )
{
if( !BeginsWith(section->m_sName, GAME_SECTION_PREFIX) )
continue;
CString sGame = section->m_sName.Right( section->m_sName.length() - GAME_SECTION_PREFIX.length() );
GamePrefs &gp = m_mapGameNameToGamePrefs[ sGame ];
ini.GetValue( section->m_sName, "Announcer", gp.m_sAnnouncer );
ini.GetValue( section->m_sName, "Theme", gp.m_sTheme );
ini.GetValue( section->m_sName, "DefaultModifiers", gp.m_sDefaultModifiers );
}
} }
void PrefsManager::SaveGlobalPrefsToDisk() const void PrefsManager::SavePrefsToDisk() const
{ {
IniFile ini; IniFile ini;
SaveGlobalPrefsToIni( ini ); SavePrefsToIni( ini );
ini.WriteFile( STEPMANIA_INI_PATH ); ini.WriteFile( STEPMANIA_INI_PATH );
} }
void PrefsManager::SaveGlobalPrefsToIni( IniFile &ini ) const void PrefsManager::SavePrefsToIni( IniFile &ini ) const
{ {
FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p ) FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p )
(*p)->WriteTo( ini ); (*p)->WriteTo( ini );
FOREACHM_CONST( CString, GamePrefs, m_mapGameNameToGamePrefs, iter )
{
CString sSection = "Game-" + CString( iter->first );
ini.SetValue( sSection, "Announcer", iter->second.m_sAnnouncer );
ini.SetValue( sSection, "Theme", iter->second.m_sTheme );
ini.SetValue( sSection, "DefaultModifiers", iter->second.m_sDefaultModifiers );
}
} }
// wrappers // wrappers
+23 -7
View File
@@ -21,6 +21,7 @@ public:
void Init(); void Init();
Preference<CString> m_sCurrentGame;
Preference<bool> m_bWindowed; Preference<bool> m_bWindowed;
Preference<int> m_iDisplayWidth; Preference<int> m_iDisplayWidth;
Preference<int> m_iDisplayHeight; Preference<int> m_iDisplayHeight;
@@ -249,9 +250,6 @@ public:
Preference<bool> m_bLogCheckpoints; Preference<bool> m_bLogCheckpoints;
Preference<bool> m_bShowLoadingWindow; Preference<bool> m_bShowLoadingWindow;
/* Game-specific prefs: */
Preference<CString> m_sDefaultModifiers;
#if defined(XBOX) #if defined(XBOX)
// Virtual memory preferences // Virtual memory preferences
Preference<bool> m_bEnableVirtualMemory; Preference<bool> m_bEnableVirtualMemory;
@@ -275,11 +273,11 @@ public:
CString GetLightsDriver(); CString GetLightsDriver();
void ReadGlobalPrefsFromIni( const IniFile &ini ); void ReadPrefsFromIni( const IniFile &ini );
void SaveGlobalPrefsToIni( IniFile &ini ) const; void SavePrefsToIni( IniFile &ini ) const;
void ReadGlobalPrefsFromDisk(); void ReadPrefsFromDisk();
void SaveGlobalPrefsToDisk() const; void SavePrefsToDisk() const;
void ResetToFactoryDefaults(); void ResetToFactoryDefaults();
@@ -289,6 +287,24 @@ public:
static void Subscribe( IPreference *p ); static void Subscribe( IPreference *p );
static void Unsubscribe( IPreference *p ); static void Unsubscribe( IPreference *p );
//
// Non-self-registering prefs
//
struct GamePrefs
{
CString m_sAnnouncer;
CString m_sTheme;
CString m_sDefaultModifiers;
};
map<CString, GamePrefs> m_mapGameNameToGamePrefs;
GamePrefs &GetCurrentGamePrefs() { return m_mapGameNameToGamePrefs[m_sCurrentGame]; } // inserts if not already present
void SaveGamePrefsToDisk();
void ReadGamePrefsFromDisk();
// Lua // Lua
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
+1 -1
View File
@@ -633,7 +633,7 @@ class DebugLineWritePreferences : public IDebugLine
virtual bool IsEnabled() { return true; } virtual bool IsEnabled() { return true; }
virtual void Do( CString &sMessageOut ) virtual void Do( CString &sMessageOut )
{ {
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SavePrefsToDisk();
IDebugLine::Do( sMessageOut ); IDebugLine::Do( sMessageOut );
} }
}; };
+2 -2
View File
@@ -214,13 +214,13 @@ void ScreenJukebox::Init()
if( GAMESTATE->m_bJukeboxUsesModifiers ) if( GAMESTATE->m_bJukeboxUsesModifiers )
{ {
GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.Init(); GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.Init();
GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.FromString( PREFSMAN->m_sDefaultModifiers ); GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.ChooseRandomModifiers(); GAMESTATE->m_pPlayerState[p]->m_PlayerOptions.ChooseRandomModifiers();
} }
} }
GAMESTATE->m_SongOptions.Init(); GAMESTATE->m_SongOptions.Init();
GAMESTATE->m_SongOptions.FromString( PREFSMAN->m_sDefaultModifiers ); GAMESTATE->m_SongOptions.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
GAMESTATE->m_SongOptions.m_FailType = SongOptions::FAIL_OFF; GAMESTATE->m_SongOptions.m_FailType = SongOptions::FAIL_OFF;
+1 -1
View File
@@ -688,7 +688,7 @@ void ScreenManager::LoadDelayedScreen()
// If we're exiting a system menu, persist settings in case we don't exit normally // If we're exiting a system menu, persist settings in case we don't exit normally
if( bWasOnSystemMenu && !bIsOnSystemMenu ) if( bWasOnSystemMenu && !bIsOnSystemMenu )
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SavePrefsToDisk();
if( bTimeToDeleteScreens ) if( bTimeToDeleteScreens )
DeletePreparedScreens(); DeletePreparedScreens();
+1 -2
View File
@@ -201,8 +201,7 @@ void ScreenOptionsMaster::HandleScreenMessage( const ScreenMessage SM )
{ {
/* Save preferences. */ /* Save preferences. */
LOG->Trace("ROW_CONFIG used; saving ..."); LOG->Trace("ROW_CONFIG used; saving ...");
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SavePrefsToDisk();
SaveGamePrefsToDisk();
} }
if( m_iChangeMask & OPT_RESET_GAME ) if( m_iChangeMask & OPT_RESET_GAME )
+5 -5
View File
@@ -18,8 +18,8 @@
static void GetDefaultModifiers( PlayerOptions &po, SongOptions &so ) static void GetDefaultModifiers( PlayerOptions &po, SongOptions &so )
{ {
po.FromString( PREFSMAN->m_sDefaultModifiers ); po.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
so.FromString( PREFSMAN->m_sDefaultModifiers ); so.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
} }
static void SetDefaultModifiers( const PlayerOptions &po, const SongOptions &so ) static void SetDefaultModifiers( const PlayerOptions &po, const SongOptions &so )
@@ -30,7 +30,7 @@ static void SetDefaultModifiers( const PlayerOptions &po, const SongOptions &so
if( so.GetString() != "" ) if( so.GetString() != "" )
as.push_back( so.GetString() ); as.push_back( so.GetString() );
PREFSMAN->m_sDefaultModifiers.Set( join(", ",as) ); PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers = join( ", ",as );
} }
template<class T> template<class T>
@@ -238,7 +238,7 @@ static void DefaultNoteSkin( int &sel, bool ToSel, const ConfOption *pConfOption
if( ToSel ) if( ToSel )
{ {
PlayerOptions po; PlayerOptions po;
po.FromString( PREFSMAN->m_sDefaultModifiers ); po.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
sel = 0; sel = 0;
for( unsigned i=0; i < choices.size(); i++ ) for( unsigned i=0; i < choices.size(); i++ )
if( !stricmp(choices[i], po.m_sNoteSkin) ) if( !stricmp(choices[i], po.m_sNoteSkin) )
@@ -397,7 +397,7 @@ static void DefaultFailType( int &sel, bool ToSel, const ConfOption *pConfOption
if( ToSel ) if( ToSel )
{ {
SongOptions so; SongOptions so;
so.FromString( PREFSMAN->m_sDefaultModifiers ); so.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
sel = so.m_FailType; sel = so.m_FailType;
} }
else else
+1 -1
View File
@@ -99,7 +99,7 @@ void ScreenPlayerOptions::Input( const InputEventPlus &input )
// apply the game default mods, but not the Profile saved mods // apply the game default mods, but not the Profile saved mods
GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.Init(); GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.Init();
GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.FromString( PREFSMAN->m_sDefaultModifiers ); GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
MESSAGEMAN->Broadcast( ssprintf("CancelAllP%i", pn+1) ); MESSAGEMAN->Broadcast( ssprintf("CancelAllP%i", pn+1) );
+1 -1
View File
@@ -131,7 +131,7 @@ void ScreenSMOnlineLogin::HandleScreenMessage(const ScreenMessage SM)
for( unsigned r=0; r<m_pRows.size(); r++ ) for( unsigned r=0; r<m_pRows.size(); r++ )
ExportOptions( r, v ); ExportOptions( r, v );
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SavePrefsToDisk();
FOREACH_EnabledPlayer(pn) FOREACH_EnabledPlayer(pn)
{ {
PROFILEMAN->LoadLocalProfileFromMachine((PlayerNumber) pn); PROFILEMAN->LoadLocalProfileFromMachine((PlayerNumber) pn);
+1 -1
View File
@@ -125,7 +125,7 @@ void SongOptions::FromString( CString sOptions )
{ {
SongOptions so; SongOptions so;
// TODO: Fix this so that SongOptions don't depend on PrefsManager // TODO: Fix this so that SongOptions don't depend on PrefsManager
so.FromString( PREFSMAN->m_sDefaultModifiers ); so.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
m_FailType = so.m_FailType; m_FailType = so.m_FailType;
} }
+13 -41
View File
@@ -286,8 +286,6 @@ void ResetGame()
THEME->SwitchThemeAndLanguage( "default", THEME->GetCurLanguage() ); THEME->SwitchThemeAndLanguage( "default", THEME->GetCurLanguage() );
TEXTUREMAN->DoDelayedDelete(); TEXTUREMAN->DoDelayedDelete();
} }
SaveGamePrefsToDisk();
// //
// update last seen joysticks // update last seen joysticks
@@ -310,6 +308,8 @@ void ResetGame()
PREFSMAN->m_sLastSeenInputDevices.Set( sInputDevices ); PREFSMAN->m_sLastSeenInputDevices.Set( sInputDevices );
} }
PREFSMAN->SavePrefsToDisk();
} }
@@ -382,7 +382,7 @@ static void CheckSettings()
* systems. */ * systems. */
PREFSMAN->m_BannerCache.Set( LowMemory ? PrefsManager::BNCACHE_OFF:PrefsManager::BNCACHE_LOW_RES_PRELOAD ); PREFSMAN->m_BannerCache.Set( LowMemory ? PrefsManager::BNCACHE_OFF:PrefsManager::BNCACHE_LOW_RES_PRELOAD );
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SavePrefsToDisk();
#endif #endif
} }
@@ -739,24 +739,22 @@ RageDisplay *CreateDisplay()
RageException::Throw( error ); RageException::Throw( error );
} }
#define GAMEPREFS_INI_PATH "Data/GamePrefs.ini"
#define STATIC_INI_PATH "Data/Static.ini" #define STATIC_INI_PATH "Data/Static.ini"
void ChangeCurrentGame( const Game* g ) void ChangeCurrentGame( const Game* g )
{ {
ASSERT( g ); ASSERT( g );
SaveGamePrefsToDisk();
INPUTMAPPER->SaveMappingsToDisk(); // save mappings before switching the game INPUTMAPPER->SaveMappingsToDisk(); // save mappings before switching the game
GAMESTATE->m_pCurGame = g; GAMESTATE->m_pCurGame = g;
/* Load this game's preferences. If we just set an unavailable game type, this /* Load this game's preferences. If we just set an unavailable game type, this
* will change it back to the default. */ * will change it back to the default. */
ReadGamePrefsFromDisk( false ); PREFSMAN->m_sCurrentGame.Set( g->m_szName );
/* Save the newly-selected game. */ /* Save the newly-selected game. */
SaveGamePrefsToDisk(); PREFSMAN->SavePrefsToDisk();
/* Load keymaps for the new game. */ /* Load keymaps for the new game. */
INPUTMAPPER->ReadMappingsFromDisk(); INPUTMAPPER->ReadMappingsFromDisk();
@@ -769,17 +767,13 @@ void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame )
ASSERT( THEME ); ASSERT( THEME );
ASSERT( GAMESTATE ); ASSERT( GAMESTATE );
IniFile ini;
ini.ReadFile( GAMEPREFS_INI_PATH ); // it's OK if this fails
ini.ReadFile( STATIC_INI_PATH ); // it's OK if this fails, too
if( bSwitchToLastPlayedGame ) if( bSwitchToLastPlayedGame )
{ {
ASSERT( GAMEMAN != NULL ); ASSERT( GAMEMAN != NULL );
CString sGame; CString sGame;
GAMESTATE->m_pCurGame = NULL; GAMESTATE->m_pCurGame = NULL;
if( ini.GetValue("Options", "Game", sGame) ) if( !PREFSMAN->m_sCurrentGame.Get().empty() )
GAMESTATE->m_pCurGame = GAMEMAN->StringToGameType( sGame ); GAMESTATE->m_pCurGame = GAMEMAN->StringToGameType( PREFSMAN->m_sCurrentGame );
} }
/* If the active game type isn't actually available, revert to the default. */ /* If the active game type isn't actually available, revert to the default. */
@@ -805,40 +799,19 @@ void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame )
CString sGameName = GAMESTATE->GetCurrentGame()->m_szName; CString sGameName = GAMESTATE->GetCurrentGame()->m_szName;
CString sAnnouncer = sGameName; CString sAnnouncer = sGameName;
CString sTheme = sGameName; CString sTheme = sGameName;
CString sNoteSkin = sGameName;
CString sDefaultModifiers;
// if these calls fail, the three strings will keep the initial values set above. // if these calls fail, the three strings will keep the initial values set above.
ini.GetValue( sGameName, "Announcer", sAnnouncer ); if( !PREFSMAN->GetCurrentGamePrefs().m_sAnnouncer.empty() )
ini.GetValue( sGameName, "Theme", sTheme ); sAnnouncer = PREFSMAN->GetCurrentGamePrefs().m_sAnnouncer;
ini.GetValue( sGameName, "DefaultModifiers", sDefaultModifiers ); if( !PREFSMAN->GetCurrentGamePrefs().m_sTheme.empty() )
PREFSMAN->m_sDefaultModifiers.Set( sDefaultModifiers ); sTheme = PREFSMAN->GetCurrentGamePrefs().m_sTheme;
// it's OK to call these functions with names that don't exist. // it's OK to call these functions with names that don't exist.
ANNOUNCER->SwitchAnnouncer( sAnnouncer ); ANNOUNCER->SwitchAnnouncer( sAnnouncer );
THEME->SwitchThemeAndLanguage( sTheme, PREFSMAN->m_sLanguage ); THEME->SwitchThemeAndLanguage( sTheme, PREFSMAN->m_sLanguage );
// NOTESKIN->SwitchNoteSkin( sNoteSkin );
} }
void SaveGamePrefsToDisk()
{
if( !GAMESTATE )
return;
CString sGameName = GAMESTATE->GetCurrentGame()->m_szName;
IniFile ini;
ini.ReadFile( GAMEPREFS_INI_PATH ); // it's OK if this fails
ini.SetValue( sGameName, "Announcer", ANNOUNCER->GetCurAnnouncerName() );
ini.SetValue( sGameName, "Theme", THEME->GetCurThemeName() );
ini.SetValue( sGameName, "DefaultModifiers", PREFSMAN->m_sDefaultModifiers );
ini.SetValue( "Options", "Game", (CString)GAMESTATE->GetCurrentGame()->m_szName );
ini.WriteFile( GAMEPREFS_INI_PATH );
}
static void MountTreeOfZips( const CString &dir ) static void MountTreeOfZips( const CString &dir )
{ {
vector<CString> dirs; vector<CString> dirs;
@@ -1037,7 +1010,7 @@ int main(int argc, char* argv[])
/* One of the above filesystems might contain files that affect preferences, eg Data/Static.ini. /* One of the above filesystems might contain files that affect preferences, eg Data/Static.ini.
* Re-read preferences. */ * Re-read preferences. */
PREFSMAN->ReadGlobalPrefsFromDisk(); PREFSMAN->ReadPrefsFromDisk();
ApplyLogPreferences(); ApplyLogPreferences();
#if defined(HAVE_SDL) #if defined(HAVE_SDL)
@@ -1174,8 +1147,7 @@ int main(int argc, char* argv[])
/* If we ended mid-game, finish up. */ /* If we ended mid-game, finish up. */
GAMESTATE->EndGame(); GAMESTATE->EndGame();
PREFSMAN->SaveGlobalPrefsToDisk(); PREFSMAN->SavePrefsToDisk();
SaveGamePrefsToDisk();
ShutdownGame(); ShutdownGame();
-1
View File
@@ -13,7 +13,6 @@ void ApplyGraphicOptions();
void NORETURN HandleException( CString error ); void NORETURN HandleException( CString error );
void ExitGame(); void ExitGame();
void ResetGame(); void ResetGame();
void SaveGamePrefsToDisk();
void ChangeCurrentGame( const Game* g ); void ChangeCurrentGame( const Game* g );
void FocusChanged( bool bHasFocus ); void FocusChanged( bool bHasFocus );
bool AppHasFocus(); bool AppHasFocus();