diff --git a/stepmania/src/Preference.cpp b/stepmania/src/Preference.cpp new file mode 100644 index 0000000000..395af56175 --- /dev/null +++ b/stepmania/src/Preference.cpp @@ -0,0 +1,61 @@ +#include "global.h" +#include "Preference.h" +#include "PrefsManager.h" +#include "IniFile.h" + +static const CString PrefsGroupNames[NUM_PREFS_GROUPS] = { + "Debug", + "Editor", + "Options", +}; +XToString( PrefsGroup ); + +void SubscribePreference( IPreference *p ) +{ + PrefsManager::Subscribe( p ); +} + +void UnsubscribePreference( IPreference *p ) +{ + PrefsManager::Unsubscribe( p ); +} + +#define READFROM_AND_WRITETO( type ) \ + void Preference::ReadFrom( const IniFile &ini ) \ + { \ + ini.GetValue( PrefsGroupToString(m_PrefsGroup), m_sName, m_currentValue ); \ + } \ + void Preference::WriteTo( IniFile &ini ) const \ + { \ + ini.SetValue( PrefsGroupToString(m_PrefsGroup), m_sName, m_currentValue ); \ + } \ + +READFROM_AND_WRITETO( CString ) +READFROM_AND_WRITETO( int ) +READFROM_AND_WRITETO( float ) +READFROM_AND_WRITETO( bool ) + +/* + * (c) 2001-2004 Chris Danford, Chris Gomez + * All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, and/or sell copies of the Software, and to permit persons to + * whom the Software is furnished to do so, provided that the above + * copyright notice(s) and this permission notice appear in all copies of + * the Software and that both the above copyright notice(s) and this + * permission notice appear in supporting documentation. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF + * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS + * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT + * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/stepmania/src/Preference.h b/stepmania/src/Preference.h index 71ce98ebd0..04f94f787e 100644 --- a/stepmania/src/Preference.h +++ b/stepmania/src/Preference.h @@ -3,26 +3,18 @@ #ifndef PREFERENCE_H #define PREFERENCE_H -#include "IniFile.h" -#include "PrefsManager.h" +#include "EnumHelper.h" +class IniFile; enum PrefsGroup { Debug, Editor, Options, + NUM_PREFS_GROUPS }; +const CString& PrefsGroupToString( PrefsGroup pg ); -inline CString PrefsGroupToString( PrefsGroup pg ) -{ - switch( pg ) - { - case Debug: return "Debug"; - case Editor: return "Editor"; - case Options: return "Options"; - default: ASSERT(0); return ""; - } -} class IPreference { @@ -33,6 +25,9 @@ public: virtual void WriteTo( IniFile &ini ) const = 0; }; +void SubscribePreference( IPreference *p ); +void UnsubscribePreference( IPreference *p ); + template class Preference : public IPreference { @@ -41,6 +36,9 @@ private: CString m_sName; T m_defaultValue; T m_currentValue; + + CString ToString(); + void FromString( const CString &s ); public: Preference( PrefsGroup PrefsGroup, const CString& sName, const T& defaultValue ): @@ -49,12 +47,13 @@ public: m_defaultValue( defaultValue ), m_currentValue( defaultValue ) { - PrefsManager::Subscribe( this ); + SubscribePreference( this ); + LoadDefault(); } ~Preference() { - PrefsManager::Unsubscribe( this ); + UnsubscribePreference( this ); } void LoadDefault() @@ -62,21 +61,14 @@ public: m_currentValue = m_defaultValue; } - void ReadFrom( const IniFile &ini ) - { - ini.GetValue( PrefsGroupToString(m_PrefsGroup), m_sName, m_currentValue ); - } + void ReadFrom( const IniFile &ini ); + void WriteTo( IniFile &ini ) const; - void WriteTo( IniFile &ini ) const - { - ini.SetValue( PrefsGroupToString(m_PrefsGroup), m_sName, m_currentValue ); - } - - const T& GetValue() const + operator T& () { return m_currentValue; } - + operator const T& () const { return m_currentValue; diff --git a/stepmania/src/ScreenSystemLayer.cpp b/stepmania/src/ScreenSystemLayer.cpp index d04c1f026b..9a9a4f146d 100644 --- a/stepmania/src/ScreenSystemLayer.cpp +++ b/stepmania/src/ScreenSystemLayer.cpp @@ -275,12 +275,15 @@ void ScreenSystemLayer::Update( float fDeltaTime ) { Screen::Update(fDeltaTime); - if( PREFSMAN && PREFSMAN->m_bShowStats ) + if( PREFSMAN && (bool)PREFSMAN->m_bShowStats ) { m_textStats.SetDiffuse( RageColor(1,1,1,0.7f) ); m_textStats.SetText( DISPLAY->GetStats() ); - } else + } + else + { m_textStats.SetDiffuse( RageColor(1,1,1,0) ); /* hide */ + } UpdateTimestampAndSkips(); } diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index 52f517a9ef..a47a36047b 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -62,7 +62,7 @@ IntDir=.\../Debug6 TargetDir=\stepmania\stepmania\Program TargetName=StepMania-debug SOURCE="$(InputPath)" -PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -99,7 +99,7 @@ IntDir=.\../Release6 TargetDir=\stepmania\stepmania\Program TargetName=StepMania SOURCE="$(InputPath)" -PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=archutils\Win32\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=archutils\Win32\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -940,6 +940,14 @@ SOURCE=.\PlayerOptions.h # End Source File # Begin Source File +SOURCE=.\Preference.cpp +# End Source File +# Begin Source File + +SOURCE=.\Preference.h +# End Source File +# Begin Source File + SOURCE=.\Profile.cpp # End Source File # Begin Source File diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index e2a42119af..d084a46dd0 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -833,6 +833,9 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + +