From d75a4549818905508bc2f6a29f1adf2ab3245958 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Fri, 5 Jan 2018 22:29:15 +0100 Subject: [PATCH] fileselector menu --- .gitignore | 3 +- README.md | 4 +- src/mrbesen/cr/auto/clicker/PosSelector.java | 1 + src/mrbesen/cr/auto/clicker/UI.java | 68 ++++++++++++++------ 4 files changed, 55 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 04d8a84..11913d6 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ export.jardesc .project .classpath -.profile \ No newline at end of file +.profile +/default.profile diff --git a/README.md b/README.md index 5a7c6e1..d463cce 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/mrbesen/cr/auto/clicker/PosSelector.java b/src/mrbesen/cr/auto/clicker/PosSelector.java index dae29a8..acb5dd8 100644 --- a/src/mrbesen/cr/auto/clicker/PosSelector.java +++ b/src/mrbesen/cr/auto/clicker/PosSelector.java @@ -11,6 +11,7 @@ public class PosSelector implements Runnable { UI ui; private boolean required; + public boolean isRequired() { return required; } diff --git a/src/mrbesen/cr/auto/clicker/UI.java b/src/mrbesen/cr/auto/clicker/UI.java index cc31607..1cd7916 100644 --- a/src/mrbesen/cr/auto/clicker/UI.java +++ b/src/mrbesen/cr/auto/clicker/UI.java @@ -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; @@ -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; @@ -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 @@ -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; @@ -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."); @@ -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 @@ -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 @@ -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_(); } @@ -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")) { @@ -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); @@ -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(); @@ -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() { @@ -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 = ""; @@ -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() { @@ -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); + } } } \ No newline at end of file