Skip to content

Commit

Permalink
Merge pull request #588 from GriffinRichards/preserve-settings
Browse files Browse the repository at this point in the history
Stop changing settings if their features fail to load
  • Loading branch information
GriffinRichards authored Jan 25, 2024
2 parents 662ada1 + 42a95b3 commit d74affe
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 143 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ 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 Wild Encounters fail to load they are now only disabled for that session, and the settings remain unchanged.
- Defaults are used if project constants are missing, rather than failing to open the project or changing settings.

### 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
- Fix the Tileset Editor selectors scrolling to the wrong selection when zoomed.
- Fix the Tileset Editor selectors getting extra white space when changing tilesets.
- Fix a crash when adding disabled events with the Pencil tool.

## [5.3.0] - 2024-01-15
### Added
Expand Down
1 change: 0 additions & 1 deletion include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ private slots:
void initShortcuts();
void initExtraShortcuts();
void setProjectSpecificUI();
void setWildEncountersUIEnabled(bool enabled);
void loadUserSettings();
void applyMapListFilter(QString filterText);
void restoreWindowState();
Expand Down
5 changes: 2 additions & 3 deletions include/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Project : public QObject
QMap<int, QString> mapSectionValueToName;
QMap<QString, EventGraphics*> eventGraphicsMap;
QMap<QString, int> gfxDefines;
QString defaultSong;
QStringList songNames;
QStringList itemNames;
QStringList flagNames;
Expand All @@ -78,6 +79,7 @@ class Project : public QObject
bool usingAsmTilesets;
QString importExportPath;
QSet<QString> disabledSettingsNames;
bool wildEncountersLoaded;

void set_root(QString);

Expand Down Expand Up @@ -162,8 +164,6 @@ class Project : public QObject
void saveTilesetMetatiles(Tileset*);
void saveTilesetTilesImage(Tileset*);
void saveTilesetPalettes(Tileset*);

QString defaultSong;
void appendTilesetLabel(QString label, QString isSecondaryStr);
bool readTilesetLabels();
bool readTilesetMetatileLabels();
Expand Down Expand Up @@ -253,7 +253,6 @@ class Project : public QObject
void reloadProject();
void uncheckMonitorFilesAction();
void mapCacheCleared();
void disableWildEncountersUI();
};

#endif // PROJECT_H
22 changes: 11 additions & 11 deletions src/core/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ bool ObjectEvent::loadFromJson(QJsonObject json, Project *) {
}

