mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-28 03:25:30 -05:00
fix the scripting api and many other changes
- remove obsolete Map::commit() - add ScriptEditMap command - reorganize metatile history - fix next selected event for multi event deletion
This commit is contained in:
@@ -12,22 +12,22 @@ class DraggablePixmapItem;
|
||||
class Editor;
|
||||
|
||||
enum CommandId {
|
||||
ID_PaintMetatile, // - done
|
||||
ID_BucketFillMetatile, // - done
|
||||
ID_MagicFillMetatile, // - done
|
||||
ID_ShiftMetatiles, // - done
|
||||
ID_PaintCollision, // -
|
||||
ID_BucketFillCollision, // -
|
||||
ID_MagicFillCollision, // -
|
||||
ID_ResizeMap, // - done
|
||||
ID_PaintBorder, // - done
|
||||
ID_EventMove, // - done
|
||||
ID_EventShift, // - done
|
||||
ID_EventCreate, // - done
|
||||
ID_EventDelete, // - done
|
||||
ID_EventDuplicate, // - done
|
||||
ID_EventSetData, // - ?
|
||||
// Region map editor history commands
|
||||
ID_PaintMetatile,
|
||||
ID_BucketFillMetatile,
|
||||
ID_MagicFillMetatile,
|
||||
ID_ShiftMetatiles,
|
||||
ID_PaintCollision,
|
||||
ID_BucketFillCollision,
|
||||
ID_MagicFillCollision,
|
||||
ID_ResizeMap,
|
||||
ID_PaintBorder,
|
||||
ID_EventMove,
|
||||
ID_EventShift,
|
||||
ID_EventCreate,
|
||||
ID_EventDelete,
|
||||
ID_EventDuplicate,
|
||||
ID_EventSetData,
|
||||
ID_ScriptEditMap,
|
||||
};
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ public:
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; };
|
||||
bool mergeWith(const QUndoCommand *) override { return false; };
|
||||
int id() const override { return CommandId::ID_PaintBorder; }
|
||||
|
||||
private:
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
unsigned actionId, QUndoCommand *parent = nullptr);
|
||||
~BucketFillMetatile();
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override { return CommandId::ID_BucketFillMetatile; }
|
||||
};
|
||||
|
||||
@@ -125,7 +125,7 @@ public:
|
||||
setText("Flood Fill Collision");
|
||||
}
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override { return CommandId::ID_BucketFillCollision; }
|
||||
};
|
||||
|
||||
@@ -140,7 +140,7 @@ public:
|
||||
unsigned actionId, QUndoCommand *parent = nullptr);
|
||||
~MagicFillMetatile();
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override { return CommandId::ID_BucketFillMetatile; }
|
||||
};
|
||||
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
setText("Magic Fill Collision");
|
||||
}
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override { return CommandId::ID_MagicFillCollision; }
|
||||
};
|
||||
|
||||
@@ -200,7 +200,7 @@ public:
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override { return CommandId::ID_ResizeMap; }
|
||||
|
||||
private:
|
||||
@@ -274,7 +274,7 @@ public:
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override { return CommandId::ID_EventCreate; }
|
||||
|
||||
private:
|
||||
@@ -297,7 +297,7 @@ public:
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override { return CommandId::ID_EventDelete; }
|
||||
|
||||
private:
|
||||
@@ -319,7 +319,7 @@ public:
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *command) override { return false; }
|
||||
bool mergeWith(const QUndoCommand *) override { return false; }
|
||||
int id() const override { return CommandId::ID_EventDuplicate; }
|
||||
|
||||
private:
|
||||
@@ -328,4 +328,34 @@ private:
|
||||
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:
|
||||
ScriptEditMap(Map *map,
|
||||
QSize oldMapDimensions, QSize newMapDimensions,
|
||||
Blockdata *oldMetatiles, Blockdata *newMetatiles,
|
||||
QUndoCommand *parent = nullptr);
|
||||
~ScriptEditMap();
|
||||
|
||||
void undo() override;
|
||||
void redo() override;
|
||||
|
||||
bool mergeWith(const QUndoCommand *) override { return false; };
|
||||
int id() const override { return CommandId::ID_ScriptEditMap; }
|
||||
|
||||
private:
|
||||
Map *map;
|
||||
|
||||
Blockdata *newMetatiles;
|
||||
Blockdata *oldMetatiles;
|
||||
|
||||
int oldMapWidth;
|
||||
int oldMapHeight;
|
||||
int newMapWidth;
|
||||
int newMapHeight;
|
||||
};
|
||||
|
||||
#endif // EDITCOMMANDS_H
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef HISTORYITEM_H
|
||||
#define HISTORYITEM_H
|
||||
|
||||
#include "blockdata.h"
|
||||
|
||||
class HistoryItem {
|
||||
public:
|
||||
Blockdata *metatiles;
|
||||
Blockdata *border;
|
||||
int layoutWidth;
|
||||
int layoutHeight;
|
||||
int borderWidth;
|
||||
int borderHeight;
|
||||
HistoryItem(Blockdata *metatiles, Blockdata *border, int layoutWidth, int layoutHeight, int borderWidth, int borderHeight);
|
||||
~HistoryItem();
|
||||
};
|
||||
|
||||
enum RegionMapEditorBox {
|
||||
BackgroundImage = 1,
|
||||
CityMapImage = 2,
|
||||
};
|
||||
|
||||
class RegionMapHistoryItem {
|
||||
public:
|
||||
int which;
|
||||
int mapWidth = 0;
|
||||
int mapHeight = 0;
|
||||
QVector<uint8_t> tiles;
|
||||
QString cityMap;
|
||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, QString cityMap);
|
||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, int width, int height);
|
||||
~RegionMapHistoryItem();
|
||||
};
|
||||
|
||||
#endif // HISTORYITEM_H
|
||||
@@ -2,8 +2,6 @@
|
||||
#define MAP_H
|
||||
|
||||
#include "blockdata.h"
|
||||
#include "history.h"
|
||||
#include "historyitem.h"
|
||||
#include "mapconnection.h"
|
||||
#include "maplayout.h"
|
||||
#include "tileset.h"
|
||||
@@ -59,7 +57,6 @@ public:
|
||||
QPixmap collision_pixmap;
|
||||
QImage image;
|
||||
QPixmap pixmap;
|
||||
History<HistoryItem*> metatileHistory;
|
||||
QMap<QString, QList<Event*>> events;
|
||||
QList<MapConnection*> connections;
|
||||
QList<int> metatileLayerOrder;
|
||||
@@ -104,8 +101,6 @@ public:
|
||||
BorderMetatilesPixmapItem *borderItem = nullptr;
|
||||
void setBorderItem(BorderMetatilesPixmapItem *item) { borderItem = item; }
|
||||
|
||||
void commit(); // TODO: delete this
|
||||
|
||||
QUndoStack editHistory;
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,6 +30,10 @@ public:
|
||||
Blockdata *cached_blockdata = nullptr;
|
||||
Blockdata *cached_collision = nullptr;
|
||||
Blockdata *cached_border = nullptr;
|
||||
struct {
|
||||
Blockdata *blocks = nullptr;
|
||||
QSize dimensions;
|
||||
} lastCommitMapBlocks; // to track map changes
|
||||
};
|
||||
|
||||
#endif // MAPLAYOUT_H
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "project.h"
|
||||
#include "tilemaptileselector.h"
|
||||
#include "history.h"
|
||||
#include "historyitem.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
@@ -15,6 +14,32 @@
|
||||
#include <QGraphicsScene>
|
||||
#include <QGraphicsView>
|
||||
|
||||
enum RegionMapEditorBox {
|
||||
BackgroundImage = 1,
|
||||
CityMapImage = 2,
|
||||
};
|
||||
|
||||
class RegionMapHistoryItem {
|
||||
public:
|
||||
int which;
|
||||
int mapWidth = 0;
|
||||
int mapHeight = 0;
|
||||
QVector<uint8_t> tiles;
|
||||
QString cityMap;
|
||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, QString cityMap) {
|
||||
this->which = which;
|
||||
this->tiles = tiles;
|
||||
this->cityMap = cityMap;
|
||||
}
|
||||
RegionMapHistoryItem(int type, QVector<uint8_t> tiles, int width, int height) {
|
||||
this->which = which;
|
||||
this->tiles = tiles;
|
||||
this->mapWidth = width;
|
||||
this->mapHeight = height;
|
||||
}
|
||||
~RegionMapHistoryItem() {}
|
||||
};
|
||||
|
||||
class RegionMapEntry
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||
virtual void select(QGraphicsSceneMouseEvent*);
|
||||
virtual void shift(QGraphicsSceneMouseEvent*);
|
||||
void shift(int xDelta, int yDelta);
|
||||
void shift(int xDelta, int yDelta, bool fromScriptCall = false);
|
||||
virtual void draw(bool ignoreCache = false);
|
||||
void updateMetatileSelection(QGraphicsSceneMouseEvent *event);
|
||||
void paintNormal(int x, int y, bool fromScriptCall = false);
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
#include "regionmaplayoutpixmapitem.h"
|
||||
#include "regionmapentriespixmapitem.h"
|
||||
#include "regionmap.h"
|
||||
#include "history.h"
|
||||
#include "historyitem.h"
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
|
||||
Reference in New Issue
Block a user