mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 08:39:12 +00:00
[FEATURE] Changed layout of VerboseLoader
This commit is contained in:
+1
-1
@@ -122,4 +122,4 @@ releases
|
|||||||
._*
|
._*
|
||||||
|
|
||||||
Test.java
|
Test.java
|
||||||
.DS_Store
|
*.DS_Store
|
||||||
Regular → Executable
+66
-23
@@ -1,39 +1,44 @@
|
|||||||
package org.parabot.core.ui.components;
|
package org.parabot.core.ui.components;
|
||||||
|
|
||||||
|
import org.parabot.core.Configuration;
|
||||||
import org.parabot.core.Core;
|
import org.parabot.core.Core;
|
||||||
import org.parabot.core.forum.AccountManager;
|
import org.parabot.core.forum.AccountManager;
|
||||||
import org.parabot.core.forum.AccountManagerAccess;
|
import org.parabot.core.forum.AccountManagerAccess;
|
||||||
import org.parabot.core.io.ProgressListener;
|
import org.parabot.core.io.ProgressListener;
|
||||||
import org.parabot.core.ui.ServerSelector;
|
import org.parabot.core.ui.ServerSelector;
|
||||||
import org.parabot.core.ui.images.Images;
|
import org.parabot.core.ui.images.Images;
|
||||||
|
import org.parabot.core.ui.utils.Fonts;
|
||||||
import org.parabot.core.ui.utils.UILog;
|
import org.parabot.core.ui.utils.UILog;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.geom.Line2D;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.awt.image.RescaleOp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An informative JPanel which tells the user what bot is doing
|
* An informative JPanel which tells the user what bot is doing
|
||||||
*
|
*
|
||||||
* @author Everel
|
* @author Everel
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class VerboseLoader extends JPanel implements ProgressListener {
|
public class VerboseLoader extends JPanel implements ProgressListener {
|
||||||
private static final long serialVersionUID = 7412412644921803896L;
|
private static final long serialVersionUID = 7412412644921803896L;
|
||||||
private static VerboseLoader current;
|
private static VerboseLoader current;
|
||||||
private static String state = "Initializing loader...";
|
private static String state = "Initializing loader...";
|
||||||
|
|
||||||
public static final int STATE_AUTHENTICATION = 0;
|
private static final int STATE_AUTHENTICATION = 0;
|
||||||
public static final int STATE_LOADING = 1;
|
public static final int STATE_LOADING = 1;
|
||||||
public static final int STATE_SERVER_SELECT = 2;
|
private static final int STATE_SERVER_SELECT = 2;
|
||||||
private int currentState;
|
private int currentState;
|
||||||
|
private static final String titleName = "Parabot";
|
||||||
|
private static final String sloganText = "The best RuneScape private server bot";
|
||||||
|
|
||||||
private static AccountManager manager;
|
private static AccountManager manager;
|
||||||
|
|
||||||
private FontMetrics fontMetrics;
|
private FontMetrics fontMetrics;
|
||||||
private BufferedImage background;
|
private BufferedImage background, banner, loginBox;
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
private JPanel loginPanel;
|
private JPanel loginPanel;
|
||||||
|
|
||||||
@@ -47,11 +52,13 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private VerboseLoader(String username, String password) {
|
private VerboseLoader(String username, String password) {
|
||||||
if(current != null) {
|
if (current != null) {
|
||||||
throw new IllegalStateException("MainScreenComponent already made.");
|
throw new IllegalStateException("MainScreenComponent already made.");
|
||||||
}
|
}
|
||||||
current = this;
|
current = this;
|
||||||
this.background = Images.getResource("/storage/images/background.png");
|
this.background = Images.getResource("/storage/images/background.png");
|
||||||
|
this.banner = Images.getResource("/storage/images/logo.png");
|
||||||
|
this.loginBox = Images.getResource("/storage/images/login.png");
|
||||||
this.progressBar = new ProgressBar(400, 20);
|
this.progressBar = new ProgressBar(400, 20);
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
setSize(775, 510);
|
setSize(775, 510);
|
||||||
@@ -59,22 +66,33 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
setDoubleBuffered(true);
|
setDoubleBuffered(true);
|
||||||
setOpaque(false);
|
setOpaque(false);
|
||||||
|
|
||||||
if(username != null && password != null) {
|
if (username != null && password != null) {
|
||||||
if(Core.inDebugMode() || manager.login(username, password, false)) {
|
if (Core.inDebugMode() || manager.login(username, password, false)) {
|
||||||
currentState = STATE_SERVER_SELECT;
|
currentState = STATE_SERVER_SELECT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentState == STATE_AUTHENTICATION) {
|
if (currentState == STATE_AUTHENTICATION) {
|
||||||
addLoginPanel();
|
addLoginPanel();
|
||||||
} else if(currentState == STATE_SERVER_SELECT) {
|
} else if (currentState == STATE_SERVER_SELECT) {
|
||||||
addServerPanel();
|
addServerPanel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addServerPanel() {
|
public void addServerPanel() {
|
||||||
JPanel servers = ServerSelector.getInstance();
|
JPanel servers = ServerSelector.getInstance();
|
||||||
add(servers, new GridBagConstraints());
|
GridBagLayout bagLayout = (GridBagLayout) getLayout();
|
||||||
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
|
|
||||||
|
c.weightx = 1;
|
||||||
|
c.weighty = 1;
|
||||||
|
c.gridx = 0;
|
||||||
|
c.gridy = 0;
|
||||||
|
c.anchor = GridBagConstraints.SOUTH;
|
||||||
|
c.insets = new Insets(0, 0, 25, 0);
|
||||||
|
|
||||||
|
bagLayout.setConstraints(servers, c);
|
||||||
|
add(servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addLoginPanel() {
|
public void addLoginPanel() {
|
||||||
@@ -83,15 +101,15 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
|
|
||||||
loginPanel.setLayout(new BoxLayout(loginPanel, BoxLayout.Y_AXIS));
|
loginPanel.setLayout(new BoxLayout(loginPanel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
Font labelFont = new Font("Times New Roman", Font.PLAIN, 11);
|
Font labelFont = Fonts.getResource("leelawadee.ttf");
|
||||||
|
|
||||||
JLabel usernameLabel = new JLabel("Username");
|
JLabel usernameLabel = new JLabel("Username");
|
||||||
usernameLabel.setFont(labelFont);
|
usernameLabel.setFont(labelFont);
|
||||||
usernameLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
usernameLabel.setAlignmentX(Box.CENTER_ALIGNMENT);
|
||||||
usernameLabel.setForeground(Color.white);
|
usernameLabel.setForeground(Color.white);
|
||||||
|
|
||||||
final JTextField userInput = new JTextField(25);
|
final JTextField userInput = new JTextField(20);
|
||||||
final JTextField passInput = new JPasswordField(25);
|
final JTextField passInput = new JPasswordField(20);
|
||||||
userInput.addActionListener(new ActionListener() {
|
userInput.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -131,7 +149,7 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if(manager.login(userInput.getText(), passInput.getText(), false)) {
|
if (manager.login(userInput.getText(), passInput.getText(), false)) {
|
||||||
switchState(STATE_SERVER_SELECT);
|
switchState(STATE_SERVER_SELECT);
|
||||||
} else {
|
} else {
|
||||||
Core.verbose("Failed to log in.");
|
Core.verbose("Failed to log in.");
|
||||||
@@ -158,9 +176,9 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
|
|
||||||
public void switchState(int state) {
|
public void switchState(int state) {
|
||||||
removeAll();
|
removeAll();
|
||||||
if(state == STATE_AUTHENTICATION) {
|
if (state == STATE_AUTHENTICATION) {
|
||||||
addLoginPanel();
|
addLoginPanel();
|
||||||
} else if(state == STATE_SERVER_SELECT) {
|
} else if (state == STATE_SERVER_SELECT) {
|
||||||
addServerPanel();
|
addServerPanel();
|
||||||
}
|
}
|
||||||
this.currentState = state;
|
this.currentState = state;
|
||||||
@@ -181,21 +199,44 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||||
|
|
||||||
g.drawImage(background, 0, 0, null);
|
g.drawImage(background, 0, 0, null);
|
||||||
|
float[] scales = { 1f, 1f, 1f, 0.9f };
|
||||||
|
float[] offsets = new float[4];
|
||||||
|
RescaleOp rop = new RescaleOp(scales, offsets, null);
|
||||||
|
g.drawImage(banner, rop, 0, 0);
|
||||||
|
|
||||||
|
g.setStroke(new BasicStroke(5));
|
||||||
|
g.setPaint(Color.WHITE);
|
||||||
|
|
||||||
|
g.draw(new Line2D.Float(0, 0, this.getWidth(), 0));
|
||||||
|
g.draw(new Line2D.Float(0, 0, 0, 120));
|
||||||
|
g.draw(new Line2D.Float(0, 120, this.getWidth(), 120));
|
||||||
|
g.draw(new Line2D.Float(this.getWidth() - 6, 0, this.getWidth() - 6, 120));
|
||||||
|
|
||||||
|
g.setColor(Color.white);
|
||||||
|
|
||||||
|
g.setFont(Fonts.getResource("leelawadee.ttf", 30));
|
||||||
|
g.getFont().deriveFont(Font.BOLD);
|
||||||
|
g.drawString(titleName, 20, 50);
|
||||||
|
|
||||||
|
g.setFont(Fonts.getResource("leelawadee.ttf", 15));
|
||||||
|
g.getFont().deriveFont(Font.ITALIC);
|
||||||
|
g.drawString(sloganText, 20, 85);
|
||||||
|
|
||||||
if (fontMetrics == null) {
|
if (fontMetrics == null) {
|
||||||
fontMetrics = g.getFontMetrics();
|
fontMetrics = g.getFontMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentState == STATE_AUTHENTICATION) {
|
if (currentState == STATE_AUTHENTICATION) {
|
||||||
g.setColor(new Color(74, 74, 72, 100));
|
/*g.setColor(new Color(74, 74, 72, 100));
|
||||||
g.fillRect(loginPanel.getX() - 10, loginPanel.getY(), loginPanel.getWidth() + 20, loginPanel.getHeight());
|
g.fillRect(loginPanel.getX() - 10, loginPanel.getY(), loginPanel.getWidth() + 20, loginPanel.getHeight());
|
||||||
g.setColor(Color.black);
|
g.setColor(Color.black);
|
||||||
g.drawRect(loginPanel.getX() - 10, loginPanel.getY(), loginPanel.getWidth() + 20, loginPanel.getHeight());
|
g.drawRect(loginPanel.getX() - 10, loginPanel.getY(), loginPanel.getWidth() + 20, loginPanel.getHeight());*/
|
||||||
|
g.drawImage(loginBox, loginPanel.getX() - 30, loginPanel.getY() - 22, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
g.setColor(Color.white);
|
g.setColor(Color.white);
|
||||||
|
|
||||||
if(currentState == STATE_LOADING) {
|
if (currentState == STATE_LOADING) {
|
||||||
progressBar.draw(g, (getWidth() / 2) - 200, 220);
|
progressBar.draw(g, (getWidth() / 2) - 200, 220);
|
||||||
g.setFont(new Font("Times New Roman", Font.PLAIN, 14));
|
g.setFont(new Font("Times New Roman", Font.PLAIN, 14));
|
||||||
int x = (getWidth() / 2) - (fontMetrics.stringWidth(state) / 2);
|
int x = (getWidth() / 2) - (fontMetrics.stringWidth(state) / 2);
|
||||||
@@ -203,8 +244,8 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
g.setFont(new Font("Times New Roman", Font.PLAIN, 12));
|
g.setFont(Fonts.getResource("leelawadee.ttf"));
|
||||||
final String version = "v2.1";
|
final String version = Configuration.BOT_VERSION.get();
|
||||||
g.drawString(version,
|
g.drawString(version,
|
||||||
getWidth() - g.getFontMetrics().stringWidth(version) - 10,
|
getWidth() - g.getFontMetrics().stringWidth(version) - 10,
|
||||||
getHeight() - 12);
|
getHeight() - 12);
|
||||||
@@ -212,6 +253,7 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets instance of this panel
|
* Gets instance of this panel
|
||||||
|
*
|
||||||
* @return instance of this panel
|
* @return instance of this panel
|
||||||
*/
|
*/
|
||||||
public static VerboseLoader get(String username, String password) {
|
public static VerboseLoader get(String username, String password) {
|
||||||
@@ -220,6 +262,7 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets instance of this panel
|
* Gets instance of this panel
|
||||||
|
*
|
||||||
* @return instance of this panel
|
* @return instance of this panel
|
||||||
*/
|
*/
|
||||||
public static VerboseLoader get() {
|
public static VerboseLoader get() {
|
||||||
@@ -229,6 +272,7 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the status message and repaints the panel
|
* Updates the status message and repaints the panel
|
||||||
|
*
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
public static void setState(final String message) {
|
public static void setState(final String message) {
|
||||||
@@ -246,5 +290,4 @@ public class VerboseLoader extends JPanel implements ProgressListener {
|
|||||||
public void updateDownloadSpeed(double mbPerSecond) {
|
public void updateDownloadSpeed(double mbPerSecond) {
|
||||||
progressBar.setText(String.format("(%.2fMB/s)", mbPerSecond));
|
progressBar.setText(String.format("(%.2fMB/s)", mbPerSecond));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user