create edit history for region map tilemap and layout

This commit is contained in:
garak
2022-04-26 17:02:03 -04:00
committed by garakmon
parent 43ebeb1662
commit 2b152ce64e
9 changed files with 152 additions and 176 deletions

View File

@@ -19,32 +19,6 @@ using std::shared_ptr;
class Project;
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 which, QVector<uint8_t> tiles, QString cityMap) {
this->which = which;
this->tiles = tiles;
this->cityMap = cityMap;
}
RegionMapHistoryItem(int which, QVector<uint8_t> tiles, int width, int height) {
this->which = which;
this->tiles = tiles;
this->mapWidth = width;
this->mapHeight = height;
}
~RegionMapHistoryItem() {}
};
struct LayoutSquare
{
QString map_section;
@@ -69,9 +43,9 @@ public:
RegionMap() = delete;
RegionMap(Project *);
Project *project = nullptr;
~RegionMap() {}
History<RegionMapHistoryItem*> history; // TODO
Project *project = nullptr;
bool loadMapData(poryjson::Json);
bool loadTilemap(poryjson::Json);
@@ -121,6 +95,9 @@ public:
QByteArray getTilemap();
void setTilemap(QByteArray newTilemap);
QList<LayoutSquare> getLayout(QString layer);
void setLayout(QString layer, QList<LayoutSquare> layout);
QStringList getLayers() { return this->layout_layers; }
void setLayer(QString layer) { this->current_layer = layer; }
QString getLayer() { return this->current_layer; }
@@ -146,6 +123,12 @@ public:
QString fullPath(QString local);
void commit(QUndoCommand *command);
QUndoStack editHistory;
void undo();
void redo();
private:
// TODO: defaults needed?
tsl::ordered_map<QString, MapSectionEntry> *region_map_entries = nullptr;

View File

@@ -45,9 +45,6 @@ public:
void onRegionMapEntriesSelectedTileChanged(QString) {};
void onRegionMapEntryDragged(int, int);
void undo();
void redo();
void resize(int width, int height);
QObjectList shortcutableObjects() const;
@@ -61,7 +58,7 @@ private:
poryjson::Json rmConfigJson;
History<RegionMapHistoryItem*> history;
QUndoGroup history;
int currIndex = 0;
unsigned selectedCityTile;
@@ -124,8 +121,6 @@ private:
private slots:
void on_action_RegionMap_Save_triggered();
void on_action_RegionMap_Undo_triggered();
void on_action_RegionMap_Redo_triggered();
void on_action_RegionMap_Resize_triggered();
void on_action_RegionMap_ClearImage_triggered();
void on_action_RegionMap_ClearLayout_triggered();

View File

@@ -123,7 +123,9 @@ public:
this->tileset = QImage(tilesetFilepath);
this->format = format;
bool err;
this->palette = PaletteUtil::parse(palFilepath, &err);
if (!palFilepath.isEmpty()) {
this->palette = PaletteUtil::parse(palFilepath, &err);
}
this->setPixmap(QPixmap::fromImage(this->tileset));
this->numTilesWide = this->tileset.width() / 8;
this->selectedTile = 0x00;