do not call initWindow() on failed load

This commit is contained in:
garakmon 2020-09-13 18:34:18 -04:00
parent 1b3bd9314d
commit d1af93f3b5
3 changed files with 34 additions and 27 deletions

View file

@ -51,7 +51,8 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#pragma once #ifndef ORDERED_JSON_H
#define ORDERED_JSON_H
#include <QString> #include <QString>
#include <QVector> #include <QVector>
@ -240,3 +241,4 @@ protected:
} // namespace poryjson } // namespace poryjson
#endif // ORDERED_JSON_H

View file

@ -262,6 +262,7 @@ private:
bool isProgrammaticEventTabChange; bool isProgrammaticEventTabChange;
bool projectHasUnsavedChanges; bool projectHasUnsavedChanges;
bool projectOpenFailure = false;
MapSortOrder mapSortOrder; MapSortOrder mapSortOrder;

View file

@ -58,10 +58,11 @@ MainWindow::MainWindow(QWidget *parent) :
this->initWindow(); this->initWindow();
if (!this->openRecentProject()) { if (!this->openRecentProject()) {
// Re-initialize everything to a blank slate if opening the recent project failed. setWindowDisabled(true);
this->initWindow(); } else {
setWindowDisabled(false);
on_toolButton_Paint_clicked();
} }
on_toolButton_Paint_clicked();
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -118,6 +119,7 @@ void MainWindow::initExtraShortcuts() {
void MainWindow::initCustomUI() { void MainWindow::initCustomUI() {
// Set up the tab bar // Set up the tab bar
while (ui->mainTabBar->count()) ui->mainTabBar->removeTab(0);
ui->mainTabBar->addTab("Map"); ui->mainTabBar->addTab("Map");
ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico"))); ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico")));
ui->mainTabBar->addTab("Events"); ui->mainTabBar->addTab("Events");
@ -125,12 +127,19 @@ void MainWindow::initCustomUI() {
ui->mainTabBar->addTab("Connections"); ui->mainTabBar->addTab("Connections");
ui->mainTabBar->addTab("Wild Pokemon"); ui->mainTabBar->addTab("Wild Pokemon");
ui->mainTabBar->setTabIcon(4, QIcon(QStringLiteral(":/icons/tall_grass.ico"))); ui->mainTabBar->setTabIcon(4, QIcon(QStringLiteral(":/icons/tall_grass.ico")));
}
void MainWindow::initExtraSignals() {
// Right-clicking on items in the map list tree view brings up a context menu. // Right-clicking on items in the map list tree view brings up a context menu.
ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu); ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)), connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(onOpenMapListContextMenu(const QPoint &))); this, SLOT(onOpenMapListContextMenu(const QPoint &)));
// other signals
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged);
// Change pages on wild encounter groups
QStackedWidget *stack = ui->stackedWidget_WildMons; QStackedWidget *stack = ui->stackedWidget_WildMons;
QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel; QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel;
connect(labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){ connect(labelCombo, QOverload<int>::of(&QComboBox::currentIndexChanged), [=](int index){
@ -151,11 +160,6 @@ void MainWindow::initCustomUI() {
ui->frame_mapTools->setLayout(flowLayout); ui->frame_mapTools->setLayout(flowLayout);
} }
void MainWindow::initExtraSignals() {
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
connect(ui->tabWidget_EventType, &QTabWidget::currentChanged, this, &MainWindow::eventTabChanged);
}
void MainWindow::initEditor() { void MainWindow::initEditor() {
this->editor = new Editor(ui); this->editor = new Editor(ui);
connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateObjects())); connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateObjects()));
@ -394,6 +398,7 @@ bool MainWindow::openRecentProject() {
bool MainWindow::openProject(QString dir) { bool MainWindow::openProject(QString dir) {
if (dir.isNull()) { if (dir.isNull()) {
projectOpenFailure = true;
return false; return false;
} }
@ -450,13 +455,12 @@ bool MainWindow::openProject(QString dir) {
Scripting::cb_ProjectOpened(dir); Scripting::cb_ProjectOpened(dir);
} }
setWindowDisabled(false); projectOpenFailure = !success;
return success; return success;
} }
bool MainWindow::isProjectOpen() { bool MainWindow::isProjectOpen() {
return editor != nullptr && editor->project != nullptr; return !projectOpenFailure && editor && editor->project;
} }
QString MainWindow::getDefaultMap() { QString MainWindow::getDefaultMap() {
@ -500,9 +504,7 @@ void MainWindow::on_action_Open_Project_triggered()
this->ui->graphicsView_Map->overlay.clearItems(); this->ui->graphicsView_Map->overlay.clearItems();
} }
porymapConfig.setRecentProject(dir); porymapConfig.setRecentProject(dir);
if (!openProject(dir)) { setWindowDisabled(!openProject(dir));
this->initWindow();
}
} }
} }
@ -2666,19 +2668,22 @@ void MainWindow::closeSupplementaryWindows() {
} }
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) { if (isProjectOpen()) {
QMessageBox::StandardButton result = QMessageBox::question( if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) {
this, "porymap", "The project has been modified, save changes?", QMessageBox::StandardButton result = QMessageBox::question(
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); this, "porymap", "The project has been modified, save changes?",
QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes);
if (result == QMessageBox::Yes) { if (result == QMessageBox::Yes) {
editor->saveProject(); editor->saveProject();
} else if (result == QMessageBox::No) { } else if (result == QMessageBox::No) {
logWarn("Closing porymap with unsaved changes."); logWarn("Closing porymap with unsaved changes.");
} else if (result == QMessageBox::Cancel) { } else if (result == QMessageBox::Cancel) {
event->ignore(); event->ignore();
return; return;
}
} }
projectConfig.save();
} }
porymapConfig.setMainGeometry( porymapConfig.setMainGeometry(
@ -2688,7 +2693,6 @@ void MainWindow::closeEvent(QCloseEvent *event) {
this->ui->splitter_main->saveState() this->ui->splitter_main->saveState()
); );
porymapConfig.save(); porymapConfig.save();
projectConfig.save();
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }