No Description

map.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #ifndef MAP_H
  2. #define MAP_H
  3. #include "tileset.h"
  4. #include "blockdata.h"
  5. #include "event.h"
  6. #include <QPixmap>
  7. #include <QObject>
  8. #include <QDebug>
  9. #include <QGraphicsPixmapItem>
  10. class HistoryItem {
  11. public:
  12. Blockdata *metatiles;
  13. short layoutWidth;
  14. short layoutHeight;
  15. HistoryItem(Blockdata *metatiles_, short layoutWidth_, short layoutHeight_) {
  16. this->metatiles = metatiles_;
  17. this->layoutWidth = layoutWidth_;
  18. this->layoutHeight = layoutHeight_;
  19. }
  20. };
  21. template <typename T>
  22. class History {
  23. public:
  24. History() {
  25. }
  26. T back() {
  27. if (head > 0) {
  28. return history.at(--head);
  29. }
  30. return NULL;
  31. }
  32. T next() {
  33. if (head + 1 < history.length()) {
  34. return history.at(++head);
  35. }
  36. return NULL;
  37. }
  38. void push(T commit) {
  39. while (head + 1 < history.length()) {
  40. history.removeLast();
  41. }
  42. if (saved > head) {
  43. saved = -1;
  44. }
  45. history.append(commit);
  46. head++;
  47. }
  48. T current() {
  49. if (head < 0 || history.length() == 0) {
  50. return NULL;
  51. }
  52. return history.at(head);
  53. }
  54. void save() {
  55. saved = head;
  56. }
  57. bool isSaved() {
  58. return saved == head;
  59. }
  60. private:
  61. QList<T> history;
  62. int head = -1;
  63. int saved = -1;
  64. };
  65. class Connection {
  66. public:
  67. Connection() {
  68. }
  69. public:
  70. QString direction;
  71. QString offset;
  72. QString map_name;
  73. };
  74. class MapLayout {
  75. public:
  76. MapLayout() {}
  77. int index;
  78. QString name;
  79. QString label;
  80. QString width;
  81. QString height;
  82. QString border_label;
  83. QString border_path;
  84. QString blockdata_label;
  85. QString blockdata_path;
  86. QString tileset_primary_label;
  87. QString tileset_secondary_label;
  88. Tileset *tileset_primary = NULL;
  89. Tileset *tileset_secondary = NULL;
  90. Blockdata* blockdata = NULL;
  91. QImage border_image;
  92. QPixmap border_pixmap;
  93. Blockdata *border = NULL;
  94. Blockdata *cached_blockdata = NULL;
  95. Blockdata *cached_collision = NULL;
  96. Blockdata *cached_border = NULL;
  97. bool has_unsaved_changes = false;
  98. public:
  99. static QString getNameFromLabel(QString label) {
  100. // ASSUMPTION: strip off "_Layout" from layout label. Directories in 'data/layouts/' must be well-formed.
  101. return label.replace(label.lastIndexOf("_Layout"), label.length(), "");
  102. }
  103. };
  104. class Map : public QObject
  105. {
  106. Q_OBJECT
  107. public:
  108. explicit Map(QObject *parent = 0);
  109. public:
  110. QString name;
  111. QString constantName;
  112. QString group_num;
  113. QString layout_label;
  114. QString events_label;
  115. QString scripts_label;
  116. QString connections_label;
  117. QString song;
  118. QString layout_id;
  119. QString location;
  120. QString visibility;
  121. QString weather;
  122. QString type;
  123. QString unknown;
  124. QString show_location;
  125. QString battle_scene;
  126. MapLayout *layout;
  127. bool isPersistedToFile = true;
  128. public:
  129. void setName(QString mapName);
  130. static QString mapConstantFromName(QString mapName);
  131. static QString objectEventsLabelFromName(QString mapName);
  132. static QString warpEventsLabelFromName(QString mapName);
  133. static QString coordEventsLabelFromName(QString mapName);
  134. static QString bgEventsLabelFromName(QString mapName);
  135. int getWidth();
  136. int getHeight();
  137. int getSelectedBlockIndex(int);
  138. int getDisplayedBlockIndex(int);
  139. QPixmap render(bool ignoreCache);
  140. QPixmap renderMetatiles();
  141. QPixmap renderCollision(bool ignoreCache);
  142. QImage collision_image;
  143. QPixmap collision_pixmap;
  144. QImage getCollisionMetatileImage(Block);
  145. QImage getElevationMetatileImage(Block);
  146. QImage getCollisionMetatileImage(int);
  147. QImage getElevationMetatileImage(int);
  148. QPixmap renderCollisionMetatiles();
  149. QPixmap renderElevationMetatiles();
  150. void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter);
  151. bool blockChanged(int, Blockdata*);
  152. void cacheBlockdata();
  153. void cacheCollision();
  154. QImage image;
  155. QPixmap pixmap;
  156. QList<QImage> metatile_images;
  157. bool smart_paths_enabled = false;
  158. int paint_metatile_initial_x;
  159. int paint_metatile_initial_y;
  160. int paint_tile_index;
  161. int paint_tile_width = 1;
  162. int paint_tile_height = 1;
  163. int paint_tile_initial_x;
  164. int paint_tile_initial_y;
  165. int paint_collision;
  166. int paint_elevation;
  167. Block *getBlock(int x, int y);
  168. void setBlock(int x, int y, Block block);
  169. void _setBlock(int x, int y, Block block);
  170. void floodFillCollision(int x, int y, uint collision);
  171. void _floodFillCollision(int x, int y, uint collision);
  172. void floodFillElevation(int x, int y, uint elevation);
  173. void _floodFillElevation(int x, int y, uint elevation);
  174. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  175. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  176. History<HistoryItem*> history;
  177. void undo();
  178. void redo();
  179. void commit();
  180. QList<Event*> getAllEvents();
  181. void removeEvent(Event *event);
  182. void addEvent(Event *event);
  183. QMap<QString, QList<Event*>> events;
  184. QList<Connection*> connections;
  185. QPixmap renderConnection(Connection);
  186. void setNewDimensionsBlockdata(int newWidth, int newHeight);
  187. void setDimensions(int newWidth, int newHeight, bool setNewBlockData = true);
  188. QPixmap renderBorder();
  189. void cacheBorder();
  190. bool hasUnsavedChanges();
  191. void hoveredTileChanged(int x, int y, int block);
  192. void clearHoveredTile();
  193. void hoveredMetatileChanged(int block);
  194. void clearHoveredMetatile();
  195. void hoveredCollisionTileChanged(int collision);
  196. void clearHoveredCollisionTile();
  197. void hoveredElevationTileChanged(int elevation);
  198. void clearHoveredElevationTile();
  199. signals:
  200. void paintTileChanged(Map *map);
  201. void paintCollisionChanged(Map *map);
  202. void mapChanged(Map *map);
  203. void mapNeedsRedrawing(Map *map);
  204. void statusBarMessage(QString);
  205. public slots:
  206. };
  207. #endif // MAP_H