From 4f4a8753820dd6268782a6d41b7b1ce27bc7e23e Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 29 Jun 2020 14:11:52 +1000 Subject: [PATCH] Pass delegates instead of MainForm to EmuHawkOptions --- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 10 ++++++++- .../config/EmuHawkOptions.cs | 21 ++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 36ea6a38db..b9b28ab271 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -1023,9 +1023,17 @@ namespace BizHawk.Client.EmuHawk : "Rom Extension Preferences cancelled"); } + private void BumpAutoFlushSaveRamTimer() + { + if (AutoFlushSaveRamIn > Config.FlushSaveRamFrames) + { + AutoFlushSaveRamIn = Config.FlushSaveRamFrames; + } + } + private void CustomizeMenuItem_Click(object sender, EventArgs e) { - using var form = new EmuHawkOptions(this, Config); + using var form = new EmuHawkOptions(BumpAutoFlushSaveRamTimer, Config, this.AddOnScreenMessage); form.ShowDialog(); } diff --git a/src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs b/src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs index 332c4fd1c9..8568c25144 100644 --- a/src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs +++ b/src/BizHawk.Client.EmuHawk/config/EmuHawkOptions.cs @@ -6,13 +6,17 @@ namespace BizHawk.Client.EmuHawk { public partial class EmuHawkOptions : Form { - private readonly MainForm _mainForm; + private readonly Action _autoFlushSaveRamTimerBumpCallback; + private readonly Config _config; - public EmuHawkOptions(MainForm mainForm, Config config) + private readonly Action _osdMessageCallback; + + public EmuHawkOptions(Action autoFlushSaveRamTimerBumpCallback, Config config, Action osdMessageCallback) { - _mainForm = mainForm; + _autoFlushSaveRamTimerBumpCallback = autoFlushSaveRamTimerBumpCallback; _config = config; + _osdMessageCallback = osdMessageCallback; InitializeComponent(); } @@ -121,10 +125,7 @@ namespace BizHawk.Client.EmuHawk _config.BackupSaveram = BackupSRamCheckbox.Checked; _config.AutosaveSaveRAM = AutosaveSRAMCheckbox.Checked; _config.FlushSaveRamFrames = AutosaveSaveRAMSeconds * 60; - if (_mainForm.AutoFlushSaveRamIn > _config.FlushSaveRamFrames) - { - _mainForm.AutoFlushSaveRamIn = _config.FlushSaveRamFrames; - } + _autoFlushSaveRamTimerBumpCallback(); _config.SkipLagFrame = FrameAdvSkipLagCheckbox.Checked; _config.RunLuaDuringTurbo = LuaDuringTurboCheckbox.Checked; @@ -141,10 +142,10 @@ namespace BizHawk.Client.EmuHawk _config.LuaEngine = ELuaEngine.NLuaPlusKopiLua; } - _mainForm.AddOnScreenMessage("Custom configurations saved."); + _osdMessageCallback("Custom configurations saved."); if (prevLuaEngine != _config.LuaEngine) { - _mainForm.AddOnScreenMessage("Restart emulator for Lua change to take effect"); + _osdMessageCallback("Restart emulator for Lua change to take effect"); } Close(); @@ -155,7 +156,7 @@ namespace BizHawk.Client.EmuHawk { Close(); DialogResult = DialogResult.Cancel; - _mainForm.AddOnScreenMessage("Customizing aborted."); + _osdMessageCallback("Customizing aborted."); } private void AcceptBackgroundInputCheckbox_CheckedChanged(object sender, EventArgs e)