Pass MainForm to UI helpers instead of using GlobalWin.Sound
This commit is contained in:
parent
636a9a4735
commit
3ccdfa8289
|
@ -12,7 +12,7 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions
|
|||
{
|
||||
public static class ToolExtensions
|
||||
{
|
||||
public static ToolStripItem[] RecentMenu(this RecentFiles recent, Action<string> loadFileCallback, string entrySemantic, bool noAutoload = false, bool romLoading = false)
|
||||
public static ToolStripItem[] RecentMenu(this RecentFiles recent, IMainFormForTools mainForm, Action<string> loadFileCallback, string entrySemantic, bool noAutoload = false, bool romLoading = false)
|
||||
{
|
||||
var items = new List<ToolStripItem>();
|
||||
|
||||
|
@ -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<ToolStripItem> MenuItems(this IMemoryDomains domains, Action<string> setCallback, string selected = "", int? maxSize = null)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -13,9 +13,12 @@ namespace BizHawk.Client.EmuHawk
|
|||
/// </summary>
|
||||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:",
|
||||
|
|
|
@ -564,7 +564,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
{
|
||||
if (!file.Exists)
|
||||
{
|
||||
Settings.RecentTas.HandleLoadError(file.FullName);
|
||||
Settings.RecentTas.HandleLoadError(MainForm, file.FullName);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue