Fix closing tileset editor not closing palette editor

This commit is contained in:
BigBahss 2020-09-25 08:12:13 -04:00 committed by huderlem
parent 7cbdea4e26
commit e4095130c5
8 changed files with 70 additions and 26 deletions

View file

@ -45,6 +45,7 @@ private:
void refreshColor(int);
void setColor(int);
void commitEditHistory(int paletteid);
void restoreWindowState();
void setColorsFromHistory(PaletteHistoryItem*, int);
void closeEvent(QCloseEvent*);

View file

@ -97,6 +97,7 @@ private:
bool createCityMap(QString name);
bool tryInsertNewMapEntry(QString);
void restoreWindowState();
void closeEvent(QCloseEvent* event);
private slots:

View file

@ -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;

View file

@ -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<QString, QByteArray> 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<QString, QByteArray> 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()) {

View file

@ -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();

View file

@ -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<QString, QByteArray> 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();

View file

@ -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<QString, QByteArray> 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) {

View file

@ -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<QString, QByteArray> 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<QString, QByteArray> geometry = porymapConfig.getPaletteEditorGeometry();
this->paletteEditor->restoreGeometry(geometry.value("palette_editor_geometry"));
this->paletteEditor->restoreState(geometry.value("palette_editor_state"));
}
if (!this->paletteEditor->isVisible()) {