06 Maps/Floors/Objects - Swing ScriptSelector - minor bug fixes

This commit is contained in:
Ethan
2019-12-17 04:20:52 -06:00
parent e38ac33066
commit 67e801cf9c
15 changed files with 151 additions and 170 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10 -1
View File
@@ -6316,7 +6316,6 @@ public class Client extends GameApplet {
ObjectDefinition.clear();
NpcDefinition.clear();
ItemDefinition.clear();
FloorDefinition.underlays = null;
FloorDefinition.overlays = null;
IdentityKit.kits = null;
Widget.interfaceCache = null;
@@ -7936,6 +7935,16 @@ public class Client extends GameApplet {
private void login(String name, String password, boolean reconnecting) {
SignLink.setError(name);
try {
if(name.length() < 3) {
firstLoginMessage = "";
secondLoginMessage = "Your username is too short.";
return;
}
if(password.length() < 3) {
firstLoginMessage = "";
secondLoginMessage = "Your password is too short.";
return;
}
if (!reconnecting) {
firstLoginMessage = "";
secondLoginMessage = "Connecting to server...";
+1 -1
View File
@@ -281,7 +281,7 @@ public class GameApplet extends Applet implements Runnable, MouseListener,
Client.updateChatbox = true;
}
} else {
if(Client.loggedIn && viewport.contains(p)) {
if(Client.loggedIn && viewport.contains(p) && Client.openInterfaceId == -1) {
if (Client.cameraZoom < 1800 && rotation == 1) {
Client.cameraZoom = Client.cameraZoom + 20;
} else if (Client.cameraZoom > 20 && rotation == -1) {
+17 -33
View File
@@ -3,12 +3,12 @@ package org.rebotted.cache.def;
import java.nio.ByteBuffer;
import org.rebotted.cache.FileArchive;
import org.rebotted.io.Buffer;
public class FloorDefinition {
public static FloorDefinition[] overlays;
public static FloorDefinition[] underlays;
public int texture;
public int rgb;
@@ -33,26 +33,17 @@ public class FloorDefinition {
}
public static void unpackConfig(FileArchive streamLoader) {
ByteBuffer buffer = ByteBuffer.wrap(streamLoader.readFile("flo.dat"));
int underlayAmount = buffer.getShort();
Buffer buffer = new Buffer(streamLoader.readFile("flo.dat"));
int underlayAmount = buffer.readUShort();
System.out.println("Underlay Floors Loaded: "+underlayAmount);
underlays = new FloorDefinition[underlayAmount];
for (int i = 0; i < underlayAmount; i++) {
if (underlays[i] == null) {
underlays[i] = new FloorDefinition();
}
underlays[i].readValuesUnderlay(buffer);
underlays[i].generateHsl();
if(overlays == null) {
overlays = new FloorDefinition[underlayAmount];
}
int overlayAmount = buffer.getShort();
System.out.println("Overlay Floors Loaded: "+overlayAmount);
overlays = new FloorDefinition[overlayAmount];
for (int i = 0; i < overlayAmount; i++) {
for (int i = 0; i < underlayAmount; i++) {
if (overlays[i] == null) {
overlays[i] = new FloorDefinition();
}
overlays[i].readValuesOverlay(buffer);
overlays[i].generateHsl();
}
}
@@ -66,32 +57,25 @@ public class FloorDefinition {
rgbToHsl(rgb);
}
private void readValuesUnderlay(ByteBuffer buffer) {
private void readValuesOverlay(Buffer buffer) {
for (;;) {
int opcode = buffer.get();
int opcode = buffer.readUnsignedByte();
if (opcode == 0) {
break;
} else if (opcode == 1) {
rgb = ((buffer.get() & 0xff) << 16) + ((buffer.get() & 0xff) << 8) + (buffer.get() & 0xff);
} else {
System.out.println("Error unrecognised underlay code: " + opcode);
}
}
}
private void readValuesOverlay(ByteBuffer buffer) {
for (;;) {
int opcode = buffer.get();
if (opcode == 0) {
break;
} else if (opcode == 1) {
rgb = ((buffer.get() & 0xff) << 16) + ((buffer.get() & 0xff) << 8) + (buffer.get() & 0xff);
rgb = buffer.read3Bytes();
rgbToHsl(rgb);
} else if (opcode == 2) {
texture = buffer.get() & 0xff;
texture = buffer.readUnsignedByte();
} else if (opcode == 3) {
} else if (opcode == 5) {
occlude = false;
} else if(opcode == 6) {
buffer.readString();
} else if (opcode == 7) {
anotherRgb = ((buffer.get() & 0xff) << 16) + ((buffer.get() & 0xff) << 8) + (buffer.get() & 0xff);
anotherRgb = buffer.read3Bytes();
rgbToHsl(anotherRgb);
} else {
System.out.println("Error unrecognised overlay code: " + opcode);
}
@@ -27,6 +27,12 @@ public final class Buffer extends Cacheable {
return buffer;
}
public int read3Bytes() {
currentPosition += 3;
return ((payload[currentPosition - 3] & 0xff) << 16) + ((payload[currentPosition - 2] & 0xff) << 8) + (payload[currentPosition - 1] & 0xff);
}
public final int readUTriByte(int i) {
currentPosition += 3;
return (0xff & payload[currentPosition - 3] << 16)
@@ -176,7 +176,7 @@ public final class ResourceProvider extends Provider implements Runnable {
byte[] data = archive.readFile("map_index");
Buffer stream = new Buffer(data);
int j1 = stream.readUShort();//mapData.length / 6;
int j1 = data.length / 7;
areas = new int[j1];
mapFiles = new int[j1];
landscapes = new int[j1];
@@ -186,6 +186,7 @@ public final class ResourceProvider extends Provider implements Runnable {
areas[i2] = stream.readUShort();
mapFiles[i2] = stream.readUShort();
landscapes[i2] = stream.readUShort();
membersArea[i2] = stream.readUnsignedByte();
}
System.out.println("Map Amount: " + file_amounts[3] + "");
@@ -120,10 +120,7 @@ public final class MapRegion {
if (k9 >= 0 && k9 < regionSizeX) {
int l12 = underlays[z][k9][i8] & 0xff;
if (l12 > 0) {
if (l12 > FloorDefinition.underlays.length) {
l12 = FloorDefinition.underlays.length;
}
FloorDefinition flo = FloorDefinition.underlays[l12 - 1];
FloorDefinition flo = FloorDefinition.overlays[l12 - 1];
hues[i8] += flo.blendHue;
saturations[i8] += flo.saturation;
luminances[i8] += flo.luminance;
@@ -135,7 +132,7 @@ public final class MapRegion {
if (i13 >= 0 && i13 < regionSizeX) {
int i14 = underlays[z][i13][i8] & 0xff;
if (i14 > 0) {
FloorDefinition flo_1 = FloorDefinition.underlays[i14 - 1];
FloorDefinition flo_1 = FloorDefinition.overlays[i14 - 1];
hues[i8] -= flo_1.blendHue;
saturations[i8] -= flo_1.saturation;
luminances[i8] -= flo_1.luminance;
+1 -1
View File
@@ -64,7 +64,7 @@ public final class BotFrame extends JFrame implements ActionListener {
switch (e.getActionCommand().toLowerCase()) {
case "run":
if (ScriptHandler.getInstance().getScriptState() == ScriptHandler.State.STOPPED) {
new ScriptSelector(new ScriptLoader(client.getApiData()));
new ScriptSelector(new ScriptLoader(client.getApiData())).setVisible(true);
} else if (ScriptHandler.getInstance().getScriptState() == ScriptHandler.State.PAUSE) {
ScriptHandler.getInstance().setScriptState(ScriptHandler.State.RUNNING);
setRunning();
@@ -1,36 +0,0 @@
package org.rebotted.ui.script;
import org.rebotted.script.scriptdata.ScriptData;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import java.awt.*;
public class ScriptPanel extends JPanel {
private static final long serialVersionUID = -5181188196122580695L;
private JButton button;
public ScriptPanel(final ScriptData scriptData) {
setLayout(new BorderLayout());
setToolTipText(scriptData.getDesc());
button = new JButton("Start");
add(button, BorderLayout.SOUTH);
final JLabel scriptName = new JLabel(scriptData.getName());
scriptName.setHorizontalAlignment(JLabel.CENTER);
add(scriptName, BorderLayout.NORTH);
setBorder(new EtchedBorder());
}
public JButton getButton() {
return button;
}
}
@@ -1,115 +1,134 @@
package org.rebotted.ui.script;
import org.rebotted.directory.DirectoryManager;
import org.rebotted.script.ScriptHandler;
import org.rebotted.script.loader.ScriptLoader;
import org.rebotted.script.scriptdata.ScriptData;
import org.rebotted.script.types.Script;
import org.rebotted.ui.BotFrame;
import org.rebotted.ui.menu.BotMenuBar;
import org.rebotted.ui.themes.SubstanceDark;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import java.awt.*;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;
/**
* @author Ethan
*/
public class ScriptSelector extends JFrame {
private static final long serialVersionUID = 1L;
private final ScriptLoader scriptLoader;
private JTextField searchField;
private JComboBox<String> accounts;
private JPanel topPanel;
private JPanel scriptPanel;
private JScrollPane scrollPane;
private JScrollPane scrollPane1;
private JTable scriptTable;
private JButton startButton;
private JComboBox accounts;
private JTextField search;
private ScriptLoader scriptLoader;
private List<ScriptData> scripts;
public ScriptSelector(ScriptLoader scriptLoader) {
super("Script Selector");
this.scriptLoader = scriptLoader;
setResizable(false);
searchField = new JTextField(20);
searchField.setForeground(Color.LIGHT_GRAY);
searchField.setText("Search");
searchField.setMaximumSize(new Dimension(100, 30));
searchField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
super.focusGained(e);
searchField.setForeground(Color.BLACK);
searchField.setText("");
}
@Override
public void focusLost(FocusEvent e) {
super.focusLost(e);
searchField.setForeground(Color.LIGHT_GRAY);
searchField.setText("Search");
}
});
searchField.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
super.keyTyped(e);
}
});
accounts = new JComboBox<>();
topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
topPanel.add(accounts);
topPanel.add(Box.createHorizontalGlue());
topPanel.add(searchField);
scriptPanel = new JPanel();
scriptPanel.setLayout(null);
scrollPane = new JScrollPane(scriptPanel);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(topPanel, BorderLayout.NORTH);
getContentPane().add(scrollPane, BorderLayout.CENTER);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setSize(535, 405);
loadScripts();
setVisible(true);
scripts = scriptLoader.getScripts();
initComponents();
}
private void loadScripts() {
scriptPanel.removeAll();
java.util.List<ScriptData> scripts = scriptLoader.getScripts();
final int width = 170;
final int height = 115;
final int spacing = 3;
final int scriptPerRow = 3;
int realIndex = 0;
for (int scriptIndex = 0; scriptIndex < scripts.size(); scriptIndex++) {
final ScriptData scriptData = scripts.get(scriptIndex);
final ScriptPanel panel = new ScriptPanel(scriptData);
int col = realIndex / scriptPerRow;
int row = realIndex - (col * scriptPerRow);
int x = row * width + spacing;
int y = col * height + spacing;
panel.setBounds(x, y, width, height);
panel.getButton().addActionListener(e -> {
startScript(scriptData);
dispose();
});
scriptPanel.add(panel);
realIndex++;
private void startScript(ActionEvent e) {
final int category = 0;
final int name = 1;
final int version = 2;
final int desc = 3;
final int author = 4;
final int row = scriptTable.getSelectedRow();
final String categoryName = scriptTable.getModel().getValueAt(row, category).toString();
final String scriptName = scriptTable.getModel().getValueAt(row, name).toString();
final String versionString = scriptTable.getModel().getValueAt(row, version).toString();
final String descString = scriptTable.getModel().getValueAt(row, desc).toString();
final String authorName = scriptTable.getModel().getValueAt(row, author).toString();
for(ScriptData scriptData : scripts) {
if(scriptData.getName().equals(scriptName) && scriptData.getAuthor().equals(authorName)) {
if(scriptData.getDesc().equals(descString) && String.valueOf(scriptData.getVersion()).equals(versionString)) {
if(scriptData.getSkillCategory().getName().equals(categoryName)) {
startScript(scriptData);
}
}
}
}
searchField.setText("");
scriptPanel.setPreferredSize(new Dimension(535, (int) (Math.ceil((Double.valueOf(scriptPanel.getComponentCount()) / 3.0)) * height)));
}
private void initComponents() {
scrollPane1 = new JScrollPane();
startButton = new JButton();
accounts = new JComboBox();
search = new JTextField();
setTitle("2006Rebotted - Script Selector");
setResizable(false);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
final Container contentPane = getContentPane();
contentPane.setLayout(null);
final java.util.List<String> columns = new ArrayList<>();
final java.util.List<String[]> values = new ArrayList<>();
columns.add("Category");
columns.add("Script");
columns.add("Version");
columns.add("Description");
columns.add("Author");
for (ScriptData scriptData : scripts) {
values.add(new String[]{scriptData.getSkillCategory().getName(), scriptData.getName(), String.valueOf(scriptData.getVersion()), scriptData.getDesc(), scriptData.getAuthor()});
}
final TableModel tableModel = new DefaultTableModel(values.toArray(new Object[][]{}), columns.toArray());
scriptTable = new JTable(tableModel);
scriptTable.setDefaultEditor(Object.class, null);
TableColumnModel cm = scriptTable.getColumnModel();
cm.getColumn(0).setMinWidth(110);
cm.getColumn(0).setMaxWidth(110);
cm.getColumn(1).setMinWidth(180);
cm.getColumn(1).setMaxWidth(180);
cm.getColumn(2).setMinWidth(60);
cm.getColumn(2).setMaxWidth(60);
cm.getColumn(3).setMinWidth(40);
cm.getColumn(4).setMinWidth(100);
cm.getColumn(4).setMaxWidth(100);
scrollPane1.setViewportView(scriptTable);
contentPane.add(scrollPane1);
scrollPane1.setBounds(0, 0, 640, 280);
startButton.setText("Start");
startButton.addActionListener(e -> startScript(e));
contentPane.add(startButton);
startButton.setBounds(545, 280, 93, startButton.getPreferredSize().height);
contentPane.add(accounts);
accounts.setBounds(5, 280, 250, accounts.getPreferredSize().height);
contentPane.add(search);
search.setBounds(270, 281, 255, search.getPreferredSize().height);
final Dimension preferredSize = new Dimension();
for (int i = 0; i < contentPane.getComponentCount(); i++) {
Rectangle bounds = contentPane.getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = contentPane.getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
contentPane.setMinimumSize(preferredSize);
contentPane.setPreferredSize(preferredSize);
setSize(645, 340);
setLocationRelativeTo(getOwner());
}
private void startScript(ScriptData scriptData) {
@@ -121,5 +140,6 @@ public class ScriptSelector extends JFrame {
}
ScriptHandler.getInstance().start(script, scriptData);
BotFrame.setRunning();
dispose();
}
}