No Description

map.h 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. template <typename T>
  11. class History {
  12. public:
  13. History() {
  14. }
  15. T back() {
  16. if (head > 0) {
  17. return history.at(--head);
  18. }
  19. return NULL;
  20. }
  21. T next() {
  22. if (head + 1 < history.length()) {
  23. return history.at(++head);
  24. }
  25. return NULL;
  26. }
  27. void push(T commit) {
  28. while (head + 1 < history.length()) {
  29. history.removeLast();
  30. }
  31. if (saved > head) {
  32. saved = -1;
  33. }
  34. history.append(commit);
  35. head++;
  36. }
  37. T current() {
  38. if (head < 0 || history.length() == 0) {
  39. return NULL;
  40. }
  41. return history.at(head);
  42. }
  43. void save() {
  44. saved = head;
  45. }
  46. bool isSaved() {
  47. return saved == head;
  48. }
  49. private:
  50. QList<T> history;
  51. int head = -1;
  52. int saved = -1;
  53. };
  54. class Connection {
  55. public:
  56. Connection() {
  57. }
  58. public:
  59. QString direction;
  60. QString offset;
  61. QString map_name;
  62. };
  63. class Map : public QObject
  64. {
  65. Q_OBJECT
  66. public:
  67. explicit Map(QObject *parent = 0);
  68. public:
  69. QString name;
  70. QString constantName;
  71. QString group_num;
  72. QString attributes_label;
  73. QString events_label;
  74. QString scripts_label;
  75. QString connections_label;
  76. QString song;
  77. QString index;
  78. QString location;
  79. QString visibility;
  80. QString weather;
  81. QString type;
  82. QString unknown;
  83. QString show_location;
  84. QString battle_scene;
  85. QString width;
  86. QString height;
  87. QString border_label;
  88. QString blockdata_label;
  89. QString tileset_primary_label;
  90. QString tileset_secondary_label;
  91. Tileset *tileset_primary = NULL;
  92. Tileset *tileset_secondary = NULL;
  93. Blockdata* blockdata = NULL;
  94. bool isPersistedToFile = true;
  95. public:
  96. void setName(QString mapName);
  97. static QString mapConstantFromName(QString mapName);
  98. int getWidth();
  99. int getHeight();
  100. Tileset* getBlockTileset(int);
  101. int getBlockIndex(int index);
  102. Metatile* getMetatile(int);
  103. QImage getMetatileImage(int);
  104. QImage getMetatileTile(int);
  105. QPixmap render();
  106. QPixmap renderMetatiles();
  107. QPixmap renderCollision();
  108. QImage collision_image;
  109. QPixmap collision_pixmap;
  110. QImage getCollisionMetatileImage(Block);
  111. QImage getElevationMetatileImage(Block);
  112. QImage getCollisionMetatileImage(int);
  113. QImage getElevationMetatileImage(int);
  114. QPixmap renderCollisionMetatiles();
  115. QPixmap renderElevationMetatiles();
  116. void drawSelection(int i, int w, QPainter *painter);
  117. bool blockChanged(int, Blockdata*);
  118. Blockdata* cached_blockdata = NULL;
  119. void cacheBlockdata();
  120. Blockdata* cached_collision = NULL;
  121. void cacheCollision();
  122. QImage image;
  123. QPixmap pixmap;
  124. QList<QImage> metatile_images;
  125. bool smart_paths_enabled = false;
  126. int paint_metatile_initial_x;
  127. int paint_metatile_initial_y;
  128. int paint_tile;
  129. int paint_tile_width = 1;
  130. int paint_tile_height = 1;
  131. int paint_tile_initial_x;
  132. int paint_tile_initial_y;
  133. int paint_collision;
  134. int paint_elevation;
  135. Block *getBlock(int x, int y);
  136. void setBlock(int x, int y, Block block);
  137. void _setBlock(int x, int y, Block block);
  138. void floodFill(int x, int y, uint tile);
  139. void _floodFill(int x, int y, uint tile);
  140. void floodFillCollision(int x, int y, uint collision);
  141. void _floodFillCollision(int x, int y, uint collision);
  142. void floodFillElevation(int x, int y, uint elevation);
  143. void _floodFillElevation(int x, int y, uint elevation);
  144. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  145. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  146. History<Blockdata*> history;
  147. void undo();
  148. void redo();
  149. void commit();
  150. QString object_events_label;
  151. QString warps_label;
  152. QString coord_events_label;
  153. QString bg_events_label;
  154. QList<Event*> getAllEvents();
  155. QList<Event*> getEventsByType(QString type);
  156. void removeEvent(Event *event);
  157. void addEvent(Event *event);
  158. QMap<QString, QList<Event*>> events;
  159. QList<Connection*> connections;
  160. QMap<QString, QGraphicsPixmapItem*> connection_items;
  161. QPixmap renderConnection(Connection);
  162. QImage border_image;
  163. QPixmap border_pixmap;
  164. Blockdata *border = NULL;
  165. Blockdata *cached_border = NULL;
  166. QPixmap renderBorder();
  167. void cacheBorder();
  168. bool hasUnsavedChanges();
  169. void hoveredTileChanged(int x, int y, int block);
  170. void clearHoveredTile();
  171. void hoveredMetatileChanged(int block);
  172. void clearHoveredMetatile();
  173. void hoveredCollisionTileChanged(int collision);
  174. void clearHoveredCollisionTile();
  175. void hoveredElevationTileChanged(int elevation);
  176. void clearHoveredElevationTile();
  177. QList<QList<QRgb> > getBlockPalettes(int metatile_index);
  178. signals:
  179. void paintTileChanged(Map *map);
  180. void paintCollisionChanged(Map *map);
  181. void mapChanged(Map *map);
  182. void statusBarMessage(QString);
  183. public slots:
  184. };
  185. #endif // MAP_H