From 4f3022ea7909ca8a353bcc8c3a00e58426b47dca Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 4 Oct 2005 02:34:10 +0000 Subject: [PATCH] Make it possible to specify a null OptionOrder if you want a key to not have any function. Remove use of MAX_CHOICES --- stepmania/src/ScreenSelectMaster.cpp | 64 ++++++++++++++-------------- stepmania/src/ScreenSelectMaster.h | 2 +- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/stepmania/src/ScreenSelectMaster.cpp b/stepmania/src/ScreenSelectMaster.cpp index 0abcc05d65..c304cc218e 100644 --- a/stepmania/src/ScreenSelectMaster.cpp +++ b/stepmania/src/ScreenSelectMaster.cpp @@ -159,36 +159,14 @@ void ScreenSelectMaster::Init() // init m_Next order info FOREACH_MenuDir( dir ) { - /* Reasonable defaults: */ - for( unsigned c = 0; c < m_aGameCommands.size(); ++c ) - { - int add; - switch( dir ) - { - case MENU_DIR_UP: - case MENU_DIR_LEFT: add = -1; break; - default: add = +1; break; - } - - m_Next[dir][c] = c + add; - /* Always wrap around MENU_DIR_AUTO. */ - if( dir == MENU_DIR_AUTO || (bool)WRAP_CURSOR ) - wrap( m_Next[dir][c], m_aGameCommands.size() ); - else - m_Next[dir][c] = clamp( m_Next[dir][c], 0, (int)m_aGameCommands.size()-1 ); - } - const CString order = OPTION_ORDER.GetValue( dir ); vector parts; split( order, ",", parts, true ); - if( parts.size() == 0 ) - continue; - for( unsigned part = 0; part < parts.size(); ++part ) { unsigned from, to; - if( sscanf( parts[part], "%u:%u", &from, &to ) != 2 ) + if( sscanf( parts[part], "%d:%d", &from, &to ) != 2 ) { LOG->Warn( "%s::OptionOrder%s parse error", m_sName.c_str(), MenuDirToString(dir).c_str() ); continue; @@ -197,14 +175,33 @@ void ScreenSelectMaster::Init() --from; --to; - if( from >= m_aGameCommands.size() || - to >= m_aGameCommands.size() ) - { - LOG->Warn( "%s::OptionOrder%s out of range", m_sName.c_str(), MenuDirToString(dir).c_str() ); - continue; - } + m_mapCurrentChoiceToNextChoice[dir][from] = to; + } - m_Next[dir][from] = to; + if( m_mapCurrentChoiceToNextChoice[dir].empty() ) // Didn't specify any mappings + { + // Fill with reasonable defaults + for( unsigned c = 0; c < m_aGameCommands.size(); ++c ) + { + int add; + switch( dir ) + { + case MENU_DIR_UP: + case MENU_DIR_LEFT: + add = -1; + break; + default: + add = +1; + break; + } + + m_mapCurrentChoiceToNextChoice[dir][c] = c + add; + /* Always wrap around MENU_DIR_AUTO. */ + if( dir == MENU_DIR_AUTO || (bool)WRAP_CURSOR ) + wrap( m_mapCurrentChoiceToNextChoice[dir][c], m_aGameCommands.size() ); + else + m_mapCurrentChoiceToNextChoice[dir][c] = clamp( m_mapCurrentChoiceToNextChoice[dir][c], 0, (int)m_aGameCommands.size()-1 ); + } } } } @@ -396,8 +393,11 @@ bool ScreenSelectMaster::Move( PlayerNumber pn, MenuDir dir ) int iSwitchToIndex = m_iChoice[pn]; set seen; try_again: - iSwitchToIndex = m_Next[dir][iSwitchToIndex]; - if( iSwitchToIndex == -1 ) + map::const_iterator iter = m_mapCurrentChoiceToNextChoice[dir].find( iSwitchToIndex ); + if( iter != m_mapCurrentChoiceToNextChoice[dir].end() ) + iSwitchToIndex = iter->second; + + if( iSwitchToIndex < 0 || iSwitchToIndex >= m_aGameCommands.size() ) // out of choice range return false; // can't go that way if( seen.find(iSwitchToIndex) != seen.end() ) return false; // went full circle and none found diff --git a/stepmania/src/ScreenSelectMaster.h b/stepmania/src/ScreenSelectMaster.h index 5cf3d91720..96984b4d11 100644 --- a/stepmania/src/ScreenSelectMaster.h +++ b/stepmania/src/ScreenSelectMaster.h @@ -60,7 +60,7 @@ protected: ThemeMetric SCROLLER_SUBDIVISIONS; ThemeMetric DEFAULT_CHOICE; - int m_Next[NUM_MENU_DIRS][MAX_CHOICES]; + map m_mapCurrentChoiceToNextChoice[NUM_MENU_DIRS]; virtual int GetSelectionIndex( PlayerNumber pn ); virtual void UpdateSelectableChoices();