Reset Tileset Editor history when tileset changes

This commit is contained in:
GriffinR 2023-02-17 22:27:02 -05:00
parent f8bc65ad3f
commit 26f07add79
2 changed files with 10 additions and 4 deletions

View file

@ -10,9 +10,15 @@ public:
History() { } History() { }
~History() { ~History() {
clear();
}
void clear() {
while (!history.isEmpty()) { while (!history.isEmpty()) {
delete history.takeLast(); delete history.takeLast();
} }
head = -1;
saved = -1;
} }
T back() { T back() {

View file

@ -22,7 +22,6 @@ TilesetEditor::TilesetEditor(Project *project, Map *map, QWidget *parent) :
{ {
this->setTilesets(this->map->layout->tileset_primary_label, this->map->layout->tileset_secondary_label); this->setTilesets(this->map->layout->tileset_primary_label, this->map->layout->tileset_secondary_label);
this->initUi(); this->initUi();
this->initMetatileHistory();
} }
TilesetEditor::~TilesetEditor() TilesetEditor::~TilesetEditor()
@ -64,7 +63,6 @@ void TilesetEditor::updateTilesets(QString primaryTilesetLabel, QString secondar
if (result == QMessageBox::Yes) if (result == QMessageBox::Yes)
this->on_actionSave_Tileset_triggered(); this->on_actionSave_Tileset_triggered();
} }
this->hasUnsavedChanges = false;
this->setTilesets(primaryTilesetLabel, secondaryTilesetLabel); this->setTilesets(primaryTilesetLabel, secondaryTilesetLabel);
this->refresh(); this->refresh();
} }
@ -89,6 +87,7 @@ void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTi
this->primaryTileset = new Tileset(*primaryTileset); this->primaryTileset = new Tileset(*primaryTileset);
this->secondaryTileset = new Tileset(*secondaryTileset); this->secondaryTileset = new Tileset(*secondaryTileset);
if (paletteEditor) paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset); if (paletteEditor) paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset);
this->initMetatileHistory();
} }
void TilesetEditor::initUi() { void TilesetEditor::initUi() {
@ -276,12 +275,13 @@ void TilesetEditor::restoreWindowState() {
} }
void TilesetEditor::initMetatileHistory() { void TilesetEditor::initMetatileHistory() {
MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, new Metatile(*metatile), QString(), QString()); metatileHistory.clear();
MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, new Metatile(), QString(), QString());
metatileHistory.push(commit); metatileHistory.push(commit);
this->hasUnsavedChanges = false;
} }
void TilesetEditor::reset() { void TilesetEditor::reset() {
this->hasUnsavedChanges = false;
this->setTilesets(this->primaryTileset->name, this->secondaryTileset->name); this->setTilesets(this->primaryTileset->name, this->secondaryTileset->name);
if (this->paletteEditor) if (this->paletteEditor)
this->paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset); this->paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset);