From 37d30d60b3e05116163aa46a2eda1b4e158ba8d9 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Sun, 28 May 2017 19:59:09 +0200 Subject: [PATCH] Pause Function Added. --- src/mrbesen/cr/auto/clicker/Clicker.java | 13 +++++++++++++ src/mrbesen/cr/auto/clicker/UI.java | 12 +++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/mrbesen/cr/auto/clicker/Clicker.java b/src/mrbesen/cr/auto/clicker/Clicker.java index dc24f53..2094579 100644 --- a/src/mrbesen/cr/auto/clicker/Clicker.java +++ b/src/mrbesen/cr/auto/clicker/Clicker.java @@ -31,6 +31,7 @@ public class Clicker implements Runnable{ private boolean doubleplayout = true; private int truppenwait = 180; private int randomness = 15; + private boolean paused = false; private int mincolordistance = 35; @@ -39,6 +40,9 @@ public class Clicker implements Runnable{ return; try { Thread.sleep(ms); + while(paused) { + Thread.sleep(75); + } } catch (InterruptedException e) {//when skip is applyed ; } @@ -319,4 +323,13 @@ public class Clicker implements Runnable{ mincolordistance = minimumdistance; System.out.println(colornum + ": "+c.getRed() + " " + c.getGreen() + " " + c.getBlue()); } + + + public boolean isPaused() { + return paused; + } + + public void setPause(boolean b) { + paused = b; + } } \ No newline at end of file diff --git a/src/mrbesen/cr/auto/clicker/UI.java b/src/mrbesen/cr/auto/clicker/UI.java index 5e0d7d2..7be9c0d 100644 --- a/src/mrbesen/cr/auto/clicker/UI.java +++ b/src/mrbesen/cr/auto/clicker/UI.java @@ -53,8 +53,9 @@ public class UI implements ActionListener { new PosColSelector(this, "Arena View", false, 7,1) }; - private JButton skip = new JButton("SKIP"); // the button, to skip waiting private JButton start = new JButton("START"); + private JButton skip = new JButton("SKIP"); // the button, to skip waiting + private JButton pause = new JButton("Pause"); private JButton exit = new JButton("EXIT"); private JLabel info = new JLabel("Define positions, to start."); @@ -161,6 +162,15 @@ public class UI implements ActionListener { bot.stop(); frame.setVisible(false); System.exit(0); + } else if(srcb.equals(pause)) { + if(bot.isPaused()) {//the bot is going to be unpaused + pause.setText("Pause"); + info("Unpaused."); + } else {//the bot is going to be paused. + pause.setText("Unpause"); + info("Paused."); + } + bot.setPause(!bot.isPaused()); } } else if(src instanceof JMenuItem) { JMenuItem srcI = (JMenuItem) src;