From 1df41efc0d04999e83ffaaffcd5abc2d3fa872ce Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Mon, 21 Oct 2019 23:54:16 -0400 Subject: [PATCH] Consolidate core accuracy warning dialog. --- .../BizHawk.Client.EmuHawk.csproj | 1 + BizHawk.Client.EmuHawk/EmuHawkUtil.cs | 54 ++++++++++++++++++ BizHawk.Client.EmuHawk/MainForm.Events.cs | 51 +---------------- .../tools/TAStudio/TAStudio.cs | 55 +------------------ 4 files changed, 61 insertions(+), 100 deletions(-) create mode 100644 BizHawk.Client.EmuHawk/EmuHawkUtil.cs diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index 1b30776f00..6623c8199c 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -649,6 +649,7 @@ + diff --git a/BizHawk.Client.EmuHawk/EmuHawkUtil.cs b/BizHawk.Client.EmuHawk/EmuHawkUtil.cs new file mode 100644 index 0000000000..41ed03e16f --- /dev/null +++ b/BizHawk.Client.EmuHawk/EmuHawkUtil.cs @@ -0,0 +1,54 @@ +using System; +using System.Drawing; +using System.Windows.Forms; +using BizHawk.Client.Common; +using BizHawk.Client.EmuHawk.CustomControls; +using BizHawk.Emulation.Common; +using Cores = BizHawk.Emulation.Cores; + +namespace BizHawk.Client.EmuHawk +{ + public static class EmuHawkUtil + { + public static bool EnsureCoreIsAccurate(IEmulator emulator) + { + bool PromptToSwitchCore(string currentCore, string recommendedCore, Action disableCurrentCore) + { + var box = new MsgBox( + $"While the {currentCore} core is faster, it is not nearly as accurate as {recommendedCore}.{Environment.NewLine}It is recommended that you switch to the {recommendedCore} core for movie recording. {Environment.NewLine}Switch to {recommendedCore}?", + "Accuracy Warning", + MessageBoxIcon.Warning); + + box.SetButtons( + new[] { "Switch", "Continue" }, + new[] { DialogResult.Yes, DialogResult.Cancel }); + + box.MaximumSize = UIHelper.Scale(new Size(575, 175)); + box.SetMessageToAutoSize(); + + var result = box.ShowDialog(); + box.Dispose(); + + if (result != DialogResult.Yes) + { + return false; + } + + disableCurrentCore(); + GlobalWin.MainForm.RebootCore(); + return true; + } + + if (emulator is Cores.Nintendo.SNES9X.Snes9x) + { + return PromptToSwitchCore("Snes9x", "bsnes", () => Global.Config.SNES_InSnes9x = false); + } + if (emulator is Cores.Consoles.Nintendo.QuickNES.QuickNES) + { + return PromptToSwitchCore("QuickNes", "NesHawk", () => Global.Config.NES_InQuickNES = false); + } + + return true; + } + } +} diff --git a/BizHawk.Client.EmuHawk/MainForm.Events.cs b/BizHawk.Client.EmuHawk/MainForm.Events.cs index 3a6f38a98a..1f704cf7b6 100644 --- a/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -478,55 +478,10 @@ namespace BizHawk.Client.EmuHawk return; } } - else if (Emulator is Snes9x) + + if (!EmuHawkUtil.EnsureCoreIsAccurate(Emulator)) { - var box = new MsgBox( - "While the Snes9x core is faster, it is not nearly as accurate as bsnes. \nIt is recommended that you switch to the bsnes core for movie recording\nSwitch to bsnes?", - "Accuracy Warning", - MessageBoxIcon.Warning); - - box.SetButtons( - new[] { "Switch", "Continue" }, - new[] { DialogResult.Yes, DialogResult.Cancel }); - - box.MaximumSize = UIHelper.Scale(new Size(475, 350)); - box.SetMessageToAutoSize(); - var result = box.ShowDialog(); - - if (result == DialogResult.Yes) - { - Global.Config.SNES_InSnes9x = false; - RebootCore(); - } - else if (result == DialogResult.Cancel) - { - // Do nothing and allow the user to continue to record the movie - } - } - else if (Emulator is QuickNES) // This is unsustainable :( But mixing the logic together is even worse, this needs to be rethought - { - var box = new MsgBox( - "While the QuickNes core is faster, it is not nearly as accurate as NesHawk. \nIt is recommended that you switch to the NesHawk core for movie recording\nSwitch to NesHawk?", - "Accuracy Warning", - MessageBoxIcon.Warning); - - box.SetButtons( - new[] { "Switch", "Continue" }, - new[] { DialogResult.Yes, DialogResult.Cancel }); - - box.MaximumSize = UIHelper.Scale(new Size(475, 350)); - box.SetMessageToAutoSize(); - var result = box.ShowDialog(); - - if (result == DialogResult.Yes) - { - Global.Config.NES_InQuickNES = false; - RebootCore(); - } - else if (result == DialogResult.Cancel) - { - // Do nothing and allow the user to continue to record the movie - } + // Inaccurate core but allow the user to continue anyway } new RecordMovie(Emulator).ShowDialog(); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 183b37df89..72eae81252 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; @@ -8,14 +7,12 @@ using System.ComponentModel; using BizHawk.Emulation.Common; using BizHawk.Emulation.Common.IEmulatorExtensions; -using BizHawk.Emulation.Cores.Nintendo.SNES9X; using BizHawk.Client.Common; using BizHawk.Client.Common.MovieConversionExtensions; using BizHawk.Client.EmuHawk.WinFormExtensions; using BizHawk.Client.EmuHawk.ToolExtensions; -using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; namespace BizHawk.Client.EmuHawk { @@ -320,56 +317,10 @@ namespace BizHawk.Client.EmuHawk Mainform.PauseOnFrame = null; Mainform.PauseEmulator(); - // Start Scenario 0: snes9x needs a nag (copied from RecordMovieMenuItem_Click()) - if (Emulator is Snes9x) + // Start Scenario 0: core needs a nag + if (!EmuHawkUtil.EnsureCoreIsAccurate(Emulator)) { - var box = new CustomControls.MsgBox( - "While the Snes9x core is faster, it is not nearly as accurate as bsnes. \nIt is recommended that you switch to the bsnes core for movie recording\nSwitch to bsnes?", - "Accuracy Warning", - MessageBoxIcon.Warning); - - box.SetButtons( - new[] { "Switch", "Continue" }, - new[] { DialogResult.Yes, DialogResult.Cancel }); - - box.MaximumSize = UIHelper.Scale(new Size(475, 350)); - box.SetMessageToAutoSize(); - var result = box.ShowDialog(); - - if (result == DialogResult.Yes) - { - Global.Config.SNES_InSnes9x = false; - Mainform.RebootCore(); - } - else if (result == DialogResult.Cancel) - { - //return false; - } - } - else if (Emulator is QuickNES) // Copy pasta of unsustainable logic, even better - { - var box = new CustomControls.MsgBox( - "While the QuickNes core is faster, it is not nearly as accurate as NesHawk. \nIt is recommended that you switch to the NesHawk core for movie recording\nSwitch to NesHawk?", - "Accuracy Warning", - MessageBoxIcon.Warning); - - box.SetButtons( - new[] { "Switch", "Continue" }, - new[] { DialogResult.Yes, DialogResult.Cancel }); - - box.MaximumSize = UIHelper.Scale(new Size(475, 350)); - box.SetMessageToAutoSize(); - var result = box.ShowDialog(); - - if (result == DialogResult.Yes) - { - Global.Config.NES_InQuickNES = false; - Mainform.RebootCore(); - } - else if (result == DialogResult.Cancel) - { - //return false; - } + // Inaccurate core but allow the user to continue anyway } // Start Scenario 1: A regular movie is active