diff --git a/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs b/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs index 917cdbda50..89b0f0cf5e 100644 --- a/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs +++ b/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs @@ -127,7 +127,7 @@ namespace BizHawk.MultiClient string s; if (!RealConfigObject.TryGetValue(buttons[button], out s)) s = ""; - Inputs[button].SetBindings(s); + Inputs[button].Bindings = s; } } diff --git a/BizHawk.MultiClient/config/InputWidget.cs b/BizHawk.MultiClient/config/InputWidget.cs index 66ee3d3a4c..98c0133eb8 100644 --- a/BizHawk.MultiClient/config/InputWidget.cs +++ b/BizHawk.MultiClient/config/InputWidget.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using System.Linq; using System.Collections.Generic; using System.Windows.Forms; using System.Runtime.InteropServices; @@ -11,18 +12,19 @@ namespace BizHawk.MultiClient { //TODO: when binding, make sure that the new key combo is not in one of the other bindings - int MaxBind = 4; //Max number of bindings allowed - int pos = 0; //Which mapping the widget will listen for + private int MaxBind = 4; //Max number of bindings allowed + private int pos = 0; //Which mapping the widget will listen for private Timer timer = new Timer(); - public bool AutoTab = true; - string[] Bindings = new string[4]; - string wasPressed = ""; - ToolTip tooltip1 = new ToolTip(); - public string WidgetName; - Color _highlight_color = Color.LightCyan; - Color _no_highlight_color = SystemColors.Window; - + private string[] _bindings = new string[4]; + private string wasPressed = ""; + private ToolTip tooltip1 = new ToolTip(); + private Color _highlight_color = Color.LightCyan; + private Color _no_highlight_color = SystemColors.Window; private bool conflicted = false; + + public bool AutoTab = true; + public string WidgetName; + public bool Conflicted { get @@ -71,7 +73,7 @@ namespace BizHawk.MultiClient { this.ContextMenu = new ContextMenu(); this.timer.Tick += new System.EventHandler(this.Timer_Tick); - InitializeBindings(); + _clearBindings(); tooltip1.AutoPopDelay = 2000; } @@ -81,8 +83,8 @@ namespace BizHawk.MultiClient this.ContextMenu = new ContextMenu(); this.timer.Tick += new System.EventHandler(this.Timer_Tick); MaxBind = maxBindings; - Bindings = new string[MaxBind]; - InitializeBindings(); + _bindings = new string[MaxBind]; + _clearBindings(); tooltip1.AutoPopDelay = 2000; } @@ -92,11 +94,11 @@ namespace BizHawk.MultiClient base.OnMouseClick(e); } - private void InitializeBindings() + private void _clearBindings() { - for (int x = 0; x < MaxBind; x++) + for (int i = 0; i < MaxBind; i++) { - Bindings[x] = ""; + _bindings[i] = ""; } } @@ -124,7 +126,7 @@ namespace BizHawk.MultiClient public void EraseMappings() { - ClearBindings(); + _clearBindings(); Conflicted = false; Text = ""; } @@ -141,7 +143,7 @@ namespace BizHawk.MultiClient { if (TempBindingStr == "Escape") { - ClearBindings(); + _clearBindings(); Conflicted = false; Increment(); return; @@ -152,7 +154,7 @@ namespace BizHawk.MultiClient if (!IsDuplicate(TempBindingStr)) { - Bindings[pos] = TempBindingStr; + _bindings[pos] = TempBindingStr; } wasPressed = TempBindingStr; @@ -164,13 +166,7 @@ namespace BizHawk.MultiClient //Checks if the key is already mapped to this widget private bool IsDuplicate(string binding) { - for (int x = 0; x < MaxBind; x++) - { - if (Bindings[x] == binding) - return true; - } - - return false; + return _bindings.FirstOrDefault(x => x == binding) != null; } protected override void OnKeyUp(KeyEventArgs e) @@ -220,50 +216,50 @@ namespace BizHawk.MultiClient } } - public void ClearBindings() - { - for (int i = 0; i < MaxBind; i++) - { - Bindings[i] = ""; - } - } - public void UpdateLabel() { Text = ""; for (int x = 0; x < MaxBind; x++) { - if (Bindings[x].Length > 0) + if (_bindings[x].Length > 0) { - Text += Bindings[x]; - if (x < MaxBind - 1 && Bindings[x+1].Length > 0) + Text += _bindings[x]; + if (x < MaxBind - 1 && _bindings[x+1].Length > 0) Text += ", "; } } } - public void SetBindings(string bindingsString) + public string Bindings { - Text = ""; - ClearBindings(); - string str = bindingsString.Trim(); - int x; - for (int i = 0; i < MaxBind; i++) + get { - str = str.Trim(); - x = str.IndexOf(','); - if (x < 0) - { - Bindings[i] = str; - str = ""; - } - else - { - Bindings[i] = str.Substring(0, x); - str = str.Substring(x + 1, str.Length - x - 1); - } + return Text; + } + set + { + Text = ""; + _clearBindings(); + string str = value.Trim(); + int x; + for (int i = 0; i < MaxBind; i++) + { + str = str.Trim(); + x = str.IndexOf(','); + if (x < 0) + { + _bindings[i] = str; + str = ""; + } + else + { + _bindings[i] = str.Substring(0, x); + str = str.Substring(x + 1, str.Length - x - 1); + } + } + + UpdateLabel(); } - UpdateLabel(); } protected override void OnKeyPress(KeyPressEventArgs e) diff --git a/BizHawk.MultiClient/config/NewHotkeyWindow.cs b/BizHawk.MultiClient/config/NewHotkeyWindow.cs index bdaeedc865..e4588f3291 100644 --- a/BizHawk.MultiClient/config/NewHotkeyWindow.cs +++ b/BizHawk.MultiClient/config/NewHotkeyWindow.cs @@ -106,7 +106,7 @@ namespace BizHawk.MultiClient InputWidget w = new InputWidget() { - Text = b.Bindings, + Bindings = b.Bindings, Location = new Point(_x + iw_offset_x , _y + iw_offset_y), AutoTab = AutoTabCheckBox.Checked, Width = iw_width,