Save-state: 1. Added load from backup. 2. Removed save/load "Other..." (not connected to anything anyway)

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4461 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
avihal@gmail.com 2011-03-20 08:01:16 +00:00
parent eccbf165b9
commit bebea985ce
8 changed files with 76 additions and 14 deletions

View File

@ -107,7 +107,8 @@ enum MenuIdentifiers
MenuId_State_Load,
MenuId_State_LoadOther,
MenuId_State_Load01, // first of many load slots
MenuId_State_Save = MenuId_State_Load01+20,
MenuId_State_LoadBackup = MenuId_State_Load01+20,
MenuId_State_Save,
MenuId_State_SaveOther,
MenuId_State_Save01, // first of many save slots

View File

@ -59,9 +59,12 @@ protected:
extern void StateCopy_SaveToFile( const wxString& file );
extern void StateCopy_LoadFromFile( const wxString& file );
extern void StateCopy_SaveToSlot( uint num );
extern void StateCopy_LoadFromSlot( uint slot );
extern void StateCopy_LoadFromSlot( uint slot, bool isFromBackup = false );
extern void States_registerLoadBackupMenuItem( wxMenuItem* loadBackupMenuItem );
extern bool States_isSlotUsed(int num);
extern void States_DefrostCurrentSlotBackup();
extern void States_DefrostCurrentSlot();
extern void States_FreezeCurrentSlot();
extern void States_CycleSlotForward();

View File

