Skip to content

Commit

Permalink
fileselector menu
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbesen committed Jan 5, 2018
1 parent 1b1dff4 commit d75a454
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
export.jardesc
.project
.classpath
.profile
.profile
/default.profile
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/mrbesen/cr/auto/clicker/PosSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class PosSelector implements Runnable {
UI ui;
private boolean required;


public boolean isRequired() {
return required;
}
Expand Down
68 changes: 50 additions & 18 deletions src/mrbesen/cr/auto/clicker/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand All @@ -23,6 +24,7 @@
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;

Expand Down Expand Up @@ -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
Expand All @@ -82,12 +86,8 @@ public void update(int nummber) {
}
},false)
};


Clicker bot = new Clicker();


private File file = new File(".profile");
Clicker bot = new Clicker();

public UI() {
Main.get().ui = this;
Expand Down Expand Up @@ -153,7 +153,7 @@ public UI() {
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.");
Expand All @@ -173,6 +173,8 @@ public UI() {
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
Expand Down Expand Up @@ -207,6 +209,7 @@ public void actionPerformed(ActionEvent e) {
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
Expand All @@ -223,9 +226,18 @@ else if(srcb.equals(exit)) {
} 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_();
}
Expand All @@ -244,10 +256,10 @@ else if(srcb.equals(exit)) {
}
}

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")) {
Expand Down Expand Up @@ -289,11 +301,11 @@ private void load(boolean info) {
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);
Expand All @@ -302,9 +314,10 @@ private void save() {
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();
Expand All @@ -325,6 +338,17 @@ private void new_() {
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() {
Expand Down Expand Up @@ -447,7 +471,7 @@ public class Slider extends JPanel implements ChangeListener{
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 = "";
Expand Down Expand Up @@ -475,6 +499,7 @@ public Slider(String prefix, String sufix, int minvalue, int maxvalue, int start
listener = cl;
updater = upd;
slider.setEnabled(enabled);
defaultvalue = startvalue;
}

public int getValue() {
Expand Down Expand Up @@ -504,5 +529,12 @@ public void stateChanged(ChangeEvent e) {
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);
}
}
}

0 comments on commit d75a454

Please sign in to comment.