controller config - simplify allow L+R to just a checkbox, where off = "forbid" option, since nobody cares about priority vs forbid, simplify ULDRController and don't use globals

This commit is contained in:
adelikat 2020-06-06 09:52:29 -05:00
parent e8b84b466b
commit bd1c3cb991
5 changed files with 43 additions and 179 deletions

View File

@ -77,7 +77,6 @@ namespace BizHawk.Client.Common
public bool HandleAlternateKeyboardLayouts { get; set; } public bool HandleAlternateKeyboardLayouts { get; set; }
public bool SingleInstanceMode { get; set; } public bool SingleInstanceMode { get; set; }
public bool AllowUdlr { get; set; } public bool AllowUdlr { get; set; }
public bool ForbidUdlr { get; set; }
public bool ShowContextMenu { get; set; } = true; public bool ShowContextMenu { get; set; } = true;
public bool HotkeyConfigAutoTab { get; set; } = true; public bool HotkeyConfigAutoTab { get; set; } = true;
public bool InputConfigAutoTab { get; set; } = true; public bool InputConfigAutoTab { get; set; } = true;

View File

@ -57,6 +57,7 @@ namespace BizHawk.Client.Common
ControllerInputCoalescer.Definition = ActiveController.Definition; ControllerInputCoalescer.Definition = ActiveController.Definition;
UdLRControllerAdapter.Source = ActiveController.Or(AutoFireController); UdLRControllerAdapter.Source = ActiveController.Or(AutoFireController);
UdLRControllerAdapter.AllowUdlr = Global.Config.AllowUdlr;
StickyXorAdapter.Source = UdLRControllerAdapter; StickyXorAdapter.Source = UdLRControllerAdapter;
AutofireStickyXorAdapter.Source = StickyXorAdapter; AutofireStickyXorAdapter.Source = StickyXorAdapter;

View File

