暂无描述

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