From 3cbdd36fe0ce5d8688753c16feb58304ae137eba Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Sun, 11 Sep 2022 14:30:25 +1000 Subject: [PATCH] Deduplicate some code in `MainForm` --- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 17 ++++++++++++++++- src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs | 11 +++++------ src/BizHawk.Client.EmuHawk/MainForm.cs | 13 +++++-------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 08ebb519ca..5466433fd9 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -414,11 +414,17 @@ namespace BizHawk.Client.EmuHawk } private void SaveToCurrentSlotMenuItem_Click(object sender, EventArgs e) + => SavestateCurrentSlot(); + + private void SavestateCurrentSlot() { SaveQuickSave($"QuickSave{Config.SaveSlot}"); } private void LoadCurrentSlotMenuItem_Click(object sender, EventArgs e) + => LoadstateCurrentSlot(); + + private void LoadstateCurrentSlot() { LoadQuickSave($"QuickSave{Config.SaveSlot}"); } @@ -645,9 +651,12 @@ namespace BizHawk.Client.EmuHawk } } + private void ScheduleShutdown() + => _exitRequestPending = true; + public void CloseEmulator(int? exitCode = null) { - _exitRequestPending = true; + ScheduleShutdown(); if (exitCode != null) _exitCode = exitCode.Value; } @@ -1094,6 +1103,9 @@ namespace BizHawk.Client.EmuHawk } private void UnthrottledMenuItem_Click(object sender, EventArgs e) + => ToggleUnthrottled(); + + private void ToggleUnthrottled() { Config.Unthrottled ^= true; ThrottleMessage(); @@ -2445,6 +2457,9 @@ namespace BizHawk.Client.EmuHawk } private void LoadLastRomContextMenuItem_Click(object sender, EventArgs e) + => LoadMostRecentROM(); + + private void LoadMostRecentROM() { LoadRomFromRecent(Config.RecentRoms.MostRecent); } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs b/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs index ee3d29bbc1..522651e77c 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Hotkey.cs @@ -54,8 +54,7 @@ namespace BizHawk.Client.EmuHawk FrameInch = true; return false; case "Toggle Throttle": - Config.Unthrottled ^= true; - ThrottleMessage(); + ToggleUnthrottled(); break; case "Soft Reset": SoftReset(); @@ -64,10 +63,10 @@ namespace BizHawk.Client.EmuHawk HardReset(); break; case "Quick Load": - LoadQuickSave($"QuickSave{Config.SaveSlot}"); + LoadstateCurrentSlot(); break; case "Quick Save": - SaveQuickSave($"QuickSave{Config.SaveSlot}"); + SavestateCurrentSlot(); break; case "Clear Autohold": ClearAutohold(); @@ -93,7 +92,7 @@ namespace BizHawk.Client.EmuHawk CloseRom(); break; case "Load Last ROM": - LoadRomFromRecent(Config.RecentRoms.MostRecent); + LoadMostRecentROM(); break; case "Flush SaveRAM": FlushSaveRAM(); @@ -126,7 +125,7 @@ namespace BizHawk.Client.EmuHawk ToggleSound(); break; case "Exit Program": - _exitRequestPending = true; + ScheduleShutdown(); break; case "Record A/V": RecordAv(); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index ebd831a4b0..69fe18adc2 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -556,7 +556,7 @@ namespace BizHawk.Client.EmuHawk } else if (Config.RecentRoms.AutoLoad && !Config.RecentRoms.Empty) { - LoadRomFromRecent(Config.RecentRoms.MostRecent); + LoadMostRecentROM(); } if (_argParser.audiosync.HasValue) @@ -637,7 +637,7 @@ namespace BizHawk.Client.EmuHawk } else if (Config.AutoLoadLastSaveSlot) { - LoadQuickSave($"QuickSave{Config.SaveSlot}"); + LoadstateCurrentSlot(); } } @@ -3608,10 +3608,7 @@ namespace BizHawk.Client.EmuHawk if (_autoDumpLength == 0) // finish { StopAv(); - if (_argParser._autoCloseOnDump) - { - _exitRequestPending = true; - } + if (_argParser._autoCloseOnDump) ScheduleShutdown(); } } } @@ -3949,7 +3946,7 @@ namespace BizHawk.Client.EmuHawk Tools.UpdateCheatRelatedTools(null, null); if (!MovieSession.NewMovieQueued && Config.AutoLoadLastSaveSlot && HasSlot(Config.SaveSlot)) { - LoadQuickSave($"QuickSave{Config.SaveSlot}"); + LoadstateCurrentSlot(); } if (FirmwareManager.RecentlyServed.Count > 0) @@ -4078,7 +4075,7 @@ namespace BizHawk.Client.EmuHawk private void AutoSaveStateIfConfigured() { - if (Config.AutoSaveLastSaveSlot && Emulator.HasSavestates()) SaveQuickSave($"QuickSave{Config.SaveSlot}"); + if (Config.AutoSaveLastSaveSlot && Emulator.HasSavestates()) SavestateCurrentSlot(); } public bool GameIsClosing { get; private set; } // Lets tools make better decisions when being called by CloseGame