Add auto login, update GUI

This commit is contained in:
RedSparr0w
2019-10-12 16:49:15 +13:00
parent 68c253de47
commit bb2864823c
6 changed files with 167 additions and 37 deletions
+6 -2
View File
@@ -2,7 +2,11 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="3ab8e8a0-ccfd-4b0b-9547-98173085dc38" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/src/ParaScript/data/variables/Trees.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ParaScript/data/variables/Trees.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/ParaScript/strategies/HandleLogin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ParaScript/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ParaScript/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ParaScript/data/Variables.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ParaScript/data/Variables.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ParaScript/strategies/MakeArrowShafts.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ParaScript/strategies/MakeArrowShafts.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ParaScript/ui/UI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ParaScript/ui/UI.java" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -38,9 +42,9 @@
</component>
<component name="RecentsManager">
<key name="CopyClassDialog.RECENTS_KEY">
<recent name="ParaScript.strategies" />
<recent name="ParaScript.ui" />
<recent name="ParaScript.data" />
<recent name="ParaScript.strategies" />
<recent name="ParaScript" />
</key>
</component>
+2 -4
View File
@@ -1,10 +1,7 @@
package ParaScript;
import ParaScript.data.Variables;
import ParaScript.strategies.MakeArrowShafts;
import ParaScript.strategies.ScriptState;
import ParaScript.strategies.Thieving;
import ParaScript.strategies.WoodcutTree;
import ParaScript.strategies.*;
import ParaScript.ui.UI;
import org.parabot.environment.api.utils.Time;
import org.parabot.environment.scripts.Script;
@@ -31,6 +28,7 @@ public class Main extends Script{
strategies.add(new ScriptState());
strategies.add(new MakeArrowShafts());
strategies.add(new WoodcutTree());
strategies.add(new HandleLogin());
provide(strategies);
return true;
}
+8
View File
@@ -10,6 +10,8 @@ public class Variables {
public static boolean running = false;
private static String currentStatus = "none";
private static String username = "";
private static String password = "";
public static String getStatus() {
return currentStatus;
@@ -20,4 +22,10 @@ public class Variables {
}
public final static Zone LUMBRIDGE_NORMAL_TREE_ZONE = new Zone(new Tile(3140, 3260), new Tile(3206, 3206));
public static String getAccountUsername() { return username; }
public static void setAccountUsername(String i) { username = i; }
public static String getAccountPassword() { return password; }
public static void setAccountPassword(String i) { password = i; }
}
@@ -0,0 +1,74 @@
package ParaScript.strategies;
import ParaScript.data.Variables;
import org.parabot.environment.api.utils.Time;
import org.parabot.environment.input.Keyboard;
import org.parabot.environment.input.Mouse;
import org.parabot.environment.scripts.framework.SleepCondition;
import org.parabot.environment.scripts.framework.Strategy;
import org.rev317.min.api.methods.Game;
import java.awt.*;
import java.awt.event.KeyEvent;
public class HandleLogin implements Strategy {
private Point point = new Point(432, 282);
private Point point2 = new Point(328, 324);
private Boolean typed = false;
@Override
public boolean activate() {
return !Game.isLoggedIn() || Game.getOpenBackDialogId() == 15812;
}
public void execute() {
Variables.setStatus("logging in");
if (Game.isLoggedIn() && Game.getOpenInterfaceId() == 15812) {
Mouse.getInstance().click(point2);
Variables.setStatus("none");
}
if (!Game.isLoggedIn()) {
if(Variables.getAccountPassword() != null && Variables.getAccountUsername() != null) {
if(!typed) {
Mouse.getInstance().click(point);
Time.sleep(1000);
clearInput();
Keyboard.getInstance().sendKeys(Variables.getAccountUsername());
Time.sleep(2000);
clearInput();
// Checking again so people don't type their passwords ingame.
if(!Game.isLoggedIn()) {
Keyboard.getInstance().sendKeys(Variables.getAccountPassword());
}
typed = true;
}
}
if(typed) {
Time.sleep(new SleepCondition() {
@Override
public boolean isValid() {
return Game.isLoggedIn();
}
}, 5000);
Mouse.getInstance().click(point);
Time.sleep(1000);
Keyboard.getInstance().clickKey(KeyEvent.VK_ENTER);
Time.sleep(1000);
Keyboard.getInstance().clickKey(KeyEvent.VK_ENTER);
Variables.setStatus("none");
}
}
}
private void clearInput() {
for(int i = 0; i < 30; i ++) {
Keyboard.getInstance().clickKey(KeyEvent.VK_DELETE);
Time.sleep(100);
}
}
}
@@ -42,6 +42,6 @@ public class MakeArrowShafts implements Strategy {
private boolean hasRequiredItems(){
// Make sure we have a knife and logs
return Inventory.contains(947, 1512);
return Inventory.getItem(947) != null && Inventory.getItem(1512) != null;
}
}
+76 -30
View File
@@ -2,9 +2,12 @@ package ParaScript.ui;
import ParaScript.data.variables.Trees;
import ParaScript.data.Variables;
import org.rev317.min.api.methods.Game;
import org.rev317.min.api.wrappers.Player;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -15,64 +18,100 @@ public class UI extends JFrame {
private JComboBox treeSelect = new JComboBox();
private JRadioButton bank = new JRadioButton("Bank");
private JRadioButton drop = new JRadioButton("Drop");
private JCheckBox birdsNest = new JCheckBox();
// Login tab
private JTextField username = new JTextField();
private JPasswordField password = new JPasswordField();
private JCheckBox birdsNest = new JCheckBox();
private JCheckBox autoLogin = new JCheckBox();
// Our colors
private Color Color_MidnightBlue = new Color(44, 62, 80);
private Color Color_WetAsphalt = new Color(52, 73, 94);
private Color Color_WhiteSmoke = new Color(245, 245, 245);
private Color Color_Emerald = new Color(46, 204, 113);
private Color Color_Alizarin = new Color(231, 76, 60);
public UI() {
setTitle("ParaScript");
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setBounds(100, 100, 400, 280);
setBounds(100, 100, 400, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
contentPane.setForeground(Color_WhiteSmoke);
contentPane.setBackground(Color_MidnightBlue);
setContentPane(contentPane);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBounds(0, 0, 395, 220);
tabbedPane.setBounds(0, 0, 395, 215);
contentPane.add(tabbedPane);
/*
* Login Stuff
*/
JPanel loginPanel = new JPanel();
loginPanel.setForeground(Color_WhiteSmoke);
loginPanel.setBackground(Color_WetAsphalt);
tabbedPane.addTab("Login", null, loginPanel, null);
loginPanel.setLayout(null);
// Username
JLabel lblUsername = new JLabel("Username:");
lblUsername.setForeground(Color_WhiteSmoke);
lblUsername.setBounds(20, 20, 73, 20);
loginPanel.add(lblUsername);
username.setBounds(20, 40, 150, 20);
loginPanel.add(username);
// Password
JLabel lblPassword = new JLabel("Password:");
lblPassword.setForeground(Color_WhiteSmoke);
lblPassword.setBounds(200, 20, 73, 20);
loginPanel.add(lblPassword);
password.setBounds(200, 40, 150, 20);
loginPanel.add(password);
// Auto Login
JLabel lblAutoLogin = new JLabel("Auto Login Enabled");
lblAutoLogin.setForeground(Color_WhiteSmoke);
lblAutoLogin.setBounds(40, 80, 130, 20);
loginPanel.add(lblAutoLogin);
autoLogin.setBackground(Color_WetAsphalt);
autoLogin.setForeground(Color_WhiteSmoke);
autoLogin.setBounds(15, 80, 20, 20);
autoLogin.setSelected(true);
loginPanel.add(autoLogin);
JPanel woodcuttingPanel = new JPanel();
woodcuttingPanel.setForeground(Color_WhiteSmoke);
woodcuttingPanel.setBackground(Color_WetAsphalt);
tabbedPane.addTab("Woodcutting", null, woodcuttingPanel, null);
woodcuttingPanel.setLayout(null);
JLabel lblUsername = new JLabel("Username:");
lblUsername.setBounds(20, 20, 73, 20);
woodcuttingPanel.add(lblUsername);
username.setBounds(20, 40, 150, 20);
woodcuttingPanel.add(username);
JLabel lblPassword = new JLabel("Password:");
lblPassword.setBounds(20, 60, 73, 20);
woodcuttingPanel.add(lblPassword);
password.setBounds(20, 80, 150, 20);
woodcuttingPanel.add(password);
/*
JLabel lblLocation = new JLabel("Location");
lblLocation.setBounds(200, 20, 73, 20);
woodcuttingPanel.add(lblLocation);
/*
location.setModel(
new DefaultComboBoxModel(Methods.locationToStringArray()));
location.setModel(new DefaultComboBoxModel(Methods.locationToStringArray()));
location.setBounds(200, 40, 150, 20);
woodcuttingPanel.add(location);
*/
// Select which tree to cut
JLabel lblTree = new JLabel("Tree");
lblTree.setBounds(200, 60, 73, 20);
lblTree.setForeground(Color_WhiteSmoke);
lblTree.setBounds(20, 20, 73, 20);
woodcuttingPanel.add(lblTree);
treeSelect.setModel(new DefaultComboBoxModel(Trees.toStringArray()));
treeSelect.setBounds(200, 80, 150, 20);
treeSelect.setBounds(20, 40, 150, 20);
woodcuttingPanel.add(treeSelect);
/*
JLabel lblMethod = new JLabel("Method");
lblMethod.setBounds(20, 120, 73, 20);
woodcuttingPanel.add(lblMethod);
/*
woodcutOptionButtonGroup.add(bank);
bank.setSelected(true);
bank.setBounds(20, 140, 80, 20);
@@ -83,6 +122,7 @@ public class UI extends JFrame {
woodcuttingPanel.add(drop);
JLabel lblBirdsNest = new JLabel("Bird nests");
lblBirdsNest.setForeground(WhiteSmoke);
lblBirdsNest.setBounds(200, 120, 150, 20);
woodcuttingPanel.add(lblBirdsNest);
@@ -106,9 +146,13 @@ public class UI extends JFrame {
});
*/
JButton start = new JButton("Start");
JButton start = new JButton("START");
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(autoLogin.isSelected() && !username.getText().equals("")) {
Variables.setAccountUsername(username.getText());
Variables.setAccountPassword(password.getText());
}
/*
for (Location loc : Location.values()) {
if (loc.getName().equalsIgnoreCase(location.getSelectedItem().toString())) {
@@ -121,10 +165,6 @@ public class UI extends JFrame {
System.out.println(selectedTree.getName());
}
}
if(!password.getText().equals("") && !username.getText().equals("")) {
Variables.setAccountUsername(username.getText());
Variables.setAccountPassword(password.getText());
}
if (drop.isSelected()) {
Variables.setDrop(true);
}
@@ -137,10 +177,16 @@ public class UI extends JFrame {
dispose();
*/
Variables.running = !Variables.running;
start.setText(Variables.running ? "pause" : "start");
start.setText(Variables.running ? "PAUSE" : "START");
start.setBackground(Variables.running ? Color_Alizarin : Color_Emerald);
}
});
start.setBounds(0, 220, 400, 20);
start.setBackground(Color_Emerald);
start.setForeground(Color_MidnightBlue);
// these next two lines do the magic..
start.setContentAreaFilled(false);
start.setOpaque(true);
start.setBounds(20, 220, 360, 40);
contentPane.add(start);
}
}