2018-09-27 00:30:05 +01:00
|
|
|
#include "collisionpixmapitem.h"
|
2020-08-01 01:30:35 +01:00
|
|
|
#include "editcommands.h"
|
2020-10-02 20:32:22 +01:00
|
|
|
#include "metatile.h"
|
2018-09-27 00:30:05 +01:00
|
|
|
|
|
|
|
void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
|
|
|
|
int x = static_cast<int>(event->pos().x()) / 16;
|
|
|
|
int y = static_cast<int>(event->pos().y()) / 16;
|
|
|
|
emit this->hoveredMapMovementPermissionChanged(x, y);
|
2019-11-02 18:40:43 +00:00
|
|
|
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles) {
|
2018-09-27 00:30:05 +01:00
|
|
|
setCursor(this->settings->mapCursor);
|
|
|
|
}
|
|
|
|
}
|
2020-08-23 13:37:14 +01:00
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
|
|
|
emit this->hoveredMapMovementPermissionCleared();
|
2019-11-02 18:40:43 +00:00
|
|
|
if (this->settings->betterCursors && this->paintingMode == MapPixmapItem::PaintMode::Metatiles){
|
2018-09-27 00:30:05 +01:00
|
|
|
unsetCursor();
|
|
|
|
}
|
|
|
|
}
|
2020-08-23 13:37:14 +01:00
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
2020-10-02 20:32:22 +01:00
|
|
|
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
|
|
|
this->paint_tile_initial_x = this->straight_path_initial_x = pos.x();
|
|
|
|
this->paint_tile_initial_y = this->straight_path_initial_y = pos.y();
|
2018-09-27 00:30:05 +01:00
|
|
|
emit mouseEvent(event, this);
|
|
|
|
}
|
2020-08-23 13:37:14 +01:00
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
|
|
|
emit mouseEvent(event, this);
|
|
|
|
}
|
2020-08-23 13:37:14 +01:00
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
2020-08-21 17:11:06 +01:00
|
|
|
this->lockedAxis = CollisionPixmapItem::Axis::None;
|
2018-09-27 00:30:05 +01:00
|
|
|
emit mouseEvent(event, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollisionPixmapItem::draw(bool ignoreCache) {
|
|
|
|
if (map) {
|
2020-08-01 01:30:35 +01:00
|
|
|
map->setCollisionItem(this);
|
2019-01-06 18:53:31 +00:00
|
|
|
setPixmap(map->renderCollision(*this->opacity, ignoreCache));
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
2020-08-01 01:30:35 +01:00
|
|
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
|
|
|
actionId_++;
|
|
|
|
} else if (map) {
|
2021-02-14 20:10:03 +00:00
|
|
|
Blockdata *oldCollision = new Blockdata(*map->layout->blockdata);
|
2020-08-01 01:30:35 +01:00
|
|
|
|
2020-10-02 20:32:22 +01:00
|
|
|
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
2020-08-21 17:11:06 +01:00
|
|
|
|
|
|
|
// Set straight paths on/off and snap to the dominant axis when on
|
2020-08-23 13:37:14 +01:00
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
2020-08-21 17:11:06 +01:00
|
|
|
this->lockNondominantAxis(event);
|
2020-10-02 20:32:22 +01:00
|
|
|
pos = this->adjustCoords(pos);
|
2020-08-23 13:37:14 +01:00
|
|
|
} else {
|
|
|
|
this->prevStraightPathState = false;
|
|
|
|
this->lockedAxis = MapPixmapItem::Axis::None;
|
2020-08-21 17:11:06 +01:00
|
|
|
}
|
|
|
|
|
2021-02-13 21:16:52 +00:00
|
|
|
Block block;
|
|
|
|
if (map->getBlock(pos.x(), pos.y(), &block)) {
|
|
|
|
block.collision = this->movementPermissionsSelector->getSelectedCollision();
|
|
|
|
block.elevation = this->movementPermissionsSelector->getSelectedElevation();
|
|
|
|
map->setBlock(pos.x(), pos.y(), block, true);
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|
2020-08-01 01:30:35 +01:00
|
|
|
|
2021-02-14 20:10:03 +00:00
|
|
|
Blockdata *newCollision = new Blockdata(*map->layout->blockdata);
|
|
|
|
if (*newCollision == *oldCollision) {
|
2020-08-04 05:32:50 +01:00
|
|
|
delete newCollision;
|
|
|
|
delete oldCollision;
|
|
|
|
} else {
|
2021-02-14 20:10:03 +00:00
|
|
|
map->editHistory.push(new PaintCollision(map, *oldCollision, *newCollision, actionId_));
|
2020-08-04 05:32:50 +01:00
|
|
|
}
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
|
2020-08-19 05:30:02 +01:00
|
|
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
|
|
|
this->actionId_++;
|
2020-08-01 01:30:35 +01:00
|
|
|
} else if (map) {
|
2021-02-14 20:10:03 +00:00
|
|
|
Blockdata *oldCollision = new Blockdata(*map->layout->blockdata);
|
2020-08-01 01:30:35 +01:00
|
|
|
|
2020-10-02 20:32:22 +01:00
|
|
|
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
2018-09-27 00:30:05 +01:00
|
|
|
uint16_t collision = this->movementPermissionsSelector->getSelectedCollision();
|
|
|
|
uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation();
|
2020-10-02 20:32:22 +01:00
|
|
|
map->floodFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
2020-08-01 01:30:35 +01:00
|
|
|
|
2021-02-14 20:10:03 +00:00
|
|
|
Blockdata *newCollision = new Blockdata(*map->layout->blockdata);
|
|
|
|
if (*newCollision == *oldCollision) {
|
2020-08-04 05:32:50 +01:00
|
|
|
delete newCollision;
|
|
|
|
delete oldCollision;
|
|
|
|
} else {
|
2021-02-14 20:10:03 +00:00
|
|
|
map->editHistory.push(new BucketFillCollision(map, *oldCollision, *newCollision));
|
2020-08-04 05:32:50 +01:00
|
|
|
}
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 02:49:21 +00:00
|
|
|
void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
|
2020-08-19 05:30:02 +01:00
|
|
|
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
|
|
|
this->actionId_++;
|
2020-08-01 01:30:35 +01:00
|
|
|
} else if (map) {
|
2021-02-14 20:10:03 +00:00
|
|
|
Blockdata *oldCollision = new Blockdata(*map->layout->blockdata);
|
2020-10-02 20:32:22 +01:00
|
|
|
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
2019-01-05 02:49:21 +00:00
|
|
|
uint16_t collision = this->movementPermissionsSelector->getSelectedCollision();
|
|
|
|
uint16_t elevation = this->movementPermissionsSelector->getSelectedElevation();
|
2020-10-02 20:32:22 +01:00
|
|
|
map->magicFillCollisionElevation(pos.x(), pos.y(), collision, elevation);
|
2020-08-01 01:30:35 +01:00
|
|
|
|
2021-02-14 20:10:03 +00:00
|
|
|
Blockdata *newCollision = new Blockdata(*map->layout->blockdata);
|
|
|
|
if (*newCollision == *oldCollision) {
|
2020-08-04 05:32:50 +01:00
|
|
|
delete newCollision;
|
|
|
|
delete oldCollision;
|
|
|
|
} else {
|
2021-02-14 20:10:03 +00:00
|
|
|
map->editHistory.push(new MagicFillCollision(map, *oldCollision, *newCollision));
|
2020-08-04 05:32:50 +01:00
|
|
|
}
|
2019-01-05 02:49:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
2020-10-02 20:32:22 +01:00
|
|
|
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
2021-02-13 21:16:52 +00:00
|
|
|
Block block;
|
|
|
|
if (map->getBlock(pos.x(), pos.y(), &block)) {
|
|
|
|
this->movementPermissionsSelector->select(block.collision, block.elevation);
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event) {
|
2020-10-02 20:32:22 +01:00
|
|
|
QPoint pos = Metatile::coordFromPixmapCoord(event->pos());
|
2018-09-27 00:30:05 +01:00
|
|
|
|
|
|
|
// Snap point to within map bounds.
|
2020-10-02 20:32:22 +01:00
|
|
|
if (pos.x() < 0) pos.setX(0);
|
|
|
|
if (pos.x() >= map->getWidth()) pos.setX(map->getWidth() - 1);
|
|
|
|
if (pos.y() < 0) pos.setY(0);
|
|
|
|
if (pos.y() >= map->getHeight()) pos.setY(map->getHeight() - 1);
|
2018-09-27 00:30:05 +01:00
|
|
|
|
2021-02-13 21:16:52 +00:00
|
|
|
Block block;
|
|
|
|
if (map->getBlock(pos.x(), pos.y(), &block)) {
|
|
|
|
this->movementPermissionsSelector->select(block.collision, block.elevation);
|
|
|
|
}
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|