mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 16:49:10 +00:00
[FEATURE] Finished key bindings
This commit is contained in:
@@ -9,6 +9,7 @@ import org.parabot.core.parsers.hooks.HookParser;
|
|||||||
import org.parabot.core.ui.BotDialog;
|
import org.parabot.core.ui.BotDialog;
|
||||||
import org.parabot.core.ui.BotUI;
|
import org.parabot.core.ui.BotUI;
|
||||||
import org.parabot.core.ui.components.GamePanel;
|
import org.parabot.core.ui.components.GamePanel;
|
||||||
|
import org.parabot.core.ui.listeners.PBKeyListener;
|
||||||
import org.parabot.environment.api.interfaces.Paintable;
|
import org.parabot.environment.api.interfaces.Paintable;
|
||||||
import org.parabot.environment.input.Keyboard;
|
import org.parabot.environment.input.Keyboard;
|
||||||
import org.parabot.environment.input.Mouse;
|
import org.parabot.environment.input.Mouse;
|
||||||
@@ -47,6 +48,7 @@ public class Context {
|
|||||||
private PaintDebugger paintDebugger;
|
private PaintDebugger paintDebugger;
|
||||||
private Mouse mouse;
|
private Mouse mouse;
|
||||||
private Keyboard keyboard;
|
private Keyboard keyboard;
|
||||||
|
private PBKeyListener pbKeyListener;
|
||||||
private ServerProviderInfo providerInfo;
|
private ServerProviderInfo providerInfo;
|
||||||
private JSONParser jsonParser;
|
private JSONParser jsonParser;
|
||||||
|
|
||||||
@@ -226,6 +228,10 @@ public class Context {
|
|||||||
serverProvider.initKeyboard();
|
serverProvider.initKeyboard();
|
||||||
Core.verbose("Done.");
|
Core.verbose("Done.");
|
||||||
|
|
||||||
|
Core.verbose("Initializing key listener...");
|
||||||
|
this.pbKeyListener = new PBKeyListener();
|
||||||
|
applet.addKeyListener(this.pbKeyListener);
|
||||||
|
|
||||||
BotDialog.getInstance().validate();
|
BotDialog.getInstance().validate();
|
||||||
System.setOut(this.defaultOut);
|
System.setOut(this.defaultOut);
|
||||||
System.setErr(this.defaultErr);
|
System.setErr(this.defaultErr);
|
||||||
@@ -359,4 +365,8 @@ public class Context {
|
|||||||
public JSONParser getJsonParser() {
|
public JSONParser getJsonParser() {
|
||||||
return jsonParser;
|
return jsonParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PBKeyListener getPbKeyListener() {
|
||||||
|
return pbKeyListener;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
private JMenuItem run, pause, stop;
|
private JMenuItem run, pause, stop;
|
||||||
private boolean runScript, pauseScript;
|
private boolean runScript, pauseScript;
|
||||||
|
|
||||||
private PBKeyListener keyListener;
|
|
||||||
|
|
||||||
public BotUI(String username, String password) {
|
public BotUI(String username, String password) {
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
throw new IllegalStateException("BotUI already created");
|
throw new IllegalStateException("BotUI already created");
|
||||||
@@ -54,9 +52,6 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener,
|
|||||||
addComponentListener(this);
|
addComponentListener(this);
|
||||||
addWindowListener(this);
|
addWindowListener(this);
|
||||||
|
|
||||||
this.keyListener = new PBKeyListener();
|
|
||||||
addKeyListener(keyListener);
|
|
||||||
|
|
||||||
add(GamePanel.getInstance());
|
add(GamePanel.getInstance());
|
||||||
GamePanel.getInstance().add(VerboseLoader.get(username, password), BorderLayout.CENTER);
|
GamePanel.getInstance().add(VerboseLoader.get(username, password), BorderLayout.CENTER);
|
||||||
add(Logger.getInstance(), BorderLayout.SOUTH);
|
add(Logger.getInstance(), BorderLayout.SOUTH);
|
||||||
|
|||||||
@@ -14,19 +14,10 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class PBKeyListener implements KeyListener {
|
public class PBKeyListener implements KeyListener {
|
||||||
|
|
||||||
private int mainKey;
|
|
||||||
|
|
||||||
private List<Binding> bindings;
|
private List<Binding> bindings;
|
||||||
|
|
||||||
public PBKeyListener() {
|
public PBKeyListener() {
|
||||||
this.bindings = new ArrayList<>();
|
this.bindings = new ArrayList<>();
|
||||||
this.mainKey = (OperatingSystem.getOS() == OperatingSystem.MAC ? KeyEvent.VK_META : KeyEvent.VK_CONTROL);
|
|
||||||
this.fillBindings();
|
|
||||||
}
|
|
||||||
|
|
||||||
public PBKeyListener(int mainKey) {
|
|
||||||
this.bindings = new ArrayList<>();
|
|
||||||
this.mainKey = mainKey;
|
|
||||||
this.fillBindings();
|
this.fillBindings();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,14 +26,6 @@ public class PBKeyListener implements KeyListener {
|
|||||||
this.bindings.add(new ActionEventBinding(KeyEvent.VK_R, "Stop"));
|
this.bindings.add(new ActionEventBinding(KeyEvent.VK_R, "Stop"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMainKey() {
|
|
||||||
return mainKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMainKey(int mainKey) {
|
|
||||||
this.mainKey = mainKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Binding> getBindings() {
|
public List<Binding> getBindings() {
|
||||||
return bindings;
|
return bindings;
|
||||||
}
|
}
|
||||||
@@ -51,6 +34,11 @@ public class PBKeyListener implements KeyListener {
|
|||||||
this.bindings.add(binding);
|
this.bindings.add(binding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetBindings(){
|
||||||
|
this.bindings = new ArrayList<>();
|
||||||
|
this.fillBindings();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyTyped(KeyEvent e) {
|
public void keyTyped(KeyEvent e) {
|
||||||
|
|
||||||
@@ -58,12 +46,7 @@ public class PBKeyListener implements KeyListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void keyPressed(KeyEvent e) {
|
public void keyPressed(KeyEvent e) {
|
||||||
|
if (e.isControlDown()) {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void keyReleased(KeyEvent e) {
|
|
||||||
if (e.getKeyCode() == mainKey) {
|
|
||||||
for (Binding binding : bindings) {
|
for (Binding binding : bindings) {
|
||||||
if (binding.getKey() == e.getKeyCode()) {
|
if (binding.getKey() == e.getKeyCode()) {
|
||||||
binding.perform();
|
binding.perform();
|
||||||
@@ -71,4 +54,9 @@ public class PBKeyListener implements KeyListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void keyReleased(KeyEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,9 @@ public class Script implements Runnable {
|
|||||||
this.state = STATE_STOPPED;
|
this.state = STATE_STOPPED;
|
||||||
context.setRunningScript(null);
|
context.setRunningScript(null);
|
||||||
|
|
||||||
|
Core.verbose("Resetting key bindings...");
|
||||||
|
Context.getInstance().getPbKeyListener().resetBindings();
|
||||||
|
|
||||||
BotUI.getInstance().toggleRun();
|
BotUI.getInstance().toggleRun();
|
||||||
Core.verbose("Done.");
|
Core.verbose("Done.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user