porymap/include/core/editcommands.h

341 lines
9 KiB
C
Raw Normal View History

2020-09-13 23:37:55 +01:00
#pragma once
2020-07-29 20:51:04 +01:00
#ifndef EDITCOMMANDS_H
#define EDITCOMMANDS_H
#include "blockdata.h"
2020-07-29 20:51:04 +01:00
#include <QUndoCommand>
#include <QList>
2020-07-29 20:51:04 +01:00
class MapPixmapItem;
class Map;
class Blockdata;
class Event;
class DraggablePixmapItem;
class Editor;
2020-07-29 20:51:04 +01:00
enum CommandId {
ID_PaintMetatile = 0,
ID_BucketFillMetatile,
ID_MagicFillMetatile,
ID_ShiftMetatiles,
ID_PaintCollision,
ID_BucketFillCollision,
ID_MagicFillCollision,
ID_ResizeMap,
ID_PaintBorder,
ID_ScriptEditMap,
ID_EventMove,
ID_EventShift,
ID_EventCreate,
ID_EventDelete,
ID_EventDuplicate,
2020-07-29 20:51:04 +01:00
};
2021-02-18 00:20:14 +00:00
#define IDMask_EventType_Object (1 << 8)
#define IDMask_EventType_Warp (1 << 9)
#define IDMask_EventType_BG (1 << 10)
#define IDMask_EventType_Trigger (1 << 11)
2021-02-18 00:20:14 +00:00
#define IDMask_EventType_Heal (1 << 12)
2020-07-29 20:51:04 +01:00
/// Implements a command to commit metatile paint actions
/// onto the map using the pencil tool.
2020-07-29 20:51:04 +01:00
class PaintMetatile : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
PaintMetatile(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent = nullptr);
2020-07-29 20:51:04 +01:00
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand* command) override;
int id() const override {
return CommandId::ID_PaintMetatile;
}
2020-07-29 20:51:04 +01:00
private:
2021-02-18 00:20:14 +00:00
Map* map;
2020-07-29 20:51:04 +01:00
Blockdata newMetatiles;
Blockdata oldMetatiles;
2020-07-29 20:51:04 +01:00
unsigned actionId;
};
/// Implements a command to commit paint actions
/// on the metatile collision and elevation.
class PaintCollision : public PaintMetatile {
public:
2021-02-18 00:20:14 +00:00
PaintCollision(Map* map, const Blockdata& oldCollision, const Blockdata& newCollision, unsigned actionId, QUndoCommand* parent = nullptr)
: PaintMetatile(map, oldCollision, newCollision, actionId, parent) {
setText("Paint Collision");
}
2021-02-18 00:20:14 +00:00
int id() const override {
return CommandId::ID_PaintCollision;
}
2020-07-29 20:51:04 +01:00
};
/// Implements a command to commit paint actions on the map border.
2020-07-29 20:51:04 +01:00
class PaintBorder : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
PaintBorder(Map* map, const Blockdata& oldBorder, const Blockdata& newBorder, unsigned actionId, QUndoCommand* parent = nullptr);
2020-07-29 20:51:04 +01:00
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand*) override {
return false;
};
int id() const override {
return CommandId::ID_PaintBorder;
}
2020-07-29 20:51:04 +01:00
private:
2021-02-18 00:20:14 +00:00
Map* map;
2020-07-29 20:51:04 +01:00
Blockdata newBorder;
Blockdata oldBorder;
2020-07-29 20:51:04 +01:00
unsigned actionId;
2020-07-29 20:51:04 +01:00
};
/// Implements a command to commit flood fill metatile actions
/// with the bucket tool onto the map.
2020-07-29 20:51:04 +01:00
class BucketFillMetatile : public PaintMetatile {
public:
2021-02-18 00:20:14 +00:00
BucketFillMetatile(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent = nullptr)
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
2020-08-04 04:55:22 +01:00
setText("Bucket Fill Metatiles");
}
2020-07-29 20:51:04 +01:00
2021-02-18 00:20:14 +00:00
int id() const override {
return CommandId::ID_BucketFillMetatile;
}
2020-07-29 20:51:04 +01:00
};
/// Implements a command to commit flood fill actions
/// on the metatile collision and elevation.
class BucketFillCollision : public PaintCollision {
public:
2021-02-18 00:20:14 +00:00
BucketFillCollision(Map* map, const Blockdata& oldCollision, const Blockdata& newCollision, QUndoCommand* parent = nullptr)
: PaintCollision(map, oldCollision, newCollision, -1, parent) {
setText("Flood Fill Collision");
}
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override {
return CommandId::ID_BucketFillCollision;
}
};
/// Implements a command to commit magic fill metatile actions
/// with the bucket or paint tool onto the map.
2020-07-29 20:51:04 +01:00
class MagicFillMetatile : public PaintMetatile {
public:
2021-02-18 00:20:14 +00:00
MagicFillMetatile(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent = nullptr)
: PaintMetatile(map, oldMetatiles, newMetatiles, actionId, parent) {
2020-08-04 04:55:22 +01:00
setText("Magic Fill Metatiles");
}
2020-07-29 20:51:04 +01:00
2021-02-18 00:20:14 +00:00
int id() const override {
return CommandId::ID_MagicFillMetatile;
}
2020-07-29 20:51:04 +01:00
};
/// Implements a command to commit magic fill collision actions.
class MagicFillCollision : public PaintCollision {
public:
2021-02-18 00:20:14 +00:00
MagicFillCollision(Map* map, const Blockdata& oldCollision, const Blockdata& newCollision, QUndoCommand* parent = nullptr)
: PaintCollision(map, oldCollision, newCollision, -1, parent) {
setText("Magic Fill Collision");
}
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override {
return CommandId::ID_MagicFillCollision;
}
};
/// Implements a command to commit metatile shift actions.
2020-07-29 20:51:04 +01:00
class ShiftMetatiles : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
ShiftMetatiles(Map* map, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, unsigned actionId, QUndoCommand* parent = nullptr);
2020-07-29 20:51:04 +01:00
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand* command) override;
int id() const override {
return CommandId::ID_ShiftMetatiles;
}
2020-07-29 20:51:04 +01:00
private:
2021-02-18 00:20:14 +00:00
Map* map;
2020-07-29 20:51:04 +01:00
Blockdata newMetatiles;
Blockdata oldMetatiles;
2020-07-29 20:51:04 +01:00
unsigned actionId;
2020-07-29 20:51:04 +01:00
};
/// Implements a command to commit a map or border resize action.
2020-07-29 20:51:04 +01:00
class ResizeMap : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
ResizeMap(Map* map, QSize oldMapDimensions, QSize newMapDimensions, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, QSize oldBorderDimensions,
QSize newBorderDimensions, const Blockdata& oldBorder, const Blockdata& newBorder, QUndoCommand* parent = nullptr);
2020-07-29 20:51:04 +01:00
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override {
return CommandId::ID_ResizeMap;
}
2020-07-29 20:51:04 +01:00
private:
2021-02-18 00:20:14 +00:00
Map* map;
2020-07-29 20:51:04 +01:00
int oldMapWidth;
int oldMapHeight;
int newMapWidth;
int newMapHeight;
int oldBorderWidth;
int oldBorderHeight;
int newBorderWidth;
int newBorderHeight;
Blockdata newMetatiles;
Blockdata oldMetatiles;
2020-07-29 20:51:04 +01:00
Blockdata newBorder;
Blockdata oldBorder;
2020-07-29 20:51:04 +01:00
};
/// Implements a command to commit a single- or multi-Event move action.
/// Actions are merged into one until the mouse is released.
class EventMove : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
EventMove(QList<Event*> events, int deltaX, int deltaY, unsigned actionId, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand* command) override;
int id() const override;
private:
2021-02-18 00:20:14 +00:00
QList<Event*> events;
int deltaX;
int deltaY;
unsigned actionId;
};
/// Implements a command to commit Event shift actions.
class EventShift : public EventMove {
public:
2021-02-18 00:20:14 +00:00
EventShift(QList<Event*> events, int deltaX, int deltaY, unsigned actionId, QUndoCommand* parent = nullptr);
int id() const override;
2021-02-18 00:20:14 +00:00
private:
2021-02-18 00:20:14 +00:00
QList<Event*> events;
};
/// Implements a command to commit Event create actions.
/// Works for a single Event only.
class EventCreate : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
EventCreate(Editor* editor, Map* map, Event* event, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override;
private:
2021-02-18 00:20:14 +00:00
Map* map;
Event* event;
Editor* editor;
};
/// Implements a command to commit Event deletions.
/// Applies to every currently selected Event.
class EventDelete : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
EventDelete(Editor* editor, Map* map, QList<Event*> selectedEvents, Event* nextSelectedEvent, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override;
private:
2021-02-18 00:20:14 +00:00
Editor* editor;
Map* map;
QList<Event*> selectedEvents; // allow multiple deletion of events
Event* nextSelectedEvent;
};
/// Implements a command to commit Event duplications.
class EventDuplicate : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
EventDuplicate(Editor* editor, Map* map, QList<Event*> selectedEvents, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override;
private:
2021-02-18 00:20:14 +00:00
Map* map;
QList<Event*> selectedEvents; // allow multiple deletion of events
Editor* editor;
};
/// Implements a command to commit map edits from the scripting API.
/// The scripting api can edit metatiles and map dimensions.
class ScriptEditMap : public QUndoCommand {
public:
2021-02-18 00:20:14 +00:00
ScriptEditMap(
Map* map, QSize oldMapDimensions, QSize newMapDimensions, const Blockdata& oldMetatiles, const Blockdata& newMetatiles, QUndoCommand* parent = nullptr);
void undo() override;
void redo() override;
2021-02-18 00:20:14 +00:00
bool mergeWith(const QUndoCommand*) override {
return false;
}
int id() const override {
return CommandId::ID_ScriptEditMap;
}
private:
2021-02-18 00:20:14 +00:00
Map* map;
Blockdata newMetatiles;
Blockdata oldMetatiles;
int oldMapWidth;
int oldMapHeight;
int newMapWidth;
int newMapHeight;
};
2020-07-29 20:51:04 +01:00
#endif // EDITCOMMANDS_H