暫無描述

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