Stop changing settings if their features fail to load

This commit is contained in:
GriffinR 2024-01-18 12:00:18 -05:00
parent 662ada181a
commit 3505251ad2
6 changed files with 26 additions and 20 deletions

View file

@ -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

View file

@ -373,7 +373,6 @@ private:
void initShortcuts();
void initExtraShortcuts();
void setProjectSpecificUI();
void setWildEncountersUIEnabled(bool enabled);
void loadUserSettings();
void applyMapListFilter(QString filterText);
void restoreWindowState();

View file

@ -78,6 +78,9 @@ public:
bool usingAsmTilesets;
QString importExportPath;
QSet<QString> 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

View file

@ -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) {

View file

@ -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;
}

View file

@ -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);
}