From e57c9cc9b86fdcb5aa9dd72a2bb9c7987d00a375 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 7 Mar 2004 00:17:50 +0000 Subject: [PATCH] filter locked and hidden songs from player's best in SongManager add GetBestSongs accessor that filters like GetAllSongs --- stepmania/src/SongManager.cpp | 42 ++++++++++++++++++++++++++++++----- stepmania/src/SongManager.h | 1 + 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index ee9c9fd15d..ac70f42ce7 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -422,14 +422,24 @@ CString SongManager::GetDifficultyThemeName( Difficulty dc ) const return THEME->GetMetric( "Common", sMetricName ); } -void SongManager::GetSongs( vector &AddTo, CString sGroupName, int iMaxStages ) const +static void GetSongsFromVector( const vector &Songs, vector &AddTo, CString sGroupName, int iMaxStages ) { AddTo.clear(); - for( unsigned i=0; im_sGroupName ) - if( GetNumStagesForSong(m_pSongs[i])<=iMaxStages ) - AddTo.push_back( m_pSongs[i] ); + for( unsigned i=0; im_sGroupName ) + if( SongManager::GetNumStagesForSong(Songs[i]) <= iMaxStages ) + AddTo.push_back( Songs[i] ); +} + +void SongManager::GetSongs( vector &AddTo, CString sGroupName, int iMaxStages ) const +{ + GetSongsFromVector( m_pSongs, AddTo, sGroupName, iMaxStages ); +} + +void SongManager::GetBestSongs( vector &AddTo, CString sGroupName, int iMaxStages, ProfileSlot slot ) const +{ + GetSongsFromVector( m_pBestSongs[slot], AddTo, sGroupName, iMaxStages ); } int SongManager::GetNumSongs() const @@ -873,13 +883,33 @@ Course *SongManager::FindCourse( CString sName ) return NULL; } +#include "UnlockSystem.h" void SongManager::UpdateBest() { // update players best for( int i = 0; i < NUM_PROFILE_SLOTS; ++i ) { - m_pBestSongs[i] = m_pSongs; + vector &Best = m_pBestSongs[i]; + Best = m_pSongs; + + for ( unsigned j=0; j < Best.size() ; ++j ) + { + bool bFiltered = false; + /* Filter out hidden songs. */ + if( Best[j]->GetDisplayed() != Song::SHOW_ALWAYS ) + bFiltered = true; + /* Filter out locked songs. */ + if( UNLOCKMAN->SongIsLocked(Best[j]) ) + bFiltered = true; + if( !bFiltered ) + continue; + + /* Remove it. */ + swap( Best[j], Best.back() ); + Best.erase( Best.end()-1 ); + } + SortSongPointerArrayByNumPlays( m_pBestSongs[i], (ProfileSlot) i, true ); m_pBestCourses[i] = m_pCourses; diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 2d17f7bfe8..9c960402cd 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -64,6 +64,7 @@ public: // Lookup const vector &GetAllSongs() const { return m_pSongs; } + void GetBestSongs( vector &AddTo, CString sGroupName, int iMaxStages = 100000 /*inf*/, ProfileSlot slot=PROFILE_SLOT_MACHINE ) const; const vector &GetBestSongs( ProfileSlot slot=PROFILE_SLOT_MACHINE ) const { return m_pBestSongs[slot]; } const vector &GetBestCourses( ProfileSlot slot=PROFILE_SLOT_MACHINE ) const { return m_pBestCourses[slot]; } void GetSongs( vector &AddTo, CString sGroupName, int iMaxStages = 100000 /*inf*/ ) const;