From 1f3b71f3b1131bd581099415fd748acac5a41fc3 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 18 Jan 2006 02:00:22 +0000 Subject: [PATCH] move SelectExactlyOne and GetOneSelection into a namespace --- stepmania/src/OptionRowHandler.cpp | 18 +++++++++--------- stepmania/src/OptionRowHandler.h | 3 +++ stepmania/src/ScreenOptionsEditCourseEntry.cpp | 13 +++---------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/stepmania/src/OptionRowHandler.cpp b/stepmania/src/OptionRowHandler.cpp index b57c754eb9..8ae12bc861 100644 --- a/stepmania/src/OptionRowHandler.cpp +++ b/stepmania/src/OptionRowHandler.cpp @@ -31,7 +31,7 @@ void OptionRowHandler::GetIconTextAndGameCommand( const OptionRowDefinition &def gcOut.Init(); } -static void SelectExactlyOne( int iSelection, vector &vbSelectedOut ) +void OptionRowHandlerUtil::SelectExactlyOne( int iSelection, vector &vbSelectedOut ) { ASSERT_M( iSelection >= 0 && iSelection < (int) vbSelectedOut.size(), ssprintf("%d/%u",iSelection, unsigned(vbSelectedOut.size())) ); @@ -39,7 +39,7 @@ static void SelectExactlyOne( int iSelection, vector &vbSelectedOut ) vbSelectedOut[i] = i==iSelection; } -static int GetOneSelection( const vector &vbSelected ) +int OptionRowHandlerUtil::GetOneSelection( const vector &vbSelected ) { int iRet = -1; for( unsigned i=0; i &vbSelOut = vbSelectedOut[p]; int iSelection = opt->Get(); - SelectExactlyOne( iSelection, vbSelOut ); + OptionRowHandlerUtil::SelectExactlyOne( iSelection, vbSelOut ); } } virtual int ExportOption( const OptionRowDefinition &def, const vector &vpns, const vector vbSelected[NUM_PLAYERS] ) const @@ -849,7 +849,7 @@ public: PlayerNumber p = *pn; const vector &vbSel = vbSelected[p]; - int sel = GetOneSelection(vbSel); + int sel = OptionRowHandlerUtil::GetOneSelection(vbSel); /* Get the original choice. */ int Original = opt->Get(); @@ -954,7 +954,7 @@ public: PlayerNumber p = *pn; const vector &vbSel = vbSelected[p]; - int index = GetOneSelection( vbSel ); + int index = OptionRowHandlerUtil::GetOneSelection( vbSel ); m_pstToFill->Set( m_vStepsTypesToShow[index] ); } @@ -1111,7 +1111,7 @@ public: PlayerNumber p = *pn; const vector &vbSel = vbSelected[p]; - int index = GetOneSelection( vbSel ); + int index = OptionRowHandlerUtil::GetOneSelection( vbSel ); Difficulty dc = m_vDifficulties[index]; Steps *pSteps = m_vSteps[index]; if( m_pDifficultyToFill ) diff --git a/stepmania/src/OptionRowHandler.h b/stepmania/src/OptionRowHandler.h index 76d3a29fd8..248416f4ec 100644 --- a/stepmania/src/OptionRowHandler.h +++ b/stepmania/src/OptionRowHandler.h @@ -57,6 +57,9 @@ namespace OptionRowHandlerUtil { OptionRowHandler* Make( const Commands &cmds ); OptionRowHandler* MakeNull(); + + void SelectExactlyOne( int iSelection, vector &vbSelectedOut ); + int GetOneSelection( const vector &vbSelected ); } inline void VerifySelected( SelectType st, const vector &vbSelected, const CString &sName ) diff --git a/stepmania/src/ScreenOptionsEditCourseEntry.cpp b/stepmania/src/ScreenOptionsEditCourseEntry.cpp index 2e31e9a74e..10503b8645 100644 --- a/stepmania/src/ScreenOptionsEditCourseEntry.cpp +++ b/stepmania/src/ScreenOptionsEditCourseEntry.cpp @@ -77,19 +77,12 @@ public: if( iter != m_vpDisplayedSongs.end() ) iChoice = iter - m_vpDisplayedSongs.begin(); FOREACH_PlayerNumber(pn) - vbSelectedOut[pn][iChoice] = true; + OptionRowHandlerUtil::SelectExactlyOne( iChoice, vbSelectedOut[pn] ); } virtual int ExportOption( const OptionRowDefinition &def, const vector &vpns, const vector vbSelected[NUM_PLAYERS] ) const { - for( size_t iChoice = 0; iChoice < vbSelected[PLAYER_1].size(); ++iChoice ) - { - if( vbSelected[PLAYER_1][iChoice] ) - { - GAMESTATE->m_pCurSong.Set( m_vpDisplayedSongs[iChoice] ); - return 0; - } - } - + int iChoice = OptionRowHandlerUtil::GetOneSelection( vbSelected[PLAYER_1] ); + GAMESTATE->m_pCurSong.Set( m_vpDisplayedSongs[iChoice] ); return 0; } };