2015-03-08 04:42:04 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using BizHawk.Client.Common;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
|
|
|
|
{
|
|
|
|
|
public partial class PatternsForm : Form
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
private readonly TAStudio _tastudio;
|
|
|
|
|
|
|
|
|
|
private readonly List<int> _counts = new List<int>();
|
|
|
|
|
private readonly List<string> _values = new List<string>();
|
|
|
|
|
private int _loopAt;
|
|
|
|
|
private bool _updating;
|
|
|
|
|
|
|
|
|
|
private string SelectedButton => ButtonBox.Text;
|
|
|
|
|
|
|
|
|
|
private bool IsBool => SelectedButton == "Default bool Auto-Fire" || Global.MovieSession.MovieControllerAdapter.Definition.BoolButtons.Contains(SelectedButton);
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
|
|
|
|
public PatternsForm(TAStudio owner)
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_tastudio = owner;
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
2016-12-12 18:30:32 +00:00
|
|
|
|
foreach (var button in Global.MovieSession.MovieControllerAdapter.Definition.BoolButtons)
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
ButtonBox.Items.Add(button);
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 18:30:32 +00:00
|
|
|
|
foreach (var button in Global.MovieSession.MovieControllerAdapter.Definition.FloatControls)
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
ButtonBox.Items.Add(button);
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
ButtonBox.Items.Add("Default bool Auto-Fire");
|
|
|
|
|
ButtonBox.Items.Add("Default float Auto-Fire");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PatternsForm_Load(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ButtonBox.SelectedIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ButtonBox_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
GetPattern();
|
|
|
|
|
UpdateDisplay();
|
|
|
|
|
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (IsBool)
|
2015-03-08 04:42:04 +00:00
|
|
|
|
{
|
|
|
|
|
OnOffBox.Visible = true;
|
|
|
|
|
ValueNum.Visible = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ValueNum.Visible = true;
|
|
|
|
|
OnOffBox.Visible = false;
|
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
|
|
|
|
|
CountNum.Value = _counts[0];
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PatternList_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!_updating)
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
UpdateDisplay();
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InsertButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_counts.Insert(PatternList.SelectedIndex, 1);
|
2015-03-08 04:42:04 +00:00
|
|
|
|
string defaultStr = "false";
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (!IsBool)
|
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
defaultStr = "0";
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_values.Insert(PatternList.SelectedIndex, defaultStr);
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
|
|
|
|
UpdatePattern();
|
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DeleteButton_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_counts.RemoveAt(PatternList.SelectedIndex);
|
|
|
|
|
_values.RemoveAt(PatternList.SelectedIndex);
|
2015-03-08 04:42:04 +00:00
|
|
|
|
UpdatePattern();
|
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LagBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdatePattern();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ValueNum_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (_updating || PatternList.SelectedIndex == -1 || PatternList.SelectedIndex >= _counts.Count)
|
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
return;
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_values[PatternList.SelectedIndex] = ValueNum.Value.ToString();
|
2015-03-08 04:42:04 +00:00
|
|
|
|
UpdatePattern();
|
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
private void OnOffBox_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (_updating || PatternList.SelectedIndex == -1 || PatternList.SelectedIndex >= _counts.Count)
|
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
return;
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_values[PatternList.SelectedIndex] = OnOffBox.Checked.ToString();
|
2015-03-08 04:42:04 +00:00
|
|
|
|
UpdatePattern();
|
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
private void CountNum_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (_updating || PatternList.SelectedIndex == -1 || PatternList.SelectedIndex > _counts.Count)
|
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
return;
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (PatternList.SelectedIndex == _counts.Count)
|
|
|
|
|
{
|
|
|
|
|
_loopAt = (int)CountNum.Value;
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
else
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
|
|
|
|
_counts[PatternList.SelectedIndex] = (int)CountNum.Value;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
UpdatePattern();
|
|
|
|
|
UpdateDisplay();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateDisplay()
|
|
|
|
|
{
|
|
|
|
|
_updating = true;
|
|
|
|
|
PatternList.SuspendLayout();
|
|
|
|
|
|
|
|
|
|
int oldIndex = PatternList.SelectedIndex;
|
|
|
|
|
if (oldIndex == -1)
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
oldIndex = 0;
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
|
|
|
|
PatternList.Items.Clear();
|
|
|
|
|
int index = 0;
|
2017-05-24 15:49:35 +00:00
|
|
|
|
for (int i = 0; i < _counts.Count; i++)
|
2015-03-08 04:42:04 +00:00
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
string str = index + ": ";
|
|
|
|
|
if (IsBool)
|
|
|
|
|
{
|
|
|
|
|
str += _values[i][0] == 'T' ? "On" : "Off";
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
else
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
|
|
|
|
str += _values[i];
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
2017-05-24 15:49:35 +00:00
|
|
|
|
PatternList.Items.Add(str + ("\t(x" + _counts[i] + ")"));
|
|
|
|
|
index += _counts[i];
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
|
|
|
|
|
PatternList.Items.Add("Loop to: " + _loopAt);
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
|
|
|
|
if (oldIndex >= PatternList.Items.Count)
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
2015-03-08 04:42:04 +00:00
|
|
|
|
oldIndex = PatternList.Items.Count - 1;
|
2017-05-24 15:49:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
PatternList.SelectedIndex = oldIndex;
|
|
|
|
|
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (PatternList.SelectedIndex != -1 && PatternList.SelectedIndex < _values.Count)
|
2015-03-08 04:42:04 +00:00
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
index = Global.MovieSession.MovieControllerAdapter.Definition.BoolButtons.IndexOf(SelectedButton);
|
|
|
|
|
if (SelectedButton == "Default bool Auto-Fire")
|
|
|
|
|
{
|
|
|
|
|
index = _tastudio.BoolPatterns.Length + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
LagBox.Checked = _tastudio.BoolPatterns[index].SkipsLag;
|
|
|
|
|
OnOffBox.Checked = _values[PatternList.SelectedIndex][0] == 'T';
|
|
|
|
|
CountNum.Value = _counts[PatternList.SelectedIndex];
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (SelectedButton == "Default float Auto-Fire")
|
|
|
|
|
{
|
|
|
|
|
index = _tastudio.FloatPatterns.Length + 1;
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
else
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
|
|
|
|
index = Global.MovieSession.MovieControllerAdapter.Definition.FloatControls.IndexOf(SelectedButton);
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
2017-05-24 15:49:35 +00:00
|
|
|
|
LagBox.Checked = _tastudio.FloatPatterns[index].SkipsLag;
|
|
|
|
|
ValueNum.Value = Convert.ToDecimal(_values[PatternList.SelectedIndex]);
|
|
|
|
|
CountNum.Value = _counts[PatternList.SelectedIndex];
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
else if (PatternList.SelectedIndex == _values.Count)
|
|
|
|
|
{
|
|
|
|
|
CountNum.Value = _loopAt;
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
|
|
|
|
|
PatternList.ResumeLayout();
|
|
|
|
|
_updating = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdatePattern()
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
int index = Global.MovieSession.MovieControllerAdapter.Definition.BoolButtons.IndexOf(SelectedButton);
|
|
|
|
|
if (SelectedButton == "Default bool Auto-Fire")
|
|
|
|
|
{
|
|
|
|
|
index = _tastudio.BoolPatterns.Length + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
|
|
|
|
List<bool> p = new List<bool>();
|
2017-05-24 15:49:35 +00:00
|
|
|
|
for (int i = 0; i < _counts.Count; i++)
|
2015-03-08 04:42:04 +00:00
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
for (int c = 0; c < _counts[i]; c++)
|
|
|
|
|
{
|
|
|
|
|
p.Add(Convert.ToBoolean(_values[i]));
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
|
|
|
|
|
_tastudio.BoolPatterns[index] = new AutoPatternBool(p.ToArray(), LagBox.Checked, 0, _loopAt);
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (SelectedButton == "Default float Auto-Fire")
|
|
|
|
|
{
|
|
|
|
|
index = _tastudio.FloatPatterns.Length + 1;
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
else
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
|
|
|
|
index = Global.MovieSession.MovieControllerAdapter.Definition.FloatControls.IndexOf(SelectedButton);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
List<float> p = new List<float>();
|
2017-05-24 15:49:35 +00:00
|
|
|
|
for (int i = 0; i < _counts.Count; i++)
|
2015-03-08 04:42:04 +00:00
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
for (int c = 0; c < _counts[i]; c++)
|
|
|
|
|
{
|
|
|
|
|
p.Add(Convert.ToSingle(_values[i]));
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
|
|
|
|
|
_tastudio.FloatPatterns[index] = new AutoPatternFloat(p.ToArray(), LagBox.Checked, 0, _loopAt);
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_tastudio.UpdateAutoFire(SelectedButton, null);
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetPattern()
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
int index = Global.MovieSession.MovieControllerAdapter.Definition.BoolButtons.IndexOf(SelectedButton);
|
|
|
|
|
if (SelectedButton == "Default bool Auto-Fire")
|
|
|
|
|
{
|
|
|
|
|
index = _tastudio.BoolPatterns.Length + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-08 04:42:04 +00:00
|
|
|
|
if (index != -1)
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
bool[] p = _tastudio.BoolPatterns[index].Pattern;
|
2015-03-08 04:42:04 +00:00
|
|
|
|
bool lastValue = p[0];
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_counts.Clear();
|
|
|
|
|
_values.Clear();
|
|
|
|
|
_counts.Add(1);
|
|
|
|
|
_values.Add(lastValue.ToString());
|
2015-03-08 04:42:04 +00:00
|
|
|
|
for (int i = 1; i < p.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (p[i] == lastValue)
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
|
|
|
|
_counts[_counts.Count - 1]++;
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_counts.Add(1);
|
|
|
|
|
_values.Add(p[i].ToString());
|
2015-03-08 04:42:04 +00:00
|
|
|
|
lastValue = p[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
|
|
|
|
|
_loopAt = _tastudio.BoolPatterns[index].Loop;
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
if (SelectedButton == "Default float Auto-Fire")
|
|
|
|
|
{
|
|
|
|
|
index = _tastudio.FloatPatterns.Length + 1;
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
else
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
|
|
|
|
index = Global.MovieSession.MovieControllerAdapter.Definition.FloatControls.IndexOf(SelectedButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float[] p = _tastudio.FloatPatterns[index].Pattern;
|
2015-03-08 04:42:04 +00:00
|
|
|
|
float lastValue = p[0];
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_counts.Clear();
|
|
|
|
|
_values.Clear();
|
|
|
|
|
_counts.Add(1);
|
|
|
|
|
_values.Add(lastValue.ToString());
|
2015-03-08 04:42:04 +00:00
|
|
|
|
for (int i = 1; i < p.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
if (p[i] == lastValue)
|
2017-05-24 15:49:35 +00:00
|
|
|
|
{
|
|
|
|
|
_counts[_counts.Count - 1]++;
|
|
|
|
|
}
|
2015-03-08 04:42:04 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
2017-05-24 15:49:35 +00:00
|
|
|
|
_counts.Add(1);
|
|
|
|
|
_values.Add(p[i].ToString());
|
2015-03-08 04:42:04 +00:00
|
|
|
|
lastValue = p[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-24 15:49:35 +00:00
|
|
|
|
|
|
|
|
|
_loopAt = _tastudio.FloatPatterns[index].Loop;
|
2015-03-08 04:42:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|