From ed4a86501150da92661c3f6e0ed0b044c335815b Mon Sep 17 00:00:00 2001 From: Souryo Date: Sun, 22 May 2016 19:29:51 -0400 Subject: [PATCH] Input Config: Fixed bug where input config window did not list the correct controllers --- GUI.NET/Config/InputInfo.cs | 6 ----- GUI.NET/Forms/BaseConfigForm.cs | 35 ++++++++++++++++++++------ GUI.NET/Forms/Config/frmInputConfig.cs | 18 ++++++------- 3 files changed, 37 insertions(+), 22 deletions(-) diff --git a/GUI.NET/Config/InputInfo.cs b/GUI.NET/Config/InputInfo.cs index 2e266b28..a1a3213e 100644 --- a/GUI.NET/Config/InputInfo.cs +++ b/GUI.NET/Config/InputInfo.cs @@ -106,12 +106,6 @@ namespace Mesen.GUI.Config public InteropEmu.ExpansionPortDevice ExpansionPortDevice = InteropEmu.ExpansionPortDevice.None; public bool UseFourScore = false; - [NonSerialized] - public InteropEmu.ControllerType ControllerType1; - public InteropEmu.ControllerType ControllerType2; - public InteropEmu.ControllerType ControllerType3; - public InteropEmu.ControllerType ControllerType4; - public List Controllers = new List(); public void InitializeDefaults() diff --git a/GUI.NET/Forms/BaseConfigForm.cs b/GUI.NET/Forms/BaseConfigForm.cs index 92d0450d..3a88b24e 100644 --- a/GUI.NET/Forms/BaseConfigForm.cs +++ b/GUI.NET/Forms/BaseConfigForm.cs @@ -260,13 +260,9 @@ namespace Mesen.GUI.Forms } } else if(kvp.Value is ComboBox) { if(field.FieldType.IsSubclassOf(typeof(Enum))) { - object selectedItem = ((ComboBox)kvp.Value).SelectedItem; - - foreach(Enum value in Enum.GetValues(field.FieldType)) { - if(ResourceHelper.GetEnumText(value) == selectedItem.ToString()) { - field.SetValue(Entity, value); - break; - } + Enum enumValue = ((ComboBox)kvp.Value).GetEnumValue(field.FieldType); + if(enumValue != null) { + field.SetValue(Entity, enumValue); } } else if(field.FieldType == typeof(UInt32)) { UInt32 numericValue; @@ -295,4 +291,29 @@ namespace Mesen.GUI.Forms this.Close(); } } + + public static class ComboBoxExtensions + { + public static Enum GetEnumValue(this ComboBox cbo, Type enumType) + { + foreach(Enum value in Enum.GetValues(enumType)) { + if(ResourceHelper.GetEnumText(value) == cbo.SelectedItem.ToString()) { + return value; + } + } + + return null; + } + + public static T GetEnumValue(this ComboBox cbo) + { + foreach(Enum value in Enum.GetValues(typeof(T))) { + if(ResourceHelper.GetEnumText(value) == cbo.SelectedItem.ToString()) { + return (T)(object)value; + } + } + + return default(T); + } + } } diff --git a/GUI.NET/Forms/Config/frmInputConfig.cs b/GUI.NET/Forms/Config/frmInputConfig.cs index 7875713f..d536b147 100644 --- a/GUI.NET/Forms/Config/frmInputConfig.cs +++ b/GUI.NET/Forms/Config/frmInputConfig.cs @@ -22,11 +22,6 @@ namespace Mesen.GUI.Forms.Config AddBinding("ExpansionPortDevice", cboExpansionPort); AddBinding("ConsoleType", cboConsoleType); AddBinding("UseFourScore", chkFourScore); - - AddBinding("ControllerType1", cboPlayer1); - AddBinding("ControllerType2", cboPlayer2); - AddBinding("ControllerType3", cboPlayer3); - AddBinding("ControllerType4", cboPlayer4); } protected override void AfterUpdateUI() @@ -72,10 +67,10 @@ namespace Mesen.GUI.Forms.Config { InputInfo inputInfo = (InputInfo)Entity; - inputInfo.Controllers[0].ControllerType = inputInfo.ControllerType1; - inputInfo.Controllers[1].ControllerType = inputInfo.ControllerType2; - inputInfo.Controllers[2].ControllerType = inputInfo.ControllerType3; - inputInfo.Controllers[3].ControllerType = inputInfo.ControllerType4; + inputInfo.Controllers[0].ControllerType = cboPlayer1.GetEnumValue(); + inputInfo.Controllers[1].ControllerType = cboPlayer2.GetEnumValue(); + inputInfo.Controllers[2].ControllerType = cboPlayer3.GetEnumValue(); + inputInfo.Controllers[3].ControllerType = cboPlayer4.GetEnumValue(); InputInfo.ApplyConfig(); } @@ -91,6 +86,11 @@ namespace Mesen.GUI.Forms.Config UpdatePlayer3And4Visibility(); UpdateAvailableControllerTypes(); + + cboPlayer1.SelectedItem = ResourceHelper.GetEnumText(ConfigManager.Config.InputInfo.Controllers[0].ControllerType); + cboPlayer2.SelectedItem = ResourceHelper.GetEnumText(ConfigManager.Config.InputInfo.Controllers[1].ControllerType); + cboPlayer3.SelectedItem = ResourceHelper.GetEnumText(ConfigManager.Config.InputInfo.Controllers[2].ControllerType); + cboPlayer4.SelectedItem = ResourceHelper.GetEnumText(ConfigManager.Config.InputInfo.Controllers[3].ControllerType); } }