diff --git a/include/config.h b/include/config.h index bd0a1296..e9264d15 100644 --- a/include/config.h +++ b/include/config.h @@ -1,3 +1,4 @@ +#pragma once #ifndef CONFIG_H #define CONFIG_H diff --git a/include/core/block.h b/include/core/block.h index 798e179c..6a787265 100644 --- a/include/core/block.h +++ b/include/core/block.h @@ -1,3 +1,4 @@ +#pragma once #ifndef BLOCK_H #define BLOCK_H diff --git a/include/core/blockdata.h b/include/core/blockdata.h index 35c071fb..a8e29d36 100644 --- a/include/core/blockdata.h +++ b/include/core/blockdata.h @@ -1,3 +1,4 @@ +#pragma once #ifndef BLOCKDATA_H #define BLOCKDATA_H diff --git a/include/core/editcommands.h b/include/core/editcommands.h index 69d2f14f..cbc98415 100644 --- a/include/core/editcommands.h +++ b/include/core/editcommands.h @@ -1,3 +1,4 @@ +#pragma once #ifndef EDITCOMMANDS_H #define EDITCOMMANDS_H diff --git a/include/core/event.h b/include/core/event.h index b6e0d175..4a6e7c4a 100644 --- a/include/core/event.h +++ b/include/core/event.h @@ -1,3 +1,4 @@ +#pragma once #ifndef EVENT_H #define EVENT_H diff --git a/include/core/heallocation.h b/include/core/heallocation.h index fd00a22b..a39386c1 100644 --- a/include/core/heallocation.h +++ b/include/core/heallocation.h @@ -1,3 +1,4 @@ +#pragma once #ifndef HEALLOCATION_H #define HEALLOCATION_H diff --git a/include/core/history.h b/include/core/history.h index 40576ff2..75883d2d 100644 --- a/include/core/history.h +++ b/include/core/history.h @@ -1,3 +1,4 @@ +#pragma once #ifndef HISTORY_H #define HISTORY_H diff --git a/include/core/imageexport.h b/include/core/imageexport.h index e6552323..d195e471 100644 --- a/include/core/imageexport.h +++ b/include/core/imageexport.h @@ -1,3 +1,4 @@ +#pragma once #ifndef IMAGEEXPORT_H #define IMAGEEXPORT_H diff --git a/include/core/map.h b/include/core/map.h index a2a51551..7052802a 100644 --- a/include/core/map.h +++ b/include/core/map.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAP_H #define MAP_H diff --git a/include/core/mapconnection.h b/include/core/mapconnection.h index 8823e7bc..b6be238e 100644 --- a/include/core/mapconnection.h +++ b/include/core/mapconnection.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAPCONNECTION_H #define MAPCONNECTION_H diff --git a/include/core/maplayout.h b/include/core/maplayout.h index e44a3646..d04fbab5 100644 --- a/include/core/maplayout.h +++ b/include/core/maplayout.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAPLAYOUT_H #define MAPLAYOUT_H diff --git a/include/core/metatile.h b/include/core/metatile.h index 27d515ba..c016ae7c 100644 --- a/include/core/metatile.h +++ b/include/core/metatile.h @@ -1,3 +1,4 @@ +#pragma once #ifndef METATILE_H #define METATILE_H diff --git a/include/core/metatileparser.h b/include/core/metatileparser.h index 1d423a72..7bf0b096 100644 --- a/include/core/metatileparser.h +++ b/include/core/metatileparser.h @@ -1,3 +1,4 @@ +#pragma once #ifndef METATILEPARSER_H #define METATILEPARSER_H diff --git a/include/core/paletteutil.h b/include/core/paletteutil.h index a067dea3..abc1700a 100644 --- a/include/core/paletteutil.h +++ b/include/core/paletteutil.h @@ -1,3 +1,4 @@ +#pragma once #ifndef PALETTEUTIL_H #define PALETTEUTIL_H diff --git a/include/core/parseutil.h b/include/core/parseutil.h index bd614686..82fad4e2 100644 --- a/include/core/parseutil.h +++ b/include/core/parseutil.h @@ -1,3 +1,4 @@ +#pragma once #ifndef PARSEUTIL_H #define PARSEUTIL_H diff --git a/include/core/regionmap.h b/include/core/regionmap.h index a8158395..a24ae1ea 100644 --- a/include/core/regionmap.h +++ b/include/core/regionmap.h @@ -1,3 +1,4 @@ +#pragma once #ifndef REGIONMAP_H #define REGIONMAP_H diff --git a/include/core/tile.h b/include/core/tile.h index 05349c4a..e2b1ec4d 100644 --- a/include/core/tile.h +++ b/include/core/tile.h @@ -1,3 +1,4 @@ +#pragma once #ifndef TILE_H #define TILE_H diff --git a/include/core/tileset.h b/include/core/tileset.h index 9113788a..c6349cfe 100644 --- a/include/core/tileset.h +++ b/include/core/tileset.h @@ -1,3 +1,4 @@ +#pragma once #ifndef TILESET_H #define TILESET_H diff --git a/include/core/wildmoninfo.h b/include/core/wildmoninfo.h index f0868f7f..06877622 100644 --- a/include/core/wildmoninfo.h +++ b/include/core/wildmoninfo.h @@ -1,3 +1,4 @@ +#pragma once #ifndef GUARD_WILDMONINFO_H #define GUARD_WILDMONINFO_H diff --git a/include/editor.h b/include/editor.h index 90361ca3..e876a3ca 100644 --- a/include/editor.h +++ b/include/editor.h @@ -1,3 +1,4 @@ +#pragma once #ifndef EDITOR_H #define EDITOR_H diff --git a/include/lib/orderedjson.h b/include/lib/orderedjson.h index fb68527d..20463cee 100644 --- a/include/lib/orderedjson.h +++ b/include/lib/orderedjson.h @@ -52,6 +52,8 @@ */ #pragma once +#ifndef ORDERED_JSON_H +#define ORDERED_JSON_H #include #include @@ -240,3 +242,4 @@ protected: } // namespace poryjson +#endif // ORDERED_JSON_H diff --git a/include/lib/orderedmap.h b/include/lib/orderedmap.h index 40fe08b8..40882d9f 100644 --- a/include/lib/orderedmap.h +++ b/include/lib/orderedmap.h @@ -21,6 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ +#pragma once #ifndef TSL_ORDERED_MAP_H #define TSL_ORDERED_MAP_H diff --git a/include/lib/qstringhash.h b/include/lib/qstringhash.h index 10947d6f..a9affaf7 100644 --- a/include/lib/qstringhash.h +++ b/include/lib/qstringhash.h @@ -1,3 +1,4 @@ +#pragma once #ifndef QSTRINGHASH_H #define QSTRINGHASH_H diff --git a/include/log.h b/include/log.h index 87e0ae01..37571dae 100644 --- a/include/log.h +++ b/include/log.h @@ -1,3 +1,4 @@ +#pragma once #ifndef LOG_H #define LOG_H diff --git a/include/mainwindow.h b/include/mainwindow.h index f5cab1e8..d1631b1b 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -1,3 +1,4 @@ +#pragma once #ifndef MAINWINDOW_H #define MAINWINDOW_H @@ -271,6 +272,7 @@ private: bool isProgrammaticEventTabChange; bool projectHasUnsavedChanges; + bool projectOpenFailure = false; MapSortOrder mapSortOrder; diff --git a/include/project.h b/include/project.h index afc82030..085cd6d1 100644 --- a/include/project.h +++ b/include/project.h @@ -1,3 +1,4 @@ +#pragma once #ifndef PROJECT_H #define PROJECT_H diff --git a/include/scripting.h b/include/scripting.h index 99daac89..6f3b0d16 100644 --- a/include/scripting.h +++ b/include/scripting.h @@ -1,3 +1,4 @@ +#pragma once #ifndef SCRIPTING_H #define SCRIPTING_H diff --git a/include/settings.h b/include/settings.h index 5b989ed5..d37283cd 100644 --- a/include/settings.h +++ b/include/settings.h @@ -1,3 +1,4 @@ +#pragma once #ifndef SETTINGS_H #define SETTINGS_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4c3cb660..f87d04a5 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -58,10 +58,11 @@ MainWindow::MainWindow(QWidget *parent) : this->initWindow(); if (!this->openRecentProject()) { - // Re-initialize everything to a blank slate if opening the recent project failed. - this->initWindow(); + setWindowDisabled(true); + } else { + setWindowDisabled(false); + on_toolButton_Paint_clicked(); } - on_toolButton_Paint_clicked(); } MainWindow::~MainWindow() @@ -173,6 +174,7 @@ void MainWindow::applyUserShortcuts() { void MainWindow::initCustomUI() { // Set up the tab bar + while (ui->mainTabBar->count()) ui->mainTabBar->removeTab(0); ui->mainTabBar->addTab("Map"); ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico"))); ui->mainTabBar->addTab("Events"); @@ -180,12 +182,19 @@ void MainWindow::initCustomUI() { ui->mainTabBar->addTab("Connections"); ui->mainTabBar->addTab("Wild Pokemon"); 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. ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->mapList, SIGNAL(customContextMenuRequested(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; QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel; connect(labelCombo, QOverload::of(&QComboBox::currentIndexChanged), [=](int index){ @@ -217,11 +226,6 @@ void MainWindow::initCustomUI() { label_MapRulerStatus->setTextInteractionFlags(Qt::TextSelectableByMouse); } -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() { this->editor = new Editor(ui); connect(this->editor, SIGNAL(objectsChanged()), this, SLOT(updateObjects())); @@ -461,11 +465,12 @@ bool MainWindow::openRecentProject() { return openProject(default_dir); } - return true; + return false; } bool MainWindow::openProject(QString dir) { if (dir.isNull()) { + projectOpenFailure = true; return false; } @@ -522,13 +527,12 @@ bool MainWindow::openProject(QString dir) { Scripting::cb_ProjectOpened(dir); } - setWindowDisabled(false); - + projectOpenFailure = !success; return success; } bool MainWindow::isProjectOpen() { - return editor != nullptr && editor->project != nullptr; + return !projectOpenFailure && editor && editor->project; } QString MainWindow::getDefaultMap() { @@ -572,9 +576,7 @@ void MainWindow::on_action_Open_Project_triggered() this->ui->graphicsView_Map->overlay.clearItems(); } porymapConfig.setRecentProject(dir); - if (!openProject(dir)) { - this->initWindow(); - } + setWindowDisabled(!openProject(dir)); } } @@ -1556,6 +1558,7 @@ void MainWindow::addNewEvent(QString event_type) if (editor && editor->project) { DraggablePixmapItem *object = editor->addNewEvent(event_type); if (object) { + updateObjects(); editor->selectMapEvent(object, false); } else { QMessageBox msgBox(this); @@ -2827,19 +2830,22 @@ void MainWindow::closeSupplementaryWindows() { } void MainWindow::closeEvent(QCloseEvent *event) { - if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) { - QMessageBox::StandardButton result = QMessageBox::question( - this, "porymap", "The project has been modified, save changes?", - QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); + if (isProjectOpen()) { + if (projectHasUnsavedChanges || (editor->map && editor->map->hasUnsavedChanges())) { + QMessageBox::StandardButton result = QMessageBox::question( + this, "porymap", "The project has been modified, save changes?", + QMessageBox::No | QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes); - if (result == QMessageBox::Yes) { - editor->saveProject(); - } else if (result == QMessageBox::No) { - logWarn("Closing porymap with unsaved changes."); - } else if (result == QMessageBox::Cancel) { - event->ignore(); - return; + if (result == QMessageBox::Yes) { + editor->saveProject(); + } else if (result == QMessageBox::No) { + logWarn("Closing porymap with unsaved changes."); + } else if (result == QMessageBox::Cancel) { + event->ignore(); + return; + } } + projectConfig.save(); } porymapConfig.setMainGeometry(