revert from in-memory copy, not from disk

This commit is contained in:
Chris Danford
2005-03-08 21:19:17 +00:00
parent 38bd0116d1
commit dc9e8e23ff
2 changed files with 52 additions and 70 deletions
+42 -69
View File
@@ -67,7 +67,7 @@ const ScreenMessage SM_BackFromInsertAttack = (ScreenMessage)(SM_User+9);
const ScreenMessage SM_BackFromInsertAttackModifiers= (ScreenMessage)(SM_User+10); const ScreenMessage SM_BackFromInsertAttackModifiers= (ScreenMessage)(SM_User+10);
const ScreenMessage SM_BackFromPrefs = (ScreenMessage)(SM_User+11); const ScreenMessage SM_BackFromPrefs = (ScreenMessage)(SM_User+11);
const ScreenMessage SM_BackFromCourseModeMenu = (ScreenMessage)(SM_User+12); const ScreenMessage SM_BackFromCourseModeMenu = (ScreenMessage)(SM_User+12);
const ScreenMessage SM_DoReloadFromDisk = (ScreenMessage)(SM_User+13); const ScreenMessage SM_DoRevertToLastSave = (ScreenMessage)(SM_User+13);
const ScreenMessage SM_DoUpdateTextInfo = (ScreenMessage)(SM_User+14); const ScreenMessage SM_DoUpdateTextInfo = (ScreenMessage)(SM_User+14);
const ScreenMessage SM_BackFromBPMChange = (ScreenMessage)(SM_User+15); const ScreenMessage SM_BackFromBPMChange = (ScreenMessage)(SM_User+15);
const ScreenMessage SM_BackFromStopChange = (ScreenMessage)(SM_User+16); const ScreenMessage SM_BackFromStopChange = (ScreenMessage)(SM_User+16);
@@ -372,7 +372,7 @@ static const MenuRow g_MainMenuItems[] =
{ ScreenEdit::play_whole_song, "Play Whole Song", true, true, 0, { NULL } }, { ScreenEdit::play_whole_song, "Play Whole Song", true, true, 0, { NULL } },
{ ScreenEdit::play_current_beat_to_end, "Play Current Beat To End", true, true, 0, { NULL } }, { ScreenEdit::play_current_beat_to_end, "Play Current Beat To End", true, true, 0, { NULL } },
{ ScreenEdit::save, "Save", true, true, 0, { NULL } }, { ScreenEdit::save, "Save", true, true, 0, { NULL } },
{ ScreenEdit::reload, "Revert", true, true, 0, { NULL } }, { ScreenEdit::revert_to_last_save, "Revert to Last Save", true, true, 0, { NULL } },
{ ScreenEdit::player_options, "Player Options", true, true, 0, { NULL } }, { ScreenEdit::player_options, "Player Options", true, true, 0, { NULL } },
{ ScreenEdit::song_options, "Song Options", true, false, 0, { NULL } }, { ScreenEdit::song_options, "Song Options", true, false, 0, { NULL } },
{ ScreenEdit::edit_song_info, "Edit Song Info", true, false, 0, { NULL } }, { ScreenEdit::edit_song_info, "Edit Song Info", true, false, 0, { NULL } },
@@ -504,6 +504,11 @@ void ScreenEdit::Init()
/* We do this ourself. */ /* We do this ourself. */
SOUND->HandleSongTimer( false ); SOUND->HandleSongTimer( false );
// save the originals for reverting later
CopyToLastSave();
// set both players to joined so the credit message doesn't show // set both players to joined so the credit message doesn't show
FOREACH_PlayerNumber( p ) FOREACH_PlayerNumber( p )
GAMESTATE->m_bSideIsJoined[p] = true; GAMESTATE->m_bSideIsJoined[p] = true;
@@ -1489,24 +1494,12 @@ void ScreenEdit::TransitionFromRecordToEdit()
m_NoteDataRecord.ClearAll(); m_NoteDataRecord.ClearAll();
} }
/* Helper for SM_DoReloadFromDisk */
static bool g_DoReload;
void ReloadFromDisk( void *p )
{
g_DoReload = true;
}
void ScreenEdit::HandleScreenMessage( const ScreenMessage SM ) void ScreenEdit::HandleScreenMessage( const ScreenMessage SM )
{ {
switch( SM ) switch( SM )
{ {
case SM_GoToNextScreen: case SM_GoToNextScreen:
// Reload song from disk to discard changes. CopyFromLastSave();
SONGMAN->RevertFromDisk( GAMESTATE->m_pCurSong, true );
/* We might do something with m_pSteps (eg. UpdateTextInfo) before we end up
* in ScreenEditMenu, and m_pSteps might be invalid due to RevertFromDisk. */
m_pSteps = GAMESTATE->m_pCurSteps[PLAYER_1];
SCREENMAN->SetNewScreen( "ScreenEditMenu" ); SCREENMAN->SetNewScreen( "ScreenEditMenu" );
@@ -1591,52 +1584,14 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM )
GAMESTATE->RestoreSelectedOptions(); // restore the edit and playback options GAMESTATE->RestoreSelectedOptions(); // restore the edit and playback options
} }
break; break;
case SM_DoReloadFromDisk: case SM_DoRevertToLastSave:
{ if( ScreenPrompt::s_LastAnswer == ANSWER_YES )
if( !g_DoReload )
return;
const StepsType st = m_pSteps->m_StepsType;
StepsID id;
id.FromSteps( m_pSteps );
GAMESTATE->m_pCurSteps[PLAYER_1].Set( NULL ); /* make RevertFromDisk not try to reset it */
SONGMAN->RevertFromDisk( GAMESTATE->m_pCurSong );
CString sMessage = "Reloaded from disk.";
Steps *pSteps = id.ToSteps( GAMESTATE->m_pCurSong, false );
// Don't allow an autogen match. This can't be what they chose to
// edit originally because autogen steps are hidden.
if( pSteps && pSteps->IsAutogen() )
pSteps = NULL;
/* If we couldn't find the steps we were on before, warn and use the first available. */
if( pSteps == NULL )
{ {
pSteps = GAMESTATE->m_pCurSong->GetStepsByDifficulty( st, DIFFICULTY_INVALID, false ); CopyFromLastSave();
if( pSteps ) m_pSteps->GetNoteData( m_NoteDataEdit );
sMessage = ssprintf( "old steps not found; changed to %s.",
DifficultyToString(pSteps->GetDifficulty()).c_str() );
} }
/* If we still couldn't find any steps, then all steps of the current StepsType
* were removed. Don't create them; only do that in EditMenu. */
if( pSteps == NULL )
{
SCREENMAN->SetNewScreen( "ScreenEditMenu" );
return;
}
SCREENMAN->SystemMessage( sMessage );
m_pSteps = pSteps;
GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps );
m_pSteps->GetNoteData( m_NoteDataEdit );
break; break;
}
case SM_DoUpdateTextInfo: case SM_DoUpdateTextInfo:
this->PostScreenMessage( SM_DoUpdateTextInfo, 0.5f ); this->PostScreenMessage( SM_DoUpdateTextInfo, 0.5f );
UpdateTextInfo(); UpdateTextInfo();
@@ -1645,6 +1600,8 @@ void ScreenEdit::HandleScreenMessage( const ScreenMessage SM )
case SM_DoExit: case SM_DoExit:
if( ScreenPrompt::s_LastAnswer != ANSWER_CANCEL ) if( ScreenPrompt::s_LastAnswer != ANSWER_CANCEL )
{ {
CopyFromLastSave();
// If these steps have never been saved, then we should delete them. // If these steps have never been saved, then we should delete them.
// If the user created them in the edit menu and never bothered // If the user created them in the edit menu and never bothered
// to save them, then they aren't wanted. // to save them, then they aren't wanted.
@@ -1798,6 +1755,10 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, int* iAnswers )
pSteps->SetNoteData( m_NoteDataEdit ); pSteps->SetNoteData( m_NoteDataEdit );
pSteps->SetSavedToDisk( true ); pSteps->SetSavedToDisk( true );
CopyToLastSave();
if( HOME_EDIT_MODE ) if( HOME_EDIT_MODE )
{ {
CString s; CString s;
@@ -1813,23 +1774,23 @@ void ScreenEdit::HandleMainMenuChoice( MainMenuChoice c, int* iAnswers )
{ {
GAMESTATE->m_pCurSong->Save(); GAMESTATE->m_pCurSong->Save();
SCREENMAN->ZeroNextUpdate(); SCREENMAN->ZeroNextUpdate();
// we shouldn't say we're saving a DWI if we're on any game besides
// dance, it just looks tacky and people may be wondering where the
// DWI file is :-)
if ((int)pSteps->m_StepsType <= (int)STEPS_TYPE_DANCE_SOLO)
SCREENMAN->SystemMessage( "Saved as SM and DWI." );
else
SCREENMAN->SystemMessage( "Saved as SM." );
} }
// we shouldn't say we're saving a DWI if we're on any game besides
// dance, it just looks tacky and people may be wondering where the
// DWI file is :-)
if ((int)pSteps->m_StepsType <= (int)STEPS_TYPE_DANCE_SOLO)
SCREENMAN->SystemMessage( "Saved as SM and DWI." );
else
SCREENMAN->SystemMessage( "Saved as SM." );
SOUND->PlayOnce( THEME->GetPathS("ScreenEdit","save") ); SOUND->PlayOnce( THEME->GetPathS("ScreenEdit","save") );
} }
break; break;
case reload: case revert_to_last_save:
g_DoReload = false; SCREENMAN->Prompt( SM_DoRevertToLastSave,
SCREENMAN->Prompt( SM_DoReloadFromDisk, "Do you want to revert to your last save?\n\nThis will destroy all unsaved changes.",
"Do you want to reload from disk?\n\nThis will destroy all changes.", PROMPT_YES_NO, ANSWER_NO );
PROMPT_YES_NO, ANSWER_NO, ReloadFromDisk, NULL, NULL );
break; break;
case player_options: case player_options:
SCREENMAN->AddNewScreenToTop( "ScreenPlayerOptions", SM_BackFromPlayerOptions ); SCREENMAN->AddNewScreenToTop( "ScreenPlayerOptions", SM_BackFromPlayerOptions );
@@ -2454,6 +2415,18 @@ void ScreenEdit::SetupCourseAttacks()
GAMESTATE->RebuildPlayerOptionsFromActiveAttacks( PLAYER_1 ); GAMESTATE->RebuildPlayerOptionsFromActiveAttacks( PLAYER_1 );
} }
void ScreenEdit::CopyToLastSave()
{
m_songLastSave = *GAMESTATE->m_pCurSong;
m_stepsLastSave = *GAMESTATE->m_pCurSteps[PLAYER_1];
}
void ScreenEdit::CopyFromLastSave()
{
*GAMESTATE->m_pCurSong = m_songLastSave;
*GAMESTATE->m_pCurSteps[PLAYER_1] = m_stepsLastSave;
}
/* /*
* (c) 2001-2004 Chris Danford * (c) 2001-2004 Chris Danford
* All rights reserved. * All rights reserved.
+10 -1
View File
@@ -14,6 +14,8 @@
#include "Foreground.h" #include "Foreground.h"
#include "Course.h" #include "Course.h"
#include "NoteField.h" #include "NoteField.h"
#include "song.h"
#include "Steps.h"
const int NUM_ACTION_MENU_ITEMS = 23; const int NUM_ACTION_MENU_ITEMS = 23;
const int NUM_NAMING_MENU_ITEMS = 6; const int NUM_NAMING_MENU_ITEMS = 6;
@@ -174,6 +176,13 @@ protected:
Transition m_In; Transition m_In;
Transition m_Out; Transition m_Out;
// used for reverting
void CopyToLastSave();
void CopyFromLastSave();
Song m_songLastSave;
Steps m_stepsLastSave;
// for MODE_RECORD // for MODE_RECORD
@@ -201,7 +210,7 @@ public:
play_whole_song, play_whole_song,
play_current_beat_to_end, play_current_beat_to_end,
save, save,
reload, revert_to_last_save,
player_options, player_options,
song_options, song_options,
edit_song_info, edit_song_info,