Ingen beskrivning

map.h 5.4KB

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