diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9ada39e7..602736a8 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2248,9 +2248,23 @@ void MainWindow::onMapCacheCleared() { } void MainWindow::onTilesetsSaved(QString primaryTilesetLabel, QString secondaryTilesetLabel) { - this->editor->updatePrimaryTileset(primaryTilesetLabel, true); - this->editor->updateSecondaryTileset(secondaryTilesetLabel, true); - redrawMapScene(); + // If saved tilesets are currently in-use, update them and redraw + // Otherwise overwrite the cache for the saved tileset + bool updated = false; + if (primaryTilesetLabel == this->editor->map->layout->tileset_primary_label) { + this->editor->updatePrimaryTileset(primaryTilesetLabel, true); + updated = true; + } else { + this->editor->project->getTileset(primaryTilesetLabel, true); + } + if (secondaryTilesetLabel == this->editor->map->layout->tileset_secondary_label) { + this->editor->updateSecondaryTileset(secondaryTilesetLabel, true); + updated = true; + } else { + this->editor->project->getTileset(secondaryTilesetLabel, true); + } + if (updated) + redrawMapScene(); } void MainWindow::onWildMonDataChanged() { diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index d0f6b5d1..3a9f33fd 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -116,6 +116,17 @@ void TilesetEditor::setMap(Map *map) { } void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) { + if (this->hasUnsavedChanges) { + QMessageBox::StandardButton result = QMessageBox::question( + this, + "porymap", + "Tileset has been modified, save changes?", + QMessageBox::No | QMessageBox::Yes, + QMessageBox::Yes); + if (result == QMessageBox::Yes) + this->on_actionSave_Tileset_triggered(); + } + this->hasUnsavedChanges = false; delete this->primaryTileset; delete this->secondaryTileset; Tileset *primaryTileset = project->getTileset(primaryTilesetLabel);