diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 71634f648b..da452842e2 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -27,6 +27,7 @@ #include "BannerCache.h" #include "RageFile.h" #include "arch/arch.h" +#include "ThemeManager.h" /* Amount to increase meter ranges to make them difficult: */ const int DIFFICULT_METER_CHANGE = 2; @@ -761,11 +762,65 @@ static bool CompareCoursePointersByDifficulty(const Course* pCourse1, const Cour return CompareCoursePointersByAutogen( pCourse1, pCourse2 ); } +static bool CompareCoursePointersByAvgDifficulty(const Course* pCourse1, const Course* pCourse2) +{ + float iNum1 = pCourse1->SortOrder_AvgDifficulty; + float iNum2 = pCourse2->SortOrder_AvgDifficulty; + + if( iNum1 < iNum2 ) + return true; + else if( iNum1 > iNum2 ) + return false; + else // iNum1 == iNum2 + return CompareCoursePointersByAutogen( pCourse1, pCourse2 ); +} + +static bool CompareCoursePointersByTotalDifficulty(const Course* pCourse1, const Course* pCourse2) +{ + float iNum1 = pCourse1->SortOrder_TotalDifficulty; + float iNum2 = pCourse2->SortOrder_TotalDifficulty; + + if( iNum1 < iNum2 ) + return true; + else if( iNum1 > iNum2 ) + return false; + else // iNum1 == iNum2 + return CompareCoursePointersByAutogen( pCourse1, pCourse2 ); +} + +static bool CompareCoursePointersByRanking(const Course* pCourse1, const Course* pCourse2) +{ + float iNum1 = pCourse1->SortOrder_Ranking; + float iNum2 = pCourse2->SortOrder_Ranking; + + if( iNum1 < iNum2 ) + return true; + else if( iNum1 > iNum2 ) + return false; + else // iNum1 == iNum2 + return CompareCoursePointersByAutogen( pCourse1, pCourse2 ); +} + void SortCoursePointerArrayByDifficulty( vector &apCourses ) { sort( apCourses.begin(), apCourses.end(), CompareCoursePointersByDifficulty ); } +void SortCoursePointerArrayByRanking( vector &apCourses ) +{ + sort( apCourses.begin(), apCourses.end(), CompareCoursePointersByRanking ); +} + +void SortCoursePointerArrayByAvgDifficulty( vector &apCourses ) +{ + sort( apCourses.begin(), apCourses.end(), CompareCoursePointersByAvgDifficulty ); +} + +void SortCoursePointerArrayByTotalDifficulty( vector &apCourses ) +{ + sort( apCourses.begin(), apCourses.end(), CompareCoursePointersByTotalDifficulty ); +} + static bool CompareCoursePointersByType(const Course* pCourse1, const Course* pCourse2) { return pCourse1->GetPlayMode() < pCourse2->GetPlayMode(); @@ -781,3 +836,36 @@ bool Course::HasBanner() const { return m_sBannerPath != "" && IsAFile(m_sBannerPath); } + +void Course::UpdateCourseStats() +{ + LOG->Trace("Updating course stats for %s", this->m_sName.c_str() ); + + SortOrder_AvgDifficulty = 0; + SortOrder_NumStages = 0; + SortOrder_Ranking = 2; + SortOrder_TotalDifficulty = 0; + + unsigned i; + + vector ci; + GetCourseInfo( GAMESTATE->GetCurrentStyleDef()->m_NotesType, ci ); + + for(i = 0; i < m_entries.size(); i++) + { + SortOrder_NumStages++; + SortOrder_TotalDifficulty += ci[i].pNotes->GetMeter(); + } + + SortOrder_AvgDifficulty = (float)SortOrder_TotalDifficulty/SortOrder_NumStages; + if (SortOrder_NumStages > 7) SortOrder_Ranking = 3; + + CStringArray RankingCourses; + + split( THEME->GetMetric("ScreenRanking","CoursesToShow"),",", RankingCourses); + + for(i = 0; i < RankingCourses.size(); i++) + if (!RankingCourses[i].CompareNoCase(this->m_sPath)) + SortOrder_Ranking = 1; + +} \ No newline at end of file diff --git a/stepmania/src/Course.h b/stepmania/src/Course.h index 21fb3f514b..dbbf297d36 100644 --- a/stepmania/src/Course.h +++ b/stepmania/src/Course.h @@ -120,6 +120,13 @@ public: void AddScores( NotesType nt, bool bPlayerEnabled[NUM_PLAYERS], int iDancePoints[NUM_PLAYERS], float fSurviveTime[NUM_PLAYERS], int iRankingIndexOut[NUM_PLAYERS], bool bNewRecordOut[NUM_PLAYERS] ); // iNewRecordIndexOut[p] = -1 if not a new record + // sorting values + int SortOrder_NumStages; + int SortOrder_TotalDifficulty; + float SortOrder_AvgDifficulty; + int SortOrder_Ranking; + + void UpdateCourseStats(); private: void SetDefaultScore(); @@ -129,5 +136,9 @@ private: void SortCoursePointerArrayByDifficulty( vector &apCourses ); void SortCoursePointerArrayByType( vector &apCourses ); +void SortCoursePointerArrayByAvgDifficulty( vector &apCourses ); +void SortCoursePointerArrayByTotalDifficulty( vector &apCourses ); +void SortCoursePointerArrayByRanking( vector &apCourses ); + #endif diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index ea9c13e7fb..323d618c5a 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -571,8 +571,24 @@ void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas default: ASSERT(0); break; } + // default sort order; other songs may alter this SortCoursePointerArrayByDifficulty( apCourses ); + if (PREFSMAN->m_iCourseSortOrder != 0) + { + for(i=0; iUpdateCourseStats(); + + if (PREFSMAN->m_iCourseSortOrder == 1) + SortCoursePointerArrayByAvgDifficulty( apCourses ); + + if (PREFSMAN->m_iCourseSortOrder == 2) + SortCoursePointerArrayByTotalDifficulty( apCourses ); + + if (PREFSMAN->m_iCourseSortOrder == 3) + SortCoursePointerArrayByRanking( apCourses ); + } + if( so == SORT_ALL_COURSES ) SortCoursePointerArrayByType( apCourses ); diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp index e6d631139b..c80952c431 100644 --- a/stepmania/src/PrefsManager.cpp +++ b/stepmania/src/PrefsManager.cpp @@ -109,6 +109,9 @@ PrefsManager::PrefsManager() * stage CRS files) don't get it changed around on them. */ m_bPickExtraStage = false; + // default to old sort order + m_iCourseSortOrder = 0; + m_fLongVerSongSeconds = 60*2.5f; // Dynamite Rave is 2:55 m_fMarathonVerSongSeconds = 60*5.f; @@ -214,6 +217,7 @@ void PrefsManager::ReadGlobalPrefsFromDisk( bool bSwitchToLastPlayedGame ) ini.GetValueB( "Options", "BreakComboToGetItem", m_bBreakComboToGetItem ); ini.GetValueB( "Options", "ShowDancingCharacters", m_bShowDancingCharacters ); ini.GetValueB( "Options", "TenFooterInRed", m_bTenFooterInRed ); + ini.GetValueI( "Options", "CourseSortOrder", (int&)m_iCourseSortOrder ); ini.GetValueB( "Options", "UseUnlockSystem", m_bUseUnlockSystem ); @@ -325,6 +329,7 @@ void PrefsManager::SaveGlobalPrefsToDisk() ini.SetValueB( "Options", "DebugMode", m_bDebugMode ); ini.SetValueB( "Options", "TenFooterInRed", m_bTenFooterInRed ); + ini.SetValueI( "Options", "CourseSortOrder", m_iCourseSortOrder ); /* Only write these if they aren't the default. This ensures that we can change diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index 97e7643a5a..2507d6f9d4 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -84,6 +84,10 @@ public: bool m_bDebugMode; bool m_bTenFooterInRed; + // course ranking + // by # songs = 0, avg diff=1, total diff=2, ranking=3 + int m_iCourseSortOrder; + /* 0 = no; 1 = yes; -1 = auto (do whatever is appropriate for the arch). */ int m_iBoostAppPriority; diff --git a/stepmania/src/ScreenAppearanceOptions.cpp b/stepmania/src/ScreenAppearanceOptions.cpp index 3ce0829da6..44ff66ffcc 100644 --- a/stepmania/src/ScreenAppearanceOptions.cpp +++ b/stepmania/src/ScreenAppearanceOptions.cpp @@ -36,6 +36,7 @@ enum { AO_SELECT_GROUP, AO_WHEEL_SECTIONS, AO_TEN_FOOT_RED, + AO_COURSE_SORT, AO_SHOW_TRANSLATIONS, AO_SHOW_LYRICS, NUM_APPEARANCE_OPTIONS_LINES @@ -52,6 +53,7 @@ OptionRow g_AppearanceOptionsLines[NUM_APPEARANCE_OPTIONS_LINES] = { OptionRow( "Song\nGroup", "ALL MUSIC","CHOOSE"), OptionRow( "Wheel\nSections", "NEVER","ALWAYS", "ABC ONLY"), OptionRow( "10+ foot\nIn Red", "NO", "YES"), + OptionRow( "Course\nSort", "# SONGS", "AVG FEET", "TOTAL FEET", "RANKING"), OptionRow( "Translations", "NATIVE","TRANSLITERATE"), OptionRow( "Lyrics", "HIDE","SHOW"), }; @@ -144,6 +146,7 @@ void ScreenAppearanceOptions::ImportOptions() m_iSelectedOption[0][AO_SELECT_GROUP] = PREFSMAN->m_bShowSelectGroup? 1:0; m_iSelectedOption[0][AO_WHEEL_SECTIONS] = (int)PREFSMAN->m_MusicWheelUsesSections; m_iSelectedOption[0][AO_TEN_FOOT_RED] = PREFSMAN->m_bTenFooterInRed? 1:0; + m_iSelectedOption[0][AO_COURSE_SORT] = (int)PREFSMAN->m_iCourseSortOrder; m_iSelectedOption[0][AO_SHOW_TRANSLATIONS] = PREFSMAN->m_bShowNative? 0:1; m_iSelectedOption[0][AO_SHOW_LYRICS] = PREFSMAN->m_bShowLyrics; } @@ -192,6 +195,7 @@ void ScreenAppearanceOptions::ExportOptions() PREFSMAN->m_bShowLyrics = !!m_iSelectedOption[0][AO_SHOW_LYRICS]; PREFSMAN->m_bDancePointsForOni = !!m_iSelectedOption[0][AO_DANCE_POINTS_FOR_ONI]; PREFSMAN->m_bTenFooterInRed = !!m_iSelectedOption[0][AO_TEN_FOOT_RED]; + PREFSMAN->m_iCourseSortOrder = m_iSelectedOption[0][AO_COURSE_SORT]; PREFSMAN->SaveGamePrefsToDisk(); PREFSMAN->SaveGlobalPrefsToDisk();