diff --git a/stepmania/src/DifficultyList.cpp b/stepmania/src/DifficultyList.cpp index 2dd17a3d12..b6a48fb565 100644 --- a/stepmania/src/DifficultyList.cpp +++ b/stepmania/src/DifficultyList.cpp @@ -70,13 +70,15 @@ void DifficultyList::Load() int DifficultyList::GetCurrentRowIndex( PlayerNumber pn ) const { + Difficulty ClosestDifficulty = GAMESTATE->GetClosestShownDifficulty(pn); + for( unsigned i=0; im_pCurSteps[pn] == NULL ) { - if( row.m_dc == GAMESTATE->m_PreferredDifficulty[pn] ) + if( row.m_dc == ClosestDifficulty ) return i; } else diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index f2f0394e78..2953f15d27 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1599,11 +1599,14 @@ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc ) return true; } +/* When only displaying difficulties in DIFFICULTIES_TO_SHOW, use GetClosestShownDifficulty + * to find which difficulty to show, and ChangePreferredDifficulty(pn, dir) to change + * difficulty. */ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir ) { const vector &v = CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(); - Difficulty d = m_PreferredDifficulty[pn]; + Difficulty d = GAMESTATE->GetClosestShownDifficulty(pn); while( 1 ) { d = (Difficulty)(d+dir); @@ -1616,6 +1619,28 @@ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir ) return ChangePreferredDifficulty( pn, d ); } +/* The user may be set to prefer a difficulty that isn't always shown; typically, + * DIFFICULTY_EDIT. Return the closest shown difficulty <= m_PreferredDifficulty. */ +Difficulty GameState::GetClosestShownDifficulty( PlayerNumber pn ) const +{ + const vector &v = CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(); + + Difficulty iClosest = (Difficulty) 0; + int iClosestDist = -1; + FOREACH_CONST( Difficulty, v, dc ) + { + int iDist = m_PreferredDifficulty[pn] - *dc; + if( iDist < 0 ) + continue; + if( iClosestDist != -1 && iDist > iClosestDist ) + continue; + iClosestDist = iDist; + iClosest = *dc; + } + + return iClosest; +} + bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, CourseDifficulty cd ) { m_PreferredCourseDifficulty[pn].Set( cd ); diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 2b66990d95..8117718a50 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -67,6 +67,7 @@ public: bool ChangePreferredCourseDifficulty( PlayerNumber pn, CourseDifficulty cd ); bool ChangePreferredCourseDifficulty( PlayerNumber pn, int dir ); bool IsCourseDifficultyShown( CourseDifficulty cd ); + Difficulty GetClosestShownDifficulty( PlayerNumber pn ) const; Difficulty GetEasiestStepsDifficulty() const; RageTimer m_timeGameStarted; // from the moment the first player pressed Start LuaTable *m_Environment;