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(); ObjectDefinition.clear();
NpcDefinition.clear(); NpcDefinition.clear();
ItemDefinition.clear(); ItemDefinition.clear();
FloorDefinition.underlays = null;
FloorDefinition.overlays = null; FloorDefinition.overlays = null;
IdentityKit.kits = null; IdentityKit.kits = null;
Widget.interfaceCache = null; Widget.interfaceCache = null;
@@ -7936,6 +7935,16 @@ public class Client extends GameApplet {
private void login(String name, String password, boolean reconnecting) { private void login(String name, String password, boolean reconnecting) {
SignLink.setError(name); SignLink.setError(name);
try { 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) { if (!reconnecting) {
firstLoginMessage = ""; firstLoginMessage = "";
secondLoginMessage = "Connecting to server..."; secondLoginMessage = "Connecting to server...";
+1 -1
View File
@@ -281,7 +281,7 @@ public class GameApplet extends Applet implements Runnable, MouseListener,
Client.updateChatbox = true; Client.updateChatbox = true;
} }
} else { } else {
if(Client.loggedIn && viewport.contains(p)) { if(Client.loggedIn && viewport.contains(p) && Client.openInterfaceId == -1) {
if (Client.cameraZoom < 1800 && rotation == 1) { if (Client.cameraZoom < 1800 && rotation == 1) {
Client.cameraZoom = Client.cameraZoom + 20; Client.cameraZoom = Client.cameraZoom + 20;
} else if (Client.cameraZoom > 20 && rotation == -1) { } 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 java.nio.ByteBuffer;
import org.rebotted.cache.FileArchive; import org.rebotted.cache.FileArchive;
import org.rebotted.io.Buffer;
public class FloorDefinition { public class FloorDefinition {
public static FloorDefinition[] overlays; public static FloorDefinition[] overlays;
public static FloorDefinition[] underlays;
public int texture; public int texture;
public int rgb; public int rgb;
@@ -33,26 +33,17 @@ public class FloorDefinition {
} }
public static void unpackConfig(FileArchive streamLoader) { public static void unpackConfig(FileArchive streamLoader) {
ByteBuffer buffer = ByteBuffer.wrap(streamLoader.readFile("flo.dat")); Buffer buffer = new Buffer(streamLoader.readFile("flo.dat"));
int underlayAmount = buffer.getShort(); int underlayAmount = buffer.readUShort();
System.out.println("Underlay Floors Loaded: "+underlayAmount); System.out.println("Underlay Floors Loaded: "+underlayAmount);
underlays = new FloorDefinition[underlayAmount]; if(overlays == null) {
for (int i = 0; i < underlayAmount; i++) { overlays = new FloorDefinition[underlayAmount];
if (underlays[i] == null) {
underlays[i] = new FloorDefinition();
}
underlays[i].readValuesUnderlay(buffer);
underlays[i].generateHsl();
} }
int overlayAmount = buffer.getShort(); for (int i = 0; i < underlayAmount; i++) {
System.out.println("Overlay Floors Loaded: "+overlayAmount);
overlays = new FloorDefinition[overlayAmount];
for (int i = 0; i < overlayAmount; i++) {
if (overlays[i] == null) { if (overlays[i] == null) {
overlays[i] = new FloorDefinition(); overlays[i] = new FloorDefinition();
} }
overlays[i].readValuesOverlay(buffer); overlays[i].readValuesOverlay(buffer);
overlays[i].generateHsl();
} }
} }
@@ -66,32 +57,25 @@ public class FloorDefinition {
rgbToHsl(rgb); rgbToHsl(rgb);
} }
private void readValuesUnderlay(ByteBuffer buffer) { private void readValuesOverlay(Buffer buffer) {
for (;;) { for (;;) {
int opcode = buffer.get(); int opcode = buffer.readUnsignedByte();
if (opcode == 0) { if (opcode == 0) {
break; break;
} else if (opcode == 1) { } else if (opcode == 1) {
rgb = ((buffer.get() & 0xff) << 16) + ((buffer.get() & 0xff) << 8) + (buffer.get() & 0xff); rgb = buffer.read3Bytes();
} else { rgbToHsl(rgb);
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);
} else if (opcode == 2) { } else if (opcode == 2) {
texture = buffer.get() & 0xff; texture = buffer.readUnsignedByte();
} else if (opcode == 3) {
} else if (opcode == 5) { } else if (opcode == 5) {
occlude = false; occlude = false;
} else if(opcode == 6) {
buffer.readString();
} else if (opcode == 7) { } else if (opcode == 7) {
anotherRgb = ((buffer.get() & 0xff) << 16) + ((buffer.get() & 0xff) << 8) + (buffer.get() & 0xff); anotherRgb = buffer.read3Bytes();
rgbToHsl(anotherRgb);
} else { } else {
System.out.println("Error unrecognised overlay code: " + opcode); System.out.println("Error unrecognised overlay code: " + opcode);
} }
@@ -27,6 +27,12 @@ public final class Buffer extends Cacheable {
return buffer; 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) { public final int readUTriByte(int i) {
currentPosition += 3; currentPosition += 3;
return (0xff & payload[currentPosition - 3] << 16) return (0xff & payload[currentPosition - 3] << 16)
@@ -176,7 +176,7 @@ public final class ResourceProvider extends Provider implements Runnable {
byte[] data = archive.readFile("map_index"); byte[] data = archive.readFile("map_index");
Buffer stream = new Buffer(data); Buffer stream = new Buffer(data);
int j1 = stream.readUShort();//mapData.length / 6; int j1 = data.length / 7;
areas = new int[j1]; areas = new int[j1];
mapFiles = new int[j1]; mapFiles = new int[j1];
landscapes = new int[j1]; landscapes = new int[j1];
@@ -186,6 +186,7 @@ public final class ResourceProvider extends Provider implements Runnable {
areas[i2] = stream.readUShort(); areas[i2] = stream.readUShort();
mapFiles[i2] = stream.readUShort(); mapFiles[i2] = stream.readUShort();
landscapes[i2] = stream.readUShort(); landscapes[i2] = stream.readUShort();
membersArea[i2] = stream.readUnsignedByte();
} }
System.out.println("Map Amount: " + file_amounts[3] + ""); System.out.println("Map Amount: " + file_amounts[3] + "");
@@ -120,10 +120,7 @@ public final class MapRegion {
if (k9 >= 0 && k9 < regionSizeX) { if (k9 >= 0 && k9 < regionSizeX) {
int l12 = underlays[z][k9][i8] & 0xff; int l12 = underlays[z][k9][i8] & 0xff;
if (l12 > 0) { if (l12 > 0) {
if (l12 > FloorDefinition.underlays.length) { FloorDefinition flo = FloorDefinition.overlays[l12 - 1];
l12 = FloorDefinition.underlays.length;
}
FloorDefinition flo = FloorDefinition.underlays[l12 - 1];
hues[i8] += flo.blendHue; hues[i8] += flo.blendHue;
saturations[i8] += flo.saturation; saturations[i8] += flo.saturation;
luminances[i8] += flo.luminance; luminances[i8] += flo.luminance;
@@ -135,7 +132,7 @@ public final class MapRegion {
if (i13 >= 0 && i13 < regionSizeX) { if (i13 >= 0 && i13 < regionSizeX) {
int i14 = underlays[z][i13][i8] & 0xff; int i14 = underlays[z][i13][i8] & 0xff;
if (i14 > 0) { if (i14 > 0) {
FloorDefinition flo_1 = FloorDefinition.underlays[i14 - 1]; FloorDefinition flo_1 = FloorDefinition.overlays[i14 - 1];
hues[i8] -= flo_1.blendHue; hues[i8] -= flo_1.blendHue;
saturations[i8] -= flo_1.saturation; saturations[i8] -= flo_1.saturation;
luminances[i8] -= flo_1.luminance; 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()) { switch (e.getActionCommand().toLowerCase()) {
case "run": case "run":
if (ScriptHandler.getInstance().getScriptState() == ScriptHandler.State.STOPPED) { 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) { } else if (ScriptHandler.getInstance().getScriptState() == ScriptHandler.State.PAUSE) {
ScriptHandler.getInstance().setScriptState(ScriptHandler.State.RUNNING); ScriptHandler.getInstance().setScriptState(ScriptHandler.State.RUNNING);
setRunning(); 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; package org.rebotted.ui.script;
import org.rebotted.directory.DirectoryManager;
import org.rebotted.script.ScriptHandler; import org.rebotted.script.ScriptHandler;
import org.rebotted.script.loader.ScriptLoader; import org.rebotted.script.loader.ScriptLoader;
import org.rebotted.script.scriptdata.ScriptData; import org.rebotted.script.scriptdata.ScriptData;
import org.rebotted.script.types.Script; import org.rebotted.script.types.Script;
import org.rebotted.ui.BotFrame; import org.rebotted.ui.BotFrame;
import org.rebotted.ui.menu.BotMenuBar; import org.rebotted.ui.themes.SubstanceDark;
import javax.swing.*; import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
import java.awt.*; import java.awt.*;
import java.awt.event.FocusAdapter; import java.awt.event.ActionEvent;
import java.awt.event.FocusEvent; import java.util.ArrayList;
import java.awt.event.KeyAdapter; import java.util.List;
import java.awt.event.KeyEvent;
/**
* @author Ethan
*/
public class ScriptSelector extends JFrame { public class ScriptSelector extends JFrame {
private JScrollPane scrollPane1;
private static final long serialVersionUID = 1L; private JTable scriptTable;
private final ScriptLoader scriptLoader; private JButton startButton;
private JTextField searchField; private JComboBox accounts;
private JComboBox<String> accounts; private JTextField search;
private JPanel topPanel; private ScriptLoader scriptLoader;
private JPanel scriptPanel; private List<ScriptData> scripts;
private JScrollPane scrollPane;
public ScriptSelector(ScriptLoader scriptLoader) { public ScriptSelector(ScriptLoader scriptLoader) {
super("Script Selector");
this.scriptLoader = scriptLoader; this.scriptLoader = scriptLoader;
setResizable(false); scripts = scriptLoader.getScripts();
searchField = new JTextField(20); initComponents();
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);
} }
private void startScript(ActionEvent e) {
private void loadScripts() { final int category = 0;
scriptPanel.removeAll(); final int name = 1;
java.util.List<ScriptData> scripts = scriptLoader.getScripts(); final int version = 2;
final int desc = 3;
final int width = 170; final int author = 4;
final int height = 115; final int row = scriptTable.getSelectedRow();
final int spacing = 3; final String categoryName = scriptTable.getModel().getValueAt(row, category).toString();
final int scriptPerRow = 3; final String scriptName = scriptTable.getModel().getValueAt(row, name).toString();
int realIndex = 0; final String versionString = scriptTable.getModel().getValueAt(row, version).toString();
for (int scriptIndex = 0; scriptIndex < scripts.size(); scriptIndex++) { final String descString = scriptTable.getModel().getValueAt(row, desc).toString();
final ScriptData scriptData = scripts.get(scriptIndex); final String authorName = scriptTable.getModel().getValueAt(row, author).toString();
final ScriptPanel panel = new ScriptPanel(scriptData); for(ScriptData scriptData : scripts) {
int col = realIndex / scriptPerRow; if(scriptData.getName().equals(scriptName) && scriptData.getAuthor().equals(authorName)) {
int row = realIndex - (col * scriptPerRow); if(scriptData.getDesc().equals(descString) && String.valueOf(scriptData.getVersion()).equals(versionString)) {
int x = row * width + spacing; if(scriptData.getSkillCategory().getName().equals(categoryName)) {
int y = col * height + spacing; startScript(scriptData);
panel.setBounds(x, y, width, height); }
panel.getButton().addActionListener(e -> { }
startScript(scriptData); }
dispose();
});
scriptPanel.add(panel);
realIndex++;
} }
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) { private void startScript(ScriptData scriptData) {
@@ -121,5 +140,6 @@ public class ScriptSelector extends JFrame {
} }
ScriptHandler.getInstance().start(script, scriptData); ScriptHandler.getInstance().start(script, scriptData);
BotFrame.setRunning(); BotFrame.setRunning();
dispose();
} }
} }