From 0b063d96082d589a6783734252f378b682e8bc16 Mon Sep 17 00:00:00 2001 From: MinaciousGrace Date: Mon, 1 May 2017 01:48:33 -0400 Subject: [PATCH] always land on a song object (if available) during song search --- src/MusicWheel.cpp | 31 ++++++++++++++++++++++++++++--- src/MusicWheel.h | 2 ++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/MusicWheel.cpp b/src/MusicWheel.cpp index a70e6e3bcd..c5e2794e69 100644 --- a/src/MusicWheel.cpp +++ b/src/MusicWheel.cpp @@ -265,8 +265,8 @@ void MusicWheel::ReloadSongList(bool searching, RString findme) { int songIdxToPreserve = m_iSelection; // Remove the song from any sorting caches: - FOREACH_ENUM( SortOrder, so ) - m_WheelItemDatasStatus[so]=INVALID; + FOREACH_ENUM(SortOrder, so) + m_WheelItemDatasStatus[so] = INVALID; // rebuild the info associated with this sort order readyWheelItemsData(GAMESTATE->m_SortOrder, searching, findme); // re-open the section to refresh song counts, etc. @@ -275,7 +275,32 @@ void MusicWheel::ReloadSongList(bool searching, RString findme) m_iSelection = songIdxToPreserve; RebuildWheelItems(); // refresh the song preview - SCREENMAN->PostMessageToTopScreen( SM_SongChanged, 0 ); + SCREENMAN->PostMessageToTopScreen(SM_SongChanged, 0); + + // when searching, automatically land on the first search result available -mina & dadbearcop + if (findme != "") { + Song *pSong = GAMESTATE->m_pCurSong; + if (pSong) { + RString curSongTitle = pSong->GetDisplayMainTitle(); + if (GetSelectedSection() != NULL && curSongTitle != prevSongTitle) { + prevSongTitle = curSongTitle; + SelectSongAfterSearch(); + } + } + else { + SelectSongAfterSearch(); + } + } + else { + SetOpenSection(""); + } +} + +void MusicWheel::SelectSongAfterSearch() { + vector &from = getWheelItemsData(GAMESTATE->m_SortOrder); + SelectSection(from[0]->m_sText); + SetOpenSection(from[0]->m_sText); + ChangeMusic(1); } /* If a song or course is set in GAMESTATE and available, select it. Otherwise, choose the diff --git a/src/MusicWheel.h b/src/MusicWheel.h index e59d17b990..460b7ea802 100644 --- a/src/MusicWheel.h +++ b/src/MusicWheel.h @@ -115,6 +115,8 @@ class MusicWheel : public WheelBase void BuildWheelItemDatas( vector &arrayWheelItems, SortOrder so, bool searching, RString findme ); void FilterWheelItemDatas(vector& aUnFilteredDatas, vector& aFilteredData, SortOrder so); + void SelectSongAfterSearch(); + RString prevSongTitle; }; #endif