Açıklama Yok

map.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 attributes_label;
  71. QString events_label;
  72. QString scripts_label;
  73. QString connections_label;
  74. QString song;
  75. QString index;
  76. QString location;
  77. QString visibility;
  78. QString weather;
  79. QString type;
  80. QString unknown;
  81. QString show_location;
  82. QString battle_scene;
  83. QString width;
  84. QString height;
  85. QString border_label;
  86. QString blockdata_label;
  87. QString tileset_primary_label;
  88. QString tileset_secondary_label;
  89. Tileset *tileset_primary = NULL;
  90. Tileset *tileset_secondary = NULL;
  91. Blockdata* blockdata = NULL;
  92. public:
  93. void setName(QString mapName);
  94. static QString mapConstantFromName(QString mapName);
  95. int getWidth();
  96. int getHeight();
  97. Tileset* getBlockTileset(int);
  98. int getBlockIndex(int index);
  99. Metatile* getMetatile(int);
  100. QImage getMetatileImage(int);
  101. QImage getMetatileTile(int);
  102. QPixmap render();
  103. QPixmap renderMetatiles();
  104. QPixmap renderCollision();
  105. QImage collision_image;
  106. QPixmap collision_pixmap;
  107. QImage getCollisionMetatileImage(Block);
  108. QImage getElevationMetatileImage(Block);
  109. QImage getCollisionMetatileImage(int);
  110. QImage getElevationMetatileImage(int);
  111. QPixmap renderCollisionMetatiles();
  112. QPixmap renderElevationMetatiles();
  113. void drawSelection(int i, int w, QPainter *painter);
  114. bool blockChanged(int, Blockdata*);
  115. Blockdata* cached_blockdata = NULL;
  116. void cacheBlockdata();
  117. Blockdata* cached_collision = NULL;
  118. void cacheCollision();
  119. QImage image;
  120. QPixmap pixmap;
  121. QList<QImage> metatile_images;
  122. int paint_tile;
  123. int paint_collision;
  124. int paint_elevation;
  125. Block *getBlock(int x, int y);
  126. void setBlock(int x, int y, Block block);
  127. void _setBlock(int x, int y, Block block);
  128. void floodFill(int x, int y, uint tile);
  129. void _floodFill(int x, int y, uint tile);
  130. void floodFillCollision(int x, int y, uint collision);
  131. void _floodFillCollision(int x, int y, uint collision);
  132. void floodFillElevation(int x, int y, uint elevation);
  133. void _floodFillElevation(int x, int y, uint elevation);
  134. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  135. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  136. History<Blockdata*> history;
  137. void undo();
  138. void redo();
  139. void commit();
  140. QString object_events_label;
  141. QString warps_label;
  142. QString coord_events_label;
  143. QString bg_events_label;
  144. QList<Event*> getAllEvents();
  145. QList<Event*> getEventsByType(QString type);
  146. void removeEvent(Event *event);
  147. void addEvent(Event *event);
  148. QMap<QString, QList<Event*>> events;
  149. QList<Connection*> connections;
  150. QPixmap renderConnection(Connection);
  151. QImage border_image;
  152. QPixmap border_pixmap;
  153. Blockdata *border = NULL;
  154. Blockdata *cached_border = NULL;
  155. QPixmap renderBorder();
  156. void cacheBorder();
  157. bool hasUnsavedChanges();
  158. QList<QList<QRgb> > getBlockPalettes(int metatile_index);
  159. signals:
  160. void paintTileChanged(Map *map);
  161. void paintCollisionChanged(Map *map);
  162. void mapChanged(Map *map);
  163. public slots:
  164. };
  165. #endif // MAP_H