@ -1,6 +1,4 @@
using System.Collections.Generic; using BizHawk.Common.StringExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -11,137 +9,52 @@ namespace BizHawk.Client.Common
/// </summary> /// </summary>
public class UdlrControllerAdapter : IController public class UdlrControllerAdapter : IController
{ {
private readonly HashSet<string> _unpresses = new HashSet<string>();
public IController Source { get; set; } public IController Source { get; set; }
public ControllerDefinition Definition => Source.Definition; public ControllerDefinition Definition => Source.Definition;
public bool AllowUdlr { get; set; }
public bool IsPressed(string button) public bool IsPressed(string button)
{ {
if (Global.Config.AllowUdlr) if (AllowUdlr)
{ {
return Source.IsPressed(button); return Source.IsPressed(button);
} }
string prefix;
// " C " is for N64 "P1 C Up" and the like, which should not be subject to mutexing // " C " is for N64 "P1 C Up" and the like, which should not be subject to mutexing
// regarding the unpressing and UDLR logic...... don't think about it. don't question it. don't look at it. // regarding the unpressing and UDLR logic...... don't think about it. don't question it. don't look at it.
if (button.Contains("Down") && !button.Contains(" C ")) if (button.Contains(" C "))
{ {
if (!Source.IsPressed(button)) return Source.IsPressed(button);
{ }
_unpresses.Remove(button);
}
prefix = button.SubstringBeforeOrNull("Down"); if (button.Contains("Down"))
{
var prefix = button.SubstringBeforeOrNull("Down");
string other = $"{prefix}Up"; string other = $"{prefix}Up";
if (Source.IsPressed(other)) return Source.IsPressed(button) && !Source.IsPressed(other);
{
if (_unpresses.Contains(button))
{
return false;
}
if (Global.Config.ForbidUdlr)
{
return false;
}
_unpresses.Add(other);
}
else
{
_unpresses.Remove(button);
}
} }
if (button.Contains("Up") && !button.Contains(" C ")) if (button.Contains("Up"))
{ {
if (!Source.IsPressed(button)) var prefix = button.SubstringBeforeOrNull("Up");
{
_unpresses.Remove(button);
}
prefix = button.SubstringBeforeOrNull("Up");
string other = $"{prefix}Down"; string other = $"{prefix}Down";
if (Source.IsPressed(other)) return Source.IsPressed(button) && !Source.IsPressed(other);
{
if (_unpresses.Contains(button))
{
return false;
}
if (Global.Config.ForbidUdlr)
{
return false;
}
_unpresses.Add(other);
}
else
{
_unpresses.Remove(button);
}
} }
if (button.Contains("Right") && !button.Contains(" C ")) if (button.Contains("Right"))
{ {
if (!Source.IsPressed(button)) var prefix = button.SubstringBeforeOrNull("Right");
{
_unpresses.Remove(button);
}
prefix = button.SubstringBeforeOrNull("Right");
string other = $"{prefix}Left"; string other = $"{prefix}Left";
if (Source.IsPressed(other)) return Source.IsPressed(button) && !Source.IsPressed(other);
{
if (_unpresses.Contains(button))
{
return false;
}
if (Global.Config.ForbidUdlr)
{
return false;
}
_unpresses.Add(other);
}
else
{
_unpresses.Remove(button);
}
} }
if (button.Contains("Left") && !button.Contains(" C ")) if (button.Contains("Left"))
{ {
if (!Source.IsPressed(button)) var prefix = button.SubstringBeforeOrNull("Left");
{
_unpresses.Remove(button);
}
prefix = button.SubstringBeforeOrNull("Left");
string other = $"{prefix}Right"; string other = $"{prefix}Right";
if (Source.IsPressed(other)) return Source.IsPressed(button) && !Source.IsPressed(other);
{
if (_unpresses.Contains(button))
{
return false;
}
if (Global.Config.ForbidUdlr)
{
return false;
}
_unpresses.Add(other);
}
else
{
_unpresses.Remove(button);
}
} }
return Source.IsPressed(button); return Source.IsPressed(button);

View File

@ -46,11 +46,8 @@
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.label38 = new System.Windows.Forms.Label(); this.label38 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.rbUDLRForbid = new System.Windows.Forms.RadioButton();
this.rbUDLRPriority = new System.Windows.Forms.RadioButton();
this.rbUDLRAllow = new System.Windows.Forms.RadioButton();
this.btnMisc = new BizHawk.Client.EmuHawk.MenuButton(); this.btnMisc = new BizHawk.Client.EmuHawk.MenuButton();
this.AllowUdCheckbox = new System.Windows.Forms.CheckBox();
this.tabControl1.SuspendLayout(); this.tabControl1.SuspendLayout();
this.tableLayoutPanel1.SuspendLayout(); this.tableLayoutPanel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
@ -168,26 +165,26 @@
this.loadDefaultsToolStripMenuItem, this.loadDefaultsToolStripMenuItem,
this.clearToolStripMenuItem}); this.clearToolStripMenuItem});
this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(142, 70); this.contextMenuStrip1.Size = new System.Drawing.Size(147, 70);
// //
// testToolStripMenuItem // testToolStripMenuItem
// //
this.testToolStripMenuItem.Name = "testToolStripMenuItem"; this.testToolStripMenuItem.Name = "testToolStripMenuItem";
this.testToolStripMenuItem.Size = new System.Drawing.Size(141, 22); this.testToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.testToolStripMenuItem.Text = "Save Defaults"; this.testToolStripMenuItem.Text = "Save Defaults";
this.testToolStripMenuItem.Click += new System.EventHandler(this.ButtonSaveDefaults_Click); this.testToolStripMenuItem.Click += new System.EventHandler(this.ButtonSaveDefaults_Click);
// //
// loadDefaultsToolStripMenuItem // loadDefaultsToolStripMenuItem
// //
this.loadDefaultsToolStripMenuItem.Name = "loadDefaultsToolStripMenuItem"; this.loadDefaultsToolStripMenuItem.Name = "loadDefaultsToolStripMenuItem";
this.loadDefaultsToolStripMenuItem.Size = new System.Drawing.Size(141, 22); this.loadDefaultsToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.loadDefaultsToolStripMenuItem.Text = "Load Defaults"; this.loadDefaultsToolStripMenuItem.Text = "Load Defaults";
this.loadDefaultsToolStripMenuItem.Click += new System.EventHandler(this.ButtonLoadDefaults_Click); this.loadDefaultsToolStripMenuItem.Click += new System.EventHandler(this.ButtonLoadDefaults_Click);
// //
// clearToolStripMenuItem // clearToolStripMenuItem
// //
this.clearToolStripMenuItem.Name = "clearToolStripMenuItem"; this.clearToolStripMenuItem.Name = "clearToolStripMenuItem";
this.clearToolStripMenuItem.Size = new System.Drawing.Size(141, 22); this.clearToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
this.clearToolStripMenuItem.Text = "Clear"; this.clearToolStripMenuItem.Text = "Clear";
this.clearToolStripMenuItem.Click += new System.EventHandler(this.ClearBtn_Click); this.clearToolStripMenuItem.Click += new System.EventHandler(this.ClearBtn_Click);
// //
@ -221,52 +218,6 @@
this.label38.TabIndex = 110; this.label38.TabIndex = 110;
this.label38.Text = "* Escape clears a key mapping"; this.label38.Text = "* Escape clears a key mapping";
// //
// label1
//
this.label1.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(442, 550);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(57, 13);
this.label1.TabIndex = 113;
this.label1.Text = "U+D/L+R:";
//
// rbUDLRForbid
//
this.rbUDLRForbid.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.rbUDLRForbid.AutoSize = true;
this.rbUDLRForbid.Location = new System.Drawing.Point(559, 548);
this.rbUDLRForbid.Name = "rbUDLRForbid";
this.rbUDLRForbid.Size = new System.Drawing.Size(54, 17);
this.rbUDLRForbid.TabIndex = 114;
this.rbUDLRForbid.TabStop = true;
this.rbUDLRForbid.Text = "Forbid";
this.rbUDLRForbid.UseVisualStyleBackColor = true;
//
// rbUDLRPriority
//
this.rbUDLRPriority.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.rbUDLRPriority.AutoSize = true;
this.rbUDLRPriority.Location = new System.Drawing.Point(622, 548);
this.rbUDLRPriority.Name = "rbUDLRPriority";
this.rbUDLRPriority.Size = new System.Drawing.Size(56, 17);
this.rbUDLRPriority.TabIndex = 115;
this.rbUDLRPriority.TabStop = true;
this.rbUDLRPriority.Text = "Priority";
this.rbUDLRPriority.UseVisualStyleBackColor = true;
//
// rbUDLRAllow
//
this.rbUDLRAllow.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.rbUDLRAllow.AutoSize = true;
this.rbUDLRAllow.Location = new System.Drawing.Point(503, 548);
this.rbUDLRAllow.Name = "rbUDLRAllow";
this.rbUDLRAllow.Size = new System.Drawing.Size(50, 17);
this.rbUDLRAllow.TabIndex = 116;
this.rbUDLRAllow.TabStop = true;
this.rbUDLRAllow.Text = "Allow";
this.rbUDLRAllow.UseVisualStyleBackColor = true;
//
// btnMisc // btnMisc
// //
this.btnMisc.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnMisc.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -278,6 +229,17 @@
this.btnMisc.Text = "Misc..."; this.btnMisc.Text = "Misc...";
this.btnMisc.UseVisualStyleBackColor = true; this.btnMisc.UseVisualStyleBackColor = true;
// //
// AllowUdCheckbox
//
this.AllowUdCheckbox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.AllowUdCheckbox.AutoSize = true;
this.AllowUdCheckbox.Location = new System.Drawing.Point(576, 548);
this.AllowUdCheckbox.Name = "AllowUdCheckbox";
this.AllowUdCheckbox.Size = new System.Drawing.Size(101, 17);
this.AllowUdCheckbox.TabIndex = 114;
this.AllowUdCheckbox.Text = "Allow U+D/L+R";
this.AllowUdCheckbox.UseVisualStyleBackColor = true;
//
// ControllerConfig // ControllerConfig
// //
this.AcceptButton = this.buttonOK; this.AcceptButton = this.buttonOK;
@ -285,10 +247,7 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.buttonCancel; this.CancelButton = this.buttonCancel;
this.ClientSize = new System.Drawing.Size(932, 572); this.ClientSize = new System.Drawing.Size(932, 572);
this.Controls.Add(this.rbUDLRAllow); this.Controls.Add(this.AllowUdCheckbox);
this.Controls.Add(this.rbUDLRPriority);
this.Controls.Add(this.rbUDLRForbid);
this.Controls.Add(this.label1);
this.Controls.Add(this.label3); this.Controls.Add(this.label3);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.label38); this.Controls.Add(this.label38);
@ -297,7 +256,6 @@
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK); this.Controls.Add(this.buttonOK);
this.Controls.Add(this.checkBoxAutoTab); this.Controls.Add(this.checkBoxAutoTab);
this.Icon = global::BizHawk.Client.EmuHawk.Properties.Resources.GameController_MultiSize;
this.Name = "ControllerConfig"; this.Name = "ControllerConfig";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Controller Config"; this.Text = "Controller Config";
@ -332,9 +290,6 @@
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label38; private System.Windows.Forms.Label label38;
private System.Windows.Forms.Label label1; private System.Windows.Forms.CheckBox AllowUdCheckbox;
private System.Windows.Forms.RadioButton rbUDLRForbid;
private System.Windows.Forms.RadioButton rbUDLRPriority;
private System.Windows.Forms.RadioButton rbUDLRAllow;
} }
} }

