From f84065a45adc6415b0dd5d948b1b09e599dff482 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 31 May 2017 08:10:09 -0500 Subject: [PATCH] cleanup controller config user control classes --- .../config/ControllerConfig.cs | 3 +- .../AnalogBindControl.Designer.cs | 10 +- .../ControllerConfig/AnalogBindControl.cs | 64 +++++---- .../ControllerConfig/AnalogBindPanel.cs | 35 +++-- .../ControllerConfigPanel.Designer.cs | 2 +- .../ControllerConfig/ControllerConfigPanel.cs | 127 +++++++++--------- 6 files changed, 119 insertions(+), 122 deletions(-) diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig.cs index 0c78e0720e..9ac2bb2e01 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig.cs @@ -73,8 +73,7 @@ namespace BizHawk.Client.EmuHawk private Control CreateNormalPanel(Dictionary settings, List 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; } diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindControl.Designer.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindControl.Designer.cs index efb3f91f95..e385ec92aa 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindControl.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindControl.Designer.cs @@ -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 // diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindControl.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindControl.cs index adfa4f6597..19de6e3bb8 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindControl.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindControl.cs @@ -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 = ""; } } diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindPanel.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindPanel.cs index cec4756595..b00f38adc7 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindPanel.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig/AnalogBindPanel.cs @@ -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 RealConfigObject; + private readonly Dictionary _realConfigObject; - public AnalogBindPanel(Dictionary RealConfigObject, List RealConfigButtons = null) - :base() + public AnalogBindPanel(Dictionary realConfigObject, List realConfigButtons = null) { - this.RealConfigObject = RealConfigObject; - - LoadSettings(RealConfigButtons ?? (IEnumerable)RealConfigObject.Keys); + _realConfigObject = realConfigObject; + LoadSettings(realConfigButtons ?? (IEnumerable)realConfigObject.Keys); } - void LoadSettings(IEnumerable ButtonList) + private void LoadSettings(IEnumerable 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(); } /// /// save to config /// - /// if non-null, save to possibly different config object than originally initialized from - public void Save(Dictionary SaveConfigObject = null) + /// if non-null, save to possibly different config object than originally initialized from + public void Save(Dictionary saveConfigObject = null) { - var saveto = SaveConfigObject ?? RealConfigObject; + var saveto = saveConfigObject ?? _realConfigObject; foreach (Control c in Controls) { var abc = (AnalogBindControl)c; diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig/ControllerConfigPanel.Designer.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig/ControllerConfigPanel.Designer.cs index 1e38e366f2..b54256100f 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig/ControllerConfigPanel.Designer.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig/ControllerConfigPanel.Designer.cs @@ -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 // diff --git a/BizHawk.Client.EmuHawk/config/ControllerConfig/ControllerConfigPanel.cs b/BizHawk.Client.EmuHawk/config/ControllerConfig/ControllerConfigPanel.cs index 70d1a5655a..9837eddbe4 100644 --- a/BizHawk.Client.EmuHawk/config/ControllerConfig/ControllerConfigPanel.cs +++ b/BizHawk.Client.EmuHawk/config/ControllerConfig/ControllerConfigPanel.cs @@ -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 RealConfigObject; + private Dictionary _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 RealConfigButtons; + private List _realConfigButtons; - public List buttons = new List(); + private readonly List _buttons = new List(); - 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 Inputs = new List(); - protected List