/* */ package NET.worlds.console; /* */ /* */ import NET.worlds.network.URL; /* */ import NET.worlds.scape.BGLoaded; /* */ import NET.worlds.scape.BackgroundLoader; /* */ import NET.worlds.scape.FrameEvent; /* */ import NET.worlds.scape.Pilot; /* */ import NET.worlds.scape.Room; /* */ import NET.worlds.scape.SendURLAction; /* */ import NET.worlds.scape.TeleportAction; /* */ import NET.worlds.scape.World; /* */ import java.awt.Component; /* */ import java.awt.Container; /* */ import java.awt.Dimension; /* */ import java.awt.Event; /* */ import java.awt.Graphics; /* */ import java.awt.Image; /* */ import java.awt.Rectangle; /* */ import java.io.DataInputStream; /* */ import java.io.FileInputStream; /* */ import java.io.IOException; /* */ import java.util.StringTokenizer; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class MapPart /* */ extends ImageButtons /* */ implements FramePart, ImageButtonsCallback, BGLoaded /* */ { /* */ private static final long serialVersionUID = 1886153221201046188L; /* */ private static final int width = 158; /* */ private static final int height = 124; /* */ private URL lastURL; /* */ private URL mapURL; /* */ private URL infURL; /* */ private int filesLoaded; /* */ private Rectangle[] hotspots; /* */ private String[] names; /* */ private String[] locations; /* */ private int cursedButton; /* */ private DefaultConsole console; /* */ /* */ public MapPart() /* */ { /* 83 */ setHandler(this); /* 84 */ setBackground(true); /* 85 */ setWidth(158); /* 86 */ setHeight(124); /* */ } /* */ /* */ private synchronized void changeURL(URL url) { /* 90 */ this.lastURL = url; /* 91 */ String path = url.getAbsolute(); /* 92 */ path = path.substring(0, path.lastIndexOf('.')); /* 93 */ this.filesLoaded = 0; /* 94 */ setHotspots(new Rectangle[0]); /* 95 */ this.console.exploreButton.setVisible(true); /* 96 */ this.console.relayoutMap(); /* 97 */ this.locations = null; /* 98 */ repaint(); /* 99 */ BackgroundLoader.get(this, this.mapURL = URL.make(path + "-map.gif"), true); /* 100 */ BackgroundLoader.get(this, this.infURL = URL.make(path + "-map.inf"), true); /* */ } /* */ /* */ private boolean readInfo(String localName) { /* 104 */ DataInputStream in = null; /* */ try { /* 106 */ in = new DataInputStream(new FileInputStream(localName)); /* */ /* 108 */ int item = -1; /* 109 */ String line; while ((line = in.readLine()) != null) { /* 110 */ String line = line.trim(); /* 111 */ if (item == -1) { /* 112 */ int count = Integer.parseInt(line); /* 113 */ this.hotspots = new Rectangle[count]; /* 114 */ this.names = new String[count]; /* 115 */ this.locations = new String[count]; /* */ } else { /* 117 */ StringTokenizer tok = new StringTokenizer(line); /* 118 */ this.hotspots[item] = new Rectangle(Integer.parseInt(tok /* 119 */ .nextToken()), Integer.parseInt(tok.nextToken()), /* 120 */ Integer.parseInt(tok.nextToken()), /* 121 */ Integer.parseInt(tok.nextToken())); /* 122 */ this.names[item] = tok.nextToken().replace('_', ' '); /* 123 */ this.locations[item] = tok.nextToken(); /* 124 */ for (; tok.hasMoreTokens(); /* 125 */ tmp167_162[tmp167_165] = (tmp167_162[tmp167_165] + " " + tok.nextToken())) {} /* */ } /* 127 */ item++; /* */ } /* 129 */ return true; /* */ } /* */ catch (Exception localException) {}finally { /* */ try { /* 133 */ if (in != null) { /* 134 */ in.close(); /* */ } /* */ } catch (IOException localIOException2) {} /* */ } /* 138 */ return false; /* */ } /* */ /* */ private int hasLink(String name) /* */ { /* 143 */ if (this.locations != null) { /* 144 */ for (int i = 0; i < this.locations.length; i++) /* 145 */ if (name.equals(this.locations[i])) /* 146 */ return i; /* */ } /* 148 */ return -1; /* */ } /* */ /* */ /* */ /* */ public synchronized void paint(Graphics g) /* */ { /* 155 */ if (this.filesLoaded == 2) { /* 156 */ super.paint(g); /* */ } /* */ } /* */ /* */ @Deprecated /* */ public synchronized boolean handleEvent(Event event) /* */ { /* 163 */ return super.handleEvent(event); /* */ } /* */ /* */ public Dimension getPreferredSize() /* */ { /* 168 */ return new Dimension(158, 124); /* */ } /* */ /* */ /* */ /* */ protected Graphics drawButton(Graphics g, int button, int state) /* */ { /* 175 */ Graphics ret = super.drawButton(g, button, state); /* 176 */ if ((state == 2) || (state == 3)) { /* 177 */ this.cursedButton = button; /* 178 */ if ((button != -1) && (this.console != null)) /* 179 */ this.console.overrideStatusMsg(this.names[button]); /* 180 */ } else if ((state == 1) && (button == this.cursedButton)) { /* 181 */ this.cursedButton = -1; /* 182 */ if (this.console != null) /* 183 */ this.console.overrideStatusMsg(null); /* */ } /* 185 */ return ret; /* */ } /* */ /* */ /* */ public synchronized Object imageButtonsCallback(Component who, int which) /* */ { /* 191 */ String loc = this.locations[which]; /* 192 */ if (loc.startsWith("pnm:")) { /* 193 */ new SendURLAction(loc).startBrowser(); /* 194 */ return null; } /* 195 */ if (loc.equals("system:universe")) { /* 196 */ this.console.toggleUniverseMode(); /* 197 */ return null; } /* 198 */ if (loc.charAt(0) == '-') { /* 199 */ loc = loc.substring(1); /* */ } else /* 201 */ loc = this.lastURL.getAbsolute() + "#" + loc; /* 202 */ TeleportAction.teleport(loc, null); /* 203 */ return null; /* */ } /* */ /* */ /* */ /* */ public void activate(Console c, Container f, Console prev) /* */ { /* 210 */ this.console = ((DefaultConsole)c); /* */ } /* */ /* */ /* */ public void deactivate() {} /* */ /* */ /* */ public synchronized boolean handle(FrameEvent f) /* */ { /* 219 */ Pilot pilot = Pilot.getActive(); /* 220 */ if (pilot != null) { /* 221 */ World world = pilot.getWorld(); /* 222 */ if (world != null) { /* 223 */ URL sourceURL = world.getSourceURL(); /* 224 */ if ((sourceURL != this.lastURL) && (sourceURL != null)) /* 225 */ changeURL(sourceURL); /* */ } /* */ } /* 228 */ return true; /* */ } /* */ /* */ /* */ /* */ public Object asyncBackgroundLoad(String localName, URL remoteURL) /* */ { /* 235 */ boolean success = false; /* 236 */ if (localName != null) { /* 237 */ if (remoteURL == this.mapURL) { /* 238 */ this.image_ = loadImage(URL.make(localName), this); /* 239 */ success = this.image_ != null; /* 240 */ if (success) { /* 241 */ setWidth(this.image_.getWidth(null) / 4); /* 242 */ setHeight(this.image_.getHeight(null)); /* */ } /* */ } else { /* 245 */ success = readInfo(localName); /* */ /* */ int link; /* 248 */ if ((link = hasLink("system:universe")) >= 0) { /* 249 */ this.console.exploreButton.setVisible(false); /* 250 */ this.console.relayoutMap(); /* */ } /* */ } /* */ } /* 254 */ if (success) { /* 255 */ synchronized (this) { /* 256 */ if (++this.filesLoaded == 2) { /* 257 */ setHotspots(this.hotspots); /* 258 */ repaint(); /* */ } /* */ } /* */ } /* 262 */ return null; /* */ } /* */ /* */ public boolean syncBackgroundLoad(Object obj, URL remoteURL) /* */ { /* 267 */ return false; /* */ } /* */ /* */ public Room getBackgroundLoadRoom() /* */ { /* 272 */ return null; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\MapPart.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */