Input Config - backend for supporting showing conflicts, rip out old inputwidget conflict code in favor of a simpler design
This commit is contained in:
parent
2e4ca0fae6
commit
99c7c132f1
|
@ -38,6 +38,37 @@ namespace BizHawk.MultiClient
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DoConflicts()
|
||||||
|
{
|
||||||
|
List<KeyValuePair<int, string>> BindingList = new List<KeyValuePair<int, string>>();
|
||||||
|
HashSet<string> uniqueBindings = new HashSet<string>();
|
||||||
|
|
||||||
|
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<int, string>(i, binding));
|
||||||
|
uniqueBindings.Add(binding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string binding in uniqueBindings)
|
||||||
|
{
|
||||||
|
List<KeyValuePair<int, string>> kvps = BindingList.Where(x => x.Value == binding).ToList();
|
||||||
|
if (kvps.Count > 0)
|
||||||
|
{
|
||||||
|
foreach(KeyValuePair<int, string> kvp in kvps)
|
||||||
|
{
|
||||||
|
Inputs[kvp.Key].Conflicted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void ClearAll()
|
public void ClearAll()
|
||||||
{
|
{
|
||||||
foreach (InputWidget i in Inputs)
|
foreach (InputWidget i in Inputs)
|
||||||
|
|
|
@ -190,7 +190,7 @@ namespace BizHawk.MultiClient
|
||||||
int yoffset = (row * 24);
|
int yoffset = (row * 24);
|
||||||
TempLabel.Location = new Point(8 + xoffset, 20 + yoffset);
|
TempLabel.Location = new Point(8 + xoffset, 20 + yoffset);
|
||||||
Labels.Add(TempLabel);
|
Labels.Add(TempLabel);
|
||||||
TempTextBox = new InputWidget(HotkeyMappingList);
|
TempTextBox = new InputWidget();
|
||||||
TempTextBox.Location = new Point(64 + xoffset, 20 + yoffset);
|
TempTextBox.Location = new Point(64 + xoffset, 20 + yoffset);
|
||||||
TextBoxes.Add(TempTextBox);
|
TextBoxes.Add(TempTextBox);
|
||||||
object field = null;
|
object field = null;
|
||||||
|
|
|
@ -22,6 +22,29 @@ namespace BizHawk.MultiClient
|
||||||
Color _highlight_color = Color.LightCyan;
|
Color _highlight_color = Color.LightCyan;
|
||||||
Color _no_highlight_color = SystemColors.Window;
|
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()
|
private void Highlight()
|
||||||
{
|
{
|
||||||
BackColor = _highlight_color;
|
BackColor = _highlight_color;
|
||||||
|
@ -32,8 +55,6 @@ namespace BizHawk.MultiClient
|
||||||
BackColor = _no_highlight_color;
|
BackColor = _no_highlight_color;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<KeyValuePair<string, string>> ConflictLookup = new List<KeyValuePair<string, string>>();
|
|
||||||
|
|
||||||
[DllImport("user32")]
|
[DllImport("user32")]
|
||||||
private static extern bool HideCaret(IntPtr hWnd);
|
private static extern bool HideCaret(IntPtr hWnd);
|
||||||
|
|
||||||
|
@ -45,15 +66,6 @@ namespace BizHawk.MultiClient
|
||||||
tooltip1.AutoPopDelay = 2000;
|
tooltip1.AutoPopDelay = 2000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputWidget(List<KeyValuePair<string, string>> conflictList)
|
|
||||||
{
|
|
||||||
this.ContextMenu = new ContextMenu();
|
|
||||||
this.timer.Tick += new System.EventHandler(this.Timer_Tick);
|
|
||||||
InitializeBindings();
|
|
||||||
tooltip1.AutoPopDelay = 2000;
|
|
||||||
ConflictLookup = conflictList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputWidget(int maxBindings)
|
public InputWidget(int maxBindings)
|
||||||
{
|
{
|
||||||
this.ContextMenu = new ContextMenu();
|
this.ContextMenu = new ContextMenu();
|
||||||
|
@ -64,11 +76,6 @@ namespace BizHawk.MultiClient
|
||||||
tooltip1.AutoPopDelay = 2000;
|
tooltip1.AutoPopDelay = 2000;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetConflictList(List<KeyValuePair<string, string>> conflictLookup)
|
|
||||||
{
|
|
||||||
ConflictLookup = conflictLookup;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnMouseClick(MouseEventArgs e)
|
protected override void OnMouseClick(MouseEventArgs e)
|
||||||
{
|
{
|
||||||
HideCaret(this.Handle);
|
HideCaret(this.Handle);
|
||||||
|
@ -108,7 +115,7 @@ namespace BizHawk.MultiClient
|
||||||
public void EraseMappings()
|
public void EraseMappings()
|
||||||
{
|
{
|
||||||
ClearBindings();
|
ClearBindings();
|
||||||
HideConflicts();
|
conflicted = false;
|
||||||
Text = "";
|
Text = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +132,7 @@ namespace BizHawk.MultiClient
|
||||||
if (TempBindingStr == "Escape")
|
if (TempBindingStr == "Escape")
|
||||||
{
|
{
|
||||||
ClearBindings();
|
ClearBindings();
|
||||||
HideConflicts();
|
conflicted = false;
|
||||||
Increment();
|
Increment();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -139,57 +146,11 @@ namespace BizHawk.MultiClient
|
||||||
}
|
}
|
||||||
wasPressed = TempBindingStr;
|
wasPressed = TempBindingStr;
|
||||||
|
|
||||||
DoConflictCheck();
|
|
||||||
|
|
||||||
UpdateLabel();
|
UpdateLabel();
|
||||||
Increment();
|
Increment();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string Conflicts = "";
|
|
||||||
|
|
||||||
private void DoConflictCheck()
|
|
||||||
{
|
|
||||||
StringBuilder conflicts = new StringBuilder(); ;
|
|
||||||
foreach (KeyValuePair<string, string> 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
|
//Checks if the key is already mapped to this widget
|
||||||
private bool IsDuplicate(string binding)
|
private bool IsDuplicate(string binding)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue