Add straight paths for map shifting

This commit is contained in:
BigBahss 2020-08-21 12:15:25 -04:00 committed by garak
parent a59e695907
commit 713ded1754
2 changed files with 25 additions and 0 deletions

View file

@ -1081,6 +1081,12 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
item->pick(event);
}
} else if (map_edit_mode == "shift") {
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->shift(event);
}
} else if (item->paintingMode == MapPixmapItem::PaintMode::EventObjects) {
@ -1183,6 +1189,12 @@ void Editor::mouseEvent_collision(QGraphicsSceneMouseEvent *event, CollisionPixm
} else if (map_edit_mode == "pick") {
item->pick(event);
} else if (map_edit_mode == "shift") {
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->shift(event);
}
this->playerViewRect->updateLocation(x, y);

View file

@ -56,6 +56,19 @@ void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
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);
}
if (event->type() == QEvent::GraphicsSceneMousePress) {
selection_origin = QPoint(x, y);
selection.clear();