From 8a1fd6749746a171f76251f92473d26c71135f9e Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 10 Aug 2015 15:57:22 -0500 Subject: [PATCH] refactor psx controller P# assignment to reusable code --- .../config/PSX/PSXControllerConfigNew.cs | 31 +++++++------ .../BizHawk.Emulation.Cores.csproj | 5 ++- .../Sony/PSX/OctoshockControlConfig.cs | 44 +++++++++++++++++++ 3 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockControlConfig.cs diff --git a/BizHawk.Client.EmuHawk/config/PSX/PSXControllerConfigNew.cs b/BizHawk.Client.EmuHawk/config/PSX/PSXControllerConfigNew.cs index 9922ba0bae..2f7758a097 100644 --- a/BizHawk.Client.EmuHawk/config/PSX/PSXControllerConfigNew.cs +++ b/BizHawk.Client.EmuHawk/config/PSX/PSXControllerConfigNew.cs @@ -64,28 +64,33 @@ namespace BizHawk.Client.EmuHawk combo_2_4.Enabled = b2; lbl_p_2_2.Visible = b2; lbl_p_2_3.Visible = b2; - lbl_p_2_4.Visible = b2; + lbl_p_2_4.Visible = b2; + + OctoshockControlUserConfig uc = new OctoshockControlUserConfig(); + + uc.Multitaps[0] = multitap_1; + uc.Multitaps[1] = multitap_2; - int id = 1; - List Assignments = new List(); - if (combo_1_1.SelectedIndex == 0) Assignments.Add(-1); else Assignments.Add(id++); - if (combo_1_2.SelectedIndex == 0 || !multitap_1) Assignments.Add(-1); else Assignments.Add(id++); - if (combo_1_3.SelectedIndex == 0 || !multitap_1) Assignments.Add(-1); else Assignments.Add(id++); - if (combo_1_4.SelectedIndex == 0 || !multitap_1) Assignments.Add(-1); else Assignments.Add(id++); - if (combo_2_1.SelectedIndex == 0) Assignments.Add(-1); else Assignments.Add(id++); - if (combo_2_2.SelectedIndex == 0 || !multitap_2) Assignments.Add(-1); else Assignments.Add(id++); - if (combo_2_3.SelectedIndex == 0 || !multitap_2) Assignments.Add(-1); else Assignments.Add(id++); - if (combo_2_4.SelectedIndex == 0 || !multitap_2) Assignments.Add(-1); else Assignments.Add(id++); + var combos = new[] { combo_1_1, combo_1_2, combo_1_3, combo_1_4, combo_2_1, combo_2_2, combo_2_3, combo_2_4}; + for (int i = 0; i < 8; i++) + { + var combo = combos[i]; + if (combo.SelectedIndex == 0) uc.Devices8[i] = OctoshockDll.ePeripheralType.None; + if (combo.SelectedIndex == 1) uc.Devices8[i] = OctoshockDll.ePeripheralType.DualAnalog; + if (combo.SelectedIndex == 2) uc.Devices8[i] = OctoshockDll.ePeripheralType.DualShock; + } + + var LC = uc.ToLogicalConfig(); var p_labels = new[] { lbl_p_1_1,lbl_p_1_2,lbl_p_1_3,lbl_p_1_4,lbl_p_2_1,lbl_p_2_2,lbl_p_2_3,lbl_p_2_4}; for (int i = 0; i < 8; i++) { var lbl = p_labels[i]; - if (Assignments[i] == -1) + if (LC.PlayerAssignments[i] == -1) lbl.Visible = false; else { - lbl.Text = "P" + Assignments[i]; + lbl.Text = "P" + LC.PlayerAssignments[i]; lbl.Visible = true; } } diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index 30250ca3c7..be60843cc4 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -772,7 +772,10 @@ - + + Code + + diff --git a/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockControlConfig.cs b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockControlConfig.cs new file mode 100644 index 0000000000..6cbf28bf3f --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Sony/PSX/OctoshockControlConfig.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; + +namespace BizHawk.Emulation.Cores.Sony.PSX +{ + public class OctoshockControlUserConfig + { + public bool[] Multitaps = new bool[2]; + public OctoshockDll.ePeripheralType[] Devices8 = new OctoshockDll.ePeripheralType[8]; + + public OctoshockControlLogicalConfig ToLogicalConfig() + { + var lc = new OctoshockControlLogicalConfig(); + lc.PopulateFrom(this); + return lc; + } + } + + public class OctoshockControlLogicalConfig + { + public int[] PlayerAssignments = new int[8]; + public bool[] Multitaps; + public OctoshockDll.ePeripheralType[] Devices8; + + internal void PopulateFrom(OctoshockControlUserConfig userConfig) + { + Multitaps = (bool[])userConfig.Multitaps.Clone(); + Devices8 = (OctoshockDll.ePeripheralType[])userConfig.Devices8.Clone(); + + int id = 1; + + if (userConfig.Devices8[0] == OctoshockDll.ePeripheralType.None) PlayerAssignments[0] = -1; else PlayerAssignments[0] = id++; + if (userConfig.Devices8[1] == OctoshockDll.ePeripheralType.None || !userConfig.Multitaps[0]) PlayerAssignments[1] = -1; else PlayerAssignments[1] = id++; + if (userConfig.Devices8[2] == OctoshockDll.ePeripheralType.None || !userConfig.Multitaps[0]) PlayerAssignments[2] = -1; else PlayerAssignments[2] = id++; + if (userConfig.Devices8[3] == OctoshockDll.ePeripheralType.None || !userConfig.Multitaps[0]) PlayerAssignments[3] = -1; else PlayerAssignments[3] = id++; + + if (userConfig.Devices8[4] == OctoshockDll.ePeripheralType.None) PlayerAssignments[4] = -1; else PlayerAssignments[4] = id++; + if (userConfig.Devices8[5] == OctoshockDll.ePeripheralType.None || !userConfig.Multitaps[1]) PlayerAssignments[5] = -1; else PlayerAssignments[5] = id++; + if (userConfig.Devices8[6] == OctoshockDll.ePeripheralType.None || !userConfig.Multitaps[1]) PlayerAssignments[6] = -1; else PlayerAssignments[6] = id++; + if (userConfig.Devices8[7] == OctoshockDll.ePeripheralType.None || !userConfig.Multitaps[1]) PlayerAssignments[7] = -1; else PlayerAssignments[7] = id++; + } + } + +} \ No newline at end of file