diff --git a/stepmania/src/Preference.cpp b/stepmania/src/Preference.cpp index bdf0d47e18..255c13f28f 100644 --- a/stepmania/src/Preference.cpp +++ b/stepmania/src/Preference.cpp @@ -37,12 +37,11 @@ void IPreference::LoadAllDefaults() (*p)->LoadDefault(); } -void IPreference::ReadAllPrefsFromNode( const XNode* pNode ) +void IPreference::ReadAllPrefsFromNode( const XNode* pNode, bool bIsStatic ) { - if( pNode == NULL ) - return; + ASSERT( pNode ); FOREACHS_CONST( IPreference*, *m_Subscribers.m_pSubscribers, p ) - (*p)->ReadFrom( pNode ); + (*p)->ReadFrom( pNode, bIsStatic ); } void IPreference::SavePrefsToNode( XNode* pNode ) @@ -97,16 +96,20 @@ READFROM_AND_WRITETO( float ) READFROM_AND_WRITETO( bool ) READFROM_AND_WRITETO( RString ) -void IPreference::ReadFrom( const XNode* pNode ) +void IPreference::ReadFrom( const XNode* pNode, bool bIsStatic ) { RString sVal; if( pNode->GetAttrValue(m_sName, sVal) ) + { FromString( sVal ); + m_bLoadedFromStatic = bIsStatic; + } } void IPreference::WriteTo( XNode* pNode ) const { - pNode->AppendAttr( m_sName, ToString() ); + if( !m_bLoadedFromStatic ) + pNode->AppendAttr( m_sName, ToString() ); } /* Load our value from the node, and make it the new default. */ diff --git a/stepmania/src/Preference.h b/stepmania/src/Preference.h index 2bec371cca..de0c8c0a0e 100644 --- a/stepmania/src/Preference.h +++ b/stepmania/src/Preference.h @@ -13,7 +13,7 @@ class IPreference public: IPreference( const RString& sName ); virtual ~IPreference(); - void ReadFrom( const XNode* pNode ); + void ReadFrom( const XNode* pNode, bool bIsStatic ); void WriteTo( XNode* pNode ) const; void ReadDefaultFrom( const XNode* pNode ); @@ -30,12 +30,14 @@ public: static IPreference *GetPreferenceByName( const RString &sName ); static void LoadAllDefaults(); - static void ReadAllPrefsFromNode( const XNode* pNode ); + static void ReadAllPrefsFromNode( const XNode* pNode, bool bIsStatic ); static void SavePrefsToNode( XNode* pNode ); static void ReadAllDefaultsFromNode( const XNode* pNode ); -protected: - RString m_sName; + RString GetName() { return m_sName; } +private: + RString m_sName; + bool m_bLoadedFromStatic; // loaded from Static.ini? If so, don't write to Preferences.ini }; void BroadcastPreferenceChanged( const RString& sPreferenceName ); @@ -59,9 +61,22 @@ public: } RString ToString() const { return PrefToString( (const BasicType &) m_currentValue ); } - void FromString( const RString &s ) { PrefFromString( s, (BasicType &)m_currentValue ); if(m_pfnValidate) m_pfnValidate(m_currentValue); } - void SetFromStack( lua_State *L ) { PrefSetFromStack( L, (BasicType &)m_currentValue ); if(m_pfnValidate) m_pfnValidate(m_currentValue); } - void PushValue( lua_State *L ) const { PrefPushValue( L, (BasicType &)m_currentValue ); } + void FromString( const RString &s ) + { + PrefFromString( s, (BasicType &)m_currentValue ); + if( m_pfnValidate ) + m_pfnValidate( m_currentValue ); + } + void SetFromStack( lua_State *L ) + { + PrefSetFromStack( L, (BasicType &)m_currentValue ); + if( m_pfnValidate ) + m_pfnValidate( m_currentValue ); + } + void PushValue( lua_State *L ) const + { + PrefPushValue( L, (BasicType &)m_currentValue ); + } void LoadDefault() { @@ -85,7 +100,7 @@ public: void Set( const T& other ) { m_currentValue = other; - BroadcastPreferenceChanged( m_sName ); + BroadcastPreferenceChanged( GetName() ); } private: diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index ac6c01b8e1..a4e73f6383 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -385,7 +385,7 @@ void PrefsManager::RestoreGamePrefs() m_sDefaultModifiers .Set( gp.m_sDefaultModifiers ); // give Static.ini a chance to clobber the saved game prefs - ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection() ); + ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection(), true ); } void PrefsManager::ReadPrefsFromDisk() @@ -393,9 +393,9 @@ void PrefsManager::ReadPrefsFromDisk() ReadDefaultsFromFile( SpecialFiles::DEFAULTS_INI_PATH, GetPreferencesSection() ); IPreference::LoadAllDefaults(); - ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options" ); + ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options", false ); ReadGamePrefsFromIni( SpecialFiles::PREFERENCES_INI_PATH ); - ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection() ); + ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection(), true ); if( !m_sCurrentGame.Get().empty() ) RestoreGamePrefs(); @@ -406,31 +406,34 @@ void PrefsManager::ResetToFactoryDefaults() // clobber the users prefs by initing then applying defaults Init(); IPreference::LoadAllDefaults(); - ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection() ); + ReadPrefsFromFile( SpecialFiles::STATIC_INI_PATH, GetPreferencesSection(), true ); SavePrefsToDisk(); } -void PrefsManager::ReadPrefsFromFile( const RString &sIni, const RString &sSection ) +void PrefsManager::ReadPrefsFromFile( const RString &sIni, const RString &sSection, bool bIsStatic ) { IniFile ini; if( !ini.ReadFile(sIni) ) return; - ReadPrefsFromIni( ini, sSection ); + ReadPrefsFromIni( ini, sSection, bIsStatic ); } static const RString GAME_SECTION_PREFIX = "Game-"; -void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const RString &sSection ) +void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const RString &sSection, bool bIsStatic ) { // Apply our fallback recursively (if any) before applying ourself. - // TODO: detect circular? + static int s_iDepth = 0; + s_iDepth++; + ASSERT( s_iDepth < 100 ); RString sFallback; if( ini.GetValue(sSection,"Fallback",sFallback) ) { - ReadPrefsFromIni( ini, sFallback ); + ReadPrefsFromIni( ini, sFallback, bIsStatic ); } + s_iDepth--; //IPreference *pPref = PREFSMAN->GetPreferenceByName( *sName ); // if( pPref == NULL ) @@ -440,7 +443,9 @@ void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const RString &sSection // } // pPref->FromString( sVal ); - IPreference::ReadAllPrefsFromNode( ini.GetChild(sSection) ); + const XNode *pChild = ini.GetChild(sSection); + if( pChild ) + IPreference::ReadAllPrefsFromNode( pChild, bIsStatic ); } void PrefsManager::ReadGamePrefsFromIni( const RString &sIni ) @@ -505,7 +510,7 @@ void PrefsManager::SavePrefsToIni( IniFile &ini ) RString sSection = "Game-" + RString( iter->first ); ini.SetValue( sSection, "Announcer", iter->second.m_sAnnouncer ); - ini.SetValue( sSection, "Theme", iter->second.m_sTheme ); + ini.SetValue( sSection, "Theme", iter->second.m_sTheme ); ini.SetValue( sSection, "DefaultModifiers", iter->second.m_sDefaultModifiers ); } } diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index aca705f434..136cfe68c3 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -241,7 +241,7 @@ public: float GetSoundVolume(); - void ReadPrefsFromIni( const IniFile &ini, const RString &sSection ); + void ReadPrefsFromIni( const IniFile &ini, const RString &sSection, bool bIsStatic ); void ReadGamePrefsFromIni( const RString &sIni ); void ReadDefaultsFromIni( const IniFile &ini, const RString &sSection ); void SavePrefsToIni( IniFile &ini ); @@ -257,7 +257,7 @@ public: void PushSelf( lua_State *L ); protected: - void ReadPrefsFromFile( const RString &sIni, const RString &sSection ); + void ReadPrefsFromFile( const RString &sIni, const RString &sSection, bool bIsStatic ); void ReadDefaultsFromFile( const RString &sIni, const RString &sSection ); };