allow specifying section names in PreferredSongs

This commit is contained in:
Chris Danford
2008-07-02 00:10:47 +00:00
parent aca8629e5a
commit cefafb8bc4
4 changed files with 73 additions and 39 deletions
+9 -1
View File
@@ -512,8 +512,16 @@ void MusicWheel::BuildWheelItemDatas( vector<MusicWheelItemData *> &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
+55 -35
View File
@@ -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<Song*> &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<Course*> &AddTo, bool bIncludeAutogen ) const
@@ -1242,9 +1255,9 @@ Song* SongManager::GetSongFromDir( RString sDir ) const
sDir.Replace( '\\', '/' );
for( unsigned int i=0; i<m_pSongs.size(); i++ )
if( sDir.CompareNoCase(m_pSongs[i]->GetSongDir()) == 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<Song*> vpSongs;
PreferredSortSection section;
map<Song *, float> 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<Song*> 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() )
+8 -2
View File
@@ -80,6 +80,7 @@ public:
const vector<Song*> &GetSongs( const RString &sGroupName = GROUP_ALL ) const;
void GetPopularSongs( vector<Song*> &AddTo, const RString &sGroupName ) const;
void GetPreferredSortSongs( vector<Song*> &AddTo ) const;
RString SongToPreferredSortSectionName( const Song *pSong ) const;
const vector<Song*> &GetPopularSongs() const { return m_pPopularSongs; }
const vector<Course*> &GetPopularCourses( CourseType ct ) const { return m_pPopularCourses[ct]; }
Song *FindSong( RString sPath ) const;
@@ -137,12 +138,17 @@ protected:
vector<Song*> m_pSongs; // all songs that can be played
vector<Song*> m_pPopularSongs;
vector<Song*> m_pShuffledSongs; // used by GetRandomSong
typedef vector<Song*> SongPointerVector;
vector<SongPointerVector> m_vPreferredSongSort;
struct PreferredSortSection
{
RString sName;
vector<Song*> vpSongs;
};
vector<PreferredSortSection> m_vPreferredSongSort;
vector<RString> m_sSongGroupNames;
vector<RString> 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<Song*> SongPointerVector;
map<RString,SongPointerVector,Comp> m_mapSongGroupIndex;
vector<Course*> m_pCourses;
+1 -1
View File
@@ -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;