From cefafb8bc4066c00a7c6026df647f6430cdea407 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 2 Jul 2008 00:10:47 +0000 Subject: [PATCH] allow specifying section names in PreferredSongs --- stepmania/src/MusicWheel.cpp | 10 +++- stepmania/src/SongManager.cpp | 90 +++++++++++++++++++++-------------- stepmania/src/SongManager.h | 10 +++- stepmania/src/SongUtil.cpp | 2 +- 4 files changed, 73 insertions(+), 39 deletions(-) diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index e98453c518..01b2e24957 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -512,8 +512,16 @@ void MusicWheel::BuildWheelItemDatas( vector &arrayWheelIt * Grade and BPM sorts in the wrong order, and they're already correct, * so don't re-sort for them. */ /* We're using sections, so use the section name as the top-level sort. */ - if( so != SORT_TOP_GRADES && so != SORT_BPM ) + switch( so ) + { + case SORT_PREFERRED: + case SORT_TOP_GRADES: + case SORT_BPM: + break; // don't sort by section + default: SongUtil::SortSongPointerArrayBySectionName(arraySongs, so); + break; + } } // make WheelItemDatas with sections diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 691b9d84f5..405bb2d297 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -400,9 +400,9 @@ RageColor SongManager::GetSongColor( const Song* pSong ) const if( USE_PREFERRED_SORT_COLOR ) { - FOREACH_CONST( SongPointerVector, m_vPreferredSongSort, v ) + FOREACH_CONST( PreferredSortSection, m_vPreferredSongSort, v ) { - FOREACH_CONST( Song*, *v, s ) + FOREACH_CONST( Song*, v->vpSongs, s ) { if( *s == pSong ) { @@ -557,8 +557,21 @@ void SongManager::GetPreferredSortSongs( vector &AddTo ) const return; } - FOREACH_CONST( SongPointerVector, m_vPreferredSongSort, v ) - AddTo.insert( AddTo.end(), v->begin(), v->end() ); + FOREACH_CONST( PreferredSortSection, m_vPreferredSongSort, v ) + AddTo.insert( AddTo.end(), v->vpSongs.begin(), v->vpSongs.end() ); +} + +RString SongManager::SongToPreferredSortSectionName( const Song *pSong ) const +{ + FOREACH_CONST( PreferredSortSection, m_vPreferredSongSort, v ) + { + FOREACH_CONST( Song*, v->vpSongs, s ) + { + if( *s == pSong ) + return v->sName; + } + } + return RString(); } void SongManager::GetPreferredSortCourses( CourseType ct, vector &AddTo, bool bIncludeAutogen ) const @@ -1242,9 +1255,9 @@ Song* SongManager::GetSongFromDir( RString sDir ) const sDir.Replace( '\\', '/' ); - for( unsigned int i=0; iGetSongDir()) == 0 ) - return m_pSongs[i]; + FOREACH_CONST( Song*, m_pSongs, s ) + if( sDir.EqualsNoCase((*s)->GetSongDir()) ) + return *s; return NULL; } @@ -1407,61 +1420,68 @@ void SongManager::UpdatePreferredSort() if( asLines.empty() ) return; - vector vpSongs; + PreferredSortSection section; + map mapSongToPri; FOREACH( RString, asLines, s ) { RString sLine = *s; - bool bSectionDivider = sLine.find("---") == 0; + + bool bSectionDivider = BeginsWith(sLine, "---"); if( bSectionDivider ) { - if( !vpSongs.empty() ) + if( !section.vpSongs.empty() ) { - m_vPreferredSongSort.push_back( vpSongs ); - vpSongs.clear(); + m_vPreferredSongSort.push_back( section ); + section = PreferredSortSection(); } - continue; + + section.sName = sLine.Right( sLine.length() - RString("---").length() ); + TrimLeft( section.sName ); + TrimRight( section.sName ); + } + else + { + Song *pSong = FindSong( sLine ); + if( pSong == NULL ) + continue; + if( UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE ) + continue; + section.vpSongs.push_back( pSong ); } - - Song *pSong = FindSong( sLine ); - if( pSong == NULL ) - continue; - if( UNLOCKMAN->SongIsLocked(pSong) & LOCKED_SELECTABLE ) - continue; - - vpSongs.push_back( pSong ); } - if( !vpSongs.empty() ) + if( !section.vpSongs.empty() ) { - m_vPreferredSongSort.push_back( vpSongs ); - vpSongs.clear(); + m_vPreferredSongSort.push_back( section ); + section = PreferredSortSection(); } if( MOVE_UNLOCKS_TO_BOTTOM_OF_PREFERRED_SORT.GetValue() ) { // move all unlock songs to a group at the bottom - vector vpUnlockSongs; + PreferredSortSection section; + section.sName = "Unlocks"; FOREACH( UnlockEntry, UNLOCKMAN->m_UnlockEntries, ue ) { if( ue->m_Type == UnlockRewardType_Song ) - if( ue->m_Song.ToSong() ) - vpUnlockSongs.push_back( ue->m_Song.ToSong() ); + if( ue->m_pSong ) + section.vpSongs.push_back( ue->m_pSong ); } - FOREACH( SongPointerVector, m_vPreferredSongSort, v ) + FOREACH( PreferredSortSection, m_vPreferredSongSort, v ) { - for( int i=v->size()-1; i>=0; i-- ) + for( int i=v->vpSongs.size()-1; i>=0; i-- ) { - Song *pSong = (*v)[i]; - if( find(vpUnlockSongs.begin(),vpUnlockSongs.end(),pSong) != vpUnlockSongs.end() ) + Song *pSong = v->vpSongs[i]; + if( find(section.vpSongs.begin(),section.vpSongs.end(),pSong) != section.vpSongs.end() ) { - v->erase( v->begin()+i ); + v->vpSongs.erase( v->vpSongs.begin()+i ); } } } - m_vPreferredSongSort.push_back( vpUnlockSongs ); + m_vPreferredSongSort.push_back( section ); } // prune empty groups @@ -1470,7 +1490,7 @@ void SongManager::UpdatePreferredSort() m_vPreferredSongSort.erase( m_vPreferredSongSort.begin()+i ); FOREACH( SongPointerVector, m_vPreferredSongSort, i ) - FOREACH( Song*, *i, j ) + FOREACH( Song*, i->vpSongs, j ) ASSERT( *j ); } @@ -1487,7 +1507,7 @@ void SongManager::UpdatePreferredSort() FOREACH( RString, asLines, s ) { RString sLine = *s; - bool bSectionDivider = sLine.find("---") == 0; + bool bSectionDivider = BeginsWith( sLine, "---" ); if( bSectionDivider ) { if( !vpCourses.empty() ) diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 699d57b6c2..49f00e049b 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -80,6 +80,7 @@ public: const vector &GetSongs( const RString &sGroupName = GROUP_ALL ) const; void GetPopularSongs( vector &AddTo, const RString &sGroupName ) const; void GetPreferredSortSongs( vector &AddTo ) const; + RString SongToPreferredSortSectionName( const Song *pSong ) const; const vector &GetPopularSongs() const { return m_pPopularSongs; } const vector &GetPopularCourses( CourseType ct ) const { return m_pPopularCourses[ct]; } Song *FindSong( RString sPath ) const; @@ -137,12 +138,17 @@ protected: vector m_pSongs; // all songs that can be played vector m_pPopularSongs; vector m_pShuffledSongs; // used by GetRandomSong - typedef vector SongPointerVector; - vector m_vPreferredSongSort; + struct PreferredSortSection + { + RString sName; + vector vpSongs; + }; + vector m_vPreferredSongSort; vector m_sSongGroupNames; vector m_sSongGroupBannerPaths; // each song group may have a banner associated with it struct Comp { bool operator()(const RString& s, const RString &t) const { return CompareRStringsAsc(s,t); } }; + typedef vector SongPointerVector; map m_mapSongGroupIndex; vector m_pCourses; diff --git a/stepmania/src/SongUtil.cpp b/stepmania/src/SongUtil.cpp index b327a625c1..ddd4a03a34 100644 --- a/stepmania/src/SongUtil.cpp +++ b/stepmania/src/SongUtil.cpp @@ -547,7 +547,7 @@ RString SongUtil::GetSectionNameFromSongAndSort( const Song* pSong, SortOrder so switch( so ) { case SORT_PREFERRED: - return RString(); + return SONGMAN->SongToPreferredSortSectionName( pSong ); case SORT_GROUP: // guaranteed not empty return pSong->m_sGroupName;