From 6201e1ab94103c83ca05b8c509009ec7105bface Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Mon, 24 Feb 2025 18:36:21 -0500 Subject: [PATCH] Add Recently Played and Most Played per Profile as sorts --- src/Banner.cpp | 2 +- src/GameConstantsAndTypes.cpp | 4 ++++ src/GameConstantsAndTypes.h | 4 ++++ src/MusicWheel.cpp | 35 ++++++++++++++++++++++++++++++++++- src/SongUtil.cpp | 17 +++++++++++++++++ src/SongUtil.h | 1 + 6 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/Banner.cpp b/src/Banner.cpp index ced12ba5c0..ea02866191 100644 --- a/src/Banner.cpp +++ b/src/Banner.cpp @@ -234,7 +234,7 @@ void Banner::LoadFromSortOrder( SortOrder so ) } else { - if( so != SORT_GROUP && so != SORT_RECENT ) + if( so != SORT_GROUP && so != SORT_RECENT && so != SORT_RECENT_P1 && so != SORT_RECENT_P2 ) Load( THEME->GetPathG("Banner",ssprintf("%s",SortOrderToString(so).c_str())) ); } m_bScrolling = (bool)SCROLL_SORT_ORDER; diff --git a/src/GameConstantsAndTypes.cpp b/src/GameConstantsAndTypes.cpp index 0a43ea78f2..82e6683221 100644 --- a/src/GameConstantsAndTypes.cpp +++ b/src/GameConstantsAndTypes.cpp @@ -163,6 +163,8 @@ static const char *SortOrderNames[] = { "Title", "BPM", "Popularity", + "PopularityP1", + "PopularityP2", "TopGrades", "TopP1Grades", "TopP2Grades", @@ -186,6 +188,8 @@ static const char *SortOrderNames[] = { "Length", "Roulette", "Recent", + "RecentP1", + "RecentP2", }; XToString( SortOrder ); StringToX( SortOrder ); diff --git a/src/GameConstantsAndTypes.h b/src/GameConstantsAndTypes.h index f2f48505be..18eda2dedd 100644 --- a/src/GameConstantsAndTypes.h +++ b/src/GameConstantsAndTypes.h @@ -167,6 +167,8 @@ enum SortOrder SORT_TITLE, /**< Sort by the Song's title. */ SORT_BPM, /**< Sort by the Song's BPM. */ SORT_POPULARITY, /**< Sort by how popular the Song is. */ + SORT_POPULARITY_P1, /**< Sort by how popular the Song is for P1. */ + SORT_POPULARITY_P2, /**< Sort by how popular the Song is for P2. */ SORT_TOP_GRADES, /**< Sort by the highest grades earned on a Song. */ SORT_TOP_GRADES_P1, /**< Sort by the highest grades earned on a Song for P1. */ SORT_TOP_GRADES_P2, /**< Sort by the highest grades earned on a Song for P2. */ @@ -192,6 +194,8 @@ enum SortOrder SORT_LENGTH, /**< Sort the songs/courses by how long they would last. */ SORT_ROULETTE, SORT_RECENT, + SORT_RECENT_P1, /**< Sort by the most recent play for P1. */ + SORT_RECENT_P2, /**< Sort by the most recent play for P2. */ NUM_SortOrder, SortOrder_Invalid }; diff --git a/src/MusicWheel.cpp b/src/MusicWheel.cpp index a960c3f4a3..a8744e5ced 100644 --- a/src/MusicWheel.cpp +++ b/src/MusicWheel.cpp @@ -562,6 +562,8 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh case SORT_TITLE: case SORT_BPM: case SORT_POPULARITY: + case SORT_POPULARITY_P1: + case SORT_POPULARITY_P2: case SORT_TOP_GRADES: case SORT_TOP_GRADES_P1: case SORT_TOP_GRADES_P2: @@ -578,6 +580,8 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh case SORT_DOUBLE_CHALLENGE_METER: case SORT_LENGTH: case SORT_RECENT: + case SORT_RECENT_P1: + case SORT_RECENT_P2: { // Make an array of Song*, then sort them std::vector arraySongs; @@ -623,6 +627,20 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh arraySongs.erase( arraySongs.begin()+MOST_PLAYED_SONGS_TO_SHOW, arraySongs.end() ); bUseSections = false; break; + case SORT_POPULARITY_P1: + if( PROFILEMAN->IsPersistentProfile(PLAYER_1) ) + SongUtil::SortSongPointerArrayByNumPlays( arraySongs, ProfileSlot_Player1, true ); + if( (int) arraySongs.size() > MOST_PLAYED_SONGS_TO_SHOW ) + arraySongs.erase( arraySongs.begin()+MOST_PLAYED_SONGS_TO_SHOW, arraySongs.end() ); + bUseSections = true; + break; + case SORT_POPULARITY_P2: + if( PROFILEMAN->IsPersistentProfile(PLAYER_2) ) + SongUtil::SortSongPointerArrayByNumPlays( arraySongs, ProfileSlot_Player2, true ); + if( (int) arraySongs.size() > MOST_PLAYED_SONGS_TO_SHOW ) + arraySongs.erase( arraySongs.begin()+MOST_PLAYED_SONGS_TO_SHOW, arraySongs.end() ); + bUseSections = true; + break; case SORT_TOP_GRADES: SongUtil::SortSongPointerArrayByGrades( arraySongs, true ); break; @@ -650,6 +668,20 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh arraySongs.erase( arraySongs.begin()+RECENT_SONGS_TO_SHOW, arraySongs.end() ); bUseSections = false; break; + case SORT_RECENT_P1: + if( PROFILEMAN->IsPersistentProfile(PLAYER_1) ) + SongUtil::SortByMostRecentlyPlayedForProfile( arraySongs, PLAYER_1 ); + if( (int) arraySongs.size() > RECENT_SONGS_TO_SHOW ) + arraySongs.erase( arraySongs.begin()+RECENT_SONGS_TO_SHOW, arraySongs.end() ); + bUseSections = true; + break; + case SORT_RECENT_P2: + if( PROFILEMAN->IsPersistentProfile(PLAYER_2) ) + SongUtil::SortByMostRecentlyPlayedForProfile( arraySongs, PLAYER_2 ); + if( (int) arraySongs.size() > RECENT_SONGS_TO_SHOW ) + arraySongs.erase( arraySongs.begin()+RECENT_SONGS_TO_SHOW, arraySongs.end() ); + bUseSections = true; + break; case SORT_BEGINNER_METER: case SORT_EASY_METER: case SORT_MEDIUM_METER: @@ -1175,7 +1207,8 @@ void MusicWheel::FilterWheelItemDatas(std::vector &aUnFilt } /* Update the popularity. This is affected by filtering. */ - if( so == SORT_POPULARITY ) + if( so == SORT_POPULARITY || so == SORT_POPULARITY_P1 || so == SORT_POPULARITY_P2 ) + { for( unsigned i=0; i < std::min(3u, aFilteredData.size()); i++ ) { diff --git a/src/SongUtil.cpp b/src/SongUtil.cpp index 00a896efff..466a8de90d 100644 --- a/src/SongUtil.cpp +++ b/src/SongUtil.cpp @@ -708,7 +708,11 @@ RString SongUtil::GetSectionNameFromSongAndSort( const Song* pSong, SortOrder so return RString(); } case SORT_POPULARITY: + case SORT_POPULARITY_P1: + case SORT_POPULARITY_P2: case SORT_RECENT: + case SORT_RECENT_P1: + case SORT_RECENT_P2: return RString(); case SORT_TOP_GRADES_P1: { @@ -840,6 +844,19 @@ void SongUtil::SortByMostRecentlyPlayedForMachine( std::vector &vpSongsIn g_mapSongSortVal.clear(); } +void SongUtil::SortByMostRecentlyPlayedForProfile( std::vector &vpSongsInOut, PlayerNumber pn ) +{ + Profile *pProfile = PROFILEMAN->GetProfile(pn); + for (Song const *s : vpSongsInOut) + { + int iNumTimesPlayed = pProfile->GetSongNumTimesPlayed( s ); + RString val = iNumTimesPlayed ? pProfile->GetSongLastPlayedDateTime(s).GetString() : RString("0"); + g_mapSongSortVal[s] = val; + } + stable_sort( vpSongsInOut.begin(), vpSongsInOut.end(), CompareSongPointersBySortValueDescending ); + g_mapSongSortVal.clear(); +} + bool SongUtil::IsEditDescriptionUnique( const Song* pSong, StepsType st, const RString &sPreferredDescription, const Steps *pExclude ) { for (Steps const *pSteps : pSong->GetAllSteps()) diff --git a/src/SongUtil.h b/src/SongUtil.h index 48168daa56..965ca7c172 100644 --- a/src/SongUtil.h +++ b/src/SongUtil.h @@ -160,6 +160,7 @@ namespace SongUtil RString GetSectionNameFromSongAndSort( const Song *pSong, SortOrder so ); void SortSongPointerArrayBySectionName( std::vector &vpSongsInOut, SortOrder so ); void SortByMostRecentlyPlayedForMachine( std::vector &vpSongsInOut ); + void SortByMostRecentlyPlayedForProfile( std::vector &vpSongsInOut, PlayerNumber pn); void SortSongPointerArrayByLength( std::vector &vpSongsInOut ); int CompareSongPointersByGroup(const Song *pSong1, const Song *pSong2);