From 53e7a42ce540fb737a71ac5392bd8f04e9b94251 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 1 May 2006 12:45:07 +0000 Subject: [PATCH] automatically move unlocks to the bottom of the preferred sort list --- stepmania/src/SongManager.cpp | 81 ++++++++++++++++++++++++----------- stepmania/src/StepMania.cpp | 1 + 2 files changed, 56 insertions(+), 26 deletions(-) diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 8dcfcdef18..cefc677a13 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -44,6 +44,7 @@ const RString COURSES_DIR = "/Courses/"; static const ThemeMetric EXTRA_COLOR ("SongManager","ExtraColor"); static const ThemeMetric EXTRA_COLOR_METER ("SongManager","ExtraColorMeter"); static const ThemeMetric USE_PREFERRED_SORT_COLOR ("SongManager","UsePreferredSortColor"); +static const ThemeMetric UNLOCK_COLOR ("SongManager","UnlockColor"); RString SONG_GROUP_COLOR_NAME( size_t i ) { return ssprintf("SongGroupColor%i",(int) i+1); } RString COURSE_GROUP_COLOR_NAME( size_t i ) { return ssprintf("CourseGroupColor%i",(int) i+1); } @@ -70,8 +71,6 @@ void SongManager::InitAll( LoadingWindow *ld ) InitSongsFromDisk( ld ); InitCoursesFromDisk( ld ); InitAutogenCourses(); - - UpdatePreferredSort(); } static LocalizedString RELOADING ( "SongManager", "Reloading..." ); @@ -348,6 +347,12 @@ RageColor SongManager::GetSongColor( const Song* pSong ) { ASSERT( pSong ); + // Use unlock color if applicable + const UnlockEntry *pUE = UNLOCKMAN->FindSong( pSong ); + if( pUE ) + return UNLOCK_COLOR; + + if( USE_PREFERRED_SORT_COLOR ) { FOREACH_CONST( SongPointerVector, m_vPreferredSortGroups, v ) @@ -1307,42 +1312,66 @@ void SongManager::UpdateShuffled() void SongManager::UpdatePreferredSort() { + ASSERT( UNLOCKMAN ); + m_vPreferredSortGroups.clear(); RString sFile = THEME->GetPathO( "SongManager", "PreferredSort.txt" ); RageFile file; - if( file.Open( sFile ) ) - { - vector vpSongs; + if( !file.Open( sFile ) ) + return; - RString sLine; - while( file.GetLine(sLine) ) + vector vpSongs; + + RString sLine; + while( file.GetLine(sLine) ) + { + bool bSectionDivider = sLine.find("---") != RString::npos; + if( bSectionDivider ) { - bool bSectionDivider = sLine.find("---") != RString::npos; - if( bSectionDivider ) + if( !vpSongs.empty() ) { - if( !vpSongs.empty() ) - { - m_vPreferredSortGroups.push_back( vpSongs ); - vpSongs.clear(); - } - } - else - { - Song *pSong = NULL; - if( !sLine.empty() ) - pSong = FindSong( sLine ); - if( pSong ) - vpSongs.push_back( pSong ); + m_vPreferredSortGroups.push_back( vpSongs ); + vpSongs.clear(); } } - - if( !vpSongs.empty() ) + else { - m_vPreferredSortGroups.push_back( vpSongs ); - vpSongs.clear(); + Song *pSong = NULL; + if( !sLine.empty() ) + pSong = FindSong( sLine ); + if( pSong ) + vpSongs.push_back( pSong ); } } + + if( !vpSongs.empty() ) + { + m_vPreferredSortGroups.push_back( vpSongs ); + vpSongs.clear(); + } + + // move all unlock songs to a group at the bottom + vector vpUnlockSongs; + FOREACH( UnlockEntry, UNLOCKMAN->m_UnlockEntries, ue ) + { + if( ue->m_Type == UnlockRewardType_Song ) + vpUnlockSongs.push_back( ue->m_pSong ); + } + + FOREACH( SongPointerVector, m_vPreferredSortGroups, v ) + { + for( int i=v->size()-1; i>=0; i-- ) + { + Song *pSong = (*v)[i]; + if( find(vpUnlockSongs.begin(),vpUnlockSongs.end(),pSong) != vpUnlockSongs.end() ) + { + v->erase( v->begin()+i ); + } + } + } + + m_vPreferredSortGroups.push_back( vpUnlockSongs ); } void SongManager::SortSongs() diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 6d37007209..e3be151fd5 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -1059,6 +1059,7 @@ int main(int argc, char* argv[]) PROFILEMAN = new ProfileManager; PROFILEMAN->Init(); // must load after SONGMAN UNLOCKMAN = new UnlockManager; + SONGMAN->UpdatePreferredSort(); /* This shouldn't need to be here; if it's taking long enough that this is * even visible, we should be fixing it, not showing a progress display. */