From ca3684b232226fecf051e87bb176a29cdab32130 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Thu, 24 Feb 2005 06:10:11 +0000 Subject: [PATCH] cleanup, fix offset vbSelected values when using NextRow choice at the front --- stepmania/src/OptionRowHandler.cpp | 124 +++++++++++++++++++++++++- stepmania/src/OptionRowHandler.h | 91 +------------------ stepmania/src/ScreenOptionsMaster.cpp | 94 +++++++++---------- 3 files changed, 164 insertions(+), 145 deletions(-) diff --git a/stepmania/src/OptionRowHandler.cpp b/stepmania/src/OptionRowHandler.cpp index 1fa0f87045..220666b4cf 100644 --- a/stepmania/src/OptionRowHandler.cpp +++ b/stepmania/src/OptionRowHandler.cpp @@ -39,6 +39,101 @@ static int GetOneSelection( const vector &vbSelected ) } +class OptionRowHandlerList : public OptionRowHandler +{ +public: + vector ListEntries; + GameCommand Default; + bool m_bUseModNameForIcon; + + OptionRowHandlerList::OptionRowHandlerList() { Init(); } + virtual void Init() + { + OptionRowHandler::Init(); + ListEntries.clear(); + Default.Init(); + m_bUseModNameForIcon = false; + } + virtual void ImportOption( const OptionRowDefinition &row, PlayerNumber pn, vector &vbSelectedOut ) const; + virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector &vbSelected ) const; + virtual CString GetIconText( const OptionRowDefinition &def, int iFirstSelection ) const + { + return m_bUseModNameForIcon ? + ListEntries[iFirstSelection].m_sModifiers : + def.choices[iFirstSelection]; + } + virtual CString GetAndEraseScreen( int iChoice ) + { + GameCommand &mc = ListEntries[iChoice]; + if( mc.m_sScreen != "" ) + { + /* Hack: instead of applying screen commands here, store them in + * m_sNextScreen and apply them after we tween out. If we don't set + * m_sScreen to "", we'll load it twice (once for each player) and + * then again for m_sNextScreen. */ + CString sNextScreen = mc.m_sScreen; + mc.m_sScreen = ""; + return sNextScreen; + } + return ""; + } +}; + +class OptionRowHandlerLua : public OptionRowHandler +{ +public: + LuaExpression *m_pLuaTable; + + OptionRowHandlerLua::OptionRowHandlerLua() { m_pLuaTable = NULL; Init(); } + void Init() + { + OptionRowHandler::Init(); + delete m_pLuaTable; + m_pLuaTable = new LuaExpression; + } + virtual void ImportOption( const OptionRowDefinition &row, PlayerNumber pn, vector &vbSelectedOut ) const; + virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector &vbSelected ) const; + virtual void Reload( OptionRowDefinition &defOut ); +}; + +class OptionRowHandlerConfig : public OptionRowHandler +{ +public: + const ConfOption *opt; + + OptionRowHandlerConfig::OptionRowHandlerConfig() { Init(); } + void Init() + { + OptionRowHandler::Init(); + opt = NULL; + } + virtual void ImportOption( const OptionRowDefinition &row, PlayerNumber pn, vector &vbSelectedOut ) const; + virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector &vbSelected ) const; +}; + + +namespace OptionRowHandlerUtil +{ + void FillList( OptionRowHandlerList* pHand, OptionRowDefinition &defOut, CString param ); + void FillLua( OptionRowHandlerLua* pHand, OptionRowDefinition &defOut, CString sLuaFunction ); + void FillSteps( OptionRowHandlerList* pHand, OptionRowDefinition &defOut ); + void FillConf( OptionRowHandlerConfig* pHand, OptionRowDefinition &defOut, CString param ); + void FillCharacters( OptionRowHandlerList* pHand, OptionRowDefinition &defOut ); + void FillStyles( OptionRowHandlerList* pHand, OptionRowDefinition &defOut ); + void FillGroups( OptionRowHandlerList* pHand, OptionRowDefinition &defOut ); + void FillDifficulties( OptionRowHandlerList* pHand, OptionRowDefinition &defOut ); + + inline OptionRowHandler* MakeList( OptionRowDefinition &defOut, CString param ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillList( pHand, defOut, param ); return pHand; } + inline OptionRowHandler* MakeLua( OptionRowDefinition &defOut, CString sLuaFunction ) { OptionRowHandlerLua *pHand = new OptionRowHandlerLua; FillLua( pHand, defOut, sLuaFunction ); return pHand; } + inline OptionRowHandler* MakeSteps( OptionRowDefinition &defOut ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillSteps( pHand, defOut ); return pHand; } + inline OptionRowHandler* MakeConf( OptionRowDefinition &defOut, CString param ) { OptionRowHandlerConfig *pHand = new OptionRowHandlerConfig; FillConf( pHand, defOut, param ); return pHand; } + inline OptionRowHandler* MakeCharacters( OptionRowDefinition &defOut ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillCharacters( pHand, defOut ); return pHand; } + inline OptionRowHandler* MakeStyles( OptionRowDefinition &defOut ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillStyles( pHand, defOut ); return pHand; } + inline OptionRowHandler* MakeGroups( OptionRowDefinition &defOut ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillGroups( pHand, defOut ); return pHand; } + inline OptionRowHandler* MakeDifficulties( OptionRowDefinition &defOut ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillDifficulties( pHand, defOut ); return pHand; } +} + + void OptionRowHandlerList::ImportOption( const OptionRowDefinition &row, PlayerNumber pn, vector &vbSelectedOut ) const { int FallbackOption = -1; @@ -194,9 +289,9 @@ int OptionRowHandlerLua::ExportOption( const OptionRowDefinition &def, PlayerNum return 0; } -void OptionRowHandlerLua::Reload( OptionRowDefinition &def ) +void OptionRowHandlerLua::Reload( OptionRowDefinition &defOut ) { - OptionRowHandlerUtil::FillLua( this, def, m_sName ); + OptionRowHandlerUtil::FillLua( this, defOut, m_sName ); } @@ -226,6 +321,8 @@ int OptionRowHandlerConfig::ExportOption( const OptionRowDefinition &def, Player return opt->GetEffects(); } +/////////////////////////////////////////////////////////////////////////////////// + /* Add the list named "ListName" to the given row/handler. */ void OptionRowHandlerUtil::FillList( OptionRowHandlerList* pHand, OptionRowDefinition &row, CString _ListName ) @@ -653,6 +750,29 @@ void OptionRowHandlerUtil::FillDifficulties( OptionRowHandlerList* pHand, Option } +OptionRowHandler* OptionRowHandlerUtil::Make( const Command &command, OptionRowDefinition &defOut ) +{ + OptionRowHandler* pHand = NULL; + + BeginHandleArgs; + + const CString &name = command.GetName(); + + if( name == "list" ) pHand = OptionRowHandlerUtil::MakeList( defOut, sArg(1) ); + else if( name == "lua" ) pHand = OptionRowHandlerUtil::MakeLua( defOut, sArg(1) ); + else if( name == "steps" ) pHand = OptionRowHandlerUtil::MakeSteps( defOut ); + else if( name == "conf" ) pHand = OptionRowHandlerUtil::MakeConf( defOut, sArg(1) ); + else if( name == "characters" ) pHand = OptionRowHandlerUtil::MakeCharacters( defOut ); + else if( name == "styles" ) pHand = OptionRowHandlerUtil::MakeStyles( defOut ); + else if( name == "groups" ) pHand = OptionRowHandlerUtil::MakeGroups( defOut ); + else if( name == "difficulties" ) pHand = OptionRowHandlerUtil::MakeDifficulties( defOut ); + + EndHandleArgs; + + return pHand; +} + + /* * (c) 2002-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/OptionRowHandler.h b/stepmania/src/OptionRowHandler.h index 8113b53ab8..309a5dcb04 100644 --- a/stepmania/src/OptionRowHandler.h +++ b/stepmania/src/OptionRowHandler.h @@ -26,102 +26,15 @@ public: virtual void ImportOption( const OptionRowDefinition &row, PlayerNumber pn, vector &vbSelectedOut ) const = 0; /* Returns an OPT mask. */ virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector &vbSelected ) const = 0; - virtual void Reload( OptionRowDefinition &def ) {} + virtual void Reload( OptionRowDefinition &defOut ) {} virtual CString GetIconText( const OptionRowDefinition &def, int iFirstSelection ) const { return ""; } virtual CString GetAndEraseScreen( int iChoice ) { return ""; } }; -class OptionRowHandlerList : public OptionRowHandler -{ -public: - vector ListEntries; - GameCommand Default; - bool m_bUseModNameForIcon; - - OptionRowHandlerList::OptionRowHandlerList() { Init(); } - virtual void Init() - { - OptionRowHandler::Init(); - ListEntries.clear(); - Default.Init(); - m_bUseModNameForIcon = false; - } - virtual void ImportOption( const OptionRowDefinition &row, PlayerNumber pn, vector &vbSelectedOut ) const; - virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector &vbSelected ) const; - virtual CString GetIconText( const OptionRowDefinition &def, int iFirstSelection ) const - { - return m_bUseModNameForIcon ? - ListEntries[iFirstSelection].m_sModifiers : - def.choices[iFirstSelection]; - } - virtual CString GetAndEraseScreen( int iChoice ) - { - GameCommand &mc = ListEntries[iChoice]; - if( mc.m_sScreen != "" ) - { - /* Hack: instead of applying screen commands here, store them in - * m_sNextScreen and apply them after we tween out. If we don't set - * m_sScreen to "", we'll load it twice (once for each player) and - * then again for m_sNextScreen. */ - CString sNextScreen = mc.m_sScreen; - mc.m_sScreen = ""; - return sNextScreen; - } - return ""; - } -}; - -class OptionRowHandlerLua : public OptionRowHandler -{ -public: - LuaExpression *m_pLuaTable; - - OptionRowHandlerLua::OptionRowHandlerLua() { m_pLuaTable = NULL; Init(); } - void Init() - { - OptionRowHandler::Init(); - delete m_pLuaTable; - m_pLuaTable = new LuaExpression; - } - virtual void ImportOption( const OptionRowDefinition &row, PlayerNumber pn, vector &vbSelectedOut ) const; - virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector &vbSelected ) const; - virtual void Reload( OptionRowDefinition &def ); -}; - -class OptionRowHandlerConfig : public OptionRowHandler -{ -public: - const ConfOption *opt; - - OptionRowHandlerConfig::OptionRowHandlerConfig() { Init(); } - void Init() - { - OptionRowHandler::Init(); - opt = NULL; - } - virtual void ImportOption( const OptionRowDefinition &row, PlayerNumber pn, vector &vbSelectedOut ) const; - virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector &vbSelected ) const; -}; namespace OptionRowHandlerUtil { - void FillList( OptionRowHandlerList* pHand, OptionRowDefinition &def, CString param ); - void FillLua( OptionRowHandlerLua* pHand, OptionRowDefinition &def, CString sLuaFunction ); - void FillSteps( OptionRowHandlerList* pHand, OptionRowDefinition &def ); - void FillConf( OptionRowHandlerConfig* pHand, OptionRowDefinition &def, CString param ); - void FillCharacters( OptionRowHandlerList* pHand, OptionRowDefinition &def ); - void FillStyles( OptionRowHandlerList* pHand, OptionRowDefinition &def ); - void FillGroups( OptionRowHandlerList* pHand, OptionRowDefinition &def ); - void FillDifficulties( OptionRowHandlerList* pHand, OptionRowDefinition &def ); - - inline OptionRowHandler* MakeList( OptionRowDefinition &def, CString param ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillList( pHand, def, param ); return pHand; } - inline OptionRowHandler* MakeLua( OptionRowDefinition &def, CString sLuaFunction ) { OptionRowHandlerLua *pHand = new OptionRowHandlerLua; FillLua( pHand, def, sLuaFunction ); return pHand; } - inline OptionRowHandler* MakeSteps( OptionRowDefinition &def ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillSteps( pHand, def ); return pHand; } - inline OptionRowHandler* MakeConf( OptionRowDefinition &def, CString param ) { OptionRowHandlerConfig *pHand = new OptionRowHandlerConfig; FillConf( pHand, def, param ); return pHand; } - inline OptionRowHandler* MakeCharacters( OptionRowDefinition &def ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillCharacters( pHand, def ); return pHand; } - inline OptionRowHandler* MakeStyles( OptionRowDefinition &def ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillStyles( pHand, def ); return pHand; } - inline OptionRowHandler* MakeGroups( OptionRowDefinition &def ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillGroups( pHand, def ); return pHand; } - inline OptionRowHandler* MakeDifficulties( OptionRowDefinition &def ) { OptionRowHandlerList *pHand = new OptionRowHandlerList; FillDifficulties( pHand, def ); return pHand; } + OptionRowHandler* Make( const Command &cmd, OptionRowDefinition &defOut ); } diff --git a/stepmania/src/ScreenOptionsMaster.cpp b/stepmania/src/ScreenOptionsMaster.cpp index 70697f3dab..95b266953f 100644 --- a/stepmania/src/ScreenOptionsMaster.cpp +++ b/stepmania/src/ScreenOptionsMaster.cpp @@ -82,45 +82,25 @@ void ScreenOptionsMaster::Init() for( unsigned i = 0; i < asLineNames.size(); ++i ) { CString sLineName = asLineNames[i]; - - OptionRowDefinition &row = m_OptionRowAlloc[i]; - + OptionRowDefinition &def = m_OptionRowAlloc[i]; CString sRowCommands = LINE(sLineName); + OptionRowHandler* &pHand = OptionRowHandlers[i]; + pHand = NULL; Commands vCommands; ParseCommands( sRowCommands, vCommands ); - - if( vCommands.v.size() < 1 ) + if( vCommands.v.size() != 1 ) RageException::Throw( "Parse error in %s::Line%i", m_sName.c_str(), i+1 ); - OptionRowHandler* &pHand = OptionRowHandlers[i]; - pHand = NULL; + Command& command = vCommands.v[0]; + pHand = OptionRowHandlerUtil::Make( command, def ); + if( pHand == NULL ) + RageException::Throw( "Invalid OptionRowHandler '%s' in %s::Line%i", command.GetOriginalCommandString().c_str(), m_sName.c_str(), i ); - for( unsigned c=0; cImportOption(def, PLAYER_1, row.m_vbSelected[0] ); + INSERT_ONE_BOOL_AT_FRONT_IF_NEEDED( row.m_vbSelected[0] ); } else { FOREACH_HumanPlayer( p ) + { + ERASE_ONE_BOOL_AT_FRONT_IF_NEEDED( row.m_vbSelected[p] ); pHand->ImportOption( def, p, row.m_vbSelected[p] ); - } - - if( m_OptionsNavigation == NAV_TOGGLE_THREE_KEY ) - { - if( def.bOneChoiceForAllPlayers ) - row.m_vbSelected[0].insert( row.m_vbSelected[0].begin(), false ); - else - FOREACH_HumanPlayer( p ) - row.m_vbSelected[p].insert( row.m_vbSelected[p].begin(), false ); + INSERT_ONE_BOOL_AT_FRONT_IF_NEEDED( row.m_vbSelected[p] ); + } } } @@ -226,11 +202,21 @@ void ScreenOptionsMaster::ExportOptions( int iRow ) const OptionRowHandler *pHand = OptionRowHandlers[iRow]; const OptionRowDefinition &def = m_OptionRowAlloc[iRow]; OptionRow &row = *m_Rows[iRow]; - FOREACH_HumanPlayer( pn ) - { - vector &vbSelected = row.m_vbSelected[pn]; - m_iChangeMask |= pHand->ExportOption( def, pn, vbSelected ); + if( def.bOneChoiceForAllPlayers ) + { + ERASE_ONE_BOOL_AT_FRONT_IF_NEEDED( row.m_vbSelected[0] ); + m_iChangeMask |= pHand->ExportOption( def, PLAYER_1, row.m_vbSelected[0] ); + INSERT_ONE_BOOL_AT_FRONT_IF_NEEDED( row.m_vbSelected[0] ); + } + else + { + FOREACH_HumanPlayer( p ) + { + ERASE_ONE_BOOL_AT_FRONT_IF_NEEDED( row.m_vbSelected[p] ); + m_iChangeMask |= pHand->ExportOption( def, p, row.m_vbSelected[p] ); + INSERT_ONE_BOOL_AT_FRONT_IF_NEEDED( row.m_vbSelected[p] ); + } } } @@ -282,7 +268,7 @@ void ScreenOptionsMaster::RefreshIcons() else if( iFirstSelection != -1 ) { const OptionRowHandler *pHand = OptionRowHandlers[i]; - sIcon = pHand->GetIconText( def, iFirstSelection ); + sIcon = pHand->GetIconText( def, iFirstSelection+(m_OptionsNavigation==NAV_TOGGLE_THREE_KEY?-1:0) ); }