/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.core.IniFile; /* */ import NET.worlds.network.NetUpdate; /* */ import NET.worlds.network.URL; /* */ import java.awt.Menu; /* */ import java.awt.MenuItem; /* */ import java.awt.event.ActionEvent; /* */ import java.awt.event.ActionListener; /* */ import java.io.File; /* */ import java.io.IOException; /* */ import java.io.PrintStream; /* */ import java.io.RandomAccessFile; /* */ import java.util.Enumeration; /* */ import java.util.StringTokenizer; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class AnimatedActionManager /* */ implements ActionListener, BGLoaded /* */ { /* */ public static AnimatedActionManager get() /* */ { /* 38 */ if (theAnimatedActionManager == null) { /* 39 */ theAnimatedActionManager = new AnimatedActionManager(); /* */ } /* 41 */ return theAnimatedActionManager; /* */ } /* */ /* */ private Vector getActionList(URL avatar, URL object) /* */ { /* 46 */ if ((this.actionList == null) || (avatar == null) || (object == null)) { return null; /* */ } /* 48 */ String av = PosableShape.getBodyType(avatar); /* 49 */ if (av == null) { return null; /* */ } /* 51 */ String ob = object.toString(); /* 52 */ int dot = ob.lastIndexOf("."); /* 53 */ if (dot != -1) { /* 54 */ ob = ob.substring(0, dot); /* */ } /* 56 */ Vector ret = new Vector(); /* */ /* */ /* */ /* 60 */ Enumeration e = this.actionList.elements(); /* 61 */ while (e.hasMoreElements()) /* */ { /* 63 */ AnimatedAction a = (AnimatedAction)e.nextElement(); /* 64 */ if (vectorCheck(av, a.avatarNames)) /* */ { /* 66 */ if (vectorCheck(ob, a.targetObjects)) /* */ { /* 68 */ ret.addElement(a); /* */ } /* */ } /* */ } /* */ /* 73 */ return ret; /* */ } /* */ /* */ /* */ private boolean vectorCheck(String s, Vector v) /* */ { /* 79 */ Enumeration e = v.elements(); /* 80 */ while (e.hasMoreElements()) /* */ { /* 82 */ String element = (String)e.nextElement(); /* 83 */ if (s.toLowerCase().endsWith(element.toLowerCase())) /* 84 */ return true; /* 85 */ if (element.equals("any")) /* 86 */ return true; /* */ } /* 88 */ return false; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public boolean buildActionMenu(Menu m, Shape target) /* */ { /* 97 */ assert (m != null); /* */ /* */ /* 100 */ if (this._currentAction != null) { return false; /* */ } /* */ /* */ /* 104 */ SuperRoot ultimateOwner = target; /* 105 */ while (ultimateOwner.getOwner() != null) /* */ { /* 107 */ ultimateOwner = ultimateOwner.getOwner(); /* 108 */ if ((ultimateOwner instanceof PosableShape)) /* */ { /* 110 */ target = (Shape)ultimateOwner; /* 111 */ break; /* */ } /* */ } /* */ /* */ /* 116 */ Pilot p = Pilot.getActive(); /* 117 */ if (p == null) return false; /* 118 */ if (!(p instanceof HoloPilot)) return false; /* 119 */ HoloPilot hp = (HoloPilot)p; /* */ /* */ /* */ /* 123 */ if (hp.getInternalDrone().getRoom() != target.getRoom()) /* */ { /* */ /* 126 */ return false; /* */ } /* */ /* */ /* */ /* 131 */ Vector v = getActionList(hp.getInternalDrone() /* 132 */ .getCurrentURL(), target.getURL()); /* */ /* 134 */ this.currentMenuActions = v; /* */ /* 136 */ if (v == null) return false; /* 137 */ if (v.size() == 0) { return false; /* */ } /* 139 */ Enumeration e = v.elements(); /* 140 */ while (e.hasMoreElements()) /* */ { /* 142 */ AnimatedAction a = (AnimatedAction)e.nextElement(); /* 143 */ a.setTargetShape(target); /* */ /* 145 */ int idx = a.actionName.indexOf("\\"); /* */ /* 147 */ if (idx != -1) /* */ { /* 149 */ String action = a.actionName.substring(idx + 1); /* */ /* 151 */ String submenu = a.actionName.substring(0, idx); /* 152 */ int items = m.getItemCount(); /* 153 */ boolean inserted = false; /* 154 */ for (int i = 0; i < items; i++) /* */ { /* 156 */ MenuItem item = m.getItem(i); /* 157 */ if (item.getLabel().equals(submenu)) /* */ { /* 159 */ if ((item instanceof Menu)) /* */ { /* 161 */ ((Menu)item).add(action); /* */ /* 163 */ inserted = true; /* 164 */ break; /* */ } /* */ } /* */ } /* 168 */ if (!inserted) /* */ { /* 170 */ Menu sm = new Menu(submenu); /* 171 */ sm.addActionListener(this); /* 172 */ sm.add(action); /* 173 */ m.add(sm); /* */ } /* */ } /* */ else /* */ { /* 178 */ m.add(a.actionName); /* */ } /* */ } /* */ /* 182 */ return true; /* */ } /* */ /* */ /* */ /* */ public boolean processMenuClick(String actionName) /* */ { /* 189 */ if (this.currentMenuActions == null) { return false; /* */ } /* 191 */ Enumeration e = this.currentMenuActions.elements(); /* 192 */ while (e.hasMoreElements()) /* */ { /* 194 */ AnimatedAction a = (AnimatedAction)e.nextElement(); /* 195 */ String thisAction = a.actionName; /* 196 */ int idx = thisAction.indexOf('\\'); /* 197 */ if (idx != -1) /* */ { /* 199 */ thisAction = thisAction.substring(idx + 1); /* */ } /* */ /* */ /* */ /* */ /* 205 */ if (thisAction.equals(actionName)) /* */ { /* 207 */ Pilot p = Pilot.getActive(); /* 208 */ if (p == null) return false; /* 209 */ if (!(p instanceof HoloPilot)) return false; /* 210 */ HoloPilot hp = (HoloPilot)p; /* */ /* 212 */ if (this._currentAction != null) /* */ { /* 214 */ this._currentAction.abort(); /* */ } /* 216 */ this._currentAction = a; /* */ /* 218 */ a.execute(hp); /* 219 */ return true; /* */ } /* */ } /* */ /* 223 */ return false; /* */ } /* */ /* */ /* 227 */ private AnimatedAction _currentAction = null; /* */ static final String actionFile = "actions/actions.dat"; /* */ /* */ public void actionCompleted(AnimatedAction a) { /* 231 */ assert (a == this._currentAction); /* 232 */ this._currentAction = null; /* */ } /* */ /* */ static final String localActionFile = "actions.dat"; /* */ static final String version = "VERSION"; /* */ public void actionPerformed(ActionEvent e) { /* 238 */ processMenuClick(e.getActionCommand()); /* */ } /* */ /* */ static final String action = "ACTION"; /* */ private Vector actionList; /* */ private Vector currentMenuActions; /* */ private AnimatedActionManager() /* */ { /* 246 */ System.out.println("Loading action manager"); /* 247 */ this.actionList = new Vector(); /* */ /* 249 */ loadActionsFile(); /* */ } /* */ /* */ /* */ private void loadActionsFile() /* */ { /* 255 */ File f = new File("actions.dat"); /* 256 */ if (f.exists()) { parseActionFile("actions.dat"); /* */ } /* */ /* 259 */ String serv = NetUpdate.getUpgradeServerURL(); /* 260 */ String s = IniFile.override().getIniString("actionFile", /* 261 */ "actions/actions.dat"); /* 262 */ BackgroundLoader.get(this, URL.make(serv + s)); /* */ } /* */ /* */ /* */ public synchronized Object asyncBackgroundLoad(String localName, URL remoteURL) /* */ { /* 268 */ return localName; /* */ } /* */ /* */ public boolean syncBackgroundLoad(Object obj, URL remoteURL) { /* 272 */ System.out.println("Got actions file "); /* 273 */ String localName = (String)obj; /* 274 */ if ((localName != null) && (new File(localName).exists())) /* */ { /* 276 */ parseActionFile(localName); /* */ } /* 278 */ return false; /* */ } /* */ /* */ public Room getBackgroundLoadRoom() { /* 282 */ return null; /* */ } /* */ /* */ /* */ /* */ private String getLine(RandomAccessFile fIn) /* */ throws IOException /* */ { /* 290 */ while (fIn.getFilePointer() < fIn.length()) /* */ { /* 292 */ String line = fIn.readLine().trim(); /* 293 */ if (line == null) return null; /* 294 */ if ((!line.startsWith("//")) && /* 295 */ (line.length() != 0)) /* */ { /* 297 */ return line; /* */ } /* */ } /* 300 */ return null; /* */ } /* */ /* */ /* */ private void parseActionFile(String fileName) /* */ { /* 306 */ int verNum = 0; /* */ /* 308 */ assert (this.actionList != null); /* 309 */ this.actionList.removeAllElements(); /* */ /* */ try /* */ { /* 313 */ RandomAccessFile fIn = new RandomAccessFile(fileName, /* 314 */ "r"); /* */ /* */ String line; /* 317 */ while ((line = getLine(fIn)) != null) { /* */ String line; /* 319 */ StringTokenizer tok = new StringTokenizer(line); /* */ /* 321 */ String firstWord = tok.nextToken(); /* 322 */ if (firstWord.equals("VERSION")) /* */ { /* 324 */ String ver = tok.nextToken(); /* 325 */ if (ver.equals("1")) { /* 326 */ verNum = 1; /* 327 */ } else if (ver.equals("2")) { /* 328 */ verNum = 2; /* */ } else { /* 330 */ throw new Exception("Bad version."); /* */ } /* 332 */ } else if (firstWord.equals("ACTION")) /* */ { /* 334 */ if (verNum == 0) { /* 335 */ throw new Exception("Actions file version not specified."); /* */ } /* 337 */ AnimatedAction a = new AnimatedAction(); /* 338 */ a.actionName = line.substring("ACTION".length() + 1); /* 339 */ readVector(fIn, a.avatarNames); /* 340 */ readVector(fIn, a.targetObjects); /* 341 */ if (verNum > 1) /* */ { /* 343 */ a.consentRequired = getLine(fIn) /* 344 */ .toLowerCase().equals("consent"); /* */ } /* 346 */ StringTokenizer tok2 = new StringTokenizer( /* 347 */ getLine(fIn)); /* 348 */ Float x = new Float(tok2.nextToken()); /* 349 */ Float y = new Float(tok2.nextToken()); /* 350 */ a.targetRelPosition = new Point2( /* 351 */ x.floatValue(), y.floatValue()); /* 352 */ Float yaw = new Float(getLine(fIn)); /* 353 */ a.targetRelYaw = yaw.floatValue(); /* 354 */ a.preAnimationAction = /* 355 */ AnimatedAction.getAction(getLine(fIn)); /* 356 */ a.preAnimationParameter = getLine(fIn); /* 357 */ a.actionName1 = getLine(fIn); /* 358 */ if (verNum > 1) /* */ { /* 360 */ a.simultaneousAction = /* 361 */ AnimatedAction.getAction(getLine(fIn)); /* 362 */ a.simultaneousParameter = getLine(fIn); /* */ } /* 364 */ a.postAnimationAction = /* 365 */ AnimatedAction.getAction(getLine(fIn)); /* 366 */ a.postAnimationParameter = getLine(fIn); /* 367 */ a.actionName2 = getLine(fIn); /* 368 */ this.actionList.addElement(a); /* */ } /* */ } /* */ /* 372 */ fIn.close(); /* */ } /* */ catch (Exception e) /* */ { /* 376 */ System.out.println("Error reading actions.dat: " + /* 377 */ e.toString()); /* */ } /* */ } /* */ /* */ private void readVector(RandomAccessFile fIn, Vector v) throws IOException /* */ { /* 383 */ String line = getLine(fIn); /* 384 */ StringTokenizer tok = new StringTokenizer(line); /* */ /* 386 */ while (tok.hasMoreTokens()) /* */ { /* 388 */ v.addElement(tok.nextToken()); /* */ } /* */ } /* */ /* */ /* */ /* 394 */ private static AnimatedActionManager theAnimatedActionManager = null; /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\AnimatedActionManager.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */