cleanup controller config user control classes
This commit is contained in:
parent
52f3dc5bca
commit
f84065a45a
|
@ -73,8 +73,7 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private Control CreateNormalPanel(Dictionary<string, string> settings, List<string> buttons, Size size)
|
||||
{
|
||||
var cp = new ControllerConfigPanel { Dock = DockStyle.Fill, AutoScroll = true };
|
||||
cp.Tooltip = toolTip1;
|
||||
var cp = new ControllerConfigPanel { Dock = DockStyle.Fill, AutoScroll = true, Tooltip = toolTip1 };
|
||||
cp.LoadSettings(settings, checkBoxAutoTab.Checked, buttons, size.Width, size.Height);
|
||||
return cp;
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
this.trackBarSensitivity.SmallChange = 10;
|
||||
this.trackBarSensitivity.TabIndex = 2;
|
||||
this.trackBarSensitivity.TickFrequency = 10;
|
||||
this.trackBarSensitivity.ValueChanged += new System.EventHandler(this.trackBarSensitivity_ValueChanged);
|
||||
this.trackBarSensitivity.ValueChanged += new System.EventHandler(this.TrackBarSensitivity_ValueChanged);
|
||||
//
|
||||
// labelSensitivity
|
||||
//
|
||||
|
@ -84,7 +84,7 @@
|
|||
//
|
||||
// timer1
|
||||
//
|
||||
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
|
||||
this.timer1.Tick += new System.EventHandler(this.Timer1_Tick);
|
||||
//
|
||||
// buttonBind
|
||||
//
|
||||
|
@ -94,7 +94,7 @@
|
|||
this.buttonBind.TabIndex = 4;
|
||||
this.buttonBind.Text = "Bind!";
|
||||
this.buttonBind.UseVisualStyleBackColor = true;
|
||||
this.buttonBind.Click += new System.EventHandler(this.buttonBind_Click);
|
||||
this.buttonBind.Click += new System.EventHandler(this.ButtonBind_Click);
|
||||
//
|
||||
// trackBarDeadzone
|
||||
//
|
||||
|
@ -103,7 +103,7 @@
|
|||
this.trackBarDeadzone.Size = new System.Drawing.Size(104, 45);
|
||||
this.trackBarDeadzone.TabIndex = 5;
|
||||
this.trackBarDeadzone.TickFrequency = 2;
|
||||
this.trackBarDeadzone.ValueChanged += new System.EventHandler(this.trackBarDeadzone_ValueChanged);
|
||||
this.trackBarDeadzone.ValueChanged += new System.EventHandler(this.TrackBarDeadzone_ValueChanged);
|
||||
//
|
||||
// labelDeadzone
|
||||
//
|
||||
|
@ -122,7 +122,7 @@
|
|||
this.buttonFlip.TabIndex = 7;
|
||||
this.buttonFlip.Text = "Flip Axis";
|
||||
this.buttonFlip.UseVisualStyleBackColor = true;
|
||||
this.buttonFlip.Click += new System.EventHandler(this.buttonFlip_Click);
|
||||
this.buttonFlip.Click += new System.EventHandler(this.ButtonFlip_Click);
|
||||
//
|
||||
// buttonUnbind
|
||||
//
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
@ -18,75 +12,77 @@ namespace BizHawk.Client.EmuHawk
|
|||
InitializeComponent();
|
||||
}
|
||||
|
||||
public string ButtonName;
|
||||
public Config.AnalogBind Bind;
|
||||
bool listening = false;
|
||||
|
||||
public AnalogBindControl(string ButtonName, Config.AnalogBind Bind)
|
||||
public AnalogBindControl(string buttonName, Config.AnalogBind bind)
|
||||
: this()
|
||||
{
|
||||
this.Bind = Bind;
|
||||
this.ButtonName = ButtonName;
|
||||
labelButtonName.Text = ButtonName;
|
||||
trackBarSensitivity.Value = (int)(Bind.Mult * 10.0f);
|
||||
trackBarDeadzone.Value = (int)(Bind.Deadzone * 20.0f);
|
||||
trackBarSensitivity_ValueChanged(null, null);
|
||||
trackBarDeadzone_ValueChanged(null, null);
|
||||
textBox1.Text = Bind.Value;
|
||||
_bind = bind;
|
||||
ButtonName = buttonName;
|
||||
labelButtonName.Text = buttonName;
|
||||
trackBarSensitivity.Value = (int)(bind.Mult * 10.0f);
|
||||
trackBarDeadzone.Value = (int)(bind.Deadzone * 20.0f);
|
||||
TrackBarSensitivity_ValueChanged(null, null);
|
||||
TrackBarDeadzone_ValueChanged(null, null);
|
||||
textBox1.Text = bind.Value;
|
||||
}
|
||||
|
||||
private void timer1_Tick(object sender, EventArgs e)
|
||||
public string ButtonName { get; private set; }
|
||||
public Config.AnalogBind Bind => _bind;
|
||||
|
||||
private Config.AnalogBind _bind;
|
||||
private bool _listening;
|
||||
|
||||
private void Timer1_Tick(object sender, EventArgs e)
|
||||
{
|
||||
string bindval = Input.Instance.GetNextFloatEvent();
|
||||
if (bindval != null)
|
||||
{
|
||||
timer1.Stop();
|
||||
listening = false;
|
||||
Bind.Value = bindval;
|
||||
_listening = false;
|
||||
_bind.Value = bindval;
|
||||
textBox1.Text = Bind.Value;
|
||||
buttonBind.Text = "Bind!";
|
||||
Input.Instance.StopListeningForFloatEvents();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonBind_Click(object sender, EventArgs e)
|
||||
private void ButtonBind_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listening)
|
||||
if (_listening)
|
||||
{
|
||||
timer1.Stop();
|
||||
listening = false;
|
||||
_listening = false;
|
||||
buttonBind.Text = "Bind!";
|
||||
Input.Instance.StopListeningForFloatEvents();
|
||||
}
|
||||
else
|
||||
{
|
||||
Input.Instance.StartListeningForFloatEvents();
|
||||
listening = true;
|
||||
_listening = true;
|
||||
buttonBind.Text = "Cancel!";
|
||||
timer1.Start();
|
||||
}
|
||||
}
|
||||
|
||||
private void trackBarSensitivity_ValueChanged(object sender, EventArgs e)
|
||||
private void TrackBarSensitivity_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Bind.Mult = trackBarSensitivity.Value / 10.0f;
|
||||
labelSensitivity.Text = String.Format("Sensitivity: {0}", (Bind.Mult*100)) + "%";
|
||||
_bind.Mult = trackBarSensitivity.Value / 10.0f;
|
||||
labelSensitivity.Text = $"Sensitivity: {(Bind.Mult * 100)}" + "%";
|
||||
}
|
||||
|
||||
private void trackBarDeadzone_ValueChanged(object sender, EventArgs e)
|
||||
private void TrackBarDeadzone_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
Bind.Deadzone = trackBarDeadzone.Value / 20.0f;
|
||||
labelDeadzone.Text = String.Format("Deadzone: {0}", (Bind.Deadzone*100)) + "%";
|
||||
_bind.Deadzone = trackBarDeadzone.Value / 20.0f;
|
||||
labelDeadzone.Text = $"Deadzone: {(Bind.Deadzone * 100)}" + "%";
|
||||
}
|
||||
|
||||
private void buttonFlip_Click(object sender, EventArgs e)
|
||||
private void ButtonFlip_Click(object sender, EventArgs e)
|
||||
{
|
||||
trackBarSensitivity.Value *= -1;
|
||||
}
|
||||
|
||||
public void Unbind_Click(object sender, EventArgs e)
|
||||
{
|
||||
Bind.Value = "";
|
||||
_bind.Value = "";
|
||||
textBox1.Text = "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using System.Drawing;
|
||||
|
||||
|
@ -9,40 +6,42 @@ using BizHawk.Client.Common;
|
|||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
class AnalogBindPanel : UserControl
|
||||
public class AnalogBindPanel : UserControl
|
||||
{
|
||||
Dictionary<string, Config.AnalogBind> RealConfigObject;
|
||||
private readonly Dictionary<string, Config.AnalogBind> _realConfigObject;
|
||||
|
||||
public AnalogBindPanel(Dictionary<string, Config.AnalogBind> RealConfigObject, List<string> RealConfigButtons = null)
|
||||
:base()
|
||||
public AnalogBindPanel(Dictionary<string, Config.AnalogBind> realConfigObject, List<string> realConfigButtons = null)
|
||||
{
|
||||
this.RealConfigObject = RealConfigObject;
|
||||
|
||||
LoadSettings(RealConfigButtons ?? (IEnumerable<string>)RealConfigObject.Keys);
|
||||
_realConfigObject = realConfigObject;
|
||||
LoadSettings(realConfigButtons ?? (IEnumerable<string>)realConfigObject.Keys);
|
||||
}
|
||||
|
||||
void LoadSettings(IEnumerable<string> ButtonList)
|
||||
private void LoadSettings(IEnumerable<string> buttonList)
|
||||
{
|
||||
SuspendLayout();
|
||||
int x = 4;
|
||||
int y = 4;
|
||||
foreach (string ButtonName in ButtonList)
|
||||
foreach (string buttonName in buttonList)
|
||||
{
|
||||
var ctrl = new AnalogBindControl(ButtonName, RealConfigObject[ButtonName]);
|
||||
ctrl.Location = new Point(x, y);
|
||||
var ctrl = new AnalogBindControl(buttonName, _realConfigObject[buttonName])
|
||||
{
|
||||
Location = new Point(x, y)
|
||||
};
|
||||
|
||||
y += ctrl.Height + 4;
|
||||
Controls.Add(ctrl);
|
||||
}
|
||||
|
||||
ResumeLayout();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// save to config
|
||||
/// </summary>
|
||||
/// <param name="SaveConfigObject">if non-null, save to possibly different config object than originally initialized from</param>
|
||||
public void Save(Dictionary<string, Config.AnalogBind> SaveConfigObject = null)
|
||||
/// <param name="saveConfigObject">if non-null, save to possibly different config object than originally initialized from</param>
|
||||
public void Save(Dictionary<string, Config.AnalogBind> saveConfigObject = null)
|
||||
{
|
||||
var saveto = SaveConfigObject ?? RealConfigObject;
|
||||
var saveto = saveConfigObject ?? _realConfigObject;
|
||||
foreach (Control c in Controls)
|
||||
{
|
||||
var abc = (AnalogBindControl)c;
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
|
||||
this.clearToolStripMenuItem.Size = new System.Drawing.Size(99, 22);
|
||||
this.clearToolStripMenuItem.Text = "&Clear";
|
||||
this.clearToolStripMenuItem.Click += new System.EventHandler(this.clearToolStripMenuItem_Click);
|
||||
this.clearToolStripMenuItem.Click += new System.EventHandler(this.ClearToolStripMenuItem_Click);
|
||||
//
|
||||
// ControllerConfigPanel
|
||||
//
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
@ -12,29 +11,29 @@ namespace BizHawk.Client.EmuHawk
|
|||
public partial class ControllerConfigPanel : UserControl
|
||||
{
|
||||
// the dictionary that results are saved to
|
||||
Dictionary<string, string> RealConfigObject;
|
||||
private Dictionary<string, string> _realConfigObject;
|
||||
|
||||
// if nonnull, the list of keys to use. used to have the config panel operate on a smaller list than the whole dictionary;
|
||||
// for instance, to show only a single player
|
||||
List<string> RealConfigButtons;
|
||||
private List<string> _realConfigButtons;
|
||||
|
||||
public List<string> buttons = new List<string>();
|
||||
private readonly List<string> _buttons = new List<string>();
|
||||
|
||||
public int InputMarginLeft = UIHelper.ScaleX(0);
|
||||
public int LabelPadding = UIHelper.ScaleX(5);
|
||||
private readonly int _inputMarginLeft = UIHelper.ScaleX(0);
|
||||
private readonly int _labelPadding = UIHelper.ScaleX(5);
|
||||
private readonly int _marginTop = UIHelper.ScaleY(0);
|
||||
private readonly int _spacing = UIHelper.ScaleY(24);
|
||||
private readonly int _inputSize = UIHelper.ScaleX(170);
|
||||
private readonly int _columnWidth = UIHelper.ScaleX(280);
|
||||
|
||||
public int MarginTop = UIHelper.ScaleY(0);
|
||||
public int Spacing = UIHelper.ScaleY(24);
|
||||
public int InputSize = UIHelper.ScaleX(170);
|
||||
public int ColumnWidth = UIHelper.ScaleX(280);
|
||||
public int LabelWidth = UIHelper.ScaleX(60);
|
||||
public ToolTip Tooltip { get; set; }
|
||||
|
||||
public ToolTip Tooltip;
|
||||
|
||||
protected List<InputCompositeWidget> Inputs = new List<InputCompositeWidget>();
|
||||
protected List<Label> Labels = new List<Label>();
|
||||
private readonly List<InputCompositeWidget> _inputs = new List<InputCompositeWidget>();
|
||||
|
||||
private Size _panelSize = new Size(0, 0);
|
||||
|
||||
private bool _autotab;
|
||||
|
||||
public ControllerConfigPanel()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
@ -42,29 +41,29 @@ namespace BizHawk.Client.EmuHawk
|
|||
|
||||
private void ControllerConfigPanel_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
private void ClearAll()
|
||||
{
|
||||
Inputs.ForEach(x => x.Clear());
|
||||
_inputs.ForEach(x => x.Clear());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// save to config
|
||||
/// </summary>
|
||||
/// <param name="SaveConfigObject">if non-null, save to possibly different config object than originally initialized from</param>
|
||||
public void Save(Dictionary<string, string>SaveConfigObject = null)
|
||||
/// <param name="saveConfigObject">if non-null, save to possibly different config object than originally initialized from</param>
|
||||
public void Save(Dictionary<string, string> saveConfigObject = null)
|
||||
{
|
||||
var saveto = SaveConfigObject ?? RealConfigObject;
|
||||
for (int button = 0; button < buttons.Count; button++)
|
||||
saveto[buttons[button]] = Inputs[button].Bindings;
|
||||
var saveto = saveConfigObject ?? _realConfigObject;
|
||||
for (int button = 0; button < _buttons.Count; button++)
|
||||
{
|
||||
saveto[_buttons[button]] = _inputs[button].Bindings;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Autotab = false;
|
||||
public void LoadSettings(Dictionary<string, string> configobj, bool autotab, List<string> configbuttons = null, int? width = null, int? height = null)
|
||||
{
|
||||
Autotab = autotab;
|
||||
_autotab = autotab;
|
||||
if (width.HasValue && height.HasValue)
|
||||
{
|
||||
_panelSize = new Size(width.Value, height.Value);
|
||||
|
@ -74,78 +73,82 @@ namespace BizHawk.Client.EmuHawk
|
|||
_panelSize = Size;
|
||||
}
|
||||
|
||||
RealConfigObject = configobj;
|
||||
RealConfigButtons = configbuttons;
|
||||
_realConfigObject = configobj;
|
||||
_realConfigButtons = configbuttons;
|
||||
SetButtonList();
|
||||
Startup();
|
||||
SetWidgetStrings();
|
||||
}
|
||||
|
||||
protected void SetButtonList()
|
||||
private void SetButtonList()
|
||||
{
|
||||
buttons.Clear();
|
||||
IEnumerable<string> bl = RealConfigButtons ?? (IEnumerable<string>)RealConfigObject.Keys;
|
||||
_buttons.Clear();
|
||||
IEnumerable<string> bl = _realConfigButtons ?? (IEnumerable<string>)_realConfigObject.Keys;
|
||||
foreach (string s in bl)
|
||||
buttons.Add(s);
|
||||
}
|
||||
|
||||
protected void SetWidgetStrings()
|
||||
{
|
||||
for (int button = 0; button < buttons.Count; button++)
|
||||
{
|
||||
string s;
|
||||
if (!RealConfigObject.TryGetValue(buttons[button], out s))
|
||||
s = "";
|
||||
Inputs[button].Bindings = s;
|
||||
_buttons.Add(s);
|
||||
}
|
||||
}
|
||||
|
||||
protected void Startup()
|
||||
private void SetWidgetStrings()
|
||||
{
|
||||
int x = InputMarginLeft;
|
||||
int y = MarginTop - Spacing;
|
||||
for (int i = 0; i < buttons.Count; i++)
|
||||
for (int button = 0; button < _buttons.Count; button++)
|
||||
{
|
||||
y += Spacing;
|
||||
if (y > (_panelSize.Height - UIHelper.ScaleY(62)))
|
||||
string s;
|
||||
if (!_realConfigObject.TryGetValue(_buttons[button], out s))
|
||||
{
|
||||
y = MarginTop;
|
||||
x += ColumnWidth;
|
||||
s = "";
|
||||
}
|
||||
|
||||
InputCompositeWidget iw = new InputCompositeWidget
|
||||
_inputs[button].Bindings = s;
|
||||
}
|
||||
}
|
||||
|
||||
private void Startup()
|
||||
{
|
||||
int x = _inputMarginLeft;
|
||||
int y = _marginTop - _spacing;
|
||||
for (int i = 0; i < _buttons.Count; i++)
|
||||
{
|
||||
y += _spacing;
|
||||
if (y > (_panelSize.Height - UIHelper.ScaleY(62)))
|
||||
{
|
||||
y = _marginTop;
|
||||
x += _columnWidth;
|
||||
}
|
||||
|
||||
var iw = new InputCompositeWidget
|
||||
{
|
||||
Location = new Point(x, y),
|
||||
Size = new Size(InputSize, UIHelper.ScaleY(23)),
|
||||
Size = new Size(_inputSize, UIHelper.ScaleY(23)),
|
||||
TabIndex = i,
|
||||
AutoTab = this.Autotab
|
||||
AutoTab = _autotab
|
||||
};
|
||||
|
||||
iw.SetupTooltip(Tooltip, null);
|
||||
|
||||
iw.BringToFront();
|
||||
Controls.Add(iw);
|
||||
Inputs.Add(iw);
|
||||
Label label = new Label
|
||||
{
|
||||
Location = new Point(x + InputSize + LabelPadding, y + UIHelper.ScaleY(3)),
|
||||
Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
|
||||
Text = buttons[i].Replace('_', ' ').Trim(),
|
||||
};
|
||||
_inputs.Add(iw);
|
||||
var label = new Label
|
||||
{
|
||||
Location = new Point(x + _inputSize + _labelPadding, y + UIHelper.ScaleY(3)),
|
||||
Size = new Size(UIHelper.ScaleX(100), UIHelper.ScaleY(15)),
|
||||
Text = _buttons[i].Replace('_', ' ').Trim(),
|
||||
};
|
||||
|
||||
//Tooltip.SetToolTip(label, null); //??? not supported yet
|
||||
////Tooltip.SetToolTip(label, null); //??? not supported yet
|
||||
|
||||
Controls.Add(label);
|
||||
Labels.Add(label);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAutoTab(bool value)
|
||||
{
|
||||
Inputs.ForEach(x => x.AutoTab = value);
|
||||
_inputs.ForEach(x => x.AutoTab = value);
|
||||
}
|
||||
|
||||
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
private void ClearToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ClearAll();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue