diff --git a/stepmania/src/GameConstantsAndTypes.cpp b/stepmania/src/GameConstantsAndTypes.cpp index cd77b66b67..e4d5512bdc 100644 --- a/stepmania/src/GameConstantsAndTypes.cpp +++ b/stepmania/src/GameConstantsAndTypes.cpp @@ -15,109 +15,106 @@ #include "RageUtil.h" #include "ThemeManager.h" +const static CString EMPTY_STRING; -CString RadarCategoryToString( RadarCategory cat ) -{ - switch( cat ) - { - case RADAR_STREAM: return "stream"; - case RADAR_VOLTAGE: return "voltage"; - case RADAR_AIR: return "air"; - case RADAR_FREEZE: return "freeze"; - case RADAR_CHAOS: return "chaos"; - case RADAR_NUM_TAPS_AND_HOLDS: return "taps"; - case RADAR_NUM_JUMPS: return "jumps"; - case RADAR_NUM_HOLDS: return "holds"; - case RADAR_NUM_MINES: return "mines"; - case RADAR_NUM_HANDS: return "hands"; - default: ASSERT(0); return ""; // invalid +#define XToString(X) \ + const CString& X##ToString( X x ) \ + { \ + if( x == ARRAYSIZE(X##Names)+1 ) \ + return EMPTY_STRING; \ + ASSERT(unsigned(x) < ARRAYSIZE(X##Names)); \ + return X##Names[x]; \ } -} -CString DifficultyToString( Difficulty dc ) -{ - switch( dc ) - { - case DIFFICULTY_BEGINNER: return "beginner"; - case DIFFICULTY_EASY: return "easy"; - case DIFFICULTY_MEDIUM: return "medium"; - case DIFFICULTY_HARD: return "hard"; - case DIFFICULTY_CHALLENGE: return "challenge"; - case DIFFICULTY_EDIT: return "edit"; - default: ASSERT(0); return ""; // invalid Difficulty +#define XToThemedString(X) \ + CString X##ToThemedString( X x ) \ + { \ + return THEME->GetMetric( #X, X##ToString(x) ); \ } -} + +#define StringToX(X) \ + X StringTo##X( const CString& s ) \ + { \ + CString s2 = s; \ + s2.MakeLower(); \ + for( unsigned i = 0; i < ARRAYSIZE(X##Names); ++i ) \ + if( !s2.CompareNoCase(X##Names[i]) ) \ + return (X)i; \ + return (X)(i+1); /*invalid*/ \ + } + + +static const CString RadarCategoryNames[NUM_RADAR_CATEGORIES] = { + "stream", + "voltage", + "air", + "freeze", + "chaos", + "taps", + "jumps", + "holds", + "mines", + "hands", +}; +XToString( RadarCategory ); + + +static const CString DifficultyNames[NUM_RADAR_CATEGORIES] = { + "beginner", + "easy", + "medium", + "hard", + "challenge", + "edit", +}; +XToString( Difficulty ); /* We prefer the above names; recognize a number of others, too. (They'l * get normalized when written to SMs, etc.) */ -Difficulty StringToDifficulty( CString sDC ) +Difficulty StringToDifficulty( const CString& sDC ) { - sDC.MakeLower(); - if( sDC == "beginner" ) return DIFFICULTY_BEGINNER; - else if( sDC == "easy" ) return DIFFICULTY_EASY; - else if( sDC == "basic" ) return DIFFICULTY_EASY; - else if( sDC == "light" ) return DIFFICULTY_EASY; - else if( sDC == "medium" ) return DIFFICULTY_MEDIUM; - else if( sDC == "another" ) return DIFFICULTY_MEDIUM; - else if( sDC == "trick" ) return DIFFICULTY_MEDIUM; - else if( sDC == "standard" ) return DIFFICULTY_MEDIUM; - else if( sDC == "difficult") return DIFFICULTY_MEDIUM; - else if( sDC == "hard" ) return DIFFICULTY_HARD; - else if( sDC == "ssr" ) return DIFFICULTY_HARD; - else if( sDC == "maniac" ) return DIFFICULTY_HARD; - else if( sDC == "heavy" ) return DIFFICULTY_HARD; - else if( sDC == "smaniac" ) return DIFFICULTY_CHALLENGE; - else if( sDC == "challenge" ) return DIFFICULTY_CHALLENGE; - else if( sDC == "expert" ) return DIFFICULTY_CHALLENGE; - else if( sDC == "oni" ) return DIFFICULTY_CHALLENGE; - else if( sDC == "edit" ) return DIFFICULTY_EDIT; - else return DIFFICULTY_INVALID; + CString s2 = sDC; + s2.MakeLower(); + if( sDC == "beginner" ) return DIFFICULTY_BEGINNER; + else if( s2 == "easy" ) return DIFFICULTY_EASY; + else if( s2 == "basic" ) return DIFFICULTY_EASY; + else if( s2 == "light" ) return DIFFICULTY_EASY; + else if( s2 == "medium" ) return DIFFICULTY_MEDIUM; + else if( s2 == "another" ) return DIFFICULTY_MEDIUM; + else if( s2 == "trick" ) return DIFFICULTY_MEDIUM; + else if( s2 == "standard" ) return DIFFICULTY_MEDIUM; + else if( s2 == "difficult") return DIFFICULTY_MEDIUM; + else if( s2 == "hard" ) return DIFFICULTY_HARD; + else if( s2 == "ssr" ) return DIFFICULTY_HARD; + else if( s2 == "maniac" ) return DIFFICULTY_HARD; + else if( s2 == "heavy" ) return DIFFICULTY_HARD; + else if( s2 == "smaniac" ) return DIFFICULTY_CHALLENGE; + else if( s2 == "challenge" )return DIFFICULTY_CHALLENGE; + else if( s2 == "expert" ) return DIFFICULTY_CHALLENGE; + else if( s2 == "oni" ) return DIFFICULTY_CHALLENGE; + else if( s2 == "edit" ) return DIFFICULTY_EDIT; + else return DIFFICULTY_INVALID; } -CString CourseDifficultyToString( CourseDifficulty dc ) -{ - switch( dc ) - { - case COURSE_DIFFICULTY_REGULAR: return "regular"; - case COURSE_DIFFICULTY_DIFFICULT: return "difficult"; - default: ASSERT(0); return ""; // invalid Difficulty - } -} - -/* We prefer the above names; recognize a number of others, too. (They'l - * get normalized when written to SMs, etc.) */ -CourseDifficulty StringToCourseDifficulty( CString sDC ) -{ - sDC.MakeLower(); - if( sDC == "regular" ) return COURSE_DIFFICULTY_REGULAR; - else if( sDC == "difficult" ) return COURSE_DIFFICULTY_DIFFICULT; - else return COURSE_DIFFICULTY_INVALID; -} +static const CString CourseDifficultyNames[NUM_COURSE_DIFFICULTIES] = { + "regular", + "difficult", +}; +XToString( CourseDifficulty ); +StringToX( CourseDifficulty ); -CString PlayModeToString( PlayMode pm ) -{ - switch( pm ) - { - case PLAY_MODE_ARCADE: return "arcade"; - case PLAY_MODE_ONI: return "oni"; - case PLAY_MODE_NONSTOP: return "nonstop"; - case PLAY_MODE_ENDLESS: return "endless"; - case PLAY_MODE_BATTLE: return "battle"; - case PLAY_MODE_RAVE: return "rave"; - default: ASSERT(0); return ""; - } -} - -PlayMode StringToPlayMode( CString s ) -{ - for( int i=0; iGetMetric( #X, X##ToString(x) ); \ - } - -#define StringToX(X) \ - X StringTo##X( CString s ) \ - { \ - unsigned i; \ - for( i = 0; i < ARRAYSIZE(X##Names); ++i ) \ - if( !s.CompareNoCase(X##Names[i]) ) \ - return (X)i; \ - return (X)i; \ - } +static const CString MemoryCardStateNames[NUM_MEMORY_CARD_STATES] = { + "ready", + "late", + "error", + "none", +}; +XToString( MemoryCardState ); -static const char *PerDifficultyAwardNames[NUM_PER_DIFFICULTY_AWARDS] = { +static const CString PerDifficultyAwardNames[NUM_PER_DIFFICULTY_AWARDS] = { "FullComboGreats", "FullComboPerfects", "FullComboMarvelouses", @@ -261,15 +200,16 @@ static const char *PerDifficultyAwardNames[NUM_PER_DIFFICULTY_AWARDS] = { "Greats90Percent", "Greats100Percent", }; - XToString( PerDifficultyAward ); XToThemedString( PerDifficultyAward ); StringToX( PerDifficultyAward ); -// The number is not at the front so that these strings can be used as XML entity names -// The number is not at the back so that "1000" and "10000" don't conflict when -// searching for theme elements. -static const char *PeakComboAwardNames[NUM_PEAK_COMBO_AWARDS] = { + +// Numbers are intentially not at the front of these strings so that the +// strings can be used as XML entity names. +// Numbers are intentially not at the back so that "1000" and "10000" don't +// conflict when searching for theme elements. +static const CString PeakComboAwardNames[NUM_PEAK_COMBO_AWARDS] = { "Peak1000Combo", "Peak2000Combo", "Peak3000Combo", @@ -281,7 +221,6 @@ static const char *PeakComboAwardNames[NUM_PEAK_COMBO_AWARDS] = { "Peak9000Combo", "Peak10000Combo", }; - XToString( PeakComboAward ); XToThemedString( PeakComboAward ); StringToX( PeakComboAward ); diff --git a/stepmania/src/GameConstantsAndTypes.h b/stepmania/src/GameConstantsAndTypes.h index eebbe626be..11bfb251e8 100644 --- a/stepmania/src/GameConstantsAndTypes.h +++ b/stepmania/src/GameConstantsAndTypes.h @@ -62,7 +62,7 @@ enum RadarCategory }; #define FOREACH_RadarCategory( rc ) FOREACH_ENUM( RadarCategory, NUM_RADAR_CATEGORIES, rc ) -CString RadarCategoryToString( RadarCategory cat ); +const CString& RadarCategoryToString( RadarCategory cat ); struct RadarValues { @@ -99,8 +99,8 @@ enum Difficulty }; #define FOREACH_Difficulty( dc ) FOREACH_ENUM( Difficulty, NUM_DIFFICULTIES, dc ) -CString DifficultyToString( Difficulty dc ); -Difficulty StringToDifficulty( CString sDC ); +const CString& DifficultyToString( Difficulty dc ); +Difficulty StringToDifficulty( const CString& sDC ); enum CourseDifficulty @@ -112,8 +112,8 @@ enum CourseDifficulty }; #define FOREACH_CourseDifficulty( cd ) FOREACH_ENUM( CourseDifficulty, NUM_COURSE_DIFFICULTIES, cd ) -CString CourseDifficultyToString( CourseDifficulty dc ); -CourseDifficulty StringToCourseDifficulty( CString sDC ); +const CString& CourseDifficultyToString( CourseDifficulty dc ); +CourseDifficulty StringToCourseDifficulty( const CString& sDC ); enum StepsType @@ -166,13 +166,13 @@ enum PlayMode }; #define FOREACH_PlayMode( pm ) FOREACH_ENUM( PlayMode, NUM_PLAY_MODES, pm ) -CString PlayModeToString( PlayMode pm ); -PlayMode StringToPlayMode( CString s ); +const CString& PlayModeToString( PlayMode pm ); +PlayMode StringToPlayMode( const CString& s ); -enum SongSortOrder { +enum SortOrder { SORT_PREFERRED, SORT_GROUP, SORT_TITLE, @@ -194,13 +194,14 @@ enum SongSortOrder { NUM_SORT_ORDERS, SORT_INVALID }; -const SongSortOrder MAX_SELECTABLE_SORT = (SongSortOrder)(SORT_ROULETTE-1); +const SortOrder MAX_SELECTABLE_SORT = (SortOrder)(SORT_ROULETTE-1); -#define FOREACH_SongSortOrder( so ) FOREACH_ENUM( SongSortOrder, NUM_SORT_ORDERS, so ) +#define FOREACH_SortOrder( so ) FOREACH_ENUM( SortOrder, NUM_SORT_ORDERS, so ) -CString SongSortOrderToString( SongSortOrder so ); -SongSortOrder StringToSongSortOrder( CString str ); +const CString& SortOrderToString( SortOrder so ); +SortOrder StringToSortOrder( const CString& str ); +inline bool IsSongSort( SortOrder so ) { return so >= SORT_PREFERRED && so <= SORT_CHALLENGE_METER; } // // Scoring stuff @@ -219,7 +220,7 @@ enum TapNoteScore { }; #define FOREACH_TapNoteScore( tns ) FOREACH_ENUM( TapNoteScore, NUM_TAP_NOTE_SCORES, tns ) -CString TapNoteScoreToString( TapNoteScore tns ); +const CString& TapNoteScoreToString( TapNoteScore tns ); //enum TapNoteTiming { // TNT_NONE, @@ -262,7 +263,7 @@ enum MemoryCardState MEMORY_CARD_STATE_INVALID, }; -CString MemoryCardStateToString( MemoryCardState mcs ); +const CString& MemoryCardStateToString( MemoryCardState mcs ); // @@ -278,11 +279,11 @@ enum RankingCategory RANKING_INVALID }; #define FOREACH_RankingCategory( rc ) FOREACH_ENUM( RankingCategory, NUM_RANKING_CATEGORIES, rc ) -CString RankingCategoryToString( RankingCategory rc ); -RankingCategory StringToRankingCategory( CString rc ); +const CString& RankingCategoryToString( RankingCategory rc ); +RankingCategory StringToRankingCategory( const CString& rc ); const CString RANKING_TO_FILL_IN_MARKER[NUM_PLAYERS] = {"#P1#","#P2#"}; -inline bool IsRankingToFillIn( CString sName ) { return !sName.empty() && sName[0]=='#'; } +inline bool IsRankingToFillIn( const CString& sName ) { return !sName.empty() && sName[0]=='#'; } RankingCategory AverageMeterToRankingCategory( float fAverageMeter ); @@ -345,7 +346,7 @@ const int ITEM_NONE = -1; enum CoinMode { COIN_HOME, COIN_PAY, COIN_FREE, NUM_COIN_MODES }; -CString CoinModeToString( CoinMode cm ); +const CString& CoinModeToString( CoinMode cm ); // @@ -366,9 +367,9 @@ enum PerDifficultyAward PER_DIFFICULTY_AWARD_INVALID, }; #define FOREACH_PerDifficultyAward( pma ) FOREACH_ENUM( PerDifficultyAward, NUM_PER_DIFFICULTY_AWARDS, pma ) -CString PerDifficultyAwardToString( PerDifficultyAward pma ); +const CString& PerDifficultyAwardToString( PerDifficultyAward pma ); CString PerDifficultyAwardToThemedString( PerDifficultyAward pma ); -PerDifficultyAward StringToPerDifficultyAward( CString pma ); +PerDifficultyAward StringToPerDifficultyAward( const CString& pma ); enum PeakComboAward @@ -387,9 +388,9 @@ enum PeakComboAward PEAK_COMBO_AWARD_INVALID, }; #define FOREACH_PeakComboAward( pca ) FOREACH_ENUM( PeakComboAward, NUM_PEAK_COMBO_AWARDS, pca ) -CString PeakComboAwardToString( PeakComboAward pma ); +const CString& PeakComboAwardToString( PeakComboAward pma ); CString PeakComboAwardToThemedString( PeakComboAward pma ); -PeakComboAward StringToPeakComboAward( CString pma ); +PeakComboAward StringToPeakComboAward( const CString& pma ); #endif diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index ef81001f39..480c50b6cb 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -93,7 +93,7 @@ void GameState::Reset() m_PreferredDifficulty[p] = DIFFICULTY_INVALID; m_CourseDifficulty[p] = COURSE_DIFFICULTY_REGULAR; } - m_SongSortOrder = SORT_INVALID; + m_SortOrder = SORT_INVALID; m_PlayMode = PLAY_MODE_INVALID; m_bEditing = false; m_bDemonstrationOrJukebox = false; diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 796d92b5c2..a691fc563f 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -102,7 +102,7 @@ public: CString m_sPreferredGroup; // GROUP_ALL_MUSIC denotes no preferred group bool m_bChangedFailType; // true if FailType was changed in the song options screen Difficulty m_PreferredDifficulty[NUM_PLAYERS]; - SongSortOrder m_SongSortOrder; // used by MusicWheel + SortOrder m_SortOrder; // used by MusicWheel bool m_bEditing; // NoteField does special stuff when this is true bool m_bDemonstrationOrJukebox; // ScreenGameplay does special stuff when this is true bool m_bJukeboxUsesModifiers; diff --git a/stepmania/src/MusicSortDisplay.cpp b/stepmania/src/MusicSortDisplay.cpp index af30233821..bfc124e1a9 100644 --- a/stepmania/src/MusicSortDisplay.cpp +++ b/stepmania/src/MusicSortDisplay.cpp @@ -23,7 +23,7 @@ MusicSortDisplay::MusicSortDisplay() { } -void MusicSortDisplay::Set( SongSortOrder so ) +void MusicSortDisplay::Set( SortOrder so ) { - Load( THEME->GetPathToG(ssprintf("MusicSortDisplay %s",SongSortOrderToString(so).c_str())) ); + Load( THEME->GetPathToG(ssprintf("MusicSortDisplay %s",SortOrderToString(so).c_str())) ); } diff --git a/stepmania/src/MusicSortDisplay.h b/stepmania/src/MusicSortDisplay.h index 409154e5c0..6437b86c27 100644 --- a/stepmania/src/MusicSortDisplay.h +++ b/stepmania/src/MusicSortDisplay.h @@ -23,7 +23,7 @@ class MusicSortDisplay : public Sprite { public: MusicSortDisplay(); - void Set( SongSortOrder so ); + void Set( SortOrder so ); protected: diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index b0154ad776..94934b088a 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -33,6 +33,7 @@ #include "UnlockSystem.h" #include "ModeChoice.h" #include "ActorUtil.h" +#include "ProfileManager.h" #define FADE_SECONDS THEME->GetMetricF("MusicWheel","FadeSeconds") @@ -72,7 +73,7 @@ CachedThemeMetricI NUM_WHEEL_ITEMS_METRIC ("MusicWheel","NumWheelItems"); const int MAX_WHEEL_SOUND_SPEED = 15; -static const SongSortOrder SortOrder[] = +static const SortOrder SORT_ORDERS[] = { SORT_GROUP, SORT_TITLE, @@ -130,7 +131,7 @@ void MusicWheel::Load() m_iSelection = 0; - m_LastSongSortOrder = SORT_INVALID; + m_LastSortOrder = SORT_INVALID; m_WheelState = STATE_SELECTING_MUSIC; m_fTimeLeftInState = 0; @@ -172,16 +173,32 @@ void MusicWheel::Load() GAMESTATE->m_SongOptions = so; } - if( GAMESTATE->m_SongSortOrder == SORT_INVALID ) + if( GAMESTATE->m_SortOrder == SORT_INVALID ) { switch( GAMESTATE->m_PlayMode ) { - case PLAY_MODE_ONI: GAMESTATE->m_SongSortOrder = SORT_ONI_COURSES; break; - case PLAY_MODE_NONSTOP: GAMESTATE->m_SongSortOrder = SORT_NONSTOP_COURSES; break; - case PLAY_MODE_ENDLESS: GAMESTATE->m_SongSortOrder = SORT_ENDLESS_COURSES; break; + case PLAY_MODE_ONI: GAMESTATE->m_SortOrder = SORT_ONI_COURSES; break; + case PLAY_MODE_NONSTOP: GAMESTATE->m_SortOrder = SORT_NONSTOP_COURSES; break; + case PLAY_MODE_ENDLESS: GAMESTATE->m_SortOrder = SORT_ENDLESS_COURSES; break; default: - GAMESTATE->m_SongSortOrder = StringToSongSortOrder( DEFAULT_SORT ); - ASSERT( GAMESTATE->m_SongSortOrder != SORT_INVALID ); + // look for a player's saved sort + FOREACH_HumanPlayer( pn ) + { + if( PROFILEMAN->IsUsingProfile(pn) ) + { + GAMESTATE->m_SortOrder = PROFILEMAN->GetProfile(pn)->m_SortOrder; + if( GAMESTATE->m_SortOrder != SORT_INVALID ) // we found one + break; // stop searching + } + } + + // if no player preferred sort, fall back to theme default + if( GAMESTATE->m_SortOrder == SORT_INVALID ) + { + GAMESTATE->m_SortOrder = StringToSortOrder( DEFAULT_SORT ); + ASSERT( GAMESTATE->m_SortOrder != SORT_INVALID ); + } + break; } } @@ -200,7 +217,7 @@ void MusicWheel::Load() * the extra stage, so it knows to always display it. */ for( int so=0; soTrace( "took: %s", times.c_str() ); @@ -238,7 +255,7 @@ bool MusicWheel::SelectSongOrCourse() return true; // Select the first selectable song based on the sort order... - vector &wiWheelItems = m_WheelItemDatas[GAMESTATE->m_SongSortOrder]; + vector &wiWheelItems = m_WheelItemDatas[GAMESTATE->m_SortOrder]; for( unsigned i = 0; i < wiWheelItems.size(); i++ ) { if( wiWheelItems[i].m_pSong ) @@ -259,7 +276,7 @@ bool MusicWheel::SelectSong( Song *p ) GAMESTATE->m_pCurSong = p; unsigned i; - vector &from = m_WheelItemDatas[GAMESTATE->m_SongSortOrder]; + vector &from = m_WheelItemDatas[GAMESTATE->m_SortOrder]; for( i=0; im_pCurCourse = p; unsigned i; - vector &from = m_WheelItemDatas[GAMESTATE->m_SongSortOrder]; + vector &from = m_WheelItemDatas[GAMESTATE->m_SortOrder]; for( i=0; i &from = m_WheelItemDatas[GAMESTATE->m_SongSortOrder]; + vector &from = m_WheelItemDatas[GAMESTATE->m_SortOrder]; for( i=0; im_SongSortOrder != so ) + if( m_CurWheelItemData[i]->m_SortOrder != so ) continue; if( !m_CurWheelItemData[i]->m_Action.DescribesCurrentModeForAllPlayers() ) continue; @@ -347,7 +364,7 @@ bool MusicWheel::SelectSort( SongSortOrder so ) return true; } -void MusicWheel::GetSongList(vector &arraySongs, SongSortOrder so, CString sPreferredGroup ) +void MusicWheel::GetSongList(vector &arraySongs, SortOrder so, CString sPreferredGroup ) { vector apAllSongs; // if( so==SORT_PREFERRED && GAMESTATE->m_sPreferredGroup!=GROUP_ALL_MUSIC) @@ -393,7 +410,7 @@ void MusicWheel::GetSongList(vector &arraySongs, SongSortOrder so, CStrin -void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas, SongSortOrder so ) +void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas, SortOrder so ) { unsigned i; @@ -417,13 +434,13 @@ void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas vector parts; split( Actions[i], ";", parts ); - SongSortOrder so = SORT_GROUP; + SortOrder so = SORT_GROUP; for( unsigned j = 0; j < parts.size(); ++j ) { CStringArray asBits; split( parts[j], ",", asBits ); if( !asBits[0].CompareNoCase("sort") ) - so = StringToSongSortOrder( asBits[1] ); + so = StringToSortOrder( asBits[1] ); } WheelItemData wid( TYPE_SORT, NULL, "", NULL, SORT_MENU_COLOR, so ); @@ -894,14 +911,14 @@ void MusicWheel::Update( float fDeltaTime ) SCREENMAN->PostMessageToTopScreen( SM_SortOrderChanged, 0 ); - SetOpenGroup(GetSectionNameFromSongAndSort( pPrevSelectedSong, GAMESTATE->m_SongSortOrder )); + SetOpenGroup(GetSectionNameFromSongAndSort( pPrevSelectedSong, GAMESTATE->m_SortOrder )); m_iSelection = 0; // // Select the previously selected item // - switch( GAMESTATE->m_SongSortOrder ) + switch( GAMESTATE->m_SortOrder ) { default: // Look for the last selected song or course @@ -909,7 +926,7 @@ void MusicWheel::Update( float fDeltaTime ) break; case SORT_SORT_MENU: case SORT_MODE_MENU: - SelectSort( m_LastSongSortOrder ); + SelectSort( m_LastSortOrder ); break; } @@ -917,7 +934,7 @@ void MusicWheel::Update( float fDeltaTime ) // Change difficulty for sorts by meter // Difficulty dc = DIFFICULTY_INVALID; - switch( GAMESTATE->m_SongSortOrder ) + switch( GAMESTATE->m_SortOrder ) { case SORT_EASY_METER: dc = DIFFICULTY_EASY; break; case SORT_MEDIUM_METER: dc = DIFFICULTY_MEDIUM; break; @@ -939,7 +956,7 @@ void MusicWheel::Update( float fDeltaTime ) * back on the default song. From the CVS commit, this looks like it * was originally to fix ScreenOptionsMaster difficulty display, and * isn't needed anymore ... -glenn */ -/* switch( GAMESTATE->m_SongSortOrder ) +/* switch( GAMESTATE->m_SortOrder ) { case SORT_PREFERRED: case SORT_GROUP: @@ -1130,10 +1147,10 @@ void MusicWheel::ChangeMusic(int dist) m_soundChangeMusic.Play(); } -bool MusicWheel::ChangeSort( SongSortOrder new_so ) // return true if change successful +bool MusicWheel::ChangeSort( SortOrder new_so ) // return true if change successful { ASSERT( new_so < NUM_SORT_ORDERS ); - if( GAMESTATE->m_SongSortOrder == new_so ) + if( GAMESTATE->m_SortOrder == new_so ) return false; switch( m_WheelState ) @@ -1151,8 +1168,19 @@ bool MusicWheel::ChangeSort( SongSortOrder new_so ) // return true if change suc TweenOffScreen(true); - m_LastSongSortOrder = GAMESTATE->m_SongSortOrder; - GAMESTATE->m_SongSortOrder = new_so; + m_LastSortOrder = GAMESTATE->m_SortOrder; + GAMESTATE->m_SortOrder = new_so; + + // Save the new sort to all profiles + // HACK: Don't save course sorts + if( IsSongSort(new_so) ) + { + FOREACH_HumanPlayer( pn ) + { + if( PROFILEMAN->IsUsingProfile(pn) ) + PROFILEMAN->GetProfile(pn)->m_SortOrder = new_so; + } + } m_WheelState = STATE_FLYING_OFF_BEFORE_NEXT_SORT; return true; @@ -1161,7 +1189,7 @@ bool MusicWheel::ChangeSort( SongSortOrder new_so ) // return true if change suc bool MusicWheel::NextSort() // return true if change successful { // don't allow NextSort when on the sort menu or mode menu - switch( GAMESTATE->m_SongSortOrder ) + switch( GAMESTATE->m_SortOrder ) { case SORT_SORT_MENU: case SORT_MODE_MENU: @@ -1170,15 +1198,15 @@ bool MusicWheel::NextSort() // return true if change successful // find the index of the current sort int cur = 0; - while( cur < int(ARRAYSIZE(SortOrder)) && SortOrder[cur] != GAMESTATE->m_SongSortOrder ) + while( cur < int(ARRAYSIZE(SORT_ORDERS)) && SORT_ORDERS[cur] != GAMESTATE->m_SortOrder ) ++cur; // move to the next sort with wrapping ++cur; - wrap( cur, ARRAYSIZE(SortOrder) ); + wrap( cur, ARRAYSIZE(SORT_ORDERS) ); // apply new sort - SongSortOrder soNew = SortOrder[cur]; + SortOrder soNew = SORT_ORDERS[cur]; return ChangeSort( soNew ); } @@ -1239,8 +1267,8 @@ bool MusicWheel::Select() // return true if this selection ends the screen return true; case TYPE_SORT: m_CurWheelItemData[m_iSelection]->m_Action.ApplyToAllPlayers(); - LOG->Trace("New sort order selected: %s - %d", m_CurWheelItemData[m_iSelection]->m_sLabel.c_str(), m_CurWheelItemData[m_iSelection]->m_SongSortOrder ); - ChangeSort( m_CurWheelItemData[m_iSelection]->m_SongSortOrder ); + LOG->Trace("New sort order selected: %s - %d", m_CurWheelItemData[m_iSelection]->m_sLabel.c_str(), m_CurWheelItemData[m_iSelection]->m_SortOrder ); + ChangeSort( m_CurWheelItemData[m_iSelection]->m_SortOrder ); return false; default: ASSERT(0); @@ -1254,7 +1282,7 @@ void MusicWheel::StartRoulette() m_Moving = 1; m_TimeBeforeMovingBegins = 0; m_SpinSpeed = 1.0f/ROULETTE_SWITCH_SECONDS; - SetOpenGroup("", SongSortOrder(SORT_ROULETTE)); + SetOpenGroup("", SortOrder(SORT_ROULETTE)); } void MusicWheel::StartRandom() @@ -1265,7 +1293,7 @@ void MusicWheel::StartRandom() RandomGen rnd; random_shuffle( m_WheelItemDatas[SORT_ROULETTE].begin(), m_WheelItemDatas[SORT_ROULETTE].end(), rnd ); - SetOpenGroup("", SongSortOrder(SORT_ROULETTE)); + SetOpenGroup("", SortOrder(SORT_ROULETTE)); m_Moving = -1; m_TimeBeforeMovingBegins = 0; @@ -1287,10 +1315,10 @@ void MusicWheel::StartRandom() } } -void MusicWheel::SetOpenGroup(CString group, SongSortOrder so) +void MusicWheel::SetOpenGroup(CString group, SortOrder so) { if( so == SORT_INVALID) - so = GAMESTATE->m_SongSortOrder; + so = GAMESTATE->m_SortOrder; m_sExpandedSectionName = group; diff --git a/stepmania/src/MusicWheel.h b/stepmania/src/MusicWheel.h index b9eeb93a0e..52005cb8b7 100644 --- a/stepmania/src/MusicWheel.h +++ b/stepmania/src/MusicWheel.h @@ -54,7 +54,7 @@ public: virtual void TweenOffScreen() { TweenOffScreen(false); } void Move(int n); - bool ChangeSort( SongSortOrder new_so ); // return true if change successful + bool ChangeSort( SortOrder new_so ); // return true if change successful bool NextSort(); // return true if change successful void StartRoulette(); void StartRandom(); @@ -77,13 +77,13 @@ public: void RebuildMusicWheelItems(); protected: - void GetSongList(vector &arraySongs, SongSortOrder so, CString sPreferredGroup ); - void BuildWheelItemDatas( vector &arrayWheelItems, SongSortOrder so ); - void SetOpenGroup(CString group, SongSortOrder so = SORT_INVALID); + void GetSongList(vector &arraySongs, SortOrder so, CString sPreferredGroup ); + void BuildWheelItemDatas( vector &arrayWheelItems, SortOrder so ); + void SetOpenGroup(CString group, SortOrder so = SORT_INVALID); bool SelectSongOrCourse(); bool SelectSong( Song *p ); bool SelectCourse( Course *p ); - bool SelectSort( SongSortOrder so ); + bool SelectSort( SortOrder so ); void ChangeMusic(int dist); /* +1 or -1 */ ScrollBar m_ScrollBar; @@ -96,7 +96,7 @@ protected: int m_iSelection; // index into m_CurWheelItemData CString m_sExpandedSectionName; - SongSortOrder m_LastSongSortOrder; + SortOrder m_LastSortOrder; int m_iSwitchesLeftInSpinDown; float m_fLockedWheelVelocity; diff --git a/stepmania/src/MusicWheelItem.cpp b/stepmania/src/MusicWheelItem.cpp index ca942e8e0e..b5b7513460 100644 --- a/stepmania/src/MusicWheelItem.cpp +++ b/stepmania/src/MusicWheelItem.cpp @@ -42,7 +42,7 @@ -WheelItemData::WheelItemData( WheelItemType wit, Song* pSong, CString sSectionName, Course* pCourse, RageColor color, SongSortOrder so ) +WheelItemData::WheelItemData( WheelItemType wit, Song* pSong, CString sSectionName, Course* pCourse, RageColor color, SortOrder so ) { m_Type = wit; m_pSong = pSong; @@ -50,7 +50,7 @@ WheelItemData::WheelItemData( WheelItemType wit, Song* pSong, CString sSectionNa m_pCourse = pCourse; m_color = color; m_Flags = WheelNotifyIcon::Flags(); - m_SongSortOrder = so; + m_SortOrder = so; } diff --git a/stepmania/src/MusicWheelItem.h b/stepmania/src/MusicWheelItem.h index 1ffef78af5..781d897754 100644 --- a/stepmania/src/MusicWheelItem.h +++ b/stepmania/src/MusicWheelItem.h @@ -65,7 +65,7 @@ enum WheelItemType { TYPE_SECTION, TYPE_SONG, TYPE_ROULETTE, TYPE_RANDOM, TYPE_C struct WheelItemData { WheelItemData() {} - WheelItemData( WheelItemType wit, Song* pSong, CString sSectionName, Course* pCourse, RageColor color, SongSortOrder so ); + WheelItemData( WheelItemType wit, Song* pSong, CString sSectionName, Course* pCourse, RageColor color, SortOrder so ); bool HasBanner() const; CString GetBanner() const; @@ -80,7 +80,7 @@ struct WheelItemData // for TYPE_SORT CString m_sLabel; ModeChoice m_Action; - SongSortOrder m_SongSortOrder; + SortOrder m_SortOrder; }; #endif diff --git a/stepmania/src/PaneDisplay.cpp b/stepmania/src/PaneDisplay.cpp index 57b63e812d..f6481b7b83 100644 --- a/stepmania/src/PaneDisplay.cpp +++ b/stepmania/src/PaneDisplay.cpp @@ -344,7 +344,7 @@ void PaneDisplay::SetFromGameState() PaneModes PaneDisplay::GetMode() const { - switch( GAMESTATE->m_SongSortOrder ) + switch( GAMESTATE->m_SortOrder ) { case SORT_ALL_COURSES: case SORT_NONSTOP_COURSES: diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index fab38aaaef..d7b50c4747 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -68,6 +68,7 @@ void Profile::InitGeneralData() { m_bUsingProfileDefaultModifiers = false; m_sDefaultModifiers = ""; + m_SortOrder = SORT_INVALID; m_iTotalPlays = 0; m_iTotalPlaySeconds = 0; m_iTotalGameplaySeconds = 0; @@ -566,6 +567,7 @@ XNode* Profile::SaveGeneralDataCreateNode() const pGeneralDataNode->AppendChild( "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers ); pGeneralDataNode->AppendChild( "DefaultModifiers", m_sDefaultModifiers ); + pGeneralDataNode->AppendChild( "SortOrder", SortOrderToString(m_SortOrder) ); pGeneralDataNode->AppendChild( "TotalPlays", m_iTotalPlays ); pGeneralDataNode->AppendChild( "TotalPlaySeconds", m_iTotalPlaySeconds ); pGeneralDataNode->AppendChild( "TotalGameplaySeconds", m_iTotalGameplaySeconds ); @@ -700,6 +702,9 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode ) pNode->GetChildValue( "UsingProfileDefaultModifiers", m_bUsingProfileDefaultModifiers ); pNode->GetChildValue( "DefaultModifiers", m_sDefaultModifiers ); + CString sSortOrder; + pNode->GetChildValue( "SortOrder", sSortOrder ); + m_SortOrder = StringToSortOrder( sSortOrder ); pNode->GetChildValue( "TotalPlays", m_iTotalPlays ); pNode->GetChildValue( "TotalPlaySeconds", m_iTotalPlaySeconds ); pNode->GetChildValue( "TotalGameplaySeconds", m_iTotalGameplaySeconds ); diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 753369bb8c..89eb1ff2b2 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -88,6 +88,7 @@ public: // bool m_bUsingProfileDefaultModifiers; CString m_sDefaultModifiers; + SortOrder m_SortOrder; int m_iTotalPlays; int m_iTotalPlaySeconds; int m_iTotalGameplaySeconds; diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 8736f3d0f9..a9562ce76e 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -288,7 +288,7 @@ ScreenSelectMusic::ScreenSelectMusic( CString sClassName ) : Screen( sClassName } m_MusicSortDisplay.SetName( "SortIcon" ); - m_MusicSortDisplay.Set( GAMESTATE->m_SongSortOrder ); + m_MusicSortDisplay.Set( GAMESTATE->m_SortOrder ); SET_XY( m_MusicSortDisplay ); this->AddChild( &m_MusicSortDisplay ); @@ -499,7 +499,7 @@ void ScreenSelectMusic::TweenOnScreen() TweenSongPartsOnScreen( true ); TweenCoursePartsOnScreen( true ); - switch( GAMESTATE->m_SongSortOrder ) + switch( GAMESTATE->m_SortOrder ) { case SORT_ALL_COURSES: case SORT_NONSTOP_COURSES: @@ -552,7 +552,7 @@ void ScreenSelectMusic::TweenOnScreen() void ScreenSelectMusic::TweenOffScreen() { - switch( GAMESTATE->m_SongSortOrder ) + switch( GAMESTATE->m_SortOrder ) { case SORT_ALL_COURSES: case SORT_NONSTOP_COURSES: @@ -632,7 +632,7 @@ void ScreenSelectMusic::TweenScoreOnAndOffAfterChangeSort() m_sprHighScoreFrame[p].Command( SCORE_FRAME_SORT_CHANGE_COMMAND(p) ); } - switch( GAMESTATE->m_SongSortOrder ) + switch( GAMESTATE->m_SortOrder ) { case SORT_ALL_COURSES: case SORT_NONSTOP_COURSES: @@ -1498,9 +1498,9 @@ void ScreenSelectMusic::UpdateOptionsDisplays() void ScreenSelectMusic::SortOrderChanged() { - m_MusicSortDisplay.Set( GAMESTATE->m_SongSortOrder ); + m_MusicSortDisplay.Set( GAMESTATE->m_SortOrder ); - switch( GAMESTATE->m_SongSortOrder ) + switch( GAMESTATE->m_SortOrder ) { case SORT_ALL_COURSES: case SORT_NONSTOP_COURSES: diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index c36a84cfad..a5dc83583e 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -1393,7 +1393,7 @@ void SortSongPointerArrayByNumPlays( vector &arraySongPointers, const Pro song_sort_val.clear(); } -CString GetSectionNameFromSongAndSort( const Song* pSong, SongSortOrder so ) +CString GetSectionNameFromSongAndSort( const Song* pSong, SortOrder so ) { if( pSong == NULL ) return ""; @@ -1488,7 +1488,7 @@ CString GetSectionNameFromSongAndSort( const Song* pSong, SongSortOrder so ) } } -void SortSongPointerArrayBySectionName( vector &arraySongPointers, SongSortOrder so ) +void SortSongPointerArrayBySectionName( vector &arraySongPointers, SortOrder so ) { for(unsigned i = 0; i < arraySongPointers.size(); ++i) { diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 1d2f05ae0c..6aa62c50df 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -215,8 +215,8 @@ void SortSongPointerArrayByGroupAndTitle( vector &arraySongPointers ); void SortSongPointerArrayByNumPlays( vector &arraySongPointers, ProfileSlot slot, bool bDescending ); void SortSongPointerArrayByNumPlays( vector &arraySongPointers, const Profile* pProfile, bool bDescending ); void SortSongPointerArrayByMeter( vector &arraySongPointers, Difficulty dc ); -CString GetSectionNameFromSongAndSort( const Song* pSong, SongSortOrder so ); -void SortSongPointerArrayBySectionName( vector &arraySongPointers, SongSortOrder so ); +CString GetSectionNameFromSongAndSort( const Song* pSong, SortOrder so ); +void SortSongPointerArrayBySectionName( vector &arraySongPointers, SortOrder so );