package NET.worlds.scape; import NET.worlds.console.Console; import NET.worlds.console.Main; import NET.worlds.console.MainCallback; import NET.worlds.network.URL; import java.io.IOException; import java.text.MessageFormat; import java.util.Enumeration; public class MontyDoor extends Portal implements MouseDownHandler, MainCallback { boolean setsAvatar = false; URL url; String description = ""; DialogAction action; String viewName; URL viewURL; Persister lastTrigger; private static Object classCookie = new Object(); public MontyDoor() { this.flags |= 262144; } @Override public boolean handle(MouseDownEvent e) { if ((e.key & 1) == 0) { return false; } else if (this.action == null && this.url != null) { if (this.setsAvatar) { SelectAvatarAction a = new SelectAvatarAction(); a.url = this.viewURL; a.description = this.description; this.action = a; } else { SendURLAction a = new SendURLAction(); a.destination = this.url; a.description = this.description; this.action = a; } this.action.cancelOnly = true; Main.register(this); return true; } else { return true; } } @Override public void mainCallback() { if (this.action.cancelOnly) { this.lastTrigger = this.action.trigger(null, this.lastTrigger); if (this.lastTrigger != null) { return; } if (this.viewURL != null && this.viewName != null && this._farSideRoomName != null) { Room r = this.getRoom(); World w; if (r != null && (w = r.getWorld()) != null) { r = w.getRoom(this._farSideRoomName); if (r == null) { Main.unregister(this); this.action = null; Object[] arguments = new Object[]{new String(this.getName()), new String(this._farSideRoomName)}; Console.println(MessageFormat.format(Console.message("MontyDoor"), arguments)); return; } Enumeration list = r.getDeepOwned(); SetPropertyAction.propHelper(2, this.viewURL, "File", SuperRoot.nameSearch(list, this.viewName)); } } this.action.cancelOnly = false; this.flags &= -262145; this.reset(); } this.lastTrigger = this.action.trigger(null, this.lastTrigger); if (this.lastTrigger == null) { Main.unregister(this); this.action = null; this.flags |= 262144; this.reset(); } } @Override public BumpCalc getBumpCalc(BumpEventTemp b) { return standardPlaneBumpCalc; } @Override public boolean handle(BumpEventTemp b) { return true; } @Override public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException { Object ret = null; switch (index - offset) { case 0: if (mode == 0) { ret = BooleanPropertyEditor.make(new Property(this, index, "Avatar type"), "SendURL", "SelectAvatar"); } else if (mode == 1) { ret = new Boolean(this.setsAvatar); } else if (mode == 2) { this.setsAvatar = (Boolean)value; } break; case 1: if (mode == 0) { ret = URLPropertyEditor.make(new Property(this, index, "URL (used only for non-avatar)").allowSetNull(), null); } else if (mode == 1) { ret = this.url; } else if (mode == 2) { this.url = (URL)value; } break; case 2: if (mode == 0) { ret = StringPropertyEditor.make(new Property(this, index, "Description")); } else if (mode == 1) { ret = this.description; } else if (mode == 2) { this.description = ((String)value).toString().trim(); } break; case 3: if (mode == 0) { ret = URLPropertyEditor.make(new Property(this, index, "Display URL").allowSetNull(), null); } else if (mode == 1) { ret = this.viewURL; } else if (mode == 2) { this.viewURL = (URL)value; } break; case 4: if (mode == 0) { ret = StringPropertyEditor.make(new Property(this, index, "Display Name")); } else if (mode == 1) { ret = this.viewName; } else if (mode == 2) { this.viewName = ((String)value).toString().trim(); } break; default: ret = super.properties(index, offset + 5, mode, value); } return ret; } @Override public void saveState(Saver s) throws IOException { s.saveVersion(0, classCookie); int f = this.flags; this.flags |= 262144; super.saveState(s); this.flags = f; s.saveBoolean(this.setsAvatar); URL.save(s, this.url); s.saveString(this.description); URL.save(s, this.viewURL); s.saveString(this.viewName); } @Override public void restoreState(Restorer r) throws IOException, TooNewException { switch (r.restoreVersion(classCookie)) { case 0: super.restoreState(r); this.setsAvatar = r.restoreBoolean(); this.url = URL.restore(r); this.description = r.restoreString(); this.viewURL = URL.restore(r); this.viewName = r.restoreString(); return; default: throw new TooNewException(); } } }