From df6d8cb6ba3ce0e88e04ac63ead5375bf1b6df2e Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Sat, 20 May 2006 08:58:53 +0000 Subject: [PATCH] Make the default NoteSkin a theme metric. That means we can't call GetNoteSkinNames() before the theme is loaded so split out the code to get the names of the the skins for a particular game. --- stepmania/src/GameManager.cpp | 4 +- stepmania/src/NoteSkinManager.cpp | 74 ++++++++++++++++++------------- stepmania/src/NoteSkinManager.h | 8 +++- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/stepmania/src/GameManager.cpp b/stepmania/src/GameManager.cpp index 584695c6fa..b7f84d0627 100644 --- a/stepmania/src/GameManager.cpp +++ b/stepmania/src/GameManager.cpp @@ -2712,9 +2712,7 @@ const Game* GameManager::GetGameFromIndex( int index ) const bool GameManager::IsGameEnabled( const Game *pGame ) const { - vector asNoteSkins; - NOTESKIN->GetNoteSkinNames( pGame, asNoteSkins, false ); /* don't omit default */ - return asNoteSkins.size() > 0; + return NOTESKIN->DoNoteSkinsExistForGame( pGame ); } int GameManager::StepsTypeToNumTracks( StepsType st ) diff --git a/stepmania/src/NoteSkinManager.cpp b/stepmania/src/NoteSkinManager.cpp index 11edea975d..25c2fb81df 100644 --- a/stepmania/src/NoteSkinManager.cpp +++ b/stepmania/src/NoteSkinManager.cpp @@ -17,12 +17,12 @@ NoteSkinManager* NOTESKIN = NULL; // global object accessable from anywhere in t const RString NOTESKINS_DIR = "NoteSkins/"; -const RString GAME_BASE_NOTESKIN_NAME = "default"; const RString GLOBAL_BASE_NOTESKIN_DIR = NOTESKINS_DIR + "common/default/"; static map g_PathCache; NoteSkinManager::NoteSkinManager() { + GAME_BASE_NOTESKIN_NAME.Load( "NoteSkinManager", "GameBaseNoteSkin" ); m_pCurGame = NULL; } @@ -102,12 +102,51 @@ void NoteSkinManager::GetNoteSkinNames( vector &AddTo ) } void NoteSkinManager::GetNoteSkinNames( const Game* pGame, vector &AddTo, bool bFilterDefault ) +{ + GetAllNoteSkinNamesForGame( pGame, AddTo ); + + /* Move "default" to the front if it exists. */ + vector::iterator iter = find( AddTo.begin(), AddTo.end(), GAME_BASE_NOTESKIN_NAME.GetValue() ); + if( iter != AddTo.end() ) + { + AddTo.erase( iter ); + if( !bFilterDefault || !PREFSMAN->m_bHideDefaultNoteSkin ) + AddTo.insert( AddTo.begin(), GAME_BASE_NOTESKIN_NAME ); + } +} + + +bool NoteSkinManager::DoesNoteSkinExist( const RString &sSkinName ) +{ + vector asSkinNames; + GetAllNoteSkinNamesForGame( GAMESTATE->m_pCurGame, asSkinNames ); + for( unsigned i=0; i asSkinNames; + GetAllNoteSkinNamesForGame( pGame, asSkinNames ); + return !asSkinNames.empty(); +} + +RString NoteSkinManager::GetNoteSkinDir( const RString &sSkinName ) +{ + RString sGame = m_pCurGame->m_szName; + + return NOTESKINS_DIR + sGame + "/" + sSkinName + "/"; +} + +void NoteSkinManager::GetAllNoteSkinNamesForGame( const Game *pGame, vector &AddTo ) { if( pGame == m_pCurGame ) { /* Faster: */ for( map::const_iterator iter = m_mapNameToData.begin(); - iter != m_mapNameToData.end(); ++iter ) + iter != m_mapNameToData.end(); ++iter ) { AddTo.push_back( iter->second.sName ); } @@ -118,36 +157,7 @@ void NoteSkinManager::GetNoteSkinNames( const Game* pGame, vector &AddT GetDirListing( sBaseSkinFolder + "*", AddTo, true ); StripCvs( AddTo ); } - - /* Move "default" to the front if it exists. */ - { - vector::iterator iter = find( AddTo.begin(), AddTo.end(), "default" ); - if( iter != AddTo.end() ) - { - AddTo.erase( iter ); - if( !bFilterDefault || !PREFSMAN->m_bHideDefaultNoteSkin ) - AddTo.insert( AddTo.begin(), "default" ); - } - } -} - - -bool NoteSkinManager::DoesNoteSkinExist( const RString &sSkinName ) -{ - vector asSkinNames; - GetNoteSkinNames( asSkinNames ); - for( unsigned i=0; im_szName; - - return NOTESKINS_DIR + sGame + "/" + sSkinName + "/"; -} +} RString NoteSkinManager::GetMetric( const RString &sButtonName, const RString &sValue ) { diff --git a/stepmania/src/NoteSkinManager.h b/stepmania/src/NoteSkinManager.h index 142a6d245a..e522cd0b5d 100644 --- a/stepmania/src/NoteSkinManager.h +++ b/stepmania/src/NoteSkinManager.h @@ -7,6 +7,7 @@ #include "RageTypes.h" #include "PlayerNumber.h" #include "IniFile.h" +#include "ThemeMetric.h" #include #include @@ -22,6 +23,7 @@ public: void GetNoteSkinNames( const Game* game, vector &AddTo, bool bFilterDefault=true ); void GetNoteSkinNames( vector &AddTo ); // looks up current const Game* in GAMESTATE bool DoesNoteSkinExist( const RString &sNoteSkin ); // looks up current const Game* in GAMESTATE + bool DoNoteSkinsExistForGame( const Game *pGame ); void SetCurrentNoteSkin( const RString &sNoteSkin ) { m_sCurrentNoteSkin = sNoteSkin; } const RString &GetCurrentNoteSkin() { return m_sCurrentNoteSkin; } @@ -29,10 +31,11 @@ public: RString GetPath( const RString &sButtonName, const RString &sElement ); RString GetMetric( const RString &sButtonName, const RString &sValue ); - int GetMetricI( const RString &sButtonName, const RString &sValueName ); + int GetMetricI( const RString &sButtonName, const RString &sValueName ); float GetMetricF( const RString &sButtonName, const RString &sValueName ); bool GetMetricB( const RString &sButtonName, const RString &sValueName ); - apActorCommands GetMetricA( const RString &sButtonName, const RString &sValueName ); + apActorCommands GetMetricA( const RString &sButtonName, const RString &sValueName ); + ThemeMetric GAME_BASE_NOTESKIN_NAME; // Lua void PushSelf( lua_State *L ); @@ -40,6 +43,7 @@ public: protected: RString GetNoteSkinDir( const RString &sSkinName ); RString GetPathFromDirAndFile( const RString &sDir, const RString &sFileName ); + void GetAllNoteSkinNamesForGame( const Game *pGame, vector &AddTo ); struct NoteSkinData {