-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorMap.java
More file actions
209 lines (182 loc) · 7.23 KB
/
EditorMap.java
File metadata and controls
209 lines (182 loc) · 7.23 KB
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
import com.sun.istack.internal.Nullable;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.Random;
public class EditorMap extends MapBase {
private int click = 0;
private Point firstClick, secondClick;
private JTextArea editorAnzeige;
private boolean toIgnore;
private Color color;
private int strokeSize = 10;
private boolean showMapBorder = true;
public EditorMap(GamePanel gp, int pMapSizeX, int pMapSizeY, TileSet pTileSet) {
super(gp, pTileSet, null, null);
setMapSizeX(pMapSizeX);
setMapSizeY(pMapSizeY);
editorAnzeige = new JTextArea("EditorAnzeige");
toIgnore = false;
Random r = new Random();
color = new Color(r.nextFloat(), r.nextFloat(), r.nextFloat());
}
public void createEditorMap(@Nullable Integer iD) {
createBaseMap();
if (iD == null) {
iD = 22;
}
int i = 2;
for (int zeile = 0; zeile < mapTiles.length; zeile++) {
for (int spalte = 0; spalte < mapTiles[zeile].length; spalte++) {
mapTiles[zeile][spalte] = tileSet.tileSet[iD].clone();
mapTiles[zeile][spalte].setID(iD);
mapTiles[zeile][spalte].setOpaque(false);
i++;
}
}
if (showMapBorder) {
setMapBorder(5);
}
}
public void createBlankMap() {
createBaseMap();
int i = 2;
mapTiles = new Tile[mapSizeX][mapSizeY];
for (int zeile = 0; zeile < mapTiles.length; zeile++) {
for (int spalte = 0; spalte < mapTiles[zeile].length; spalte++) {
mapTiles[zeile][spalte] = tileSet.tileSet[6].clone();
mapTiles[zeile][spalte].setID(6);
mapTiles[zeile][spalte].setOpaque(false);
i++;
}
}
if (showMapBorder) {
setMapBorder(5);
}
}
public void setMapBorder(int stroke) {
//Oben:
for (int i = 1; i < mapSizeX; i++) {
mapTiles[i][0].setBorderInsets(new Insets(stroke, 0, 0, 0));
}
//Unten:
for (int i = 1; i < mapSizeX; i++) {
mapTiles[i][mapSizeY - 1].setBorderInsets(new Insets(0, 0, stroke, 0));
// mapTiles[i][mapSizeY - 1].setDownBorder(true);
}
//Links:
for (int i = 1; i < mapSizeY; i++) {
mapTiles[0][i].setBorderInsets(new Insets(0, stroke, 0, 0));
// mapTiles[0][i].setLeftBorder(true);
}
//Rechts:
for (int i = 1; i < mapSizeY; i++) {
mapTiles[mapSizeX - 1][i].setBorderInsets(new Insets(0, 0, 0, stroke));
// mapTiles[mapSizeX - 1][i].setRightBorder(true);
}
mapTiles[0][0].setBorderInsets(new Insets(stroke, stroke, 0, 0));
mapTiles[mapSizeX - 1][0].setBorderInsets(new Insets(stroke, 0, 0, stroke));
mapTiles[0][mapSizeY - 1].setBorderInsets(new Insets(0, stroke, stroke, 0));
mapTiles[mapSizeX - 1][mapSizeY - 1].setBorderInsets(new Insets(0, 0, stroke, stroke));
}
@Override
public void renderMap(Graphics2D g2d) {
g2d.setColor(color);
g2d.setStroke(new BasicStroke(strokeSize));
for (int zeile = 0; zeile < mapSizeY; zeile++) {
for (int spalte = 0; spalte < mapSizeX; spalte++) {
mapTiles[zeile][spalte].renderTile(g2d, chapterXOffset + zeile * Tile.TILEWIDTH - gamePanel.getCamera().getClickXOffset(), chapterYOffset + spalte * Tile.TILEHEIGHT - gamePanel.getCamera().getClickYOffset());
}
}
}
private void setMapTile(int xIndex, int yIndex, TileSet ts) {
if (!toIgnore) {
if (graphicID != 9999 /*Ausnahme*/ && !tileSet.getTileSetImagePath().equals(ts.getTileSetImagePath())) {
Meldungen meld = new Meldungen(null, true, "null");
meld.unSimilarTS(this, ts);
tileSet = meld.selectedTS;
reloadMap(tileSet);
}
} else {
tileSet = ts;
}
if (xIndex <= mapSizeX && yIndex <= mapSizeY) {
Insets tempInsets = null;
tempInsets = mapTiles[xIndex][yIndex].getBorderInsets();
if (graphicID == 9999) {
mapTiles[xIndex][yIndex] = new Tile(new BufferedImage(Tile.TILEWIDTH, Tile.TILEHEIGHT, BufferedImage.TYPE_4BYTE_ABGR)).clone();
} else {
mapTiles[xIndex][yIndex] = tileSet.tileSet[graphicID].clone();
}
mapTiles[xIndex][yIndex].setBorderInsets(tempInsets);
mapTiles[xIndex][yIndex].setID(graphicID);
} else {
new JOptionPane("Klick ist außerhalb der Map: " + xIndex + " || " + yIndex);
}
mapTiles[xIndex][yIndex].revalidate();
}
public Point getTileID(MouseEvent e) {
int x = Math.round(e.getX() + gamePanel.getCamera().getClickXOffset() - chapterXOffset) / Tile.TILEWIDTH;
int y = Math.round(e.getY() + gamePanel.getCamera().getClickYOffset() - chapterYOffset) / Tile.TILEHEIGHT;
return new Point(x, y);
}
public void setTile(MouseEvent e, TileSet ts) {
Point click = getTileID(e);
setMapTile(click.x, click.y, ts);
}
public void setTileRect(MouseEvent e, TileSet ts) {
click++;
if (click == 1) {
firstClick = getTileID(e);
editorAnzeige.setText("Fläche zeichnen :" + "\n" + " erster Klick");
}
if (click == 2) {
secondClick = getTileID(e);
editorAnzeige.setText("");
if (firstClick.getX() > secondClick.getX()) {
int swap;
swap = (int) firstClick.getX();
firstClick.x = (int) secondClick.getX();
secondClick.x = swap;
}
if (firstClick.getY() > secondClick.getY()) {
int swap = (int) firstClick.getY();
firstClick.y = (int) secondClick.getY();
secondClick.y = swap;
}
for (int x = (int) firstClick.getX(); x < secondClick.getX() + 1; x++) {
for (int y = (int) firstClick.getY(); y < secondClick.getY() + 1; y++) {
setMapTile(x, y, ts);
}
}
click = 0;
}
}
public void reloadMap(TileSet set) {
for (int zeile = 0; zeile < mapTiles.length; zeile++) {
for (int spalte = 0; spalte < mapTiles[zeile].length; spalte++) {
if (mapTiles[zeile][spalte].id == 9999) {
mapTiles[zeile][spalte] = new Tile(new BufferedImage(Tile.TILEWIDTH, Tile.TILEHEIGHT, BufferedImage.TYPE_4BYTE_ABGR));
} else {
mapTiles[zeile][spalte] = set.tileSet[mapTiles[zeile][spalte].id].clone();
}
}
}
}
public void setTileSet(TileSet tileSet) {
this.tileSet = tileSet;
}
public boolean isToIgnore() {
return toIgnore;
}
public void setToIgnore(boolean toIgnore) {
this.toIgnore = toIgnore;
}
public void setGraphicID(int graphicID) {
this.graphicID = graphicID;
}
public void setClick(int click) {
this.click = click;
}
}