Add auto save state on close (squashed PR #3218)

resolves #1861

* Add configuration for auto-saving state on exit
* Update MainForm to auto save on close game if configured
* Fix config serialization test.
* Revert unnecessary changes to Designer file
* Move autosave configuration into Save States menu off of File
* Undo previous test changes
* Remove explicit size on menu item.
* Fix logic
This commit is contained in:
Peter Jorgensen 2022-08-16 22:27:50 -06:00 committed by GitHub
parent f1fc05fe60
commit 3958348e94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 1 deletions

View File

@ -122,6 +122,7 @@ namespace BizHawk.Client.Common
public bool AutofireLagFrames { get; set; } = true;
public int SaveSlot { get; set; } // currently selected savestate slot
public bool AutoLoadLastSaveSlot { get; set; }
public bool AutoSaveLastSaveSlot { get; set; }
public bool SkipLagFrame { get; set; }
public bool SuppressAskSave { get; set; }
public bool AviCaptureOsd { get; set; }

View File

@ -39,6 +39,8 @@ namespace BizHawk.Client.EmuHawk
this.SaveState0MenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.toolStripSeparator6 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
this.SaveNamedStateMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.toolStripSeparator24 = new BizHawk.WinForms.Controls.ToolStripSeparatorEx();
this.AutosaveLastSlotMenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.LoadStateSubMenu = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.LoadState1MenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
this.LoadState2MenuItem = new BizHawk.WinForms.Controls.ToolStripMenuItemEx();
@ -463,7 +465,9 @@ namespace BizHawk.Client.EmuHawk
this.SaveState9MenuItem,
this.SaveState0MenuItem,
this.toolStripSeparator6,
this.SaveNamedStateMenuItem});
this.SaveNamedStateMenuItem,
this.toolStripSeparator24,
this.AutosaveLastSlotMenuItem});
this.SaveStateSubMenu.Text = "&Save State";
this.SaveStateSubMenu.DropDownOpened += new System.EventHandler(this.SaveStateSubMenu_DropDownOpened);
//
@ -522,6 +526,12 @@ namespace BizHawk.Client.EmuHawk
this.SaveNamedStateMenuItem.Text = "Save Named State...";
this.SaveNamedStateMenuItem.Click += new System.EventHandler(this.SaveNamedStateMenuItem_Click);
//
// AutosaveLastSlotMenuItem
//
this.AutosaveLastSlotMenuItem.Name = "AutosaveLastSlotMenuItem";
this.AutosaveLastSlotMenuItem.Text = "Autosave Last Slot";
this.AutosaveLastSlotMenuItem.Click += new System.EventHandler(this.AutosaveLastSlotMenuItem_Click);
//
// LoadStateSubMenu
//
this.LoadStateSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@ -2756,5 +2766,7 @@ namespace BizHawk.Client.EmuHawk
private BizHawk.WinForms.Controls.ToolStripMenuItemEx AmstradCPCNonSyncSettingsToolStripMenuItem;
private BizHawk.WinForms.Controls.ToolStripSeparatorEx toolStripSeparator8;
private System.Windows.Forms.ToolStripMenuItem CaptureLuaMenuItem;
private System.Windows.Forms.ToolStripMenuItem AutosaveLastSlotMenuItem;
private ToolStripSeparatorEx toolStripSeparator24;
}
}

View File

@ -119,6 +119,8 @@ namespace BizHawk.Client.EmuHawk
SetSlotFont(SaveState9MenuItem, 9);
SetSlotFont(SaveState0MenuItem, 0);
AutosaveLastSlotMenuItem.Checked = Config.AutoSaveLastSaveSlot;
SaveState1MenuItem.ShortcutKeyDisplayString = Config.HotkeyBindings["Save State 1"];
SaveState2MenuItem.ShortcutKeyDisplayString = Config.HotkeyBindings["Save State 2"];
SaveState3MenuItem.ShortcutKeyDisplayString = Config.HotkeyBindings["Save State 3"];
@ -377,6 +379,10 @@ namespace BizHawk.Client.EmuHawk
{
Config.AutoLoadLastSaveSlot ^= true;
}
private void AutosaveLastSlotMenuItem_Click(object sender, EventArgs e)
{
Config.AutoSaveLastSaveSlot ^= true;
}
private void SelectSlotMenuItems_Click(object sender, EventArgs e)
{

View File

@ -4079,6 +4079,7 @@ namespace BizHawk.Client.EmuHawk
}
StopAv();
AutoSaveStateIfConfigured();
CommitCoreSettingsToConfig();
Rewinder?.Dispose();
@ -4098,6 +4099,11 @@ namespace BizHawk.Client.EmuHawk
GameIsClosing = false;
}
private void AutoSaveStateIfConfigured()
{
if (Config.AutoSaveLastSaveSlot && Emulator.HasSavestates()) SaveQuickSave($"QuickSave{Config.SaveSlot}");
}
public bool GameIsClosing { get; private set; } // Lets tools make better decisions when being called by CloseGame
public void CloseRom(bool clearSram = false)