From 9ab281f982cfa5304c8d0f345121fe73f325498e Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 31 Oct 2003 09:42:22 +0000 Subject: [PATCH] fix "auto selection of last edited steps after saving in editor" --- stepmania/src/EditMenu.cpp | 10 ++++++---- stepmania/src/Song.cpp | 33 +++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/stepmania/src/EditMenu.cpp b/stepmania/src/EditMenu.cpp index 74418c3860..a2895ee8e2 100644 --- a/stepmania/src/EditMenu.cpp +++ b/stepmania/src/EditMenu.cpp @@ -125,17 +125,19 @@ EditMenu::EditMenu() OnRowValueChanged( ROW_SONG ); // Select the current StepsType and difficulty if any - if( GAMESTATE->m_pCurNotes ) + if( GAMESTATE->m_pCurNotes && GAMESTATE->m_pCurNotes[PLAYER_1] ) { for( i=0; im_pCurNotes[PLAYER_1]->m_StepsType ) { m_iSelection[ROW_NOTES_TYPE] = i; OnRowValueChanged( ROW_NOTES_TYPE ); + m_iSelection[ROW_DIFFICULTY] = GAMESTATE->m_pCurNotes[PLAYER_1]->GetDifficulty(); + OnRowValueChanged( ROW_DIFFICULTY ); + break; } - - m_iSelection[ROW_DIFFICULTY] = GAMESTATE->m_pCurNotes[PLAYER_1]->GetDifficulty(); - OnRowValueChanged( ROW_DIFFICULTY ); + } } } diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index e58d649da7..5b8a8e6070 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -472,12 +472,23 @@ bool Song::LoadFromSongDir( CString sDir, bool bAllowCache ) void Song::RevertFromDisk() { - unsigned CurNoteIndex[NUM_PLAYERS]; - memset(CurNoteIndex, 0, sizeof(CurNoteIndex)); - for( int pn = 0; pn < NUM_PLAYERS; ++pn ) - for( unsigned n = 0; n < m_apNotes.size(); ++n ) - if( m_apNotes[n] == GAMESTATE->m_pCurNotes[pn] ) - CurNoteIndex[pn] = n; + // Ugly: When we re-load the song, the Steps* will change. + // Fix the GAMESTATE->m_CurNotes after reloading. + StepsType st[NUM_PLAYERS]; + Difficulty dc[NUM_PLAYERS]; + for( int p = 0; p < NUM_PLAYERS; ++p ) + { + if( GAMESTATE->m_pCurNotes[p] == NULL ) + { + st[p] = STEPS_TYPE_INVALID; + dc[p] = DIFFICULTY_INVALID; + } + else + { + st[p] = GAMESTATE->m_pCurNotes[p]->m_StepsType; + dc[p] = GAMESTATE->m_pCurNotes[p]->GetDifficulty(); + } + } const CString dir = GetSongDir(); @@ -488,13 +499,15 @@ void Song::RevertFromDisk() // if they've saved in the editor. LoadFromSongDir( dir, false ); + if( GAMESTATE->m_pCurSong == this ) { - /* m_pCurNotes points at notes that we just reloaded; fix it. */ - for( int pn = 0; pn < NUM_PLAYERS; ++pn ) + for( int p = 0; p < NUM_PLAYERS; ++p ) { - int ind = min(CurNoteIndex[pn], m_apNotes.size()-1); - GAMESTATE->m_pCurNotes[pn] = m_apNotes[ind]; + if( st[p] == STEPS_TYPE_INVALID || dc[p] == DIFFICULTY_INVALID ) + continue; // skip + GAMESTATE->m_pCurNotes[p] = this->GetStepsByDifficulty( st[p], dc[p], false ); + ASSERT( GAMESTATE->m_pCurNotes[p] ); // we had something selected before reloading, so it better still be there after! } } }