From 32b83fbc00bd755ade07fb22d0a703e3ecfb0452 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 18 Jan 2006 03:18:03 +0000 Subject: [PATCH] move similar code together, in hopes of nudging them together later --- stepmania/src/OptionRowHandler.cpp | 326 ++++++++++++++--------------- 1 file changed, 163 insertions(+), 163 deletions(-) diff --git a/stepmania/src/OptionRowHandler.cpp b/stepmania/src/OptionRowHandler.cpp index 3c3e36e2c8..6771fc35ae 100644 --- a/stepmania/src/OptionRowHandler.cpp +++ b/stepmania/src/OptionRowHandler.cpp @@ -339,6 +339,169 @@ class OptionRowHandlerListSteps : public OptionRowHandlerList } }; +class OptionRowHandlerSteps : public OptionRowHandler +{ +public: + BroadcastOnChangePtr *m_ppStepsToFill; + BroadcastOnChange *m_pDifficultyToFill; + const BroadcastOnChange *m_pst; + vector m_vSteps; + vector m_vDifficulties; + + OptionRowHandlerSteps() { Init(); } + void Init() + { + OptionRowHandler::Init(); + m_ppStepsToFill = NULL; + m_pDifficultyToFill = NULL; + m_vSteps.clear(); + m_vDifficulties.clear(); + } + + virtual void LoadInternal( const Commands &cmds ) + { + ASSERT( cmds.v.size() == 1 ); + const Command &command = cmds.v[0]; + CString sParam = command.GetArg(1); + ASSERT( command.m_vsArgs.size() == 2 ); + ASSERT( sParam.size() ); + + if( sParam == "EditSteps" ) + { + m_ppStepsToFill = &GAMESTATE->m_pCurSteps[0]; + m_pDifficultyToFill = &GAMESTATE->m_PreferredDifficulty[0]; + m_pst = &GAMESTATE->m_stEdit; + m_vsReloadRowMessages.push_back( MessageToString(Message_EditStepsTypeChanged) ); + } + else if( sParam == "EditSourceSteps" ) + { + m_ppStepsToFill = &GAMESTATE->m_pEditSourceSteps; + m_pst = &GAMESTATE->m_stEditSource; + m_vsReloadRowMessages.push_back( MessageToString(Message_EditSourceStepsTypeChanged) ); + if( GAMESTATE->m_pCurSteps[0].Get() != NULL ) + m_Def.m_vEnabledForPlayers.clear(); // hide row + } + else + { + RageException::Throw( "invalid StepsType param \"%s\"", sParam.c_str() ); + } + + m_Def.m_sName = sParam; + m_Def.m_bOneChoiceForAllPlayers = true; + m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW; + m_Def.m_bExportOnChange = true; + m_Def.m_bAllowThemeItems = false; // we theme the text ourself + m_vsReloadRowMessages.push_back( MessageToString(Message_CurrentSongChanged) ); + + m_vDifficulties.clear(); + m_vSteps.clear(); + + if( GAMESTATE->m_pCurSong ) + { + FOREACH_Difficulty( dc ) + { + if( dc == DIFFICULTY_EDIT ) + continue; + m_vDifficulties.push_back( dc ); + Steps* pSteps = GAMESTATE->m_pCurSong->GetStepsByDifficulty( *m_pst, dc ); + m_vSteps.push_back( pSteps ); + } + GAMESTATE->m_pCurSong->GetSteps( m_vSteps, *m_pst, DIFFICULTY_EDIT ); + m_vDifficulties.resize( m_vSteps.size(), DIFFICULTY_EDIT ); + + if( sParam == "EditSteps" ) + { + m_vSteps.push_back( NULL ); + m_vDifficulties.push_back( DIFFICULTY_EDIT ); + } + + for( unsigned i=0; iGetDescription(); + else + s = "NewEdit"; + } + else + { + s = DifficultyToLocalizedString( dc ); + } + m_Def.m_vsChoices.push_back( s ); + } + } + else + { + m_vDifficulties.push_back( DIFFICULTY_EDIT ); + m_vSteps.push_back( NULL ); + m_Def.m_vsChoices.push_back( "none" ); + } + + if( m_pDifficultyToFill ) + m_pDifficultyToFill->Set( m_vDifficulties[0] ); + m_ppStepsToFill->Set( m_vSteps[0] ); + } + virtual void ImportOption( const OptionRowDefinition &def, const vector &vpns, vector vbSelectedOut[NUM_PLAYERS] ) const + { + FOREACH_CONST( PlayerNumber, vpns, pn ) + { + PlayerNumber p = *pn; + vector &vbSelOut = vbSelectedOut[p]; + + ASSERT( m_vSteps.size() == vbSelOut.size() ); + + // look for matching steps + vector::const_iterator iter = find( m_vSteps.begin(), m_vSteps.end(), m_ppStepsToFill->Get() ); + if( iter != m_vSteps.end() ) + { + unsigned i = iter - m_vSteps.begin(); + vbSelOut[i] = true; + return; + } + // look for matching difficulty + if( m_pDifficultyToFill ) + { + FOREACH_CONST( Difficulty, m_vDifficulties, d ) + { + unsigned i = d - m_vDifficulties.begin(); + if( *d == GAMESTATE->m_PreferredDifficulty[0] ) + { + vbSelOut[i] = true; + vector v; + v.push_back( p ); + ExportOption( def, v, vbSelectedOut ); // current steps changed + continue; + } + } + } + // default to 1st + vbSelOut[0] = true; + } + } + virtual int ExportOption( const OptionRowDefinition &def, const vector &vpns, const vector vbSelected[NUM_PLAYERS] ) const + { + FOREACH_CONST( PlayerNumber, vpns, pn ) + { + PlayerNumber p = *pn; + const vector &vbSel = vbSelected[p]; + + int index = OptionRowHandlerUtil::GetOneSelection( vbSel ); + Difficulty dc = m_vDifficulties[index]; + Steps *pSteps = m_vSteps[index]; + if( m_pDifficultyToFill ) + m_pDifficultyToFill->Set( dc ); + m_ppStepsToFill->Set( pSteps ); + } + + return 0; + } +}; + class OptionRowHandlerListCharacters: public OptionRowHandlerList { virtual void LoadInternal( const Commands &cmds ) @@ -967,169 +1130,6 @@ public: }; -class OptionRowHandlerSteps : public OptionRowHandler -{ -public: - BroadcastOnChangePtr *m_ppStepsToFill; - BroadcastOnChange *m_pDifficultyToFill; - const BroadcastOnChange *m_pst; - vector m_vSteps; - vector m_vDifficulties; - - OptionRowHandlerSteps() { Init(); } - void Init() - { - OptionRowHandler::Init(); - m_ppStepsToFill = NULL; - m_pDifficultyToFill = NULL; - m_vSteps.clear(); - m_vDifficulties.clear(); - } - - virtual void LoadInternal( const Commands &cmds ) - { - ASSERT( cmds.v.size() == 1 ); - const Command &command = cmds.v[0]; - CString sParam = command.GetArg(1); - ASSERT( command.m_vsArgs.size() == 2 ); - ASSERT( sParam.size() ); - - if( sParam == "EditSteps" ) - { - m_ppStepsToFill = &GAMESTATE->m_pCurSteps[0]; - m_pDifficultyToFill = &GAMESTATE->m_PreferredDifficulty[0]; - m_pst = &GAMESTATE->m_stEdit; - m_vsReloadRowMessages.push_back( MessageToString(Message_EditStepsTypeChanged) ); - } - else if( sParam == "EditSourceSteps" ) - { - m_ppStepsToFill = &GAMESTATE->m_pEditSourceSteps; - m_pst = &GAMESTATE->m_stEditSource; - m_vsReloadRowMessages.push_back( MessageToString(Message_EditSourceStepsTypeChanged) ); - if( GAMESTATE->m_pCurSteps[0].Get() != NULL ) - m_Def.m_vEnabledForPlayers.clear(); // hide row - } - else - { - RageException::Throw( "invalid StepsType param \"%s\"", sParam.c_str() ); - } - - m_Def.m_sName = sParam; - m_Def.m_bOneChoiceForAllPlayers = true; - m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW; - m_Def.m_bExportOnChange = true; - m_Def.m_bAllowThemeItems = false; // we theme the text ourself - m_vsReloadRowMessages.push_back( MessageToString(Message_CurrentSongChanged) ); - - m_vDifficulties.clear(); - m_vSteps.clear(); - - if( GAMESTATE->m_pCurSong ) - { - FOREACH_Difficulty( dc ) - { - if( dc == DIFFICULTY_EDIT ) - continue; - m_vDifficulties.push_back( dc ); - Steps* pSteps = GAMESTATE->m_pCurSong->GetStepsByDifficulty( *m_pst, dc ); - m_vSteps.push_back( pSteps ); - } - GAMESTATE->m_pCurSong->GetSteps( m_vSteps, *m_pst, DIFFICULTY_EDIT ); - m_vDifficulties.resize( m_vSteps.size(), DIFFICULTY_EDIT ); - - if( sParam == "EditSteps" ) - { - m_vSteps.push_back( NULL ); - m_vDifficulties.push_back( DIFFICULTY_EDIT ); - } - - for( unsigned i=0; iGetDescription(); - else - s = "NewEdit"; - } - else - { - s = DifficultyToLocalizedString( dc ); - } - m_Def.m_vsChoices.push_back( s ); - } - } - else - { - m_vDifficulties.push_back( DIFFICULTY_EDIT ); - m_vSteps.push_back( NULL ); - m_Def.m_vsChoices.push_back( "none" ); - } - - if( m_pDifficultyToFill ) - m_pDifficultyToFill->Set( m_vDifficulties[0] ); - m_ppStepsToFill->Set( m_vSteps[0] ); - } - virtual void ImportOption( const OptionRowDefinition &def, const vector &vpns, vector vbSelectedOut[NUM_PLAYERS] ) const - { - FOREACH_CONST( PlayerNumber, vpns, pn ) - { - PlayerNumber p = *pn; - vector &vbSelOut = vbSelectedOut[p]; - - ASSERT( m_vSteps.size() == vbSelOut.size() ); - - // look for matching steps - vector::const_iterator iter = find( m_vSteps.begin(), m_vSteps.end(), m_ppStepsToFill->Get() ); - if( iter != m_vSteps.end() ) - { - unsigned i = iter - m_vSteps.begin(); - vbSelOut[i] = true; - return; - } - // look for matching difficulty - if( m_pDifficultyToFill ) - { - FOREACH_CONST( Difficulty, m_vDifficulties, d ) - { - unsigned i = d - m_vDifficulties.begin(); - if( *d == GAMESTATE->m_PreferredDifficulty[0] ) - { - vbSelOut[i] = true; - vector v; - v.push_back( p ); - ExportOption( def, v, vbSelectedOut ); // current steps changed - continue; - } - } - } - // default to 1st - vbSelOut[0] = true; - } - } - virtual int ExportOption( const OptionRowDefinition &def, const vector &vpns, const vector vbSelected[NUM_PLAYERS] ) const - { - FOREACH_CONST( PlayerNumber, vpns, pn ) - { - PlayerNumber p = *pn; - const vector &vbSel = vbSelected[p]; - - int index = OptionRowHandlerUtil::GetOneSelection( vbSel ); - Difficulty dc = m_vDifficulties[index]; - Steps *pSteps = m_vSteps[index]; - if( m_pDifficultyToFill ) - m_pDifficultyToFill->Set( dc ); - m_ppStepsToFill->Set( pSteps ); - } - - return 0; - } -}; - class OptionRowHandlerGameCommand : public OptionRowHandler { public: