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

This commit is contained in:
adelikat 2020-06-20 13:05:33 -05:00
parent 440a340cb5
commit 831197aeaa
6 changed files with 58 additions and 70 deletions

View File

@ -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;

View File

@ -1694,21 +1694,6 @@ namespace BizHawk.Client.EmuHawk
Tools.Load<GBPrinterView>();
}
private void GbaCoreSettingsMenuItem_Click(object sender, EventArgs e)
{
GenericCoreConfig.DoDialog(this, "Gameboy Advance Settings");
}
private void GbaGpuViewerMenuItem_Click(object sender, EventArgs e)
{
Tools.Load<GbaGpuView>();
}
private void GBASubMenu_DropDownOpened(object sender, EventArgs e)
{
GbaGpuViewerMenuItem.Enabled = true;
}
private void NDSSubMenu_DropDownOpened(object sender, EventArgs e)
{
NdsSyncSettingsMenuItem.Enabled = MovieSession.Movie.NotActive();

View File

@ -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<Type> _specializedTools = Assembly
.GetAssembly(typeof(MainForm))
.GetTypes()
.Where(t => typeof(IToolForm).IsAssignableFrom(t) && !t.IsAbstract)
.Where(t => t.GetCustomAttribute<SpecializedToolAttribute>() != 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<SpecializedToolAttribute>().DisplayName;
var item = new ToolStripMenuItem
{
Text = dispName
};
item.Click += (o, e) =>
{
Tools.Load(tool);
};
GenericCoreSubMenu.DropDownItems.Add(item);
}
}
}
private void InitControls()

View File

@ -12,6 +12,7 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
{
[SpecializedTool("GPU Viewer")]
public partial class GbaGpuView : ToolFormBase, IToolFormAutoConfig
{
[RequiredService]

View File

@ -0,0 +1,18 @@
using System;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// Defines a <see cref="IToolForm"/> as a specialized tool that is for a specific system or core
/// </summary>
public class SpecializedToolAttribute : Attribute
{
public SpecializedToolAttribute(string displayName)
{
DisplayName = displayName;
}
public string DisplayName { get; }
}
}

View File

@ -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<MGBAHawk.Settings, MGBAHawk.SyncSettings>,