From ed097b0a5dc34f7875ba429f58829028ea2d1230 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 7 Dec 2004 02:47:21 +0000 Subject: [PATCH] cleanups (working on cleaner ConfOption/Preference integration) --- stepmania/src/ScreenOptionsMaster.cpp | 15 ++-- stepmania/src/ScreenOptionsMasterPrefs.cpp | 88 +++++++++++++--------- stepmania/src/ScreenOptionsMasterPrefs.h | 22 +++--- stepmania/src/ScreenTitleMenu.cpp | 3 +- 4 files changed, 76 insertions(+), 52 deletions(-) diff --git a/stepmania/src/ScreenOptionsMaster.cpp b/stepmania/src/ScreenOptionsMaster.cpp index 8127e378f1..ece7b4d44a 100644 --- a/stepmania/src/ScreenOptionsMaster.cpp +++ b/stepmania/src/ScreenOptionsMaster.cpp @@ -159,10 +159,13 @@ void ScreenOptionsMaster::SetConf( OptionRowData &row, OptionRowHandler &hand, C row.bOneChoiceForAllPlayers = true; hand.type = ROW_CONFIG; - hand.opt = ConfOption::Find( param ); - if( hand.opt == NULL ) + ConfOption *pConfOption = ConfOption::Find( param ); + if( pConfOption == NULL ) RageException::Throw( "Invalid Conf type \"%s\"", param.c_str() ); + pConfOption->UpdateAvailableOptions(); + + hand.opt = pConfOption; hand.opt->MakeOptionsList( row.choices ); row.name = hand.opt->name; @@ -370,7 +373,7 @@ void ScreenOptionsMaster::ImportOption( const OptionRowData &row, const OptionRo case ROW_CONFIG: { - int iSelection = hand.opt->Get( row.choices ); + int iSelection = hand.opt->Get(); SelectExactlyOne( iSelection+(m_OptionsNavigation==NAV_TOGGLE_THREE_KEY?1:0), vbSelectedOut ); return; } @@ -464,13 +467,13 @@ int ScreenOptionsMaster::ExportOption( const OptionRowData &row, const OptionRow int sel = GetOneSelection(vbSelected) - (m_OptionsNavigation==NAV_TOGGLE_THREE_KEY?1:0); /* Get the original choice. */ - int Original = hand.opt->Get( row.choices ); + int Original = hand.opt->Get(); /* Apply. */ - hand.opt->Put( sel, row.choices ); + hand.opt->Put( sel ); /* Get the new choice. */ - int New = hand.opt->Get( row.choices ); + int New = hand.opt->Get(); /* If it didn't change, don't return any side-effects. */ if( Original == New ) diff --git a/stepmania/src/ScreenOptionsMasterPrefs.cpp b/stepmania/src/ScreenOptionsMasterPrefs.cpp index 172a6bb531..6a6ea38ff1 100644 --- a/stepmania/src/ScreenOptionsMasterPrefs.cpp +++ b/stepmania/src/ScreenOptionsMasterPrefs.cpp @@ -76,7 +76,7 @@ static void MoveData( int &sel, bool &opt, bool ToSel ) } #define MOVE( name, opt ) \ - static void name( int &sel, bool ToSel, const CStringArray &choices ) \ + static void name( int &sel, bool ToSel, const ConfOption *pConfOption ) \ { \ MoveData( sel, opt, ToSel ); \ } @@ -94,8 +94,11 @@ static void GameChoices( CStringArray &out ) } } -static void GameSel( int &sel, bool ToSel, const CStringArray &choices ) +static void GameSel( int &sel, bool ToSel, const ConfOption *pConfOption ) { + CStringArray choices; + pConfOption->MakeOptionsList( choices ); + if( ToSel ) { const CString sCurGameName = GAMESTATE->m_pCurGame->m_szName; @@ -116,8 +119,11 @@ static void LanguageChoices( CStringArray &out ) THEME->GetLanguages( out ); } -static void Language( int &sel, bool ToSel, const CStringArray &choices ) +static void Language( int &sel, bool ToSel, const ConfOption *pConfOption ) { + CStringArray choices; + pConfOption->MakeOptionsList( choices ); + if( ToSel ) { sel = 0; @@ -137,8 +143,11 @@ static void ThemeChoices( CStringArray &out ) THEME->GetThemeNames( out ); } -static void Theme( int &sel, bool ToSel, const CStringArray &choices ) +static void Theme( int &sel, bool ToSel, const ConfOption *pConfOption ) { + CStringArray choices; + pConfOption->MakeOptionsList( choices ); + if( ToSel ) { sel = 0; @@ -158,8 +167,11 @@ static void AnnouncerChoices( CStringArray &out ) out.insert( out.begin(), "OFF" ); } -static void Announcer( int &sel, bool ToSel, const CStringArray &choices ) +static void Announcer( int &sel, bool ToSel, const ConfOption *pConfOption ) { + CStringArray choices; + pConfOption->MakeOptionsList( choices ); + if( ToSel ) { sel = 0; @@ -179,8 +191,11 @@ static void DefaultNoteSkinChoices( CStringArray &out ) out[i].MakeUpper(); } -static void DefaultNoteSkin( int &sel, bool ToSel, const CStringArray &choices ) +static void DefaultNoteSkin( int &sel, bool ToSel, const ConfOption *pConfOption ) { + CStringArray choices; + pConfOption->MakeOptionsList( choices ); + if( ToSel ) { PlayerOptions po; @@ -220,13 +235,13 @@ MOVE( ShowDanger, (bool&)PREFSMAN->m_bShowDanger ); MOVE( DancingCharacters, PREFSMAN->m_ShowDancingCharacters ); MOVE( BeginnerHelper, (bool&)PREFSMAN->m_bShowBeginnerHelper ); -static void BGBrightness( int &sel, bool ToSel, const CStringArray &choices ) +static void BGBrightness( int &sel, bool ToSel, const ConfOption *pConfOption ) { const float mapping[] = { 0.0f,0.1f,0.2f,0.3f,0.4f,0.5f,0.6f,0.7f,0.8f,0.9f,1.0f }; MoveMap( sel, (float&)PREFSMAN->m_fBGBrightness, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void NumBackgrounds( int &sel, bool ToSel, const CStringArray &choices ) +static void NumBackgrounds( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 5,10,15,20 }; MoveMap( sel, (int&)PREFSMAN->m_iNumBackgrounds, ToSel, mapping, ARRAYSIZE(mapping) ); @@ -239,7 +254,7 @@ MOVE( AutoPlay, (bool&)PREFSMAN->m_bAutoPlay ); MOVE( BackDelayed, (bool&)PREFSMAN->m_bDelayedBack ); MOVE( OptionsNavigation, (bool&)PREFSMAN->m_bArcadeOptionsNavigation ); -static void WheelSpeed( int &sel, bool ToSel, const CStringArray &choices ) +static void WheelSpeed( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 5, 10, 15, 25 }; MoveMap( sel, (int&)PREFSMAN->m_iMusicWheelSwitchSpeed, ToSel, mapping, ARRAYSIZE(mapping) ); @@ -257,25 +272,25 @@ MOVE( UnlockSystem, (bool&)PREFSMAN->m_bUseUnlockSystem ); /* Coin options */ MOVE( CoinMode, PREFSMAN->m_iCoinMode ); -static void CoinModeNoHome( int &sel, bool ToSel, const CStringArray &choices ) +static void CoinModeNoHome( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 1,2 }; MoveMap( sel, (int&)PREFSMAN->m_iCoinMode, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void CoinsPerCredit( int &sel, bool ToSel, const CStringArray &choices ) +static void CoinsPerCredit( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 1,2,3,4,5,6,7,8 }; MoveMap( sel, (int&)PREFSMAN->m_iCoinsPerCredit, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void Premium( int &sel, bool ToSel, const CStringArray &choices ) +static void Premium( int &sel, bool ToSel, const ConfOption *pConfOption ) { const PrefsManager::Premium mapping[] = { PrefsManager::NO_PREMIUM,PrefsManager::DOUBLES_PREMIUM,PrefsManager::JOINT_PREMIUM }; MoveMap( sel, PREFSMAN->m_Premium, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void SongsPerPlay( int &sel, bool ToSel, const CStringArray &choices ) +static void SongsPerPlay( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 1,2,3,4,5,6,7 }; MoveMap( sel, (int&)PREFSMAN->m_iNumArcadeStages, ToSel, mapping, ARRAYSIZE(mapping) ); @@ -286,31 +301,31 @@ MOVE( EventMode, (bool&)PREFSMAN->m_bEventMode ); MOVE( MenuTimer, (bool&)PREFSMAN->m_bMenuTimer ); MOVE( ScoringType, PREFSMAN->m_iScoringType ); -static void JudgeDifficulty( int &sel, bool ToSel, const CStringArray &choices ) +static void JudgeDifficulty( int &sel, bool ToSel, const ConfOption *pConfOption ) { const float mapping[] = { 1.50f,1.33f,1.16f,1.00f,0.84f,0.66f,0.50f,0.33f,0.20f }; MoveMap( sel, (float&)PREFSMAN->m_fJudgeWindowScale, ToSel, mapping, ARRAYSIZE(mapping) ); } -void LifeDifficulty( int &sel, bool ToSel, const CStringArray &choices ) +void LifeDifficulty( int &sel, bool ToSel, const ConfOption *pConfOption ) { const float mapping[] = { 1.60f,1.40f,1.20f,1.00f,0.80f,0.60f,0.40f }; MoveMap( sel, (float&)PREFSMAN->m_fLifeDifficultyScale, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void ShowSongOptions( int &sel, bool ToSel, const CStringArray &choices ) +static void ShowSongOptions( int &sel, bool ToSel, const ConfOption *pConfOption ) { const PrefsManager::Maybe mapping[] = { PrefsManager::NO,PrefsManager::YES,PrefsManager::ASK }; MoveMap( sel, PREFSMAN->m_ShowSongOptions, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void ShowNameEntry( int &sel, bool ToSel, const CStringArray &choices ) +static void ShowNameEntry( int &sel, bool ToSel, const ConfOption *pConfOption ) { const PrefsManager::GetRankingName mapping[] = { PrefsManager::RANKING_OFF, PrefsManager::RANKING_ON, PrefsManager::RANKING_LIST }; MoveMap( sel, PREFSMAN->m_iGetRankingName, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void DefaultFailType( int &sel, bool ToSel, const CStringArray &choices ) +static void DefaultFailType( int &sel, bool ToSel, const ConfOption *pConfOption ) { if( ToSel ) { @@ -367,7 +382,7 @@ struct res_t } }; -static void DisplayResolution( int &sel, bool ToSel, const CStringArray &choices ) +static void DisplayResolution( int &sel, bool ToSel, const ConfOption *pConfOption ) { const res_t mapping[] = { @@ -389,31 +404,31 @@ static void DisplayResolution( int &sel, bool ToSel, const CStringArray &choices } } -static void DisplayColor( int &sel, bool ToSel, const CStringArray &choices ) +static void DisplayColor( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 16,32 }; MoveMap( sel, (int&)PREFSMAN->m_iDisplayColorDepth, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void TextureResolution( int &sel, bool ToSel, const CStringArray &choices ) +static void TextureResolution( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 256,512,1024,2048 }; MoveMap( sel, (int&)PREFSMAN->m_iMaxTextureResolution, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void TextureColor( int &sel, bool ToSel, const CStringArray &choices ) +static void TextureColor( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 16,32 }; MoveMap( sel, (int&)PREFSMAN->m_iTextureColorDepth, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void MovieColor( int &sel, bool ToSel, const CStringArray &choices ) +static void MovieColor( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { 16,32 }; MoveMap( sel, (int&)PREFSMAN->m_iMovieColorDepth, ToSel, mapping, ARRAYSIZE(mapping) ); } -static void RefreshRate( int &sel, bool ToSel, const CStringArray &choices ) +static void RefreshRate( int &sel, bool ToSel, const ConfOption *pConfOption ) { const int mapping[] = { (int) REFRESH_DEFAULT,60,70,72,75,80,85,90,100,120,150 }; MoveMap( sel, (int&)PREFSMAN->m_iRefreshRate, ToSel, mapping, ARRAYSIZE(mapping) ); @@ -423,14 +438,14 @@ static void RefreshRate( int &sel, bool ToSel, const CStringArray &choices ) MOVE( ResamplingQuality, PREFSMAN->m_iSoundResampleQuality ); MOVE( AttractSoundFrequency,PREFSMAN->m_iAttractSoundFrequency ); -static void SoundVolume( int &sel, bool ToSel, const CStringArray &choices ) +static void SoundVolume( int &sel, bool ToSel, const ConfOption *pConfOption ) { const float mapping[] = { 0.0f,0.1f,0.2f,0.3f,0.4f,0.5f,0.6f,0.7f,0.8f,0.9f,1.0f }; MoveMap( sel, (float&)PREFSMAN->m_fSoundVolume, ToSel, mapping, ARRAYSIZE(mapping) ); } -static const ConfOption g_ConfOptions[] = +static ConfOption g_ConfOptions[] = { /* Select game */ ConfOption( "Game", GameSel, GameChoices ), @@ -552,11 +567,11 @@ int ConfOption::GetEffects() const return ret; } -const ConfOption *ConfOption::Find( CString name ) +ConfOption *ConfOption::Find( CString name ) { for( unsigned i = 0; g_ConfOptions[i].name != ""; ++i ) { - const ConfOption *opt = &g_ConfOptions[i]; + ConfOption *opt = &g_ConfOptions[i]; CString match(opt->name); match.Replace("\n", ""); @@ -572,15 +587,18 @@ const ConfOption *ConfOption::Find( CString name ) return NULL; } +void ConfOption::UpdateAvailableOptions() +{ + if( MakeOptionsListCB != NULL ) + { + names.clear(); + MakeOptionsListCB( names ); + } +} + void ConfOption::MakeOptionsList( CStringArray &out ) const { - if( MakeOptionsListCB == NULL ) - { - out = names; - return; - } - - MakeOptionsListCB( out ); + out = names; } /* diff --git a/stepmania/src/ScreenOptionsMasterPrefs.h b/stepmania/src/ScreenOptionsMasterPrefs.h index b0813b8ae9..09f05c6ecd 100644 --- a/stepmania/src/ScreenOptionsMasterPrefs.h +++ b/stepmania/src/ScreenOptionsMasterPrefs.h @@ -11,23 +11,27 @@ static const int MAX_OPTIONS=16; struct ConfOption { - static const ConfOption *Find( CString name ); + static ConfOption *Find( CString name ); /* Name of this option. It's helpful to delimit this with newlines, as it'll * be the default display title. */ CString name; - typedef void (*MoveData_t)( int &sel, bool ToSel, const CStringArray &choices ); + typedef void (*MoveData_t)( int &sel, bool ToSel, const ConfOption *pConfOption ); MoveData_t MoveData; - /* If MakeOptionsListCB is set, it'll be called by MakeOptionsList; otherwise - * the contents of names is returned. */ + /* For dynamic options, update the options. Since this changes the available + * options, this may invalidate the offsets returned by Get() and Put(). */ + void UpdateAvailableOptions(); + + /* Return the list of available selections; Get() and Put() use indexes into this + * array. UpdateAvailableOptions() should be called before using this. */ void MakeOptionsList( CStringArray &out ) const; - inline int Get( const CStringArray &choices ) const { int sel; MoveData( sel, true, choices ); return sel; } - inline void Put( int sel, const CStringArray &choices ) const { MoveData( sel, false, choices ); } + inline int Get() const { int sel; MoveData( sel, true, this ); return sel; } + inline void Put( int sel ) const { MoveData( sel, false, this ); } int GetEffects() const; - ConfOption( const char *n, void (*m)( int &sel, bool in, const CStringArray &choices ), + ConfOption( const char *n, MoveData_t m, const char *c0=NULL, const char *c1=NULL, const char *c2=NULL, const char *c3=NULL, const char *c4=NULL, const char *c5=NULL, const char *c6=NULL, const char *c7=NULL, const char *c8=NULL, const char *c9=NULL, const char *c10=NULL, const char *c11=NULL, const char *c12=NULL, const char *c13=NULL, const char *c14=NULL, const char *c15=NULL, const char *c16=NULL, const char *c17=NULL, const char *c18=NULL, const char *c19=NULL ) { name = n; @@ -38,7 +42,7 @@ struct ConfOption #undef PUSH } - ConfOption( const char *n, void (*m)( int &sel, bool in, const CStringArray &choices ), + ConfOption( const char *n, MoveData_t m, void (*lst)( CStringArray &out ) ) { name = n; @@ -54,7 +58,7 @@ private: // HACK: This is used by ScreenTitleMenu -void LifeDifficulty( int &sel, bool ToSel, const CStringArray &choices ); +void LifeDifficulty( int &sel, bool ToSel, const ConfOption *pConfOption ); #endif diff --git a/stepmania/src/ScreenTitleMenu.cpp b/stepmania/src/ScreenTitleMenu.cpp index 24c55f7910..15e29dceb2 100644 --- a/stepmania/src/ScreenTitleMenu.cpp +++ b/stepmania/src/ScreenTitleMenu.cpp @@ -122,8 +122,7 @@ ScreenTitleMenu::ScreenTitleMenu( CString sClassName ) : ScreenSelect( sClassNam m_textLifeDifficulty.LoadFromFont( THEME->GetPathF(m_sName,"LifeDifficulty") ); m_textLifeDifficulty.RunCommands( LIFE_DIFFICULTY_ON_COMMAND ); int iLifeDifficulty; - const CStringArray dummy; - LifeDifficulty( iLifeDifficulty, true, dummy ); + LifeDifficulty( iLifeDifficulty, true, NULL ); iLifeDifficulty++; // LifeDifficulty returns an index m_textLifeDifficulty.SetText( ssprintf( "life difficulty %d", iLifeDifficulty ) ); this->AddChild( &m_textLifeDifficulty );