move Preferences from ThemeManager to completely in PrefsManager
Also, allow Defaults.ini and Static.ini to have sections
This commit is contained in:
@@ -587,7 +587,7 @@ void GameState::SetCurGame( const Game *pGame )
|
|||||||
{
|
{
|
||||||
m_pCurGame.Set( pGame );
|
m_pCurGame.Set( pGame );
|
||||||
CString sGame = pGame ? CString(pGame->m_szName) : CString();
|
CString sGame = pGame ? CString(pGame->m_szName) : CString();
|
||||||
PREFSMAN->m_sCurrentGame.Set( sGame );
|
PREFSMAN->SetCurrentGame( sGame );
|
||||||
}
|
}
|
||||||
|
|
||||||
const float GameState::MUSIC_SECONDS_INVALID = -5000.0f;
|
const float GameState::MUSIC_SECONDS_INVALID = -5000.0f;
|
||||||
@@ -1022,14 +1022,14 @@ StageResult GameState::GetStageResult( PlayerNumber pn ) const
|
|||||||
void GameState::GetDefaultPlayerOptions( PlayerOptions &po )
|
void GameState::GetDefaultPlayerOptions( PlayerOptions &po )
|
||||||
{
|
{
|
||||||
po.Init();
|
po.Init();
|
||||||
po.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
|
po.FromString( PREFSMAN->m_sDefaultModifiers );
|
||||||
po.FromString( CommonMetrics::DEFAULT_MODIFIERS );
|
po.FromString( CommonMetrics::DEFAULT_MODIFIERS );
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameState::GetDefaultSongOptions( SongOptions &so )
|
void GameState::GetDefaultSongOptions( SongOptions &so )
|
||||||
{
|
{
|
||||||
so.Init();
|
so.Init();
|
||||||
so.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
|
so.FromString( PREFSMAN->m_sDefaultModifiers );
|
||||||
so.FromString( CommonMetrics::DEFAULT_MODIFIERS );
|
so.FromString( CommonMetrics::DEFAULT_MODIFIERS );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ READFROM_AND_WRITETO( float )
|
|||||||
READFROM_AND_WRITETO( bool )
|
READFROM_AND_WRITETO( bool )
|
||||||
READFROM_AND_WRITETO( CString )
|
READFROM_AND_WRITETO( CString )
|
||||||
|
|
||||||
void IPreference::ReadFrom( const IniFile &ini )
|
void IPreference::ReadFrom( const IniFile &ini, const CString &sSection )
|
||||||
{
|
{
|
||||||
CString sVal;
|
CString sVal;
|
||||||
if( ini.GetValue( "Options", m_sName, sVal ) )
|
if( ini.GetValue( sSection, m_sName, sVal ) )
|
||||||
FromString( sVal );
|
FromString( sVal );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public:
|
|||||||
virtual ~IPreference();
|
virtual ~IPreference();
|
||||||
|
|
||||||
virtual void LoadDefault() = 0;
|
virtual void LoadDefault() = 0;
|
||||||
virtual void ReadFrom( const IniFile &ini );
|
virtual void ReadFrom( const IniFile &ini, const CString &sSection );
|
||||||
virtual void WriteTo( IniFile &ini ) const;
|
virtual void WriteTo( IniFile &ini ) const;
|
||||||
|
|
||||||
virtual CString ToString() const = 0;
|
virtual CString ToString() const = 0;
|
||||||
|
|||||||
+106
-16
@@ -10,10 +10,12 @@
|
|||||||
#include "Foreach.h"
|
#include "Foreach.h"
|
||||||
#include "Preference.h"
|
#include "Preference.h"
|
||||||
#include "RageLog.h"
|
#include "RageLog.h"
|
||||||
|
#include "StepMania.h"
|
||||||
|
|
||||||
const CString DEFAULTS_INI_PATH = "Data/Defaults.ini"; // these can be overridden
|
const CString DEFAULTS_INI_PATH = "Data/Defaults.ini"; // these can be overridden
|
||||||
const CString STEPMANIA_INI_PATH = "Save/" PRODUCT_NAME ".ini"; // overlay on Defaults.ini, contains the user's choices
|
const CString STEPMANIA_INI_PATH = "Save/" PRODUCT_NAME ".ini"; // overlay on Defaults.ini, contains the user's choices
|
||||||
const CString 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
|
||||||
|
const CString TYPE_TXT_FILE = "Data/Type.txt";
|
||||||
|
|
||||||
PrefsManager* PREFSMAN = NULL; // global and accessable from anywhere in our program
|
PrefsManager* PREFSMAN = NULL; // global and accessable from anywhere in our program
|
||||||
|
|
||||||
@@ -211,6 +213,11 @@ void TimeMeterSecondsChangeInit( size_t /*ScoreEvent*/ i, CString &sNameOut, flo
|
|||||||
|
|
||||||
PrefsManager::PrefsManager() :
|
PrefsManager::PrefsManager() :
|
||||||
m_sCurrentGame ( "CurrentGame", "" ),
|
m_sCurrentGame ( "CurrentGame", "" ),
|
||||||
|
|
||||||
|
m_sAnnouncer ( "Announcer", "" ),
|
||||||
|
m_sTheme ( "Theme", "" ),
|
||||||
|
m_sDefaultModifiers ( "DefaultModifiers", "" ),
|
||||||
|
|
||||||
m_bWindowed ( "Windowed", TRUE_IF_DEBUG ),
|
m_bWindowed ( "Windowed", TRUE_IF_DEBUG ),
|
||||||
m_iDisplayWidth ( "DisplayWidth", 640 ),
|
m_iDisplayWidth ( "DisplayWidth", 640 ),
|
||||||
m_iDisplayHeight ( "DisplayHeight", 480 ),
|
m_iDisplayHeight ( "DisplayHeight", 480 ),
|
||||||
@@ -404,49 +411,119 @@ void PrefsManager::Init()
|
|||||||
{
|
{
|
||||||
FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p )
|
FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p )
|
||||||
(*p)->LoadDefault();
|
(*p)->LoadDefault();
|
||||||
|
|
||||||
|
m_mapGameNameToGamePrefs.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
PrefsManager::~PrefsManager()
|
PrefsManager::~PrefsManager()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PrefsManager::SetCurrentGame( const CString &sGame )
|
||||||
|
{
|
||||||
|
if( m_sCurrentGame.Get() == sGame )
|
||||||
|
return; // redundant
|
||||||
|
|
||||||
|
if( !m_sCurrentGame.Get().empty() )
|
||||||
|
StoreGamePrefs();
|
||||||
|
|
||||||
|
m_sCurrentGame.Set( sGame );
|
||||||
|
|
||||||
|
RestoreGamePrefs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrefsManager::StoreGamePrefs()
|
||||||
|
{
|
||||||
|
ASSERT( !m_sCurrentGame.Get().empty() )
|
||||||
|
|
||||||
|
// save off old values
|
||||||
|
GamePrefs &gp = m_mapGameNameToGamePrefs[m_sCurrentGame];
|
||||||
|
gp.m_sAnnouncer = m_sAnnouncer;
|
||||||
|
gp.m_sTheme = m_sTheme;
|
||||||
|
gp.m_sDefaultModifiers = m_sDefaultModifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrefsManager::RestoreGamePrefs()
|
||||||
|
{
|
||||||
|
ASSERT( !m_sCurrentGame.Get().empty() )
|
||||||
|
|
||||||
|
// save off old values
|
||||||
|
map<CString, GamePrefs>::const_iterator iter = m_mapGameNameToGamePrefs.find( m_sCurrentGame );
|
||||||
|
if( iter == m_mapGameNameToGamePrefs.end() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
const GamePrefs &gp = iter->second;
|
||||||
|
m_sAnnouncer .Set( gp.m_sAnnouncer );
|
||||||
|
m_sTheme .Set( gp.m_sTheme );
|
||||||
|
m_sDefaultModifiers .Set( gp.m_sDefaultModifiers );
|
||||||
|
|
||||||
|
// give Static.ini a chance to clobber the saved game prefs
|
||||||
|
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
|
||||||
|
}
|
||||||
|
|
||||||
void PrefsManager::ReadPrefsFromDisk()
|
void PrefsManager::ReadPrefsFromDisk()
|
||||||
{
|
{
|
||||||
ReadPrefsFromFile( DEFAULTS_INI_PATH );
|
ReadPrefsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
|
||||||
ReadPrefsFromFile( STEPMANIA_INI_PATH );
|
ReadPrefsFromFile( STEPMANIA_INI_PATH, "Options" );
|
||||||
ReadPrefsFromFile( STATIC_INI_PATH );
|
ReadGamePrefsFromIni( STEPMANIA_INI_PATH );
|
||||||
|
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
|
||||||
|
|
||||||
|
if( !m_sCurrentGame.Get().empty() )
|
||||||
|
RestoreGamePrefs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefsManager::ResetToFactoryDefaults()
|
void PrefsManager::ResetToFactoryDefaults()
|
||||||
{
|
{
|
||||||
// clobber the users prefs by initing then applying defaults
|
// clobber the users prefs by initing then applying defaults
|
||||||
Init();
|
Init();
|
||||||
ReadPrefsFromFile( DEFAULTS_INI_PATH );
|
ReadPrefsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
|
||||||
ReadPrefsFromFile( STATIC_INI_PATH );
|
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
|
||||||
|
|
||||||
SavePrefsToDisk();
|
SavePrefsToDisk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefsManager::ReadPrefsFromFile( const CString &sIni )
|
void PrefsManager::ReadPrefsFromFile( const CString &sIni, const CString &sSection )
|
||||||
{
|
{
|
||||||
IniFile ini;
|
IniFile ini;
|
||||||
if( !ini.ReadFile(sIni) )
|
if( !ini.ReadFile(sIni) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ReadPrefsFromIni( ini );
|
ReadPrefsFromIni( ini, sSection );
|
||||||
}
|
}
|
||||||
|
|
||||||
static const CString GAME_SECTION_PREFIX = "Game-";
|
static const CString GAME_SECTION_PREFIX = "Game-";
|
||||||
|
|
||||||
void PrefsManager::ReadPrefsFromIni( const IniFile &ini )
|
void PrefsManager::ReadPrefsFromIni( const IniFile &ini, const CString &sSection )
|
||||||
{
|
{
|
||||||
|
// Apply our fallback (if any) before applying ourself.
|
||||||
|
// TODO: detect circular?
|
||||||
|
CString sFallback;
|
||||||
|
if( ini.GetValue(sSection,"Fallback",sFallback) )
|
||||||
|
{
|
||||||
|
ReadPrefsFromIni( ini, sFallback );
|
||||||
|
}
|
||||||
|
|
||||||
|
//IPreference *pPref = PREFSMAN->GetPreferenceByName( *sName );
|
||||||
|
// if( pPref == NULL )
|
||||||
|
// {
|
||||||
|
// LOG->Warn( "Unknown preference in [%s]: %s", sClassName.c_str(), sName->c_str() );
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
// pPref->FromString( sVal );
|
||||||
|
|
||||||
FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p )
|
FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p )
|
||||||
(*p)->ReadFrom( ini );
|
(*p)->ReadFrom( ini, sSection );
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
m_iSongsPerPlay.Set( clamp(m_iSongsPerPlay.Get(),0,MAX_SONGS_PER_PLAY) );
|
m_iSongsPerPlay.Set( clamp(m_iSongsPerPlay.Get(),0,MAX_SONGS_PER_PLAY) );
|
||||||
m_RandomBackgroundMode.Set( (RandomBackgroundMode)clamp((int)m_RandomBackgroundMode.Get(),0,(int)NUM_RandomBackgroundMode-1) );
|
m_RandomBackgroundMode.Set( (RandomBackgroundMode)clamp((int)m_RandomBackgroundMode.Get(),0,(int)NUM_RandomBackgroundMode-1) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrefsManager::ReadGamePrefsFromIni( const CString &sIni )
|
||||||
|
{
|
||||||
|
IniFile ini;
|
||||||
|
if( !ini.ReadFile(sIni) )
|
||||||
|
return;
|
||||||
|
|
||||||
FOREACH_CONST_Child( &ini, section )
|
FOREACH_CONST_Child( &ini, section )
|
||||||
{
|
{
|
||||||
@@ -462,15 +539,18 @@ void PrefsManager::ReadPrefsFromIni( const IniFile &ini )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefsManager::SavePrefsToDisk() const
|
void PrefsManager::SavePrefsToDisk()
|
||||||
{
|
{
|
||||||
IniFile ini;
|
IniFile ini;
|
||||||
SavePrefsToIni( ini );
|
SavePrefsToIni( ini );
|
||||||
ini.WriteFile( STEPMANIA_INI_PATH );
|
ini.WriteFile( STEPMANIA_INI_PATH );
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrefsManager::SavePrefsToIni( IniFile &ini ) const
|
void PrefsManager::SavePrefsToIni( IniFile &ini )
|
||||||
{
|
{
|
||||||
|
if( !m_sCurrentGame.Get().empty() )
|
||||||
|
StoreGamePrefs();
|
||||||
|
|
||||||
FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p )
|
FOREACHS_CONST( IPreference*, *SubscriptionManager<IPreference>::s_pSubscribers, p )
|
||||||
(*p)->WriteTo( ini );
|
(*p)->WriteTo( ini );
|
||||||
|
|
||||||
@@ -484,6 +564,21 @@ void PrefsManager::SavePrefsToIni( IniFile &ini ) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CString PrefsManager::GetPreferencesSection() const
|
||||||
|
{
|
||||||
|
CString sSection = "Preferences";
|
||||||
|
|
||||||
|
// OK if this fails
|
||||||
|
GetFileContents( TYPE_TXT_FILE, sSection, true );
|
||||||
|
|
||||||
|
// OK if this fails
|
||||||
|
GetCommandlineArgument( "Type", &sSection );
|
||||||
|
|
||||||
|
return sSection;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// wrappers
|
// wrappers
|
||||||
CString PrefsManager::GetSoundDrivers()
|
CString PrefsManager::GetSoundDrivers()
|
||||||
{
|
{
|
||||||
@@ -522,11 +617,6 @@ CString PrefsManager::GetLightsDriver()
|
|||||||
return m_sLightsDriver;
|
return m_sLightsDriver;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrefsManager::GamePrefs &PrefsManager::GetCurrentGamePrefs()
|
|
||||||
{
|
|
||||||
ASSERT( !m_sCurrentGame.Get().empty() );
|
|
||||||
return m_mapGameNameToGamePrefs[m_sCurrentGame];
|
|
||||||
}
|
|
||||||
|
|
||||||
// lua start
|
// lua start
|
||||||
#include "LuaBinding.h"
|
#include "LuaBinding.h"
|
||||||
|
|||||||
@@ -20,7 +20,28 @@ public:
|
|||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
void SetCurrentGame( const CString &sGame );
|
||||||
|
CString GetCurrentGame() { return m_sCurrentGame; }
|
||||||
|
protected:
|
||||||
Preference<CString> m_sCurrentGame;
|
Preference<CString> m_sCurrentGame;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Game-specific prefs. Copy these off and save them every time the game changes
|
||||||
|
Preference<CString> m_sAnnouncer;
|
||||||
|
Preference<CString> m_sTheme;
|
||||||
|
Preference<CString> m_sDefaultModifiers;
|
||||||
|
protected:
|
||||||
|
void StoreGamePrefs();
|
||||||
|
void RestoreGamePrefs();
|
||||||
|
struct GamePrefs
|
||||||
|
{
|
||||||
|
CString m_sAnnouncer;
|
||||||
|
CString m_sTheme;
|
||||||
|
CString m_sDefaultModifiers;
|
||||||
|
};
|
||||||
|
map<CString, GamePrefs> m_mapGameNameToGamePrefs;
|
||||||
|
|
||||||
|
public:
|
||||||
Preference<bool> m_bWindowed;
|
Preference<bool> m_bWindowed;
|
||||||
Preference<int> m_iDisplayWidth;
|
Preference<int> m_iDisplayWidth;
|
||||||
Preference<int> m_iDisplayHeight;
|
Preference<int> m_iDisplayHeight;
|
||||||
@@ -259,14 +280,17 @@ public:
|
|||||||
CString GetLightsDriver();
|
CString GetLightsDriver();
|
||||||
|
|
||||||
|
|
||||||
void ReadPrefsFromIni( const IniFile &ini );
|
void ReadPrefsFromIni( const IniFile &ini, const CString &sSection );
|
||||||
void SavePrefsToIni( IniFile &ini ) const;
|
void ReadGamePrefsFromIni( const CString &sIni );
|
||||||
|
void SavePrefsToIni( IniFile &ini );
|
||||||
|
|
||||||
void ReadPrefsFromDisk();
|
void ReadPrefsFromDisk();
|
||||||
void SavePrefsToDisk() const;
|
void SavePrefsToDisk();
|
||||||
|
|
||||||
void ResetToFactoryDefaults();
|
void ResetToFactoryDefaults();
|
||||||
|
|
||||||
|
CString GetPreferencesSection() const;
|
||||||
|
|
||||||
//
|
//
|
||||||
// For self-registering prefs
|
// For self-registering prefs
|
||||||
//
|
//
|
||||||
@@ -274,28 +298,11 @@ public:
|
|||||||
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();
|
|
||||||
|
|
||||||
void SaveGamePrefsToDisk();
|
|
||||||
void ReadGamePrefsFromDisk();
|
|
||||||
|
|
||||||
|
|
||||||
// Lua
|
// Lua
|
||||||
void PushSelf( lua_State *L );
|
void PushSelf( lua_State *L );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void ReadPrefsFromFile( const CString &sIni );
|
void ReadPrefsFromFile( const CString &sIni, const CString &sSection );
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
static void GetPrefsDefaultModifiers( PlayerOptions &po, SongOptions &so )
|
static void GetPrefsDefaultModifiers( PlayerOptions &po, SongOptions &so )
|
||||||
{
|
{
|
||||||
po.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
|
po.FromString( PREFSMAN->m_sDefaultModifiers );
|
||||||
so.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
|
so.FromString( PREFSMAN->m_sDefaultModifiers );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetPrefsDefaultModifiers( const PlayerOptions &po, const SongOptions &so )
|
static void SetPrefsDefaultModifiers( const PlayerOptions &po, const SongOptions &so )
|
||||||
@@ -29,7 +29,7 @@ static void SetPrefsDefaultModifiers( const PlayerOptions &po, const SongOptions
|
|||||||
if( so.GetString() != "" )
|
if( so.GetString() != "" )
|
||||||
as.push_back( so.GetString() );
|
as.push_back( so.GetString() );
|
||||||
|
|
||||||
PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers = join( ", ",as );
|
PREFSMAN->m_sDefaultModifiers.Set( join(", ",as) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ugly: the input values may be a different type than the mapping. For example,
|
/* Ugly: the input values may be a different type than the mapping. For example,
|
||||||
@@ -235,7 +235,7 @@ static void DefaultNoteSkin( int &sel, bool ToSel, const ConfOption *pConfOption
|
|||||||
if( ToSel )
|
if( ToSel )
|
||||||
{
|
{
|
||||||
PlayerOptions po;
|
PlayerOptions po;
|
||||||
po.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
|
po.FromString( PREFSMAN->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) )
|
||||||
@@ -384,7 +384,7 @@ static void DefaultFailType( int &sel, bool ToSel, const ConfOption *pConfOption
|
|||||||
if( ToSel )
|
if( ToSel )
|
||||||
{
|
{
|
||||||
SongOptions so;
|
SongOptions so;
|
||||||
so.FromString( PREFSMAN->GetCurrentGamePrefs().m_sDefaultModifiers );
|
so.FromString( PREFSMAN->m_sDefaultModifiers );
|
||||||
sel = so.m_FailType;
|
sel = so.m_FailType;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
+10
-10
@@ -766,10 +766,12 @@ void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame )
|
|||||||
if( bSwitchToLastPlayedGame )
|
if( bSwitchToLastPlayedGame )
|
||||||
{
|
{
|
||||||
ASSERT( GAMEMAN != NULL );
|
ASSERT( GAMEMAN != NULL );
|
||||||
CString sGame;
|
CString sGame = PREFSMAN->GetCurrentGame();
|
||||||
GAMESTATE->SetCurGame( NULL );
|
if( !sGame.empty() )
|
||||||
if( !PREFSMAN->m_sCurrentGame.Get().empty() )
|
{
|
||||||
GAMESTATE->SetCurGame( GAMEMAN->StringToGameType(PREFSMAN->m_sCurrentGame) );
|
const Game *pGame = GAMEMAN->StringToGameType(sGame);
|
||||||
|
GAMESTATE->SetCurGame( pGame );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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. */
|
||||||
@@ -797,10 +799,10 @@ void ReadGamePrefsFromDisk( bool bSwitchToLastPlayedGame )
|
|||||||
CString sTheme = sGameName;
|
CString sTheme = sGameName;
|
||||||
|
|
||||||
// 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.
|
||||||
if( !PREFSMAN->GetCurrentGamePrefs().m_sAnnouncer.empty() )
|
if( !PREFSMAN->m_sAnnouncer.Get().empty() )
|
||||||
sAnnouncer = PREFSMAN->GetCurrentGamePrefs().m_sAnnouncer;
|
sAnnouncer = PREFSMAN->m_sAnnouncer;
|
||||||
if( !PREFSMAN->GetCurrentGamePrefs().m_sTheme.empty() )
|
if( !PREFSMAN->m_sTheme.Get().empty() )
|
||||||
sTheme = PREFSMAN->GetCurrentGamePrefs().m_sTheme;
|
sTheme = PREFSMAN->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 );
|
||||||
@@ -1042,8 +1044,6 @@ int main(int argc, char* argv[])
|
|||||||
/* Set up the theme and announcer, and switch to the last game type. */
|
/* Set up the theme and announcer, and switch to the last game type. */
|
||||||
ReadGamePrefsFromDisk( true );
|
ReadGamePrefsFromDisk( true );
|
||||||
|
|
||||||
THEME->LoadPreferencesFromMetrics();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Now that THEME is loaded, load the icon for the current theme into the
|
/* Now that THEME is loaded, load the icon for the current theme into the
|
||||||
* loading window. */
|
* loading window. */
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ const CString LANGUAGES_SUBDIR = "Languages/";
|
|||||||
const CString BASE_LANGUAGE = "english";
|
const CString BASE_LANGUAGE = "english";
|
||||||
const CString THEMES_DIR = "Themes/";
|
const CString THEMES_DIR = "Themes/";
|
||||||
const CString METRICS_FILE = "metrics.ini";
|
const CString METRICS_FILE = "metrics.ini";
|
||||||
const CString TYPE_TXT_FILE = "Data/Type.txt";
|
|
||||||
|
|
||||||
|
|
||||||
struct Theme
|
struct Theme
|
||||||
@@ -928,57 +927,6 @@ void ThemeManager::GetMetricsThatBeginWith( const CString &sClassName_, const CS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CString ThemeManager::GetPreferencesSection() const
|
|
||||||
{
|
|
||||||
CString sSection = "Preferences";
|
|
||||||
|
|
||||||
// OK if this fails
|
|
||||||
GetFileContents( TYPE_TXT_FILE, sSection, true );
|
|
||||||
|
|
||||||
// OK if this fails
|
|
||||||
GetCommandlineArgument( "Type", &sSection );
|
|
||||||
|
|
||||||
return sSection;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ThemeManager::LoadPreferencesFromMetrics()
|
|
||||||
{
|
|
||||||
CString sClassName = GetPreferencesSection();
|
|
||||||
|
|
||||||
set<CString> asNames;
|
|
||||||
|
|
||||||
GetMetricsThatBeginWith( sClassName, "", asNames );
|
|
||||||
|
|
||||||
/* If "Theme" isn't set, we're not changing the theme. Break out and
|
|
||||||
* load other preferences. */
|
|
||||||
if( asNames.find("Theme") != asNames.end() )
|
|
||||||
{
|
|
||||||
/* Change the theme. Only do this once. */
|
|
||||||
CString sTheme;
|
|
||||||
GetMetric( sClassName, "Theme", sTheme );
|
|
||||||
THEME->SwitchThemeAndLanguage( sTheme, PREFSMAN->m_sLanguage );
|
|
||||||
|
|
||||||
asNames.erase( "Theme" );
|
|
||||||
}
|
|
||||||
|
|
||||||
FOREACHS( CString, asNames, sName )
|
|
||||||
{
|
|
||||||
if( !sName->CompareNoCase("Fallback") )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
IPreference *pPref = PREFSMAN->GetPreferenceByName( *sName );
|
|
||||||
if( pPref == NULL )
|
|
||||||
{
|
|
||||||
LOG->Warn( "Unknown preference in [%s]: %s", sClassName.c_str(), sName->c_str() );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
CString sVal;
|
|
||||||
GetMetric( sClassName, *sName, sVal );
|
|
||||||
|
|
||||||
pPref->FromString( sVal );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CString ThemeManager::GetBlankGraphicPath()
|
CString ThemeManager::GetBlankGraphicPath()
|
||||||
{
|
{
|
||||||
@@ -997,7 +945,6 @@ public:
|
|||||||
static int GetPathG( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathG(SArg(1),SArg(2)) ); return 1; }
|
static int GetPathG( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathG(SArg(1),SArg(2)) ); return 1; }
|
||||||
static int GetPathB( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathB(SArg(1),SArg(2)) ); return 1; }
|
static int GetPathB( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathB(SArg(1),SArg(2)) ); return 1; }
|
||||||
static int GetPathS( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathS(SArg(1),SArg(2)) ); return 1; }
|
static int GetPathS( T* p, lua_State *L ) { lua_pushstring(L, p->GetPathS(SArg(1),SArg(2)) ); return 1; }
|
||||||
static int GetPreferencesSection( T* p, lua_State *L ) { lua_pushstring(L, p->GetPreferencesSection() ); return 1; }
|
|
||||||
|
|
||||||
static void Register(lua_State *L)
|
static void Register(lua_State *L)
|
||||||
{
|
{
|
||||||
@@ -1005,7 +952,6 @@ public:
|
|||||||
ADD_METHOD( GetPathG );
|
ADD_METHOD( GetPathG );
|
||||||
ADD_METHOD( GetPathB );
|
ADD_METHOD( GetPathB );
|
||||||
ADD_METHOD( GetPathS );
|
ADD_METHOD( GetPathS );
|
||||||
ADD_METHOD( GetPreferencesSection );
|
|
||||||
|
|
||||||
Luna<T>::Register( L );
|
Luna<T>::Register( L );
|
||||||
|
|
||||||
|
|||||||
@@ -82,8 +82,6 @@ public:
|
|||||||
void GetMetric( const CString &sClassName, const CString &sValueName, apActorCommands &valueOut );
|
void GetMetric( const CString &sClassName, const CString &sValueName, apActorCommands &valueOut );
|
||||||
|
|
||||||
void GetMetricsThatBeginWith( const CString &sClassName, const CString &sValueName, set<CString> &vsValueNamesOut );
|
void GetMetricsThatBeginWith( const CString &sClassName, const CString &sValueName, set<CString> &vsValueNamesOut );
|
||||||
CString GetPreferencesSection() const;
|
|
||||||
void LoadPreferencesFromMetrics();
|
|
||||||
|
|
||||||
static CString GetBlankGraphicPath();
|
static CString GetBlankGraphicPath();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user