Brak opisu

map.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. public:
  94. void setName(QString mapName);
  95. static QString mapConstantFromName(QString mapName);
  96. int getWidth();
  97. int getHeight();
  98. Tileset* getBlockTileset(int);
  99. int getBlockIndex(int index);
  100. Metatile* getMetatile(int);
  101. QImage getMetatileImage(int);
  102. QImage getMetatileTile(int);
  103. QPixmap render();
  104. QPixmap renderMetatiles();
  105. QPixmap renderCollision();
  106. QImage collision_image;
  107. QPixmap collision_pixmap;
  108. QImage getCollisionMetatileImage(Block);
  109. QImage getElevationMetatileImage(Block);
  110. QImage getCollisionMetatileImage(int);
  111. QImage getElevationMetatileImage(int);
  112. QPixmap renderCollisionMetatiles();
  113. QPixmap renderElevationMetatiles();
  114. void drawSelection(int i, int w, QPainter *painter);
  115. bool blockChanged(int, Blockdata*);
  116. Blockdata* cached_blockdata = NULL;
  117. void cacheBlockdata();
  118. Blockdata* cached_collision = NULL;
  119. void cacheCollision();
  120. QImage image;
  121. QPixmap pixmap;
  122. QList<QImage> metatile_images;
  123. int paint_tile;
  124. int paint_collision;
  125. int paint_elevation;
  126. Block *getBlock(int x, int y);
  127. void setBlock(int x, int y, Block block);
  128. void _setBlock(int x, int y, Block block);
  129. void floodFill(int x, int y, uint tile);
  130. void _floodFill(int x, int y, uint tile);
  131. void floodFillCollision(int x, int y, uint collision);
  132. void _floodFillCollision(int x, int y, uint collision);
  133. void floodFillElevation(int x, int y, uint elevation);
  134. void _floodFillElevation(int x, int y, uint elevation);
  135. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  136. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  137. History<Blockdata*> history;
  138. void undo();
  139. void redo();
  140. void commit();
  141. QString object_events_label;
  142. QString warps_label;
  143. QString coord_events_label;
  144. QString bg_events_label;
  145. QList<Event*> getAllEvents();
  146. QList<Event*> getEventsByType(QString type);
  147. void removeEvent(Event *event);
  148. void addEvent(Event *event);
  149. QMap<QString, QList<Event*>> events;
  150. QList<Connection*> connections;
  151. QPixmap renderConnection(Connection);
  152. QImage border_image;
  153. QPixmap border_pixmap;
  154. Blockdata *border = NULL;
  155. Blockdata *cached_border = NULL;
  156. QPixmap renderBorder();
  157. void cacheBorder();
  158. bool hasUnsavedChanges();
  159. QList<QList<QRgb> > getBlockPalettes(int metatile_index);
  160. signals:
  161. void paintTileChanged(Map *map);
  162. void paintCollisionChanged(Map *map);
  163. void mapChanged(Map *map);
  164. public slots:
  165. };
  166. class MapGroup : public QObject
  167. {
  168. Q_OBJECT
  169. public:
  170. QString name;
  171. int group_num;
  172. QList<Map*> maps;
  173. };
  174. #endif // MAP_H