2018-09-27 00:30:05 +01:00
|
|
|
#include "collisionpixmapitem.h"
|
2020-08-01 01:30:35 +01:00
|
|
|
#include "editcommands.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-08-21 17:11:06 +01:00
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 16;
|
|
|
|
int y = static_cast<int>(pos.y()) / 16;
|
2020-08-23 13:37:14 +01:00
|
|
|
this->paint_tile_initial_x = this->straight_path_initial_x = x;
|
|
|
|
this->paint_tile_initial_y = this->straight_path_initial_y = 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) {
|
|
|
|
Blockdata *oldCollision = map->layout->blockdata->copy();
|
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 16;
|
|
|
|
int y = static_cast<int>(pos.y()) / 16;
|
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);
|
|
|
|
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
|
|
|
|
y = this->adjustCoord(y, MapPixmapItem::Axis::Y);
|
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
|
|
|
}
|
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
Block *block = map->getBlock(x, y);
|
|
|
|
if (block) {
|
|
|
|
block->collision = this->movementPermissionsSelector->getSelectedCollision();
|
|
|
|
block->elevation = this->movementPermissionsSelector->getSelectedElevation();
|
2020-05-03 16:48:48 +01:00
|
|
|
map->setBlock(x, y, *block, true);
|
2018-09-27 00:30:05 +01:00
|
|
|
}
|
2020-08-01 01:30:35 +01:00
|
|
|
|
|
|
|
Blockdata *newCollision = map->layout->blockdata->copy();
|
2020-08-04 05:32:50 +01:00
|
|
|
if (newCollision->equals(oldCollision)) {
|
|
|
|
delete newCollision;
|
|
|
|
delete oldCollision;
|
|
|
|
} else {
|
|
|
|
map->editHistory.push(new PaintCollision(map, oldCollision, newCollision, actionId_));
|
|
|
|
}
|
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) {
|
|
|
|
Blockdata *oldCollision = map->layout->blockdata->copy();
|
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
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->floodFillCollisionElevation(x, y, collision, elevation);
|
2020-08-01 01:30:35 +01:00
|
|
|
|
|
|
|
Blockdata *newCollision = map->layout->blockdata->copy();
|
2020-08-04 05:32:50 +01:00
|
|
|
if (newCollision->equals(oldCollision)) {
|
|
|
|
delete newCollision;
|
|
|
|
delete oldCollision;
|
|
|
|
} else {
|
|
|
|
map->editHistory.push(new BucketFillCollision(map, oldCollision, newCollision));
|
|
|
|
}
|
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) {
|
|
|
|
Blockdata *oldCollision = map->layout->blockdata->copy();
|
2019-01-05 02:49:21 +00:00
|
|
|
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);
|
2020-08-01 01:30:35 +01:00
|
|
|
|
|
|
|
Blockdata *newCollision = map->layout->blockdata->copy();
|
2020-08-04 05:32:50 +01:00
|
|
|
if (newCollision->equals(oldCollision)) {
|
|
|
|
delete newCollision;
|
|
|
|
delete oldCollision;
|
|
|
|
} else {
|
|
|
|
map->editHistory.push(new MagicFillCollision(map, oldCollision, newCollision));
|
|
|
|
}
|
2019-01-05 02:49:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 00:30:05 +01:00
|
|
|
void CollisionPixmapItem::pick(QGraphicsSceneMouseEvent *event) {
|
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 16;
|
|
|
|
int y = static_cast<int>(pos.y()) / 16;
|
|
|
|
Block *block = map->getBlock(x, y);
|
|
|
|
if (block) {
|
|
|
|
this->movementPermissionsSelector->select(block->collision, block->elevation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CollisionPixmapItem::updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event) {
|
|
|
|
QPointF pos = event->pos();
|
|
|
|
int x = static_cast<int>(pos.x()) / 16;
|
|
|
|
int y = static_cast<int>(pos.y()) / 16;
|
|
|
|
|
|
|
|
// Snap point to within map bounds.
|
|
|
|
if (x < 0) x = 0;
|
|
|
|
if (x >= map->getWidth()) x = map->getWidth() - 1;
|
|
|
|
if (y < 0) y = 0;
|
|
|
|
if (y >= map->getHeight()) y = map->getHeight() - 1;
|
|
|
|
|
|
|
|
Block *block = map->getBlock(x, y);
|
|
|
|
this->movementPermissionsSelector->select(block->collision, block->elevation);
|
|
|
|
}
|