Fix SGB core picker which was broken (#2422)

* Fix SGB core picker which was broken

* Restore default SGB core choice of SameBoy

In 2.4.2 and before, SameBoy was implicitly the default, but this makes the choice more explicit and the core picker UI properly show the chosen core when nothing has been selected yet.

* Cleanup core picker UI gen

* Remove now defunct SgbUseBsnes option from Config

Co-authored-by: RetroEdit <30182911+RetroEdit@users.noreply.github.com>
Co-authored-by: YoshiRulz <OSSYoshiRulz@gmail.com>
This commit is contained in:
nattthebear 2020-09-24 09:23:12 -04:00 committed by GitHub
parent 757ac4e27e
commit fe929c0c55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 43 deletions

View File

@ -290,11 +290,8 @@ namespace BizHawk.Client.Common
public Dictionary<string, Dictionary<string, string>> AllTrollersAutoFire { get; set; } = new Dictionary<string, Dictionary<string, string>>();
public Dictionary<string, Dictionary<string, AnalogBind>> AllTrollersAnalog { get; set; } = new Dictionary<string, Dictionary<string, AnalogBind>>();
// Core Pick
// as this setting spans multiple cores and doesn't actually affect the behavior of any core,
// it hasn't been absorbed into the new system
/// <remarks>as this setting spans multiple cores and doesn't actually affect the behavior of any core, it hasn't been absorbed into the new system</remarks>
public bool GbAsSgb { get; set; }
public bool SgbUseBsnes { get; set; }
public string LibretroCore { get; set; }
public Dictionary<string, string> PreferredCores = new Dictionary<string, string>
@ -303,6 +300,7 @@ namespace BizHawk.Client.Common
["SNES"] = CoreNames.Snes9X,
["GB"] = CoreNames.Gambatte,
["GBC"] = CoreNames.Gambatte,
["SGB"] = CoreNames.SameBoy,
["PCE"] = CoreNames.TurboNyma,
["PCECD"] = CoreNames.TurboNyma,
["SGX"] = CoreNames.TurboNyma

View File

@ -45,62 +45,37 @@ namespace BizHawk.Client.EmuHawk
private static readonly IReadOnlyCollection<(string[] AppliesTo, string[] CoreNames)> CoreData = new List<(string[], string[])> {
(new[] { "NES" }, new[] { CoreNames.QuickNes, CoreNames.NesHawk, CoreNames.SubNesHawk }),
(new[] { "SNES" }, new[] { CoreNames.Faust, CoreNames.Snes9X, CoreNames.Bsnes }),
(new[] { "SGB" }, new[] { CoreNames.Bsnes, CoreNames.SameBoy }),
(new[] { "SGB" }, new[] { CoreNames.SameBoy, CoreNames.Bsnes }),
(new[] { "GB", "GBC" }, new[] { CoreNames.Gambatte, CoreNames.GbHawk, CoreNames.SubGbHawk }),
(new[] { "PCE", "PCECD", "SGX" }, new[] { CoreNames.HyperNyma, CoreNames.PceHawk, CoreNames.TurboNyma })
(new[] { "PCE", "PCECD", "SGX" }, new[] { CoreNames.TurboNyma, CoreNames.HyperNyma, CoreNames.PceHawk })
};
private void MainForm_Load(object sender, EventArgs e)
{
SetWindowText();
ToolStripMenuItem GenSubmenuForSystem((string[] AppliesTo, string[] CoreNames) systemData, EventHandler onclick = null, EventHandler onmouseover = null)
foreach (var (appliesTo, coreNames) in CoreData)
{
var (appliesTo, coreNames) = systemData;
var groupLabel = appliesTo[0];
var submenu = new ToolStripMenuItem { Text = groupLabel };
onclick ??= (clickSender, clickArgs) =>
void ClickHandler(object clickSender, EventArgs clickArgs)
{
var coreName = (string) ((ToolStripMenuItem) clickSender).Tag;
var coreName = ((ToolStripMenuItem) clickSender).Text;
foreach (var system in appliesTo) Config.PreferredCores[system] = coreName;
if (appliesTo.Contains(Emulator.SystemId)) FlagNeedsReboot(); //TODO don't alert if the loaded core was the one selected
};
}
submenu.DropDownItems.AddRange(coreNames.Select(coreName => {
var entry = new ToolStripMenuItem
{
Tag = coreName,
Text = coreName.StartsWith("Sub") ? $"{coreName} (Experimental)" : coreName //TODO if we ditch this "Experimental" thing, we can use Text instead of Tag
};
entry.Click += onclick;
var entry = new ToolStripMenuItem { Text = coreName };
entry.Click += ClickHandler;
return (ToolStripItem) entry;
}).ToArray());
submenu.DropDownOpened += onmouseover ?? ((openedSender, openedArgs) => {
foreach (ToolStripMenuItem entry in ((ToolStripMenuItem) openedSender).DropDownItems)
{
entry.Checked = (string) entry.Tag == Config.PreferredCores[groupLabel];
}
});
return submenu;
submenu.DropDownOpened += (openedSender, openedArgs) =>
{
Config.PreferredCores.TryGetValue(groupLabel, out var preferred);
foreach (ToolStripMenuItem entry in ((ToolStripMenuItem) openedSender).DropDownItems) entry.Checked = entry.Text == preferred;
};
CoresSubMenu.DropDownItems.Add(submenu);
}
CoresSubMenu.DropDownItems.AddRange(CoreData.Select(systemData =>
systemData.AppliesTo[0] == "SGB"
? GenSubmenuForSystem(
systemData,
(clickSender, clickArgs) =>
{
Config.SgbUseBsnes = (string) ((ToolStripMenuItem) clickSender).Tag == CoreNames.Bsnes;
if (Emulator.SystemId == "GB" || Emulator.SystemId == "GBC") FlagNeedsReboot(); //TODO don't alert if the loaded core was the one selected
},
(openedSender, openedArgs) =>
{
//TODO use Config.PreferredCores for SGB, then this custom EventHandler can go away
var entries = ((ToolStripMenuItem) openedSender).DropDownItems.Cast<ToolStripMenuItem>().ToList();
entries[0].Checked = Config.SgbUseBsnes;
entries[1].Checked = !Config.SgbUseBsnes;
}
)
: (ToolStripItem) GenSubmenuForSystem(systemData)
).ToArray());
var GBInSGBMenuItem = new ToolStripMenuItem { Text = "GB in SGB" };
GBInSGBMenuItem.Click += (clickSender, clickArgs) =>