View File

@ -3,18 +3,16 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using System.Text.RegularExpressions;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class ControllerConfig : Form public partial class ControllerConfig : Form
{ {
private const int MaxPlayers = 12;
private static readonly Dictionary<string, Lazy<Bitmap>> ControllerImages = new Dictionary<string, Lazy<Bitmap>>(); private static readonly Dictionary<string, Lazy<Bitmap>> ControllerImages = new Dictionary<string, Lazy<Bitmap>>();
private readonly IEmulator _emulator; private readonly IEmulator _emulator;
private readonly Config _config; private readonly Config _config;
@ -67,6 +65,7 @@ namespace BizHawk.Client.EmuHawk
private void ControllerConfig_Load(object sender, EventArgs e) private void ControllerConfig_Load(object sender, EventArgs e)
{ {
Icon = Properties.Resources.GameController_MultiSize;
Text = $"{_emulator.ControllerDefinition.Name} Configuration"; Text = $"{_emulator.ControllerDefinition.Name} Configuration";
} }
@ -180,9 +179,7 @@ namespace BizHawk.Client.EmuHawk
SuspendLayout(); SuspendLayout();
LoadPanels(_config); LoadPanels(_config);
rbUDLRAllow.Checked = _config.AllowUdlr; AllowUdCheckbox.Checked = _config.AllowUdlr;
rbUDLRForbid.Checked = _config.ForbidUdlr;
rbUDLRPriority.Checked = !_config.AllowUdlr && !_config.ForbidUdlr;
checkBoxAutoTab.Checked = _config.InputConfigAutoTab; checkBoxAutoTab.Checked = _config.InputConfigAutoTab;
SetControllerPicture(_emulator.ControllerDefinition.Name); SetControllerPicture(_emulator.ControllerDefinition.Name);
@ -327,8 +324,7 @@ namespace BizHawk.Client.EmuHawk
private void ButtonOk_Click(object sender, EventArgs e) private void ButtonOk_Click(object sender, EventArgs e)
{ {
_config.AllowUdlr = rbUDLRAllow.Checked; _config.AllowUdlr = AllowUdCheckbox.Checked;
_config.ForbidUdlr = rbUDLRForbid.Checked;
_config.InputConfigAutoTab = checkBoxAutoTab.Checked; _config.InputConfigAutoTab = checkBoxAutoTab.Checked;
Save(); Save();