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 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 a, Vector 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 newAnimations = this.curPilot.getAnimationList(); this.numPilotAnims = newAnimations.size(); Vector 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; } }