mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-19 23:25:09 -05:00
Map connection edit history
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
#define EDITCOMMANDS_H
|
||||
|
||||
#include "blockdata.h"
|
||||
#include "mapconnection.h"
|
||||
|
||||
#include <QUndoCommand>
|
||||
#include <QList>
|
||||
#include <QPointer>
|
||||
|
||||
class MapPixmapItem;
|
||||
class Map;
|
||||
@@ -31,6 +33,11 @@ enum CommandId {
|
||||
ID_EventDelete,
|
||||
ID_EventDuplicate,
|
||||
ID_EventPaste,
|
||||
ID_MapConnectionMove,
|
||||
ID_MapConnectionChangeDirection,
|
||||
ID_MapConnectionChangeMap,
|
||||
ID_MapConnectionAdd,
|
||||
ID_MapConnectionRemove,
|
||||
};
|
||||
|
||||
#define IDMask_EventType_Object (1 << 8)
|
||||
@@ -379,4 +386,113 @@ private:
|
||||
int newBorderHeight;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Implements a command to commit Map Connectien move actions.
|
||||
/// Actions are merged into one until the mouse is released when editing by click-and-drag,
|
||||
/// or when the offset spin box loses focus when editing with the list UI.
|
||||
class MapConnectionMove : public QUndoCommand {
|
||||
public:
|
||||
MapConnectionMove(MapConnection *connection, int newOffset, unsigned actionId,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override;
|
||||
int id() const override { return CommandId::ID_MapConnectionMove; }
|
||||
|
||||
private:
|
||||
MapConnection *connection;
|
||||
int newOffset;
|
||||
int oldOffset;
|
||||
bool mirrored;
|
||||
unsigned actionId;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Implements a command to commit changes to a Map Connectien's 'direction' field.
|
||||
class MapConnectionChangeDirection : public QUndoCommand {
|
||||
public:
|
||||
MapConnectionChangeDirection(MapConnection *connection, QString newDirection,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
int id() const override { return CommandId::ID_MapConnectionChangeDirection; }
|
||||
|
||||
private:
|
||||
QPointer<MapConnection> connection;
|
||||
QString newDirection;
|
||||
QString oldDirection;
|
||||
int oldOffset;
|
||||
int newOffset;
|
||||
bool mirrored;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Implements a command to commit changes to a Map Connectien's 'map' field.
|
||||
class MapConnectionChangeMap : public QUndoCommand {
|
||||
public:
|
||||
MapConnectionChangeMap(MapConnection *connection, QString newMapName,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
int id() const override { return CommandId::ID_MapConnectionChangeMap; }
|
||||
|
||||
private:
|
||||
QPointer<MapConnection> connection;
|
||||
QString newMapName;
|
||||
QString oldMapName;
|
||||
int oldOffset;
|
||||
int newOffset;
|
||||
bool mirrored;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Implements a command to commit adding a Map Connection to a map.
|
||||
class MapConnectionAdd : public QUndoCommand {
|
||||
public:
|
||||
MapConnectionAdd(Map *map, MapConnection *connection,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
int id() const override { return CommandId::ID_MapConnectionAdd; }
|
||||
|
||||
private:
|
||||
Map *map = nullptr;
|
||||
Map *mirrorMap = nullptr;
|
||||
QPointer<MapConnection> connection = nullptr;
|
||||
QPointer<MapConnection> mirror = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Implements a command to commit removing a Map Connection from a map.
|
||||
class MapConnectionRemove : public QUndoCommand {
|
||||
public:
|
||||
MapConnectionRemove(Map *map, MapConnection *connection,
|
||||
QUndoCommand *parent = nullptr);
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
int id() const override { return CommandId::ID_MapConnectionRemove; }
|
||||
|
||||
private:
|
||||
Map *map = nullptr;
|
||||
Map *mirrorMap = nullptr;
|
||||
QPointer<MapConnection> connection = nullptr;
|
||||
QPointer<MapConnection> mirror = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif // EDITCOMMANDS_H
|
||||
|
||||
@@ -99,10 +99,12 @@ public:
|
||||
void addEvent(Event *);
|
||||
void deleteConnections();
|
||||
QList<MapConnection*> getConnections() const;
|
||||
void removeConnection(MapConnection *);
|
||||
void addConnection(MapConnection *);
|
||||
bool takeConnection(MapConnection *);
|
||||
bool removeConnection(MapConnection *);
|
||||
bool addConnection(MapConnection *);
|
||||
void loadConnection(MapConnection *);
|
||||
QPixmap renderConnection(const QString &, MapLayout *);
|
||||
QRect getConnectionRect(const QString &direction, MapLayout *fromLayout = nullptr);
|
||||
QPixmap renderConnection(const QString &direction, MapLayout *fromLayout = nullptr);
|
||||
QPixmap renderBorder(bool ignoreCache = false);
|
||||
void setDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
|
||||
void setBorderDimensions(int newWidth, int newHeight, bool setNewBlockdata = true, bool enableScriptCallback = false);
|
||||
@@ -126,12 +128,15 @@ public:
|
||||
QUndoStack editHistory;
|
||||
void modify();
|
||||
void clean();
|
||||
void pruneEditHistory();
|
||||
|
||||
private:
|
||||
void setNewDimensionsBlockdata(int newWidth, int newHeight);
|
||||
void setNewBorderDimensionsBlockdata(int newWidth, int newHeight);
|
||||
|
||||
// MapConnections in 'ownedConnections' but not 'connections' persist in the edit history.
|
||||
QList<MapConnection*> connections;
|
||||
QSet<MapConnection*> ownedConnections;
|
||||
|
||||
signals:
|
||||
void modified();
|
||||
|
||||
@@ -29,7 +29,6 @@ public:
|
||||
int offset() const { return m_offset; }
|
||||
void setOffset(int offset, bool mirror = true);
|
||||
|
||||
bool isMirror(const MapConnection*);
|
||||
MapConnection* findMirror();
|
||||
MapConnection* createMirror();
|
||||
|
||||
@@ -43,6 +42,7 @@ public:
|
||||
static bool isVertical(const QString &direction);
|
||||
static bool isDiving(const QString &direction);
|
||||
static QString oppositeDirection(const QString &direction) { return oppositeDirections.value(direction, direction); }
|
||||
static bool areMirrored(const MapConnection*, const MapConnection*);
|
||||
|
||||
private:
|
||||
Map* m_parentMap;
|
||||
|
||||
Reference in New Issue
Block a user