diff --git a/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs b/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs index 72c9175ac7..29c77c7274 100644 --- a/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs +++ b/BizHawk.MultiClient/config/ControllerConfig/ControllerConfigPanel.cs @@ -38,6 +38,37 @@ namespace BizHawk.MultiClient } + private void DoConflicts() + { + List> BindingList = new List>(); + HashSet uniqueBindings = new HashSet(); + + for (int i = 0; i < Inputs.Count; i++) + { + if (!String.IsNullOrWhiteSpace(Inputs[0].Text)) + { + string[] bindings = Inputs[0].Text.Split(','); + foreach (string binding in bindings) + { + BindingList.Add(new KeyValuePair(i, binding)); + uniqueBindings.Add(binding); + } + } + } + + foreach (string binding in uniqueBindings) + { + List> kvps = BindingList.Where(x => x.Value == binding).ToList(); + if (kvps.Count > 0) + { + foreach(KeyValuePair kvp in kvps) + { + Inputs[kvp.Key].Conflicted = true; + } + } + } + } + public void ClearAll() { foreach (InputWidget i in Inputs) diff --git a/BizHawk.MultiClient/config/InputConfig.cs b/BizHawk.MultiClient/config/InputConfig.cs index 3b95274488..fa005d2c9b 100644 --- a/BizHawk.MultiClient/config/InputConfig.cs +++ b/BizHawk.MultiClient/config/InputConfig.cs @@ -190,7 +190,7 @@ namespace BizHawk.MultiClient int yoffset = (row * 24); TempLabel.Location = new Point(8 + xoffset, 20 + yoffset); Labels.Add(TempLabel); - TempTextBox = new InputWidget(HotkeyMappingList); + TempTextBox = new InputWidget(); TempTextBox.Location = new Point(64 + xoffset, 20 + yoffset); TextBoxes.Add(TempTextBox); object field = null; diff --git a/BizHawk.MultiClient/config/InputWidget.cs b/BizHawk.MultiClient/config/InputWidget.cs index bc5d3beb91..03d18a98c1 100644 --- a/BizHawk.MultiClient/config/InputWidget.cs +++ b/BizHawk.MultiClient/config/InputWidget.cs @@ -22,6 +22,29 @@ namespace BizHawk.MultiClient Color _highlight_color = Color.LightCyan; Color _no_highlight_color = SystemColors.Window; + private bool conflicted = false; + public bool Conflicted + { + get + { + return conflicted; + } + set + { + conflicted = value; + if (conflicted) + { + _no_highlight_color = Color.LightCoral; + _highlight_color = Color.Violet; + } + else + { + _highlight_color = Color.LightCyan; + _no_highlight_color = SystemColors.Window; + } + } + } + private void Highlight() { BackColor = _highlight_color; @@ -32,8 +55,6 @@ namespace BizHawk.MultiClient BackColor = _no_highlight_color; } - private List> ConflictLookup = new List>(); - [DllImport("user32")] private static extern bool HideCaret(IntPtr hWnd); @@ -45,15 +66,6 @@ namespace BizHawk.MultiClient tooltip1.AutoPopDelay = 2000; } - public InputWidget(List> conflictList) - { - this.ContextMenu = new ContextMenu(); - this.timer.Tick += new System.EventHandler(this.Timer_Tick); - InitializeBindings(); - tooltip1.AutoPopDelay = 2000; - ConflictLookup = conflictList; - } - public InputWidget(int maxBindings) { this.ContextMenu = new ContextMenu(); @@ -64,11 +76,6 @@ namespace BizHawk.MultiClient tooltip1.AutoPopDelay = 2000; } - public void SetConflictList(List> conflictLookup) - { - ConflictLookup = conflictLookup; - } - protected override void OnMouseClick(MouseEventArgs e) { HideCaret(this.Handle); @@ -108,7 +115,7 @@ namespace BizHawk.MultiClient public void EraseMappings() { ClearBindings(); - HideConflicts(); + conflicted = false; Text = ""; } @@ -125,7 +132,7 @@ namespace BizHawk.MultiClient if (TempBindingStr == "Escape") { ClearBindings(); - HideConflicts(); + conflicted = false; Increment(); return; } @@ -139,57 +146,11 @@ namespace BizHawk.MultiClient } wasPressed = TempBindingStr; - DoConflictCheck(); - UpdateLabel(); Increment(); } } - private string Conflicts = ""; - - private void DoConflictCheck() - { - StringBuilder conflicts = new StringBuilder(); ; - foreach (KeyValuePair conflict in ConflictLookup) - { - foreach (string binding in Bindings) - { - if (conflict.Key == binding) - { - conflicts.Append(binding); - conflicts.Append(" conflicts with Hotkey - "); //Ideally we don't hardcode Hotkey, we may want to check mappings on specific controllers or unforeseen things - conflicts.Append(conflict.Value); - conflicts.Append('\n'); - } - } - } - Conflicts = conflicts.ToString(); - - if (String.IsNullOrWhiteSpace(Conflicts)) - { - HideConflicts(); - } - else - { - ShowConflicts(); - } - } - - private void ShowConflicts() - { - _no_highlight_color = Color.LightCoral; - _highlight_color = Color.Violet; - tooltip1.SetToolTip(this, Conflicts); - } - - private void HideConflicts() - { - _highlight_color = Color.LightCyan; - _no_highlight_color = SystemColors.Window; - tooltip1.SetToolTip(this, ""); - } - //Checks if the key is already mapped to this widget private bool IsDuplicate(string binding) {