Allow songs to exist in multiple Sections in Preferred Sort.

This commit fixes a bug that causes the music wheel to freak out when a song is placed in multiple sections.
This can occur when a user's preferred songs have a song located in two different sections.

This is only applied to Preferred Sorting because Preferred sorting is the only sort where it is possible for a song to be a part of multiple sections (e.g. A song only has 1 Title therefore it would only appear in 1 section of the SORT_TITLE).

Preferred sorting allows users to create custom groups/sections by creating a file that defines the songs and their respective sections as they should appear in the sorting. Players are now able to include a song in multiple sections. Themers are now able to display the Preferred Sort of two players on 1 screen (This previously would have caused duplicate section names to occur)
This commit is contained in:
Crash Cringle
2024-02-25 09:36:21 -08:00
committed by teejusb
parent b16efb06f7
commit 58be4d521e
3 changed files with 100 additions and 22 deletions
+50 -21
View File
@@ -686,38 +686,67 @@ void MusicWheel::BuildWheelItemDatas( std::vector<MusicWheelItemData *> &arrayWh
break;
}
}
// make WheelItemDatas with sections
RString sLastSection = "";
int iSectionColorIndex = 0;
for( unsigned i=0; i< arraySongs.size(); i++ )
// If the sort order is Preferred handle it differently because we already know the sections
if( so == SORT_PREFERRED )
{
Song* pSong = arraySongs[i];
if( bUseSections )
{
RString sThisSection = SongUtil::GetSectionNameFromSongAndSort( pSong, so );
if( sThisSection != sLastSection )
// Get all section names
std::vector<RString> vsSectionNames = SONGMAN->GetPreferredSortSectionNames();
for( unsigned i=0; i<vsSectionNames.size(); i++ )
{
int iSectionCount = 0;
// Count songs in this section
unsigned j;
for( j=i; j < arraySongs.size(); j++ )
{
if( SongUtil::GetSectionNameFromSongAndSort( arraySongs[j], so ) != sThisSection )
break;
}
iSectionCount = j-i;
// new section, make a section item
// Get all songs in this section
std::vector<Song*> vsSongsInSection = SONGMAN->GetPreferredSortSongsBySectionName( vsSectionNames[i] );
// todo: preferred sort section color handling? -aj
RageColor colorSection = (so==SORT_GROUP) ? SONGMAN->GetSongGroupColor(pSong->m_sGroupName) : SECTION_COLORS.GetValue(iSectionColorIndex);
RageColor colorSection = SECTION_COLORS.GetValue(iSectionColorIndex);
iSectionColorIndex = (iSectionColorIndex+1) % NUM_SECTION_COLORS;
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Section, nullptr, sThisSection, nullptr, colorSection, iSectionCount) );
sLastSection = sThisSection;
// Add the section item
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Section, nullptr, vsSectionNames[i], nullptr, SONGMAN->GetSongGroupColor(vsSectionNames[i]), vsSongsInSection.size()) );
// Add all the songs in this section
for( unsigned j=0; j<vsSongsInSection.size(); j++ )
{
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Song, vsSongsInSection[j], vsSectionNames[i], nullptr, SONGMAN->GetSongColor(vsSongsInSection[j]), 0) );
}
}
}
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Song, pSong, sLastSection, nullptr, SONGMAN->GetSongColor(pSong), 0) );
} else {
for( unsigned i=0; i< arraySongs.size(); i++ )
{
Song* pSong = arraySongs[i];
if( bUseSections )
{
RString sThisSection = SongUtil::GetSectionNameFromSongAndSort( pSong, so );
if( sThisSection != sLastSection )
{
int iSectionCount = 0;
// Count songs in this section
unsigned j;
for( j=i; j < arraySongs.size(); j++ )
{
if( SongUtil::GetSectionNameFromSongAndSort( arraySongs[j], so ) != sThisSection )
break;
}
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) );
sLastSection = sThisSection;
}
}
arrayWheelItemDatas.push_back( new MusicWheelItemData(WheelItemDataType_Song, pSong, sLastSection, nullptr, SONGMAN->GetSongColor(pSong), 0) );
}
}
if( so != SORT_ROULETTE )
+46 -1
View File
@@ -845,6 +845,43 @@ RString SongManager::SongToPreferredSortSectionName( const Song *pSong ) const
return RString();
}
void SongManager::GetPreferredSortSongsBySectionName( const RString &sSectionName, std::vector<Song*> &AddTo ) const
{
for (PreferredSortSection const &v : m_vPreferredSongSort)
{
if (v.sName == sSectionName)
{
AddTo.insert( AddTo.end(), v.vpSongs.begin(), v.vpSongs.end() );
return;
}
}
}
std::vector<Song*> SongManager::GetPreferredSortSongsBySectionName( const RString &sSectionName ) const
{
std::vector<Song*> AddTo;
for (PreferredSortSection const &v : m_vPreferredSongSort)
{
if (v.sName == sSectionName)
{
AddTo.insert( AddTo.end(), v.vpSongs.begin(), v.vpSongs.end() );
return AddTo;
}
}
return AddTo;
}
std::vector<RString> SongManager::GetPreferredSortSectionNames() const
{
std::vector<RString> sectionNames;
for (PreferredSortSection const &v : m_vPreferredSongSort)
{
sectionNames.push_back(v.sName);
}
return sectionNames;
}
void SongManager::GetPreferredSortCourses( CourseType ct, std::vector<Course*> &AddTo, bool bIncludeAutogen ) const
{
if( m_vPreferredCourseSort.empty() )
@@ -1605,7 +1642,6 @@ void SongManager::SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute) {
ASSERT( UNLOCKMAN != nullptr );
m_vPreferredSongSort.clear();
std::vector<RString> asLines;
RString sFile = sPreferredSongs;
if (!bIsAbsolute)
@@ -2219,6 +2255,14 @@ public:
lua_pushstring(L, p->SongToPreferredSortSectionName(pSong));
return 1;
}
static int GetPreferredSortSongsBySectionName( T* p, lua_State *L )
{
std::vector<Song*> v;
p->GetPreferredSortSongsBySectionName(SArg(1), v);
LuaHelpers::CreateTableFromArray<Song*>( v, L );
return 1;
}
static int WasLoadedFromAdditionalSongs( T* p, lua_State *L ) { lua_pushboolean(L, false); return 1; } // deprecated
static int WasLoadedFromAdditionalCourses( T* p, lua_State *L ) { lua_pushboolean(L, false); return 1; } // deprecated
@@ -2261,6 +2305,7 @@ public:
ADD_METHOD( GetPopularSongs );
ADD_METHOD( GetPopularCourses );
ADD_METHOD( SongToPreferredSortSectionName );
ADD_METHOD( GetPreferredSortSongsBySectionName );
ADD_METHOD( WasLoadedFromAdditionalSongs ); // deprecated
ADD_METHOD( WasLoadedFromAdditionalCourses ); // deprecated
}
+4
View File
@@ -144,6 +144,10 @@ public:
void GetPreferredSortSongs( std::vector<Song*> &AddTo ) const;
RString SongToPreferredSortSectionName( const Song *pSong ) const;
std::vector<RString> GetPreferredSortSectionNames() const;
std::vector<Song*> GetPreferredSortSongsBySectionName( const RString &sSectionName ) const;
void GetPreferredSortSongsBySectionName( const RString &sSectionName, std::vector<Song*> &AddTo ) const;
const std::vector<Course*> &GetPopularCourses( CourseType ct ) const { return m_pPopularCourses[ct]; }
Song *FindSong( RString sPath ) const;
Song *FindSong( RString sGroup, RString sSong ) const;