1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
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;
}
}
|