Keine Beschreibung

map.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. Metatile* getMetatile(int);
  102. QImage getMetatileImage(int);
  103. QImage getMetatileTile(int);
  104. QPixmap render();
  105. QPixmap renderMetatiles();
  106. QPixmap renderCollision();
  107. QImage collision_image;
  108. QPixmap collision_pixmap;
  109. QImage getCollisionMetatileImage(Block);
  110. QImage getElevationMetatileImage(Block);
  111. QImage getCollisionMetatileImage(int);
  112. QImage getElevationMetatileImage(int);
  113. QPixmap renderCollisionMetatiles();
  114. QPixmap renderElevationMetatiles();
  115. void drawSelection(int i, int w, QPainter *painter);
  116. bool blockChanged(int, Blockdata*);
  117. Blockdata* cached_blockdata = NULL;
  118. void cacheBlockdata();
  119. Blockdata* cached_collision = NULL;
  120. void cacheCollision();
  121. QImage image;
  122. QPixmap pixmap;
  123. QList<QImage> metatile_images;
  124. bool smart_paths_enabled = false;
  125. int paint_metatile_initial_x;
  126. int paint_metatile_initial_y;
  127. int paint_tile;
  128. int paint_tile_width = 1;
  129. int paint_tile_height = 1;
  130. int paint_tile_initial_x;
  131. int paint_tile_initial_y;
  132. int paint_collision;
  133. int paint_elevation;
  134. Block *getBlock(int x, int y);
  135. void setBlock(int x, int y, Block block);
  136. void _setBlock(int x, int y, Block block);
  137. void floodFill(int x, int y, uint tile);
  138. void _floodFill(int x, int y, uint tile);
  139. void floodFillCollision(int x, int y, uint collision);
  140. void _floodFillCollision(int x, int y, uint collision);
  141. void floodFillElevation(int x, int y, uint elevation);
  142. void _floodFillElevation(int x, int y, uint elevation);
  143. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  144. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  145. History<Blockdata*> history;
  146. void undo();
  147. void redo();
  148. void commit();
  149. QString object_events_label;
  150. QString warps_label;
  151. QString coord_events_label;
  152. QString bg_events_label;
  153. QList<Event*> getAllEvents();
  154. QList<Event*> getEventsByType(QString type);
  155. void removeEvent(Event *event);
  156. void addEvent(Event *event);
  157. QMap<QString, QList<Event*>> events;
  158. QList<Connection*> connections;
  159. QPixmap renderConnection(Connection);
  160. QImage border_image;
  161. QPixmap border_pixmap;
  162. Blockdata *border = NULL;
  163. Blockdata *cached_border = NULL;
  164. QPixmap renderBorder();
  165. void cacheBorder();
  166. bool hasUnsavedChanges();
  167. void hoveredTileChanged(int x, int y, int block);
  168. void clearHoveredTile();
  169. void hoveredMetatileChanged(int block);
  170. void clearHoveredMetatile();
  171. void hoveredCollisionTileChanged(int collision);
  172. void clearHoveredCollisionTile();
  173. void hoveredElevationTileChanged(int elevation);
  174. void clearHoveredElevationTile();
  175. QList<QList<QRgb> > getBlockPalettes(int metatile_index);
  176. signals:
  177. void paintTileChanged(Map *map);
  178. void paintCollisionChanged(Map *map);
  179. void mapChanged(Map *map);
  180. void statusBarMessage(QString);
  181. public slots:
  182. };
  183. #endif // MAP_H