Add an undo load state option.

This commit is contained in:
Brandon Wright 2018-06-09 10:23:26 -05:00
parent f9e80ab932
commit 583e4b740d
3 changed files with 53 additions and 20 deletions

View File

@ -385,6 +385,8 @@ S9xAutoSaveSRAM (void)
void
S9xLoadState (const char *filename)
{
S9xFreezeGame (S9xGetFilename (".undo", SNAPSHOT_DIR));
if (S9xUnfreezeGame (filename))
{
sprintf (buf, "%s loaded", filename);
@ -528,34 +530,40 @@ S9xQuickLoadSlot (int slot)
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR, def,
slot);
if (file_exists (filename))
S9xFreezeGame (S9xGetFilename (".undo", SNAPSHOT_DIR));
if (S9xUnfreezeGame (filename))
{
snprintf (buf, PATH_MAX, "%s.%03d loaded", def, slot);
S9xSetInfoString (buf);
return;
}
else
static const char *digits = "t123456789";
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
snprintf (filename, PATH_MAX, "%s%s%s.zs%c",
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR,
def, digits[slot]);
if (file_exists (filename))
S9xFreezeGame (S9xGetFilename (".undo", SNAPSHOT_DIR));
if (S9xUnfreezeGame (filename))
{
static const char *digits = "t123456789";
_splitpath (Memory.ROMFilename, drive, dir, def, ext);
snprintf (filename, PATH_MAX, "%s%s%s.zs%c",
S9xGetDirectory (SNAPSHOT_DIR), SLASH_STR,
def, digits[slot]);
if (S9xUnfreezeGame (filename))
{
snprintf (buf, PATH_MAX,
"Loaded ZSNES freeze file %s.zs%c",
def, digits [slot]);
S9xSetInfoString (buf);
}
else
S9xMessage (S9X_ERROR,
S9X_FREEZE_FILE_NOT_FOUND,
"Freeze file not found");
snprintf (buf, PATH_MAX,
"Loaded ZSNES freeze file %s.zs%c",
def, digits [slot]);
S9xSetInfoString (buf);
return;
}
S9xMessage (S9X_ERROR,
S9X_FREEZE_FILE_NOT_FOUND,
"Freeze file not found");
return;
}

View File

@ -460,6 +460,15 @@ event_load_state (GtkWidget *widget, gpointer data)
return;
}
static void
event_load_state_undo (GtkWidget *widget, gpointer data)
{
S9xUnfreezeGame (S9xGetFilename (".undo", SNAPSHOT_DIR));
return;
}
static void
event_load_state_file (GtkWidget *widget, gpointer data)
{
@ -585,6 +594,7 @@ Snes9xWindow::Snes9xWindow (Snes9xConfig *config) :
{ "on_port_activate", G_CALLBACK (event_port) },
{ "load_save_state", G_CALLBACK (event_load_state) },
{ "load_state_file", G_CALLBACK (event_load_state_file) },
{ "load_state_undo", G_CALLBACK (event_load_state_undo) },
{ "save_save_state", G_CALLBACK (event_save_state) },
{ "save_state_file", G_CALLBACK (event_save_state_file) },
{ "drawingarea_button_press", G_CALLBACK (event_button_press) },

View File

@ -1334,6 +1334,21 @@
<signal name="activate" handler="load_state_file" swapped="no"/>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="undoseparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="load_state_undo">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">_Undo Load State</property>
<property name="use_underline">True</property>
<signal name="activate" handler="load_state_undo" swapped="no"/>
</object>
</child>
</object>
</child>
</object>