1 | package main;
|
---|
2 |
|
---|
3 | import java.awt.GraphicsEnvironment;
|
---|
4 | import java.io.OutputStream;
|
---|
5 | import java.io.PrintStream;
|
---|
6 | import java.io.FileOutputStream;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.awt.event.MouseEvent;
|
---|
9 | import java.util.Iterator;
|
---|
10 | import java.awt.geom.Point2D;
|
---|
11 | import java.util.Random;
|
---|
12 | import java.awt.image.ImageObserver;
|
---|
13 | import java.awt.Image;
|
---|
14 | import java.awt.Color;
|
---|
15 | import java.awt.geom.Area;
|
---|
16 | import java.awt.geom.Ellipse2D;
|
---|
17 | import java.awt.Shape;
|
---|
18 | import collision.Bound;
|
---|
19 | import java.awt.geom.Rectangle2D;
|
---|
20 | import utils.DynamicImage;
|
---|
21 | import gamegui.Button;
|
---|
22 | import gamegui.Align;
|
---|
23 | import gamegui.Member;
|
---|
24 | import gamegui.Label;
|
---|
25 | import java.awt.image.BufferStrategy;
|
---|
26 | import java.awt.GraphicsConfiguration;
|
---|
27 | import utils.Utils;
|
---|
28 | import java.awt.GraphicsDevice;
|
---|
29 | import java.awt.Point;
|
---|
30 | import java.util.ArrayList;
|
---|
31 | import java.util.HashMap;
|
---|
32 | import java.awt.Font;
|
---|
33 | import gamegui.Textbox;
|
---|
34 | import gamegui.ScrollBar;
|
---|
35 | import gamegui.Window;
|
---|
36 | import java.awt.Frame;
|
---|
37 | import java.awt.image.BufferedImage;
|
---|
38 | import java.awt.Graphics;
|
---|
39 | import java.awt.event.MouseListener;
|
---|
40 | import java.awt.event.KeyListener;
|
---|
41 |
|
---|
42 | public class MapEditor implements KeyListener, MouseListener
|
---|
43 | {
|
---|
44 | public static final int RES_X = 1024;
|
---|
45 | public static final int RES_Y = 768;
|
---|
46 | public static final int MAP_OFFSET_X = 204;
|
---|
47 | public static final int MAP_OFFSET_Y = 148;
|
---|
48 | private static final boolean RUNNING_FROM_JAR = false;
|
---|
49 | public State state;
|
---|
50 | public AuxState auxState;
|
---|
51 | boolean started;
|
---|
52 | boolean done;
|
---|
53 | boolean showFps;
|
---|
54 | int frameCount;
|
---|
55 | int lastFrameCount;
|
---|
56 | long lastFpsUpdate;
|
---|
57 | Graphics g;
|
---|
58 | BufferedImage mapBuffer;
|
---|
59 | Graphics mapG;
|
---|
60 | public static Frame frmMain;
|
---|
61 | public static Map map;
|
---|
62 | Window wndMain;
|
---|
63 | Window wndEdit;
|
---|
64 | Window wndEditPalette;
|
---|
65 | Window wndEditOptions;
|
---|
66 | Window wndDiagnostics;
|
---|
67 | Window wndLoadMap;
|
---|
68 | ScrollBar horBar;
|
---|
69 | ScrollBar verBar;
|
---|
70 | Window wndMessage;
|
---|
71 | Textbox selectedText;
|
---|
72 | Font font11;
|
---|
73 | Font font12;
|
---|
74 | Font font14;
|
---|
75 | Font font24;
|
---|
76 | Font fontTT;
|
---|
77 | static final int LEVEL_ARROWS_OFFSET = 0;
|
---|
78 | static final int SET_ARROWS_OFFSET = 50;
|
---|
79 | HashMap<Integer, Tile> imageMap;
|
---|
80 | HashMap<Integer, Creature> crMap;
|
---|
81 | HashMap<Integer, GroundType[]> tileBreakdowns;
|
---|
82 | ArrayList<Tile>[] tileByBreakdown;
|
---|
83 | ArrayList<ArrayList<Tile>> imgSets;
|
---|
84 | ArrayList<Tile> activeSet;
|
---|
85 | int setIndex;
|
---|
86 | Tile curTile;
|
---|
87 | int curLevel;
|
---|
88 | Tile selectedObject;
|
---|
89 | Creature selectedCreature;
|
---|
90 | String mapName;
|
---|
91 | ArrayList<Creature> crSet;
|
---|
92 | Creature curCr;
|
---|
93 | boolean bounds;
|
---|
94 | boolean passable;
|
---|
95 | boolean showCr;
|
---|
96 | boolean highLevelPlacement;
|
---|
97 | Point playerLoc;
|
---|
98 | Point start;
|
---|
99 |
|
---|
100 | public MapEditor(final GraphicsDevice device) {
|
---|
101 | this.started = false;
|
---|
102 | this.start = null;
|
---|
103 | try {
|
---|
104 | GraphicsConfiguration gc = device.getDefaultConfiguration();
|
---|
105 | gc = device.getDefaultConfiguration();
|
---|
106 | (MapEditor.frmMain = new Frame(gc)).setUndecorated(true);
|
---|
107 | MapEditor.frmMain.setIgnoreRepaint(true);
|
---|
108 | device.setFullScreenWindow(MapEditor.frmMain);
|
---|
109 | if (device.isDisplayChangeSupported()) {
|
---|
110 | Utils.chooseBestDisplayMode(device, 1024, 768);
|
---|
111 | }
|
---|
112 | MapEditor.frmMain.addMouseListener(this);
|
---|
113 | MapEditor.frmMain.addKeyListener(this);
|
---|
114 | MapEditor.frmMain.createBufferStrategy(2);
|
---|
115 | final BufferStrategy bufferStrategy = MapEditor.frmMain.getBufferStrategy();
|
---|
116 | this.g = bufferStrategy.getDrawGraphics();
|
---|
117 | this.mapBuffer = gc.createCompatibleImage(800, 600);
|
---|
118 | this.mapG = this.mapBuffer.getGraphics();
|
---|
119 | Utils.init(gc, false);
|
---|
120 | this.state = State.Main;
|
---|
121 | this.auxState = AuxState.None;
|
---|
122 | this.done = false;
|
---|
123 | this.showFps = false;
|
---|
124 | this.frameCount = 0;
|
---|
125 | this.lastFrameCount = 0;
|
---|
126 | this.lastFpsUpdate = System.nanoTime();
|
---|
127 | this.setIndex = 0;
|
---|
128 | this.curTile = null;
|
---|
129 | this.curLevel = 0;
|
---|
130 | this.selectedObject = null;
|
---|
131 | this.selectedCreature = null;
|
---|
132 | this.curCr = null;
|
---|
133 | this.bounds = true;
|
---|
134 | this.passable = false;
|
---|
135 | this.showCr = false;
|
---|
136 | this.highLevelPlacement = false;
|
---|
137 | this.loadMap();
|
---|
138 | this.loadCreatures();
|
---|
139 | this.loadGUI();
|
---|
140 | this.started = true;
|
---|
141 | while (!this.done) {
|
---|
142 | this.g = bufferStrategy.getDrawGraphics();
|
---|
143 | this.handleEvents();
|
---|
144 | this.render(this.g);
|
---|
145 | this.g.dispose();
|
---|
146 | bufferStrategy.show();
|
---|
147 | ++this.frameCount;
|
---|
148 | if (System.nanoTime() - 1000000000L >= this.lastFpsUpdate) {
|
---|
149 | this.lastFpsUpdate = System.nanoTime();
|
---|
150 | this.lastFrameCount = this.frameCount;
|
---|
151 | this.frameCount = 0;
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 | catch (Exception e) {
|
---|
156 | e.printStackTrace();
|
---|
157 | return;
|
---|
158 | }
|
---|
159 | finally {
|
---|
160 | device.setFullScreenWindow(null);
|
---|
161 | }
|
---|
162 | device.setFullScreenWindow(null);
|
---|
163 | }
|
---|
164 |
|
---|
165 | private void loadGUI() {
|
---|
166 | this.font11 = new Font("Arial", 0, 11);
|
---|
167 | this.font12 = new Font("Arial", 0, 12);
|
---|
168 | this.font24 = new Font("Arial", 0, 24);
|
---|
169 | this.fontTT = new Font("Courier New", 0, 11);
|
---|
170 | (this.wndMain = new Window("main", 0, 0, 1024, 768, true)).add(new Label("title", 256, 0, 512, 95, "Lost Haven Map Editor", this.font24));
|
---|
171 | this.wndMain.add(new Button("new map", 668, 140, 200, 40, "New Map", this.font12, Align.Center));
|
---|
172 | this.wndMain.add(new Button("load map", 668, 240, 200, 40, "Load Map", this.font12, Align.Center));
|
---|
173 | this.wndMain.add(new Button("quit", 668, 340, 200, 40, "Quit", this.font12, Align.Center));
|
---|
174 | this.wndEdit = new Window("edit", 0, 0, 1024, 768, true);
|
---|
175 | (this.wndEditPalette = new Window("editPalette", 0, 0, 203, 767, false)).add(new Label("selected", 62, 10, 80, 20, "Selected Tile:", this.font12));
|
---|
176 | this.wndEditPalette.add(new Label("level", 62, 125, 80, 20, "Level " + this.curLevel, this.font12));
|
---|
177 | this.wndEditPalette.add(new Label("switch", 62, 175, 80, 20, "Switch", this.font12));
|
---|
178 | this.wndEdit.add(this.wndEditPalette);
|
---|
179 | (this.wndEditOptions = new Window("editOptions", 203, 0, 820, 147, false)).add(new Textbox("name", 65, 25, 160, 20, "Name:", this.font12, false));
|
---|
180 | this.wndEditOptions.add(new Textbox("x", 65, 65, 80, 20, "Width:", this.font12, false));
|
---|
181 | this.wndEditOptions.add(new Textbox("y", 65, 105, 80, 20, "Height:", this.font12, false));
|
---|
182 | this.wndEditOptions.add(new Button("new", 400, 108, 80, 20, "New", this.font12));
|
---|
183 | this.wndEditOptions.add(new Button("save", 500, 108, 80, 20, "Save", this.font12));
|
---|
184 | this.wndEditOptions.add(new Button("load", 600, 108, 80, 20, "Load", this.font12));
|
---|
185 | this.wndEditOptions.add(new Button("back", 700, 108, 80, 20, "Back", this.font12));
|
---|
186 | this.wndEdit.add(this.wndEditOptions);
|
---|
187 | this.horBar = new ScrollBar("horScroll", 204, 748, 800, 19, 8, true);
|
---|
188 | this.verBar = new ScrollBar("verScroll", 1004, 147, 19, 601, 8, false);
|
---|
189 | this.wndEdit.add(this.horBar);
|
---|
190 | this.wndEdit.add(this.verBar);
|
---|
191 | (this.wndMessage = new Window("message", 402, 202, 220, 160)).add(new Label("label", 20, 15, 180, 12, "none", this.font12));
|
---|
192 | this.wndMessage.add(new Button("button", 70, 115, 80, 30, "OK", this.font12));
|
---|
193 | (this.wndLoadMap = new Window("load map", 402, 202, 220, 160)).add(new Textbox("map_name", 80, 15, 120, 20, "Map Name:", this.font12, false));
|
---|
194 | this.wndLoadMap.add(new Button("load", 20, 115, 80, 30, "Load", this.font12, Align.Center));
|
---|
195 | this.wndLoadMap.add(new Button("back", 120, 115, 80, 30, "Back", this.font12, Align.Center));
|
---|
196 | this.wndDiagnostics = new Window("diagnostics", 0, 0, 80, 40, true);
|
---|
197 | }
|
---|
198 |
|
---|
199 | private void loadMap() {
|
---|
200 | this.imageMap = new HashMap<Integer, Tile>();
|
---|
201 | this.crMap = new HashMap<Integer, Creature>();
|
---|
202 | this.tileBreakdowns = new HashMap<Integer, GroundType[]>();
|
---|
203 | this.tileByBreakdown = (ArrayList<Tile>[])new ArrayList[81];
|
---|
204 | (this.imgSets = new ArrayList<ArrayList<Tile>>()).add(new ArrayList<Tile>());
|
---|
205 | this.imgSets.add(new ArrayList<Tile>());
|
---|
206 | this.imgSets.add(new ArrayList<Tile>());
|
---|
207 | this.imgSets.add(new ArrayList<Tile>());
|
---|
208 | this.imgSets.add(new ArrayList<Tile>());
|
---|
209 | this.imgSets.add(new ArrayList<Tile>());
|
---|
210 | this.imgSets.add(new ArrayList<Tile>());
|
---|
211 | for (int x = 0; x < 16; ++x) {
|
---|
212 | this.imgSets.get(0).add(new Tile(new MapImage(new DynamicImage("tiles/ground" + (x + 1) + ".png"), MapType.Ground)));
|
---|
213 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(0).get(x));
|
---|
214 | }
|
---|
215 | for (int x = 0; x < 12; ++x) {
|
---|
216 | this.imgSets.get(1).add(new Tile(new MapImage(new DynamicImage("tiles/cliff" + (x + 1) + ".png"), MapType.Ground)));
|
---|
217 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(1).get(x));
|
---|
218 | }
|
---|
219 | int last = 15;
|
---|
220 | this.imageMap.get(last + 1).getImg().setDrawOffset(-40, 0);
|
---|
221 | this.imageMap.get(last + 3).getImg().setDrawOffset(-40, 0);
|
---|
222 | this.imageMap.get(last + 5).getImg().setDrawOffset(0, -40);
|
---|
223 | this.imageMap.get(last + 6).getImg().setDrawOffset(0, -40);
|
---|
224 | this.imageMap.get(last + 7).getImg().setDrawOffset(-40, -40);
|
---|
225 | this.imageMap.get(last + 8).getImg().setDrawOffset(0, -40);
|
---|
226 | this.imageMap.get(last + 9).getImg().setDrawOffset(-40, 0);
|
---|
227 | this.imageMap.get(last + 1).getImg().setSortOffset(-18, 0);
|
---|
228 | this.imageMap.get(last + 2).getImg().setSortOffset(62, 0);
|
---|
229 | this.imageMap.get(last + 3).getImg().setSortOffset(-18, 0);
|
---|
230 | this.imageMap.get(last + 4).getImg().setSortOffset(62, 0);
|
---|
231 | this.imageMap.get(last + 5).getImg().setSortOffset(0, 32);
|
---|
232 | this.imageMap.get(last + 6).getImg().setSortOffset(0, 32);
|
---|
233 | this.imageMap.get(last + 7).getImg().setSortOffset(-18, 32);
|
---|
234 | this.imageMap.get(last + 8).getImg().setSortOffset(62, 32);
|
---|
235 | this.imageMap.get(last + 9).getImg().setSortOffset(-18, 75);
|
---|
236 | this.imageMap.get(last + 10).getImg().setSortOffset(62, 75);
|
---|
237 | this.imageMap.get(last + 11).getImg().setSortOffset(0, 75);
|
---|
238 | this.imageMap.get(last + 12).getImg().setSortOffset(0, 75);
|
---|
239 | this.imageMap.get(last + 1).setBound(new Bound(new Rectangle2D.Double(20.0, 0.0, 15.0, 40.0)));
|
---|
240 | this.imageMap.get(last + 2).setBound(new Bound(new Rectangle2D.Double(45.0, 0.0, 21.0, 40.0)));
|
---|
241 | this.imageMap.get(last + 3).setBound(new Bound(new Rectangle2D.Double(20.0, 0.0, 15.0, 40.0)));
|
---|
242 | this.imageMap.get(last + 4).setBound(new Bound(new Rectangle2D.Double(45.0, 0.0, 21.0, 40.0)));
|
---|
243 | this.imageMap.get(last + 5).setBound(new Bound(new Rectangle2D.Double(0.0, 20.0, 40.0, 15.0)));
|
---|
244 | this.imageMap.get(last + 6).setBound(new Bound(new Rectangle2D.Double(0.0, 20.0, 40.0, 15.0)));
|
---|
245 | this.imageMap.get(last + 11).setBound(new Bound(new Rectangle2D.Double(0.0, 45.0, 40.0, 27.0)));
|
---|
246 | this.imageMap.get(last + 12).setBound(new Bound(new Rectangle2D.Double(0.0, 45.0, 40.0, 27.0)));
|
---|
247 | Bound b1 = new Bound(new Ellipse2D.Double(20.0, -48.0, 120.0, 120.0));
|
---|
248 | b1.intersect(new Bound(new Rectangle2D.Double(20.0, 12.0, 60.0, 60.0)));
|
---|
249 | b1.add(new Bound(new Rectangle2D.Double(20.0, 0.0, 15.0, 12.0)));
|
---|
250 | b1.subtract(new Bound(new Ellipse2D.Double(35.0, -21.0, 66.0, 66.0)));
|
---|
251 | b1.subtract(new Bound(new Rectangle2D.Double(68.0, 35.0, 12.0, 10.0)));
|
---|
252 | final Bound b2 = new Bound(new Ellipse2D.Double(-66.0, -60.0, 132.0, 132.0));
|
---|
253 | b2.intersect(new Bound(new Rectangle2D.Double(0.0, 6.0, 66.0, 66.0)));
|
---|
254 | b2.add(new Bound(new Rectangle2D.Double(45.0, 0.0, 21.0, 6.0)));
|
---|
255 | b2.subtract(new Bound(new Ellipse2D.Double(-45.0, -45.0, 90.0, 90.0)));
|
---|
256 | final Bound b3 = new Bound(new Ellipse2D.Double(-54.0, 20.0, 120.0, 120.0));
|
---|
257 | b3.intersect(new Bound(new Rectangle2D.Double(6.0, 20.0, 60.0, 60.0)));
|
---|
258 | b3.add(new Bound(new Rectangle2D.Double(0.0, 20.0, 6.0, 15.0)));
|
---|
259 | b3.subtract(new Bound(new Ellipse2D.Double(-33.0, 35.0, 78.0, 78.0)));
|
---|
260 | b3.subtract(new Bound(new Rectangle2D.Double(39.0, 74.0, 6.0, 6.0)));
|
---|
261 | final Bound b4 = new Bound(new Ellipse2D.Double(20.0, 20.0, 120.0, 120.0));
|
---|
262 | b4.intersect(new Bound(new Rectangle2D.Double(20.0, 20.0, 60.0, 60.0)));
|
---|
263 | b4.subtract(new Bound(new Ellipse2D.Double(35.0, 35.0, 90.0, 90.0)));
|
---|
264 | this.imageMap.get(last + 7).setBound(b4);
|
---|
265 | this.imageMap.get(last + 8).setBound(b3);
|
---|
266 | this.imageMap.get(last + 9).setBound(b1);
|
---|
267 | this.imageMap.get(last + 10).setBound(b2);
|
---|
268 | this.imageMap.get(last + 7).getImg().setNeedsBase(true);
|
---|
269 | this.imageMap.get(last + 8).getImg().setNeedsBase(true);
|
---|
270 | for (int x2 = 0; x2 < 6; ++x2) {
|
---|
271 | this.imgSets.get(2).add(new Tile(new MapImage(new DynamicImage("tiles/rock" + (x2 + 1) + ".png"), MapType.Ground)));
|
---|
272 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(2).get(x2));
|
---|
273 | }
|
---|
274 | last = 33;
|
---|
275 | this.imgSets.get(3).add(new Tile(new MapImage(new DynamicImage("objects/rock1.png"), MapType.Object)));
|
---|
276 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(3).get(0));
|
---|
277 | this.imgSets.get(3).add(new Tile(new MapImage(new DynamicImage("objects/rock2.png"), MapType.Object)));
|
---|
278 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(3).get(1));
|
---|
279 | this.imgSets.get(3).add(new Tile(new MapImage(new DynamicImage("objects/tree1.png"), MapType.Object)));
|
---|
280 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(3).get(2));
|
---|
281 | this.imgSets.get(3).add(new Tile(new MapImage(new DynamicImage("objects/tree2.png"), MapType.Object)));
|
---|
282 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(3).get(3));
|
---|
283 | this.imageMap.get(last + 1).getImg().setDrawOffset(-22, -28);
|
---|
284 | this.imageMap.get(last + 2).getImg().setDrawOffset(-16, -50);
|
---|
285 | this.imageMap.get(last + 3).getImg().setDrawOffset(-36, -100);
|
---|
286 | this.imageMap.get(last + 4).getImg().setDrawOffset(-58, -83);
|
---|
287 | this.imageMap.get(last + 1).setBound(new Bound(new Ellipse2D.Double(-6.0, -6.0, 12.0, 12.0)));
|
---|
288 | this.imageMap.get(last + 2).setBound(new Bound(new Ellipse2D.Double(-6.0, -6.0, 12.0, 12.0)));
|
---|
289 | this.imageMap.get(last + 3).setBound(new Bound(new Ellipse2D.Double(-16.0, -16.0, 32.0, 32.0)));
|
---|
290 | this.imageMap.get(last + 4).setBound(new Bound(new Ellipse2D.Double(-30.0, -30.0, 60.0, 60.0)));
|
---|
291 | for (int x2 = 0; x2 < 19; ++x2) {
|
---|
292 | this.imgSets.get(4).add(new Tile(new MapImage(new DynamicImage("tiles/pave" + (x2 + 1) + ".png"), MapType.Ground)));
|
---|
293 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(4).get(x2));
|
---|
294 | }
|
---|
295 | for (int x2 = 0; x2 < 13; ++x2) {
|
---|
296 | this.imgSets.get(5).add(new Tile(new MapImage(new DynamicImage("tiles/fence" + (x2 + 1) + ".png"), MapType.Structure)));
|
---|
297 | this.imageMap.put(MapImage.lastKey, this.imgSets.get(5).get(x2));
|
---|
298 | }
|
---|
299 | last = 56;
|
---|
300 | this.imageMap.get(last + 1).getImg().setDrawOffset(-19, -85);
|
---|
301 | this.imageMap.get(last + 2).getImg().setDrawOffset(-20, -85);
|
---|
302 | this.imageMap.get(last + 3).getImg().setDrawOffset(-20, -97);
|
---|
303 | this.imageMap.get(last + 4).getImg().setDrawOffset(-16, -72);
|
---|
304 | this.imageMap.get(last + 5).getImg().setDrawOffset(-20, -81);
|
---|
305 | this.imageMap.get(last + 6).getImg().setDrawOffset(-13, -45);
|
---|
306 | this.imageMap.get(last + 7).getImg().setDrawOffset(-20, -67);
|
---|
307 | this.imageMap.get(last + 8).getImg().setDrawOffset(-13, -51);
|
---|
308 | this.imageMap.get(last + 9).getImg().setDrawOffset(-17, -95);
|
---|
309 | this.imageMap.get(last + 10).getImg().setDrawOffset(-22, -95);
|
---|
310 | this.imageMap.get(last + 11).getImg().setDrawOffset(-19, -86);
|
---|
311 | this.imageMap.get(last + 12).getImg().setDrawOffset(-20, -67);
|
---|
312 | this.imageMap.get(last + 13).getImg().setDrawOffset(-20, -84);
|
---|
313 | b1 = new Bound(new Rectangle2D.Double(-14.0, -40.0, 34.0, 40.0));
|
---|
314 | b1.add(new Bound(new Rectangle2D.Double(-20.0, -25.0, 6.0, 25.0)));
|
---|
315 | this.imageMap.get(last + 1).setBound(new Bound(new Rectangle2D.Double(-14.0, -25.0, 34.0, 25.0)));
|
---|
316 | this.imageMap.get(last + 2).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
|
---|
317 | this.imageMap.get(last + 3).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
|
---|
318 | this.imageMap.get(last + 5).setBound(b1);
|
---|
319 | this.imageMap.get(last + 6).setBound(new Bound(new Rectangle2D.Double(-14.0, -40.0, 34.0, 40.0)));
|
---|
320 | this.imageMap.get(last + 7).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
|
---|
321 | this.imageMap.get(last + 8).setBound(new Bound(new Rectangle2D.Double(-14.0, -40.0, 34.0, 40.0)));
|
---|
322 | this.imageMap.get(last + 9).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
|
---|
323 | this.imageMap.get(last + 10).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
|
---|
324 | this.imageMap.get(last + 11).setBound(new Bound(new Rectangle2D.Double(-14.0, -40.0, 34.0, 40.0)));
|
---|
325 | this.imageMap.get(last + 12).setBound(new Bound(new Rectangle2D.Double(-20.0, -25.0, 40.0, 25.0)));
|
---|
326 | this.imgSets.get(6).add(this.imgSets.get(0).get(0));
|
---|
327 | this.imgSets.get(6).add(this.imgSets.get(0).get(9));
|
---|
328 | this.imgSets.get(6).add(this.imgSets.get(4).get(0));
|
---|
329 | this.setBreakdown(this.imgSets.get(0).get(0), GroundType.Grass, GroundType.Grass, GroundType.Grass, GroundType.Grass);
|
---|
330 | this.setBreakdown(this.imgSets.get(0).get(1), GroundType.Dirt, GroundType.Dirt, GroundType.Dirt, GroundType.Grass);
|
---|
331 | this.setBreakdown(this.imgSets.get(0).get(2), GroundType.Dirt, GroundType.Dirt, GroundType.Grass, GroundType.Dirt);
|
---|
332 | this.setBreakdown(this.imgSets.get(0).get(3), GroundType.Dirt, GroundType.Grass, GroundType.Grass, GroundType.Grass);
|
---|
333 | this.setBreakdown(this.imgSets.get(0).get(4), GroundType.Dirt, GroundType.Dirt, GroundType.Grass, GroundType.Grass);
|
---|
334 | this.setBreakdown(this.imgSets.get(0).get(5), GroundType.Grass, GroundType.Dirt, GroundType.Grass, GroundType.Grass);
|
---|
335 | this.setBreakdown(this.imgSets.get(0).get(6), GroundType.Dirt, GroundType.Grass, GroundType.Dirt, GroundType.Dirt);
|
---|
336 | this.setBreakdown(this.imgSets.get(0).get(7), GroundType.Grass, GroundType.Dirt, GroundType.Dirt, GroundType.Dirt);
|
---|
337 | this.setBreakdown(this.imgSets.get(0).get(8), GroundType.Dirt, GroundType.Grass, GroundType.Dirt, GroundType.Grass);
|
---|
338 | this.setBreakdown(this.imgSets.get(0).get(9), GroundType.Dirt, GroundType.Dirt, GroundType.Dirt, GroundType.Dirt);
|
---|
339 | this.setBreakdown(this.imgSets.get(0).get(10), GroundType.Grass, GroundType.Dirt, GroundType.Grass, GroundType.Dirt);
|
---|
340 | this.setBreakdown(this.imgSets.get(0).get(11), GroundType.Grass, GroundType.Grass, GroundType.Dirt, GroundType.Grass);
|
---|
341 | this.setBreakdown(this.imgSets.get(0).get(12), GroundType.Grass, GroundType.Grass, GroundType.Dirt, GroundType.Dirt);
|
---|
342 | this.setBreakdown(this.imgSets.get(0).get(13), GroundType.Grass, GroundType.Grass, GroundType.Grass, GroundType.Dirt);
|
---|
343 | this.setBreakdown(this.imgSets.get(0).get(14), GroundType.Dirt, GroundType.Grass, GroundType.Grass, GroundType.Dirt);
|
---|
344 | this.setBreakdown(this.imgSets.get(0).get(15), GroundType.Grass, GroundType.Dirt, GroundType.Dirt, GroundType.Grass);
|
---|
345 | this.setBreakdown(this.imgSets.get(4).get(0), GroundType.Stone, GroundType.Stone, GroundType.Stone, GroundType.Stone);
|
---|
346 | this.setBreakdown(this.imgSets.get(4).get(1), GroundType.Stone, GroundType.Stone, GroundType.Stone, GroundType.Stone);
|
---|
347 | this.setBreakdown(this.imgSets.get(4).get(2), GroundType.Stone, GroundType.Stone, GroundType.Stone, GroundType.Stone);
|
---|
348 | this.setBreakdown(this.imgSets.get(4).get(3), GroundType.Stone, GroundType.Stone, GroundType.Stone, GroundType.Stone);
|
---|
349 | this.setBreakdown(this.imgSets.get(4).get(4), GroundType.Dirt, GroundType.Dirt, GroundType.Dirt, GroundType.Stone);
|
---|
350 | this.setBreakdown(this.imgSets.get(4).get(5), GroundType.Dirt, GroundType.Dirt, GroundType.Stone, GroundType.Stone);
|
---|
351 | this.setBreakdown(this.imgSets.get(4).get(6), GroundType.Dirt, GroundType.Dirt, GroundType.Stone, GroundType.Dirt);
|
---|
352 | this.setBreakdown(this.imgSets.get(4).get(7), GroundType.Dirt, GroundType.Stone, GroundType.Stone, GroundType.Stone);
|
---|
353 | this.setBreakdown(this.imgSets.get(4).get(8), GroundType.Stone, GroundType.Dirt, GroundType.Stone, GroundType.Stone);
|
---|
354 | this.setBreakdown(this.imgSets.get(4).get(9), GroundType.Dirt, GroundType.Stone, GroundType.Dirt, GroundType.Stone);
|
---|
355 | this.setBreakdown(this.imgSets.get(4).get(10), GroundType.Stone, GroundType.Stone, GroundType.Stone, GroundType.Stone);
|
---|
356 | this.setBreakdown(this.imgSets.get(4).get(11), GroundType.Stone, GroundType.Dirt, GroundType.Stone, GroundType.Dirt);
|
---|
357 | this.setBreakdown(this.imgSets.get(4).get(12), GroundType.Stone, GroundType.Stone, GroundType.Dirt, GroundType.Stone);
|
---|
358 | this.setBreakdown(this.imgSets.get(4).get(13), GroundType.Stone, GroundType.Stone, GroundType.Stone, GroundType.Dirt);
|
---|
359 | this.setBreakdown(this.imgSets.get(4).get(14), GroundType.Dirt, GroundType.Stone, GroundType.Dirt, GroundType.Dirt);
|
---|
360 | this.setBreakdown(this.imgSets.get(4).get(15), GroundType.Stone, GroundType.Stone, GroundType.Dirt, GroundType.Dirt);
|
---|
361 | this.setBreakdown(this.imgSets.get(4).get(16), GroundType.Stone, GroundType.Dirt, GroundType.Dirt, GroundType.Dirt);
|
---|
362 | this.setBreakdown(this.imgSets.get(4).get(17), GroundType.Dirt, GroundType.Stone, GroundType.Stone, GroundType.Dirt);
|
---|
363 | this.setBreakdown(this.imgSets.get(4).get(18), GroundType.Stone, GroundType.Dirt, GroundType.Dirt, GroundType.Stone);
|
---|
364 | this.setIndex = 0;
|
---|
365 | this.activeSet = this.imgSets.get(this.setIndex);
|
---|
366 | this.curTile = this.activeSet.get(0);
|
---|
367 | }
|
---|
368 |
|
---|
369 | private void loadCreatures() {
|
---|
370 | this.crSet = new ArrayList<Creature>();
|
---|
371 | Utils.loadCreatures(this.crMap, this.crSet);
|
---|
372 | this.curCr = this.crSet.get(0);
|
---|
373 | }
|
---|
374 |
|
---|
375 | private boolean createNewMap() {
|
---|
376 | final String name = ((Textbox)this.wndEditOptions.getMember("name")).getText();
|
---|
377 | final String strX = ((Textbox)this.wndEditOptions.getMember("x")).getText();
|
---|
378 | final String strY = ((Textbox)this.wndEditOptions.getMember("y")).getText();
|
---|
379 | boolean passed = false;
|
---|
380 | if (name.equals("")) {
|
---|
381 | this.showMessage("You didn't enter a name for the map");
|
---|
382 | }
|
---|
383 | else if (strX.equals("")) {
|
---|
384 | this.showMessage("You didn't enter a width");
|
---|
385 | }
|
---|
386 | else if (strY.equals("")) {
|
---|
387 | this.showMessage("You didn't enter a height");
|
---|
388 | }
|
---|
389 | else {
|
---|
390 | int x = 0;
|
---|
391 | int y = 0;
|
---|
392 | passed = true;
|
---|
393 | try {
|
---|
394 | x = Integer.parseInt(strX);
|
---|
395 | if (x <= 0) {
|
---|
396 | passed = false;
|
---|
397 | this.showMessage("The width must be positive");
|
---|
398 | }
|
---|
399 | }
|
---|
400 | catch (NumberFormatException nfe) {
|
---|
401 | passed = false;
|
---|
402 | this.showMessage("Your width is not a valid integer");
|
---|
403 | }
|
---|
404 | try {
|
---|
405 | y = Integer.parseInt(strY);
|
---|
406 | if (y <= 0) {
|
---|
407 | passed = false;
|
---|
408 | this.showMessage("The height must be positive");
|
---|
409 | }
|
---|
410 | }
|
---|
411 | catch (NumberFormatException nfe) {
|
---|
412 | passed = false;
|
---|
413 | this.showMessage("Your height is not a valid integer");
|
---|
414 | }
|
---|
415 | if (passed) {
|
---|
416 | this.playerLoc = new Point(400, 300);
|
---|
417 | MapEditor.map = new Map(x, y, this.imgSets.get(0).get(0), this.imgSets.get(0).get(9));
|
---|
418 | this.mapName = name;
|
---|
419 | this.horBar.setSize(800 * this.horBar.getMaxSize() / (MapEditor.map.getWidth() * 40 + 800));
|
---|
420 | this.verBar.setSize(600 * this.verBar.getMaxSize() / (MapEditor.map.getHeight() * 40 + 600));
|
---|
421 | this.horBar.setPosition(this.horBar.getMaxSize() * this.playerLoc.x / (40 * MapEditor.map.getWidth() + 800));
|
---|
422 | this.verBar.setPosition(this.verBar.getMaxSize() * this.playerLoc.y / (40 * MapEditor.map.getHeight() + 600));
|
---|
423 | this.showMessage(MapEditor.map.message);
|
---|
424 | }
|
---|
425 | }
|
---|
426 | return passed;
|
---|
427 | }
|
---|
428 |
|
---|
429 | private ArrayList<Tile> getTilesByBreakdown(final GroundType[] t) {
|
---|
430 | return this.tileByBreakdown[t[0].ordinal() * 27 + t[1].ordinal() * 9 + t[2].ordinal() * 3 + t[3].ordinal()];
|
---|
431 | }
|
---|
432 |
|
---|
433 | private GroundType[] getBreakdown(final Tile t) {
|
---|
434 | return this.tileBreakdowns.get(t.getImg().key);
|
---|
435 | }
|
---|
436 |
|
---|
437 | private void setBreakdown(final Tile t, final GroundType t1, final GroundType t2, final GroundType t3, final GroundType t4) {
|
---|
438 | final GroundType[] type = { t1, t2, t3, t4 };
|
---|
439 | this.tileBreakdowns.put(t.getImg().key, type);
|
---|
440 | final int index = t1.ordinal() * 27 + t2.ordinal() * 9 + t3.ordinal() * 3 + t4.ordinal();
|
---|
441 | if (this.tileByBreakdown[index] == null) {
|
---|
442 | this.tileByBreakdown[index] = new ArrayList<Tile>();
|
---|
443 | }
|
---|
444 | this.tileByBreakdown[index].add(t);
|
---|
445 | }
|
---|
446 |
|
---|
447 | private synchronized void handleEvents() {
|
---|
448 | switch (this.state) {
|
---|
449 | }
|
---|
450 | }
|
---|
451 |
|
---|
452 | private synchronized void render(final Graphics g) {
|
---|
453 | g.setColor(Color.black);
|
---|
454 | g.fillRect(0, 0, 1024, 768);
|
---|
455 | this.mapG.setColor(Color.black);
|
---|
456 | this.mapG.fillRect(0, 0, 800, 600);
|
---|
457 | switch (this.state) {
|
---|
458 | case Main: {
|
---|
459 | this.wndMain.draw(g);
|
---|
460 | break;
|
---|
461 | }
|
---|
462 | case Edit: {
|
---|
463 | this.wndEdit.draw(g);
|
---|
464 | this.drawPalette(g);
|
---|
465 | MapEditor.map.draw(this.mapG, this.playerLoc, this.bounds, this.passable);
|
---|
466 | g.drawImage(this.mapBuffer, 204, 148, null);
|
---|
467 | if (this.selectedObject != null) {
|
---|
468 | g.setColor(Color.blue);
|
---|
469 | final int selectedX = 400 - this.playerLoc.x + 204 + this.selectedObject.loc.x;
|
---|
470 | final int selectedY = 300 - this.playerLoc.y + 148 + this.selectedObject.loc.y;
|
---|
471 | g.drawOval(selectedX - 25, selectedY - 33, 50, 50);
|
---|
472 | }
|
---|
473 | if (this.selectedCreature != null) {
|
---|
474 | g.setColor(Color.blue);
|
---|
475 | final int selectedX = 400 - this.playerLoc.x + 204 + this.selectedCreature.loc.x;
|
---|
476 | final int selectedY = 300 - this.playerLoc.y + 148 + this.selectedCreature.loc.y;
|
---|
477 | g.drawOval(selectedX - 25, selectedY - 33, 50, 50);
|
---|
478 | break;
|
---|
479 | }
|
---|
480 | break;
|
---|
481 | }
|
---|
482 | }
|
---|
483 | switch (this.auxState) {
|
---|
484 | case MsgBox: {
|
---|
485 | this.wndMessage.draw(g);
|
---|
486 | break;
|
---|
487 | }
|
---|
488 | case LoadMap: {
|
---|
489 | this.wndLoadMap.draw(g);
|
---|
490 | break;
|
---|
491 | }
|
---|
492 | }
|
---|
493 | if (this.showFps) {
|
---|
494 | this.drawDiagnostics(g);
|
---|
495 | }
|
---|
496 | }
|
---|
497 |
|
---|
498 | private void drawPalette(final Graphics g) {
|
---|
499 | if (this.showCr) {
|
---|
500 | final DynamicImage curImg = this.curCr.getModel().getAnimation(Direction.South, Action.Standing).frames.get(0);
|
---|
501 | curImg.draw(g, (204 - curImg.getWidth()) / 2, 40);
|
---|
502 | int yOffset = 215;
|
---|
503 | for (int x = 0; x < this.crSet.size(); x += 2) {
|
---|
504 | final DynamicImage img1 = this.crSet.get(x).getModel().getAnimation(Direction.South, Action.Standing).frames.get(0);
|
---|
505 | img1.draw(g, 97 - img1.getWidth(), yOffset);
|
---|
506 | if (this.crSet.size() != x + 1) {
|
---|
507 | final DynamicImage img2 = this.crSet.get(x + 1).getModel().getAnimation(Direction.South, Action.Standing).frames.get(0);
|
---|
508 | img2.draw(g, 107, yOffset);
|
---|
509 | yOffset += Math.max(img1.getHeight(), img2.getHeight()) + 10;
|
---|
510 | }
|
---|
511 | }
|
---|
512 | this.drawArrows(g, 0, this.curLevel, 5);
|
---|
513 | this.drawArrows(g, 50, this.imgSets.size(), this.imgSets.size() - 1);
|
---|
514 | return;
|
---|
515 | }
|
---|
516 | this.curTile.getImg().drawNoOffset(g, (204 - this.curTile.getImg().getWidth()) / 2, 40);
|
---|
517 | int yOffset2 = 215;
|
---|
518 | for (int x2 = 0; x2 < this.activeSet.size(); x2 += 2) {
|
---|
519 | this.activeSet.get(x2).getImg().drawNoOffset(g, 97 - this.activeSet.get(x2).getImg().getWidth(), yOffset2);
|
---|
520 | if (this.activeSet.size() != x2 + 1) {
|
---|
521 | this.activeSet.get(x2 + 1).getImg().drawNoOffset(g, 107, yOffset2);
|
---|
522 | yOffset2 += Math.max(this.activeSet.get(x2).getImg().getHeight(), this.activeSet.get(x2 + 1).getImg().getHeight()) + 10;
|
---|
523 | }
|
---|
524 | }
|
---|
525 | this.drawArrows(g, 0, this.curLevel, 5);
|
---|
526 | this.drawArrows(g, 50, this.setIndex, this.imgSets.size() - 1);
|
---|
527 | }
|
---|
528 |
|
---|
529 | private void drawArrows(final Graphics g, final int arrowShift, final int curIndex, final int maxIndex) {
|
---|
530 | if (curIndex > 0) {
|
---|
531 | g.setColor(Color.yellow);
|
---|
532 | }
|
---|
533 | else {
|
---|
534 | g.setColor(new Color(127, 127, 0));
|
---|
535 | }
|
---|
536 | g.drawLine(67, 146 + arrowShift, 87, 146 + arrowShift);
|
---|
537 | g.drawLine(67, 152 + arrowShift, 87, 152 + arrowShift);
|
---|
538 | g.drawLine(87, 146 + arrowShift, 87, 152 + arrowShift);
|
---|
539 | g.drawLine(60, 149 + arrowShift, 67, 142 + arrowShift);
|
---|
540 | g.drawLine(67, 142 + arrowShift, 67, 146 + arrowShift);
|
---|
541 | g.drawLine(60, 149 + arrowShift, 67, 156 + arrowShift);
|
---|
542 | g.drawLine(67, 156 + arrowShift, 67, 152 + arrowShift);
|
---|
543 | if (curIndex < maxIndex) {
|
---|
544 | g.setColor(Color.yellow);
|
---|
545 | }
|
---|
546 | else {
|
---|
547 | g.setColor(new Color(127, 127, 0));
|
---|
548 | }
|
---|
549 | g.drawLine(117, 146 + arrowShift, 137, 146 + arrowShift);
|
---|
550 | g.drawLine(117, 152 + arrowShift, 137, 152 + arrowShift);
|
---|
551 | g.drawLine(117, 146 + arrowShift, 117, 152 + arrowShift);
|
---|
552 | g.drawLine(144, 149 + arrowShift, 137, 142 + arrowShift);
|
---|
553 | g.drawLine(137, 142 + arrowShift, 137, 146 + arrowShift);
|
---|
554 | g.drawLine(144, 149 + arrowShift, 137, 156 + arrowShift);
|
---|
555 | g.drawLine(137, 156 + arrowShift, 137, 152 + arrowShift);
|
---|
556 | }
|
---|
557 |
|
---|
558 | private void drawDiagnostics(final Graphics g) {
|
---|
559 | this.wndDiagnostics.draw(g);
|
---|
560 | g.setColor(Color.green);
|
---|
561 | g.setFont(this.fontTT);
|
---|
562 | g.drawString("FPS: " + this.lastFrameCount, 0, 15);
|
---|
563 | }
|
---|
564 |
|
---|
565 | private boolean changeLevel(final int x, final int y) {
|
---|
566 | if (142 < y && y < 156) {
|
---|
567 | if (60 <= x && x <= 87) {
|
---|
568 | if (this.curLevel > 0) {
|
---|
569 | --this.curLevel;
|
---|
570 | ((Label)this.wndEditPalette.getMember("level")).setText("Level " + this.curLevel);
|
---|
571 | }
|
---|
572 | return true;
|
---|
573 | }
|
---|
574 | if (117 <= x && x <= 144) {
|
---|
575 | if (this.curLevel < 5) {
|
---|
576 | ++this.curLevel;
|
---|
577 | ((Label)this.wndEditPalette.getMember("level")).setText("Level " + this.curLevel);
|
---|
578 | }
|
---|
579 | return true;
|
---|
580 | }
|
---|
581 | }
|
---|
582 | return false;
|
---|
583 | }
|
---|
584 |
|
---|
585 | private boolean changeSet(final int x, final int y) {
|
---|
586 | if (192 < y && y < 206) {
|
---|
587 | if (60 <= x && x <= 87) {
|
---|
588 | if (this.setIndex > 0) {
|
---|
589 | --this.setIndex;
|
---|
590 | this.activeSet = this.imgSets.get(this.setIndex);
|
---|
591 | this.showCr = false;
|
---|
592 | }
|
---|
593 | return true;
|
---|
594 | }
|
---|
595 | if (117 <= x && x <= 144) {
|
---|
596 | if (this.setIndex < this.imgSets.size() - 1) {
|
---|
597 | ++this.setIndex;
|
---|
598 | this.activeSet = this.imgSets.get(this.setIndex);
|
---|
599 | }
|
---|
600 | else if (this.setIndex == this.imgSets.size() - 1) {
|
---|
601 | ++this.setIndex;
|
---|
602 | this.showCr = true;
|
---|
603 | }
|
---|
604 | return true;
|
---|
605 | }
|
---|
606 | }
|
---|
607 | return false;
|
---|
608 | }
|
---|
609 |
|
---|
610 | private boolean selectNewImage(final int x, final int y) {
|
---|
611 | boolean foundImage = false;
|
---|
612 | int index = 0;
|
---|
613 | int yOffset = 215;
|
---|
614 | if (this.showCr) {
|
---|
615 | DynamicImage img2 = null;
|
---|
616 | while (index < this.crSet.size() && !foundImage) {
|
---|
617 | final DynamicImage img3 = this.crSet.get(index).getModel().getAnimation(Direction.South, Action.Standing).frames.get(0);
|
---|
618 | int rowHeight;
|
---|
619 | if (this.crSet.size() == index + 1) {
|
---|
620 | rowHeight = img3.getHeight();
|
---|
621 | }
|
---|
622 | else {
|
---|
623 | img2 = this.crSet.get(index + 1).getModel().getAnimation(Direction.South, Action.Standing).frames.get(0);
|
---|
624 | rowHeight = Math.max(img3.getHeight(), img2.getHeight());
|
---|
625 | }
|
---|
626 | if (yOffset <= y && y < yOffset + rowHeight) {
|
---|
627 | if (97 - img3.getWidth() <= x && x < 97) {
|
---|
628 | if (y < yOffset + img3.getHeight()) {
|
---|
629 | foundImage = true;
|
---|
630 | }
|
---|
631 | }
|
---|
632 | else if (107 <= x && this.crSet.size() > index + 1 && x < 107 + img2.getWidth() && y < yOffset + img2.getHeight()) {
|
---|
633 | foundImage = true;
|
---|
634 | ++index;
|
---|
635 | }
|
---|
636 | }
|
---|
637 | else {
|
---|
638 | yOffset += rowHeight + 10;
|
---|
639 | }
|
---|
640 | if (!foundImage) {
|
---|
641 | index += 2;
|
---|
642 | }
|
---|
643 | }
|
---|
644 | if (foundImage) {
|
---|
645 | this.curCr = this.crSet.get(index);
|
---|
646 | }
|
---|
647 | return foundImage;
|
---|
648 | }
|
---|
649 | while (index < this.activeSet.size() && !foundImage) {
|
---|
650 | int rowHeight;
|
---|
651 | if (this.activeSet.size() == index + 1) {
|
---|
652 | rowHeight = this.activeSet.get(index).getImg().getHeight();
|
---|
653 | }
|
---|
654 | else {
|
---|
655 | rowHeight = Math.max(this.activeSet.get(index).getImg().getHeight(), this.activeSet.get(index + 1).getImg().getHeight());
|
---|
656 | }
|
---|
657 | if (yOffset <= y && y < yOffset + rowHeight) {
|
---|
658 | if (97 - this.activeSet.get(index).getImg().getWidth() <= x && x < 97) {
|
---|
659 | if (y < yOffset + this.activeSet.get(index).getImg().getHeight()) {
|
---|
660 | foundImage = true;
|
---|
661 | }
|
---|
662 | }
|
---|
663 | else if (107 <= x && this.activeSet.size() > index + 1 && x < 107 + this.activeSet.get(index + 1).getImg().getWidth() && y < yOffset + this.activeSet.get(index + 1).getImg().getHeight()) {
|
---|
664 | foundImage = true;
|
---|
665 | ++index;
|
---|
666 | }
|
---|
667 | }
|
---|
668 | else {
|
---|
669 | yOffset += rowHeight + 10;
|
---|
670 | }
|
---|
671 | if (!foundImage) {
|
---|
672 | index += 2;
|
---|
673 | }
|
---|
674 | }
|
---|
675 | if (foundImage) {
|
---|
676 | this.curTile = this.activeSet.get(index);
|
---|
677 | }
|
---|
678 | this.highLevelPlacement = (this.activeSet == this.imgSets.get(6));
|
---|
679 | return foundImage;
|
---|
680 | }
|
---|
681 |
|
---|
682 | private void placeTile(int x, int y) {
|
---|
683 | x -= 204;
|
---|
684 | y -= 148;
|
---|
685 | if (x >= 0 && x < 800 && y >= 0 && y < 600) {
|
---|
686 | x += this.playerLoc.x - 400;
|
---|
687 | y += this.playerLoc.y - 300;
|
---|
688 | if (x >= 0 && x < 40 * MapEditor.map.getWidth() && y >= 0 && y < 40 * MapEditor.map.getHeight()) {
|
---|
689 | if (this.showCr) {
|
---|
690 | MapEditor.map.addCreature(x / 40, y / 40, this.curCr.copy(new Point(x, y)));
|
---|
691 | }
|
---|
692 | else if (this.curTile.getImg().getType() == MapType.Ground) {
|
---|
693 | if (this.highLevelPlacement) {
|
---|
694 | this.placeGroup(this.curTile, x, y);
|
---|
695 | }
|
---|
696 | else {
|
---|
697 | MapEditor.map.setGround(x / 40, y / 40, new Tile(this.curTile, x - x % 40, y - y % 40, this.curLevel));
|
---|
698 | }
|
---|
699 | }
|
---|
700 | else if (this.curTile.getImg().getType() == MapType.Object) {
|
---|
701 | MapEditor.map.addObject(x / 40, y / 40, new Tile(this.curTile, x, y, this.curLevel));
|
---|
702 | System.out.println("place at (" + x / 40 + ", " + y / 40 + ")");
|
---|
703 | }
|
---|
704 | else if (this.curTile.getImg().getType() == MapType.Structure) {
|
---|
705 | MapEditor.map.addObject(x / 40, y / 40, new Tile(this.curTile, x - x % 40 + 20, y - y % 40 + 39, this.curLevel));
|
---|
706 | }
|
---|
707 | }
|
---|
708 | }
|
---|
709 | }
|
---|
710 |
|
---|
711 | private boolean containsGroundType(final GroundType[] arr, final GroundType t) {
|
---|
712 | return arr[0] == t || arr[1] == t || arr[2] == t || arr[3] == t;
|
---|
713 | }
|
---|
714 |
|
---|
715 | private void placeGroup(final Tile tile, final int x, final int y) {
|
---|
716 | final int xMap = x / 40;
|
---|
717 | final int yMap = y / 40;
|
---|
718 | final ArrayList[] tiles = new ArrayList[9];
|
---|
719 | final GroundType[] middle = this.getBreakdown(tile);
|
---|
720 | final GroundType[] breakdown = new GroundType[4];
|
---|
721 | if (this.containsGroundType(middle, GroundType.Stone)) {
|
---|
722 | if (xMap > 0 && yMap > 0 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap - 1).getGround()), GroundType.Grass)) {
|
---|
723 | this.placeGroup(this.imgSets.get(6).get(1), x - 40, y - 40);
|
---|
724 | }
|
---|
725 | if (yMap > 0 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap, yMap - 1).getGround()), GroundType.Grass)) {
|
---|
726 | this.placeGroup(this.imgSets.get(6).get(1), x, y - 40);
|
---|
727 | }
|
---|
728 | if (xMap < MapEditor.map.getWidth() - 1 && yMap > 0 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap - 1).getGround()), GroundType.Grass)) {
|
---|
729 | this.placeGroup(this.imgSets.get(6).get(1), x + 40, y - 40);
|
---|
730 | }
|
---|
731 | if (xMap < MapEditor.map.getWidth() - 1 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap).getGround()), GroundType.Grass)) {
|
---|
732 | this.placeGroup(this.imgSets.get(6).get(1), x + 40, y);
|
---|
733 | }
|
---|
734 | if (xMap < MapEditor.map.getWidth() - 1 && yMap < MapEditor.map.getHeight() - 1 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap + 1).getGround()), GroundType.Grass)) {
|
---|
735 | this.placeGroup(this.imgSets.get(6).get(1), x + 40, y + 40);
|
---|
736 | }
|
---|
737 | if (yMap < MapEditor.map.getHeight() - 1 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap, yMap + 1).getGround()), GroundType.Grass)) {
|
---|
738 | this.placeGroup(this.imgSets.get(6).get(1), x, y + 40);
|
---|
739 | }
|
---|
740 | if (xMap > 0 && yMap < MapEditor.map.getHeight() - 1 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap + 1).getGround()), GroundType.Grass)) {
|
---|
741 | this.placeGroup(this.imgSets.get(6).get(1), x - 40, y + 40);
|
---|
742 | }
|
---|
743 | if (xMap > 0 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap).getGround()), GroundType.Grass)) {
|
---|
744 | this.placeGroup(this.imgSets.get(6).get(1), x - 40, y);
|
---|
745 | }
|
---|
746 | }
|
---|
747 | else if (this.containsGroundType(middle, GroundType.Grass)) {
|
---|
748 | if (xMap > 0 && yMap > 0 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap - 1).getGround()), GroundType.Stone)) {
|
---|
749 | this.placeGroup(this.imgSets.get(6).get(1), x - 40, y - 40);
|
---|
750 | }
|
---|
751 | if (yMap > 0 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap, yMap - 1).getGround()), GroundType.Stone)) {
|
---|
752 | this.placeGroup(this.imgSets.get(6).get(1), x, y - 40);
|
---|
753 | }
|
---|
754 | if (xMap < MapEditor.map.getWidth() - 1 && yMap > 0 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap - 1).getGround()), GroundType.Stone)) {
|
---|
755 | this.placeGroup(this.imgSets.get(6).get(1), x + 40, y - 40);
|
---|
756 | }
|
---|
757 | if (xMap < MapEditor.map.getWidth() - 1 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap).getGround()), GroundType.Stone)) {
|
---|
758 | this.placeGroup(this.imgSets.get(6).get(1), x + 40, y);
|
---|
759 | }
|
---|
760 | if (xMap < MapEditor.map.getWidth() - 1 && yMap < MapEditor.map.getHeight() - 1 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap + 1).getGround()), GroundType.Stone)) {
|
---|
761 | this.placeGroup(this.imgSets.get(6).get(1), x + 40, y + 40);
|
---|
762 | }
|
---|
763 | if (yMap < MapEditor.map.getHeight() - 1 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap, yMap + 1).getGround()), GroundType.Stone)) {
|
---|
764 | this.placeGroup(this.imgSets.get(6).get(1), x, y + 40);
|
---|
765 | }
|
---|
766 | if (xMap > 0 && yMap < MapEditor.map.getHeight() - 1 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap + 1).getGround()), GroundType.Stone)) {
|
---|
767 | this.placeGroup(this.imgSets.get(6).get(1), x - 40, y + 40);
|
---|
768 | }
|
---|
769 | if (xMap > 0 && this.containsGroundType(this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap).getGround()), GroundType.Stone)) {
|
---|
770 | this.placeGroup(this.imgSets.get(6).get(1), x - 40, y);
|
---|
771 | }
|
---|
772 | }
|
---|
773 | tiles[4] = this.getTilesByBreakdown(middle);
|
---|
774 | if (xMap > 0 && yMap > 0) {
|
---|
775 | final GroundType[] old = this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap - 1).getGround());
|
---|
776 | System.arraycopy(old, 0, breakdown, 0, 4);
|
---|
777 | breakdown[3] = middle[0];
|
---|
778 | tiles[0] = this.getTilesByBreakdown(breakdown);
|
---|
779 | this.addTile(x - 40, y - 40, tiles[0].get(new Random().nextInt(tiles[0].size())));
|
---|
780 | }
|
---|
781 | if (yMap > 0) {
|
---|
782 | final GroundType[] old = this.getBreakdown(MapEditor.map.getLoc(xMap, yMap - 1).getGround());
|
---|
783 | System.arraycopy(old, 0, breakdown, 0, 4);
|
---|
784 | breakdown[2] = middle[0];
|
---|
785 | breakdown[3] = middle[1];
|
---|
786 | tiles[1] = this.getTilesByBreakdown(breakdown);
|
---|
787 | this.addTile(x, y - 40, tiles[1].get(new Random().nextInt(tiles[1].size())));
|
---|
788 | }
|
---|
789 | if (xMap < MapEditor.map.getWidth() - 1 && yMap > 0) {
|
---|
790 | final GroundType[] old = this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap - 1).getGround());
|
---|
791 | System.arraycopy(old, 0, breakdown, 0, 4);
|
---|
792 | breakdown[2] = middle[1];
|
---|
793 | tiles[2] = this.getTilesByBreakdown(breakdown);
|
---|
794 | this.addTile(x + 40, y - 40, tiles[2].get(new Random().nextInt(tiles[2].size())));
|
---|
795 | }
|
---|
796 | if (xMap < MapEditor.map.getWidth() - 1) {
|
---|
797 | final GroundType[] old = this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap).getGround());
|
---|
798 | System.arraycopy(old, 0, breakdown, 0, 4);
|
---|
799 | breakdown[0] = middle[1];
|
---|
800 | breakdown[2] = middle[3];
|
---|
801 | tiles[5] = this.getTilesByBreakdown(breakdown);
|
---|
802 | this.addTile(x + 40, y, tiles[5].get(new Random().nextInt(tiles[5].size())));
|
---|
803 | }
|
---|
804 | if (xMap < MapEditor.map.getWidth() - 1 && yMap < MapEditor.map.getHeight() - 1) {
|
---|
805 | final GroundType[] old = this.getBreakdown(MapEditor.map.getLoc(xMap + 1, yMap + 1).getGround());
|
---|
806 | System.arraycopy(old, 0, breakdown, 0, 4);
|
---|
807 | breakdown[0] = middle[3];
|
---|
808 | tiles[8] = this.getTilesByBreakdown(breakdown);
|
---|
809 | this.addTile(x + 40, y + 40, tiles[8].get(new Random().nextInt(tiles[8].size())));
|
---|
810 | }
|
---|
811 | if (yMap < MapEditor.map.getHeight() - 1) {
|
---|
812 | final GroundType[] old = this.getBreakdown(MapEditor.map.getLoc(xMap, yMap + 1).getGround());
|
---|
813 | System.arraycopy(old, 0, breakdown, 0, 4);
|
---|
814 | breakdown[0] = middle[2];
|
---|
815 | breakdown[1] = middle[3];
|
---|
816 | tiles[7] = this.getTilesByBreakdown(breakdown);
|
---|
817 | this.addTile(x, y + 40, tiles[7].get(new Random().nextInt(tiles[7].size())));
|
---|
818 | }
|
---|
819 | if (xMap > 0 && yMap < MapEditor.map.getHeight() - 1) {
|
---|
820 | final GroundType[] old = this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap + 1).getGround());
|
---|
821 | System.arraycopy(old, 0, breakdown, 0, 4);
|
---|
822 | breakdown[1] = middle[2];
|
---|
823 | tiles[6] = this.getTilesByBreakdown(breakdown);
|
---|
824 | this.addTile(x - 40, y + 40, tiles[6].get(new Random().nextInt(tiles[6].size())));
|
---|
825 | }
|
---|
826 | if (xMap > 0) {
|
---|
827 | final GroundType[] old = this.getBreakdown(MapEditor.map.getLoc(xMap - 1, yMap).getGround());
|
---|
828 | System.arraycopy(old, 0, breakdown, 0, 4);
|
---|
829 | breakdown[1] = middle[0];
|
---|
830 | breakdown[3] = middle[2];
|
---|
831 | tiles[3] = this.getTilesByBreakdown(breakdown);
|
---|
832 | this.addTile(x - 40, y, tiles[3].get(new Random().nextInt(tiles[3].size())));
|
---|
833 | }
|
---|
834 | this.addTile(x, y, tiles[4].get(new Random().nextInt(tiles[4].size())));
|
---|
835 | }
|
---|
836 |
|
---|
837 | private void addTile(final int x, final int y, final Tile t) {
|
---|
838 | MapEditor.map.setGround(x / 40, y / 40, new Tile(t, x - x % 40, y - y % 40, this.curLevel));
|
---|
839 | }
|
---|
840 |
|
---|
841 | private void selectObject(int x, int y) {
|
---|
842 | x -= 204;
|
---|
843 | y -= 148;
|
---|
844 | if (x >= 0 && x < 800 && y >= 0 && y < 600) {
|
---|
845 | x += this.playerLoc.x - 400;
|
---|
846 | y += this.playerLoc.y - 300;
|
---|
847 | final Iterator<Tile> iter = MapEditor.map.getLoc(x / 40, y / 40).getObjects().iterator();
|
---|
848 | Tile closest = null;
|
---|
849 | final Point curPoint = new Point(x, y);
|
---|
850 | if (!iter.hasNext()) {
|
---|
851 | this.selectedObject = null;
|
---|
852 | return;
|
---|
853 | }
|
---|
854 | closest = iter.next();
|
---|
855 | while (iter.hasNext()) {
|
---|
856 | final Tile cur = iter.next();
|
---|
857 | if (cur.loc.distance(curPoint) < closest.loc.distance(curPoint)) {
|
---|
858 | closest = cur;
|
---|
859 | }
|
---|
860 | }
|
---|
861 | this.selectedObject = closest;
|
---|
862 | }
|
---|
863 | else {
|
---|
864 | this.selectedObject = null;
|
---|
865 | }
|
---|
866 | }
|
---|
867 |
|
---|
868 | private void selectCreature(int x, int y) {
|
---|
869 | x -= 204;
|
---|
870 | y -= 148;
|
---|
871 | if (x >= 0 && x < 800 && y >= 0 && y < 600) {
|
---|
872 | x += this.playerLoc.x - 400;
|
---|
873 | y += this.playerLoc.y - 300;
|
---|
874 | final Iterator<Creature> iter = MapEditor.map.getLoc(x / 40, y / 40).getCreatures().iterator();
|
---|
875 | Creature closest = null;
|
---|
876 | final Point curPoint = new Point(x, y);
|
---|
877 | if (!iter.hasNext()) {
|
---|
878 | this.selectedCreature = null;
|
---|
879 | return;
|
---|
880 | }
|
---|
881 | closest = iter.next();
|
---|
882 | while (iter.hasNext()) {
|
---|
883 | final Creature cur = iter.next();
|
---|
884 | if (cur.loc.distance(curPoint) < closest.loc.distance(curPoint)) {
|
---|
885 | closest = cur;
|
---|
886 | }
|
---|
887 | }
|
---|
888 | if (this.selectedObject == null || closest.loc.distance(curPoint) < this.selectedObject.loc.distance(curPoint)) {
|
---|
889 | this.selectedCreature = closest;
|
---|
890 | }
|
---|
891 | }
|
---|
892 | else {
|
---|
893 | this.selectedCreature = null;
|
---|
894 | }
|
---|
895 | }
|
---|
896 |
|
---|
897 | public void showMessage(final String text) {
|
---|
898 | this.auxState = AuxState.MsgBox;
|
---|
899 | ((Label)this.wndMessage.getMember("label")).setText(text);
|
---|
900 | }
|
---|
901 |
|
---|
902 | private void selectText(final Textbox text) {
|
---|
903 | if (this.selectedText != null) {
|
---|
904 | this.selectedText.setSelected(false);
|
---|
905 | }
|
---|
906 | if ((this.selectedText = text) != null) {
|
---|
907 | text.setSelected(true);
|
---|
908 | }
|
---|
909 | }
|
---|
910 |
|
---|
911 | private synchronized void handleMouseInput(final MouseEvent e) {
|
---|
912 | if (!this.started) {
|
---|
913 | return;
|
---|
914 | }
|
---|
915 | this.selectText(null);
|
---|
916 | switch (this.auxState) {
|
---|
917 | case None: {
|
---|
918 | switch (this.state) {
|
---|
919 | case Main: {
|
---|
920 | if (this.wndMain.getMember("new map").isClicked(e.getX(), e.getY())) {
|
---|
921 | MapEditor.map = new Map(40, 40, this.activeSet.get(0));
|
---|
922 | this.playerLoc = new Point(400, 300);
|
---|
923 | this.mapName = "mapSave.txt";
|
---|
924 | this.horBar.setSize(800 * this.horBar.getMaxSize() / (MapEditor.map.getWidth() * 40 + 800));
|
---|
925 | this.verBar.setSize(600 * this.verBar.getMaxSize() / (MapEditor.map.getHeight() * 40 + 600));
|
---|
926 | this.horBar.setPosition(this.horBar.getMaxSize() * this.playerLoc.x / (40 * MapEditor.map.getWidth() + 800));
|
---|
927 | this.verBar.setPosition(this.verBar.getMaxSize() * this.playerLoc.y / (40 * MapEditor.map.getHeight() + 600));
|
---|
928 | this.state = State.Edit;
|
---|
929 | break;
|
---|
930 | }
|
---|
931 | if (this.wndMain.getMember("load map").isClicked(e.getX(), e.getY())) {
|
---|
932 | this.auxState = AuxState.LoadMap;
|
---|
933 | ((Textbox)this.wndLoadMap.getMember("map_name")).setText("mapSave.txt");
|
---|
934 | break;
|
---|
935 | }
|
---|
936 | if (this.wndMain.getMember("quit").isClicked(e.getX(), e.getY())) {
|
---|
937 | this.done = true;
|
---|
938 | break;
|
---|
939 | }
|
---|
940 | break;
|
---|
941 | }
|
---|
942 | case Edit: {
|
---|
943 | if (this.wndEditOptions.getMember("name").isClicked(e.getX(), e.getY())) {
|
---|
944 | this.selectText((Textbox)this.wndEditOptions.getMember("name"));
|
---|
945 | break;
|
---|
946 | }
|
---|
947 | if (this.wndEditOptions.getMember("x").isClicked(e.getX(), e.getY())) {
|
---|
948 | this.selectText((Textbox)this.wndEditOptions.getMember("x"));
|
---|
949 | break;
|
---|
950 | }
|
---|
951 | if (this.wndEditOptions.getMember("y").isClicked(e.getX(), e.getY())) {
|
---|
952 | this.selectText((Textbox)this.wndEditOptions.getMember("y"));
|
---|
953 | break;
|
---|
954 | }
|
---|
955 | if (this.wndEditOptions.getMember("new").isClicked(e.getX(), e.getY())) {
|
---|
956 | this.createNewMap();
|
---|
957 | break;
|
---|
958 | }
|
---|
959 | if (this.wndEditOptions.getMember("save").isClicked(e.getX(), e.getY())) {
|
---|
960 | MapEditor.map.save(this.mapName);
|
---|
961 | this.showMessage(MapEditor.map.message);
|
---|
962 | break;
|
---|
963 | }
|
---|
964 | if (this.wndEditOptions.getMember("load").isClicked(e.getX(), e.getY())) {
|
---|
965 | this.auxState = AuxState.LoadMap;
|
---|
966 | ((Textbox)this.wndLoadMap.getMember("map_name")).setText("mapSave.txt");
|
---|
967 | break;
|
---|
968 | }
|
---|
969 | if (this.wndEditOptions.getMember("back").isClicked(e.getX(), e.getY())) {
|
---|
970 | this.state = State.Main;
|
---|
971 | break;
|
---|
972 | }
|
---|
973 | if (this.wndEdit.handleEvent(e)) {
|
---|
974 | this.playerLoc.x = (MapEditor.map.getWidth() * 40 + 800) * this.horBar.getPosition() / this.horBar.getMaxSize();
|
---|
975 | this.playerLoc.y = (MapEditor.map.getHeight() * 40 + 600) * this.verBar.getPosition() / this.verBar.getMaxSize();
|
---|
976 | break;
|
---|
977 | }
|
---|
978 | if (this.selectNewImage(e.getX(), e.getY()) || this.changeSet(e.getX(), e.getY()) || this.changeLevel(e.getX(), e.getY())) {
|
---|
979 | break;
|
---|
980 | }
|
---|
981 | if (e.isShiftDown()) {
|
---|
982 | this.selectObject(e.getX(), e.getY());
|
---|
983 | this.selectCreature(e.getX(), e.getY());
|
---|
984 | break;
|
---|
985 | }
|
---|
986 | this.placeTile(e.getX(), e.getY());
|
---|
987 | break;
|
---|
988 | }
|
---|
989 | }
|
---|
990 | break;
|
---|
991 | }
|
---|
992 | case MsgBox: {
|
---|
993 | if (this.wndMessage.getMember("button").isClicked(e.getX(), e.getY())) {
|
---|
994 | this.auxState = AuxState.None;
|
---|
995 | break;
|
---|
996 | }
|
---|
997 | break;
|
---|
998 | }
|
---|
999 | case LoadMap: {
|
---|
1000 | if (this.wndLoadMap.getMember("map_name").isClicked(e.getX(), e.getY())) {
|
---|
1001 | this.selectText((Textbox)this.wndLoadMap.getMember("map_name"));
|
---|
1002 | break;
|
---|
1003 | }
|
---|
1004 | if (this.wndLoadMap.getMember("load").isClicked(e.getX(), e.getY())) {
|
---|
1005 | final String strName = ((Textbox)this.wndLoadMap.getMember("map_name")).getText();
|
---|
1006 | MapEditor.map = null;
|
---|
1007 | final Map newMap = Map.load(strName, MapEditor.map, this.imageMap, this.crMap);
|
---|
1008 | if (newMap.valid) {
|
---|
1009 | MapEditor.map = newMap;
|
---|
1010 | this.playerLoc = new Point(400, 300);
|
---|
1011 | this.mapName = strName;
|
---|
1012 | this.horBar.setSize(800 * this.horBar.getMaxSize() / (MapEditor.map.getWidth() * 40 + 800));
|
---|
1013 | this.verBar.setSize(600 * this.verBar.getMaxSize() / (MapEditor.map.getHeight() * 40 + 600));
|
---|
1014 | this.horBar.setPosition(this.horBar.getMaxSize() * this.playerLoc.x / (40 * MapEditor.map.getWidth() + 800));
|
---|
1015 | this.verBar.setPosition(this.verBar.getMaxSize() * this.playerLoc.y / (40 * MapEditor.map.getHeight() + 600));
|
---|
1016 | this.state = State.Edit;
|
---|
1017 | }
|
---|
1018 | this.showMessage(newMap.message);
|
---|
1019 | break;
|
---|
1020 | }
|
---|
1021 | if (this.wndLoadMap.getMember("back").isClicked(e.getX(), e.getY())) {
|
---|
1022 | this.auxState = AuxState.None;
|
---|
1023 | break;
|
---|
1024 | }
|
---|
1025 | break;
|
---|
1026 | }
|
---|
1027 | }
|
---|
1028 | }
|
---|
1029 |
|
---|
1030 | public void handleKeyboardInput(final KeyEvent e) {
|
---|
1031 | if (this.selectedText != null) {
|
---|
1032 | this.selectedText.handleEvent(e);
|
---|
1033 | }
|
---|
1034 | else if (e.getKeyCode() == 83) {
|
---|
1035 | this.showFps = !this.showFps;
|
---|
1036 | }
|
---|
1037 | else if (e.getKeyCode() == 27) {
|
---|
1038 | if (this.state == State.Edit) {
|
---|
1039 | this.state = State.Main;
|
---|
1040 | }
|
---|
1041 | else {
|
---|
1042 | this.done = true;
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 | else if (e.getKeyCode() == 127) {
|
---|
1046 | if (this.state == State.Edit && this.selectedObject != null) {
|
---|
1047 | MapEditor.map.removeObject(this.selectedObject.getMapX(), this.selectedObject.getMapY(), this.selectedObject);
|
---|
1048 | this.selectedObject = null;
|
---|
1049 | }
|
---|
1050 | if (this.state == State.Edit && this.selectedCreature != null) {
|
---|
1051 | MapEditor.map.removeCreature(this.selectedCreature.getMapX(), this.selectedCreature.getMapY(), this.selectedCreature);
|
---|
1052 | this.selectedCreature = null;
|
---|
1053 | }
|
---|
1054 | }
|
---|
1055 | else if (e.getKeyCode() == 90 && this.state == State.Edit) {
|
---|
1056 | this.bounds = !this.bounds;
|
---|
1057 | }
|
---|
1058 | else if (e.getKeyCode() == 88 && this.state == State.Edit) {
|
---|
1059 | this.passable = !this.passable;
|
---|
1060 | }
|
---|
1061 | }
|
---|
1062 |
|
---|
1063 | @Override
|
---|
1064 | public void mousePressed(final MouseEvent e) {
|
---|
1065 | this.handleMouseInput(e);
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 | @Override
|
---|
1069 | public void mouseReleased(final MouseEvent e) {
|
---|
1070 | }
|
---|
1071 |
|
---|
1072 | @Override
|
---|
1073 | public void mouseEntered(final MouseEvent e) {
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | @Override
|
---|
1077 | public void mouseExited(final MouseEvent e) {
|
---|
1078 | }
|
---|
1079 |
|
---|
1080 | @Override
|
---|
1081 | public void mouseClicked(final MouseEvent e) {
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | @Override
|
---|
1085 | public void keyTyped(final KeyEvent e) {
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | @Override
|
---|
1089 | public void keyPressed(final KeyEvent e) {
|
---|
1090 | this.handleKeyboardInput(e);
|
---|
1091 | }
|
---|
1092 |
|
---|
1093 | @Override
|
---|
1094 | public void keyReleased(final KeyEvent e) {
|
---|
1095 | }
|
---|
1096 |
|
---|
1097 | public static void main(final String[] args) {
|
---|
1098 | try {
|
---|
1099 | final PrintStream st = new PrintStream(new FileOutputStream("errMapEditor.txt", true));
|
---|
1100 | System.setErr(st);
|
---|
1101 | System.setOut(st);
|
---|
1102 | System.out.println("-----[ Session started on " + Utils.dateString() + " ]-----");
|
---|
1103 | final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
---|
1104 | final GraphicsDevice device = env.getDefaultScreenDevice();
|
---|
1105 | new MapEditor(device);
|
---|
1106 | }
|
---|
1107 | catch (Exception e) {
|
---|
1108 | e.printStackTrace();
|
---|
1109 | }
|
---|
1110 | System.exit(0);
|
---|
1111 | }
|
---|
1112 |
|
---|
1113 | public enum AuxState
|
---|
1114 | {
|
---|
1115 | None("None", 0),
|
---|
1116 | MsgBox("MsgBox", 1),
|
---|
1117 | LoadMap("LoadMap", 2);
|
---|
1118 |
|
---|
1119 | private AuxState(final String s, final int n) {
|
---|
1120 | }
|
---|
1121 | }
|
---|
1122 |
|
---|
1123 | private enum GroundType
|
---|
1124 | {
|
---|
1125 | Grass("Grass", 0),
|
---|
1126 | Dirt("Dirt", 1),
|
---|
1127 | Stone("Stone", 2);
|
---|
1128 |
|
---|
1129 | private GroundType(final String s, final int n) {
|
---|
1130 | }
|
---|
1131 | }
|
---|
1132 |
|
---|
1133 | public enum State
|
---|
1134 | {
|
---|
1135 | Main("Main", 0),
|
---|
1136 | Edit("Edit", 1);
|
---|
1137 |
|
---|
1138 | private State(final String s, final int n) {
|
---|
1139 | }
|
---|
1140 | }
|
---|
1141 | }
|
---|