diff --git a/src/BizHawk.Client.EmuHawk/tools/ToolBox.cs b/src/BizHawk.Client.EmuHawk/tools/ToolBox.cs index 00cf18f0ef..bfadadc100 100644 --- a/src/BizHawk.Client.EmuHawk/tools/ToolBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/ToolBox.cs @@ -12,6 +12,15 @@ namespace BizHawk.Client.EmuHawk { public partial class ToolBox : ToolFormBase { + private static readonly Lazy IconMissingIcon = new(() => Properties.Resources.Logo.ToBitmap()); + + private static readonly Lazy> ToolTypes = new(() => EmuHawk.ReflectionCache.Types + .Where(static t => typeof(IToolForm).IsAssignableFrom(t) && typeof(Form).IsAssignableFrom(t)) + .Where(VersionInfo.DeveloperBuild + ? static t => true + : static t => !t.GetCustomAttributes(false).OfType().Any(static a => !a.Released)) + .Except(new[] { typeof(ToolBox), typeof(ToolFormBase) }).ToList()); + [RequiredService] private IEmulator Emulator { get; set; } @@ -43,71 +52,39 @@ namespace BizHawk.Client.EmuHawk private void SetTools() { ToolBoxStrip.Items.Clear(); - - var tools = EmuHawk.ReflectionCache.Types - .Where(t => typeof(IToolForm).IsAssignableFrom(t) && typeof(Form).IsAssignableFrom(t) - && !typeof(ToolBox).IsAssignableFrom(t) - && ServiceInjector.IsAvailable(Emulator.ServiceProvider, t) - && (VersionInfo.DeveloperBuild || !t.GetCustomAttributes(false).OfType().Any(static a => !a.Released))); - - /* - for (int i = 0; i < tools.Count(); i++) + foreach (var t in ToolTypes.Value) { - Console.WriteLine(tools.ElementAt(i).FullName); - } - */ - - foreach (var t in tools) - { - if (t.FullName != "BizHawk.Client.EmuHawk.ToolFormBase") - { - //var instance = Activator.CreateInstance(t); - - var image_t = Properties.Resources.Logo; - var text_t = ""; - - if (t.FullName == "BizHawk.Client.EmuHawk.CoreFeatureAnalysis") { image_t = Properties.Resources.Logo; } - if (t.FullName == "BizHawk.Client.EmuHawk.LogWindow") { image_t = Properties.Resources.CommandWindow; } - if (t.FullName == "BizHawk.Client.EmuHawk.LuaConsole") { image_t = Properties.Resources.TextDocIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.MacroInputTool") { image_t = Properties.Resources.TAStudioIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.MultiDiskBundler") { image_t = Properties.Resources.DualIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.VirtualpadTool") { image_t = Properties.Resources.GameControllerIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.BasicBot") { image_t = Properties.Resources.BasicBot; } - if (t.FullName == "BizHawk.Client.EmuHawk.CDL") { image_t = Properties.Resources.CdLoggerIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.Cheats") { image_t = Properties.Resources.BugIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.GenericDebugger") { image_t = Properties.Resources.BugIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.GameShark") { image_t = Properties.Resources.SharkIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.GBPrinterView") { image_t = Properties.Resources.GambatteIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.GbGpuView") { image_t = Properties.Resources.GambatteIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.HexEditor") { image_t = Properties.Resources.FreezeIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.TAStudio") { image_t = Properties.Resources.TAStudioIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.TraceLogger") { image_t = Properties.Resources.PencilIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.RamSearch") { image_t = Properties.Resources.SearchIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.RamWatch") { image_t = Properties.Resources.WatchIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.NESSoundConfig") { image_t = Properties.Resources.NesControllerIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.NESMusicRipper") { image_t = Properties.Resources.NesControllerIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.NesPPU") { image_t = Properties.Resources.MonitorIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.NESNameTableViewer") { image_t = Properties.Resources.MonitorIcon; } - if (t.FullName == "BizHawk.Client.EmuHawk.SmsVdpViewer") { image_t = Properties.Resources.SmsIcon; } - - var tsb = new ToolStripButton - { - Image = image_t.ToBitmap(), - Text = text_t, - DisplayStyle = ToolStripItemDisplayStyle.Image - //Image = ((Form)instance).Icon.ToBitmap(), - //Text = ((Form)instance).Text, - //DisplayStyle = ((Form)instance).ShowIcon ? ToolStripItemDisplayStyle.Image : ToolStripItemDisplayStyle.Text - }; - - tsb.Click += (o, e) => - { - Tools.Load(t); - //Close(); - }; - - ToolBoxStrip.Items.Add(tsb); - } + if (!ServiceInjector.IsAvailable(Emulator.ServiceProvider, t)) continue; + Icon/*?*/ image_t = null; + if (t.FullName == "BizHawk.Client.EmuHawk.CoreFeatureAnalysis") { image_t = Properties.Resources.Logo; } + if (t.FullName == "BizHawk.Client.EmuHawk.LogWindow") { image_t = Properties.Resources.CommandWindow; } + if (t.FullName == "BizHawk.Client.EmuHawk.LuaConsole") { image_t = Properties.Resources.TextDocIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.MacroInputTool") { image_t = Properties.Resources.TAStudioIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.MultiDiskBundler") { image_t = Properties.Resources.DualIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.VirtualpadTool") { image_t = Properties.Resources.GameControllerIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.BasicBot") { image_t = Properties.Resources.BasicBot; } + if (t.FullName == "BizHawk.Client.EmuHawk.CDL") { image_t = Properties.Resources.CdLoggerIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.Cheats") { image_t = Properties.Resources.BugIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.GenericDebugger") { image_t = Properties.Resources.BugIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.GameShark") { image_t = Properties.Resources.SharkIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.GBPrinterView") { image_t = Properties.Resources.GambatteIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.GbGpuView") { image_t = Properties.Resources.GambatteIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.HexEditor") { image_t = Properties.Resources.FreezeIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.TAStudio") { image_t = Properties.Resources.TAStudioIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.TraceLogger") { image_t = Properties.Resources.PencilIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.RamSearch") { image_t = Properties.Resources.SearchIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.RamWatch") { image_t = Properties.Resources.WatchIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.NESSoundConfig") { image_t = Properties.Resources.NesControllerIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.NESMusicRipper") { image_t = Properties.Resources.NesControllerIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.NesPPU") { image_t = Properties.Resources.MonitorIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.NESNameTableViewer") { image_t = Properties.Resources.MonitorIcon; } + if (t.FullName == "BizHawk.Client.EmuHawk.SmsVdpViewer") { image_t = Properties.Resources.SmsIcon; } + ToolStripButton tsb = new() { + DisplayStyle = ToolStripItemDisplayStyle.Image, + Image = image_t?.ToBitmap() ?? IconMissingIcon.Value, + }; + tsb.Click += (_, _) => Tools.Load(t); + ToolBoxStrip.Items.Add(tsb); } }