void ObjectEvent::setDefaultValues(Project *project) {
this->setGfx(project->gfxDefines.keys().first());
this->setMovement(project->movementTypes.first());
this->setGfx(project->gfxDefines.keys().value(0, "0"));
this->setMovement(project->movementTypes.value(0, "0"));
this->setScript("NULL");
this->setTrainerType(project->trainerTypes.value(0, "0"));
this->setFlag("0");
Expand Down Expand Up @@ -404,7 +404,7 @@ bool CloneObjectEvent::loadFromJson(QJsonObject json, Project *project) {
}

void CloneObjectEvent::setDefaultValues(Project *project) {
this->setGfx(project->gfxDefines.keys().first());
this->setGfx(project->gfxDefines.keys().value(0, "0"));
this->setTargetID(1);
if (this->getMap()) this->setTargetMap(this->getMap()->name);
}
Expand Down Expand Up @@ -436,8 +436,8 @@ void CloneObjectEvent::loadPixmap(Project *project) {
this->movement = clonedObject->getMovement();
} else {
// Invalid object specified, use default graphics data (as would be shown in-game)
this->gfx = project->gfxDefines.key(0);
this->movement = project->movementTypes.first();
this->gfx = project->gfxDefines.key(0, "0");
this->movement = project->movementTypes.value(0, "0");
}

EventGraphics *eventGfx = project->eventGraphicsMap.value(gfx, nullptr);
Expand Down Expand Up @@ -596,7 +596,7 @@ bool TriggerEvent::loadFromJson(QJsonObject json, Project *) {

void TriggerEvent::setDefaultValues(Project *project) {
this->setScriptLabel("NULL");
this->setScriptVar(project->varNames.first());
this->setScriptVar(project->varNames.value(0, "0"));
this->setScriptVarValue("0");
this->setElevation(0);
}
Expand Down Expand Up @@ -665,7 +665,7 @@ bool WeatherTriggerEvent::loadFromJson(QJsonObject json, Project *) {
}

void WeatherTriggerEvent::setDefaultValues(Project *project) {
this->setWeather(project->coordEventWeatherNames.first());
this->setWeather(project->coordEventWeatherNames.value(0, "0"));
this->setElevation(0);
}

Expand Down Expand Up @@ -734,7 +734,7 @@ bool SignEvent::loadFromJson(QJsonObject json, Project *) {
}

void SignEvent::setDefaultValues(Project *project) {
this->setFacingDirection(project->bgEventFacingDirections.first());
this->setFacingDirection(project->bgEventFacingDirections.value(0, "0"));
this->setScriptLabel("NULL");
this->setElevation(0);
}
Expand Down Expand Up @@ -819,8 +819,8 @@ bool HiddenItemEvent::loadFromJson(QJsonObject json, Project *) {
}

void HiddenItemEvent::setDefaultValues(Project *project) {
this->setItem(project->itemNames.first());
this->setFlag(project->flagNames.first());
this->setItem(project->itemNames.value(0, "0"));
this->setFlag(project->flagNames.value(0, "0"));
if (projectConfig.getHiddenItemQuantityEnabled()) {
this->setQuantity(1);
}
Expand Down Expand Up @@ -898,7 +898,7 @@ bool SecretBaseEvent::loadFromJson(QJsonObject json, Project *) {
}

void SecretBaseEvent::setDefaultValues(Project *project) {
this->setBaseID(project->secretBaseIds.first());
this->setBaseID(project->secretBaseIds.value(0, "0"));
this->setElevation(0);
}

Expand Down
48 changes: 19 additions & 29 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -500,7 +498,10 @@ bool MainWindow::openProject(const QString &dir, bool initial) {
}
return false;
}
this->statusBar()->showMessage(QString("Opening %1").arg(projectString));

const QString openMessage = QString("Opening %1").arg(projectString);
this->statusBar()->showMessage(openMessage);
logInfo(openMessage);

userConfig.setProjectDir(dir);
userConfig.load();
Expand All @@ -520,7 +521,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)
Expand All @@ -544,10 +544,7 @@ bool MainWindow::openProject(const QString &dir, bool initial) {
}

showWindowTitle();

const QString successMessage = QString("Opened %1").arg(projectString);
this->statusBar()->showMessage(successMessage);
logInfo(successMessage);
this->statusBar()->showMessage(QString("Opened %1").arg(projectString));

porymapConfig.addRecentProject(dir);
refreshRecentProjectsMenu();
Expand Down Expand Up @@ -575,29 +572,22 @@ bool MainWindow::isProjectOpen() {
}

bool MainWindow::setInitialMap() {
QList<QStringList> names;
QStringList names;
if (editor && editor->project)
names = editor->project->groupedMapNames;
names = editor->project->mapNames;

// Try to set most recently-opened map, if it's still in the list.
QString recentMap = userConfig.getRecentMap();
if (!recentMap.isEmpty()) {
// Make sure the recent map is still in the map list
for (int i = 0; i < names.length(); i++) {
if (names.value(i).contains(recentMap)) {
return setMap(recentMap, true);
}
}
}
if (!recentMap.isEmpty() && names.contains(recentMap) && setMap(recentMap, true))
return true;

// Failing that, just get the first map in the list.
for (int i = 0; i < names.length(); i++) {
QStringList list = names.value(i);
if (list.length()) {
return setMap(list.value(0), true);
}
// Failing that, try loading maps in the map list sequentially.
for (auto name : names) {
if (name != recentMap && setMap(name, true))
return true;
}

logError("Failed to load any map names.");
logError("Failed to load any maps.");
return false;
}

Expand Down Expand Up @@ -1767,7 +1757,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) {
Expand Down
Loading

0 comments on commit d74affe

Please sign in to comment.