No Description

map.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. int paint_tile;
  125. int paint_collision;
  126. int paint_elevation;
  127. Block *getBlock(int x, int y);
  128. void setBlock(int x, int y, Block block);
  129. void _setBlock(int x, int y, Block block);
  130. void floodFill(int x, int y, uint tile);
  131. void _floodFill(int x, int y, uint tile);
  132. void floodFillCollision(int x, int y, uint collision);
  133. void _floodFillCollision(int x, int y, uint collision);
  134. void floodFillElevation(int x, int y, uint elevation);
  135. void _floodFillElevation(int x, int y, uint elevation);
  136. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  137. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  138. History<Blockdata*> history;
  139. void undo();
  140. void redo();
  141. void commit();
  142. QString object_events_label;
  143. QString warps_label;
  144. QString coord_events_label;
  145. QString bg_events_label;
  146. QList<Event*> getAllEvents();
  147. QList<Event*> getEventsByType(QString type);
  148. void removeEvent(Event *event);
  149. void addEvent(Event *event);
  150. QMap<QString, QList<Event*>> events;
  151. QList<Connection*> connections;
  152. QPixmap renderConnection(Connection);
  153. QImage border_image;
  154. QPixmap border_pixmap;
  155. Blockdata *border = NULL;
  156. Blockdata *cached_border = NULL;
  157. QPixmap renderBorder();
  158. void cacheBorder();
  159. bool hasUnsavedChanges();
  160. QList<QList<QRgb> > getBlockPalettes(int metatile_index);
  161. signals:
  162. void paintTileChanged(Map *map);
  163. void paintCollisionChanged(Map *map);
  164. void mapChanged(Map *map);
  165. public slots:
  166. };
  167. #endif // MAP_H