Input Config - backend for supporting showing conflicts, rip out old inputwidget conflict code in favor of a simpler design

This commit is contained in:
adelikat 2012-12-04 21:47:07 +00:00
parent 2e4ca0fae6
commit 99c7c132f1
3 changed files with 57 additions and 65 deletions

View File

@ -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()
{
foreach (InputWidget i in Inputs)

View File

@ -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;

View File

@ -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<KeyValuePair<string, string>> ConflictLookup = new List<KeyValuePair<string, string>>();
[DllImport("user32")]
private static extern bool HideCaret(IntPtr hWnd);
@ -45,15 +66,6 @@ namespace BizHawk.MultiClient
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)
{
this.ContextMenu = new ContextMenu();
@ -64,11 +76,6 @@ namespace BizHawk.MultiClient
tooltip1.AutoPopDelay = 2000;
}
public void SetConflictList(List<KeyValuePair<string, string>> 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<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
private bool IsDuplicate(string binding)
{