diff --git a/CHANGELOG.md b/CHANGELOG.md index 60dcf572..e546dc45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp The **"Breaking Changes"** listed below are changes that have been made in the decompilation projects (e.g. pokeemerald), which porymap requires in order to work properly. It also includes changes to the scripting API that may change the behavior of existing porymap scripts. If porymap is used with a project or API script that is not up-to-date with the breaking changes, then porymap will likely break or behave improperly. ## [Unreleased] +### Changed +- If settings-specific features like Wild Encounters fail to load they are now only disabled for that session + ### Fixed - Fix the Tileset Editor selectors scrolling to the wrong selection when zoomed - Fix the Tileset Editor selectors getting extra white space when changing tilesets diff --git a/include/mainwindow.h b/include/mainwindow.h index e95db003..7d939595 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -373,7 +373,6 @@ private: void initShortcuts(); void initExtraShortcuts(); void setProjectSpecificUI(); - void setWildEncountersUIEnabled(bool enabled); void loadUserSettings(); void applyMapListFilter(QString filterText); void restoreWindowState(); diff --git a/include/project.h b/include/project.h index cf74229a..89249d55 100644 --- a/include/project.h +++ b/include/project.h @@ -78,6 +78,9 @@ public: bool usingAsmTilesets; QString importExportPath; QSet disabledSettingsNames; + bool weatherEventConstantsLoaded; + bool secretBaseConstantsLoaded; + bool wildEncountersLoaded; void set_root(QString); @@ -253,7 +256,6 @@ signals: void reloadProject(); void uncheckMonitorFilesAction(); void mapCacheCleared(); - void disableWildEncountersUI(); }; #endif // PROJECT_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3a649062..c4a128d9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -361,14 +361,12 @@ void MainWindow::markMapEdited() { } } -void MainWindow::setWildEncountersUIEnabled(bool enabled) { - ui->mainTabBar->setTabEnabled(4, enabled); -} - // Update the UI using information we've read from the user's project files. void MainWindow::setProjectSpecificUI() { - this->setWildEncountersUIEnabled(userConfig.getEncounterJsonActive()); + // Wild Encounters tab + // TODO: This index should come from an enum + ui->mainTabBar->setTabEnabled(4, editor->project->wildEncountersLoaded); bool hasFlags = projectConfig.getMapAllowFlagsEnabled(); ui->checkBox_AllowRunning->setVisible(hasFlags); @@ -378,8 +376,8 @@ void MainWindow::setProjectSpecificUI() ui->label_AllowBiking->setVisible(hasFlags); ui->label_AllowEscaping->setVisible(hasFlags); - ui->newEventToolButton->newWeatherTriggerAction->setVisible(projectConfig.getEventWeatherTriggerEnabled()); - ui->newEventToolButton->newSecretBaseAction->setVisible(projectConfig.getEventSecretBaseEnabled()); + ui->newEventToolButton->newWeatherTriggerAction->setVisible(editor->project->weatherEventConstantsLoaded); + ui->newEventToolButton->newSecretBaseAction->setVisible(editor->project->secretBaseConstantsLoaded); ui->newEventToolButton->newCloneObjectAction->setVisible(projectConfig.getEventCloneObjectEnabled()); bool floorNumEnabled = projectConfig.getFloorNumberEnabled(); @@ -520,7 +518,6 @@ bool MainWindow::openProject(const QString &dir, bool initial) { editor->project = new Project(this); QObject::connect(editor->project, &Project::reloadProject, this, &MainWindow::on_action_Reload_Project_triggered); QObject::connect(editor->project, &Project::mapCacheCleared, this, &MainWindow::onMapCacheCleared); - QObject::connect(editor->project, &Project::disableWildEncountersUI, [this]() { this->setWildEncountersUIEnabled(false); }); QObject::connect(editor->project, &Project::uncheckMonitorFilesAction, [this]() { porymapConfig.setMonitorFiles(false); if (this->preferenceEditor) @@ -1767,7 +1764,7 @@ void MainWindow::on_mainTabBar_tabBarClicked(int index) editor->setEditingConnections(); } if (index != 4) { - if (userConfig.getEncounterJsonActive()) + if (editor->project && editor->project->wildEncountersLoaded) editor->saveEncounterTabData(); } if (index != 1) { diff --git a/src/project.cpp b/src/project.cpp index 41211d5b..3550e859 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -614,7 +614,7 @@ void Project::saveMapGroups() { } void Project::saveWildMonData() { - if (!userConfig.getEncounterJsonActive()) return; + if (!this->wildEncountersLoaded) return; QString wildEncountersJsonFilepath = QString("%1/%2").arg(root).arg(projectConfig.getFilePath(ProjectFilePath::json_wild_encounters)); QFile wildEncountersFile(wildEncountersJsonFilepath); @@ -1602,6 +1602,7 @@ bool Project::readWildMonData() { wildMonFields.clear(); wildMonData.clear(); encounterGroupLabels.clear(); + this->wildEncountersLoaded = false; if (!userConfig.getEncounterJsonActive()) { return true; } @@ -1611,10 +1612,7 @@ bool Project::readWildMonData() { OrderedJson::object wildMonObj; if (!parser.tryParseOrderedJsonFile(&wildMonObj, wildMonJsonFilepath)) { - // Failing to read wild encounters data is not a critical error, just disable the - // encounter editor and log a warning in case the user intended to have this data. - userConfig.setEncounterJsonActive(false); - emit disableWildEncountersUI(); + // Failing to read wild encounters data is not a critical error, the encounter editor will just be disabled logWarn(QString("Failed to read wild encounters from %1").arg(wildMonJsonFilepath)); return true; } @@ -1702,6 +1700,7 @@ bool Project::readWildMonData() { setDefaultEncounterRate(i.key(), rate); } + this->wildEncountersLoaded = true; return true; } @@ -2268,6 +2267,7 @@ bool Project::readWeatherNames() { } bool Project::readCoordEventWeatherNames() { + this->weatherEventConstantsLoaded = false; if (!projectConfig.getEventWeatherTriggerEnabled()) return true; @@ -2277,12 +2277,15 @@ bool Project::readCoordEventWeatherNames() { coordEventWeatherNames = parser.readCDefineNames(filename, prefixes); if (coordEventWeatherNames.isEmpty()) { logWarn(QString("Failed to read coord event weather constants from %1. Disabling Weather Trigger events.").arg(filename)); - projectConfig.setEventWeatherTriggerEnabled(false); + return true; } + + this->weatherEventConstantsLoaded = true; return true; } bool Project::readSecretBaseIds() { + this->secretBaseConstantsLoaded = false; if (!projectConfig.getEventSecretBaseEnabled()) return true; @@ -2292,8 +2295,10 @@ bool Project::readSecretBaseIds() { secretBaseIds = parser.readCDefineNames(filename, prefixes); if (secretBaseIds.isEmpty()) { logWarn(QString("Failed to read secret base id constants from '%1'. Disabling Secret Base events.").arg(filename)); - projectConfig.setEventSecretBaseEnabled(false); + return true; } + + this->secretBaseConstantsLoaded = true; return true; } diff --git a/src/scriptapi/apiutility.cpp b/src/scriptapi/apiutility.cpp index 559e46af..38ff3e39 100644 --- a/src/scriptapi/apiutility.cpp +++ b/src/scriptapi/apiutility.cpp @@ -141,8 +141,8 @@ int ScriptUtility::getMainTab() { void ScriptUtility::setMainTab(int index) { if (!window || !window->ui || !window->ui->mainTabBar || index < 0 || index >= window->ui->mainTabBar->count()) return; - // Can't select Wild Encounters tab if it's disabled - if (index == 4 && !userConfig.getEncounterJsonActive()) + // Can't select tab if it's disabled + if (!window->ui->mainTabBar->isTabEnabled(index)) return; window->on_mainTabBar_tabBarClicked(index); }