From 9c74104e77b9b9e71ac3a02070212693c237da74 Mon Sep 17 00:00:00 2001 From: James Groom Date: Wed, 1 May 2024 23:46:55 +1000 Subject: [PATCH] Re-order preferred cores menu, have invalid values auto-set to first ...upon opening menu note that first != empty-config default (though with this commit, they all match) --- src/BizHawk.Client.Common/config/Config.cs | 28 +++++++++++----------- src/BizHawk.Client.EmuHawk/MainForm.cs | 11 +++++++-- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/BizHawk.Client.Common/config/Config.cs b/src/BizHawk.Client.Common/config/Config.cs index a95d9843a3..70743b285b 100644 --- a/src/BizHawk.Client.Common/config/Config.cs +++ b/src/BizHawk.Client.Common/config/Config.cs @@ -19,33 +19,33 @@ namespace BizHawk.Client.Common /// /// AppliesTo[0] is used as the group label, and - /// Config.PreferredCores[AppliesTo[0]] (lookup on global instance) determines the currently selected option. - /// The tuples' order determines the order of menu items. + /// Config.PreferredCores[AppliesTo[0]] (lookup on global instance) determines which option is shown as checked.
+ /// The order within submenus and the order of the submenus themselves are determined by the declaration order here. ///
public static readonly IReadOnlyList<(string[] AppliesTo, string[] CoreNames)> CorePickerUIData = new List<(string[], string[])> { - (new[] { VSystemID.Raw.NES }, - new[] { CoreNames.QuickNes, CoreNames.NesHawk, CoreNames.SubNesHawk }), - (new[] { VSystemID.Raw.SNES }, - new[] { CoreNames.Faust, CoreNames.Snes9X, CoreNames.Bsnes, CoreNames.Bsnes115, CoreNames.SubBsnes115 }), - (new[] { VSystemID.Raw.N64 }, - new[] { CoreNames.Mupen64Plus, CoreNames.Ares64 }), - (new[] { VSystemID.Raw.SGB }, - new[] { CoreNames.Gambatte, CoreNames.Bsnes, CoreNames.Bsnes115, CoreNames.SubBsnes115 }), (new[] { VSystemID.Raw.GB, VSystemID.Raw.GBC }, new[] { CoreNames.Gambatte, CoreNames.Sameboy, CoreNames.GbHawk, CoreNames.SubGbHawk }), (new[] { VSystemID.Raw.GBL }, new[] { CoreNames.GambatteLink, CoreNames.GBHawkLink, CoreNames.GBHawkLink3x, CoreNames.GBHawkLink4x }), + (new[] { VSystemID.Raw.SGB }, + new[] { CoreNames.Gambatte, CoreNames.Bsnes115, CoreNames.SubBsnes115, CoreNames.Bsnes }), (new[] { VSystemID.Raw.GEN }, new[] { CoreNames.Gpgx, CoreNames.PicoDrive }), - (new[] { VSystemID.Raw.SMS, VSystemID.Raw.GG, VSystemID.Raw.SG }, - new[] { CoreNames.Gpgx, CoreNames.SMSHawk }), + (new[] { VSystemID.Raw.N64 }, + new[] { CoreNames.Mupen64Plus, CoreNames.Ares64 }), + (new[] { VSystemID.Raw.NES }, + new[] { CoreNames.QuickNes, CoreNames.NesHawk, CoreNames.SubNesHawk }), (new[] { VSystemID.Raw.PCE, VSystemID.Raw.PCECD, VSystemID.Raw.SGX, VSystemID.Raw.SGXCD }, new[] { CoreNames.TurboNyma, CoreNames.HyperNyma, CoreNames.PceHawk }), (new[] { VSystemID.Raw.PSX }, - new[] { CoreNames.Octoshock, CoreNames.Nymashock }), + new[] { CoreNames.Nymashock, CoreNames.Octoshock }), + (new[] { VSystemID.Raw.SMS, VSystemID.Raw.GG, VSystemID.Raw.SG }, + new[] { CoreNames.Gpgx, CoreNames.SMSHawk }), + (new[] { VSystemID.Raw.SNES }, + new[] { CoreNames.Snes9X, CoreNames.Bsnes115, CoreNames.SubBsnes115, CoreNames.Faust, CoreNames.Bsnes }), (new[] { VSystemID.Raw.TI83 }, - new[] { CoreNames.TI83Hawk, CoreNames.Emu83 }), + new[] { CoreNames.Emu83, CoreNames.TI83Hawk }), }; public Config() diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 364b7d13b0..d419410dd0 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -86,9 +86,9 @@ namespace BizHawk.Client.EmuHawk } WindowSizeSubMenu.DropDownItems.AddRange(CreateWindowSizeFactorSubmenus()); - foreach (var (groupLabel, appliesTo, coreNames) in Config.CorePickerUIData.Select(static tuple => (GroupLabel: tuple.AppliesTo[0], tuple.AppliesTo, tuple.CoreNames)) - .OrderBy(static tuple => tuple.GroupLabel)) + foreach (var (appliesTo, coreNames) in Config.CorePickerUIData) { + var groupLabel = appliesTo[0]; var submenu = new ToolStripMenuItem { Text = groupLabel }; void ClickHandler(object clickSender, EventArgs clickArgs) { @@ -107,6 +107,13 @@ namespace BizHawk.Client.EmuHawk submenu.DropDownOpened += (openedSender, _1) => { _ = Config.PreferredCores.TryGetValue(groupLabel, out var preferred); + if (!coreNames.Contains(preferred)) + { + // invalid --> default (doing this here rather than when reading config file to allow for hacked-in values, though I'm not sure if that could do anything at the moment --yoshi) + var defaultCore = coreNames[0]; + Console.WriteLine($"setting preferred core for {groupLabel} etc. to {defaultCore} (was {preferred ?? "null"})"); + Config.PreferredCores[groupLabel] = preferred = defaultCore; + } foreach (ToolStripMenuItem entry in ((ToolStripMenuItem) openedSender).DropDownItems) entry.Checked = entry.Text == preferred; }; CoresSubMenu.DropDownItems.Add(submenu);