refactor sticky hold/autofire logic in TAStudio

- setting multiple buttons to autofire actually works
- the config to respect lag in autofire is applied now
- can set meaningful axis hold / autofire
- removed last reference to "float autofire"
This commit is contained in:
Morilli 2024-09-27 00:10:25 +02:00
parent 6d9aa4d467
commit 15ff0ec2c7
4 changed files with 56 additions and 115 deletions

View File

@ -112,6 +112,16 @@
// ValueNum
//
this.ValueNum.Location = new System.Drawing.Point(48, 179);
this.ValueNum.Maximum = new decimal(new int[] {
10000,
0,
0,
0});
this.ValueNum.Minimum = new decimal(new int[] {
10000,
0,
0,
-2147483648});
this.ValueNum.Name = "ValueNum";
this.ValueNum.Size = new System.Drawing.Size(51, 20);
this.ValueNum.TabIndex = 5;

View File

@ -17,14 +17,13 @@ namespace BizHawk.Client.EmuHawk
private string SelectedButton => ButtonBox.Text;
private bool IsBool => SelectedButton == "Default bool Auto-Fire" || _tastudio.MovieSession.MovieController.Definition.BoolButtons.Contains(SelectedButton);
private bool IsBool => _tastudio.MovieSession.MovieController.Definition.BoolButtons.Contains(SelectedButton);
public PatternsForm(TAStudio owner)
{
InitializeComponent();
_tastudio = owner;
foreach (var button in _tastudio.MovieSession.MovieController.Definition.BoolButtons)
{
ButtonBox.Items.Add(button);
@ -34,9 +33,6 @@ namespace BizHawk.Client.EmuHawk
{
ButtonBox.Items.Add(button);
}
ButtonBox.Items.Add("Default bool Auto-Fire");
ButtonBox.Items.Add("Default float Auto-Fire");
}
private void PatternsForm_Load(object sender, EventArgs e)
@ -77,7 +73,7 @@ namespace BizHawk.Client.EmuHawk
string defaultStr = "false";
if (!IsBool)
{
defaultStr = "0";
defaultStr = _tastudio.MovieSession.MovieController.Definition.Axes[SelectedButton].Neutral.ToString();
}
_values.Insert(PatternList.SelectedIndex, defaultStr);
@ -194,10 +190,6 @@ namespace BizHawk.Client.EmuHawk
if (PatternList.SelectedIndex != -1 && PatternList.SelectedIndex < _values.Count)
{
index = _tastudio.MovieSession.MovieController.Definition.BoolButtons.IndexOf(SelectedButton);
if (SelectedButton == "Default bool Auto-Fire")
{
index = _tastudio.BoolPatterns.Length - 1;
}
if (index != -1)
{
@ -207,14 +199,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
if (SelectedButton == "Default float Auto-Fire")
{
index = _tastudio.AxisPatterns.Length - 1;
}
else
{
index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton);
}
index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton);
LagBox.Checked = _tastudio.AxisPatterns[index].SkipsLag;
ValueNum.Value = int.Parse(_values[PatternList.SelectedIndex]);
@ -233,10 +218,6 @@ namespace BizHawk.Client.EmuHawk
private void UpdatePattern()
{
int index = _tastudio.MovieSession.MovieController.Definition.BoolButtons.IndexOf(SelectedButton);
if (SelectedButton == "Default bool Auto-Fire")
{
index = _tastudio.BoolPatterns.Length - 1;
}
if (index != -1)
{
@ -253,14 +234,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
if (SelectedButton == "Default float Auto-Fire")
{
index = _tastudio.AxisPatterns.Length - 1;
}
else
{
index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton);
}
index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton);
var p = new List<int>();
for (int i = 0; i < _counts.Count; i++)
@ -274,21 +248,13 @@ namespace BizHawk.Client.EmuHawk
_tastudio.AxisPatterns[index] = new AutoPatternAxis(p.ToArray(), LagBox.Checked, 0, _loopAt);
}
if ((SelectedButton != "Default float Auto-Fire") && (SelectedButton != "Default bool Auto-Fire"))
{
_tastudio.UpdateAutoFire(SelectedButton, null);
}
_tastudio.UpdateAutoFire(SelectedButton, null);
}
private void GetPattern()
{
int index = _tastudio.MovieSession.MovieController.Definition.BoolButtons.IndexOf(SelectedButton);
if (SelectedButton == "Default bool Auto-Fire")
{
index = _tastudio.BoolPatterns.Length - 1;
}
if (index != -1)
{
bool[] p = _tastudio.BoolPatterns[index].Pattern;
@ -315,14 +281,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
if (SelectedButton == "Default float Auto-Fire")
{
index = _tastudio.AxisPatterns.Length - 1;
}
else
{
index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton);
}
index = _tastudio.MovieSession.MovieController.Definition.Axes.IndexOf(SelectedButton);
var p = _tastudio.AxisPatterns[index].Pattern;
var lastValue = p[0];

View File

@ -439,64 +439,51 @@ namespace BizHawk.Client.EmuHawk
public void UpdateAutoFire(string button, bool? isOn)
{
if (!isOn.HasValue) // No value means don't change whether it's on or off.
{
isOn = TasView.AllColumns.Find(c => c.Name == button).Emphasis;
}
// No value means don't change whether it's on or off.
isOn ??= TasView.AllColumns.Find(c => c.Name == button).Emphasis;
int index = 0;
if (autoHoldToolStripMenuItem.Checked)
{
index = 1;
}
if (autoFireToolStripMenuItem.Checked)
{
index = 2;
}
// use custom pattern if set
bool useCustom = customPatternToolStripMenuItem.Checked;
// else, set autohold or fire based on setting
bool autoHold = autoHoldToolStripMenuItem.Checked; // !autoFireToolStripMenuItem.Checked
if (ControllerType.BoolButtons.Contains(button))
{
if (index == 0)
InputManager.StickyHoldController.SetButtonHold(button, false);
InputManager.StickyAutofireController.SetButtonAutofire(button, false);
if (!isOn.Value) return;
if (useCustom)
{
index = ControllerType.BoolButtons.IndexOf(button);
InputManager.StickyAutofireController.SetButtonAutofire(button, true, BoolPatterns[ControllerType.BoolButtons.IndexOf(button)]);
}
else if (autoHold)
{
InputManager.StickyHoldController.SetButtonHold(button, true);
}
else
{
index += ControllerType.BoolButtons.Count - 1;
}
// Fixes auto-loading, but why is this code like this? The code above suggests we have a BoolPattern for every bool button? But we don't
// This is a sign of a deeper problem, but this fixes some basic functionality at least
if (index < BoolPatterns.Length)
{
AutoPatternBool p = BoolPatterns[index];
InputManager.StickyAutofireController.SetButtonAutofire(button, isOn.Value, p);
InputManager.StickyAutofireController.SetButtonAutofire(button, true);
}
}
else
{
if (index == 0)
InputManager.StickyHoldController.SetAxisHold(button, null);
InputManager.StickyAutofireController.SetAxisAutofire(button, null);
if (!isOn.Value) return;
int holdValue = ControllerType.Axes[button].Range.EndInclusive; // it's not clear what value to use for auto-hold, just use max i guess
if (useCustom)
{
index = ControllerType.Axes.IndexOf(button);
InputManager.StickyAutofireController.SetAxisAutofire(button, holdValue, AxisPatterns[ControllerType.Axes.IndexOf(button)]);
}
else if (autoHold)
{
InputManager.StickyHoldController.SetAxisHold(button, holdValue);
}
else
{
index += ControllerType.Axes.Count - 1;
}
int? value = null;
if (isOn.Value)
{
value = 0;
}
// Fixes auto-loading, but why is this code like this? The code above suggests we have a AxisPattern for every axis button? But we don't
// This is a sign of a deeper problem, but this fixes some basic functionality at least
if (index < AxisPatterns.Length)
{
AutoPatternAxis p = AxisPatterns[index];
InputManager.StickyAutofireController.SetAxisAutofire(button, value, p);
InputManager.StickyAutofireController.SetAxisAutofire(button, holdValue);
}
}
}

View File

@ -398,39 +398,24 @@ namespace BizHawk.Client.EmuHawk
TasView.AllColumns.ColumnsChanged();
}
private void SetupBoolPatterns()
private void SetupCustomPatterns()
{
// Patterns
int bStart = 0;
int fStart = 0;
if (BoolPatterns == null)
{
BoolPatterns = new AutoPatternBool[ControllerType.BoolButtons.Count + 2];
AxisPatterns = new AutoPatternAxis[ControllerType.Axes.Count + 2];
}
else
{
bStart = BoolPatterns.Length - 2;
fStart = AxisPatterns.Length - 2;
Array.Resize(ref BoolPatterns, ControllerType.BoolButtons.Count + 2);
Array.Resize(ref AxisPatterns, ControllerType.Axes.Count + 2);
}
// custom autofire patterns to allow configuring a unique pattern for each button or axis
BoolPatterns = new AutoPatternBool[ControllerType.BoolButtons.Count];
AxisPatterns = new AutoPatternAxis[ControllerType.Axes.Count];
for (int i = bStart; i < BoolPatterns.Length - 2; i++)
for (int i = 0; i < BoolPatterns.Length; i++)
{
// standard 1 on 1 off autofire pattern
BoolPatterns[i] = new AutoPatternBool(1, 1);
}
BoolPatterns[BoolPatterns.Length - 2] = new(1, 0);
BoolPatterns[BoolPatterns.Length - 1] = new(Config.AutofireOn, Config.AutofireOff);
for (int i = fStart; i < AxisPatterns.Length - 2; i++)
for (int i = 0; i < AxisPatterns.Length; i++)
{
AxisPatterns[i] = new AutoPatternAxis(new[] { 1 });
// autohold pattern with the maximum axis range as hold value (bit arbitrary)
var axisSpec = ControllerType.Axes[ControllerType.Axes[i]];
AxisPatterns[i] = new AutoPatternAxis([ axisSpec.Range.EndInclusive ]);
}
AxisPatterns[AxisPatterns.Length - 2] = new([ 1 ]);
AxisPatterns[AxisPatterns.Length - 1] = new(1, Config.AutofireOn, 0, Config.AutofireOff);
}
/// <remarks>for Lua</remarks>
@ -572,7 +557,7 @@ namespace BizHawk.Client.EmuHawk
SetUpColumns();
}
SetUpToolStripColumns();
SetupBoolPatterns();
SetupCustomPatterns();
UpdateAutoFire();
}