No Description

map.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. QList<T> history;
  13. int head = -1;
  14. int saved = -1;
  15. History() {
  16. }
  17. T pop() {
  18. if (head > 0) {
  19. return history.at(--head);
  20. }
  21. return NULL;
  22. }
  23. T next() {
  24. if (head + 1 < history.length()) {
  25. return history.at(++head);
  26. }
  27. return NULL;
  28. }
  29. void push(T commit) {
  30. while (head + 1 < history.length()) {
  31. history.removeLast();
  32. }
  33. if (saved > head) {
  34. saved = -1;
  35. }
  36. history.append(commit);
  37. head++;
  38. }
  39. void save() {
  40. saved = head;
  41. }
  42. bool isSaved() {
  43. return saved == head;
  44. }
  45. };
  46. class Connection {
  47. public:
  48. Connection() {
  49. }
  50. public:
  51. QString direction;
  52. QString offset;
  53. QString map_name;
  54. };
  55. class Map : public QObject
  56. {
  57. Q_OBJECT
  58. public:
  59. explicit Map(QObject *parent = 0);
  60. public:
  61. QString name;
  62. QString attributes_label;
  63. QString events_label;
  64. QString scripts_label;
  65. QString connections_label;
  66. QString song;
  67. QString index;
  68. QString location;
  69. QString visibility;
  70. QString weather;
  71. QString type;
  72. QString unknown;
  73. QString show_location;
  74. QString battle_scene;
  75. QString width;
  76. QString height;
  77. QString border_label;
  78. QString blockdata_label;
  79. QString tileset_primary_label;
  80. QString tileset_secondary_label;
  81. Tileset *tileset_primary = NULL;
  82. Tileset *tileset_secondary = NULL;
  83. Blockdata* blockdata = NULL;
  84. public:
  85. int getWidth();
  86. int getHeight();
  87. Tileset* getBlockTileset(int);
  88. int getBlockIndex(int index);
  89. Metatile* getMetatile(int);
  90. QImage getMetatileImage(int);
  91. QImage getMetatileTile(int);
  92. QPixmap render();
  93. QPixmap renderMetatiles();
  94. QPixmap renderCollision();
  95. QImage collision_image;
  96. QPixmap collision_pixmap;
  97. QImage getCollisionMetatileImage(Block);
  98. QImage getElevationMetatileImage(Block);
  99. QImage getCollisionMetatileImage(int);
  100. QImage getElevationMetatileImage(int);
  101. QPixmap renderCollisionMetatiles();
  102. QPixmap renderElevationMetatiles();
  103. void drawSelection(int i, int w, QPainter *painter);
  104. bool blockChanged(int, Blockdata*);
  105. Blockdata* cached_blockdata = NULL;
  106. void cacheBlockdata();
  107. Blockdata* cached_collision = NULL;
  108. void cacheCollision();
  109. QImage image;
  110. QPixmap pixmap;
  111. QList<QImage> metatile_images;
  112. int paint_tile;
  113. int paint_collision;
  114. int paint_elevation;
  115. Block *getBlock(int x, int y);
  116. void setBlock(int x, int y, Block block);
  117. void _setBlock(int x, int y, Block block);
  118. void floodFill(int x, int y, uint tile);
  119. void _floodFill(int x, int y, uint tile);
  120. void floodFillCollision(int x, int y, uint collision);
  121. void _floodFillCollision(int x, int y, uint collision);
  122. void floodFillElevation(int x, int y, uint elevation);
  123. void _floodFillElevation(int x, int y, uint elevation);
  124. void floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  125. void _floodFillCollisionElevation(int x, int y, uint collision, uint elevation);
  126. History<Blockdata*> history;
  127. void undo();
  128. void redo();
  129. void commit();
  130. QString object_events_label;
  131. QString warps_label;
  132. QString coord_events_label;
  133. QString bg_events_label;
  134. QList<Event*> getAllEvents();
  135. QList<Event*> getEventsByType(QString type);
  136. void removeEvent(Event *event);
  137. void addEvent(Event *event);
  138. QMap<QString, QList<Event*>> events;
  139. QList<Connection*> connections;
  140. QPixmap renderConnection(Connection);
  141. QImage border_image;
  142. QPixmap border_pixmap;
  143. Blockdata *border = NULL;
  144. Blockdata *cached_border = NULL;
  145. QPixmap renderBorder();
  146. void cacheBorder();
  147. bool hasUnsavedChanges();
  148. QList<QList<QRgb> > getBlockPalettes(int metatile_index);
  149. signals:
  150. void paintTileChanged(Map *map);
  151. void paintCollisionChanged(Map *map);
  152. void mapChanged(Map *map);
  153. public slots:
  154. };
  155. #endif // MAP_H