Ask user about unsaved changes when closing tileset editor window
This commit is contained in:
parent
da13b8ea5e
commit
cf150f3ce9
4 changed files with 51 additions and 7 deletions
|
@ -94,6 +94,7 @@ private slots:
|
||||||
void onAddNewMapToGroupClick(QAction* triggeredAction);
|
void onAddNewMapToGroupClick(QAction* triggeredAction);
|
||||||
void onTilesetChanged(QString);
|
void onTilesetChanged(QString);
|
||||||
void currentMetatilesSelectionChanged();
|
void currentMetatilesSelectionChanged();
|
||||||
|
void onTilesetEditorClosed();
|
||||||
|
|
||||||
void on_action_Export_Map_Image_triggered();
|
void on_action_Export_Map_Image_triggered();
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ public:
|
||||||
explicit TilesetEditor(Project*, QString, QString, QWidget *parent = nullptr);
|
explicit TilesetEditor(Project*, QString, QString, QWidget *parent = nullptr);
|
||||||
~TilesetEditor();
|
~TilesetEditor();
|
||||||
void setTilesets(QString, QString);
|
void setTilesets(QString, QString);
|
||||||
|
void init(Project*, QString, QString);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onHoveredMetatileChanged(uint16_t);
|
void onHoveredMetatileChanged(uint16_t);
|
||||||
|
@ -46,6 +47,7 @@ private slots:
|
||||||
void on_actionImport_Secondary_Tiles_triggered();
|
void on_actionImport_Secondary_Tiles_triggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void closeEvent(QCloseEvent*);
|
||||||
void initMetatileSelector();
|
void initMetatileSelector();
|
||||||
void initTileSelector();
|
void initTileSelector();
|
||||||
void initSelectedTileItem();
|
void initSelectedTileItem();
|
||||||
|
@ -62,8 +64,9 @@ private:
|
||||||
int paletteId;
|
int paletteId;
|
||||||
bool tileXFlip;
|
bool tileXFlip;
|
||||||
bool tileYFlip;
|
bool tileYFlip;
|
||||||
Tileset *primaryTileset;
|
bool hasUnsavedChanges;
|
||||||
Tileset *secondaryTileset;
|
Tileset *primaryTileset = nullptr;
|
||||||
|
Tileset *secondaryTileset = nullptr;
|
||||||
QGraphicsScene *metatilesScene = nullptr;
|
QGraphicsScene *metatilesScene = nullptr;
|
||||||
QGraphicsScene *tilesScene = nullptr;
|
QGraphicsScene *tilesScene = nullptr;
|
||||||
QGraphicsScene *selectedTileScene = nullptr;
|
QGraphicsScene *selectedTileScene = nullptr;
|
||||||
|
@ -72,6 +75,7 @@ private:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void tilesetsSaved(QString, QString);
|
void tilesetsSaved(QString, QString);
|
||||||
|
void closed();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TILESETEDITOR_H
|
#endif // TILESETEDITOR_H
|
||||||
|
|
|
@ -1246,11 +1246,21 @@ void MainWindow::on_actionTileset_Editor_triggered()
|
||||||
if (!this->tilesetEditor) {
|
if (!this->tilesetEditor) {
|
||||||
this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label, this);
|
this->tilesetEditor = new TilesetEditor(this->editor->project, this->editor->map->layout->tileset_primary_label, this->editor->map->layout->tileset_secondary_label, this);
|
||||||
connect(this->tilesetEditor, SIGNAL(tilesetsSaved(QString, QString)), this, SLOT(onTilesetsSaved(QString, QString)));
|
connect(this->tilesetEditor, SIGNAL(tilesetsSaved(QString, QString)), this, SLOT(onTilesetsSaved(QString, QString)));
|
||||||
|
connect(this->tilesetEditor, SIGNAL(closed()), this, SLOT(onTilesetEditorClosed()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this->tilesetEditor->isVisible()) {
|
if (!this->tilesetEditor->isVisible()) {
|
||||||
this->tilesetEditor->show();
|
this->tilesetEditor->show();
|
||||||
|
} else if (this->tilesetEditor->isMinimized()) {
|
||||||
|
this->tilesetEditor->showNormal();
|
||||||
} else {
|
} else {
|
||||||
this->tilesetEditor->activateWindow();
|
this->tilesetEditor->activateWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onTilesetEditorClosed() {
|
||||||
|
if (this->tilesetEditor) {
|
||||||
|
delete this->tilesetEditor;
|
||||||
|
this->tilesetEditor = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,15 +9,27 @@ TilesetEditor::TilesetEditor(Project *project, QString primaryTilesetLabel, QStr
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::TilesetEditor)
|
ui(new Ui::TilesetEditor)
|
||||||
{
|
{
|
||||||
|
this->init(project, primaryTilesetLabel, secondaryTilesetLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
TilesetEditor::~TilesetEditor()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TilesetEditor::init(Project *project, QString primaryTilesetLabel, QString secondaryTilesetLabel) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->project = project;
|
this->project = project;
|
||||||
|
|
||||||
|
this->hasUnsavedChanges = false;
|
||||||
this->tileXFlip = ui->checkBox_xFlip->isChecked();
|
this->tileXFlip = ui->checkBox_xFlip->isChecked();
|
||||||
this->tileYFlip = ui->checkBox_yFlip->isChecked();
|
this->tileYFlip = ui->checkBox_yFlip->isChecked();
|
||||||
this->paletteId = ui->spinBox_paletteSelector->value();
|
this->paletteId = ui->spinBox_paletteSelector->value();
|
||||||
|
|
||||||
Tileset *primaryTileset = project->getTileset(primaryTilesetLabel);
|
Tileset *primaryTileset = project->getTileset(primaryTilesetLabel);
|
||||||
Tileset *secondaryTileset = project->getTileset(secondaryTilesetLabel);
|
Tileset *secondaryTileset = project->getTileset(secondaryTilesetLabel);
|
||||||
|
if (this->primaryTileset) delete this->primaryTileset;
|
||||||
|
if (this->secondaryTileset) delete this->secondaryTileset;
|
||||||
this->primaryTileset = primaryTileset->copy();
|
this->primaryTileset = primaryTileset->copy();
|
||||||
this->secondaryTileset = secondaryTileset->copy();
|
this->secondaryTileset = secondaryTileset->copy();
|
||||||
|
|
||||||
|
@ -38,11 +50,6 @@ TilesetEditor::TilesetEditor(Project *project, QString primaryTilesetLabel, QStr
|
||||||
this->metatileSelector->select(0);
|
this->metatileSelector->select(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TilesetEditor::~TilesetEditor()
|
|
||||||
{
|
|
||||||
delete ui;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) {
|
void TilesetEditor::setTilesets(QString primaryTilesetLabel, QString secondaryTilesetLabel) {
|
||||||
delete this->primaryTileset;
|
delete this->primaryTileset;
|
||||||
delete this->secondaryTileset;
|
delete this->secondaryTileset;
|
||||||
|
@ -202,6 +209,7 @@ void TilesetEditor::onMetatileLayerTileChanged(int x, int y) {
|
||||||
|
|
||||||
this->metatileSelector->draw();
|
this->metatileSelector->draw();
|
||||||
this->metatileLayersItem->draw();
|
this->metatileLayersItem->draw();
|
||||||
|
this->hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilesetEditor::on_spinBox_paletteSelector_valueChanged(int paletteId)
|
void TilesetEditor::on_spinBox_paletteSelector_valueChanged(int paletteId)
|
||||||
|
@ -245,6 +253,7 @@ void TilesetEditor::on_actionSave_Tileset_triggered()
|
||||||
this->project->saveTilesets(this->primaryTileset, this->secondaryTileset);
|
this->project->saveTilesets(this->primaryTileset, this->secondaryTileset);
|
||||||
emit this->tilesetsSaved(this->primaryTileset->name, this->secondaryTileset->name);
|
emit this->tilesetsSaved(this->primaryTileset->name, this->secondaryTileset->name);
|
||||||
this->ui->statusbar->showMessage(QString("Saved primary and secondary Tilesets!"), 5000);
|
this->ui->statusbar->showMessage(QString("Saved primary and secondary Tilesets!"), 5000);
|
||||||
|
this->hasUnsavedChanges = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TilesetEditor::on_actionImport_Primary_Tiles_triggered()
|
void TilesetEditor::on_actionImport_Primary_Tiles_triggered()
|
||||||
|
@ -319,4 +328,24 @@ void TilesetEditor::importTilesetTiles(Tileset *tileset, bool primary) {
|
||||||
this->project->loadTilesetTiles(tileset, image);
|
this->project->loadTilesetTiles(tileset, image);
|
||||||
this->project->loadTilesetMetatiles(tileset);
|
this->project->loadTilesetMetatiles(tileset);
|
||||||
this->refresh();
|
this->refresh();
|
||||||
|
this->hasUnsavedChanges = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TilesetEditor::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
bool close = true;
|
||||||
|
if (this->hasUnsavedChanges) {
|
||||||
|
QMessageBox::StandardButton result = QMessageBox::question(this, "porymap",
|
||||||
|
"Discard unsaved Tileset changes?",
|
||||||
|
QMessageBox::No | QMessageBox::Yes,
|
||||||
|
QMessageBox::Yes);
|
||||||
|
close = result == QMessageBox::Yes;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (close) {
|
||||||
|
event->accept();
|
||||||
|
emit closed();
|
||||||
|
} else {
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue