From 5f1640a3b133ac03f745f1fdebd09d4eb157561f Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 2 Nov 2013 20:13:53 +0000 Subject: [PATCH] move Ram Search into toolmanager --- BizHawk.MultiClient/MainForm.Events.cs | 2 +- BizHawk.MultiClient/MainForm.cs | 42 +++--------- .../tools/HexEditor/HexEditor.cs | 4 +- BizHawk.MultiClient/tools/IToolForm.cs | 1 + .../Lua/Libraries/EmuLuaLibrary.Client.cs | 2 +- BizHawk.MultiClient/tools/ToolBox.cs | 2 +- BizHawk.MultiClient/tools/ToolHelpers.cs | 2 +- BizHawk.MultiClient/tools/ToolManager.cs | 64 ++++++++++++++----- BizHawk.MultiClient/tools/Watch/RamSearch.cs | 5 +- 9 files changed, 69 insertions(+), 55 deletions(-) diff --git a/BizHawk.MultiClient/MainForm.Events.cs b/BizHawk.MultiClient/MainForm.Events.cs index 5fec45ec28..ba642f84d5 100644 --- a/BizHawk.MultiClient/MainForm.Events.cs +++ b/BizHawk.MultiClient/MainForm.Events.cs @@ -1160,7 +1160,7 @@ namespace BizHawk.MultiClient private void RamSearchMenuItem_Click(object sender, EventArgs e) { - LoadRamSearch(); + GlobalWinF.Tools.Load(); } private void HexEditorMenuItem_Click(object sender, EventArgs e) diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index c5beeae170..ec8b254e68 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -86,8 +86,6 @@ namespace BizHawk.MultiClient //tool dialogs - private RamSearch _ramsearch; - private HexEditor _hexeditor; private TraceLogger _tracelogger; private SNESGraphicsDebugger _snesgraphicsdebugger; @@ -109,7 +107,6 @@ namespace BizHawk.MultiClient private NESSoundConfig _nessound; //TODO: this is a lazy way to refactor things, but works for now. The point is to not have these objects created until needed, without refactoring a lot of code - public RamSearch RamSearch1 { get { if (_ramsearch == null) _ramsearch = new RamSearch(); return _ramsearch; } set { _ramsearch = value; } } public HexEditor HexEditor1 { get { if (_hexeditor == null) _hexeditor = new HexEditor(); return _hexeditor; } set { _hexeditor = value; } } public TraceLogger TraceLogger1 { get { if (_tracelogger == null) _tracelogger = new TraceLogger(); return _tracelogger; } set { _tracelogger = value; } } public SNESGraphicsDebugger SNESGraphicsDebugger1 { get { if (_snesgraphicsdebugger == null) _snesgraphicsdebugger = new SNESGraphicsDebugger(); return _snesgraphicsdebugger; } set { _snesgraphicsdebugger = value; } } @@ -353,7 +350,7 @@ namespace BizHawk.MultiClient } if (Global.Config.RecentSearches.AutoLoad) { - LoadRamSearch(); + GlobalWinF.Tools.Load(); } if (Global.Config.AutoLoadHexEditor) { @@ -1610,8 +1607,6 @@ namespace BizHawk.MultiClient GlobalWinF.Tools.Restart(); - if (_ramsearch != null) RamSearch1.Restart(); - if (_hexeditor != null) HexEditor1.Restart(); if (_nesppu != null) NESPPU1.Restart(); if (_nesnametableview != null) NESNameTableViewer1.Restart(); @@ -2102,7 +2097,7 @@ namespace BizHawk.MultiClient case "Movie Poke": ToggleModePokeMode(); break; case "Ram Watch": LoadRamWatch(true); break; - case "Ram Search": LoadRamSearch(); break; + case "Ram Search": GlobalWinF.Tools.Load(); break; case "Hex Editor": LoadHexEditor(); break; case "Trace Logger": LoadTraceLogger(); break; case "Lua Console": OpenLuaConsole(); break; @@ -2111,12 +2106,12 @@ namespace BizHawk.MultiClient case "ToolBox": LoadToolBox(); break; case "Virtual Pad": LoadVirtualPads(); break; - case "Do Search": RamSearch_DoSearch(); break; - case "New Search": RamSearch_NewSearch(); break; - case "Previous Compare To": RamSearch_PreviousCompareTo(); break; - case "Next Compare To": RamSearch_NextCompareTo(); break; - case "Previous Operator": RamSearch_PreviousOperator(); break; - case "Next Operator": RamSearch_NextOperator(); break; + case "Do Search": GlobalWinF.Tools.RamSearch.DoSearch(); break; + case "New Search": GlobalWinF.Tools.RamSearch.NewSearch(); break; + case "Previous Compare To": GlobalWinF.Tools.RamSearch.NextCompareTo(reverse: true); break; + case "Next Compare To": GlobalWinF.Tools.RamSearch.NextCompareTo(); break; + case "Previous Operator": GlobalWinF.Tools.RamSearch.NextOperator(reverse: true); break; + case "Next Operator": GlobalWinF.Tools.RamSearch.NextOperator(); break; case "Toggle BG 1": SNES_ToggleBG1(); break; case "Toggle BG 2": SNES_ToggleBG2(); break; @@ -2359,9 +2354,6 @@ namespace BizHawk.MultiClient if (_snesgraphicsdebugger != null) SNESGraphicsDebugger1.UpdateToolsLoadstate(); } - /// - /// Update all tools that are frame dependent like Ram Search after processing - /// public void UpdateToolsAfter(bool fromLua = false) { #if WINDOWS @@ -2372,7 +2364,6 @@ namespace BizHawk.MultiClient #endif GlobalWinF.Tools.UpdateAfter(); - if (_ramsearch != null) RamSearch1.UpdateValues(); if (_hexeditor != null) HexEditor1.UpdateValues(); //The other tool updates are earlier, TAStudio needs to be later so it can display the latest //frame of execution in its list view. @@ -2586,19 +2577,7 @@ namespace BizHawk.MultiClient GlobalWinF.OSD.AddMessage("Slot " + Global.Config.SaveSlot + " selected."); } - public void LoadRamSearch() - { - if (!RamSearch1.IsHandleCreated || RamSearch1.IsDisposed) - { - RamSearch1 = new RamSearch(); - RamSearch1.Show(); - } - else - { - RamSearch1.Focus(); - } - } - + /*TODO delete me private void RamSearch_DoSearch() { if (!RamSearch1.IsHandleCreated || RamSearch1.IsDisposed) @@ -2670,6 +2649,7 @@ namespace BizHawk.MultiClient RamSearch1.NextOperator(reverse: true); } } + */ public void LoadNesSoundConfig() { @@ -3210,7 +3190,6 @@ namespace BizHawk.MultiClient RewireSound(); ResetRewindBuffer(); - RamSearch1.Restart(); HexEditor1.Restart(); NESPPU1.Restart(); NESNameTableViewer1.Restart(); @@ -3251,7 +3230,6 @@ namespace BizHawk.MultiClient public void CloseTools() { - CloseForm(RamSearch1); CloseForm(HexEditor1); CloseForm(NESNameTableViewer1); CloseForm(NESPPU1); diff --git a/BizHawk.MultiClient/tools/HexEditor/HexEditor.cs b/BizHawk.MultiClient/tools/HexEditor/HexEditor.cs index 62fdbc771e..a780b6120c 100644 --- a/BizHawk.MultiClient/tools/HexEditor/HexEditor.cs +++ b/BizHawk.MultiClient/tools/HexEditor/HexEditor.cs @@ -895,9 +895,9 @@ namespace BizHawk.MultiClient private void UpdateRelatedDialogs() { - GlobalWinF.MainForm.UpdateCheatStatus(); - GlobalWinF.MainForm.RamSearch1.UpdateValues(); GlobalWinF.Tools.UpdateValues(); + GlobalWinF.Tools.UpdateValues(); + GlobalWinF.MainForm.UpdateCheatStatus(); GlobalWinF.MainForm.Cheats_UpdateValues(); UpdateValues(); } diff --git a/BizHawk.MultiClient/tools/IToolForm.cs b/BizHawk.MultiClient/tools/IToolForm.cs index e8af01f8e9..163230feb8 100644 --- a/BizHawk.MultiClient/tools/IToolForm.cs +++ b/BizHawk.MultiClient/tools/IToolForm.cs @@ -33,5 +33,6 @@ bool Focus(); void Show(); void Close(); + bool IsDisposed { get; } } } diff --git a/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Client.cs b/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Client.cs index 9bac329668..e513bcd94d 100644 --- a/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Client.cs +++ b/BizHawk.MultiClient/tools/Lua/Libraries/EmuLuaLibrary.Client.cs @@ -127,7 +127,7 @@ namespace BizHawk.MultiClient public static void client_openramsearch() { - GlobalWinF.MainForm.LoadRamSearch(); + GlobalWinF.Tools.Load(); } public static void client_openrom(object lua_input) diff --git a/BizHawk.MultiClient/tools/ToolBox.cs b/BizHawk.MultiClient/tools/ToolBox.cs index 4c4c9a8452..ea39d08524 100644 --- a/BizHawk.MultiClient/tools/ToolBox.cs +++ b/BizHawk.MultiClient/tools/ToolBox.cs @@ -98,7 +98,7 @@ namespace BizHawk.MultiClient private void toolStripButton3_Click(object sender, EventArgs e) { - GlobalWinF.MainForm.LoadRamSearch(); + GlobalWinF.Tools.Load(); } private void HexEditor_Click(object sender, EventArgs e) diff --git a/BizHawk.MultiClient/tools/ToolHelpers.cs b/BizHawk.MultiClient/tools/ToolHelpers.cs index c3df6e2d91..92d5fd043b 100644 --- a/BizHawk.MultiClient/tools/ToolHelpers.cs +++ b/BizHawk.MultiClient/tools/ToolHelpers.cs @@ -207,9 +207,9 @@ namespace BizHawk.MultiClient public static void UpdateCheatRelatedTools() { GlobalWinF.Tools.UpdateValues(); + GlobalWinF.Tools.UpdateValues(); GlobalWinF.MainForm.HexEditor1.UpdateValues(); GlobalWinF.MainForm.Cheats_UpdateValues(); - GlobalWinF.MainForm.RamSearch1.UpdateValues(); GlobalWinF.MainForm.UpdateCheatStatus(); } diff --git a/BizHawk.MultiClient/tools/ToolManager.cs b/BizHawk.MultiClient/tools/ToolManager.cs index 70db529b4e..295f1c3595 100644 --- a/BizHawk.MultiClient/tools/ToolManager.cs +++ b/BizHawk.MultiClient/tools/ToolManager.cs @@ -23,16 +23,21 @@ namespace BizHawk.MultiClient var existingTool = _tools.FirstOrDefault(x => x is T); if (existingTool != null) { - existingTool.Show(); - existingTool.Focus(); - return existingTool; - } - else - { - var result = Get(); - result.Show(); - return result; + if (existingTool.IsDisposed) + { + _tools.Remove(existingTool); + } + else + { + existingTool.Show(); + existingTool.Focus(); + return existingTool; + } } + + var result = Get(); + result.Show(); + return result; } /// @@ -183,17 +188,44 @@ namespace BizHawk.MultiClient var tool = _tools.FirstOrDefault(x => x is RamWatch); if (tool != null) { - return tool as RamWatch; - } - else - { - var ramWatch = new RamWatch(); - _tools.Add(ramWatch); - return ramWatch; + if (tool.IsDisposed) + { + _tools.Remove(tool); + } + else + { + return tool as RamWatch; + } } + + var ramWatch = new RamWatch(); + _tools.Add(ramWatch); + return ramWatch; } } + public RamSearch RamSearch + { + get + { + var tool = _tools.FirstOrDefault(x => x is RamSearch); + if (tool != null) + { + if (tool.IsDisposed) + { + _tools.Remove(tool); + } + else + { + return tool as RamSearch; + } + } + + var ramWatch = new RamSearch(); + _tools.Add(ramWatch); + return ramWatch; + } + } #endregion } diff --git a/BizHawk.MultiClient/tools/Watch/RamSearch.cs b/BizHawk.MultiClient/tools/Watch/RamSearch.cs index b4c9cddf8a..843b3a4de8 100644 --- a/BizHawk.MultiClient/tools/Watch/RamSearch.cs +++ b/BizHawk.MultiClient/tools/Watch/RamSearch.cs @@ -17,7 +17,7 @@ namespace BizHawk.MultiClient /// /// A winform designed to search through ram values /// - public partial class RamSearch : Form + public partial class RamSearch : Form, IToolForm { //TODO: DoSearch grabs the state of widgets and passes it to the engine before running, so rip out code that is attempting to keep the state up to date through change events @@ -47,6 +47,9 @@ namespace BizHawk.MultiClient public const int MaxDetailedSize = (1024 * 1024); //1mb, semi-arbituary decision, sets the size to check for and automatically switch to fast mode for the user public const int MaxSupportedSize = (1024 * 1024 * 64); //64mb, semi-arbituary decision, sets the maximum size ram search will support (as it will crash beyond this) + public bool AskSave() { return true; } + public bool UpdateBefore { get { return false; } } + #region Initialize, Load, and Save public RamSearch()