Input Config - show when a button mapping conflicts with a hotkey mapping (but still allow it)
This commit is contained in:
parent
259be1c607
commit
1460f7b860
|
@ -88,8 +88,26 @@ namespace BizHawk.MultiClient
|
|||
foreach (string control in controlbindings)
|
||||
bindings[button].Add(control.Trim());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all keys mapped and the name of the button they are mapped to
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public List<KeyValuePair<string, string>> MappingList()
|
||||
{
|
||||
List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
|
||||
|
||||
foreach (KeyValuePair<string, List<string>> key in bindings)
|
||||
{
|
||||
foreach (string binding in key.Value)
|
||||
{
|
||||
list.Add(new KeyValuePair<string, string>(binding, key.Key));
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
public class AutofireController : IController
|
||||
{
|
||||
|
|
|
@ -52,6 +52,9 @@ namespace BizHawk.MultiClient
|
|||
{"SNES", 4},
|
||||
{"TI-83", 1}
|
||||
};
|
||||
|
||||
private List<KeyValuePair<string, string>> HotkeyMappingList = new List<KeyValuePair<string, string>>(); //A list of all button mappings and the hotkey they are assigned to
|
||||
|
||||
private ArrayList Labels;
|
||||
private ArrayList TextBoxes;
|
||||
private string CurSelectConsole;
|
||||
|
@ -199,7 +202,7 @@ namespace BizHawk.MultiClient
|
|||
int yoffset = (row * 24);
|
||||
TempLabel.Location = new Point(8 + xoffset, 20 + yoffset);
|
||||
Labels.Add(TempLabel);
|
||||
TempTextBox = new InputWidget();
|
||||
TempTextBox = new InputWidget(HotkeyMappingList);
|
||||
TempTextBox.Location = new Point(64 + xoffset, 20 + yoffset);
|
||||
TextBoxes.Add(TempTextBox);
|
||||
object field = null;
|
||||
|
@ -459,7 +462,11 @@ namespace BizHawk.MultiClient
|
|||
private void InputConfig_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (Global.MainForm.INTERIM)
|
||||
{
|
||||
SystemComboBox.Items.Add("Atari"); //When Atari is ready, add this in the designer instead
|
||||
}
|
||||
|
||||
HotkeyMappingList = Global.ClientControls.MappingList();
|
||||
|
||||
AutoTab.Checked = Global.Config.InputConfigAutoTab;
|
||||
SetAutoTab();
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Drawing;
|
|||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
|
@ -18,8 +19,20 @@ namespace BizHawk.MultiClient
|
|||
string wasPressed = "";
|
||||
ToolTip tooltip1 = new ToolTip();
|
||||
public string ButtonName;
|
||||
Color HighlightedColor = Color.LightCyan;
|
||||
Color RegularColor = SystemColors.Window;
|
||||
Color _highlight_color = Color.LightCyan;
|
||||
Color _no_highlight_color = SystemColors.Window;
|
||||
|
||||
private void Highlight()
|
||||
{
|
||||
BackColor = _highlight_color;
|
||||
}
|
||||
|
||||
private void UnHighlight()
|
||||
{
|
||||
BackColor = _no_highlight_color;
|
||||
}
|
||||
|
||||
private List<KeyValuePair<string, string>> ConflictLookup = new List<KeyValuePair<string, string>>();
|
||||
|
||||
[DllImport("user32")]
|
||||
private static extern bool HideCaret(IntPtr hWnd);
|
||||
|
@ -32,6 +45,15 @@ 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();
|
||||
|
@ -42,19 +64,9 @@ namespace BizHawk.MultiClient
|
|||
tooltip1.AutoPopDelay = 2000;
|
||||
}
|
||||
|
||||
public void FlagDuplicate(string duplicateName)
|
||||
public void SetConflictList(List<KeyValuePair<string, string>> conflictLookup)
|
||||
{
|
||||
RegularColor = Color.LightCoral;
|
||||
HighlightedColor = Color.Violet;
|
||||
BackColor = RegularColor;
|
||||
tooltip1.SetToolTip(this, "same mapping as " + duplicateName);
|
||||
}
|
||||
|
||||
public void UnflagDuplicate()
|
||||
{
|
||||
HighlightedColor = Color.LightCyan;
|
||||
RegularColor = SystemColors.Window;
|
||||
tooltip1.SetToolTip(this, "");
|
||||
ConflictLookup = conflictLookup;
|
||||
}
|
||||
|
||||
protected override void OnMouseClick(MouseEventArgs e)
|
||||
|
@ -115,12 +127,60 @@ namespace BizHawk.MultiClient
|
|||
Bindings[pos] = TempBindingStr;
|
||||
}
|
||||
wasPressed = TempBindingStr;
|
||||
|
||||
DoConflictCheck();
|
||||
|
||||
UpdateLabel();
|
||||
Increment();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDuplicate(string binding)
|
||||
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)
|
||||
{
|
||||
for (int x = 0; x < MaxBind; x++)
|
||||
{
|
||||
|
@ -274,13 +334,12 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
//base.OnGotFocus(e);
|
||||
HideCaret(this.Handle);
|
||||
BackColor = HighlightedColor;
|
||||
Highlight();
|
||||
}
|
||||
|
||||
protected override void OnLostFocus(EventArgs e)
|
||||
{
|
||||
UnflagDuplicate();
|
||||
BackColor = RegularColor;
|
||||
UnHighlight();
|
||||
base.OnLostFocus(e);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue