more undo commands

- add edit command for duplicating map events
- add edit commands for painting map collision
- edit commands that delete events now select
  the proper next event
This commit is contained in:
garakmon
2020-07-31 20:30:35 -04:00
committed by garak
parent 98c3298805
commit 6c2d035dfa
7 changed files with 122 additions and 47 deletions

View File

@@ -8,16 +8,20 @@
void renderMapBlocks(Map *map, bool ignoreCache = false) {
map->mapItem->draw(ignoreCache);
map->collisionItem->draw(ignoreCache);
}
PaintMetatile::PaintMetatile(Map *map,
Blockdata *oldMetatiles, Blockdata *newMetatiles,
unsigned eventId, QUndoCommand *parent) : QUndoCommand(parent) {
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
setText("Paint Metatiles");
this->map = map;
this->oldMetatiles = oldMetatiles;
this->newMetatiles = newMetatiles;
this->eventId = eventId;
this->actionId = actionId;
}
PaintMetatile::~PaintMetatile() {
@@ -34,7 +38,7 @@ void PaintMetatile::redo() {
map->layout->blockdata->copyFrom(newMetatiles);
}
map->mapItem->draw();
renderMapBlocks(map);
}
void PaintMetatile::undo() {
@@ -44,7 +48,7 @@ void PaintMetatile::undo() {
map->layout->blockdata->copyFrom(oldMetatiles);
}
map->mapItem->draw();
renderMapBlocks(map);
QUndoCommand::undo();
}
@@ -55,7 +59,7 @@ bool PaintMetatile::mergeWith(const QUndoCommand *command) {
if (this->map != other->map)
return false;
if (eventId != other->eventId)
if (actionId != other->actionId)
return false;
this->newMetatiles->copyFrom(other->newMetatiles);
@@ -69,14 +73,14 @@ bool PaintMetatile::mergeWith(const QUndoCommand *command) {
PaintBorder::PaintBorder(Map *map,
Blockdata *oldBorder, Blockdata *newBorder,
unsigned eventId, QUndoCommand *parent) : QUndoCommand(parent) {
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
setText("Paint Border");
this->map = map;
this->oldBorder = oldBorder;
this->newBorder = newBorder;
this->eventId = eventId;
this->actionId = actionId;
}
PaintBorder::~PaintBorder() {
@@ -114,8 +118,8 @@ void PaintBorder::undo() {
BucketFillMetatile::BucketFillMetatile(Map *map,
Blockdata *oldMetatiles, Blockdata *newMetatiles,
unsigned eventId, QUndoCommand *parent)
: PaintMetatile(map, oldMetatiles, newMetatiles, eventId, parent) {
unsigned actionId, QUndoCommand *parent)
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
setText("Bucket Fill Metatiles");
}
@@ -129,8 +133,8 @@ BucketFillMetatile::~BucketFillMetatile() {
MagicFillMetatile::MagicFillMetatile(Map *map,
Blockdata *oldMetatiles, Blockdata *newMetatiles,
unsigned eventId, QUndoCommand *parent)
: PaintMetatile(map, oldMetatiles, newMetatiles, eventId, parent) {
unsigned actionId, QUndoCommand *parent)
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
setText("Magic Fill Metatiles");
}
@@ -144,14 +148,14 @@ MagicFillMetatile::~MagicFillMetatile() {
ShiftMetatiles::ShiftMetatiles(Map *map,
Blockdata *oldMetatiles, Blockdata *newMetatiles,
unsigned eventId, QUndoCommand *parent) : QUndoCommand(parent) {
unsigned actionId, QUndoCommand *parent) : QUndoCommand(parent) {
setText("Shift Metatiles");
this->map = map;
this->oldMetatiles = oldMetatiles;
this->newMetatiles = newMetatiles;
this->eventId = eventId;
this->actionId = actionId;
}
ShiftMetatiles::~ShiftMetatiles() {
@@ -168,7 +172,7 @@ void ShiftMetatiles::redo() {
map->layout->blockdata->copyFrom(newMetatiles);
}
map->mapItem->draw(true);
renderMapBlocks(map, true);
}
void ShiftMetatiles::undo() {
@@ -178,7 +182,7 @@ void ShiftMetatiles::undo() {
map->layout->blockdata->copyFrom(oldMetatiles);
}
map->mapItem->draw(true);
renderMapBlocks(map, true);
QUndoCommand::undo();
}
@@ -189,7 +193,7 @@ bool ShiftMetatiles::mergeWith(const QUndoCommand *command) {
if (this->map != other->map)
return false;
if (eventId != other->eventId)
if (actionId != other->actionId)
return false;
this->newMetatiles->copyFrom(other->newMetatiles);

View File

@@ -1,4 +1,5 @@
#include "collisionpixmapitem.h"
#include "editcommands.h"
void CollisionPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
int x = static_cast<int>(event->pos().x()) / 16;
@@ -26,12 +27,17 @@ void CollisionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
void CollisionPixmapItem::draw(bool ignoreCache) {
if (map) {
map->setCollisionItem(this);
setPixmap(map->renderCollision(*this->opacity, ignoreCache));
}
}
void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
if (map) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
actionId_++;
} else if (map) {
Blockdata *oldCollision = map->layout->blockdata->copy();
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 16;
int y = static_cast<int>(pos.y()) / 16;
@@ -41,34 +47,44 @@ void CollisionPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
block->elevation = this->movementPermissionsSelector->getSelectedElevation();
map->setBlock(x, y, *block, true);
}
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
map->commit();
}
draw();
Blockdata *newCollision = map->layout->blockdata->copy();
map->editHistory.push(new PaintCollision(map, oldCollision, newCollision, actionId_));
}
}
void CollisionPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
if (map) {
if (event->type() != QEvent::GraphicsSceneMouseRelease) {
// do nothing
} else if (map) {
Blockdata *oldCollision = map->layout->blockdata->copy();
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);
draw();
Blockdata *newCollision = map->layout->blockdata->copy();
map->editHistory.push(new BucketFillCollision(map, oldCollision, newCollision));
}
}
void CollisionPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
if (map) {
if (event->type() != QEvent::GraphicsSceneMouseRelease) {
// do nothing
} else if (map) {
Blockdata *oldCollision = map->layout->blockdata->copy();
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);
draw();
Blockdata *newCollision = map->layout->blockdata->copy();
map->editHistory.push(new MagicFillCollision(map, oldCollision, newCollision));
}
}

