diff --git a/BizHawk.Client.Common/config/Config.cs b/BizHawk.Client.Common/config/Config.cs index 74c8bc767c..263a33d3a9 100644 --- a/BizHawk.Client.Common/config/Config.cs +++ b/BizHawk.Client.Common/config/Config.cs @@ -411,6 +411,8 @@ namespace BizHawk.Client.Common #endregion + public Dictionary CommonToolSettings = new Dictionary(); + // SMS VDP Viewer Settings public ToolDialogSettings SmsVdpSettings = new ToolDialogSettings(); public bool SmsVdpAutoLoad = false; @@ -419,10 +421,6 @@ namespace BizHawk.Client.Common public ToolDialogSettings PceVdpSettings = new ToolDialogSettings(); public bool PceVdpAutoLoad = false; - // Genesis VDP Viewer Settings - public ToolDialogSettings GenVdpSettings = new ToolDialogSettings(); - public bool GenVdpAutoLoad = false; - // NESPPU Settings public ToolDialogSettings NesPPUSettings = new ToolDialogSettings(); public bool AutoLoadNESPPU = false; diff --git a/BizHawk.Client.Common/config/ToolDialogSettings.cs b/BizHawk.Client.Common/config/ToolDialogSettings.cs index 099719f708..5dabf9bdb1 100644 --- a/BizHawk.Client.Common/config/ToolDialogSettings.cs +++ b/BizHawk.Client.Common/config/ToolDialogSettings.cs @@ -48,6 +48,7 @@ namespace BizHawk.Client.Common public bool SaveWindowPosition { get; set; } public bool TopMost { get; set; } public bool FloatingWindow { get; set; } + public bool AutoLoad { get; set; } [JsonIgnore] public bool UseWindowPosition diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index 50ef170ad8..4a14089342 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -355,6 +355,8 @@ namespace BizHawk.Client.EmuHawk LoadQuickSave("QuickSave" + Global.Config.SaveSlot); } + GlobalWin.Tools.AutoLoad(); + if (Global.Config.RecentWatches.AutoLoad) { GlobalWin.Tools.LoadRamWatch(!Global.Config.DisplayRamWatch); @@ -435,11 +437,6 @@ namespace BizHawk.Client.EmuHawk GlobalWin.Tools.Load(); } - if (Global.Config.GenVdpAutoLoad) - { - GlobalWin.Tools.Load(); - } - if (Global.Config.AutoLoadSNESGraphicsDebugger) { GlobalWin.Tools.Load(); diff --git a/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.Designer.cs b/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.Designer.cs index 7f4c6d1312..dbe1b3d05d 100644 --- a/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.Designer.cs @@ -48,11 +48,6 @@ this.savePaletteScreenshotToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.closeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.OptionsSubMenu = new System.Windows.Forms.ToolStripMenuItem(); - this.AutoloadMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.SaveWindowPositionMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.AlwaysOnTopMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.FloatingWindowMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -165,8 +160,7 @@ // this.menuStrip1.ClickThrough = true; this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.fileToolStripMenuItem, - this.OptionsSubMenu}); + this.fileToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1078, 24); @@ -184,97 +178,57 @@ this.toolStripSeparator1, this.closeToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); + this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20); this.fileToolStripMenuItem.Text = "&File"; // // saveBGAScreenshotToolStripMenuItem // this.saveBGAScreenshotToolStripMenuItem.Name = "saveBGAScreenshotToolStripMenuItem"; - this.saveBGAScreenshotToolStripMenuItem.Size = new System.Drawing.Size(215, 22); + this.saveBGAScreenshotToolStripMenuItem.Size = new System.Drawing.Size(208, 22); this.saveBGAScreenshotToolStripMenuItem.Text = "Save BG A Screenshot..."; this.saveBGAScreenshotToolStripMenuItem.Click += new System.EventHandler(this.saveBGAScreenshotToolStripMenuItem_Click); // // saveBGBScreenshotToolStripMenuItem // this.saveBGBScreenshotToolStripMenuItem.Name = "saveBGBScreenshotToolStripMenuItem"; - this.saveBGBScreenshotToolStripMenuItem.Size = new System.Drawing.Size(215, 22); + this.saveBGBScreenshotToolStripMenuItem.Size = new System.Drawing.Size(208, 22); this.saveBGBScreenshotToolStripMenuItem.Text = "Save BG B Screenshot..."; this.saveBGBScreenshotToolStripMenuItem.Click += new System.EventHandler(this.saveBGBScreenshotToolStripMenuItem_Click); // // saveTilesScreenshotToolStripMenuItem // this.saveTilesScreenshotToolStripMenuItem.Name = "saveTilesScreenshotToolStripMenuItem"; - this.saveTilesScreenshotToolStripMenuItem.Size = new System.Drawing.Size(215, 22); + this.saveTilesScreenshotToolStripMenuItem.Size = new System.Drawing.Size(208, 22); this.saveTilesScreenshotToolStripMenuItem.Text = "Save Tiles Screenshot..."; this.saveTilesScreenshotToolStripMenuItem.Click += new System.EventHandler(this.saveTilesScreenshotToolStripMenuItem_Click); // // saveWindowScreenshotToolStripMenuItem // this.saveWindowScreenshotToolStripMenuItem.Name = "saveWindowScreenshotToolStripMenuItem"; - this.saveWindowScreenshotToolStripMenuItem.Size = new System.Drawing.Size(215, 22); + this.saveWindowScreenshotToolStripMenuItem.Size = new System.Drawing.Size(208, 22); this.saveWindowScreenshotToolStripMenuItem.Text = "Save Window Screenshot..."; this.saveWindowScreenshotToolStripMenuItem.Click += new System.EventHandler(this.saveWindowScreenshotToolStripMenuItem_Click); // // savePaletteScreenshotToolStripMenuItem // this.savePaletteScreenshotToolStripMenuItem.Name = "savePaletteScreenshotToolStripMenuItem"; - this.savePaletteScreenshotToolStripMenuItem.Size = new System.Drawing.Size(215, 22); + this.savePaletteScreenshotToolStripMenuItem.Size = new System.Drawing.Size(208, 22); this.savePaletteScreenshotToolStripMenuItem.Text = "Save Palette Screenshot..."; this.savePaletteScreenshotToolStripMenuItem.Click += new System.EventHandler(this.savePaletteScreenshotToolStripMenuItem_Click); // // toolStripSeparator1 // this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(212, 6); + this.toolStripSeparator1.Size = new System.Drawing.Size(205, 6); // // closeToolStripMenuItem // this.closeToolStripMenuItem.Name = "closeToolStripMenuItem"; this.closeToolStripMenuItem.ShortcutKeyDisplayString = "Alt+F4"; - this.closeToolStripMenuItem.Size = new System.Drawing.Size(215, 22); + this.closeToolStripMenuItem.Size = new System.Drawing.Size(208, 22); this.closeToolStripMenuItem.Text = "&Close"; this.closeToolStripMenuItem.Click += new System.EventHandler(this.closeToolStripMenuItem_Click); // - // OptionsSubMenu - // - this.OptionsSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.AutoloadMenuItem, - this.SaveWindowPositionMenuItem, - this.AlwaysOnTopMenuItem, - this.FloatingWindowMenuItem}); - this.OptionsSubMenu.Name = "OptionsSubMenu"; - this.OptionsSubMenu.Size = new System.Drawing.Size(61, 20); - this.OptionsSubMenu.Text = "&Options"; - this.OptionsSubMenu.DropDownOpened += new System.EventHandler(this.OptionsSubMenu_DropDownOpened); - // - // AutoloadMenuItem - // - this.AutoloadMenuItem.Name = "AutoloadMenuItem"; - this.AutoloadMenuItem.Size = new System.Drawing.Size(191, 22); - this.AutoloadMenuItem.Text = "&Autoload"; - this.AutoloadMenuItem.Click += new System.EventHandler(this.AutoloadMenuItem_Click); - // - // SaveWindowPositionMenuItem - // - this.SaveWindowPositionMenuItem.Name = "SaveWindowPositionMenuItem"; - this.SaveWindowPositionMenuItem.Size = new System.Drawing.Size(191, 22); - this.SaveWindowPositionMenuItem.Text = "Save Window Position"; - this.SaveWindowPositionMenuItem.Click += new System.EventHandler(this.SaveWindowPositionMenuItem_Click); - // - // AlwaysOnTopMenuItem - // - this.AlwaysOnTopMenuItem.Name = "AlwaysOnTopMenuItem"; - this.AlwaysOnTopMenuItem.Size = new System.Drawing.Size(191, 22); - this.AlwaysOnTopMenuItem.Text = "Always On Top"; - this.AlwaysOnTopMenuItem.Click += new System.EventHandler(this.AlwaysOnTopMenuItem_Click); - // - // FloatingWindowMenuItem - // - this.FloatingWindowMenuItem.Name = "FloatingWindowMenuItem"; - this.FloatingWindowMenuItem.Size = new System.Drawing.Size(191, 22); - this.FloatingWindowMenuItem.Text = "Floating Window"; - this.FloatingWindowMenuItem.Click += new System.EventHandler(this.FloatingWindowMenuItem_Click); - // // GenVDPViewer // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -328,10 +282,5 @@ private System.Windows.Forms.ToolStripMenuItem savePaletteScreenshotToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem closeToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem OptionsSubMenu; - private System.Windows.Forms.ToolStripMenuItem AutoloadMenuItem; - private System.Windows.Forms.ToolStripMenuItem SaveWindowPositionMenuItem; - private System.Windows.Forms.ToolStripMenuItem AlwaysOnTopMenuItem; - private System.Windows.Forms.ToolStripMenuItem FloatingWindowMenuItem; } } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs b/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs index 820a457f29..050562f019 100644 --- a/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs +++ b/BizHawk.Client.EmuHawk/tools/Genesis/VDPViewer.cs @@ -26,8 +26,6 @@ namespace BizHawk.Client.EmuHawk InitializeComponent(); bmpViewTiles.ChangeBitmapSize(512, 256); bmpViewPal.ChangeBitmapSize(16, 4); - - TopMost = Global.Config.GenVdpSettings.TopMost; } unsafe static void DrawTile(int* dest, int pitch, byte* src, int* pal) @@ -216,52 +214,8 @@ namespace BizHawk.Client.EmuHawk Close(); } - private void OptionsSubMenu_DropDownOpened(object sender, EventArgs e) - { - AutoloadMenuItem.Checked = Global.Config.GenVdpAutoLoad; - SaveWindowPositionMenuItem.Checked = Global.Config.GenVdpSettings.SaveWindowPosition; - AlwaysOnTopMenuItem.Checked = Global.Config.GenVdpSettings.TopMost; - FloatingWindowMenuItem.Checked = Global.Config.GenVdpSettings.FloatingWindow; - } - - private void AutoloadMenuItem_Click(object sender, EventArgs e) - { - Global.Config.GenVdpAutoLoad ^= true; - } - - private void SaveWindowPositionMenuItem_Click(object sender, EventArgs e) - { - Global.Config.GenVdpSettings.SaveWindowPosition ^= true; - } - - private void AlwaysOnTopMenuItem_Click(object sender, EventArgs e) - { - TopMost = Global.Config.GenVdpSettings.TopMost ^= true; - } - - private void FloatingWindowMenuItem_Click(object sender, EventArgs e) - { - Global.Config.GenVdpSettings.FloatingWindow ^= true; - RefreshFloatingWindowControl(); - } - - private void RefreshFloatingWindowControl() - { - Owner = Global.Config.GenVdpSettings.FloatingWindow ? null : GlobalWin.MainForm; - } - - protected override void OnShown(EventArgs e) - { - RefreshFloatingWindowControl(); - base.OnShown(e); - } - private void GenVDPViewer_Load(object sender, EventArgs e) { - if (Global.Config.GenVdpSettings.UseWindowPosition) - { - Location = Global.Config.GenVdpSettings.WindowPosition; - } } } } diff --git a/BizHawk.Client.EmuHawk/tools/ToolManager.cs b/BizHawk.Client.EmuHawk/tools/ToolManager.cs index 8a1cf34f74..98dad50829 100644 --- a/BizHawk.Client.EmuHawk/tools/ToolManager.cs +++ b/BizHawk.Client.EmuHawk/tools/ToolManager.cs @@ -8,6 +8,7 @@ using BizHawk.Emulation.Common.IEmulatorExtensions; using BizHawk.Client.Common; using BizHawk.Emulation.Common; +using System.Windows.Forms; namespace BizHawk.Client.EmuHawk { @@ -60,12 +61,120 @@ namespace BizHawk.Client.EmuHawk var newTool = CreateInstance(toolType); ServiceInjector.UpdateServices(Global.Emulator.ServiceProvider, newTool); - newTool.Restart(); + ToolDialogSettings settings; + if (!Global.Config.CommonToolSettings.TryGetValue(toolType.ToString(), out settings)) + { + settings = new ToolDialogSettings(); + Global.Config.CommonToolSettings[toolType.ToString()] = settings; + } + + AttachSettingHooks(newTool, settings); + + newTool.Restart(); newTool.Show(); return newTool; } + public void AutoLoad() + { + foreach (var typename in Global.Config.CommonToolSettings.Where(kvp => kvp.Value.AutoLoad).Select(kvp => kvp.Key)) + { + // this type resolution might not be sufficient. more investigation is needed + Type t = Type.GetType(typename); + if (t == null) + { + Console.WriteLine("BENIGN: Couldn't find type {0}", typename); + } + else + { + Load(t, false); + } + } + } + + private static void AttachSettingHooks(IToolForm tool, ToolDialogSettings settings) + { + if (!(tool is GenVDPViewer)) + return; + var form = (Form)tool; + + var menu = new ToolStripMenuItem("Tool Settings (FIX ME)"); + + menu.DropDownItems.Add("Save Window Position"); + menu.DropDownItems.Add("Stay on Top"); + menu.DropDownItems.Add("Float from Parent"); + menu.DropDownItems.Add("Auto Load"); + + (menu.DropDownItems[0] as ToolStripMenuItem).Checked = settings.SaveWindowPosition; + (menu.DropDownItems[1] as ToolStripMenuItem).Checked = settings.TopMost; + (menu.DropDownItems[2] as ToolStripMenuItem).Checked = settings.FloatingWindow; + (menu.DropDownItems[3] as ToolStripMenuItem).Checked = settings.AutoLoad; + + form.TopMost = settings.TopMost; + + // do we need to do this OnShown() as well? + form.Owner = settings.FloatingWindow ? null : GlobalWin.MainForm; + + if (settings.UseWindowPosition) + { + form.Location = settings.WindowPosition; + } + if (settings.UseWindowSize) + { + form.Size = settings.WindowSize; + } + + form.FormClosing += (o, e) => + { + settings.Wndx = form.Location.X; + settings.Wndy = form.Location.Y; + settings.Width = form.Right - form.Left; // why not form.Size.Width? + settings.Height = form.Bottom - form.Top; + }; + + menu.DropDownItems[0].Click += (o, e) => + { + bool val = !(o as ToolStripMenuItem).Checked; + settings.SaveWindowPosition = val; + (o as ToolStripMenuItem).Checked = val; + }; + menu.DropDownItems[1].Click += (o, e) => + { + bool val = !(o as ToolStripMenuItem).Checked; + settings.TopMost = val; + (o as ToolStripMenuItem).Checked = val; + form.TopMost = val; + }; + menu.DropDownItems[2].Click += (o, e) => + { + bool val = !(o as ToolStripMenuItem).Checked; + settings.FloatingWindow = val; + (o as ToolStripMenuItem).Checked = val; + form.Owner = val ? null : GlobalWin.MainForm; + }; + menu.DropDownItems[3].Click += (o, e) => + { + bool val = !(o as ToolStripMenuItem).Checked; + settings.AutoLoad = val; + (o as ToolStripMenuItem).Checked = val; + }; + + foreach (Control c in form.Controls) + { + if (c is MenuStrip) + { + var ms = c as MenuStrip; + ms.Items.Add(menu); + return; + } + } + // got here without finding a menustrip, means there is no menustrip. + // what to do? could put in a context menu or something? + } + + + /// /// Determines whether a given IToolForm is already loaded ///