Magic fill collision and elevation (#76)

This commit is contained in:
Diegoisawesome 2019-01-04 20:49:21 -06:00 committed by huderlem
parent bd9fc001b4
commit 060a3e359a
5 changed files with 35 additions and 1 deletions

View file

@ -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();

View file

@ -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);

View file

@ -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<Event *> Map::getAllEvents() {
QList<Event*> all;
for (QList<Event*> list : events.values()) {

View file

@ -60,6 +60,18 @@ void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
}
}
void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
if (map) {
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 16;
int y = static_cast<int>(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<int>(pos.x()) / 16;

View file

@ -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;