diff --git a/include/ui/paletteeditor.h b/include/ui/paletteeditor.h index 9bf58062..2dbd6d29 100644 --- a/include/ui/paletteeditor.h +++ b/include/ui/paletteeditor.h @@ -45,6 +45,7 @@ private: void refreshColor(int); void setColor(int); void commitEditHistory(int paletteid); + void restoreWindowState(); void setColorsFromHistory(PaletteHistoryItem*, int); void closeEvent(QCloseEvent*); diff --git a/include/ui/regionmapeditor.h b/include/ui/regionmapeditor.h index a664df77..484103f3 100644 --- a/include/ui/regionmapeditor.h +++ b/include/ui/regionmapeditor.h @@ -97,6 +97,7 @@ private: bool createCityMap(QString name); bool tryInsertNewMapEntry(QString); + void restoreWindowState(); void closeEvent(QCloseEvent* event); private slots: diff --git a/include/ui/tileseteditor.h b/include/ui/tileseteditor.h index fde5a4be..a3aa4589 100644 --- a/include/ui/tileseteditor.h +++ b/include/ui/tileseteditor.h @@ -37,8 +37,9 @@ class TilesetEditor : public QMainWindow public: explicit TilesetEditor(Project*, Map*, QWidget *parent = nullptr); ~TilesetEditor(); - void setMap(Map*); - void setTilesets(QString, QString); + void update(Map *map, QString primaryTilsetLabel, QString secondaryTilesetLabel); + void updateMap(Map *map); + void updateTilesets(QString primaryTilsetLabel, QString secondaryTilesetLabel); bool selectMetatile(uint16_t metatileId); private slots: @@ -98,6 +99,9 @@ private: void initTileSelector(); void initSelectedTileItem(); void initMetatileLayersItem(); + void restoreWindowState(); + void setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel); + void reset(); void drawSelectedTiles(); void importTilesetTiles(Tileset*, bool); void importTilesetMetatiles(Tileset*, bool); @@ -110,6 +114,7 @@ private: MetatileLayersItem *metatileLayersItem = nullptr; PaletteEditor *paletteEditor = nullptr; Project *project = nullptr; + Map *map = nullptr; Metatile *metatile = nullptr; int paletteId; bool tileXFlip; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0e77fffc..8ef1e5af 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1206,8 +1206,11 @@ void MainWindow::on_actionNew_Tileset_triggered() { void MainWindow::updateTilesetEditor() { if (this->tilesetEditor) { - this->tilesetEditor->setMap(this->editor->map); - this->tilesetEditor->setTilesets(editor->ui->comboBox_PrimaryTileset->currentText(), editor->ui->comboBox_SecondaryTileset->currentText()); + this->tilesetEditor->update( + this->editor->map, + editor->ui->comboBox_PrimaryTileset->currentText(), + editor->ui->comboBox_SecondaryTileset->currentText() + ); } } @@ -2518,10 +2521,6 @@ void MainWindow::on_actionTileset_Editor_triggered() this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->map, this); connect(this->tilesetEditor, SIGNAL(tilesetsSaved(QString, QString)), this, SLOT(onTilesetsSaved(QString, QString))); connect(this->tilesetEditor, &QObject::destroyed, [=](QObject *) { this->tilesetEditor = nullptr; }); - logInfo("Restoring tileset editor geometry from previous session."); - QMap geometry = porymapConfig.getTilesetEditorGeometry(); - this->tilesetEditor->restoreGeometry(geometry.value("tileset_editor_geometry")); - this->tilesetEditor->restoreState(geometry.value("tileset_editor_state")); } if (!this->tilesetEditor->isVisible()) { @@ -2661,10 +2660,6 @@ void MainWindow::on_actionRegion_Map_Editor_triggered() { return; } connect(this->regionMapEditor, &QObject::destroyed, [=](QObject *) { this->regionMapEditor = nullptr; }); - logInfo("Restoring region map editor geometry from previous session."); - QMap geometry = porymapConfig.getRegionMapEditorGeometry(); - this->regionMapEditor->restoreGeometry(geometry.value("region_map_editor_geometry")); - this->regionMapEditor->restoreState(geometry.value("region_map_editor_state")); } if (!this->regionMapEditor->isVisible()) { diff --git a/src/mainwindow_scriptapi.cpp b/src/mainwindow_scriptapi.cpp index cc89fc0b..b60ba820 100644 --- a/src/mainwindow_scriptapi.cpp +++ b/src/mainwindow_scriptapi.cpp @@ -247,7 +247,7 @@ void MainWindow::addImage(int x, int y, QString filepath) { void MainWindow::refreshAfterPaletteChange(Tileset *tileset) { if (this->tilesetEditor) { - this->tilesetEditor->setTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label); + this->tilesetEditor->updateTilesets(this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label); } this->editor->metatile_selector_item->draw(); this->editor->selected_border_metatiles_item->draw(); diff --git a/src/ui/paletteeditor.cpp b/src/ui/paletteeditor.cpp index c24aad6a..0e1366e6 100644 --- a/src/ui/paletteeditor.cpp +++ b/src/ui/paletteeditor.cpp @@ -113,6 +113,7 @@ PaletteEditor::PaletteEditor(Project *project, Tileset *primaryTileset, Tileset this->initColorSliders(); this->setPaletteId(paletteId); this->commitEditHistory(this->ui->spinBox_PaletteId->value()); + this->restoreWindowState(); } PaletteEditor::~PaletteEditor() @@ -228,6 +229,13 @@ void PaletteEditor::commitEditHistory(int paletteId) { this->palettesHistory[paletteId].push(commit); } +void PaletteEditor::restoreWindowState() { + logInfo("Restoring palette editor geometry from previous session."); + QMap geometry = porymapConfig.getPaletteEditorGeometry(); + this->restoreGeometry(geometry.value("palette_editor_geometry")); + this->restoreState(geometry.value("palette_editor_state")); +} + void PaletteEditor::on_actionUndo_triggered() { int paletteId = this->ui->spinBox_PaletteId->value(); diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index b6d9030b..ce3440dd 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -24,6 +24,7 @@ RegionMapEditor::RegionMapEditor(QWidget *parent, Project *project_) : this->project = project_; this->region_map = new RegionMap; this->ui->action_RegionMap_Resize->setVisible(false); + this->restoreWindowState(); } RegionMapEditor::~RegionMapEditor() @@ -42,6 +43,13 @@ RegionMapEditor::~RegionMapEditor() delete scene_region_map_tiles; } +void RegionMapEditor::restoreWindowState() { + logInfo("Restoring region map editor geometry from previous session."); + QMap geometry = porymapConfig.getRegionMapEditorGeometry(); + this->restoreGeometry(geometry.value("region_map_editor_geometry")); + this->restoreState(geometry.value("region_map_editor_state")); +} + void RegionMapEditor::on_action_RegionMap_Save_triggered() { setCurrentSquareOptions(); if (project && region_map) { diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 580ad4cc..af5da658 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -100,6 +100,7 @@ void TilesetEditor::init(Project *project, Map *map) { this->initTileSelector(); this->initSelectedTileItem(); this->metatileSelector->select(0); + this->restoreWindowState(); MetatileHistoryItem *commit = new MetatileHistoryItem(0, nullptr, this->metatile->copy()); metatileHistory.push(commit); @@ -113,11 +114,17 @@ bool TilesetEditor::selectMetatile(uint16_t metatileId) { return true; } -void TilesetEditor::setMap(Map *map) { +void TilesetEditor::update(Map *map, QString primaryTilesetLabel, QString secondaryTilesetLabel) { + this->updateMap(map); + this->updateTilesets(primaryTilesetLabel, secondaryTilesetLabel); +} + +void TilesetEditor::updateMap(Map *map) { + this->map = map; this->metatileSelector->map = map; } -void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) { +void TilesetEditor::updateTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) { if (this->hasUnsavedChanges) { QMessageBox::StandardButton result = QMessageBox::question( this, @@ -129,13 +136,17 @@ void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTi this->on_actionSave_Tileset_triggered(); } this->hasUnsavedChanges = false; - delete this->primaryTileset; - delete this->secondaryTileset; + this->setTilesets(primaryTilesetLabel, secondaryTilesetLabel); + this->refresh(); +} + +void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) { Tileset *primaryTileset = project->getTileset(primaryTilesetLabel); Tileset *secondaryTileset = project->getTileset(secondaryTilesetLabel); + if (this->primaryTileset) delete this->primaryTileset; + if (this->secondaryTileset) delete this->secondaryTileset; this->primaryTileset = primaryTileset->copy(); this->secondaryTileset = secondaryTileset->copy(); - this->refresh(); } void TilesetEditor::refresh() { @@ -196,6 +207,21 @@ void TilesetEditor::initSelectedTileItem() { this->ui->graphicsView_selectedTile->setFixedSize(this->selectedTilePixmapItem->pixmap().width() + 2, this->selectedTilePixmapItem->pixmap().height() + 2); } +void TilesetEditor::restoreWindowState() { + logInfo("Restoring tileset editor geometry from previous session."); + QMap geometry = porymapConfig.getTilesetEditorGeometry(); + this->restoreGeometry(geometry.value("tileset_editor_geometry")); + this->restoreState(geometry.value("tileset_editor_state")); +} + +void TilesetEditor::reset() { + this->hasUnsavedChanges = false; + this->setTilesets(this->primaryTileset->name, this->secondaryTileset->name); + if (this->paletteEditor) + this->paletteEditor->setTilesets(this->primaryTileset, this->secondaryTileset); + this->refresh(); +} + void TilesetEditor::drawSelectedTiles() { if (!this->selectedTileScene) { return; @@ -599,6 +625,7 @@ void TilesetEditor::closeEvent(QCloseEvent *event) this->on_actionSave_Tileset_triggered(); event->accept(); } else if (result == QMessageBox::No) { + this->reset(); event->accept(); } else if (result == QMessageBox::Cancel) { event->ignore(); @@ -607,10 +634,13 @@ void TilesetEditor::closeEvent(QCloseEvent *event) event->accept(); } - porymapConfig.setTilesetEditorGeometry( - this->saveGeometry(), - this->saveState() - ); + if (event->isAccepted()) { + if (this->paletteEditor) this->paletteEditor->close(); + porymapConfig.setTilesetEditorGeometry( + this->saveGeometry(), + this->saveState() + ); + } } void TilesetEditor::on_actionChange_Metatiles_Count_triggered() @@ -694,10 +724,6 @@ void TilesetEditor::on_actionChange_Palettes_triggered() this->paletteEditor = new PaletteEditor(this->project, this->primaryTileset, this->secondaryTileset, this->paletteId, this); connect(this->paletteEditor, SIGNAL(changedPaletteColor()), this, SLOT(onPaletteEditorChangedPaletteColor())); connect(this->paletteEditor, SIGNAL(changedPalette(int)), this, SLOT(onPaletteEditorChangedPalette(int))); - logInfo("Restoring palette editor geometry from previous session."); - QMap geometry = porymapConfig.getPaletteEditorGeometry(); - this->paletteEditor->restoreGeometry(geometry.value("palette_editor_geometry")); - this->paletteEditor->restoreState(geometry.value("palette_editor_state")); } if (!this->paletteEditor->isVisible()) {