From 24876804efb8f93c216a998e7ff7614a1538d07c Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:14:18 -0500 Subject: [PATCH] Add Top Grades sort per profile. This allows each player to see their top grades based on the currently used profile. The present implementation adds 2 new sorts for this, TOP_P1_Grades and TOP_P2_GRADES following the naming convention of TOP_GRADES which returns the machine grades. I named the sort TopP1Grades rather than TopGradesP1 to prevent the "conflicting" banner error. Eventually, I'd like to condense this to be 1 sort fed a playernumber or profile parameter in the future. (cherry picked from commit 731ae501d8a14a196984bf7578afaa9351c22c5c) --- .../Graphics/Banner TopP1Grades.redir | 1 + .../Graphics/Banner TopP2Grades.redir | 1 + Themes/_fallback/Languages/en.ini | 2 + Themes/_fallback/metrics.ini | 4 +- src/GameConstantsAndTypes.cpp | 2 + src/GameConstantsAndTypes.h | 2 + src/MusicWheel.cpp | 20 ++++++- src/SongUtil.cpp | 57 +++++++++++++++++++ src/SongUtil.h | 3 +- 9 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 Themes/_fallback/Graphics/Banner TopP1Grades.redir create mode 100644 Themes/_fallback/Graphics/Banner TopP2Grades.redir diff --git a/Themes/_fallback/Graphics/Banner TopP1Grades.redir b/Themes/_fallback/Graphics/Banner TopP1Grades.redir new file mode 100644 index 0000000000..507050cda9 --- /dev/null +++ b/Themes/_fallback/Graphics/Banner TopP1Grades.redir @@ -0,0 +1 @@ +Common fallback banner \ No newline at end of file diff --git a/Themes/_fallback/Graphics/Banner TopP2Grades.redir b/Themes/_fallback/Graphics/Banner TopP2Grades.redir new file mode 100644 index 0000000000..507050cda9 --- /dev/null +++ b/Themes/_fallback/Graphics/Banner TopP2Grades.redir @@ -0,0 +1 @@ +Common fallback banner \ No newline at end of file diff --git a/Themes/_fallback/Languages/en.ini b/Themes/_fallback/Languages/en.ini index f82ab2b563..78c1e250a4 100644 --- a/Themes/_fallback/Languages/en.ini +++ b/Themes/_fallback/Languages/en.ini @@ -309,6 +309,8 @@ PreferredText=Preferred TitleText=Title RecentText=Recent TopGradesText=Top Grades +TopP1GradesText=P1 Top Grades +TopP2GradesText=P2 Top Grades CoursesText=Courses AllCoursesText=All Courses diff --git a/Themes/_fallback/metrics.ini b/Themes/_fallback/metrics.ini index 75cdd378c9..15b2fd42f4 100644 --- a/Themes/_fallback/metrics.ini +++ b/Themes/_fallback/metrics.ini @@ -965,7 +965,7 @@ RecentSongsToShow=30 UseEasyMarkerFlag=false -ModeMenuChoiceNames="Preferred,Group,Title,Bpm,Popularity,TopGrades,Artist,EasyMeter,MediumMeter,HardMeter,ChallengeMeter,DoubleEasyMeter,DoubleMediumMeter,DoubleHardMeter,DoubleChallengeMeter,Genre,Length,Recent" +ModeMenuChoiceNames="Preferred,Group,Title,Bpm,Popularity,TopGrades,TopP1Grades,TopP2Grades,Artist,EasyMeter,MediumMeter,HardMeter,ChallengeMeter,DoubleEasyMeter,DoubleMediumMeter,DoubleHardMeter,DoubleChallengeMeter,Genre,Length,Recent" # ModeMenuChoiceNames="Preferred,Group,Title,Bpm,Popularity,TopGrades,Artist,EasyMeter,MediumMeter,HardMeter,ChallengeMeter,DoubleEasyMeter,DoubleMediumMeter,DoubleHardMeter,DoubleChallengeMeter,Genre,Length,Recent,NormalMode,BattleMode" ChoicePreferred="sort,Preferred" ChoiceGroup="sort,Group" @@ -973,6 +973,8 @@ ChoiceTitle="sort,Title" ChoiceBpm="sort,BPM" ChoicePopularity="sort,Popularity" ChoiceTopGrades="sort,TopGrades" +ChoiceTopP1Grades="sort,TopP1Grades" +ChoiceTopP2Grades="sort,TopP2Grades" ChoiceArtist="sort,Artist" ChoiceGenre="sort,Genre" ChoiceEasyMeter="sort,EasyMeter" diff --git a/src/GameConstantsAndTypes.cpp b/src/GameConstantsAndTypes.cpp index b572faf4c6..795f4b45cc 100644 --- a/src/GameConstantsAndTypes.cpp +++ b/src/GameConstantsAndTypes.cpp @@ -166,6 +166,8 @@ static const char *SortOrderNames[] = { "BPM", "Popularity", "TopGrades", + "TopP1Grades", + "TopP2Grades", "Artist", "Genre", "BeginnerMeter", diff --git a/src/GameConstantsAndTypes.h b/src/GameConstantsAndTypes.h index 1d3a9b8e4d..0b8dd09465 100644 --- a/src/GameConstantsAndTypes.h +++ b/src/GameConstantsAndTypes.h @@ -166,6 +166,8 @@ enum SortOrder SORT_BPM, /**< Sort by the Song's BPM. */ SORT_POPULARITY, /**< Sort by how popular the Song is. */ 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. */ SORT_ARTIST, /**< Sort by the name of the artist of the Song. */ SORT_GENRE, /**< Sort by the Song's genre. */ SORT_BEGINNER_METER, /**< Sort by the difficulty of the single beginner meter. */ diff --git a/src/MusicWheel.cpp b/src/MusicWheel.cpp index 45ee06b78f..7f8469f2fb 100644 --- a/src/MusicWheel.cpp +++ b/src/MusicWheel.cpp @@ -544,6 +544,8 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh case SORT_BPM: case SORT_POPULARITY: case SORT_TOP_GRADES: + case SORT_TOP_GRADES_P1: + case SORT_TOP_GRADES_P2: case SORT_ARTIST: case SORT_GENRE: case SORT_BEGINNER_METER: @@ -600,7 +602,21 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh bUseSections = false; break; case SORT_TOP_GRADES: - SongUtil::SortSongPointerArrayByGrades( arraySongs, true ); + SongUtil::SortSongPointerArrayByGrades( arraySongs, true ); + break; + case SORT_TOP_GRADES_P1: + // Check if master player profile is persistent + if( PROFILEMAN->IsPersistentProfile(PLAYER_1) ) + SongUtil::SortSongPointerArrayByProfileGrades( arraySongs, true, PLAYER_1); + else + SongUtil::SortSongPointerArrayByGrades( arraySongs, true ); + break; + case SORT_TOP_GRADES_P2: + if( PROFILEMAN->IsPersistentProfile(PLAYER_2) ) + SongUtil::SortSongPointerArrayByProfileGrades( arraySongs, true, PLAYER_2); + else + SongUtil::SortSongPointerArrayByGrades( arraySongs, true ); + break; case SORT_ARTIST: SongUtil::SortSongPointerArrayByArtist( arraySongs ); @@ -665,6 +681,8 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh { case SORT_PREFERRED: case SORT_TOP_GRADES: + case SORT_TOP_GRADES_P1: + case SORT_TOP_GRADES_P2: case SORT_BPM: case SORT_LENGTH: break; // don't sort by section diff --git a/src/SongUtil.cpp b/src/SongUtil.cpp index ffe9dda04f..75c061d0d5 100644 --- a/src/SongUtil.cpp +++ b/src/SongUtil.cpp @@ -17,6 +17,8 @@ #include "CommonMetrics.h" #include "LuaBinding.h" #include "EnumHelper.h" +#include "PlayerNumber.h" + #include #include @@ -495,6 +497,35 @@ void SongUtil::SortSongPointerArrayByGrades( std::vector &vpSongsInOut, b vpSongsInOut[i] = vals[i].first; } +void SongUtil::SortSongPointerArrayByProfileGrades( std::vector &vpSongsInOut, bool bDescending, PlayerNumber pn ) +{ + /* Optimize by pre-writing a string to compare, since doing + * GetNumNotesWithGrade inside the sort is too slow. */ + typedef std::pair val; + std::vector vals; + vals.reserve( vpSongsInOut.size() ); + + for( unsigned i = 0; i < vpSongsInOut.size(); ++i ) + { + Song *pSong = vpSongsInOut[i]; + + int iCounts[NUM_Grade]; + const Profile *pProfile = PROFILEMAN->GetProfile(pn); + ASSERT( pProfile != nullptr ); + pProfile->GetGrades( pSong, GAMESTATE->GetCurrentStyle(pn)->m_StepsType, iCounts ); + + RString foo; + foo.reserve(256); + for( int g=Grade_Tier01; g &vpSongsInOut ) { @@ -631,6 +662,32 @@ RString SongUtil::GetSectionNameFromSongAndSort( const Song* pSong, SortOrder so case SORT_POPULARITY: case SORT_RECENT: return RString(); + case SORT_TOP_GRADES_P1: + { + int iCounts[NUM_Grade]; + PROFILEMAN->GetProfile(PLAYER_1)->GetGrades( pSong, GAMESTATE->GetCurrentStyle(PLAYER_1)->m_StepsType, iCounts ); + + for( int i=Grade_Tier01; i 0 ) + return ssprintf( "%4s x %d", GradeToLocalizedString(g).c_str(), iCounts[i] ); + } + return GradeToLocalizedString( Grade_NoData ); + } + case SORT_TOP_GRADES_P2: + { + int iCounts[NUM_Grade]; + PROFILEMAN->GetProfile(PLAYER_2)->GetGrades( pSong, GAMESTATE->GetCurrentStyle(PLAYER_2)->m_StepsType, iCounts ); + + for( int i=Grade_Tier01; i 0 ) + return ssprintf( "%4s x %d", GradeToLocalizedString(g).c_str(), iCounts[i] ); + } + return GradeToLocalizedString( Grade_NoData ); + } case SORT_TOP_GRADES: { int iCounts[NUM_Grade]; diff --git a/src/SongUtil.h b/src/SongUtil.h index 35ade1086d..7d921c61ec 100644 --- a/src/SongUtil.h +++ b/src/SongUtil.h @@ -2,7 +2,7 @@ #ifndef SONG_UTIL_H #define SONG_UTIL_H - +#include "PlayerNumber.h" #include "GameConstantsAndTypes.h" #include "Difficulty.h" @@ -138,6 +138,7 @@ namespace SongUtil void SortSongPointerArrayByTitle( std::vector &vpSongsInOut ); void SortSongPointerArrayByBPM( std::vector &vpSongsInOut ); void SortSongPointerArrayByGrades( std::vector &vpSongsInOut, bool bDescending ); + void SortSongPointerArrayByProfileGrades( std::vector &vpSongsInOut, bool bDescending, PlayerNumber pn ); void SortSongPointerArrayByArtist( std::vector &vpSongsInOut ); void SortSongPointerArrayByDisplayArtist( std::vector &vpSongsInOut ); void SortSongPointerArrayByGenre( std::vector &vpSongsInOut );