edit commands for creating and deleting events
This commit is contained in:
parent
a0dc347ad3
commit
2598ca2277
7 changed files with 177 additions and 14 deletions
|
@ -9,6 +9,7 @@ class Map;
|
|||
class Blockdata;
|
||||
class Event;
|
||||
class DraggablePixmapItem;
|
||||
class Editor;
|
||||
|
||||
enum CommandId {
|
||||
ID_PaintMetatile, // - done
|
||||
|
@ -18,9 +19,9 @@ enum CommandId {
|
|||
ID_ResizeMap, // - done
|
||||
ID_PaintBorder, // - done
|
||||
ID_EventMove, // - done
|
||||
ID_EventShift, // -
|
||||
ID_EventCreate, // -
|
||||
ID_EventDelete, // -
|
||||
ID_EventShift, // - done
|
||||
ID_EventCreate, // - done
|
||||
ID_EventDelete, // - done
|
||||
ID_EventSetData, // - ?
|
||||
// Tileset editor history commands
|
||||
// Region map editor history commands
|
||||
|
@ -193,4 +194,59 @@ private:
|
|||
unsigned actionId;
|
||||
};
|
||||
|
||||
|
||||
|
||||
///
|
||||
class EventShift : public EventMove {
|
||||
public:
|
||||
EventShift(QList<Event *> events,
|
||||
int deltaX, int deltaY, unsigned actionId,
|
||||
QUndoCommand *parent = nullptr);
|
||||
~EventShift();
|
||||
|
||||
int id() const override { return CommandId::ID_EventShift; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
///
|
||||
class EventCreate : public QUndoCommand {
|
||||
public:
|
||||
EventCreate(Editor *editor, Map *map, Event *event,
|
||||
QUndoCommand *parent = nullptr);
|
||||
~EventCreate();
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
int id() const override { return CommandId::ID_EventCreate; }
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
Event *event;
|
||||
Editor *editor;
|
||||
};
|
||||
|
||||
|
||||
|
||||
///
|
||||
class EventDelete : public QUndoCommand {
|
||||
public:
|
||||
EventDelete(Editor *editor, Map *map, Event *event,
|
||||
QUndoCommand *parent = nullptr);
|
||||
~EventDelete();
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
int id() const override { return CommandId::ID_EventDelete; }
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
Event *event;
|
||||
Editor *editor;
|
||||
};
|
||||
|
||||
#endif // EDITCOMMANDS_H
|
||||
|
|
|
@ -99,8 +99,15 @@ public:
|
|||
bool hFlip = false;
|
||||
bool usingSprite;
|
||||
|
||||
void activate() { active = true; }
|
||||
void deactivate() { active = false; }
|
||||
bool isActive() { return active; }
|
||||
|
||||
DraggablePixmapItem *pixmapItem = nullptr;
|
||||
void setPixmapItem(DraggablePixmapItem *item) { pixmapItem = item; }
|
||||
|
||||
private:
|
||||
bool active = true;
|
||||
};
|
||||
|
||||
#endif // EVENT_H
|
||||
|
|
|
@ -111,6 +111,7 @@ private:
|
|||
signals:
|
||||
void mapChanged(Map *map);
|
||||
void mapNeedsRedrawing();
|
||||
void objectsChanged();
|
||||
};
|
||||
|
||||
#endif // MAP_H
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "mappixmapitem.h"
|
||||
#include "draggablepixmapitem.h"
|
||||
#include "bordermetatilespixmapitem.h"
|
||||
#include "editor.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
@ -321,4 +322,95 @@ bool EventMove::mergeWith(const QUndoCommand *command) {
|
|||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
EventShift::EventShift(QList<Event *> events,
|
||||
int deltaX, int deltaY, unsigned actionId,
|
||||
QUndoCommand *parent)
|
||||
: EventMove(events, deltaX, deltaY, actionId, parent) {
|
||||
setText("Shift Events");
|
||||
}
|
||||
|
||||
EventShift::~EventShift() {}
|
||||
|
||||
/******************************************************************************
|
||||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
EventCreate::EventCreate(Editor *editor, Map *map, Event *event,
|
||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
//
|
||||
setText("Create Event");
|
||||
|
||||
this->editor = editor;
|
||||
|
||||
this->map = map;
|
||||
this->event = event;
|
||||
}
|
||||
|
||||
EventCreate::~EventCreate() {}
|
||||
|
||||
void EventCreate::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
map->addEvent(event);
|
||||
|
||||
editor->project->loadEventPixmaps(map->getAllEvents());
|
||||
editor->addMapEvent(event);
|
||||
|
||||
map->objectsChanged();
|
||||
}
|
||||
|
||||
void EventCreate::undo() {
|
||||
//
|
||||
map->removeEvent(event);
|
||||
|
||||
if (editor->scene->items().contains(event->pixmapItem)) {
|
||||
editor->scene->removeItem(event->pixmapItem);
|
||||
}
|
||||
editor->selected_events->removeOne(event->pixmapItem);
|
||||
|
||||
map->objectsChanged();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
************************************************************************
|
||||
******************************************************************************/
|
||||
|
||||
EventDelete::EventDelete(Editor *editor, Map *map, Event *event,
|
||||
QUndoCommand *parent) : QUndoCommand(parent) {
|
||||
//
|
||||
setText("Delete Event");
|
||||
|
||||
this->editor = editor;
|
||||
|
||||
this->map = map;
|
||||
this->event = event;
|
||||
}
|
||||
|
||||
EventDelete::~EventDelete() {}
|
||||
|
||||
void EventDelete::redo() {
|
||||
QUndoCommand::redo();
|
||||
|
||||
map->removeEvent(event);
|
||||
|
||||
if (editor->scene->items().contains(event->pixmapItem)) {
|
||||
editor->scene->removeItem(event->pixmapItem);
|
||||
}
|
||||
editor->selected_events->removeOne(event->pixmapItem);
|
||||
|
||||
map->objectsChanged();
|
||||
}
|
||||
|
||||
void EventDelete::undo() {
|
||||
//
|
||||
map->addEvent(event);
|
||||
|
||||
editor->project->loadEventPixmaps(map->getAllEvents());
|
||||
editor->addMapEvent(event);
|
||||
|
||||
map->objectsChanged();
|
||||
|
||||
QUndoCommand::undo();
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ Event::Event(QJsonObject obj, QString type)
|
|||
|
||||
Event* Event::createNewEvent(QString event_type, QString map_name, Project *project)
|
||||
{
|
||||
Event *event = new Event;
|
||||
Event *event = nullptr;
|
||||
if (event_type == EventType::Object) {
|
||||
event = createNewObjectEvent(project);
|
||||
event->setFrameFromMovement(event->get("movement_type"));
|
||||
|
@ -59,6 +59,9 @@ Event* Event::createNewEvent(QString event_type, QString map_name, Project *proj
|
|||
event = createNewHiddenItemEvent(project);
|
||||
} else if (event_type == EventType::SecretBase) {
|
||||
event = createNewSecretBaseEvent(project);
|
||||
} else {
|
||||
// should never be reached but just in case
|
||||
event = new Event;
|
||||
}
|
||||
|
||||
event->setX(0);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "currentselectedmetatilespixmapitem.h"
|
||||
#include "mapsceneeventfilter.h"
|
||||
#include "montabwidget.h"
|
||||
#include "editcommands.h"
|
||||
#include <QCheckBox>
|
||||
#include <QPainter>
|
||||
#include <QMouseEvent>
|
||||
|
@ -1081,9 +1082,11 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
// do nothing here, at least for now
|
||||
} else if (obj_edit_mode == "shift" && item->map) {
|
||||
static QPoint selection_origin;
|
||||
static unsigned actionId = 0;
|
||||
|
||||
if (event->type() == QEvent::GraphicsSceneMouseRelease) {
|
||||
// TODO: commit / update history here
|
||||
actionId++;
|
||||
} else {
|
||||
if (event->type() == QEvent::GraphicsSceneMousePress) {
|
||||
selection_origin = QPoint(x, y);
|
||||
|
@ -1092,10 +1095,15 @@ void Editor::mouseEvent_map(QGraphicsSceneMouseEvent *event, MapPixmapItem *item
|
|||
int xDelta = x - selection_origin.x();
|
||||
int yDelta = y - selection_origin.y();
|
||||
|
||||
QList<Event *> selectedEvents;
|
||||
|
||||
for (DraggablePixmapItem *item : *(getObjects())) {
|
||||
item->move(xDelta, yDelta);
|
||||
//item->move(xDelta, yDelta);
|
||||
selectedEvents.append(item->event);
|
||||
}
|
||||
selection_origin = QPoint(x, y);
|
||||
|
||||
map->editHistory.push(new EventShift(selectedEvents, xDelta, yDelta, actionId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1845,10 +1853,9 @@ DraggablePixmapItem* Editor::addNewEvent(QString event_type) {
|
|||
project->healLocations.append(hl);
|
||||
event->put("index", project->healLocations.length());
|
||||
}
|
||||
map->addEvent(event);
|
||||
project->loadEventPixmaps(map->getAllEvents());
|
||||
DraggablePixmapItem *object = addMapEvent(event);
|
||||
return object;
|
||||
map->editHistory.push(new EventCreate(this, map, event));
|
||||
|
||||
return event->pixmapItem;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -514,6 +514,7 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
|||
|
||||
connect(editor->map, SIGNAL(mapChanged(Map*)), this, SLOT(onMapChanged(Map *)));
|
||||
connect(editor->map, SIGNAL(mapNeedsRedrawing()), this, SLOT(onMapNeedsRedrawing()));
|
||||
connect(editor->map, SIGNAL(objectsChanged()), this, SLOT(updateObjects()));
|
||||
|
||||
setRecentMap(map_name);
|
||||
updateMapList();
|
||||
|
@ -2124,11 +2125,7 @@ void MainWindow::on_toolButton_deleteObject_clicked()
|
|||
}
|
||||
}
|
||||
}
|
||||
editor->deleteEvent(item->event);
|
||||
if (editor->scene->items().contains(item)) {
|
||||
editor->scene->removeItem(item);
|
||||
}
|
||||
editor->selected_events->removeOne(item);
|
||||
editor->map->editHistory.push(new EventDelete(editor, editor->map, item->event));
|
||||
}
|
||||
else { // don't allow deletion of heal locations
|
||||
logWarn(QString("Cannot delete event of type '%1'").arg(item->event->get("event_type")));
|
||||
|
|
Loading…
Reference in a new issue