mirror of
https://github.com/huderlem/porymap.git
synced 2026-09-26 09:56:32 -05:00
Shift events if map moves when resized
This commit is contained in:
@@ -180,6 +180,8 @@ public:
|
||||
qreal collisionOpacity = 0.5;
|
||||
static QList<QList<const QImage*>> collisionIcons;
|
||||
|
||||
int eventShiftActionId = 0;
|
||||
|
||||
void objectsView_onMousePress(QMouseEvent *event);
|
||||
|
||||
int getBorderDrawDistance(int dimension);
|
||||
|
||||
@@ -1379,10 +1379,9 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
|
||||
// do nothing here, at least for now
|
||||
} else if (objectEditAction == EditAction::Shift) {
|
||||
static QPoint selection_origin;
|
||||
static unsigned actionId = 0;
|
||||
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
actionId++;
|
||||
this->eventShiftActionId++;
|
||||
} else {
|
||||
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||
selection_origin = QPoint(pos.x(), pos.y());
|
||||
@@ -1398,7 +1397,7 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, LayoutPixmapItem *i
|
||||
}
|
||||
selection_origin = QPoint(pos.x(), pos.y());
|
||||
|
||||
map->commit(new EventShift(selectedEvents, xDelta, yDelta, actionId));
|
||||
map->commit(new EventShift(selectedEvents, xDelta, yDelta, this->eventShiftActionId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2609,6 +2609,8 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked() {
|
||||
popup.setupLayoutView();
|
||||
if (popup.exec() == QDialog::Accepted) {
|
||||
Layout *layout = this->editor->layout;
|
||||
Map *map = this->editor->map;
|
||||
|
||||
QMargins result = popup.getResult();
|
||||
QSize borderResult = popup.getBorderResult();
|
||||
QSize oldLayoutDimensions(layout->getWidth(), layout->getHeight());
|
||||
@@ -2626,6 +2628,15 @@ void MainWindow::on_pushButton_ChangeDimensions_clicked() {
|
||||
oldBorder, layout->border
|
||||
));
|
||||
}
|
||||
// If we're in map-editing mode, adjust the events' position by the same amount.
|
||||
if (map) {
|
||||
auto events = map->getEvents();
|
||||
int deltaX = result.left();
|
||||
int deltaY = result.top();
|
||||
if ((deltaX || deltaY) && !events.isEmpty()) {
|
||||
map->commit(new EventShift(events, deltaX, deltaY, this->editor->eventShiftActionId++));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user