From 3fd0bd8adeaf02a8d61b0a51b7be34859a8041df Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Sun, 25 Feb 2024 11:12:46 -0500 Subject: [PATCH] Creating mapping of preferred sort section name to songs. --- .../_fallback/Graphics/Banner Preferred.redir | 1 + src/MusicWheel.cpp | 18 ++---- src/SongManager.cpp | 55 ++++++++++--------- src/SongManager.h | 3 + 4 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 Themes/_fallback/Graphics/Banner Preferred.redir diff --git a/Themes/_fallback/Graphics/Banner Preferred.redir b/Themes/_fallback/Graphics/Banner Preferred.redir new file mode 100644 index 0000000000..507050cda9 --- /dev/null +++ b/Themes/_fallback/Graphics/Banner Preferred.redir @@ -0,0 +1 @@ +Common fallback banner \ No newline at end of file diff --git a/src/MusicWheel.cpp b/src/MusicWheel.cpp index 62d12135d9..6679929fcf 100644 --- a/src/MusicWheel.cpp +++ b/src/MusicWheel.cpp @@ -695,24 +695,19 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh { if( bUseSections ) { - // Get all section names - std::vector vsSectionNames = SONGMAN->GetPreferredSortSectionNames(); - for( unsigned i=0; i> preferredSortSongsMap = SONGMAN->GetPreferredSortSongsMap(); + for (auto const& [sectionName, songs] : SONGMAN->GetPreferredSortSongsMap()) { - - // Get all songs in this section - std::vector vsSongsInSection = SONGMAN->GetPreferredSortSongsBySectionName( vsSectionNames[i] ); - // todo: preferred sort section color handling? -aj RageColor colorSection = SECTION_COLORS.GetValue(iSectionColorIndex); iSectionColorIndex = (iSectionColorIndex+1) % NUM_SECTION_COLORS; - // Add the section item - arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Section, nullptr, vsSectionNames[i], nullptr, SONGMAN->GetSongGroupColor(vsSectionNames[i]), vsSongsInSection.size()) ); + arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Section, nullptr, sectionName, nullptr, colorSection, songs.size()) ); // Add all the songs in this section - for( unsigned j=0; jGetSongColor(vsSongsInSection[j]), 0) ); + arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Song, song, sectionName, nullptr, SONGMAN->GetSongColor(song), 0) ); } } } @@ -738,7 +733,6 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh iSectionCount = j-i; // new section, make a section item - // todo: preferred sort section color handling? -aj RageColor colorSection = (so==SORT_GROUP) ? SONGMAN->GetSongGroupColor(pSong->m_sGroupName) : SECTION_COLORS.GetValue(iSectionColorIndex); iSectionColorIndex = (iSectionColorIndex+1) % NUM_SECTION_COLORS; arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Section, nullptr, sThisSection, nullptr, colorSection, iSectionCount) ); diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 0a1c764377..03dfa68cae 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -848,14 +848,10 @@ RString SongManager::SongToPreferredSortSectionName( const Song *pSong ) const void SongManager::GetPreferredSortSongsBySectionName( const RString &sSectionName, std::vector &AddTo ) const { - for (PreferredSortSection const &v : m_vPreferredSongSort) - { - if (v.sName == sSectionName) - { - AddTo.insert( AddTo.end(), v.vpSongs.begin(), v.vpSongs.end() ); - return; - } - } + // Use m_mapPreferredSectionToSongs + std::map::const_iterator iter = m_mapPreferredSectionToSongs.find( sSectionName ); + if( iter != m_mapPreferredSectionToSongs.end() ) + AddTo.insert( AddTo.end(), iter->second.begin(), iter->second.end() ); } std::vector SongManager::GetPreferredSortSongsBySectionName( const RString &sSectionName ) const @@ -868,11 +864,11 @@ std::vector SongManager::GetPreferredSortSongsBySectionName( const RStrin std::vector SongManager::GetPreferredSortSectionNames() const { std::vector sectionNames; - for (PreferredSortSection const &v : m_vPreferredSongSort) - { - sectionNames.push_back(v.sName); - } + // Use m_mapPreferredSectionToSongs + for (std::pair const &iter : m_mapPreferredSectionToSongs) + sectionNames.push_back(iter.first); return sectionNames; + } void SongManager::GetPreferredSortCourses( CourseType ct, std::vector &AddTo, bool bIncludeAutogen ) const @@ -1635,6 +1631,7 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) { ASSERT( UNLOCKMAN != nullptr ); m_vPreferredSongSort.clear(); + m_mapPreferredSectionToSongs.clear(); std::vector asLines; RString sFile = sPreferredSongs; if (!bIsAbsolute) @@ -1654,6 +1651,7 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) { if( !section.vpSongs.empty() ) { m_vPreferredSongSort.push_back( section ); + m_mapPreferredSectionToSongs[section.sName] = section.vpSongs; section = PreferredSortSection(); } @@ -1693,6 +1691,7 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) { if( !section.vpSongs.empty() ) { m_vPreferredSongSort.push_back( section ); + m_mapPreferredSectionToSongs[section.sName] = section.vpSongs; section = PreferredSortSection(); } @@ -1711,25 +1710,31 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) { } } - for (std::vector::iterator v = m_vPreferredSongSort.begin(); v != m_vPreferredSongSort.end(); ++v) - { - for( int i=v->vpSongs.size()-1; i>=0; i-- ) - { - Song *pSong = v->vpSongs[i]; - if( find(PFSection.vpSongs.begin(),PFSection.vpSongs.end(),pSong) != PFSection.vpSongs.end() ) - { - v->vpSongs.erase( v->vpSongs.begin()+i ); - } - } - } - + // NOTE(crashcringle): This code removed the unlocks from other sections they might have been in. + // This was needed due to the previous 1:1 relationship between songs and section in order for the song to appear in the Unlocks section correctly. + // Commented out for now. + // for (std::vector::iterator v = m_vPreferredSongSort.begin(); v != m_vPreferredSongSort.end(); ++v) + // { + // for( int i=v->vpSongs.size()-1; i>=0; i-- ) + // { + // Song *pSong = v->vpSongs[i]; + // if( find(PFSection.vpSongs.begin(),PFSection.vpSongs.end(),pSong) != PFSection.vpSongs.end() ) + // { + // v->vpSongs.erase( v->vpSongs.begin()+i ); + // } + // } + // } + m_vPreferredSongSort.push_back( PFSection ); + m_mapPreferredSectionToSongs[PFSection.sName] = PFSection.vpSongs; } // prune empty groups for( int i=m_vPreferredSongSort.size()-1; i>=0; i-- ) - if( m_vPreferredSongSort[i].vpSongs.empty() ) + if( m_vPreferredSongSort[i].vpSongs.empty() ) { m_vPreferredSongSort.erase( m_vPreferredSongSort.begin()+i ); + m_mapPreferredSectionToSongs.erase( m_vPreferredSongSort[i].sName ); + } for (PreferredSortSection const &i : m_vPreferredSongSort) { diff --git a/src/SongManager.h b/src/SongManager.h index 57aa5857dc..ada2313131 100644 --- a/src/SongManager.h +++ b/src/SongManager.h @@ -143,6 +143,7 @@ public: const std::vector &GetAllSongsOfCurrentGame() const; void GetPreferredSortSongs( std::vector &AddTo ) const; + std::map> GetPreferredSortSongsMap() const { return m_mapPreferredSectionToSongs;}; RString SongToPreferredSortSectionName( const Song *pSong ) const; std::vector GetPreferredSortSectionNames() const; std::vector GetPreferredSortSongsBySectionName( const RString &sSectionName ) const; @@ -229,6 +230,8 @@ protected: RString sName; std::vector vpSongs; }; + /** @brief All preferred songs, keyed by section */ + std::map> m_mapPreferredSectionToSongs; std::vector m_vPreferredSongSort; std::vector m_sSongGroupNames; std::vector m_sSongGroupBannerPaths; // each song group may have a banner associated with it