make input binding limitless (instead of limited to 4). at the same time, fix bugs caused by index accounting related to the limit.

This commit is contained in:
zeromus 2014-10-11 08:43:26 +00:00
parent 3eb4dde346
commit 6428b07d0a
1 changed files with 8 additions and 44 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -11,10 +12,8 @@ namespace BizHawk.Client.EmuHawk
// 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 ToolTip _tooltip1 = new ToolTip();
private readonly Timer _timer = new Timer(); private readonly Timer _timer = new Timer();
private readonly string[] _bindings = new string[4]; private readonly List<string> _bindings = new List<string>();
private readonly int _maxBind = 4; // Max number of bindings allowed
private int _pos; // Which mapping the widget will listen for
private string _wasPressed = string.Empty; private string _wasPressed = string.Empty;
public InputCompositeWidget CompositeWidget; public InputCompositeWidget CompositeWidget;
@ -42,8 +41,7 @@ namespace BizHawk.Client.EmuHawk
AutoTab = autotab; AutoTab = autotab;
ContextMenu = new ContextMenu(); ContextMenu = new ContextMenu();
_timer.Tick += Timer_Tick; _timer.Tick += Timer_Tick;
_maxBind = maxBindings; _bindings = new List<string>();
_bindings = new string[_maxBind];
ClearBindings(); ClearBindings();
_tooltip1.AutoPopDelay = 2000; _tooltip1.AutoPopDelay = 2000;
} }
@ -62,14 +60,7 @@ namespace BizHawk.Client.EmuHawk
{ {
ClearBindings(); ClearBindings();
var newBindings = value.Trim().Split(','); var newBindings = value.Trim().Split(',');
for (var i = 0; i < _maxBind; i++) _bindings.AddRange(newBindings);
{
if (i < newBindings.Length)
{
_bindings[i] = newBindings[i];
}
}
UpdateLabel(); UpdateLabel();
} }
} }
@ -91,15 +82,11 @@ namespace BizHawk.Client.EmuHawk
private void ClearBindings() private void ClearBindings()
{ {
for (var i = 0; i < _maxBind; i++) _bindings.Clear();
{
_bindings[i] = string.Empty;
}
} }
protected override void OnEnter(EventArgs e) protected override void OnEnter(EventArgs e)
{ {
_pos = 0;
_timer.Start(); _timer.Start();
_wasPressed = Input.Instance.GetNextBindEvent(); _wasPressed = Input.Instance.GetNextBindEvent();
@ -131,7 +118,7 @@ namespace BizHawk.Client.EmuHawk
/// </summary> /// </summary>
public void SetBinding(string bindingStr) public void SetBinding(string bindingStr)
{ {
_bindings[_pos] = bindingStr; _bindings.Add(bindingStr);
UpdateLabel(); UpdateLabel();
Increment(); Increment();
} }
@ -178,10 +165,9 @@ namespace BizHawk.Client.EmuHawk
if (AutoTab) if (AutoTab)
{ {
ClearBindings(); ClearBindings();
_pos = 0;
} }
_bindings[_pos] = bindingStr; _bindings.Add(bindingStr);
} }
_wasPressed = bindingStr; _wasPressed = bindingStr;
@ -216,24 +202,13 @@ namespace BizHawk.Client.EmuHawk
e.Handled = true; e.Handled = true;
} }
// Advances to the next widget or the next binding depending on the autotab setting // Advances to the next widget depending on the autotab setting
public void Increment() public void Increment()
{ {
if (AutoTab) if (AutoTab)
{ {
CompositeWidget.TabNext(); CompositeWidget.TabNext();
} }
else
{
if (_pos < _maxBind)
{
_pos++;
}
else
{
_pos = 0;
}
}
} }
public void Decrement() public void Decrement()
@ -242,17 +217,6 @@ namespace BizHawk.Client.EmuHawk
{ {
Parent.SelectNextControl(this, false, true, true, true); Parent.SelectNextControl(this, false, true, true, true);
} }
else
{
if (_pos == 0)
{
_pos = _maxBind - 1;
}
else
{
_pos--;
}
}
} }
public void UpdateLabel() public void UpdateLabel()