-
Notifications
You must be signed in to change notification settings - Fork 7
/
map.h
executable file
·231 lines (206 loc) · 6.15 KB
/
map.h
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
#ifndef MAP_H
#define MAP_H
#include "tileset.h"
#include "blockdata.h"
#include "event.h"
#include <QPixmap>
#include <QObject>
#include <QDebug>
#include <QGraphicsPixmapItem>
class HistoryItem {
public:
Blockdata *metatiles;
short layoutWidth;
short layoutHeight;
HistoryItem(Blockdata *metatiles_, short layoutWidth_, short layoutHeight_) {
this->metatiles = metatiles_;
this->layoutWidth = layoutWidth_;
this->layoutHeight = layoutHeight_;
}
};
template <typename T>
class History {
public:
History() {
}
T back() {
if (head > 0) {
return history.at(--head);
}
return NULL;
}
T next() {
if (head + 1 < history.length()) {
return history.at(++head);
}
return NULL;
}
void push(T commit) {
while (head + 1 < history.length()) {
history.removeLast();
}
if (saved > head) {
saved = -1;
}
history.append(commit);
head++;
}
T current() {
if (head < 0 || history.length() == 0) {
return NULL;
}
return history.at(head);
}
void save() {
saved = head;
}
bool isSaved() {
return saved == head;
}
private:
QList<T> history;
int head = -1;
int saved = -1;
};
class Connection {
public:
Connection() {
}
public:
QString direction;
QString offset;
QString map_name;
};
class MapLayout {
public:
MapLayout() {}
int index;
QString name;
QString label;
QString width;
QString height;
QString border_label;
QString border_path;
QString blockdata_label;
QString blockdata_path;
QString tileset_primary_label;
QString tileset_secondary_label;
Tileset *tileset_primary = NULL;
Tileset *tileset_secondary = NULL;
Blockdata* blockdata = NULL;
QImage border_image;
QPixmap border_pixmap;
Blockdata *border = NULL;
Blockdata *cached_blockdata = NULL;
Blockdata *cached_collision = NULL;
Blockdata *cached_border = NULL;
bool has_unsaved_changes = false;
public:
static QString getNameFromLabel(QString label) {
// ASSUMPTION: strip off "_Layout" from layout label. Directories in 'data/layouts/' must be well-formed.
return label.replace(label.lastIndexOf("_Layout"), label.length(), "");
}
};
class Map : public QObject
{
Q_OBJECT
public:
explicit Map(QObject *parent = 0);
public:
QString name;
QString constantName;
QString group_num;
QString layout_label;
QString events_label;
QString scripts_label;
QString connections_label;
QString song;
QString layout_id;
QString location;
QString requiresFlash;
QString weather;
QString type;
QString unknown;
QString show_location;
QString battle_scene;
MapLayout *layout;
bool isPersistedToFile = true;
public:
void setName(QString mapName);
static QString mapConstantFromName(QString mapName);
static QString objectEventsLabelFromName(QString mapName);
static QString warpEventsLabelFromName(QString mapName);
static QString coordEventsLabelFromName(QString mapName);
static QString bgEventsLabelFromName(QString mapName);
int getWidth();
int getHeight();
int getSelectedBlockIndex(int);
int getDisplayedBlockIndex(int);
QPixmap render(bool ignoreCache);
QPixmap renderMetatiles();
QPixmap renderCollision(bool ignoreCache);
QImage collision_image;
QPixmap collision_pixmap;
QImage getCollisionMetatileImage(Block);
QImage getCollisionMetatileImage(int, int);
QPixmap renderCollisionMetatiles();
void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter, int gridWidth);
bool blockChanged(int, Blockdata*);
void cacheBlockdata();
void cacheCollision();
QImage image;
QPixmap pixmap;
QList<QImage> metatile_images;
bool smart_paths_enabled = false;
int paint_metatile_initial_x;
int paint_metatile_initial_y;
int paint_tile_index;
int paint_tile_width = 1;
int paint_tile_height = 1;
int paint_tile_initial_x;
int paint_tile_initial_y;
int selected_metatiles_width;
int selected_metatiles_height;
QList<int> *selected_metatiles = NULL;
int paint_collision;
int paint_elevation;
Block *getBlock(int x, int y);
void setBlock(int x, int y, Block block);
void _setBlock(int x, int y, Block block);
void floodFillCollision(int x, int y, uint collision);
void _floodFillCollision(int x, int y, uint collision);
void floodFillElevation(int x, int y, uint elevation);
void _floodFillElevation(int x, int y, uint elevation);
void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
History<HistoryItem*> history;
void undo();
void redo();
void commit();
QList<Event*> getAllEvents();
void removeEvent(Event *event);
void addEvent(Event *event);
QMap<QString, QList<Event*>> events;
QList<Connection*> connections;
QPixmap renderConnection(Connection);
void setNewDimensionsBlockdata(int newWidth, int newHeight);
void setDimensions(int newWidth, int newHeight, bool setNewBlockData = true);
QPixmap renderBorder();
void cacheBorder();
bool hasUnsavedChanges();
void hoveredTileChanged(int x, int y, int block);
void clearHoveredTile();
void hoveredMetatileChanged(int block);
void clearHoveredMetatile();
void hoveredMovementPermissionTileChanged(int collision, int elevation);
void clearHoveredMovementPermissionTile();
void setSelectedMetatilesFromTilePicker();
signals:
void paintTileChanged(Map *map);
void paintCollisionChanged(Map *map);
void mapChanged(Map *map);
void mapNeedsRedrawing(Map *map);
void statusBarMessage(QString);
public slots:
};
#endif // MAP_H