From 0eae9924035f42e18789a299ec0f2bcc2937b68b Mon Sep 17 00:00:00 2001 From: brandman211 Date: Sun, 25 Mar 2012 00:39:51 +0000 Subject: [PATCH] Created general functions Do and Update. -Because I have been advised not to convert the objects to dictionaries, and because using the equivalent of typedef seems confusing if it isn't outright impossible, I had to implement switch statements to handle certain aspects on a platform to platform basis. -These will end up being much bigger than I would have hoped, but the entire file will be much, much smaller. TODO: Implement all of the other platforms using these functions. Note: It seems that the Enabled checkbox doesn't do anything other than persist its state. I checked the latest release, and the same issue was there, so I didn't break it! --- BizHawk.MultiClient/Config.cs | 11 +-- BizHawk.MultiClient/config/InputConfig.cs | 98 ++++++++++++++++------- 2 files changed, 75 insertions(+), 34 deletions(-) diff --git a/BizHawk.MultiClient/Config.cs b/BizHawk.MultiClient/Config.cs index 9215a3d785..3548ee1965 100644 --- a/BizHawk.MultiClient/Config.cs +++ b/BizHawk.MultiClient/Config.cs @@ -19,7 +19,7 @@ namespace BizHawk.MultiClient NESController[3] = new NESControllerTemplate(false); GameBoyController = new NESControllerTemplate(true); TI83Controller[0] = new TI83ControllerTemplate(true); - + GenesisController[0] = new GenControllerTemplate(true); GenesisAutoController[0] = new GenControllerTemplate(true); @@ -119,7 +119,6 @@ namespace BizHawk.MultiClient public string WatchPath = "."; public string AVIPath = "."; - //BIOS Paths public string PathPCEBios = Path.Combine(".", "PCECDBios.pce"); //TODO: better default filename @@ -223,7 +222,6 @@ namespace BizHawk.MultiClient public int LuaConsoleWidth = -1; public int LuaConsoleHeight = -1; public bool DisableLuaScriptsOnLoad = false; - // RamWatch Settings public bool AutoLoadRamWatch = false; @@ -461,7 +459,7 @@ namespace BizHawk.MultiClient public string AVIRecordBinding = ""; public string AVIStopBinding = ""; public string ToggleMenuBinding = ""; - + // SMS / GameGear Settings public bool SmsEnableFM = true; public bool SmsAllowOverlock = false; @@ -472,7 +470,7 @@ namespace BizHawk.MultiClient public string SmsPause = "V, J1 B8"; public SMSControllerTemplate[] SMSController = new SMSControllerTemplate[2]; public SMSControllerTemplate[] SMSAutoController = new SMSControllerTemplate[2]; - + // PCEngine Settings public bool PceSpriteLimit = false; public bool PceEqualizeVolume = false; @@ -699,7 +697,6 @@ namespace BizHawk.MultiClient } } - public class Atari2600ControllerTemplate { public string Up = ""; @@ -890,4 +887,4 @@ namespace BizHawk.MultiClient } } } -} +} \ No newline at end of file diff --git a/BizHawk.MultiClient/config/InputConfig.cs b/BizHawk.MultiClient/config/InputConfig.cs index d680a79c04..ac2a518d7f 100644 --- a/BizHawk.MultiClient/config/InputConfig.cs +++ b/BizHawk.MultiClient/config/InputConfig.cs @@ -47,6 +47,7 @@ namespace BizHawk.MultiClient private string CurSelectConsole; private int CurSelectController; private bool Changed; + public InputConfig() { InitializeComponent(); @@ -847,58 +848,101 @@ namespace BizHawk.MultiClient IDX_CONTROLLERENABLED.Enabled = true; } - private void DoNES() + private void Do(string platform) { Label TempLabel; InputWidget TempTextBox; - this.Text = ControllerStr + "NES"; - ControllerImage.Image = BizHawk.MultiClient.Properties.Resources.NESController; - int jpad = this.ControllComboBox.SelectedIndex; - NESControllerTemplate[] controller = Global.Config.NESController; - if (jpad > 3) + this.Text = ControllerStr + platform; + object[] controller = null; + object[] mainController = null; + object[] autoController = null; + switch (platform) { - jpad -= 4; - controller = Global.Config.NESAutoController; + case "NES": + ControllerImage.Image = BizHawk.MultiClient.Properties.Resources.NESController; + controller = Global.Config.NESController; + mainController = controller; + autoController = Global.Config.NESAutoController; + break; + default: + return; + } + int jpad = this.ControllComboBox.SelectedIndex; + if (jpad >= Global.PLAYERS[platform + " Controller"]) + { + jpad -= Global.PLAYERS[platform + " Controller"]; + controller = autoController; + } + switch (platform) + { + case "NES": + IDX_CONTROLLERENABLED.Checked = ((NESControllerTemplate)mainController[jpad]).Enabled; + break; } - IDX_CONTROLLERENABLED.Checked = Global.Config.NESController[jpad].Enabled; Labels.Clear(); TextBoxes.Clear(); - for (int button = 0; button < CONTROLS["NES"].Length; button++) + for (int button = 0; button < CONTROLS[platform].Length; button++) { TempLabel = new Label(); - TempLabel.Text = CONTROLS["NES"][button]; + TempLabel.Text = CONTROLS[platform][button]; TempLabel.Location = new Point(8, 20 + (button * 24)); Labels.Add(TempLabel); TempTextBox = new InputWidget(); TempTextBox.Location = new Point(48, 20 + (button * 24)); TextBoxes.Add(TempTextBox); - TempTextBox.SetBindings( - (string)controller[jpad].GetType().GetField(CONTROLS["NES"][button]).GetValue(controller[jpad]) - ); + object field = null; + string fieldName = CONTROLS[platform][button]; + switch (platform) + { + case "NES": + NESControllerTemplate obj = (NESControllerTemplate)controller[jpad]; + field = obj.GetType().GetField(fieldName).GetValue(obj); + break; + } + TempTextBox.SetBindings((string)field); ButtonsGroupBox.Controls.Add(TempTextBox); ButtonsGroupBox.Controls.Add(TempLabel); } Changed = true; } - private void UpdateNES(int prev) + private void Update(int prev, string platform) { ButtonsGroupBox.Controls.Clear(); - NESControllerTemplate[] controller = Global.Config.NESController; - if (prev > 3) + object[] controller = null; + object[] mainController = null; + object[] autoController = null; + switch (platform) { - prev -= 4; - controller = Global.Config.NESAutoController; + case "NES": + ControllerImage.Image = BizHawk.MultiClient.Properties.Resources.NESController; + controller = Global.Config.NESController; + mainController = controller; + autoController = Global.Config.NESAutoController; + break; + default: + return; + } + if (prev >= Global.PLAYERS[platform + " Controller"]) + { + prev -= Global.PLAYERS[platform + " Controller"]; + controller = autoController; } Global.Config.NESController[prev].Enabled = IDX_CONTROLLERENABLED.Checked; - for (int button = 0; button < CONTROLS["NES"].Length; button++) + for (int button = 0; button < CONTROLS[platform].Length; button++) { InputWidget TempBox = TextBoxes[button] as InputWidget; - FieldInfo buttonField = controller[prev].GetType().GetField(CONTROLS["NES"][button]); - buttonField.SetValue( - controller[prev], - AppendButtonMapping(TempBox.Text, (string)buttonField.GetValue(controller[prev])) - ); + object field = null; + string fieldName = CONTROLS[platform][button]; + switch (platform) + { + case "NES": + NESControllerTemplate obj = (NESControllerTemplate)controller[prev]; + FieldInfo buttonField = obj.GetType().GetField(fieldName); + field = buttonField.GetValue(obj); + buttonField.SetValue(obj, AppendButtonMapping(TempBox.Text, (string)field)); + break; + } TempBox.Dispose(); Label TempLabel = Labels[button] as Label; TempLabel.Dispose(); @@ -1053,7 +1097,7 @@ namespace BizHawk.MultiClient DoTI83(); break; case "NES": - DoNES(); + Do("NES"); break; case "Atari": DoAtari(); @@ -1082,7 +1126,7 @@ namespace BizHawk.MultiClient UpdateTI83(); break; case "NES": - UpdateNES(CurSelectController); + Update(CurSelectController, "NES"); break; case "Atari": UpdateAtari(CurSelectController);