From 0d25ef8f8fea6979f107344bcd212f4094411378 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 7 Sep 2013 01:38:24 +0000 Subject: [PATCH] Refactor Recent menu stuff again, and move autload to a property of recent files, ram watch now uses that value instead, all other dialogs with recent menus need to be refactored this way --- BizHawk.MultiClient/Config.cs | 18 -- BizHawk.MultiClient/MainForm.cs | 336 ++++++++++++----------- BizHawk.MultiClient/RecentFiles.cs | 109 ++++---- BizHawk.MultiClient/tools/NewRamWatch.cs | 237 ++++++++-------- BizHawk.MultiClient/tools/RamWatch.cs | 31 +-- 5 files changed, 351 insertions(+), 380 deletions(-) diff --git a/BizHawk.MultiClient/Config.cs b/BizHawk.MultiClient/Config.cs index 771630d48f..6614cfc5fa 100644 --- a/BizHawk.MultiClient/Config.cs +++ b/BizHawk.MultiClient/Config.cs @@ -174,7 +174,6 @@ namespace BizHawk.MultiClient public bool DisableLuaScriptsOnLoad = false; // RamWatch Settings - public bool AutoLoadRamWatch = false; public RecentFiles RecentWatches = new RecentFiles(8); public bool RamWatchSaveWindowPosition = true; public int RamWatchWndx = -1; //Negative numbers will be ignored even with save window position set @@ -192,7 +191,6 @@ namespace BizHawk.MultiClient public int RamWatchDiffWidth = -1; public int RamWatchNotesWidth = -1; public int RamWatchDomainWidth = -1; - public int RamWatchAddressIndex = 0; public int RamWatchValueIndex = 1; public int RamWatchPrevIndex = 2; @@ -451,22 +449,6 @@ namespace BizHawk.MultiClient public BindingCollection HotkeyBindings = new BindingCollection(); - - - - - - - - - - - - - - - - //Analog Hotkey values public int Analog_LargeChange = 10; public int Analog_SmallChange = 1; diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index d1f0a95ecf..399f54c6d2 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -106,7 +106,7 @@ namespace BizHawk.MultiClient private GBGameGenie _gbgg = null; private GenGameGenie _gengg = null; private NESSoundConfig _nessound = null; - private NewRamWatch _newramwatch = null; + private NewRamWatch _newramwatch = null; //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 RamWatch RamWatch1 { get { if (_ramwatch == null) _ramwatch = new RamWatch(); return _ramwatch; } set { _ramwatch = value; } } @@ -131,7 +131,7 @@ namespace BizHawk.MultiClient public GenGameGenie Gengg { get { if (_gengg == null) _gengg = new GenGameGenie(); return _gengg; } set { _gengg = value; } } public NESSoundConfig NesSound { get { if (_nessound == null) _nessound = new NESSoundConfig(); return _nessound; } set { _nessound = value; } } - public NewRamWatch NewRamWatch1 { get { if (_newramwatch == null) _newramwatch = new NewRamWatch(); return _newramwatch; } set { _newramwatch = value; } } + public NewRamWatch NewRamWatch1 { get { if (_newramwatch == null) _newramwatch = new NewRamWatch(); return _newramwatch; } set { _newramwatch = value; } } //TODO: eventually start doing this, rather than tools attempting to talk to tools public void Cheats_UpdateValues() { if (_cheats != null) { _cheats.UpdateValues(); } } @@ -145,7 +145,7 @@ namespace BizHawk.MultiClient /// number of frames to autodump /// int autoDumpLength; - bool autoCloseOnDump = false; + bool autoCloseOnDump = false; static MainForm() { @@ -155,7 +155,7 @@ namespace BizHawk.MultiClient public MainForm(string[] args) { - Global.MovieSession = new MovieSession {Movie = new Movie()}; + Global.MovieSession = new MovieSession { Movie = new Movie() }; MainWait = new AutoResetEvent(false); Icon = Properties.Resources.logo; InitializeComponent(); @@ -251,20 +251,20 @@ namespace BizHawk.MultiClient } string arg = args[i].ToLower(); - if (arg.StartsWith("--load-slot=")) - cmdLoadState = arg.Substring(arg.IndexOf('=') + 1); - else if (arg.StartsWith("--movie=")) - cmdMovie = arg.Substring(arg.IndexOf('=') + 1); - else if (arg.StartsWith("--dump-type=")) - cmdDumpType = arg.Substring(arg.IndexOf('=') + 1); - else if (arg.StartsWith("--dump-name=")) - cmdDumpName = arg.Substring(arg.IndexOf('=') + 1); - else if (arg.StartsWith("--dump-length=")) - int.TryParse(arg.Substring(arg.IndexOf('=') + 1), out autoDumpLength); - else if (arg.StartsWith("--dump_close=")) - autoCloseOnDump = true; - else - cmdRom = arg; + if (arg.StartsWith("--load-slot=")) + cmdLoadState = arg.Substring(arg.IndexOf('=') + 1); + else if (arg.StartsWith("--movie=")) + cmdMovie = arg.Substring(arg.IndexOf('=') + 1); + else if (arg.StartsWith("--dump-type=")) + cmdDumpType = arg.Substring(arg.IndexOf('=') + 1); + else if (arg.StartsWith("--dump-name=")) + cmdDumpName = arg.Substring(arg.IndexOf('=') + 1); + else if (arg.StartsWith("--dump-length=")) + int.TryParse(arg.Substring(arg.IndexOf('=') + 1), out autoDumpLength); + else if (arg.StartsWith("--dump_close=")) + autoCloseOnDump = true; + else + cmdRom = arg; } if (cmdRom != null) @@ -320,17 +320,17 @@ namespace BizHawk.MultiClient LoadState("QuickSave" + Global.Config.SaveSlot.ToString()); } - if (Global.Config.AutoLoadRamWatch) + if (Global.Config.RecentWatches.AutoLoad) { if (Global.Config.DisplayRamWatch) { LoadRamWatch(false); - LoadNewRamWatch(false); + LoadNewRamWatch(false); } else { LoadRamWatch(true); - LoadNewRamWatch(true); + LoadNewRamWatch(true); } } if (Global.Config.AutoLoadRamSearch) @@ -455,7 +455,7 @@ namespace BizHawk.MultiClient var cfp = new CoreFileProvider(); target.CoreFileProvider = cfp; cfp.FirmwareManager = FirmwareManager; - + target.NES_BackdropColor = Global.Config.NESBackgroundColor; target.NES_UnlimitedSprites = Global.Config.NESAllowMoreThanEightSprites; target.NES_ShowBG = Global.Config.NESDispBackground; @@ -621,7 +621,7 @@ namespace BizHawk.MultiClient } //if (!EmulatorPaused) - //Global.ClickyVirtualPadController.FrameTick(); + //Global.ClickyVirtualPadController.FrameTick(); #if WINDOWS LuaConsole1.ResumeScripts(false); @@ -989,13 +989,13 @@ namespace BizHawk.MultiClient // allow propogating controls that are in the current controller definition but not in the prebaked one // these two lines shouldn't be required anymore under the new system? Global.ActiveController.ForceType(new ControllerDefinition(Global.Emulator.ControllerDefinition)); - Global.ClickyVirtualPadController.Type = new ControllerDefinition(Global.Emulator.ControllerDefinition); + Global.ClickyVirtualPadController.Type = new ControllerDefinition(Global.Emulator.ControllerDefinition); RewireInputChain(); } void RewireInputChain() { - Global.ControllerInputCoalescer = new ControllerInputCoalescer {Type = Global.ActiveController.Type}; + Global.ControllerInputCoalescer = new ControllerInputCoalescer { Type = Global.ActiveController.Type }; Global.OrControllerAdapter.Source = Global.ActiveController; Global.OrControllerAdapter.SourceOr = Global.AutoFireController; @@ -1091,7 +1091,7 @@ namespace BizHawk.MultiClient game.System = "PCECD"; break; } - + /* probably dead code here if (Emulation.Consoles.PSX.Octoshock.CheckIsPSX(disc)) { @@ -1099,11 +1099,11 @@ namespace BizHawk.MultiClient disc.Dispose(); } */ - //else if (disc.DetectSegaSaturn()) // DetectSegaSaturn does not exist - //{ - // Console.WriteLine("Sega Saturn disc detected!"); - // game = new GameInfo { System = "SAT", Name = Path.GetFileNameWithoutExtension(file.Name), Hash = hash }; - //} + //else if (disc.DetectSegaSaturn()) // DetectSegaSaturn does not exist + //{ + // Console.WriteLine("Sega Saturn disc detected!"); + // game = new GameInfo { System = "SAT", Name = Path.GetFileNameWithoutExtension(file.Name), Hash = hash }; + //} } switch (game.System) @@ -1189,15 +1189,15 @@ namespace BizHawk.MultiClient var R = Database.GetGameInfo(XMLG.Assets["RightRom"], "right.gb"); if (Global.Config.GB_ForceDMG) L.AddOption("ForceDMG"); - if (Global.Config.GB_GBACGB) L.AddOption("GBACGB"); - if (Global.Config.GB_MulticartCompat) L.AddOption("MulitcartCompat"); + if (Global.Config.GB_GBACGB) L.AddOption("GBACGB"); + if (Global.Config.GB_MulticartCompat) L.AddOption("MulitcartCompat"); if (Global.Config.GB_ForceDMG) R.AddOption("ForceDMG"); - if (Global.Config.GB_GBACGB) R.AddOption("GBACGB"); - if (Global.Config.GB_MulticartCompat) R.AddOption("MulitcartCompat"); + if (Global.Config.GB_GBACGB) R.AddOption("GBACGB"); + if (Global.Config.GB_MulticartCompat) R.AddOption("MulitcartCompat"); GambatteLink gbl = new GambatteLink(nextComm, L, XMLG.Assets["LeftRom"], R, XMLG.Assets["RightRom"]); - nextEmulator = gbl; - // other stuff todo + nextEmulator = gbl; + // other stuff todo break; default: @@ -1234,8 +1234,8 @@ namespace BizHawk.MultiClient var snes = new LibsnesCore(nextComm); nextEmulator = snes; - byte[] romData = isXml?null:rom.FileData; - byte[] xmlData = isXml?rom.FileData:null; + byte[] romData = isXml ? null : rom.FileData; + byte[] xmlData = isXml ? rom.FileData : null; snes.Load(game, romData, null, deterministicemulation, xmlData); } break; @@ -1275,7 +1275,7 @@ namespace BizHawk.MultiClient case "NES": { //TODO - move into nes core - string biosPath = nextComm.CoreFileProvider.PathFirmware("NES","Bios_FDS"); + string biosPath = nextComm.CoreFileProvider.PathFirmware("NES", "Bios_FDS"); byte[] bios = null; if (File.Exists(biosPath)) { @@ -1310,66 +1310,66 @@ namespace BizHawk.MultiClient break; case "GB": case "GBC": - if (!Global.Config.GB_AsSGB) + if (!Global.Config.GB_AsSGB) + { + if (Global.Config.GB_ForceDMG) game.AddOption("ForceDMG"); + if (Global.Config.GB_GBACGB) game.AddOption("GBACGB"); + if (Global.Config.GB_MulticartCompat) game.AddOption("MulitcartCompat"); + Gameboy gb = new Gameboy(nextComm, game, rom.FileData); + nextEmulator = gb; + if (gb.IsCGBMode()) { - if (Global.Config.GB_ForceDMG) game.AddOption("ForceDMG"); - if (Global.Config.GB_GBACGB) game.AddOption("GBACGB"); - if (Global.Config.GB_MulticartCompat) game.AddOption("MulitcartCompat"); - Gameboy gb = new Gameboy(nextComm, game, rom.FileData); - nextEmulator = gb; - if (gb.IsCGBMode()) - { - gb.SetCGBColors(Global.Config.CGBColors); - } - else - { - try - { - using (StreamReader f = new StreamReader(Global.Config.GB_PaletteFile)) - { - int[] colors = GBtools.ColorChooserForm.LoadPalFile(f); - if (colors != null) - gb.ChangeDMGColors(colors); - } - } - catch { } - } + gb.SetCGBColors(Global.Config.CGBColors); } else { - string sgbromPath = this.FirmwareManager.Request("SNES","Rom_SGB"); - byte[] sgbrom = null; try { - if (File.Exists(sgbromPath)) + using (StreamReader f = new StreamReader(Global.Config.GB_PaletteFile)) { - sgbrom = File.ReadAllBytes(sgbromPath); - } - else - { - MessageBox.Show("Couldn't open sgb.sfc from the configured SNES firmwares path, which is:\n\n" + sgbromPath + "\n\nPlease make sure it is available and try again.\n\nWe're going to disable SGB for now; please re-enable it when you've set up the file."); - Global.Config.GB_AsSGB = false; - game.System = "GB"; - goto RETRY; + int[] colors = GBtools.ColorChooserForm.LoadPalFile(f); + if (colors != null) + gb.ChangeDMGColors(colors); } } - catch (Exception) + catch { } + } + } + else + { + string sgbromPath = this.FirmwareManager.Request("SNES", "Rom_SGB"); + byte[] sgbrom = null; + try + { + if (File.Exists(sgbromPath)) { - // failed to load SGB bios. to avoid catch-22, disable SGB mode + sgbrom = File.ReadAllBytes(sgbromPath); + } + else + { + MessageBox.Show("Couldn't open sgb.sfc from the configured SNES firmwares path, which is:\n\n" + sgbromPath + "\n\nPlease make sure it is available and try again.\n\nWe're going to disable SGB for now; please re-enable it when you've set up the file."); Global.Config.GB_AsSGB = false; - throw; - } - if (sgbrom != null) - { - game.System = "SNES"; - game.AddOption("SGB"); - nextComm.SNES_ExePath = SNES_Prepare(Global.Config.SNESProfile); - var snes = new LibsnesCore(nextComm); - nextEmulator = snes; - game.FirmwareHash = Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(sgbrom)); - snes.Load(game, rom.FileData, sgbrom, deterministicemulation, null); + game.System = "GB"; + goto RETRY; } } + catch (Exception) + { + // failed to load SGB bios. to avoid catch-22, disable SGB mode + Global.Config.GB_AsSGB = false; + throw; + } + if (sgbrom != null) + { + game.System = "SNES"; + game.AddOption("SGB"); + nextComm.SNES_ExePath = SNES_Prepare(Global.Config.SNESProfile); + var snes = new LibsnesCore(nextComm); + nextEmulator = snes; + game.FirmwareHash = Util.BytesToHexString(System.Security.Cryptography.SHA1.Create().ComputeHash(sgbrom)); + snes.Load(game, rom.FileData, sgbrom, deterministicemulation, null); + } + } //} break; case "Coleco": @@ -1443,16 +1443,16 @@ namespace BizHawk.MultiClient } string gamedbpath = Path.Combine(PathManager.GetExeDirectoryAbsolute(), "gamedb", "EMU7800.csv"); - try - { - var a78 = new Atari7800(nextComm, game, rom.RomData, NTSC_BIOS7800, PAL_BIOS7800, HighScoreBIOS, gamedbpath); - nextEmulator = a78; - } - catch (InvalidDataException ex) - { - MessageBox.Show(ex.Message, "Region specific bios missing", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } + try + { + var a78 = new Atari7800(nextComm, game, rom.RomData, NTSC_BIOS7800, PAL_BIOS7800, HighScoreBIOS, gamedbpath); + nextEmulator = a78; + } + catch (InvalidDataException ex) + { + MessageBox.Show(ex.Message, "Region specific bios missing", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } break; case "C64": C64 c64 = new C64(nextComm, game, rom.RomData, rom.Extension); @@ -1710,7 +1710,7 @@ namespace BizHawk.MultiClient { sram = new byte[Global.Emulator.ReadSaveRam().Length]; using (var reader = new BinaryReader(new FileStream(PathManager.SaveRamPath(Global.Game), FileMode.Open, FileAccess.Read))) - reader.Read(sram, 0, sram.Length); + reader.Read(sram, 0, sram.Length); } Global.Emulator.StoreSaveRam(sram); } @@ -1832,7 +1832,7 @@ namespace BizHawk.MultiClient //zero 09-sep-2012 - all input is eligible for controller input. not sure why the above was done. //maybe because it doesnt make sense to me to bind hotkeys and controller inputs to the same keystrokes - + //adelikat 02-dec-2012 - implemented options for how to handle controller vs hotkey conflicts. This is primarily motivated by computer emulation and thus controller being nearly the entire keyboard bool handled; switch (Global.Config.Input_Hotkey_OverrideOptions) @@ -2054,7 +2054,7 @@ namespace BizHawk.MultiClient case "Ram Search": LoadRamSearch(); break; case "Ram Poke": new RamPoke().Show(); break; case "Hex Editor": LoadHexEditor(); break; - case "Trace Logger": LoadTraceLogger(); break; + case "Trace Logger": LoadTraceLogger(); break; case "Lua Console": OpenLuaConsole(); break; case "Cheats": LoadCheatsWindow(); break; case "TAStudio": LoadTAStudio(); break; @@ -2106,7 +2106,7 @@ namespace BizHawk.MultiClient if (Global.Config.SkipLagFrame && Global.Emulator.IsLagFrame && frameProgressTimeElapsed) { - runFrame = true; + runFrame = true; } if (Global.ClientControls["Frame Advance"] || PressFrameAdvance) @@ -2236,7 +2236,7 @@ namespace BizHawk.MultiClient { AVIFrameAdvance(); } - + if (Global.Emulator.IsLagFrame && Global.Config.AutofireLagFrames) { Global.AutoFireController.IncrementStarts(); @@ -2281,11 +2281,11 @@ namespace BizHawk.MultiClient public void UpdateToolsBefore(bool fromLua = false) { #if WINDOWS - if (_luaconsole != null) - { - if (!fromLua) LuaConsole1.StartLuaDrawing(); - LuaConsole1.LuaImp.FrameRegisterBefore(); - } + if (_luaconsole != null) + { + if (!fromLua) LuaConsole1.StartLuaDrawing(); + LuaConsole1.LuaImp.FrameRegisterBefore(); + } #endif if (_nesnametableview != null) NESNameTableViewer1.UpdateValues(); if (_nesppu != null) NESPPU1.UpdateValues(); @@ -2305,14 +2305,14 @@ namespace BizHawk.MultiClient public void UpdateToolsAfter(bool fromLua = false) { #if WINDOWS - if (_luaconsole != null && !fromLua) - { - LuaConsole1.ResumeScripts(true); - } + if (_luaconsole != null && !fromLua) + { + LuaConsole1.ResumeScripts(true); + } #endif if (_ramwatch != null) RamWatch1.UpdateValues(); - if (_newramwatch != null) NewRamWatch1.UpdateValues(); + if (_newramwatch != null) NewRamWatch1.UpdateValues(); 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 @@ -2324,15 +2324,15 @@ namespace BizHawk.MultiClient if (_tracelogger != null) TraceLogger1.UpdateValues(); HandleToggleLight(); #if WINDOWS - if (_luaconsole != null) - { - LuaConsole1.LuaImp.FrameRegisterAfter(); - if (!fromLua) - { - Global.DisplayManager.PreFrameUpdateLuaSource(); - LuaConsole1.EndLuaDrawing(); - } - } + if (_luaconsole != null) + { + LuaConsole1.LuaImp.FrameRegisterAfter(); + if (!fromLua) + { + Global.DisplayManager.PreFrameUpdateLuaSource(); + LuaConsole1.EndLuaDrawing(); + } + } #endif } @@ -2561,7 +2561,7 @@ namespace BizHawk.MultiClient catch (EndOfStreamException) { } - + }); @@ -2571,7 +2571,7 @@ namespace BizHawk.MultiClient bw.Dispose(); } } - else + else { // text mode @@ -2600,7 +2600,7 @@ namespace BizHawk.MultiClient Global.OSD.AddMessage("Loadstate error!"); } - cleanup: + cleanup: Global.OSD.ClearGUIText(); UpdateToolsBefore(fromLua); UpdateToolsAfter(fromLua); @@ -2730,7 +2730,7 @@ namespace BizHawk.MultiClient else SNESgg.Focus(); } - else if ((Global.Emulator.SystemId == "GB") || (Global.Game.System == "GG")) + else if ((Global.Emulator.SystemId == "GB") || (Global.Game.System == "GG")) { if (!GBgg.IsHandleCreated || GBgg.IsDisposed) { @@ -2894,7 +2894,7 @@ namespace BizHawk.MultiClient PluginToUse = Global.MovieSession.Movie.Header.HeaderParams[MovieHeader.VIDEOPLUGIN]; } - if (PluginToUse == "" || (PluginToUse != "Rice" && PluginToUse != "Glide64")) + if (PluginToUse == "" || (PluginToUse != "Rice" && PluginToUse != "Glide64")) { PluginToUse = Global.Config.N64VidPlugin; } @@ -2916,7 +2916,7 @@ namespace BizHawk.MultiClient Global.Config.Glide64mk2Plugin.FillPerGameHacks(game); video_settings.Parameters = Global.Config.Glide64mk2Plugin.GetPluginSettings(); } - + if (hasmovie && Global.MovieSession.Movie.Header.HeaderParams[MovieHeader.PLATFORM] == "N64" && Global.MovieSession.Movie.Header.HeaderParams.ContainsKey(MovieHeader.VIDEOPLUGIN)) { List settings = new List(video_settings.Parameters.Keys); @@ -2953,7 +2953,7 @@ namespace BizHawk.MultiClient } } } - + return video_settings; } @@ -3077,7 +3077,7 @@ namespace BizHawk.MultiClient //sends a simulation of a plain alt key keystroke void SendPlainAltKey(int lparam) { - Message m = new Message {WParam = new IntPtr(0xF100), LParam = new IntPtr(lparam), Msg = 0x0112, HWnd = Handle}; + Message m = new Message { WParam = new IntPtr(0xF100), LParam = new IntPtr(lparam), Msg = 0x0112, HWnd = Handle }; base.WndProc(ref m); } @@ -3105,7 +3105,7 @@ namespace BizHawk.MultiClient int LastOpenRomFilter; private void OpenROM() { - var ofd = new OpenFileDialog {InitialDirectory = PathManager.GetRomsPath(Global.Emulator.SystemId)}; + var ofd = new OpenFileDialog { InitialDirectory = PathManager.GetRomsPath(Global.Emulator.SystemId) }; //"Rom Files|*.NES;*.SMS;*.GG;*.SG;*.PCE;*.SGX;*.GB;*.BIN;*.SMD;*.ROM;*.ZIP;*.7z|NES (*.NES)|*.NES|Master System|*.SMS;*.GG;*.SG;*.ZIP;*.7z|PC Engine|*.PCE;*.SGX;*.ZIP;*.7z|Gameboy|*.GB;*.ZIP;*.7z|TI-83|*.rom|Archive Files|*.zip;*.7z|Savestate|*.state|All Files|*.*"; //adelikat: ugly design for this, I know @@ -3153,13 +3153,13 @@ namespace BizHawk.MultiClient "Archive Files", "%ARCH%", "Savestate", "*.state", "Genesis (experimental)", "*.gen;*.md;*.smd;*.bin;*.cue;%ARCH%", - + "All Files", "*.*"); } - + ofd.RestoreDirectory = false; ofd.FilterIndex = LastOpenRomFilter; - + Global.Sound.StopSound(); var result = ofd.ShowDialog(); Global.Sound.StartSound(); @@ -3336,9 +3336,13 @@ namespace BizHawk.MultiClient { ReadOnly = read_only; if (ReadOnly) + { Global.OSD.AddMessage("Movie read-only mode"); + } else + { Global.OSD.AddMessage("Movie read+write mode"); + } } public void LoadRamWatch(bool load_dialog) @@ -3346,7 +3350,7 @@ namespace BizHawk.MultiClient if (!RamWatch1.IsHandleCreated || RamWatch1.IsDisposed) { RamWatch1 = new RamWatch(); - if (Global.Config.AutoLoadRamWatch && Global.Config.RecentWatches.Count > 0) + if (Global.Config.RecentWatches.AutoLoad && !Global.Config.RecentWatches.Empty) { RamWatch1.LoadWatchFromRecent(Global.Config.RecentWatches[0]); } @@ -3356,7 +3360,9 @@ namespace BizHawk.MultiClient } } else + { RamWatch1.Focus(); + } } public void LoadTAStudio() @@ -3799,14 +3805,14 @@ namespace BizHawk.MultiClient if (autoDumpLength > 0) { autoDumpLength--; - if (autoDumpLength == 0) // finish - { - StopAVI(); - if (autoCloseOnDump) - { - Close(); - } - } + if (autoDumpLength == 0) // finish + { + StopAVI(); + if (autoCloseOnDump) + { + Close(); + } + } } } } @@ -4191,29 +4197,29 @@ namespace BizHawk.MultiClient Global.DisplayManager.NeedsToPaint = true; } - private void newRamWatchToolStripMenuItem_Click(object sender, EventArgs e) - { - LoadNewRamWatch(true); - } + private void newRamWatchToolStripMenuItem_Click(object sender, EventArgs e) + { + LoadNewRamWatch(true); + } - private void LoadNewRamWatch(bool load_dialog) - { - if (!NewRamWatch1.IsHandleCreated || NewRamWatch1.IsDisposed) - { - NewRamWatch1 = new NewRamWatch(); - if (Global.Config.AutoLoadRamWatch && Global.Config.RecentWatches.Count > 0) - { - NewRamWatch1.LoadWatchFromRecent(Global.Config.RecentWatches[0]); - } - if (load_dialog) - { - NewRamWatch1.Show(); - } - } - else - { - NewRamWatch1.Focus(); - } - } + private void LoadNewRamWatch(bool load_dialog) + { + if (!NewRamWatch1.IsHandleCreated || NewRamWatch1.IsDisposed) + { + NewRamWatch1 = new NewRamWatch(); + if (Global.Config.RecentWatches.AutoLoad && !Global.Config.RecentWatches.Empty) + { + NewRamWatch1.LoadWatchFromRecent(Global.Config.RecentWatches[0]); + } + if (load_dialog) + { + NewRamWatch1.Show(); + } + } + else + { + NewRamWatch1.Focus(); + } + } } } diff --git a/BizHawk.MultiClient/RecentFiles.cs b/BizHawk.MultiClient/RecentFiles.cs index 5977d09df9..1daee00cca 100644 --- a/BizHawk.MultiClient/RecentFiles.cs +++ b/BizHawk.MultiClient/RecentFiles.cs @@ -11,6 +11,8 @@ namespace BizHawk.MultiClient private readonly int MAX_RECENT_FILES; //Maximum number of files private readonly List recentlist; //List of recent files + public bool AutoLoad = false; + public RecentFiles() : this(8) { } public RecentFiles(int max) { @@ -18,15 +20,15 @@ namespace BizHawk.MultiClient MAX_RECENT_FILES = max; } - public IEnumerator GetEnumerator() - { - return recentlist.GetEnumerator(); - } + public IEnumerator GetEnumerator() + { + return recentlist.GetEnumerator(); + } - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return GetEnumerator(); - } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } public void Clear() { @@ -79,52 +81,59 @@ namespace BizHawk.MultiClient return recentlist.Select(t => t.Substring(0, length)).ToList(); } - public string this[int index] - { - get - { - if (recentlist.Any()) - { - return recentlist[index]; - } - else - { - return ""; - } - } - } + public string this[int index] + { + get + { + if (recentlist.Any()) + { + return recentlist[index]; + } + else + { + return ""; + } + } + } - public void GenerateRecentMenu(ToolStripMenuItem menu, Action loadFileCallback, bool? autoloadConfigVar = null, Action autoloadCallback = null) - { - menu.DropDownItems.Clear(); + public List GenerateRecentMenu(Action loadFileCallback) + { + var items = new List(); - if (Empty) - { - var none = new ToolStripMenuItem { Enabled = false, Text = "None" }; - menu.DropDownItems.Add(none); - } - else - { - foreach (string filename in recentlist) - { - var item = new ToolStripMenuItem { Text = filename }; - item.Click += (o, ev) => loadFileCallback(filename); - menu.DropDownItems.Add(item); - } - } + if (Empty) + { + var none = new ToolStripMenuItem { Enabled = false, Text = "None" }; + items.Add(none); + } + else + { + foreach (string filename in recentlist) + { + var item = new ToolStripMenuItem { Text = filename }; + item.Click += (o, ev) => loadFileCallback(filename); + items.Add(item); + } + } - menu.DropDownItems.Add("-"); + items.Add(new ToolStripSeparator()); - var clearitem = new ToolStripMenuItem { Text = "&Clear" }; - clearitem.Click += (o, ev) => recentlist.Clear(); - menu.DropDownItems.Add(clearitem); + var clearitem = new ToolStripMenuItem { Text = "&Clear" }; + clearitem.Click += (o, ev) => recentlist.Clear(); + items.Add(clearitem); - if (autoloadConfigVar.HasValue) - { - var auto = new ToolStripMenuItem { Text = "&Auto-Load", Checked = autoloadConfigVar.Value }; - auto.Click += (o, ev) => autoloadCallback(); - menu.DropDownItems.Add(auto); - } - } + return items; + } + + public ToolStripMenuItem GenerateAutoLoadItem() + { + var auto = new ToolStripMenuItem { Text = "&Auto-Load", Checked = AutoLoad }; + auto.Click += (o, ev) => ToggleAutoLoad(); + return auto; + } + + private void ToggleAutoLoad() + { + AutoLoad ^= true; + } } } diff --git a/BizHawk.MultiClient/tools/NewRamWatch.cs b/BizHawk.MultiClient/tools/NewRamWatch.cs index 04d7890b2d..9a9588a6e2 100644 --- a/BizHawk.MultiClient/tools/NewRamWatch.cs +++ b/BizHawk.MultiClient/tools/NewRamWatch.cs @@ -12,9 +12,9 @@ namespace BizHawk.MultiClient { public partial class NewRamWatch : Form { - private int defaultWidth; - private int defaultHeight; - private WatchList Watches = new WatchList(); + private int defaultWidth; + private int defaultHeight; + private WatchList Watches = new WatchList(); private string systemID = "NULL"; private string sortedCol = ""; private bool sortReverse = false; @@ -25,17 +25,17 @@ namespace BizHawk.MultiClient WatchListView.QueryItemText += WatchListView_QueryItemText; WatchListView.QueryItemBkColor += WatchListView_QueryItemBkColor; WatchListView.VirtualMode = true; - Closing += (o, e) => SaveConfigSettings(); - sortedCol = ""; - sortReverse = false; + Closing += (o, e) => SaveConfigSettings(); + sortedCol = ""; + sortReverse = false; } - protected override void OnClosing(CancelEventArgs e) - { - if (!AskSave()) - e.Cancel = true; - base.OnClosing(e); - } + protected override void OnClosing(CancelEventArgs e) + { + if (!AskSave()) + e.Cancel = true; + base.OnClosing(e); + } private void WatchListView_QueryItemBkColor(int index, int column, ref Color color) { @@ -230,50 +230,45 @@ namespace BizHawk.MultiClient } } - private void UpdateAutoLoadRamWatch() - { - Global.Config.AutoLoadRamWatch ^= true; - } + public void SaveConfigSettings() + { + Global.Config.RamWatchAddressWidth = WatchListView.Columns[Global.Config.RamWatchAddressIndex].Width; + Global.Config.RamWatchValueWidth = WatchListView.Columns[Global.Config.RamWatchValueIndex].Width; + Global.Config.RamWatchPrevWidth = WatchListView.Columns[Global.Config.RamWatchPrevIndex].Width; + Global.Config.RamWatchChangeWidth = WatchListView.Columns[Global.Config.RamWatchChangeIndex].Width; + Global.Config.RamWatchDiffWidth = WatchListView.Columns[Global.Config.RamWatchDiffIndex].Width; + Global.Config.RamWatchDomainWidth = WatchListView.Columns[Global.Config.RamWatchDomainIndex].Width; + Global.Config.RamWatchNotesWidth = WatchListView.Columns[Global.Config.RamWatchNotesIndex].Width; - public void SaveConfigSettings() - { - Global.Config.RamWatchAddressWidth = WatchListView.Columns[Global.Config.RamWatchAddressIndex].Width; - Global.Config.RamWatchValueWidth = WatchListView.Columns[Global.Config.RamWatchValueIndex].Width; - Global.Config.RamWatchPrevWidth = WatchListView.Columns[Global.Config.RamWatchPrevIndex].Width; - Global.Config.RamWatchChangeWidth = WatchListView.Columns[Global.Config.RamWatchChangeIndex].Width; - Global.Config.RamWatchDiffWidth = WatchListView.Columns[Global.Config.RamWatchDiffIndex].Width; - Global.Config.RamWatchDomainWidth = WatchListView.Columns[Global.Config.RamWatchDomainIndex].Width; - Global.Config.RamWatchNotesWidth = WatchListView.Columns[Global.Config.RamWatchNotesIndex].Width; - - Global.Config.RamWatchWndx = Location.X; - Global.Config.RamWatchWndy = Location.Y; - Global.Config.RamWatchWidth = Right - Left; - Global.Config.RamWatchHeight = Bottom - Top; - } + Global.Config.RamWatchWndx = Location.X; + Global.Config.RamWatchWndy = Location.Y; + Global.Config.RamWatchWidth = Right - Left; + Global.Config.RamWatchHeight = Bottom - Top; + } #region Winform Events - private void NewRamWatch_Load(object sender, EventArgs e) - { - defaultWidth = Size.Width; //Save these first so that the user can restore to its original size - defaultHeight = Size.Height; + private void NewRamWatch_Load(object sender, EventArgs e) + { + defaultWidth = Size.Width; //Save these first so that the user can restore to its original size + defaultHeight = Size.Height; - if (Global.Config.RamWatchSaveWindowPosition && Global.Config.RamWatchWndx >= 0 && Global.Config.RamWatchWndy >= 0) - { - Location = new Point(Global.Config.RamWatchWndx, Global.Config.RamWatchWndy); - } + if (Global.Config.RamWatchSaveWindowPosition && Global.Config.RamWatchWndx >= 0 && Global.Config.RamWatchWndy >= 0) + { + Location = new Point(Global.Config.RamWatchWndx, Global.Config.RamWatchWndy); + } - if (Global.Config.RamWatchWidth >= 0 && Global.Config.RamWatchHeight >= 0) - { - Size = new Size(Global.Config.RamWatchWidth, Global.Config.RamWatchHeight); - } - } + if (Global.Config.RamWatchWidth >= 0 && Global.Config.RamWatchHeight >= 0) + { + Size = new Size(Global.Config.RamWatchWidth, Global.Config.RamWatchHeight); + } + } - /*************File***********************/ - private void filesToolStripMenuItem_DropDownOpened(object sender, EventArgs e) - { - saveToolStripMenuItem.Enabled = Watches.Changes; - } + /*************File***********************/ + private void filesToolStripMenuItem_DropDownOpened(object sender, EventArgs e) + { + saveToolStripMenuItem.Enabled = Watches.Changes; + } private void newListToolStripMenuItem_Click(object sender, EventArgs e) { @@ -282,8 +277,8 @@ namespace BizHawk.MultiClient private void openToolStripMenuItem_Click(object sender, EventArgs e) { - bool append = sender == appendFileToolStripMenuItem; - var file = WatchList.GetFileFromUser(Watches.CurrentFileName); + bool append = sender == appendFileToolStripMenuItem; + var file = WatchList.GetFileFromUser(Watches.CurrentFileName); if (file != null) { bool result = true; @@ -296,7 +291,7 @@ namespace BizHawk.MultiClient { Watches.Load(file.FullName, true, append); DisplayWatches(); - MessageLabel.Text = Path.GetFileNameWithoutExtension(Watches.CurrentFileName) + (Watches.Changes ? " *" : String.Empty); + MessageLabel.Text = Path.GetFileNameWithoutExtension(Watches.CurrentFileName) + (Watches.Changes ? " *" : String.Empty); UpdateWatchCount(); Global.Config.RecentWatches.Add(Watches.CurrentFileName); SetMemoryDomain(WatchCommon.GetDomainPos(Watches.Domain.ToString())); @@ -304,29 +299,31 @@ namespace BizHawk.MultiClient } } - private void saveToolStripMenuItem_Click(object sender, EventArgs e) - { - bool result = Watches.Save(); - if (result) - { - MessageLabel.Text = Path.GetFileName(Watches.CurrentFileName) + " saved."; - } - } + private void saveToolStripMenuItem_Click(object sender, EventArgs e) + { + bool result = Watches.Save(); + if (result) + { + MessageLabel.Text = Path.GetFileName(Watches.CurrentFileName) + " saved."; + } + } - private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) - { - bool result = Watches.SaveAs(); - if (result) - { - MessageLabel.Text = Path.GetFileName(Watches.CurrentFileName) + " saved."; - Global.Config.RecentWatches.Add(Watches.CurrentFileName); - } - } + private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) + { + bool result = Watches.SaveAs(); + if (result) + { + MessageLabel.Text = Path.GetFileName(Watches.CurrentFileName) + " saved."; + Global.Config.RecentWatches.Add(Watches.CurrentFileName); + } + } - private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e) - { - Global.Config.RecentWatches.GenerateRecentMenu(recentToolStripMenuItem, LoadWatchFromRecent, Global.Config.AutoLoadRamWatch, UpdateAutoLoadRamWatch); - } + private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e) + { + recentToolStripMenuItem.DropDownItems.Clear(); + recentToolStripMenuItem.DropDownItems.AddRange(Global.Config.RecentWatches.GenerateRecentMenu(LoadWatchFromRecent).ToArray()); + recentToolStripMenuItem.DropDownItems.Add(Global.Config.RecentWatches.GenerateAutoLoadItem()); + } private void exitToolStripMenuItem_Click(object sender, EventArgs e) { @@ -340,59 +337,59 @@ namespace BizHawk.MultiClient } } - /*************Options***********************/ - private void optionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e) - { - displayWatchesOnScreenToolStripMenuItem.Checked = Global.Config.DisplayRamWatch; - saveWindowPositionToolStripMenuItem.Checked = Global.Config.RamWatchSaveWindowPosition; - } + /*************Options***********************/ + private void optionsToolStripMenuItem_DropDownOpened(object sender, EventArgs e) + { + displayWatchesOnScreenToolStripMenuItem.Checked = Global.Config.DisplayRamWatch; + saveWindowPositionToolStripMenuItem.Checked = Global.Config.RamWatchSaveWindowPosition; + } - private void displayWatchesOnScreenToolStripMenuItem_Click(object sender, EventArgs e) - { - Global.Config.DisplayRamWatch ^= true; + private void displayWatchesOnScreenToolStripMenuItem_Click(object sender, EventArgs e) + { + Global.Config.DisplayRamWatch ^= true; - if (!Global.Config.DisplayRamWatch) - { - Global.OSD.ClearGUIText(); - } - else - { - UpdateValues(); - } - } + if (!Global.Config.DisplayRamWatch) + { + Global.OSD.ClearGUIText(); + } + else + { + UpdateValues(); + } + } - private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e) - { - Global.Config.RamWatchSaveWindowPosition ^= true; - } + private void saveWindowPositionToolStripMenuItem_Click(object sender, EventArgs e) + { + Global.Config.RamWatchSaveWindowPosition ^= true; + } - private void restoreWindowSizeToolStripMenuItem_Click(object sender, EventArgs e) - { - Size = new Size(defaultWidth, defaultHeight); + private void restoreWindowSizeToolStripMenuItem_Click(object sender, EventArgs e) + { + Size = new Size(defaultWidth, defaultHeight); - Global.Config.RamWatchAddressIndex = 0; - Global.Config.RamWatchValueIndex = 1; - Global.Config.RamWatchPrevIndex = 2; - Global.Config.RamWatchChangeIndex = 3; - Global.Config.RamWatchDiffIndex = 4; - Global.Config.RamWatchNotesIndex = 5; + Global.Config.RamWatchAddressIndex = 0; + Global.Config.RamWatchValueIndex = 1; + Global.Config.RamWatchPrevIndex = 2; + Global.Config.RamWatchChangeIndex = 3; + Global.Config.RamWatchDiffIndex = 4; + Global.Config.RamWatchNotesIndex = 5; - showPreviousValueToolStripMenuItem.Checked = false; - Global.Config.RamWatchShowPrevColumn = false; - showChangeCountsToolStripMenuItem.Checked = true; - Global.Config.RamWatchShowChangeColumn = true; - Global.Config.RamWatchShowDiffColumn = false; - Global.Config.RamWatchShowDomainColumn = true; - WatchListView.Columns[0].Width = 60; - WatchListView.Columns[1].Width = 59; - WatchListView.Columns[2].Width = 0; - WatchListView.Columns[3].Width = 55; - WatchListView.Columns[4].Width = 0; - WatchListView.Columns[5].Width = 55; - WatchListView.Columns[6].Width = 128; - Global.Config.DisplayRamWatch = false; - Global.Config.RamWatchSaveWindowPosition = true; - } + showPreviousValueToolStripMenuItem.Checked = false; + Global.Config.RamWatchShowPrevColumn = false; + showChangeCountsToolStripMenuItem.Checked = true; + Global.Config.RamWatchShowChangeColumn = true; + Global.Config.RamWatchShowDiffColumn = false; + Global.Config.RamWatchShowDomainColumn = true; + WatchListView.Columns[0].Width = 60; + WatchListView.Columns[1].Width = 59; + WatchListView.Columns[2].Width = 0; + WatchListView.Columns[3].Width = 55; + WatchListView.Columns[4].Width = 0; + WatchListView.Columns[5].Width = 55; + WatchListView.Columns[6].Width = 128; + Global.Config.DisplayRamWatch = false; + Global.Config.RamWatchSaveWindowPosition = true; + } #endregion } diff --git a/BizHawk.MultiClient/tools/RamWatch.cs b/BizHawk.MultiClient/tools/RamWatch.cs index 01b0ac0f6a..7023cf86eb 100644 --- a/BizHawk.MultiClient/tools/RamWatch.cs +++ b/BizHawk.MultiClient/tools/RamWatch.cs @@ -672,29 +672,14 @@ namespace BizHawk.MultiClient private void filesToolStripMenuItem_DropDownOpened(object sender, EventArgs e) { - if (Global.Config.AutoLoadRamWatch) - { - autoLoadToolStripMenuItem.Checked = true; - } - else - { - autoLoadToolStripMenuItem.Checked = false; - } - - if (!changes) - { - saveToolStripMenuItem.Enabled = false; - } - else - { - saveToolStripMenuItem.Enabled = true; - } + saveToolStripMenuItem.Enabled = changes; } private void UpdateAutoLoadRamWatch() { - autoLoadToolStripMenuItem.Checked = Global.Config.AutoLoadRamWatch ^= true; + autoLoadToolStripMenuItem.Checked = Global.Config.RecentWatches.AutoLoad ^= true; } + private void recentToolStripMenuItem_DropDownOpened(object sender, EventArgs e) { //Clear out recent Roms list @@ -725,15 +710,7 @@ namespace BizHawk.MultiClient var auto = new ToolStripMenuItem {Text = "&Auto-Load"}; auto.Click += (o, ev) => UpdateAutoLoadRamWatch(); - if (Global.Config.AutoLoadRamWatch) - { - auto.Checked = true; - } - else - { - auto.Checked = false; - } - + auto.Checked = Global.Config.RecentWatches.AutoLoad; recentToolStripMenuItem.DropDownItems.Add(auto); }