From 1c2be70ff0215112718196031ba70787a0831302 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 17 Jun 2024 12:11:55 -0400 Subject: [PATCH] Allow users to fix faulty region map settings --- include/mainwindow.h | 1 + include/ui/regionmapeditor.h | 2 ++ src/core/regionmap.cpp | 2 +- src/mainwindow.cpp | 35 ++++++++++++++++++++++++++++------- src/ui/regionmapeditor.cpp | 10 ++++++++-- 5 files changed, 40 insertions(+), 10 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index f3aa9375..7fda1b09 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -388,6 +388,7 @@ private: void initTilesetEditor(); bool initRegionMapEditor(bool silent = false); + bool askToFixRegionMapEditor(); void initShortcutsEditor(); void initCustomScriptsEditor(); void connectSubEditorsToShortcutsEditor(); diff --git a/include/ui/regionmapeditor.h b/include/ui/regionmapeditor.h index ef72b5ee..3d889f88 100644 --- a/include/ui/regionmapeditor.h +++ b/include/ui/regionmapeditor.h @@ -42,6 +42,8 @@ public: void resizeTilemap(int width, int height); + bool reconfigure(); + QObjectList shortcutableObjects() const; public slots: diff --git a/src/core/regionmap.cpp b/src/core/regionmap.cpp index 9c66860b..45fc1141 100644 --- a/src/core/regionmap.cpp +++ b/src/core/regionmap.cpp @@ -303,7 +303,7 @@ bool RegionMap::loadLayout(poryjson::Json layoutJson) { } setLayout("main", layout); } else { - logError("Region map layout is not readable."); + logError(QString("Failed to read region map layout from '%1'.").arg(this->layout_path)); return false; } } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ae498fb4..0b92c1c9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2958,14 +2958,12 @@ void MainWindow::on_pushButton_CreatePrefab_clicked() { bool MainWindow::initRegionMapEditor(bool silent) { this->regionMapEditor = new RegionMapEditor(this, this->editor->project); - bool success = this->regionMapEditor->load(silent); - if (!success) { + if (!this->regionMapEditor->load(silent)) { + // The region map editor either failed to load, + // or the user declined configuring their settings. if (!silent && this->regionMapEditor->setupErrored()) { - QMessageBox msgBox(this); - QString errorMsg = QString("There was an error opening the region map data. Please see %1 for full error details.\n\n%2") - .arg(getLogPath()) - .arg(getMostRecentError()); - msgBox.critical(nullptr, "Error Opening Region Map Editor", errorMsg); + if (this->askToFixRegionMapEditor()) + return true; } delete this->regionMapEditor; return false; @@ -2974,6 +2972,29 @@ bool MainWindow::initRegionMapEditor(bool silent) { return true; } +bool MainWindow::askToFixRegionMapEditor() { + QMessageBox msgBox; + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText(QString("There was an error opening the region map data. Please see %1 for full error details.").arg(getLogPath())); + msgBox.setDetailedText(getMostRecentError()); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.setDefaultButton(QMessageBox::Ok); + auto reconfigButton = msgBox.addButton("Reconfigure", QMessageBox::ActionRole); + msgBox.exec(); + if (msgBox.clickedButton() == reconfigButton) { + if (this->regionMapEditor->reconfigure()) { + // User fixed error + return true; + } + if (this->regionMapEditor->setupErrored()) { + // User's new settings still fail, show error and ask again + return this->askToFixRegionMapEditor(); + } + } + // User accepted error + return false; +} + void MainWindow::closeSupplementaryWindows() { delete this->tilesetEditor; delete this->regionMapEditor; diff --git a/src/ui/regionmapeditor.cpp b/src/ui/regionmapeditor.cpp index ee491a3e..0f75a730 100644 --- a/src/ui/regionmapeditor.cpp +++ b/src/ui/regionmapeditor.cpp @@ -599,6 +599,11 @@ void RegionMapEditor::on_actionSave_All_triggered() { } void RegionMapEditor::on_action_Configure_triggered() { + reconfigure(); +} + +bool RegionMapEditor::reconfigure() { + this->setupError = false; if (this->modified()) { QMessageBox warning; warning.setIcon(QMessageBox::Warning); @@ -609,15 +614,16 @@ void RegionMapEditor::on_action_Configure_triggered() { if (warning.exec() == QMessageBox::Ok) { if (buildConfigDialog()) { - reload(); + return reload(); } } } else { if (buildConfigDialog()) { - reload(); + return reload(); } } + return false; } void RegionMapEditor::displayRegionMap() {