summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/InventoryDialog.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/InventoryDialog.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/InventoryDialog.java')
-rw-r--r--NET/worlds/scape/InventoryDialog.java310
1 files changed, 310 insertions, 0 deletions
diff --git a/NET/worlds/scape/InventoryDialog.java b/NET/worlds/scape/InventoryDialog.java
new file mode 100644
index 0000000..d3b1f93
--- /dev/null
+++ b/NET/worlds/scape/InventoryDialog.java
@@ -0,0 +1,310 @@
+package NET.worlds.scape;
+
+import NET.worlds.console.Console;
+import NET.worlds.console.ImageCanvas;
+import NET.worlds.console.PolledDialog;
+import NET.worlds.network.URL;
+import java.awt.Button;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Label;
+import java.util.Vector;
+
+public class InventoryDialog extends PolledDialog {
+ private InventoryList rightWristItems_;
+ private ImageCanvas rightWristIcon_;
+ private InventoryList leftWristItems_;
+ private ImageCanvas leftWristIcon_;
+ private InventoryList headItems_;
+ private ImageCanvas headIcon_;
+ private InventoryList rightAnkleItems_;
+ private ImageCanvas rightAnkleIcon_;
+ private InventoryList leftAnkleItems_;
+ private ImageCanvas leftAnkleIcon_;
+ private Button okButton_;
+ private Button cancelButton_;
+ private Frame parent_;
+ private static final URL defaultImageURL = URL.make("home:..\\default.gif");
+ private static Object lastPosAndSize;
+
+ public InventoryDialog(Frame frame) {
+ super(frame, null, Console.message("Inventory"), true);
+ InventoryManager im = InventoryManager.getInventoryManager();
+ Vector equippableItems = im.getEquippableItems();
+ Vector equippedItems = im.getEquippedItems();
+ this.parent_ = frame;
+ this.rightWristItems_ = new InventoryList();
+ this.leftWristItems_ = new InventoryList();
+ this.headItems_ = new InventoryList();
+ this.rightAnkleItems_ = new InventoryList();
+ this.leftAnkleItems_ = new InventoryList();
+ this.rightWristIcon_ = new ImageCanvas(defaultImageURL);
+ this.leftWristIcon_ = new ImageCanvas(defaultImageURL);
+ this.headIcon_ = new ImageCanvas(defaultImageURL);
+ this.leftAnkleIcon_ = new ImageCanvas(defaultImageURL);
+ this.rightAnkleIcon_ = new ImageCanvas(defaultImageURL);
+ this.okButton_ = new Button("Ok");
+ this.cancelButton_ = new Button("Cancel");
+
+ for (int i = 0; i < equippableItems.size(); i++) {
+ EquippableItem item = (EquippableItem)equippableItems.elementAt(i);
+ switch (item.getBodyLocation()) {
+ case 4:
+ this.headItems_.add(item);
+ break;
+ case 8:
+ this.rightWristItems_.add(item);
+ break;
+ case 13:
+ this.leftWristItems_.add(item);
+ break;
+ case 17:
+ this.rightAnkleItems_.add(item);
+ break;
+ case 21:
+ this.leftAnkleItems_.add(item);
+ }
+ }
+
+ for (int i = 0; i < equippedItems.size(); i++) {
+ EquippableItem item = (EquippableItem)equippedItems.elementAt(i);
+ switch (item.getBodyLocation()) {
+ case 4:
+ this.headItems_.selectItem(item);
+ break;
+ case 8:
+ this.rightWristItems_.selectItem(item);
+ break;
+ case 13:
+ this.leftWristItems_.selectItem(item);
+ break;
+ case 17:
+ this.rightAnkleItems_.selectItem(item);
+ break;
+ case 21:
+ this.leftAnkleItems_.selectItem(item);
+ }
+ }
+
+ this.ready();
+ }
+
+ @Override
+ protected void build() {
+ this.setBackground(Color.cyan);
+ this.setForeground(Color.black);
+ GridBagLayout gbag = new GridBagLayout();
+ this.setLayout(gbag);
+ GridBagConstraints c = new GridBagConstraints();
+ Font f1 = new Font(Console.message("ConsoleFont"), 1, 18);
+ Font f2 = new Font(Console.message("ConsoleFont"), 0, 12);
+ Label invLabel = new Label("Inventory");
+ c.gridx = 2;
+ c.gridy = 0;
+ c.weightx = 3.0;
+ invLabel.setFont(f1);
+ this.add(gbag, invLabel, c);
+ Label rwLabel = new Label("Right Hand");
+ c.gridx = 4;
+ c.gridy = 4;
+ c.weightx = 1.0;
+ rwLabel.setFont(f2);
+ this.add(gbag, rwLabel, c);
+ c.gridy = 5;
+ c.weighty = 1.0;
+ this.rightWristItems_.setFont(f2);
+ this.add(gbag, this.rightWristItems_, c);
+ c.gridx = 3;
+ c.gridy = 5;
+ c.weighty = 1.0;
+ c.weightx = 1.0;
+ this.add(gbag, this.rightWristIcon_, c);
+ Label lwLabel = new Label("Left Hand");
+ c.gridx = 0;
+ c.gridy = 4;
+ c.weighty = 1.0;
+ lwLabel.setFont(f2);
+ this.add(gbag, lwLabel, c);
+ c.gridy = 5;
+ c.weighty = 1.0;
+ this.leftWristItems_.setFont(f2);
+ this.add(gbag, this.leftWristItems_, c);
+ c.gridx = 1;
+ c.gridy = 5;
+ c.weighty = 1.0;
+ c.weightx = 1.0;
+ this.add(gbag, this.leftWristIcon_, c);
+ Label headLabel = new Label("Head");
+ c.gridx = 2;
+ c.gridy = 2;
+ c.weighty = 1.0;
+ headLabel.setFont(f2);
+ this.add(gbag, headLabel, c);
+ c.gridy = 3;
+ c.weighty = 1.0;
+ this.headItems_.setFont(f2);
+ this.add(gbag, this.headItems_, c);
+ c.gridx = 2;
+ c.gridy = 4;
+ c.weighty = 1.0;
+ c.weightx = 1.0;
+ this.add(gbag, this.headIcon_, c);
+ Label raLabel = new Label("Right Foot");
+ c.gridx = 4;
+ c.gridy = 6;
+ c.weightx = 1.0;
+ raLabel.setFont(f2);
+ this.add(gbag, raLabel, c);
+ c.gridy = 7;
+ c.weighty = 0.0;
+ this.rightAnkleItems_.setFont(f2);
+ this.add(gbag, this.rightAnkleItems_, c);
+ c.gridx = 3;
+ c.gridy = 7;
+ c.weighty = 1.0;
+ c.weightx = 1.0;
+ this.add(gbag, this.rightAnkleIcon_, c);
+ Label laLabel = new Label("Left Foot");
+ c.gridx = 0;
+ c.gridy = 6;
+ c.weighty = 1.0;
+ laLabel.setFont(f2);
+ this.add(gbag, laLabel, c);
+ c.gridy = 7;
+ c.weighty = 0.0;
+ this.leftAnkleItems_.setFont(f2);
+ this.add(gbag, this.leftAnkleItems_, c);
+ c.gridx = 1;
+ c.gridy = 7;
+ c.weighty = 1.0;
+ c.weightx = 1.0;
+ this.add(gbag, this.leftAnkleIcon_, c);
+ c.gridx = 0;
+ c.gridy = 10;
+ c.weightx = 2.0;
+ c.weighty = 1.0;
+ this.okButton_.setFont(f2);
+ this.add(gbag, this.okButton_, c);
+ c.gridx = 4;
+ c.gridy = 10;
+ this.cancelButton_.setFont(f2);
+ this.add(gbag, this.cancelButton_, c);
+ this.setSize(360, 300);
+ }
+
+ @Override
+ public synchronized boolean done(boolean confirmed) {
+ Vector equippedItems = new Vector();
+ EquippableItem eItem;
+ if ((eItem = this.rightWristItems_.getSelected()) != null) {
+ equippedItems.add(eItem);
+ }
+
+ if ((eItem = this.leftWristItems_.getSelected()) != null) {
+ equippedItems.add(eItem);
+ }
+
+ if ((eItem = this.headItems_.getSelected()) != null) {
+ equippedItems.add(eItem);
+ }
+
+ if ((eItem = this.leftAnkleItems_.getSelected()) != null) {
+ equippedItems.add(eItem);
+ }
+
+ if ((eItem = this.rightAnkleItems_.getSelected()) != null) {
+ equippedItems.add(eItem);
+ }
+
+ if (confirmed) {
+ InventoryManager im = InventoryManager.getInventoryManager();
+ im.setEquippedItems(equippedItems);
+ }
+
+ return super.done(confirmed);
+ }
+
+ @Override
+ public boolean handleEvent(java.awt.Event event) {
+ return super.handleEvent(event);
+ }
+
+ @Override
+ public boolean action(java.awt.Event event, Object what) {
+ Object target = event.target;
+ URL imageURL = defaultImageURL;
+ if (target == this.leftWristItems_) {
+ InventoryItem item = this.leftWristItems_.getSelected();
+ if (item != null) {
+ imageURL = item.getItemGraphicLocation();
+ }
+
+ this.setIcon(this.leftWristIcon_, imageURL);
+ return true;
+ } else if (target == this.rightWristItems_) {
+ InventoryItem item = this.rightWristItems_.getSelected();
+ if (item != null) {
+ imageURL = item.getItemGraphicLocation();
+ }
+
+ this.setIcon(this.rightWristIcon_, imageURL);
+ return true;
+ } else if (target == this.headItems_) {
+ InventoryItem item = this.headItems_.getSelected();
+ if (item != null) {
+ imageURL = item.getItemGraphicLocation();
+ }
+
+ this.setIcon(this.headIcon_, imageURL);
+ return true;
+ } else if (target == this.leftAnkleItems_) {
+ InventoryItem item = this.leftAnkleItems_.getSelected();
+ if (item != null) {
+ imageURL = item.getItemGraphicLocation();
+ }
+
+ this.setIcon(this.leftAnkleIcon_, imageURL);
+ return true;
+ } else if (target == this.rightAnkleItems_) {
+ InventoryItem item = this.rightAnkleItems_.getSelected();
+ if (item != null) {
+ imageURL = item.getItemGraphicLocation();
+ }
+
+ this.setIcon(this.rightAnkleIcon_, imageURL);
+ return true;
+ } else if (target == this.okButton_) {
+ return this.done(true);
+ } else {
+ return target == this.cancelButton_ ? this.done(false) : false;
+ }
+ }
+
+ private void setIcon(ImageCanvas ic, URL newLoc) {
+ ic.setNewImage(newLoc, this.getGraphics());
+ this.repaint();
+ }
+
+ @Override
+ public void savePosAndSize(Object state) {
+ lastPosAndSize = state;
+ }
+
+ @Override
+ public Object restorePosAndSize() {
+ return lastPosAndSize;
+ }
+
+ @Override
+ public boolean keyDown(java.awt.Event event, int key) {
+ return key == 27 ? this.done(false) : super.keyDown(event, key);
+ }
+
+ @Override
+ protected synchronized void activeCallback() {
+ this.notify();
+ }
+}