Add straight paths for collision tiles
This commit is contained in:
parent
5da761ea94
commit
a59e695907
2 changed files with 29 additions and 2 deletions
|
@ -1151,8 +1151,7 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
|
|||
QPointF pos = event->pos();
|
||||
int x = static_cast<int>(pos.x()) / 16;
|
||||
int y = static_cast<int>(pos.y()) / 16;
|
||||
this->playerViewRect->updateLocation(x, y);
|
||||
this->cursorMapTileRect->updateLocation(x, y);
|
||||
|
||||
if (map_edit_mode == "paint") {
|
||||
if (event->buttons() & Qt::RightButton) {
|
||||
item->updateMovementPermissionSelection(event);
|
||||
|
@ -1163,6 +1162,12 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
|
|||
item->floodFill(event);
|
||||
}
|
||||
} else {
|
||||
this->setStraightPathCursorMode(event);
|
||||
if (this->cursorMapTileRect->getStraightPathMode()) {
|
||||
item->lockNondominantAxis(event);
|
||||
x = item->adjustCoord(x, MapPixmapItem::Axis::X);
|
||||
y = item->adjustCoord(y, MapPixmapItem::Axis::Y);
|
||||
}
|
||||
item->paint(event);
|
||||
}
|
||||
} else if (map_edit_mode == "select") {
|
||||
|
@ -1180,6 +1185,8 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
|
|||
} else if (map_edit_mode == "shift") {
|
||||
item->shift(event);
|
||||
}
|
||||
this->playerViewRect->updateLocation(x, y);
|
||||
this->cursorMapTileRect->updateLocation(x, y);
|
||||
}
|
||||
|
||||
bool Editor::displayMap() {
|
||||
|
|
|
@ -16,12 +16,18 @@ void CollisionPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *) {
|
|||
}
|
||||
}
|
||||
void CollisionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
|
||||
QPointF pos = event->pos();
|
||||
int x = static_cast<int>(pos.x()) / 16;
|
||||
int y = static_cast<int>(pos.y()) / 16;
|
||||
this->paint_tile_initial_x = x;
|
||||
this->paint_tile_initial_y = y;
|
||||
emit mouseEvent(event, this);
|
||||
}
|
||||
void CollisionPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
|
||||
emit mouseEvent(event, this);
|
||||
}
|
||||
void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
|
||||
this->lockedAxis = CollisionPixmapItem::Axis::None;
|
||||
emit mouseEvent(event, this);
|
||||
}
|
||||
|
||||
|
@ -41,6 +47,20 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
|
|||
QPointF pos = event->pos();
|
||||
int x = static_cast<int>(pos.x()) / 16;
|
||||
int y = static_cast<int>(pos.y()) / 16;
|
||||
|
||||
// Set straight paths on/off and snap to the dominant axis when on
|
||||
bool straightPathsEnabled = event->modifiers() & Qt::ControlModifier;
|
||||
if (this->settings->straightPathsEnabled || straightPathsEnabled) {
|
||||
this->straightPathMode = true;
|
||||
} else {
|
||||
this->straightPathMode = false;
|
||||
}
|
||||
if (this->straightPathMode) {
|
||||
this->lockNondominantAxis(event);
|
||||
x = this->adjustCoord(x, MapPixmapItem::Axis::X);
|
||||
y = this->adjustCoord(y, MapPixmapItem::Axis::Y);
|
||||
}
|
||||
|
||||
Block *block = map->getBlock(x, y);
|
||||
if (block) {
|
||||
block->collision = this->movementPermissionsSelector->getSelectedCollision();
|
||||
|
|
Loading…
Reference in a new issue