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/MapPart.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/console/MapPart.java')
| -rw-r--r-- | NET/worlds/console/MapPart.java | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/NET/worlds/console/MapPart.java b/NET/worlds/console/MapPart.java new file mode 100644 index 0000000..76188fe --- /dev/null +++ b/NET/worlds/console/MapPart.java @@ -0,0 +1,234 @@ +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.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() { + this.setHandler(this); + this.setBackground(true); + this.setWidth(158); + this.setHeight(124); + } + + private synchronized void changeURL(URL url) { + this.lastURL = url; + String path = url.getAbsolute(); + path = path.substring(0, path.lastIndexOf(46)); + this.filesLoaded = 0; + this.setHotspots(new Rectangle[0]); + this.console.exploreButton.setVisible(true); + this.console.relayoutMap(); + this.locations = null; + this.repaint(); + BackgroundLoader.get(this, this.mapURL = URL.make(path + "-map.gif"), true); + BackgroundLoader.get(this, this.infURL = URL.make(path + "-map.inf"), true); + } + + private boolean readInfo(String localName) { + DataInputStream in = null; + + try { + in = new DataInputStream(new FileInputStream(localName)); + + String line; + for (int item = -1; (line = in.readLine()) != null; item++) { + line = line.trim(); + if (item == -1) { + int count = Integer.parseInt(line); + this.hotspots = new Rectangle[count]; + this.names = new String[count]; + this.locations = new String[count]; + } else { + StringTokenizer tok = new StringTokenizer(line); + this.hotspots[item] = new Rectangle( + Integer.parseInt(tok.nextToken()), Integer.parseInt(tok.nextToken()), Integer.parseInt(tok.nextToken()), Integer.parseInt(tok.nextToken()) + ); + this.names[item] = tok.nextToken().replace('_', ' '); + this.locations[item] = tok.nextToken(); + + while (tok.hasMoreTokens()) { + this.locations[item] = this.locations[item] + " " + tok.nextToken(); + } + } + } + + return true; + } catch (Exception var14) { + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException var13) { + } + } + + return false; + } + + private int hasLink(String name) { + if (this.locations != null) { + for (int i = 0; i < this.locations.length; i++) { + if (name.equals(this.locations[i])) { + return i; + } + } + } + + return -1; + } + + @Override + public synchronized void paint(Graphics g) { + if (this.filesLoaded == 2) { + super.paint(g); + } + } + + @Override + public synchronized boolean handleEvent(Event event) { + return super.handleEvent(event); + } + + @Override + public Dimension preferredSize() { + return new Dimension(158, 124); + } + + @Override + protected Graphics drawButton(Graphics g, int button, int state) { + Graphics ret = super.drawButton(g, button, state); + if (state == 2 || state == 3) { + this.cursedButton = button; + if (button != -1 && this.console != null) { + this.console.overrideStatusMsg(this.names[button]); + } + } else if (state == 1 && button == this.cursedButton) { + this.cursedButton = -1; + if (this.console != null) { + this.console.overrideStatusMsg(null); + } + } + + return ret; + } + + @Override + public synchronized Object imageButtonsCallback(Component who, int which) { + String loc = this.locations[which]; + if (loc.startsWith("pnm:")) { + new SendURLAction(loc).startBrowser(); + return null; + } else if (loc.equals("system:universe")) { + this.console.toggleUniverseMode(); + return null; + } else { + if (loc.charAt(0) == '-') { + loc = loc.substring(1); + } else { + loc = this.lastURL.getAbsolute() + "#" + loc; + } + + TeleportAction.teleport(loc, null); + return null; + } + } + + @Override + public void activate(Console c, Container f, Console prev) { + this.console = (DefaultConsole)c; + } + + @Override + public void deactivate() { + } + + @Override + public synchronized boolean handle(FrameEvent f) { + Pilot pilot = Pilot.getActive(); + if (pilot != null) { + World world = pilot.getWorld(); + if (world != null) { + URL sourceURL = world.getSourceURL(); + if (sourceURL != this.lastURL && sourceURL != null) { + this.changeURL(sourceURL); + } + } + } + + return true; + } + + @Override + public Object asyncBackgroundLoad(String localName, URL remoteURL) { + boolean success = false; + if (localName != null) { + if (remoteURL == this.mapURL) { + this.image_ = loadImage(URL.make(localName), this); + success = this.image_ != null; + if (success) { + this.setWidth(this.image_.getWidth(null) / 4); + this.setHeight(this.image_.getHeight(null)); + } + } else { + success = this.readInfo(localName); + if (this.hasLink("system:universe") >= 0) { + this.console.exploreButton.hide(); + this.console.relayoutMap(); + } + } + } + + if (success) { + synchronized (this) { + if (++this.filesLoaded == 2) { + this.setHotspots(this.hotspots); + this.repaint(); + } + } + } + + return null; + } + + @Override + public boolean syncBackgroundLoad(Object obj, URL remoteURL) { + return false; + } + + @Override + public Room getBackgroundLoadRoom() { + return null; + } +} |