Replaced another timer

This commit is contained in:
Travis Nickles 2018-02-19 05:48:46 -06:00
parent a4abe7e98e
commit 99197be610

View File

@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms; using System.Windows.Forms;
using NonFormTimer = System.Timers.Timer;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
@ -13,7 +14,8 @@ namespace DS4Windows
public partial class RecordBox : Form public partial class RecordBox : Form
{ {
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
Timer ds4 = new Timer(); //Timer ds4 = new Timer();
NonFormTimer ds4 = new NonFormTimer();
public List<int> macros = new List<int>(), macrosAfter = new List<int>(); public List<int> macros = new List<int>(), macrosAfter = new List<int>();
public List<string> macronames = new List<string>(); public List<string> macronames = new List<string>();
SpecActions sA; SpecActions sA;
@ -38,7 +40,8 @@ namespace DS4Windows
} }
AddtoDS4List(); AddtoDS4List();
ds4.Tick += ds4_Tick; //ds4.Tick += ds4_Tick;
ds4.Elapsed += ds4_Tick;
ds4.Interval = 1; ds4.Interval = 1;
if (kbm.macrostag.Count > 0) if (kbm.macrostag.Count > 0)
{ {
@ -61,7 +64,8 @@ namespace DS4Windows
if (button > -1) if (button > -1)
sAButton = button; sAButton = button;
ds4.Tick += ds4_Tick; //ds4.Tick += ds4_Tick;
ds4.Elapsed += ds4_Tick;
ds4.Interval = 1; ds4.Interval = 1;
lbRecordTip.Visible = false; lbRecordTip.Visible = false;
cBStyle.Visible = false; cBStyle.Visible = false;
@ -122,81 +126,44 @@ namespace DS4Windows
bool[] pTP = new bool[4]; bool[] pTP = new bool[4];
void ds4_Tick(object sender, EventArgs e) //void ds4_Tick(object sender, EventArgs e)
private void ds4_Tick(object sender, System.Timers.ElapsedEventArgs e)
{ {
if (Program.rootHub.DS4Controllers[0] != null) if (Program.rootHub.DS4Controllers[0] != null)
{ {
cState = Program.rootHub.getDS4State(0); cState = Program.rootHub.getDS4State(0);
if (btnRecord.Text == Properties.Resources.StopText) this.BeginInvoke((Action)(() =>
{ {
if (cBRecordDelays.Checked) if (btnRecord.Text == Properties.Resources.StopText)
{ {
Mouse tP = Program.rootHub.touchPad[0]; if (cBRecordDelays.Checked)
if (tP.leftDown && !pTP[0])
if (!btnRumble.Text.Contains("Stop"))
btnRumble_Click(sender, e);
else if (!tP.leftDown && pTP[0])
if (btnRumble.Text.Contains("Stop"))
btnRumble_Click(sender, e);
if (tP.rightDown && !pTP[1])
if (!btnLightbar.Text.Contains("Reset"))
btnLightbar_Click(sender, e);
else if (!tP.rightDown && pTP[1])
if (btnLightbar.Text.Contains("Reset"))
btnLightbar_Click(sender, e);
pTP[0] = tP.leftDown;
pTP[1] = tP.rightDown;
}
//foreach (DS4Controls dc in dcs)
for (int controlIndex = 0, dcsLen = dcs.Count; controlIndex < dcsLen; controlIndex++)
{
DS4Controls dc = dcs[controlIndex];
if (Mapping.getBoolMapping(0, dc, cState, null, null))
{ {
int value = DS4ControltoInt(dc); Mouse tP = Program.rootHub.touchPad[0];
int count = 0; if (tP.leftDown && !pTP[0])
int macroLen = macros.Count; if (!btnRumble.Text.Contains("Stop"))
//foreach (int i in macros) btnRumble_Click(sender, e);
for (int macroIndex = 0; macroIndex < macroLen; macroIndex++) else if (!tP.leftDown && pTP[0])
{ if (btnRumble.Text.Contains("Stop"))
int i = macros[macroIndex]; btnRumble_Click(sender, e);
if (i == value) if (tP.rightDown && !pTP[1])
count++; if (!btnLightbar.Text.Contains("Reset"))
} btnLightbar_Click(sender, e);
else if (!tP.rightDown && pTP[1])
if (macroLen == 0) if (btnLightbar.Text.Contains("Reset"))
{ btnLightbar_Click(sender, e);
AddMacroValue(value); pTP[0] = tP.leftDown;
lVMacros.Items.Add(DS4ControltoX360(dc), 0); pTP[1] = tP.rightDown;
if (cBRecordDelays.Checked)
{
sw.Reset();
sw.Start();
}
}
else if (count % 2 == 0)
{
if (cBRecordDelays.Checked)
{
AddMacroValue((int)sw.ElapsedMilliseconds + 300);
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
sw.Reset();
sw.Start();
}
AddMacroValue(value);
lVMacros.Items.Add(DS4ControltoX360(dc), 0);
}
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
} }
else if (!Mapping.getBoolMapping(0, dc, cState, null, null))
//foreach (DS4Controls dc in dcs)
for (int controlIndex = 0, dcsLen = dcs.Count; controlIndex < dcsLen; controlIndex++)
{ {
int macroLen = macros.Count; DS4Controls dc = dcs[controlIndex];
if (macroLen != 0) if (Mapping.getBoolMapping(0, dc, cState, null, null))
{ {
int value = DS4ControltoInt(dc); int value = DS4ControltoInt(dc);
int count = 0; int count = 0;
int macroLen = macros.Count;
//foreach (int i in macros) //foreach (int i in macros)
for (int macroIndex = 0; macroIndex < macroLen; macroIndex++) for (int macroIndex = 0; macroIndex < macroLen; macroIndex++)
{ {
@ -205,11 +172,17 @@ namespace DS4Windows
count++; count++;
} }
/*for (int i = macros.Count - 1; i >= 0; i--) if (macroLen == 0)
if (macros.Count == 261) {
count++;*/ AddMacroValue(value);
lVMacros.Items.Add(DS4ControltoX360(dc), 0);
if (count % 2 == 1) if (cBRecordDelays.Checked)
{
sw.Reset();
sw.Start();
}
}
else if (count % 2 == 0)
{ {
if (cBRecordDelays.Checked) if (cBRecordDelays.Checked)
{ {
@ -218,15 +191,50 @@ namespace DS4Windows
sw.Reset(); sw.Reset();
sw.Start(); sw.Start();
} }
AddMacroValue(value); AddMacroValue(value);
lVMacros.Items.Add(DS4ControltoX360(dc), 1); lVMacros.Items.Add(DS4ControltoX360(dc), 0);
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible(); }
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
}
else if (!Mapping.getBoolMapping(0, dc, cState, null, null))
{
int macroLen = macros.Count;
if (macroLen != 0)
{
int value = DS4ControltoInt(dc);
int count = 0;
//foreach (int i in macros)
for (int macroIndex = 0; macroIndex < macroLen; macroIndex++)
{
int i = macros[macroIndex];
if (i == value)
count++;
}
/*for (int i = macros.Count - 1; i >= 0; i--)
if (macros.Count == 261)
count++;*/
if (count % 2 == 1)
{
if (cBRecordDelays.Checked)
{
AddMacroValue((int)sw.ElapsedMilliseconds + 300);
lVMacros.Items.Add(Properties.Resources.WaitMS.Replace("*number*", sw.ElapsedMilliseconds.ToString()).Replace("*ms*", "ms"), 2);
sw.Reset();
sw.Start();
}
AddMacroValue(value);
lVMacros.Items.Add(DS4ControltoX360(dc), 1);
lVMacros.Items[lVMacros.Items.Count - 1].EnsureVisible();
}
} }
} }
} }
} }
} }));
} }
} }