From 3958348e9439061cd09776df7fc2565a5d9cb0d9 Mon Sep 17 00:00:00 2001 From: Peter Jorgensen Date: Tue, 16 Aug 2022 22:27:50 -0600 Subject: [PATCH] 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 --- src/BizHawk.Client.Common/config/Config.cs | 1 + src/BizHawk.Client.EmuHawk/MainForm.Designer.cs | 14 +++++++++++++- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 6 ++++++ src/BizHawk.Client.EmuHawk/MainForm.cs | 6 ++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index 5da7953f79..0a2ebb5f07 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -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; } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs b/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs index 00a928a7ea..6250809d64 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs @@ -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; } } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 9deee36e51..1b1a1e6f2d 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -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) { diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 9a720f309d..467c828f78 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -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)