@ -275,6 +275,12 @@ static const GlobalCommandDescriptor CommandDeclarations[] =
pxL( "Loads a virtual machine state from the current slot." ),
},
{ "States_DefrostCurrentSlotBackup",
States_DefrostCurrentSlotBackup,
pxL( "Load State Backup" ),
pxL( "Loads virtual machine state backup for current slot." ),
},
{ "States_CycleSlotForward",
States_CycleSlotForward,
pxL( "Cycle to next slot" ),

View File

@ -29,7 +29,7 @@
#endif
// ------------------------------------------------------------------------
wxMenu* MainEmuFrame::MakeStatesSubMenu( int baseid ) const
wxMenu* MainEmuFrame::MakeStatesSubMenu( int baseid, int loadBackupId ) const
{
wxMenu* mnuSubstates = new wxMenu();
@ -37,8 +37,16 @@ wxMenu* MainEmuFrame::MakeStatesSubMenu( int baseid ) const
{
mnuSubstates->Append( baseid+i+1, wxsFormat(_("Slot %d"), i) );
}
if( loadBackupId>=0 )
{
mnuSubstates->AppendSeparator();
mnuSubstates->Append( baseid - 1, _("Other...") );
wxMenuItem* m = mnuSubstates->Append( loadBackupId, _("Backup") );
m->Enable( false );
States_registerLoadBackupMenuItem( m );
}
//mnuSubstates->Append( baseid - 1, _("Other...") );
return mnuSubstates;
}
@ -210,11 +218,13 @@ void MainEmuFrame::ConnectMenus()
ConnectMenu( MenuId_Sys_Restart, Menu_SysReset_Click );
ConnectMenu( MenuId_Sys_Shutdown, Menu_SysShutdown_Click );
ConnectMenu( MenuId_State_LoadOther, Menu_LoadStateOther_Click );
//ConnectMenu( MenuId_State_LoadOther, Menu_LoadStateOther_Click );
ConnectMenuRange(MenuId_State_Load01+1, 10, Menu_LoadStates_Click);
ConnectMenu( MenuId_State_LoadBackup, Menu_LoadStates_Click );
ConnectMenu( MenuId_State_SaveOther, Menu_SaveStateOther_Click );
//ConnectMenu( MenuId_State_SaveOther, Menu_SaveStateOther_Click );
ConnectMenuRange(MenuId_State_Save01+1, 10, Menu_SaveStates_Click);
@ -306,7 +316,7 @@ MainEmuFrame::MainEmuFrame(wxWindow* parent, const wxString& title)
, m_menuMisc ( *new wxMenu() )
, m_menuDebug ( *new wxMenu() )
, m_LoadStatesSubmenu( *MakeStatesSubMenu( MenuId_State_Load01 ) )
, m_LoadStatesSubmenu( *MakeStatesSubMenu( MenuId_State_Load01, MenuId_State_LoadBackup ) )
, m_SaveStatesSubmenu( *MakeStatesSubMenu( MenuId_State_Save01 ) )
, m_MenuItem_Console( *new wxMenuItem( &m_menuMisc, MenuId_Console, _("Show Console"), wxEmptyString, wxITEM_CHECK ) )

View File

@ -213,7 +213,7 @@ protected:
// MainEmuFram Internal API for Populating Main Menu Contents
// ------------------------------------------------------------------------
wxMenu* MakeStatesSubMenu( int baseid ) const;
wxMenu* MakeStatesSubMenu( int baseid, int loadBackupId=-1 ) const;
wxMenu* MakeStatesMenu();
wxMenu* MakeLanguagesMenu() const;

View File

@ -450,6 +450,12 @@ void MainEmuFrame::Menu_OpenELF_Click(wxCommandEvent&)
void MainEmuFrame::Menu_LoadStates_Click(wxCommandEvent &event)
{
if( event.GetId() == MenuId_State_LoadBackup )
{
States_DefrostCurrentSlotBackup();
return;
}
States_SetCurrentSlot( event.GetId() - MenuId_State_Load01 - 1 );
States_DefrostCurrentSlot();
}

View File

@ -28,6 +28,7 @@
static int StatesC = 0;
static const int StateSlotsCount = 10;
static wxMenuItem* g_loadBackupMenuItem =NULL;
bool States_isSlotUsed(int num)
{
@ -60,6 +61,8 @@ protected:
}
};
void Sstates_updateLoadBackupMenuItem( bool isBeforeSave = false);
void States_FreezeCurrentSlot()
{
// FIXME : Use of the IsSavingOrLoading flag is mostly a hack until we implement a
@ -70,6 +73,7 @@ void States_FreezeCurrentSlot()
Console.WriteLn( "Load or save action is already pending." );
return;
}
Sstates_updateLoadBackupMenuItem( true );
GSchangeSaveState( StatesC, SaveStateBase::GetFilename( StatesC ).ToUTF8() );
StateCopy_SaveToSlot( StatesC );
@ -77,7 +81,7 @@ void States_FreezeCurrentSlot()
GetSysExecutorThread().PostIdleEvent( SysExecEvent_ClearSavingLoadingFlag() );
}
void States_DefrostCurrentSlot()
void _States_DefrostCurrentSlot( bool isFromBackup )
{
if( AtomicExchange(IsSavingOrLoading, true) )
{
@ -86,9 +90,27 @@ void States_DefrostCurrentSlot()
}
GSchangeSaveState( StatesC, SaveStateBase::GetFilename( StatesC ).ToUTF8() );
StateCopy_LoadFromSlot( StatesC );
StateCopy_LoadFromSlot( StatesC, isFromBackup );
GetSysExecutorThread().PostIdleEvent( SysExecEvent_ClearSavingLoadingFlag() );
Sstates_updateLoadBackupMenuItem();
}
void States_DefrostCurrentSlot()
{
_States_DefrostCurrentSlot( false );
}
void States_DefrostCurrentSlotBackup()
{
_States_DefrostCurrentSlot( true );
}
void States_registerLoadBackupMenuItem( wxMenuItem* loadBackupMenuItem )
{
g_loadBackupMenuItem = loadBackupMenuItem;
}
static void OnSlotChanged()
@ -97,6 +119,8 @@ static void OnSlotChanged()
if( GSchangeSaveState != NULL )
GSchangeSaveState(StatesC, SaveStateBase::GetFilename(StatesC).mb_str());
Sstates_updateLoadBackupMenuItem();
}
int States_GetCurrentSlot()
@ -104,6 +128,18 @@ int States_GetCurrentSlot()
return StatesC;
}
void Sstates_updateLoadBackupMenuItem( bool isBeforeSave )
{
if( !g_loadBackupMenuItem ) return;
int slot = States_GetCurrentSlot();
wxString file = SaveStateBase::GetFilename( slot );
g_loadBackupMenuItem->Enable( wxFileExists( isBeforeSave && g_Conf->EmuOptions.BackupSavestate ? file : file + L".backup" ) );
wxString label;
label.Printf(L"%s %d", _("Backup"), slot );
g_loadBackupMenuItem->SetText( label );
}
void States_SetCurrentSlot( int slot )
{
StatesC = std::min( std::max( slot, 0 ), StateSlotsCount );

View File

@ -670,9 +670,9 @@ void StateCopy_SaveToSlot( uint num )
StateCopy_SaveToFile( file );
}
void StateCopy_LoadFromSlot( uint slot )
void StateCopy_LoadFromSlot( uint slot, bool isFromBackup )
{
wxString file( SaveStateBase::GetFilename( slot ) );
wxString file( SaveStateBase::GetFilename( slot ) + wxString( isFromBackup?L".backup":L"" ) );
if( !wxFileExists( file ) )
{
@ -680,7 +680,7 @@ void StateCopy_LoadFromSlot( uint slot )
return;
}
Console.WriteLn( Color_StrongGreen, "Loading savestate from slot %d...", slot );
Console.WriteLn( Color_StrongGreen, L"Loading savestate from slot %d...%s", slot, wxString( isFromBackup?L" (backup)":L"" ).c_str() );
Console.Indent().WriteLn( Color_StrongGreen, L"filename: %s", file.c_str() );
StateCopy_LoadFromFile( file );