Input config - when autotab is off, fix bug where pressing esc was not updating the textbox, also some formatting cleanup

This commit is contained in:
adelikat 2014-02-08 16:15:07 +00:00
parent eed290cb8d
commit 2c0804eede
1 changed files with 63 additions and 71 deletions

View File

@ -1,27 +1,21 @@
using System; using System;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public sealed class InputWidget : TextBox public sealed class InputWidget : TextBox
{ {
//TODO: when binding, make sure that the new key combo is not in one of the other bindings // TODO: when binding, make sure that the new key combo is not in one of the other bindings
private readonly ToolTip _tooltip1 = new ToolTip();
private readonly int _maxBind = 4; //Max number of bindings allowed
private int _pos; //Which mapping the widget will listen for
private readonly Timer _timer = new Timer(); private readonly Timer _timer = new Timer();
private readonly string[] _bindings = new string[4]; private readonly string[] _bindings = new string[4];
private string _wasPressed = String.Empty; private readonly int _maxBind = 4; // Max number of bindings allowed
private readonly ToolTip _tooltip1 = new ToolTip();
public bool AutoTab = true; private int _pos; // Which mapping the widget will listen for
public string WidgetName; private string _wasPressed = string.Empty;
[DllImport("user32")]
private static extern bool HideCaret(IntPtr hWnd);
public InputWidget() public InputWidget()
{ {
@ -29,6 +23,7 @@ namespace BizHawk.Client.EmuHawk
_timer.Tick += Timer_Tick; _timer.Tick += Timer_Tick;
ClearBindings(); ClearBindings();
_tooltip1.AutoPopDelay = 2000; _tooltip1.AutoPopDelay = 2000;
AutoTab = true;
} }
public InputWidget(int maxBindings, bool autotab) public InputWidget(int maxBindings, bool autotab)
@ -42,6 +37,35 @@ namespace BizHawk.Client.EmuHawk
_tooltip1.AutoPopDelay = 2000; _tooltip1.AutoPopDelay = 2000;
} }
public bool AutoTab { get; set; }
public string WidgetName { get; set; }
public string Bindings
{
get
{
return Text;
}
set
{
ClearBindings();
var newBindings = value.Trim().Split(',');
for (var i = 0; i < _maxBind; i++)
{
if (i < newBindings.Length)
{
_bindings[i] = newBindings[i];
}
}
UpdateLabel();
}
}
[DllImport("user32")]
private static extern bool HideCaret(IntPtr hWnd);
protected override void OnMouseClick(MouseEventArgs e) protected override void OnMouseClick(MouseEventArgs e)
{ {
HideCaret(Handle); HideCaret(Handle);
@ -50,9 +74,9 @@ namespace BizHawk.Client.EmuHawk
private void ClearBindings() private void ClearBindings()
{ {
for (int i = 0; i < _maxBind; i++) for (var i = 0; i < _maxBind; i++)
{ {
_bindings[i] = String.Empty; _bindings[i] = string.Empty;
} }
} }
@ -71,7 +95,6 @@ namespace BizHawk.Client.EmuHawk
UpdateLabel(); UpdateLabel();
BackColor = SystemColors.Window; BackColor = SystemColors.Window;
base.OnLeave(e); base.OnLeave(e);
} }
private void Timer_Tick(object sender, EventArgs e) private void Timer_Tick(object sender, EventArgs e)
@ -82,36 +105,38 @@ namespace BizHawk.Client.EmuHawk
public void EraseMappings() public void EraseMappings()
{ {
ClearBindings(); ClearBindings();
Text = String.Empty; Text = string.Empty;
} }
private void ReadKeys() private void ReadKeys()
{ {
Input.Instance.Update(); Input.Instance.Update();
var TempBindingStr = Input.Instance.GetNextBindEvent(); var bindingStr = Input.Instance.GetNextBindEvent();
if (!String.IsNullOrEmpty(_wasPressed) && TempBindingStr == _wasPressed) if (!string.IsNullOrEmpty(_wasPressed) && bindingStr == _wasPressed)
{ {
return; return;
} }
else if (TempBindingStr != null)
if (bindingStr != null)
{ {
if (TempBindingStr == "Escape") if (bindingStr == "Escape")
{ {
ClearBindings(); EraseMappings();
Increment(); Increment();
return; return;
} }
else if (TempBindingStr == "Alt+F4")
if (bindingStr == "Alt+F4")
{ {
return; return;
} }
if (!IsDuplicate(TempBindingStr)) if (!IsDuplicate(bindingStr))
{ {
_bindings[_pos] = TempBindingStr; _bindings[_pos] = bindingStr;
} }
_wasPressed = TempBindingStr;
_wasPressed = bindingStr;
UpdateLabel(); UpdateLabel();
Increment(); Increment();
} }
@ -129,7 +154,7 @@ namespace BizHawk.Client.EmuHawk
base.OnKeyUp(e); base.OnKeyUp(e);
} }
_wasPressed = String.Empty; _wasPressed = string.Empty;
} }
protected override void OnKeyDown(KeyEventArgs e) protected override void OnKeyDown(KeyEventArgs e)
@ -184,28 +209,7 @@ namespace BizHawk.Client.EmuHawk
public void UpdateLabel() public void UpdateLabel()
{ {
Text = String.Join(",", _bindings.Where(x => !String.IsNullOrWhiteSpace(x))); Text = string.Join(",", _bindings.Where(str => !string.IsNullOrWhiteSpace(str)));
}
public string Bindings
{
get
{
return Text;
}
set
{
ClearBindings();
var newBindings = value.Trim().Split(',');
for (int i = 0; i < _maxBind; i++)
{
if (i < newBindings.Length)
{
_bindings[i] = newBindings[i];
}
}
UpdateLabel();
}
} }
protected override void OnKeyPress(KeyPressEventArgs e) protected override void OnKeyPress(KeyPressEventArgs e)
@ -217,28 +221,15 @@ namespace BizHawk.Client.EmuHawk
{ {
switch (m.Msg) switch (m.Msg)
{ {
case 0x0201: //WM_LBUTTONDOWN case 0x0201: // WM_LBUTTONDOWN
{
Focus(); Focus();
return; return;
} case 0x0203: // WM_LBUTTONDBLCLK
case 0x0203://WM_LBUTTONDBLCLK case 0x0204: // WM_RBUTTONDOWN
{ case 0x0205: // WM_RBUTTONUP
case 0x0206: // WM_RBUTTONDBLCLK
return; return;
} }
case 0x0204://WM_RBUTTONDOWN
{
return;
}
case 0x0205://WM_RBUTTONUP
{
return;
}
case 0x0206://WM_RBUTTONDBLCLK
{
return;
}
}
base.WndProc(ref m); base.WndProc(ref m);
} }
@ -253,6 +244,7 @@ namespace BizHawk.Client.EmuHawk
{ {
Increment(); Increment();
} }
base.OnMouseWheel(e); base.OnMouseWheel(e);
} }