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

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ export.jardesc
.project
.classpath
.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.
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.
## Video:
## Video (a bit outdated):
[![Video](https://i.vimeocdn.com/video/641445132_640.jpg)](https://vimeo.com/222811186 "Video")
#### 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:
* Automated Backfocus

View File

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

View File

@ -13,6 +13,7 @@ import java.util.Scanner;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
@ -23,6 +24,7 @@ import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.filechooser.FileNameExtensionFilter;
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 time = new JLabel("0 s");
private JFileChooser filechooser = new JFileChooser();
private Slider[] slider = {
new Slider("Waittime: ","s", 1,300,180,-1, null, new Updater() {
@Override
@ -83,12 +87,8 @@ public class UI implements ActionListener {
},false)
};
Clicker bot = new Clicker();
private File file = new File(".profile");
public UI() {
Main.get().ui = this;
@ -153,7 +153,7 @@ public class UI implements ActionListener {
frame.setVisible(true);
//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)");
pause.setToolTipText("Pauses the \"output\" of the Bot, but the internal states are still updated.");
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[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
@ -207,6 +209,7 @@ public class UI implements ActionListener {
else if(srcb.equals(exit)) {
bot.stop();
frame.setVisible(false);
frame.dispose();
System.exit(0);
} else if(srcb.equals(pause)) {
if(bot.isPaused()) {//the bot is going to be unpaused
@ -223,9 +226,18 @@ public class UI implements ActionListener {
} else if(src instanceof JMenuItem) {
JMenuItem srcI = (JMenuItem) src;
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)) {
save();
int returnval = filechooser.showOpenDialog(frame);
if(returnval == JFileChooser.APPROVE_OPTION) {
save(filechooser.getSelectedFile());
} else
info("cancled.");
} else if(srcI.equals(new_)) {
new_();
}
@ -244,10 +256,10 @@ public class UI implements ActionListener {
}
}
private void load(boolean info) {
if(file.exists()) {
private void load(File f, boolean info) {
if(f.exists()) {
try {
Scanner s = new Scanner(file);
Scanner s = new Scanner(f);
while(s.hasNextLine()) {
String split[] = s.nextLine().split(" ");
if(!split[1].equals("null")) {
@ -289,11 +301,11 @@ public class UI implements ActionListener {
info("no profile found.");
}
private void save() {
private void save(File f) {
try {
if(!file.exists())
file.createNewFile();
else {
if(!f.getName().endsWith(".profile"))
f = new File(f.getAbsoluteFile() + ".profile");
if(f.exists()){
/*ok == 0
cancel = 2*/
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;
}
}
} 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.flush();
fw.close();
@ -325,6 +338,17 @@ public class UI implements ActionListener {
bot.stop();
bot = null;
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() {
@ -447,7 +471,7 @@ public class UI implements ActionListener {
private static final long serialVersionUID = 1L;
private JSlider slider;
private JLabel label;
private int defaultvalue;
private ChangeListener listener;
private Updater updater;
private String prefix = "", sufix = "";
@ -475,6 +499,7 @@ public class UI implements ActionListener {
listener = cl;
updater = upd;
slider.setEnabled(enabled);
defaultvalue = startvalue;
}
public int getValue() {
@ -504,5 +529,12 @@ public class UI implements ActionListener {
if(updater != null)
updater.update(slider.getValue());
}
/**
* Restores the default value, does not change the controlled value, just the displayed one
*/
public void reset() {
setValue(defaultvalue);
}
}
}