Пример #1
0
 private Bot getCurrentBot() {
   final int idx = toolBar.getCurrentTab();
   if (idx > -1 && idx < bots.size()) {
     return bots.get(idx);
   }
   return null;
 }
Пример #2
0
 public void addBot() {
   if (bots.size() > MAX_BOTS) {
     return;
   }
   final Bot bot = new Bot();
   bots.add(bot);
   toolBar.addTab();
   toolBar.setAddTabVisible(bots.size() < MAX_BOTS);
   bot.getScriptHandler().addScriptListener(this);
   new Thread(
           new Runnable() {
             public void run() {
               bot.start();
             }
           })
       .start();
 }
Пример #3
0
 public void removeBot(final Bot bot) {
   final int idx = bots.indexOf(bot);
   bot.getScriptHandler().stopAllScripts();
   bot.getScriptHandler().removeScriptListener(this);
   if (idx >= 0) {
     toolBar.removeTab(idx);
   }
   bots.remove(idx);
   toolBar.setAddTabVisible(bots.size() < MAX_BOTS);
   new Thread(
           new Runnable() {
             public void run() {
               bot.stop();
               System.gc();
             }
           })
       .start();
 }
Пример #4
0
  public void updateScriptControls() {
    boolean idle = true, paused = false;
    final Bot bot = getCurrentBot();

    if (bot != null) {
      final Map<Integer, LoopTask> scriptMap = bot.getScriptHandler().getRunningScripts();
      if (scriptMap.size() > 0) {
        idle = false;
        paused = scriptMap.values().iterator().next().isPaused();
      } else {
        idle = true;
      }
    }

    menuBar.getMenuItem(Messages.RUNSCRIPT).setVisible(idle);
    menuBar.getMenuItem(Messages.STOPSCRIPT).setVisible(!idle);
    menuBar.getMenuItem(Messages.PAUSESCRIPT).setEnabled(!idle);
    menuBar.setPauseScript(paused);
    toolBar.setInputButtonVisible(!idle);
    menuBar.setEnabled(Messages.FORCEINPUT, !idle);

    if (idle) {
      toolBar.setOverrideInput(false);
      menuBar.setOverrideInput(false);
      toolBar.setInputState(Environment.INPUT_KEYBOARD | Environment.INPUT_MOUSE);
      toolBar.setScriptButton(BotToolBar.RUN_SCRIPT);
    } else {
      toolBar.setOverrideInput(bot.overrideInput);
      menuBar.setOverrideInput(bot.overrideInput);
      toolBar.setInputState(bot.inputFlags);
      toolBar.setScriptButton(paused ? BotToolBar.RESUME_SCRIPT : BotToolBar.PAUSE_SCRIPT);
    }

    toolBar.updateInputButton();
    repaint();
  }
