説明なし

map.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. int getWidth();
  121. int getHeight();
  122. Tileset* getBlockTileset(int);
  123. int getBlockIndex(int layout_id);
  124. int getSelectedBlockIndex(int layout_id);
  125. int getDisplayedBlockIndex(int layout_id);
  126. Metatile* getMetatile(int);
  127. QImage getMetatileImage(int);
  128. QImage getMetatileTile(int);
  129. QPixmap render(bool ignoreCache);
  130. QPixmap renderMetatiles();
  131. QPixmap renderCollision(bool ignoreCache);
  132. QImage collision_image;
  133. QPixmap collision_pixmap;
  134. QImage getCollisionMetatileImage(Block);
  135. QImage getElevationMetatileImage(Block);
  136. QImage getCollisionMetatileImage(int);
  137. QImage getElevationMetatileImage(int);
  138. QPixmap renderCollisionMetatiles();
  139. QPixmap renderElevationMetatiles();
  140. void drawSelection(int i, int w, int selectionWidth, int selectionHeight, QPainter *painter);
  141. bool blockChanged(int, Blockdata*);
  142. void cacheBlockdata();
  143. void cacheCollision();
  144. QImage image;
  145. QPixmap pixmap;
  146. QList<QImage> metatile_images;
  147. bool smart_paths_enabled = false;
  148. int paint_metatile_initial_x;
  149. int paint_metatile_initial_y;
  150. int paint_tile_index;
  151. int paint_tile_width = 1;
  152. int paint_tile_height = 1;
  153. int paint_tile_initial_x;
  154. int paint_tile_initial_y;
  155. int paint_collision;
  156. int paint_elevation;
  157. Block *getBlock(int x, int y);
  158. void setBlock(int x, int y, Block block);
  159. void _setBlock(int x, int y, Block block);
  160. void floodFill(int x, int y, uint tile);
  161. void _floodFill(int x, int y, uint tile);
  162. void floodFillCollision(int x, int y, uint collision);
  163. void _floodFillCollision(int x, int y, uint collision);
  164. void floodFillElevation(int x, int y, uint elevation);
  165. void _floodFillElevation(int x, int y, uint elevation);
  166. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  167. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  168. History<Blockdata*> history;
  169. void undo();
  170. void redo();
  171. void commit();
  172. QString object_events_label;
  173. QString warps_label;
  174. QString coord_events_label;
  175. QString bg_events_label;
  176. QList<Event*> getAllEvents();
  177. void removeEvent(Event *event);
  178. void addEvent(Event *event);
  179. QMap<QString, QList<Event*>> events;
  180. QList<Connection*> connections;
  181. QList<QGraphicsPixmapItem*> connection_items;
  182. QPixmap renderConnection(Connection);
  183. QPixmap renderBorder();
  184. void cacheBorder();
  185. bool hasUnsavedChanges();
  186. void hoveredTileChanged(int x, int y, int block);
  187. void clearHoveredTile();
  188. void hoveredMetatileChanged(int block);
  189. void clearHoveredMetatile();
  190. void hoveredCollisionTileChanged(int collision);
  191. void clearHoveredCollisionTile();
  192. void hoveredElevationTileChanged(int elevation);
  193. void clearHoveredElevationTile();
  194. QList<QList<QRgb> > getBlockPalettes(int metatile_index);
  195. signals:
  196. void paintTileChanged(Map *map);
  197. void paintCollisionChanged(Map *map);
  198. void mapChanged(Map *map);
  199. void statusBarMessage(QString);
  200. public slots:
  201. };
  202. #endif // MAP_H