From ae2f4060f58bc1087e32ac889b2aa7f8468aab1f Mon Sep 17 00:00:00 2001 From: "D.J. Rideout" Date: Sat, 18 Jan 2025 18:51:33 -0330 Subject: [PATCH] If sort order is SORT_METER, select the highest difficulty matching the meter of the current section when scrolling to a song. --- src/ScreenSelectMusic.cpp | 98 ++++++++++++++++++++++++++++++++++++++- src/ScreenSelectMusic.h | 1 + 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/src/ScreenSelectMusic.cpp b/src/ScreenSelectMusic.cpp index 76fb8e1b37..88402052db 100644 --- a/src/ScreenSelectMusic.cpp +++ b/src/ScreenSelectMusic.cpp @@ -1627,6 +1627,88 @@ void ScreenSelectMusic::AfterStepsOrTrailChange( const std::vector } } +void ScreenSelectMusic::SwitchToDifficulty(Difficulty d) +{ + if (!GAMESTATE->m_pCurCourse) + { + FOREACH_HumanPlayer(pn) + { + // Find the closest match to the given difficulty and StepsType. + int iCurDifference = -1; + int& iSelection = m_iSelection[pn]; + int i = 0; + for (Steps* s : m_vpSteps) + { + // If the current steps are listed, use them. + if (GAMESTATE->m_pCurSteps[pn] == s) + { + iSelection = i; + break; + } + + if (d != Difficulty_Invalid) + { + int iDifficultyDifference = std::abs(s->GetDifficulty() - d); + int iStepsTypeDifference = 0; + if (GAMESTATE->m_PreferredStepsType != StepsType_Invalid) + iStepsTypeDifference = std::abs(s->m_StepsType - GAMESTATE->m_PreferredStepsType); + int iTotalDifference = iStepsTypeDifference * NUM_Difficulty + iDifficultyDifference; + + if (iCurDifference == -1 || iTotalDifference < iCurDifference) + { + iSelection = i; + iCurDifference = iTotalDifference; + } + } + i += 1; + } + + CLAMP(iSelection, 0, m_vpSteps.size() - 1); + } + } + else + { + FOREACH_HumanPlayer(pn) + { + // Find the closest match to the given difficulty. + int iCurDifference = -1; + int& iSelection = m_iSelection[pn]; + int i = 0; + for (Trail* t : m_vpTrails) + { + // If the current trail is listed, use it. + if (GAMESTATE->m_pCurTrail[pn] == m_vpTrails[i]) + { + iSelection = i; + break; + } + + if (d != Difficulty_Invalid && GAMESTATE->m_PreferredStepsType != StepsType_Invalid) + { + int iDifficultyDifference = std::abs(t->m_CourseDifficulty - d); + int iStepsTypeDifference = std::abs(t->m_StepsType - GAMESTATE->m_PreferredStepsType); + int iTotalDifference = iStepsTypeDifference * NUM_CourseDifficulty + iDifficultyDifference; + + if (iCurDifference == -1 || iTotalDifference < iCurDifference) + { + iSelection = i; + iCurDifference = iTotalDifference; + } + } + i += 1; + } + + CLAMP(iSelection, 0, m_vpTrails.size() - 1); + } + } + + if (GAMESTATE->DifficultiesLocked()) + { + FOREACH_HumanPlayer(p) + m_iSelection[p] = m_iSelection[GAMESTATE->GetMasterPlayerNumber()]; + } +} + void ScreenSelectMusic::SwitchToPreferredDifficulty() { if( !GAMESTATE->m_pCurCourse ) @@ -1882,7 +1964,21 @@ void ScreenSelectMusic::AfterMusicChange() g_sCDTitlePath = pSong->GetCDTitlePath(); g_bWantFallbackCdTitle = true; - SwitchToPreferredDifficulty(); + if (GAMESTATE->m_SortOrder == SORT_METER) + { + for (int i = m_vpSteps.size() - 1; i >= 0; i--) + { + if (m_vpSteps[i]->GetMeter() == StringToInt(GAMESTATE->sLastOpenSection)) + { + SwitchToDifficulty(m_vpSteps[i]->GetDifficulty()); + break; + } + } + } + else + { + SwitchToPreferredDifficulty(); + } break; case WheelItemDataType_Course: diff --git a/src/ScreenSelectMusic.h b/src/ScreenSelectMusic.h index 1e2fb2606c..81566f5e68 100644 --- a/src/ScreenSelectMusic.h +++ b/src/ScreenSelectMusic.h @@ -65,6 +65,7 @@ protected: void ChangeSteps( PlayerNumber pn, int dir ); void AfterStepsOrTrailChange( const std::vector &vpns ); + void SwitchToDifficulty(Difficulty d); void SwitchToPreferredDifficulty(); void AfterMusicChange();