From 6a78f96258820ffa11ff68914cd3435ee88b82aa Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 18 Feb 2004 23:53:43 +0000 Subject: [PATCH] fix current song/course being reset after changing modes set GAMESTATE->m_pCurSong/Course immediately when moving --- stepmania/src/MusicWheel.cpp | 89 ++++++++++++++++-------------------- stepmania/src/MusicWheel.h | 5 +- 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index dedde8ec7d..c1aed22a56 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -210,30 +210,9 @@ void MusicWheel::Load() && !GAMESTATE->IsExtraStage() && !GAMESTATE->IsExtraStage2() ) GAMESTATE->m_pCurSong = NULL; - // If there is no currently selected song, select one. - if( GAMESTATE->m_pCurSong == NULL ) - { - //Select the first selectable song based on the sort order... - vector &wiWheelItems = m_WheelItemDatas[GAMESTATE->m_SongSortOrder]; - for( unsigned i = 0; i < wiWheelItems.size(); i++ ) - { - if( wiWheelItems[i].m_pSong != NULL ) - { - GAMESTATE->m_pCurSong = wiWheelItems[i].m_pSong; - break; - } - } - - if( GAMESTATE->m_pCurSong == NULL ) - LOG->Trace("MusicWheel::MusicWheel() - No selectable songs found in WheelData"); - } - - // Select the the previously selected song (if any) - bool selected = SelectSong(GAMESTATE->m_pCurSong); - // Select the the previously selected course (if any) - if(!selected) selected = SelectCourse(GAMESTATE->m_pCurCourse); - if(!selected) SetOpenGroup(""); + if( !SelectSongOrCourse() ) + SetOpenGroup(""); // rebuild the WheelItems that appear on screen RebuildMusicWheelItems(); @@ -243,11 +222,37 @@ MusicWheel::~MusicWheel() { } -bool MusicWheel::SelectSong( const Song *p ) +/* If a song or course is set in GAMESTATE and avaialble, select it. Otherwise, choose the + * first available song or course. Return true if an item was set, false if no items are + * available. */ +bool MusicWheel::SelectSongOrCourse() +{ + if( GAMESTATE->m_pCurSong && SelectSong( GAMESTATE->m_pCurSong ) ) + return true; + if( GAMESTATE->m_pCurCourse && SelectCourse( GAMESTATE->m_pCurCourse ) ) + return true; + + // Select the first selectable song based on the sort order... + vector &wiWheelItems = m_WheelItemDatas[GAMESTATE->m_SongSortOrder]; + for( unsigned i = 0; i < wiWheelItems.size(); i++ ) + { + if( wiWheelItems[i].m_pSong ) + return SelectSong( wiWheelItems[i].m_pSong ); + else if ( wiWheelItems[i].m_pCourse ) + return SelectCourse( wiWheelItems[i].m_pCourse ); + } + + LOG->Trace( "MusicWheel::MusicWheel() - No selectable songs or courses found in WheelData" ); + return false; +} + +bool MusicWheel::SelectSong( Song *p ) { if(p == NULL) return false; + GAMESTATE->m_pCurSong = p; + unsigned i; vector &from = m_WheelItemDatas[GAMESTATE->m_SongSortOrder]; for( i=0; im_pCurCourse = p; + unsigned i; vector &from = m_WheelItemDatas[GAMESTATE->m_SongSortOrder]; for( i=0; im_SongSortOrder ) { - case SORT_PREFERRED: - case SORT_GROUP: - case SORT_TITLE: - case SORT_BPM: - case SORT_GRADE: - case SORT_ARTIST: - case SORT_MOST_PLAYED: - case SORT_ROULETTE: - case SORT_EASY_METER: - case SORT_MEDIUM_METER: - case SORT_HARD_METER: - case SORT_CHALLENGE_METER: - case SORT_ALL_COURSES: - case SORT_NONSTOP_COURSES: - case SORT_ONI_COURSES: - case SORT_ENDLESS_COURSES: + default: // Look for the last selected song or course - if( GAMESTATE->m_pCurCourse ) - SelectCourse( GAMESTATE->m_pCurCourse ); - if( GAMESTATE->m_pCurSong ) - SelectSong( GAMESTATE->m_pCurSong ); + SelectSongOrCourse(); break; case SORT_SORT_MENU: case SORT_MODE_MENU: SelectSort( m_LastSongSortOrder ); break; - default: - ASSERT(0); } // @@ -956,7 +943,11 @@ void MusicWheel::Update( float fDeltaTime ) // Unselect the current song if this is a course mode. // Unselect the current course if this is a song sort. // - switch( GAMESTATE->m_SongSortOrder ) + /* If we do this, then switching to course mode and back will put you + * 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 ) { case SORT_PREFERRED: case SORT_GROUP: @@ -979,7 +970,7 @@ void MusicWheel::Update( float fDeltaTime ) GAMESTATE->m_pCurSong = NULL; break; } - +*/ SCREENMAN->PostMessageToTopScreen( SM_SongChanged, 0 ); RebuildMusicWheelItems(); diff --git a/stepmania/src/MusicWheel.h b/stepmania/src/MusicWheel.h index 7f2ce54024..b9eeb93a0e 100644 --- a/stepmania/src/MusicWheel.h +++ b/stepmania/src/MusicWheel.h @@ -80,8 +80,9 @@ protected: void GetSongList(vector &arraySongs, SongSortOrder so, CString sPreferredGroup ); void BuildWheelItemDatas( vector &arrayWheelItems, SongSortOrder so ); void SetOpenGroup(CString group, SongSortOrder so = SORT_INVALID); - bool SelectSong(const Song *p); - bool SelectCourse(const Course *p); + bool SelectSongOrCourse(); + bool SelectSong( Song *p ); + bool SelectCourse( Course *p ); bool SelectSort( SongSortOrder so ); void ChangeMusic(int dist); /* +1 or -1 */