Пример #5
0
 public void actionPerformed(final ActionEvent evt) {
   final String action = evt.getActionCommand();
   final String menu, option;
   final int z = action.indexOf('.');
   if (z == -1) {
     menu = action;
     option = "";
   } else {
     menu = action.substring(0, z);
     option = action.substring(z + 1);
   }
   if (menu.equals(Messages.CLOSEBOT)) {
     final int idx = Integer.parseInt(option);
     removeBot(bots.get(idx));
   } else if (menu.equals(Messages.FILE)) {
     if (option.equals(Messages.NEWBOT)) {
       addBot();
     } else if (option.equals(Messages.CLOSEBOT)) {
       removeBot(getCurrentBot());
     } else if (option.equals(Messages.ADDSCRIPT)) {
       final String pretext = "";
       final String key =
           (String)
               JOptionPane.showInputDialog(
                   this,
                   "Enter the script URL e.g. pastebin link or direct compiled file:",
                   option,
                   JOptionPane.QUESTION_MESSAGE,
                   null,
                   null,
                   pretext);
       if (!(key == null || key.trim().isEmpty())) {
         ScriptDownloader.save(key);
       }
     } else if (option.equals(Messages.RUNSCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         showScriptSelector(current);
       }
     } else if (option.equals(Messages.STOPSCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         showStopScript(current);
       }
     } else if (option.equals(Messages.PAUSESCRIPT)) {
       final Bot current = getCurrentBot();
       if (current != null) {
         pauseScript(current);
       }
     } else if (option.equals(Messages.SAVESCREENSHOT)) {
       final Bot current = getCurrentBot();
       if (current != null && current.getMethodContext() != null) {
         ScreenshotUtil.saveScreenshot(current, current.getMethodContext().game.isLoggedIn());
       }
     } else if (option.equals(Messages.HIDE)) {
       setTray();
     } else if (option.equals(Messages.EXIT)) {
       cleanExit();
     }
   } else if (menu.equals(Messages.EDIT)) {
     if (option.equals(Messages.ACCOUNTS)) {
       AccountManager.getInstance().showGUI();
     } else {
       final Bot current = getCurrentBot();
       if (current != null) {
         if (option.equals(Messages.FORCEINPUT)) {
           current.overrideInput = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
           updateScriptControls();
         } else if (option.equals(Messages.LESSCPU)) {
           current.disableRendering = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLECANVAS)) {
           current.disableGraphics = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.EXTDVIEWS)) {
           menuBar.setExtendedView(((JCheckBoxMenuItem) evt.getSource()).isSelected());
         } else if (option.equals(Messages.DISABLEANTIRANDOMS)) {
           current.disableRandoms = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLEAUTOLOGIN)) {
           current.disableAutoLogin = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         } else if (option.equals(Messages.DISABLETHEME)) {
           Preferences.getInstance().theme = !((JCheckBoxMenuItem) evt.getSource()).isSelected();
           log.info(
               "Themes will be "
                   + (Preferences.getInstance().theme ? "enabled" : "disabled")
                   + " next time you run the application");
         } else if (option.equals(Messages.DISABLEADS)) {
           Preferences.getInstance().hideAds = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
         }
       }
     }
   } else if (menu.equals(Messages.VIEW)) {
     final Bot current = getCurrentBot();
     final boolean selected = ((JCheckBoxMenuItem) evt.getSource()).isSelected();
     if (option.equals(Messages.HIDETOOLBAR)) {
       toggleViewState(toolBar, selected);
     } else if (option.equals(Messages.HIDELOGPANE)) {
       toggleViewState(textScroll, selected);
     } else if (current != null) {
       if (option.equals(Messages.ALLDEBUGGING)) {
         for (final String key : BotMenuBar.DEBUG_MAP.keySet()) {
           final Class<?> el = BotMenuBar.DEBUG_MAP.get(key);
           if (menuBar.getCheckBox(key).isVisible()) {
             final boolean wasSelected = menuBar.getCheckBox(key).isSelected();
             menuBar.getCheckBox(key).setSelected(selected);
             if (selected) {
               if (!wasSelected) {
                 current.addListener(el);
               }
             } else {
               if (wasSelected) {
                 current.removeListener(el);
               }
             }
           }
         }
       } else {
         final Class<?> el = BotMenuBar.DEBUG_MAP.get(option);
         menuBar.getCheckBox(option).setSelected(selected);
         if (selected) {
           current.addListener(el);
         } else {
           menuBar.getCheckBox(Messages.ALLDEBUGGING).setSelected(false);
           current.removeListener(el);
         }
       }
     }
   } else if (menu.equals(Messages.TOOLS)) {
     if (option.equals(Messages.LICENSES)) {
       log.warning("License manager coming soon");
     }
   } else if (menu.equals(Messages.HELP)) {
     if (option.equals(Messages.SITE)) {
       openURL(Configuration.Paths.URLs.SITE);
     } else if (option.equals(Messages.PROJECT)) {
       openURL(Configuration.Paths.URLs.PROJECT);
     } else if (option.equals(Messages.LICENSE)) {
       openURL(Configuration.Paths.URLs.LICENSE);
     } else if (option.equals(Messages.ABOUT)) {
       JOptionPane.showMessageDialog(
           this,
           new String[] {
             "An open source bot developed by the community.",
             "",
             "RuneScape® is a trademark of Jagex © 1999 - 2011 Jagex, Ltd.",
             "RuneScape content and materials are trademarks and copyrights of Jagex or its licensees.",
             "This program is issued with no warranty and is not affiliated with Jagex Ltd., nor do they endorse usage of our software.",
             "",
             "Visit " + Configuration.Paths.URLs.SITE + "/ for more information."
           },
           option,
           JOptionPane.INFORMATION_MESSAGE);
     }
   } else if (menu.equals("Tab")) {
     final Bot curr = getCurrentBot();
     menuBar.setBot(curr);
     panel.setBot(curr);
     panel.repaint();
     toolBar.setHome(curr == null);
     setTitle(curr == null ? null : curr.getAccountName());
     updateScriptControls();
   }
 }