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)
This commit is contained in:
James Groom 2024-05-01 23:46:55 +10:00 committed by GitHub
parent c2f549d02c
commit 9c74104e77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 16 deletions

View File

@ -19,33 +19,33 @@ namespace BizHawk.Client.Common
/// <remarks>
/// <c>AppliesTo[0]</c> is used as the group label, and
/// <c>Config.PreferredCores[AppliesTo[0]]</c> (lookup on global <see cref="Config"/> instance) determines the currently selected option.
/// The tuples' order determines the order of menu items.
/// <c>Config.PreferredCores[AppliesTo[0]]</c> (lookup on global <see cref="Config"/> instance) determines which option is shown as checked.<br/>
/// The order within submenus and the order of the submenus themselves are determined by the declaration order here.
/// </remarks>
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()

View File

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