diff --git a/include/core/map.h b/include/core/map.h index 542ec4e4..252a8666 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -68,6 +68,7 @@ public: void _setBlock(int x, int y, Block block); void floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); void _floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); + void magicFillCollisionElevation(int x, int y, uint16_t collision, uint16_t elevation); void undo(); void redo(); void commit(); diff --git a/include/ui/collisionpixmapitem.h b/include/ui/collisionpixmapitem.h index 82f4aed3..8fa87aff 100644 --- a/include/ui/collisionpixmapitem.h +++ b/include/ui/collisionpixmapitem.h @@ -18,6 +18,7 @@ public: void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event); virtual void paint(QGraphicsSceneMouseEvent*); virtual void floodFill(QGraphicsSceneMouseEvent*); + virtual void magicFill(QGraphicsSceneMouseEvent*); virtual void pick(QGraphicsSceneMouseEvent*); virtual void draw(bool ignoreCache = false); diff --git a/src/core/map.cpp b/src/core/map.cpp index e66194dc..16b436ab 100644 --- a/src/core/map.cpp +++ b/src/core/map.cpp @@ -412,6 +412,26 @@ void Map::floodFillCollisionElevation(int x, int y, uint16_t collision, uint16_t } } +void Map::magicFillCollisionElevation(int initialX, int initialY, uint16_t collision, uint16_t elevation) { + Block *block = getBlock(initialX, initialY); + if (block && (block->collision != collision || block->elevation != elevation)) { + uint old_coll = block->collision; + uint old_elev = block->elevation; + + for (int y = 0; y < getHeight(); y++) { + for (int x = 0; x < getWidth(); x++) { + block = getBlock(x, y); + if (block && block->collision == old_coll && block->elevation == old_elev) { + block->collision = collision; + block->elevation = elevation; + _setBlock(x, y, *block); + } + } + } + commit(); + } +} + QList Map::getAllEvents() { QList all; for (QList list : events.values()) { diff --git a/src/ui/collisionpixmapitem.cpp b/src/ui/collisionpixmapitem.cpp index 839cf24d..c2bb34e5 100644 --- a/src/ui/collisionpixmapitem.cpp +++ b/src/ui/collisionpixmapitem.cpp @@ -60,6 +60,18 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) { } } +void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) { + if (map) { + QPointF pos = event->pos(); + int x = static_cast(pos.x()) / 16; + int y = static_cast(pos.y()) / 16; + uint16_t collision = this->movementPermissionsSelector->getSelectedCollision(); + uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation(); + map->magicFillCollisionElevation(x, y, collision, elevation); + draw(); + } +} + void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) { QPointF pos = event->pos(); int x = static_cast(pos.x()) / 16; diff --git a/src/ui/mappixmapitem.cpp b/src/ui/mappixmapitem.cpp index dd6b3e94..d96c7f61 100644 --- a/src/ui/mappixmapitem.cpp +++ b/src/ui/mappixmapitem.cpp @@ -266,7 +266,7 @@ void MapPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) { for (int y = 0; y < map->getHeight(); y++) { for (int x = 0; x < map->getWidth(); x++) { - Block *block = map->getBlock(x, y); + block = map->getBlock(x, y); if (block && block->tile == tile) { int xDiff = x - initialX; int yDiff = y - initialY;