diff --git a/src/BizHawk.Client.EmuHawk/Extensions/ToolExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/ToolExtensions.cs index 4b45ab5a28..9d3d74ba2c 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/ToolExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/ToolExtensions.cs @@ -12,7 +12,7 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions { public static class ToolExtensions { - public static ToolStripItem[] RecentMenu(this RecentFiles recent, Action loadFileCallback, string entrySemantic, bool noAutoload = false, bool romLoading = false) + public static ToolStripItem[] RecentMenu(this RecentFiles recent, IMainFormForTools mainForm, Action loadFileCallback, string entrySemantic, bool noAutoload = false, bool romLoading = false) { var items = new List(); @@ -193,7 +193,7 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions var settingsItem = new ToolStripMenuItem { Text = "&Recent Settings..." }; settingsItem.Click += (o, ev) => { - using var prompt = new InputPrompt + using var prompt = new InputPrompt(mainForm) { TextInputType = InputPrompt.InputType.Unsigned, Message = "Number of recent files to track", @@ -212,9 +212,9 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions return items.ToArray(); } - public static void HandleLoadError(this RecentFiles recent, string path, string encodedPath = null) + public static void HandleLoadError(this RecentFiles recent, IMainFormForTools mainForm, string path, string encodedPath = null) { - GlobalWin.Sound.StopSound(); + mainForm.StopSound(); if (recent.Frozen) { MessageBox.Show($"Could not open {path}", "File not found", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -229,7 +229,7 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions } } - GlobalWin.Sound.StartSound(); + mainForm.StartSound(); } public static IEnumerable MenuItems(this IMemoryDomains domains, Action setCallback, string selected = "", int? maxSize = null) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 34c8302dec..0240fac6c3 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -61,7 +61,7 @@ namespace BizHawk.Client.EmuHawk private void RecentRomMenuItem_DropDownOpened(object sender, EventArgs e) { RecentRomSubMenu.DropDownItems.Clear(); - RecentRomSubMenu.DropDownItems.AddRange(Config.RecentRoms.RecentMenu(LoadRomFromRecent, "ROM", romLoading: true)); + RecentRomSubMenu.DropDownItems.AddRange(Config.RecentRoms.RecentMenu(this, LoadRomFromRecent, "ROM", romLoading: true)); } private bool HasSlot(int slot) => _stateSlots.HasSlot(Emulator, MovieSession.Movie, slot, SaveStatePrefix()); @@ -192,7 +192,7 @@ namespace BizHawk.Client.EmuHawk private void RecentMovieSubMenu_DropDownOpened(object sender, EventArgs e) { RecentMovieSubMenu.DropDownItems.Clear(); - RecentMovieSubMenu.DropDownItems.AddRange(Config.RecentMovies.RecentMenu(LoadMoviesFromRecent, "Movie")); + RecentMovieSubMenu.DropDownItems.AddRange(Config.RecentMovies.RecentMenu(this, LoadMoviesFromRecent, "Movie")); } private void MovieEndSubMenu_DropDownOpened(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 68cd469cde..375303c978 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -524,7 +524,7 @@ namespace BizHawk.Client.EmuHawk } else { - Config.RecentMovies.HandleLoadError(Config.RecentMovies.MostRecent); + Config.RecentMovies.HandleLoadError(this, Config.RecentMovies.MostRecent); } } } @@ -2020,7 +2020,7 @@ namespace BizHawk.Client.EmuHawk } else { - Config.RecentMovies.HandleLoadError(path); + Config.RecentMovies.HandleLoadError(this, path); } } @@ -2039,7 +2039,7 @@ namespace BizHawk.Client.EmuHawk if (!LoadRom(romPath, args, out var failureIsFromAskSave)) { if (failureIsFromAskSave) OSD.AddMessage("ROM loading cancelled; a tool had unsaved changes"); - else Config.RecentRoms.HandleLoadError(romPath, rom); + else Config.RecentRoms.HandleLoadError(this, romPath, rom); } } diff --git a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs index 96332c602a..0ce33dcb15 100644 --- a/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs +++ b/src/BizHawk.Client.EmuHawk/tools/BasicBot/BasicBot.cs @@ -299,7 +299,7 @@ namespace BizHawk.Client.EmuHawk private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) { RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Settings.RecentBotFiles.RecentMenu(LoadFileFromRecent, "Bot Parameters")); + RecentSubMenu.DropDownItems.AddRange(Settings.RecentBotFiles.RecentMenu(MainForm, LoadFileFromRecent, "Bot Parameters")); } private void NewMenuItem_Click(object sender, EventArgs e) @@ -519,7 +519,7 @@ namespace BizHawk.Client.EmuHawk var result = LoadBotFile(path); if (!result) { - Settings.RecentBotFiles.HandleLoadError(path); + Settings.RecentBotFiles.HandleLoadError(MainForm, path); } } diff --git a/src/BizHawk.Client.EmuHawk/tools/CDL.cs b/src/BizHawk.Client.EmuHawk/tools/CDL.cs index 89dbe801d6..b2fd8343c7 100644 --- a/src/BizHawk.Client.EmuHawk/tools/CDL.cs +++ b/src/BizHawk.Client.EmuHawk/tools/CDL.cs @@ -300,7 +300,7 @@ namespace BizHawk.Client.EmuHawk private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) { RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(_recent.RecentMenu(LoadFile, "Session")); + RecentSubMenu.DropDownItems.AddRange(_recent.RecentMenu(MainForm, LoadFile, "Session")); } private void NewFileLogic() diff --git a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs index 1a28a87c9f..9614ae4212 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Cheats/Cheats.cs @@ -99,7 +99,7 @@ namespace BizHawk.Client.EmuHawk var loadResult = MainForm.CheatList.Load(Core, path, append: false); if (!loadResult) { - Config.Cheats.Recent.HandleLoadError(path); + Config.Cheats.Recent.HandleLoadError(MainForm, path); } else { @@ -336,7 +336,7 @@ namespace BizHawk.Client.EmuHawk private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) { RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Config.Cheats.Recent.RecentMenu(LoadFileFromRecent, "Cheats")); + RecentSubMenu.DropDownItems.AddRange(Config.Cheats.Recent.RecentMenu(MainForm, LoadFileFromRecent, "Cheats")); } private void NewMenuItem_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index 8eb2117fe9..a97a753247 100644 --- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -1359,7 +1359,7 @@ namespace BizHawk.Client.EmuHawk var result = LoadTable(path); if (!result) { - RecentTables.HandleLoadError(path); + RecentTables.HandleLoadError(MainForm, path); } else { @@ -1371,7 +1371,7 @@ namespace BizHawk.Client.EmuHawk private void RecentTablesSubMenu_DropDownOpened(object sender, EventArgs e) { RecentTablesSubMenu.DropDownItems.Clear(); - RecentTablesSubMenu.DropDownItems.AddRange(RecentTables.RecentMenu(LoadFileFromRecent, "Session")); + RecentTablesSubMenu.DropDownItems.AddRange(RecentTables.RecentMenu(MainForm, LoadFileFromRecent, "Session")); } private void EditMenuItem_DropDownOpened(object sender, EventArgs e) @@ -1598,7 +1598,7 @@ namespace BizHawk.Client.EmuHawk private void GoToAddressMenuItem_Click(object sender, EventArgs e) { - using var inputPrompt = new InputPrompt + using var inputPrompt = new InputPrompt(MainForm) { Text = "Go to Address", StartLocation = this.ChildPointToScreen(MemoryViewerBox), diff --git a/src/BizHawk.Client.EmuHawk/tools/InputPrompt.cs b/src/BizHawk.Client.EmuHawk/tools/InputPrompt.cs index 125b11a3a2..f833df5936 100644 --- a/src/BizHawk.Client.EmuHawk/tools/InputPrompt.cs +++ b/src/BizHawk.Client.EmuHawk/tools/InputPrompt.cs @@ -13,9 +13,12 @@ namespace BizHawk.Client.EmuHawk /// public partial class InputPrompt : Form { - public InputPrompt() + private readonly IMainFormForTools _mainForm; + + public InputPrompt(IMainFormForTools mainForm) { - GlobalWin.Sound.StopSound(); + _mainForm = mainForm; + _mainForm.StopSound(); InitializeComponent(); StartLocation = new Point(-1, -1); } @@ -55,14 +58,14 @@ namespace BizHawk.Client.EmuHawk { DialogResult = DialogResult.OK; Close(); - GlobalWin.Sound.StartSound(); + _mainForm.StartSound(); } private void Cancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); - GlobalWin.Sound.StartSound(); + _mainForm.StartSound(); } private void PromptBox_KeyPress(object sender, KeyPressEventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index fa53825125..cdaa4bd072 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -727,7 +727,7 @@ namespace BizHawk.Client.EmuHawk { if (!LoadLuaSession(path)) { - Config.RecentLuaSession.HandleLoadError(path); + Config.RecentLuaSession.HandleLoadError(MainForm, path); } } @@ -792,13 +792,13 @@ namespace BizHawk.Client.EmuHawk private void RecentSessionsSubMenu_DropDownOpened(object sender, EventArgs e) { RecentSessionsSubMenu.DropDownItems.Clear(); - RecentSessionsSubMenu.DropDownItems.AddRange(Config.RecentLuaSession.RecentMenu(LoadSessionFromRecent, "Session")); + RecentSessionsSubMenu.DropDownItems.AddRange(Config.RecentLuaSession.RecentMenu(MainForm, LoadSessionFromRecent, "Session")); } private void RecentScriptsSubMenu_DropDownOpened(object sender, EventArgs e) { RecentScriptsSubMenu.DropDownItems.Clear(); - RecentScriptsSubMenu.DropDownItems.AddRange(Config.RecentLua.RecentMenu(LoadLuaFile, "Script")); + RecentScriptsSubMenu.DropDownItems.AddRange(Config.RecentLua.RecentMenu(MainForm, LoadLuaFile, "Script")); } private void NewSessionMenuItem_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs index f6a9a6de7f..442f1c1762 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Macros/MacroInput.cs @@ -245,7 +245,7 @@ namespace BizHawk.Client.EmuHawk private void RecentToolStripMenuItem_DropDownOpened(object sender, EventArgs e) { RecentToolStripMenuItem.DropDownItems.Clear(); - RecentToolStripMenuItem.DropDownItems.AddRange(Config.RecentMacros.RecentMenu(DummyLoadMacro, "Macro")); + RecentToolStripMenuItem.DropDownItems.AddRange(Config.RecentMacros.RecentMenu(MainForm, DummyLoadMacro, "Macro")); } private void DummyLoadMacro(string path) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 200a3f846a..6599681e48 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -566,7 +566,7 @@ namespace BizHawk.Client.EmuHawk return false; } - var i = new InputPrompt + var i = new InputPrompt(MainForm) { Text = $"Text for branch {index}", TextInputType = InputPrompt.InputType.Text, diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs index 0b90393729..d3d76d683b 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/MarkerControl.cs @@ -182,7 +182,7 @@ namespace BizHawk.Client.EmuHawk TasMovieMarker marker; if (editText) { - var i = new InputPrompt + var i = new InputPrompt(Tastudio.MainForm) { Text = $"Marker for frame {frame}", TextInputType = InputPrompt.InputType.Text, @@ -234,7 +234,7 @@ namespace BizHawk.Client.EmuHawk { var markerFrame = marker.Frame; var point = default(Point); - var i = new InputPrompt + var i = new InputPrompt(Tastudio.MainForm) { Text = $"Marker for frame {markerFrame}", TextInputType = InputPrompt.InputType.Text, diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 0a743605fd..607406d7a6 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -75,7 +75,7 @@ namespace BizHawk.Client.EmuHawk private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) { RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Settings.RecentTas.RecentMenu(DummyLoadProject, "Project")); + RecentSubMenu.DropDownItems.AddRange(Settings.RecentTas.RecentMenu(MainForm, DummyLoadProject, "Project")); } private void NewTasMenuItem_Click(object sender, EventArgs e) @@ -261,7 +261,7 @@ namespace BizHawk.Client.EmuHawk private void RecentMacrosMenuItem_DropDownOpened(object sender, EventArgs e) { recentMacrosToolStripMenuItem.DropDownItems.Clear(); - recentMacrosToolStripMenuItem.DropDownItems.AddRange(Config.RecentMacros.RecentMenu(DummyLoadMacro, "Macro", noAutoload: true)); + recentMacrosToolStripMenuItem.DropDownItems.AddRange(Config.RecentMacros.RecentMenu(MainForm, DummyLoadMacro, "Macro", noAutoload: true)); } private void ToBk2MenuItem_Click(object sender, EventArgs e) @@ -822,7 +822,7 @@ namespace BizHawk.Client.EmuHawk private void SetMaxUndoLevelsMenuItem_Click(object sender, EventArgs e) { - using var prompt = new InputPrompt + using var prompt = new InputPrompt(MainForm) { TextInputType = InputPrompt.InputType.Unsigned, Message = "Number of Undo Levels to keep", @@ -850,7 +850,7 @@ namespace BizHawk.Client.EmuHawk private void SetBranchCellHoverIntervalMenuItem_Click(object sender, EventArgs e) { - using var prompt = new InputPrompt + using var prompt = new InputPrompt(MainForm) { TextInputType = InputPrompt.InputType.Unsigned, Message = "ScreenshotPopUp Delay", @@ -870,7 +870,7 @@ namespace BizHawk.Client.EmuHawk private void SetSeekingCutoffIntervalMenuItem_Click(object sender, EventArgs e) { - using var prompt = new InputPrompt + using var prompt = new InputPrompt(MainForm) { TextInputType = InputPrompt.InputType.Unsigned, Message = "Seeking Cutoff Interval", @@ -890,7 +890,7 @@ namespace BizHawk.Client.EmuHawk private void SetAutosaveIntervalMenuItem_Click(object sender, EventArgs e) { - using var prompt = new InputPrompt + using var prompt = new InputPrompt(MainForm) { TextInputType = InputPrompt.InputType.Unsigned, Message = "Autosave Interval in seconds\nSet to 0 to disable", @@ -1170,7 +1170,7 @@ namespace BizHawk.Client.EmuHawk private void WheelScrollSpeedMenuItem_Click(object sender, EventArgs e) { - var inputPrompt = new InputPrompt + var inputPrompt = new InputPrompt(MainForm) { TextInputType = InputPrompt.InputType.Unsigned, Message = "Frames per tick:", diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 9d5ecac5b2..4a422bee2d 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -564,7 +564,7 @@ namespace BizHawk.Client.EmuHawk { if (!file.Exists) { - Settings.RecentTas.HandleLoadError(file.FullName); + Settings.RecentTas.HandleLoadError(MainForm, file.FullName); return false; } diff --git a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs index 1a241ce905..bd9fe52911 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TraceLogger.cs @@ -343,7 +343,7 @@ namespace BizHawk.Client.EmuHawk private void MaxLinesMenuItem_Click(object sender, EventArgs e) { - using var prompt = new InputPrompt + using var prompt = new InputPrompt(MainForm) { StartLocation = this.ChildPointToScreen(TraceView), TextInputType = InputPrompt.InputType.Unsigned, @@ -364,7 +364,7 @@ namespace BizHawk.Client.EmuHawk private void SegmentSizeMenuItem_Click(object sender, EventArgs e) { - using var prompt = new InputPrompt + using var prompt = new InputPrompt(MainForm) { StartLocation = this.ChildPointToScreen(TraceView), TextInputType = InputPrompt.InputType.Unsigned, diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index a0a646edd9..a96147f1ec 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -567,7 +567,7 @@ namespace BizHawk.Client.EmuHawk if (!file.Exists) { - Settings.RecentSearches.HandleLoadError(path); + Settings.RecentSearches.HandleLoadError(MainForm, path); } else { @@ -891,7 +891,7 @@ namespace BizHawk.Client.EmuHawk private void GoToSpecifiedAddress() { WatchListView.DeselectAll(); - var prompt = new InputPrompt + var prompt = new InputPrompt(MainForm) { Text = "Go to Address", StartLocation = this.ChildPointToScreen(WatchListView), @@ -964,7 +964,7 @@ namespace BizHawk.Client.EmuHawk private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) { RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Settings.RecentSearches.RecentMenu(LoadFileFromRecent, "Search", noAutoload: true)); + RecentSubMenu.DropDownItems.AddRange(Settings.RecentSearches.RecentMenu(MainForm, LoadFileFromRecent, "Search", noAutoload: true)); } private void OpenMenuItem_Click(object sender, EventArgs e) diff --git a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index b9ade830c6..ecfda442fa 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -195,7 +195,7 @@ namespace BizHawk.Client.EmuHawk var loadResult = _watches.Load(path, append: false); if (!loadResult) { - Config.RecentWatches.HandleLoadError(path); + Config.RecentWatches.HandleLoadError(MainForm, path); } else { @@ -420,7 +420,7 @@ namespace BizHawk.Client.EmuHawk } else if (SelectedSeparators.Any() && !duplicate) { - var inputPrompt = new InputPrompt + var inputPrompt = new InputPrompt(MainForm) { Text = "Edit Separator", StartLocation = this.ChildPointToScreen(WatchListView), @@ -690,7 +690,7 @@ namespace BizHawk.Client.EmuHawk private void RecentSubMenu_DropDownOpened(object sender, EventArgs e) { RecentSubMenu.DropDownItems.Clear(); - RecentSubMenu.DropDownItems.AddRange(Config.RecentWatches.RecentMenu(LoadFileFromRecent, "Watches")); + RecentSubMenu.DropDownItems.AddRange(Config.RecentWatches.RecentMenu(MainForm, LoadFileFromRecent, "Watches")); } private void WatchesSubMenu_DropDownOpened(object sender, EventArgs e)