Added Overlay

This commit is contained in:
mrbesen 2017-10-26 12:59:11 +02:00
parent 2ba3e835ca
commit ae521ece46
3 changed files with 104 additions and 0 deletions

View File

@ -37,6 +37,7 @@ public class Clicker implements Runnable{
private final int waittime = 50;//time between mouse teleports and clicks
private int mincolordistance = 35;
private Overlay ov = null;
OSType os;
@ -394,4 +395,16 @@ public class Clicker implements Runnable{
OSX,
unsupported
}
public void toggleOverlay() {
if(ov == null) {
ov = new Overlay();
ov.set(playout, cardslots, end, battle, arena_switch);
ov.init();
} else {
ov.close();
ov = null;
}
}
}

View File

@ -0,0 +1,86 @@
package mrbesen.cr.auto.clicker;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
public class Overlay {
JFrame frame;
Point spawn;
Point cards[];
Point ok;
Point battle;
Point arenaview;
public Overlay() {
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
@Override
public void run() {
if(frame != null) {
frame.dispose();
}
}
}, "Shutdownhook-Overlaycloser"));
}
void set(Point spawn, Point[] cards, Point ok, Point battle, Point arenaview) {
this.spawn = spawn;
this.cards = cards;
this.ok = ok;
this.battle = battle;
this.arenaview = arenaview;
}
public void init() {
frame = new JFrame("Bot Overlay");
frame.setUndecorated(true);
frame.setOpacity(0.5f);
int width=0, height=0;
int x=spawn.x,y=spawn.y;
for(Point p : getlist()) {
if(p != null) {
if(p.x < x) {
width += (x-p.x);//umsoviel weiter machen, wie nach links verschoben wird
x = p.x;
}
if(x+width < p.x) {
width += x+width-p.x;
}
if(p.y < y) {
height += (y-p.y);
y = p.y;
}
if(y+height < p.y) {
height += y+height-p.y;
}
}
}
frame.setSize(width, height);
frame.setLocation(x, y);
frame.setVisible(true);
Graphics gra = frame.getGraphics();
gra.setColor(new Color(255, 0, 0));//red
for(Point p : cards) {
if(p != null) {
gra.drawRect(p.x-1, p.y-1, 300, 300);
}
}
System.out.println("Overlay is da!");
}
public void close() {
frame.dispose();
}
private Point[] getlist() {
return new Point[] {spawn,ok,battle,arenaview, cards[0],cards[1],cards[2],cards[3]};
}
}

View File

@ -62,6 +62,7 @@ public class UI implements ActionListener {
private JButton skip = new JButton("SKIP"); // the button, to skip waiting
private JButton pause = new JButton("Pause");
private JButton exit = new JButton("EXIT");
private JButton overlay = new JButton("Overlay");
private JLabel info = new JLabel("Define positions, to start.");
private JLabel time = new JLabel("0 s");
@ -113,6 +114,7 @@ public class UI implements ActionListener {
start.addActionListener(this);
pause.addActionListener(this);
exit.addActionListener(this);
overlay.addActionListener(this);
doubleplace.addActionListener(this);
backfocus.addActionListener(this);
@ -124,6 +126,7 @@ public class UI implements ActionListener {
middle.add(skip);
middle.add(pause);
middle.add(exit);
middle.add(overlay);
middle.add(autoplay);
middle.add(doubleplace);
middle.add(backfocus);
@ -187,6 +190,8 @@ public class UI implements ActionListener {
info("Paused.");
}
bot.setPause(!bot.isPaused());
} else if(srcb.equals(overlay)) {
bot.toggleOverlay();
}
} else if(src instanceof JMenuItem) {
JMenuItem srcI = (JMenuItem) src;