Merge pull request #7 from mrbesen/dev

fileselector menu
This commit is contained in:
MrBesen 2018-01-05 22:30:06 +01:00 committed by GitHub
commit 569d3aaf81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 21 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@
export.jardesc export.jardesc
.project .project
.classpath .classpath
.profile .profile
/default.profile

View File

@ -22,11 +22,11 @@ Bot losses some matches -> Bot gets easyer oponents -> Bot winns some matches (A
This java Apllication needs some kind of Mobile Device Emulator or Interface. This java Apllication needs some kind of Mobile Device Emulator or Interface.
I have tested it with Teamviewer and Nox Appplayer. You can configure points of the Clashroyale app, where the bot automatically clicks. I have tested it with Teamviewer and Nox Appplayer. You can configure points of the Clashroyale app, where the bot automatically clicks.
These clicks can cause Troops to spawn or Buttons to be Pressed. These clicks can cause Troops to spawn or Buttons to be Pressed.
## Video: ## Video (a bit outdated):
[![Video](https://i.vimeocdn.com/video/641445132_640.jpg)](https://vimeo.com/222811186 "Video") [![Video](https://i.vimeocdn.com/video/641445132_640.jpg)](https://vimeo.com/222811186 "Video")
#### How does it work? #### How does it work?
This program emulates a mouse and keyboard and controls your computer with that emulated hardware. To The App it look, like you are a normal User. This program emulates a mouse and keyboard and controls your computer with that emulated hardware. To The App it look, like you are a normal user.
#### Features: #### Features:
* Automated Backfocus * Automated Backfocus

View File

@ -11,6 +11,7 @@ public class PosSelector implements Runnable {
UI ui; UI ui;
private boolean required; private boolean required;
public boolean isRequired() { public boolean isRequired() {
return required; return required;
} }

View File

@ -13,6 +13,7 @@ import java.util.Scanner;
import javax.swing.Box; import javax.swing.Box;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JCheckBox; import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JMenu; import javax.swing.JMenu;
@ -23,6 +24,7 @@ import javax.swing.JPanel;
import javax.swing.JSlider; import javax.swing.JSlider;
import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.sun.istack.internal.Nullable; import com.sun.istack.internal.Nullable;
@ -68,6 +70,8 @@ public class UI implements ActionListener {
private JLabel info = new JLabel("Define positions, to start."); private JLabel info = new JLabel("Define positions, to start.");
private JLabel time = new JLabel("0 s"); private JLabel time = new JLabel("0 s");
private JFileChooser filechooser = new JFileChooser();
private Slider[] slider = { private Slider[] slider = {
new Slider("Waittime: ","s", 1,300,180,-1, null, new Updater() { new Slider("Waittime: ","s", 1,300,180,-1, null, new Updater() {
@Override @Override
@ -82,12 +86,8 @@ public class UI implements ActionListener {
} }
},false) },false)
}; };
Clicker bot = new Clicker();
Clicker bot = new Clicker();
private File file = new File(".profile");
public UI() { public UI() {
Main.get().ui = this; Main.get().ui = this;
@ -153,7 +153,7 @@ public class UI implements ActionListener {
frame.setVisible(true); frame.setVisible(true);
//set tooltips //set tooltips
start.setToolTipText("Starts the Bot."); start.setToolTipText("Starts the Bot. (When gray, try to set the positions for the red buttons!)");
skip.setToolTipText("Skips the current Action.(Waiting or beeing in a match, only usefull, when the bot miss clicked somewhere)"); skip.setToolTipText("Skips the current Action.(Waiting or beeing in a match, only usefull, when the bot miss clicked somewhere)");
pause.setToolTipText("Pauses the \"output\" of the Bot, but the internal states are still updated."); pause.setToolTipText("Pauses the \"output\" of the Bot, but the internal states are still updated.");
exit.setToolTipText("Stops the Bot and closes the Window."); exit.setToolTipText("Stops the Bot and closes the Window.");
@ -173,6 +173,8 @@ public class UI implements ActionListener {
posselctors[6].button.setToolTipText("Set the Position, where a Card should be placed. Leave it empty to use the same position as the \"Battle\" position."); posselctors[6].button.setToolTipText("Set the Position, where a Card should be placed. Leave it empty to use the same position as the \"Battle\" position.");
posselctors[7].button.setToolTipText("Set the position of the Close button, of the menue that po up, when you tap the arena. This one also saves the color of the position to auto detect it."); posselctors[7].button.setToolTipText("Set the position of the Close button, of the menue that po up, when you tap the arena. This one also saves the color of the position to auto detect it.");
filechooser.removeChoosableFileFilter(filechooser.getAcceptAllFileFilter());
filechooser.addChoosableFileFilter(new FileNameExtensionFilter("Botsettings", "profile"));
} }
@Override @Override
@ -207,6 +209,7 @@ public class UI implements ActionListener {
else if(srcb.equals(exit)) { else if(srcb.equals(exit)) {
bot.stop(); bot.stop();
frame.setVisible(false); frame.setVisible(false);
frame.dispose();
System.exit(0); System.exit(0);
} else if(srcb.equals(pause)) { } else if(srcb.equals(pause)) {
if(bot.isPaused()) {//the bot is going to be unpaused if(bot.isPaused()) {//the bot is going to be unpaused
@ -223,9 +226,18 @@ public class UI implements ActionListener {
} else if(src instanceof JMenuItem) { } else if(src instanceof JMenuItem) {
JMenuItem srcI = (JMenuItem) src; JMenuItem srcI = (JMenuItem) src;
if(srcI.equals(load)) { if(srcI.equals(load)) {
load(true); int returnval = filechooser.showOpenDialog(frame);
if(returnval == JFileChooser.APPROVE_OPTION) {
File f = filechooser.getSelectedFile();
load(f, true);
} else
info("cancled.");
} else if(srcI.equals(save)) { } else if(srcI.equals(save)) {
save(); int returnval = filechooser.showOpenDialog(frame);
if(returnval == JFileChooser.APPROVE_OPTION) {
save(filechooser.getSelectedFile());
} else
info("cancled.");
} else if(srcI.equals(new_)) { } else if(srcI.equals(new_)) {
new_(); new_();
} }
@ -244,10 +256,10 @@ public class UI implements ActionListener {
} }
} }
private void load(boolean info) { private void load(File f, boolean info) {
if(file.exists()) { if(f.exists()) {
try { try {
Scanner s = new Scanner(file); Scanner s = new Scanner(f);
while(s.hasNextLine()) { while(s.hasNextLine()) {
String split[] = s.nextLine().split(" "); String split[] = s.nextLine().split(" ");
if(!split[1].equals("null")) { if(!split[1].equals("null")) {
@ -289,11 +301,11 @@ public class UI implements ActionListener {
info("no profile found."); info("no profile found.");
} }
private void save() { private void save(File f) {
try { try {
if(!file.exists()) if(!f.getName().endsWith(".profile"))
file.createNewFile(); f = new File(f.getAbsoluteFile() + ".profile");
else { if(f.exists()){
/*ok == 0 /*ok == 0
cancel = 2*/ cancel = 2*/
int choose = JOptionPane.showConfirmDialog(null, "You are going to override the old profile!", "Override", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); int choose = JOptionPane.showConfirmDialog(null, "You are going to override the old profile!", "Override", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE);
@ -302,9 +314,10 @@ public class UI implements ActionListener {
return; return;
} }
} } else
f.createNewFile();
FileWriter fw = new FileWriter(file); FileWriter fw = new FileWriter(f);
fw.write(bot.serialize()+"\n101 "+ slider[0].getValue() + "\n102 " + doubleplace.isSelected()+"\n103 " + slider[1].getValue()); fw.write(bot.serialize()+"\n101 "+ slider[0].getValue() + "\n102 " + doubleplace.isSelected()+"\n103 " + slider[1].getValue());
fw.flush(); fw.flush();
fw.close(); fw.close();
@ -325,6 +338,17 @@ public class UI implements ActionListener {
bot.stop(); bot.stop();
bot = null; bot = null;
bot = new Clicker(); bot = new Clicker();
//set all buttons to red
start.setEnabled(false);
skip.setEnabled(false);
for(PosSelector poss : posselctors) {
poss.red();
}
for(Slider s : slider) {
s.reset();
}
} }
public void refresh() { public void refresh() {
@ -447,7 +471,7 @@ public class UI implements ActionListener {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private JSlider slider; private JSlider slider;
private JLabel label; private JLabel label;
private int defaultvalue;
private ChangeListener listener; private ChangeListener listener;
private Updater updater; private Updater updater;
private String prefix = "", sufix = ""; private String prefix = "", sufix = "";
@ -475,6 +499,7 @@ public class UI implements ActionListener {
listener = cl; listener = cl;
updater = upd; updater = upd;
slider.setEnabled(enabled); slider.setEnabled(enabled);
defaultvalue = startvalue;
} }
public int getValue() { public int getValue() {
@ -504,5 +529,12 @@ public class UI implements ActionListener {
if(updater != null) if(updater != null)
updater.update(slider.getValue()); updater.update(slider.getValue());
} }
/**
* Restores the default value, does not change the controlled value, just the displayed one
*/
public void reset() {
setValue(defaultvalue);
}
} }
} }