Skip to content

Commit

Permalink
Fixed settings saving random X value as Y value too.
Browse files Browse the repository at this point in the history
Fixed controls remaining disabled after click count has expired.
  • Loading branch information
ApexWeed committed Dec 20, 2015
1 parent 03fc1c4 commit e59d08a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 12 deletions.
3 changes: 3 additions & 0 deletions AutoClicker/AutoClicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public class NextClickEventArgs : EventArgs

public event EventHandler<NextClickEventArgs> NextClick;

public EventHandler<EventArgs> Finished;

private void Click()
{
//System.Diagnostics.Debug.Print("Click() started");
Expand Down Expand Up @@ -254,6 +256,7 @@ private void Click()
//System.Diagnostics.Debug.Print("Had a nap");
remaining--;
}
Finished?.Invoke(this, null);
}

public bool IsAlive
Expand Down
78 changes: 66 additions & 12 deletions AutoClicker/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void SaveSettings()
w.Write((int)numFixedX.Value);
w.Write((int)numFixedY.Value);
w.Write((int)numRandomX.Value);
w.Write((int)numRandomX.Value);
w.Write((int)numRandomY.Value);
w.Write((int)numRandomWidth.Value);
w.Write((int)numRandomHeight.Value);

Expand Down Expand Up @@ -240,6 +240,7 @@ private void Form1_Load(object sender, EventArgs e)
CountHandler(null, null);

clicker.NextClick += HandleNextClick;
clicker.Finished += HandleFinished;
}

private void HandleNextClick(object sender, AutoClicker.NextClickEventArgs e)
Expand All @@ -248,6 +249,11 @@ private void HandleNextClick(object sender, AutoClicker.NextClickEventArgs e)
countdownThread.Start();
}

private void HandleFinished(object sender, EventArgs e)
{
EnableControls();
}

private void CountDown(int Milliseconds)
{
for (int i = 0; i < Milliseconds; i += 10)
Expand Down Expand Up @@ -418,26 +424,74 @@ private void btnToggle_Click(object sender, EventArgs e)
{
if (!clicker.IsAlive)
{
grpClickType.Enabled = false;
grpLocation.Enabled = false;
grpDelay.Enabled = false;
grpCount.Enabled = false;
clicker.Start();
btnToggle.Text = "Stop";
DisableControls();
}
else
{
clicker.Stop();
countdownThread.Abort();
tslStatus.Text = "Not currently doing much helpful here to be honest";
grpClickType.Enabled = true;
grpLocation.Enabled = true;
grpDelay.Enabled = true;
grpCount.Enabled = true;
btnToggle.Text = "Start";
EnableControls();
}
}

delegate void SetEnabledCallback(Control Control, bool Enabled);
private void SetEnabled(Control Control, bool Enabled)
{
if (Control.InvokeRequired)
{
var d = new SetEnabledCallback(SetEnabled);
this.Invoke(d, new object[] { Control, Enabled });
}
else
{
Control.Enabled = Enabled;
}
}

delegate void SetButtonTextCallback(Button Control, string Text);
private void SetButtonText(Button Control, string Text)
{
if (Control.InvokeRequired)
{
var d = new SetButtonTextCallback(SetButtonText);
this.Invoke(d, new object[] { Control, Text });
}
else
{
Control.Text = Text;
}
}

private void EnableControls()
{
tslStatus.Text = "Not currently doing much helpful here to be honest";
SetEnabled(grpClickType, true);
SetEnabled(grpLocation, true);
SetEnabled(grpDelay, true);
SetEnabled(grpCount, true);
SetButtonText(btnToggle, "Start");
//grpClickType.Enabled = true;
//grpLocation.Enabled = true;
//grpDelay.Enabled = true;
//grpCount.Enabled = true;
//btnToggle.Text = "Start";
}

private void DisableControls()
{
SetEnabled(grpClickType, false);
SetEnabled(grpLocation, false);
SetEnabled(grpDelay, false);
SetEnabled(grpCount, false);
SetButtonText(btnToggle, "Stop");
//grpClickType.Enabled = false;
//grpLocation.Enabled = false;
//grpDelay.Enabled = false;
//grpCount.Enabled = false;
//btnToggle.Text = "Stop";
}

protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
Expand Down

0 comments on commit e59d08a

Please sign in to comment.