From 831197aeaa052d8d266b8b77bb7cc8e1121cdd80 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 20 Jun 2020 13:05:33 -0500 Subject: [PATCH] created a SpecializedTool attribute for system/core specific tools, and use it to dynamically add available tools to the generic core menu, replace the hardcoded GBA menu using this --- .../MainForm.Designer.cs | 50 ------------------- src/BizHawk.Client.EmuHawk/MainForm.Events.cs | 15 ------ src/BizHawk.Client.EmuHawk/MainForm.cs | 42 ++++++++++++++-- .../tools/GBA/GBAGPUView.cs | 1 + .../tools/SpecializedToolAttribute.cs | 18 +++++++ .../Consoles/Nintendo/GBA/MGBAHawk.cs | 2 +- 6 files changed, 58 insertions(+), 70 deletions(-) create mode 100644 src/BizHawk.Client.EmuHawk/tools/SpecializedToolAttribute.cs diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs b/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs index ed95c630b3..66c4327343 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Designer.cs @@ -251,10 +251,6 @@ this.toolStripSeparator28 = new System.Windows.Forms.ToolStripSeparator(); this.GBGPUViewerMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.GBPrinterViewerMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.GBASubMenu = new System.Windows.Forms.ToolStripMenuItem(); - this.GBAcoresettingsToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator33 = new System.Windows.Forms.ToolStripSeparator(); - this.GbaGpuViewerMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.PSXSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.PSXControllerSettingsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.PSXOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -306,7 +302,6 @@ this.zxt2ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ZXSpectrumExportSnapshotMenuItemMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.GenericCoreSubMenu = new System.Windows.Forms.ToolStripMenuItem(); - this.GenericCoreSettingsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.HelpSubMenu = new System.Windows.Forms.ToolStripMenuItem(); this.OnlineHelpMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ForumsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -412,7 +407,6 @@ this.TI83SubMenu, this.A7800SubMenu, this.GBSubMenu, - this.GBASubMenu, this.NDSSubMenu, this.PSXSubMenu, this.SNESSubMenu, @@ -2248,36 +2242,6 @@ this.GBPrinterViewerMenuItem.Text = "&Printer Viewer"; this.GBPrinterViewerMenuItem.Click += new System.EventHandler(this.GbPrinterViewerMenuItem_Click); // - // GBASubMenu - // - this.GBASubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.GBAcoresettingsToolStripMenuItem1, - this.toolStripSeparator33, - this.GbaGpuViewerMenuItem}); - this.GBASubMenu.Name = "GBASubMenu"; - this.GBASubMenu.Size = new System.Drawing.Size(39, 17); - this.GBASubMenu.Text = "GBA"; - this.GBASubMenu.DropDownOpened += new System.EventHandler(this.GBASubMenu_DropDownOpened); - // - // GBAcoresettingsToolStripMenuItem1 - // - this.GBAcoresettingsToolStripMenuItem1.Name = "GBAcoresettingsToolStripMenuItem1"; - this.GBAcoresettingsToolStripMenuItem1.Size = new System.Drawing.Size(129, 22); - this.GBAcoresettingsToolStripMenuItem1.Text = "&Settings..."; - this.GBAcoresettingsToolStripMenuItem1.Click += new System.EventHandler(this.GbaCoreSettingsMenuItem_Click); - // - // toolStripSeparator33 - // - this.toolStripSeparator33.Name = "toolStripSeparator33"; - this.toolStripSeparator33.Size = new System.Drawing.Size(126, 6); - // - // GbaGpuViewerMenuItem - // - this.GbaGpuViewerMenuItem.Name = "GbaGpuViewerMenuItem"; - this.GbaGpuViewerMenuItem.Size = new System.Drawing.Size(129, 22); - this.GbaGpuViewerMenuItem.Text = "GPU Viewer"; - this.GbaGpuViewerMenuItem.Click += new System.EventHandler(this.GbaGpuViewerMenuItem_Click); - // // PSXSubMenu // this.PSXSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -2668,19 +2632,10 @@ // // GenericCoreSubMenu // - this.GenericCoreSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.GenericCoreSettingsMenuItem}); this.GenericCoreSubMenu.Name = "GenericCoreSubMenu"; this.GenericCoreSubMenu.Size = new System.Drawing.Size(56, 17); this.GenericCoreSubMenu.Text = "&Core"; // - // GenericCoreSettingsMenuItem - // - this.GenericCoreSettingsMenuItem.Name = "GenericCoreSettingsMenuItem"; - this.GenericCoreSettingsMenuItem.Size = new System.Drawing.Size(125, 22); - this.GenericCoreSettingsMenuItem.Text = "Settings..."; - this.GenericCoreSettingsMenuItem.Click += new System.EventHandler(this.GenericCoreSettingsMenuItem_Click); - // // HelpSubMenu // this.HelpSubMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -3624,8 +3579,6 @@ private System.Windows.Forms.ToolStripMenuItem ColecoUseSGMMenuItem; private System.Windows.Forms.ToolStripMenuItem ColecoControllerSettingsMenuItem; private System.Windows.Forms.ToolStripStatusLabel LedLightStatusLabel; - private System.Windows.Forms.ToolStripMenuItem GBASubMenu; - private System.Windows.Forms.ToolStripMenuItem GbaGpuViewerMenuItem; private System.Windows.Forms.ToolStripMenuItem KeyPrioritySubMenu; private System.Windows.Forms.ToolStripMenuItem BothHkAndControllerMenuItem; private System.Windows.Forms.ToolStripMenuItem InputOverHkMenuItem; @@ -3649,7 +3602,6 @@ private System.Windows.Forms.ToolStripMenuItem DGBSubMenu; private System.Windows.Forms.ToolStripMenuItem DGBsettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem GenericCoreSubMenu; - private System.Windows.Forms.ToolStripMenuItem GenericCoreSettingsMenuItem; private System.Windows.Forms.ToolStripMenuItem GenesisSubMenu; private System.Windows.Forms.ToolStripMenuItem GenesisSettingsToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem A7800ControllerSettingsMenuItem; @@ -3700,8 +3652,6 @@ private System.Windows.Forms.ToolStripMenuItem MovieEndPauseMenuItem; private System.Windows.Forms.ToolStripMenuItem ScreenshotClientClipboardMenuItem; private System.Windows.Forms.ToolStripMenuItem MupenStyleLagMenuItem; - private System.Windows.Forms.ToolStripSeparator toolStripSeparator33; - private System.Windows.Forms.ToolStripMenuItem GBAcoresettingsToolStripMenuItem1; private System.Windows.Forms.ToolStripStatusLabel LinkConnectStatusBarButton; private System.Windows.Forms.ToolStripMenuItem N64ExpansionSlotMenuItem; private System.Windows.Forms.ToolStripMenuItem BarcodeReaderMenuItem; diff --git a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs index 0f54fe3a21..9d7920162b 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.Events.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.Events.cs @@ -1694,21 +1694,6 @@ namespace BizHawk.Client.EmuHawk Tools.Load(); } - private void GbaCoreSettingsMenuItem_Click(object sender, EventArgs e) - { - GenericCoreConfig.DoDialog(this, "Gameboy Advance Settings"); - } - - private void GbaGpuViewerMenuItem_Click(object sender, EventArgs e) - { - Tools.Load(); - } - - private void GBASubMenu_DropDownOpened(object sender, EventArgs e) - { - GbaGpuViewerMenuItem.Enabled = true; - } - private void NDSSubMenu_DropDownOpened(object sender, EventArgs e) { NdsSyncSettingsMenuItem.Enabled = MovieSession.Movie.NotActive(); diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 6fa5712d6c..eed9aadf44 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -6,6 +6,7 @@ using System.Drawing.Imaging; using System.Globalization; using System.IO; using System.Linq; +using System.Reflection; using System.Threading; using System.Windows.Forms; @@ -1809,7 +1810,6 @@ namespace BizHawk.Client.EmuHawk PCESubMenu.Visible = false; SMSSubMenu.Visible = false; GBSubMenu.Visible = false; - GBASubMenu.Visible = false; NDSSubMenu.Visible = false; A7800SubMenu.Visible = false; SNESSubMenu.Visible = false; @@ -1861,9 +1861,6 @@ namespace BizHawk.Client.EmuHawk case "GBC": GBSubMenu.Visible = true; break; - case "GBA": - GBASubMenu.Visible = true; - break; case "NDS": NDSSubMenu.Visible = true; break; @@ -1928,10 +1925,47 @@ namespace BizHawk.Client.EmuHawk } } + private static readonly IList _specializedTools = Assembly + .GetAssembly(typeof(MainForm)) + .GetTypes() + .Where(t => typeof(IToolForm).IsAssignableFrom(t) && !t.IsAbstract) + .Where(t => t.GetCustomAttribute() != null) + .ToList(); + private void DisplayDefaultCoreMenu() { GenericCoreSubMenu.Visible = true; GenericCoreSubMenu.Text = "&" + EmulatorExtensions.DisplayName(Emulator); + GenericCoreSubMenu.DropDownItems.Clear(); + + var settingsMenuItem = new ToolStripMenuItem { Text = "&Settings" }; + settingsMenuItem.Click += GenericCoreSettingsMenuItem_Click; + GenericCoreSubMenu.DropDownItems.Add(settingsMenuItem); + + var specializedTools = _specializedTools + .Where(t => Tools.IsAvailable(t)) + .OrderBy(t => t.Name) + .ToList(); + + if (specializedTools.Any()) + { + GenericCoreSubMenu.DropDownItems.Add(new ToolStripSeparator()); + foreach (var tool in specializedTools) + { + var dispName = tool.GetCustomAttribute().DisplayName; + var item = new ToolStripMenuItem + { + Text = dispName + }; + + item.Click += (o, e) => + { + Tools.Load(tool); + }; + + GenericCoreSubMenu.DropDownItems.Add(item); + } + } } private void InitControls() diff --git a/src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs b/src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs index 70bf11ce7c..8a6d2ad66e 100644 --- a/src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs +++ b/src/BizHawk.Client.EmuHawk/tools/GBA/GBAGPUView.cs @@ -12,6 +12,7 @@ using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk { + [SpecializedTool("GPU Viewer")] public partial class GbaGpuView : ToolFormBase, IToolFormAutoConfig { [RequiredService] diff --git a/src/BizHawk.Client.EmuHawk/tools/SpecializedToolAttribute.cs b/src/BizHawk.Client.EmuHawk/tools/SpecializedToolAttribute.cs new file mode 100644 index 0000000000..c274a40c23 --- /dev/null +++ b/src/BizHawk.Client.EmuHawk/tools/SpecializedToolAttribute.cs @@ -0,0 +1,18 @@ +using System; +using BizHawk.Client.Common; + +namespace BizHawk.Client.EmuHawk +{ + /// + /// Defines a as a specialized tool that is for a specific system or core + /// + public class SpecializedToolAttribute : Attribute + { + public SpecializedToolAttribute(string displayName) + { + DisplayName = displayName; + } + + public string DisplayName { get; } + } +} diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs index 56f52ef2c5..2915f05382 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.cs @@ -4,7 +4,7 @@ using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.GBA { - [Core(CoreNames.Mgba, "endrift", true, true, "0.8", "https://mgba.io/", false)] + [Core(CoreNames.Mgba, "endrift", true, true, "0.8", "https://mgba.io/", false, "GBA")] [ServiceNotApplicable(new[] { typeof(IDriveLight), typeof(IRegionable) })] public partial class MGBAHawk : IEmulator, IVideoProvider, ISoundProvider, IGBAGPUViewable, ISaveRam, IStatable, IInputPollable, ISettable,