diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/ActionsPart.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/ActionsPart.java')
| -rw-r--r-- | NET/worlds/console/ActionsPart.java | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/NET/worlds/console/ActionsPart.java b/NET/worlds/console/ActionsPart.java new file mode 100644 index 0000000..aed4c7c --- /dev/null +++ b/NET/worlds/console/ActionsPart.java @@ -0,0 +1,122 @@ +package NET.worlds.console; + +import NET.worlds.scape.FrameEvent; +import NET.worlds.scape.InventoryAction; +import NET.worlds.scape.InventoryItem; +import NET.worlds.scape.InventoryManager; +import NET.worlds.scape.Pilot; +import java.awt.Container; +import java.awt.Event; +import java.util.Vector; + +public class ActionsPart implements FramePart { + static int actionToPerform = -1; + private Pilot curPilot; + private Vector<String> curAnimations; + private int numPilotAnims; + private static ActionsPart activePart; + private static ActionDialog dialog; + static boolean showDialog; + + public void present() { + showDialog = true; + this.curPilot = null; + } + + @Override + public void activate(Console c, Container f, Console prev) { + } + + @Override + public void deactivate() { + } + + @Override + public boolean action(Event event, Object what) { + return false; + } + + public static boolean listEquals(Vector<String> a, Vector<String> b) { + if (a != null && b != null) { + if (a.size() != b.size()) { + return false; + } else { + int i = a.size(); + + while (--i >= 0) { + Object ao = a.elementAt(i); + Object bo = b.elementAt(i); + if (ao == null || bo == null) { + if (ao != null || bo != null) { + return false; + } + } else if (!ao.equals(bo)) { + return false; + } + } + + return true; + } + } else { + return a == null == (b == null); + } + } + + public static void updateActionDialog() { + if (activePart != null && dialog != null && showDialog && dialog.isVisible()) { + Main.register(new MainCallback() { + @Override + public void mainCallback() { + ActionsPart.activePart.regenActionDialog(); + Main.unregister(this); + } + }); + } + } + + public void regenActionDialog() { + Vector<String> newAnimations = this.curPilot.getAnimationList(); + this.numPilotAnims = newAnimations.size(); + Vector<InventoryItem> specials = InventoryManager.getInventoryManager().getInventoryActionList(); + + for (int i = 0; i < specials.size(); i++) { + InventoryAction act = (InventoryAction)specials.elementAt(i); + newAnimations.addElement(act.getItemName()); + } + + if (dialog != null) { + boolean showWas = showDialog; + if (showWas && dialog.isVisible() && listEquals(newAnimations, this.curAnimations)) { + return; + } + + dialog.done(true); + showDialog = showWas; + } + + this.curAnimations = newAnimations; + if (showDialog) { + dialog = new ActionDialog(this.curAnimations); + } + } + + @Override + public synchronized boolean handle(FrameEvent f) { + Pilot pilot = Pilot.getActive(); + if (pilot != this.curPilot) { + this.curPilot = pilot; + activePart = this; + this.regenActionDialog(); + } else if (actionToPerform != -1 && actionToPerform < this.curAnimations.size()) { + String act = this.curAnimations.elementAt(actionToPerform); + if (actionToPerform < this.numPilotAnims) { + pilot.animate(act); + } else { + InventoryManager.getInventoryManager().doInventoryAction(act); + } + } + + actionToPerform = -1; + return true; + } +} |