mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-20 07:36:31 -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;
|
||||
|
||||
@@ -79,6 +79,7 @@ public:
|
||||
void setConnectionsVisibility(bool visible);
|
||||
void updateDivingMapsVisibility();
|
||||
void displayDivingConnections();
|
||||
void renderDivingConnections();
|
||||
void addConnection(MapConnection* connection);
|
||||
void removeConnection(MapConnection* connection);
|
||||
void removeSelectedConnection();
|
||||
@@ -111,7 +112,6 @@ public:
|
||||
QPointer<QGraphicsScene> scene = nullptr;
|
||||
QGraphicsPixmapItem *current_view = nullptr;
|
||||
QPointer<MapPixmapItem> map_item = nullptr;
|
||||
QPointer<ConnectionPixmapItem> selected_connection_item = nullptr;
|
||||
QList<QPointer<ConnectionPixmapItem>> connection_items;
|
||||
QMap<QString, QPointer<DivingMapPixmapItem>> diving_map_items;
|
||||
QGraphicsPathItem *connection_mask = nullptr;
|
||||
@@ -134,6 +134,8 @@ public:
|
||||
QPointer<MovementPermissionsSelector> movement_permissions_selector_item = nullptr;
|
||||
|
||||
QList<DraggablePixmapItem *> *selected_events = nullptr;
|
||||
QPointer<ConnectionPixmapItem> selected_connection_item = nullptr;
|
||||
QPointer<MapConnection> connection_to_select = nullptr;
|
||||
|
||||
QString map_edit_mode = "paint";
|
||||
QString obj_edit_mode = "select";
|
||||
@@ -183,10 +185,9 @@ private:
|
||||
void clearMapGrid();
|
||||
void clearWildMonTables();
|
||||
void updateBorderVisibility();
|
||||
QPoint calculateConnectionPosition(MapConnection *connection, const QPixmap &pixmap);
|
||||
QPoint getConnectionOrigin(MapConnection *connection);
|
||||
void removeConnectionPixmap(MapConnection* connection);
|
||||
void updateConnectionPixmap(ConnectionPixmapItem* connectionItem);
|
||||
void updateConnectionPixmapPos(ConnectionPixmapItem* connectionItem);
|
||||
void displayConnection(MapConnection* connection);
|
||||
void displayDivingConnection(MapConnection* connection);
|
||||
void setDivingMapName(QString mapName, QString direction);
|
||||
|
||||
@@ -9,36 +9,37 @@
|
||||
class ConnectionPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ConnectionPixmapItem(QPixmap pixmap, MapConnection* connection, int x, int y)
|
||||
: QGraphicsPixmapItem(pixmap)
|
||||
{
|
||||
this->basePixmap = pixmap;
|
||||
this->connection = connection;
|
||||
setFlag(ItemIsMovable);
|
||||
setFlag(ItemSendsGeometryChanges);
|
||||
this->initialX = x;
|
||||
this->initialY = y;
|
||||
this->initialOffset = connection->offset();
|
||||
this->setPos(x, y);
|
||||
}
|
||||
QPixmap basePixmap;
|
||||
QPointer<MapConnection> connection;
|
||||
int initialX;
|
||||
int initialY;
|
||||
int initialOffset;
|
||||
ConnectionPixmapItem(MapConnection* connection, int originX, int originY);
|
||||
ConnectionPixmapItem(MapConnection* connection, QPoint origin);
|
||||
|
||||
const QPointer<MapConnection> connection;
|
||||
|
||||
void setOrigin(int x, int y);
|
||||
void setOrigin(QPoint pos);
|
||||
|
||||
void setEditable(bool editable);
|
||||
bool getEditable();
|
||||
|
||||
void setSelected(bool selected);
|
||||
void render();
|
||||
|
||||
void updatePos();
|
||||
void render(bool ignoreCache = false);
|
||||
|
||||
private:
|
||||
QPixmap basePixmap;
|
||||
qreal originX;
|
||||
qreal originY;
|
||||
bool selected = false;
|
||||
unsigned actionId = 0;
|
||||
|
||||
static const int mWidth = 16;
|
||||
static const int mHeight = 16;
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*) override;
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
|
||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) override;
|
||||
|
||||
signals:
|
||||
void connectionItemDoubleClicked(MapConnection*);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define CONNECTIONSLISTITEM_H
|
||||
|
||||
#include "mapconnection.h"
|
||||
#include "map.h"
|
||||
|
||||
#include <QFrame>
|
||||
#include <QMouseEvent>
|
||||
@@ -30,11 +31,13 @@ public:
|
||||
|
||||
private:
|
||||
Ui::ConnectionsListItem *ui;
|
||||
Map *map;
|
||||
bool isSelected = false;
|
||||
unsigned actionId = 0;
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void mouseDoubleClickEvent(QMouseEvent *);
|
||||
void mousePressEvent(QMouseEvent*) override;
|
||||
void mouseDoubleClickEvent(QMouseEvent*) override;
|
||||
|
||||
signals:
|
||||
void removed(MapConnection*);
|
||||
|
||||
@@ -5,30 +5,26 @@
|
||||
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QPointer>
|
||||
#include <QComboBox>
|
||||
|
||||
class DivingMapPixmapItem : public QObject, public QGraphicsPixmapItem {
|
||||
Q_OBJECT
|
||||
public:
|
||||
DivingMapPixmapItem(MapConnection* connection)
|
||||
: QGraphicsPixmapItem(getBasePixmap(connection))
|
||||
{
|
||||
m_connection = connection;
|
||||
DivingMapPixmapItem(MapConnection *connection, QComboBox *combo);
|
||||
~DivingMapPixmapItem();
|
||||
|
||||
// Update pixmap if the connected map is swapped.
|
||||
connect(m_connection, &MapConnection::targetMapNameChanged, this, &DivingMapPixmapItem::updatePixmap);
|
||||
}
|
||||
MapConnection* connection() const { return m_connection; }
|
||||
void updatePixmap();
|
||||
|
||||
private:
|
||||
QPointer<MapConnection> m_connection;
|
||||
QPointer<QComboBox> m_combo;
|
||||
|
||||
static QPixmap getBasePixmap(MapConnection* connection) {
|
||||
// If the map is connected to itself then rendering is pointless.
|
||||
if (!connection || connection->targetMapName() == connection->parentMapName())
|
||||
return QPixmap();
|
||||
return connection->getPixmap();
|
||||
}
|
||||
void updatePixmap() { setPixmap(getBasePixmap(m_connection)); }
|
||||
void setComboText(const QString &text);
|
||||
static QPixmap getBasePixmap(MapConnection* connection);
|
||||
|
||||
private slots:
|
||||
void onTargetMapChanged();
|
||||
};
|
||||
|
||||
#endif // DIVINGMAPPIXMAPITEM_H
|
||||
|
||||
@@ -17,10 +17,11 @@ public:
|
||||
explicit NewMapConnectionDialog(QWidget *parent, Map* map, const QStringList &mapNames);
|
||||
~NewMapConnectionDialog();
|
||||
|
||||
MapConnection *result;
|
||||
|
||||
virtual void accept() override;
|
||||
|
||||
signals:
|
||||
void accepted(MapConnection *result);
|
||||
|
||||
private:
|
||||
Ui::NewMapConnectionDialog *ui;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user