説明なし

map.h 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 MapLayout {
  64. public:
  65. MapLayout() {}
  66. int index;
  67. QString name;
  68. QString label;
  69. QString width;
  70. QString height;
  71. QString border_label;
  72. QString border_path;
  73. QString blockdata_label;
  74. QString blockdata_path;
  75. QString tileset_primary_label;
  76. QString tileset_secondary_label;
  77. Tileset *tileset_primary = NULL;
  78. Tileset *tileset_secondary = NULL;
  79. Blockdata* blockdata = NULL;
  80. QImage border_image;
  81. QPixmap border_pixmap;
  82. Blockdata *border = NULL;
  83. Blockdata *cached_blockdata = NULL;
  84. Blockdata *cached_collision = NULL;
  85. Blockdata *cached_border = NULL;
  86. bool has_unsaved_changes = false;
  87. public:
  88. static QString getNameFromLabel(QString label) {
  89. // ASSUMPTION: strip off "_Layout" from layout label. Directories in 'data/layouts/' must be well-formed.
  90. return label.replace(label.lastIndexOf("_Layout"), label.length(), "");
  91. }
  92. };
  93. class Map : public QObject
  94. {
  95. Q_OBJECT
  96. public:
  97. explicit Map(QObject *parent = 0);
  98. public:
  99. QString name;
  100. QString constantName;
  101. QString group_num;
  102. QString layout_label;
  103. QString events_label;
  104. QString scripts_label;
  105. QString connections_label;
  106. QString song;
  107. QString layout_id;
  108. QString location;
  109. QString visibility;
  110. QString weather;
  111. QString type;
  112. QString unknown;
  113. QString show_location;
  114. QString battle_scene;
  115. MapLayout *layout;
  116. bool isPersistedToFile = true;
  117. public:
  118. void setName(QString mapName);
  119. static QString mapConstantFromName(QString mapName);
  120. static QString objectEventsLabelFromName(QString mapName);
  121. static QString warpEventsLabelFromName(QString mapName);
  122. static QString coordEventsLabelFromName(QString mapName);
  123. static QString bgEventsLabelFromName(QString mapName);
  124. int getWidth();
  125. int getHeight();
  126. int getSelectedBlockIndex(int);
  127. int getDisplayedBlockIndex(int);
  128. QPixmap render(bool ignoreCache);
  129. QPixmap renderMetatiles();
  130. QPixmap renderCollision(bool ignoreCache);
  131. QImage collision_image;
  132. QPixmap collision_pixmap;
  133. QImage getCollisionMetatileImage(Block);
  134. QImage getElevationMetatileImage(Block);
  135. QImage getCollisionMetatileImage(int);
  136. QImage getElevationMetatileImage(int);
  137. QPixmap renderCollisionMetatiles();
  138. QPixmap renderElevationMetatiles();
  139. void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter);
  140. bool blockChanged(int, Blockdata*);
  141. void cacheBlockdata();
  142. void cacheCollision();
  143. QImage image;
  144. QPixmap pixmap;
  145. QList<QImage> metatile_images;
  146. bool smart_paths_enabled = false;
  147. int paint_metatile_initial_x;
  148. int paint_metatile_initial_y;
  149. int paint_tile_index;
  150. int paint_tile_width = 1;
  151. int paint_tile_height = 1;
  152. int paint_tile_initial_x;
  153. int paint_tile_initial_y;
  154. int paint_collision;
  155. int paint_elevation;
  156. Block *getBlock(int x, int y);
  157. void setBlock(int x, int y, Block block);
  158. void _setBlock(int x, int y, Block block);
  159. void floodFill(int x, int y, uint tile);
  160. void _floodFill(int x, int y, uint tile);
  161. void floodFillCollision(int x, int y, uint collision);
  162. void _floodFillCollision(int x, int y, uint collision);
  163. void floodFillElevation(int x, int y, uint elevation);
  164. void _floodFillElevation(int x, int y, uint elevation);
  165. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  166. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  167. History<Blockdata*> history;
  168. void undo();
  169. void redo();
  170. void commit();
  171. QList<Event*> getAllEvents();
  172. void removeEvent(Event *event);
  173. void addEvent(Event *event);
  174. QMap<QString, QList<Event*>> events;
  175. QList<Connection*> connections;
  176. QPixmap renderConnection(Connection);
  177. QPixmap renderBorder();
  178. void cacheBorder();
  179. bool hasUnsavedChanges();
  180. void hoveredTileChanged(int x, int y, int block);
  181. void clearHoveredTile();
  182. void hoveredMetatileChanged(int block);
  183. void clearHoveredMetatile();
  184. void hoveredCollisionTileChanged(int collision);
  185. void clearHoveredCollisionTile();
  186. void hoveredElevationTileChanged(int elevation);
  187. void clearHoveredElevationTile();
  188. signals:
  189. void paintTileChanged(Map *map);
  190. void paintCollisionChanged(Map *map);
  191. void mapChanged(Map *map);
  192. void statusBarMessage(QString);
  193. public slots:
  194. };
  195. #endif // MAP_H