Input Config: Fixed bug where input config window did not list the correct controllers

This commit is contained in:
Souryo 2016-05-22 19:29:51 -04:00
parent 2b440f2374
commit ed4a865011
3 changed files with 37 additions and 22 deletions

View File

@ -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<ControllerInfo> Controllers = new List<ControllerInfo>();
public void InitializeDefaults()

View File

@ -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<T>(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);
}
}
}

View File

@ -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<InteropEmu.ControllerType>();
inputInfo.Controllers[1].ControllerType = cboPlayer2.GetEnumValue<InteropEmu.ControllerType>();
inputInfo.Controllers[2].ControllerType = cboPlayer3.GetEnumValue<InteropEmu.ControllerType>();
inputInfo.Controllers[3].ControllerType = cboPlayer4.GetEnumValue<InteropEmu.ControllerType>();
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);
}
}