Add Recently Played and Most Played per Profile as sorts

This commit is contained in:
Crash Cringle
2025-02-24 18:36:21 -05:00
committed by teejusb
parent 6707922be8
commit 6201e1ab94
6 changed files with 61 additions and 2 deletions
+1 -1
View File
@@ -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;
+4
View File
@@ -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 );
+4
View File
@@ -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
};
+34 -1
View File
@@ -562,6 +562,8 @@ void MusicWheel::BuildWheelItemDatas( std::vector<MusicWheelItemData *> &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<MusicWheelItemData *> &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<Song*> arraySongs;
@@ -623,6 +627,20 @@ void MusicWheel::BuildWheelItemDatas( std::vector<MusicWheelItemData *> &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<MusicWheelItemData *> &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<MusicWheelItemData *> &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<unsigned int>(3u, aFilteredData.size()); i++ )
{
+17
View File
@@ -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<Song*> &vpSongsIn
g_mapSongSortVal.clear();
}
void SongUtil::SortByMostRecentlyPlayedForProfile( std::vector<Song*> &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())
+1
View File
@@ -160,6 +160,7 @@ namespace SongUtil
RString GetSectionNameFromSongAndSort( const Song *pSong, SortOrder so );
void SortSongPointerArrayBySectionName( std::vector<Song*> &vpSongsInOut, SortOrder so );
void SortByMostRecentlyPlayedForMachine( std::vector<Song*> &vpSongsInOut );
void SortByMostRecentlyPlayedForProfile( std::vector<Song*> &vpSongsInOut, PlayerNumber pn);
void SortSongPointerArrayByLength( std::vector<Song*> &vpSongsInOut );
int CompareSongPointersByGroup(const Song *pSong1, const Song *pSong2);