View File

@@ -8,7 +8,7 @@
void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
if (map) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
eventId_++;
actionId_++;
} else {
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 16;
@@ -29,7 +29,7 @@ void MapPixmapItem::paint(QGraphicsSceneMouseEvent *event) {
void MapPixmapItem::shift(QGraphicsSceneMouseEvent *event) {
if (map) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
eventId_++;
actionId_++;
} else {
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 16;
@@ -71,7 +71,7 @@ void MapPixmapItem::shift(int xDelta, int yDelta) {
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
ShiftMetatiles *paintEvent = new ShiftMetatiles(map, backupBlockdata, newMetatiles, eventId_);
ShiftMetatiles *paintEvent = new ShiftMetatiles(map, backupBlockdata, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
}
@@ -112,7 +112,7 @@ void MapPixmapItem::paintNormal(int x, int y, bool fromScriptCall) {
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
PaintMetatile *paintEvent = new PaintMetatile(map, oldMetatiles, newMetatiles, eventId_);
PaintMetatile *paintEvent = new PaintMetatile(map, oldMetatiles, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
}
@@ -225,7 +225,7 @@ void MapPixmapItem::paintSmartPath(int x, int y, bool fromScriptCall) {
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
PaintMetatile *paintEvent = new PaintMetatile(map, oldMetatiles, newMetatiles, eventId_);
PaintMetatile *paintEvent = new PaintMetatile(map, oldMetatiles, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
}
@@ -279,7 +279,7 @@ void MapPixmapItem::updateMetatileSelection(QGraphicsSceneMouseEvent *event) {
void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
if (map) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
eventId_++;
actionId_++;
} else {
QPointF pos = event->pos();
int x = static_cast<int>(pos.x()) / 16;
@@ -302,7 +302,7 @@ void MapPixmapItem::floodFill(QGraphicsSceneMouseEvent *event) {
void MapPixmapItem::magicFill(QGraphicsSceneMouseEvent *event) {
if (map) {
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
eventId_++;
actionId_++;
} else {
QPointF pos = event->pos();
int initialX = static_cast<int>(pos.x()) / 16;
@@ -365,7 +365,7 @@ void MapPixmapItem::magicFill(
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
MagicFillMetatile *paintEvent = new MagicFillMetatile(map, oldMetatiles, newMetatiles, eventId_);
MagicFillMetatile *paintEvent = new MagicFillMetatile(map, oldMetatiles, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
}
}
@@ -448,7 +448,7 @@ void MapPixmapItem::floodFill(
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
BucketFillMetatile *paintEvent = new BucketFillMetatile(map, oldMetatiles, newMetatiles, eventId_);
BucketFillMetatile *paintEvent = new BucketFillMetatile(map, oldMetatiles, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
delete[] visited;
@@ -575,7 +575,7 @@ void MapPixmapItem::floodFillSmartPath(int initialX, int initialY, bool fromScri
}
Blockdata *newMetatiles = map->layout->blockdata->copy();
BucketFillMetatile *paintEvent = new BucketFillMetatile(map, oldMetatiles, newMetatiles, eventId_);
BucketFillMetatile *paintEvent = new BucketFillMetatile(map, oldMetatiles, newMetatiles, actionId_);
map->editHistory.push(paintEvent);
delete[] visited;