From 43d5e32b96d7c5da57cff8bf6884ab01e65d58e9 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 19 Feb 2025 11:07:11 -0500 Subject: [PATCH 1/3] Fix Save All after layout split changes --- include/editor.h | 6 +++--- include/mainwindow.h | 1 + include/project.h | 6 +++--- src/editor.cpp | 39 ++++++++++++++++++++++----------------- src/mainwindow.cpp | 30 +++++++++++++++++------------- src/project.cpp | 20 ++++++++++++++------ 6 files changed, 60 insertions(+), 42 deletions(-) diff --git a/include/editor.h b/include/editor.h index 689d2f4f..09eb53ad 100644 --- a/include/editor.h +++ b/include/editor.h @@ -57,9 +57,8 @@ public: GridSettings gridSettings; void setProject(Project * project); - void save(); - void saveProject(); - void saveUiFields(); + void saveAll(); + void saveCurrent(); void saveEncounterTabData(); void closeProject(); @@ -204,6 +203,7 @@ private: EditMode editMode = EditMode::None; + void save(bool currentOnly); void clearMap(); void clearMetatileSelector(); void clearMovementPermissionSelector(); diff --git a/include/mainwindow.h b/include/mainwindow.h index 805899a1..47f278a9 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -175,6 +175,7 @@ private slots: void on_action_Reload_Project_triggered(); void on_action_Close_Project_triggered(); void on_action_Save_Project_triggered(); + void save(bool all = true); void openWarpMap(QString map_name, int event_id, Event::Group event_group); diff --git a/include/project.h b/include/project.h index f3a1093b..e5fad3ba 100644 --- a/include/project.h +++ b/include/project.h @@ -167,13 +167,13 @@ public: void loadTilesetMetatileLabels(Tileset*); void readTilesetPaths(Tileset* tileset); + void saveAll(); + void saveGlobalData(); void saveLayout(Layout *); void saveLayoutBlockdata(Layout *); void saveLayoutBorder(Layout *); void writeBlockdata(QString, const Blockdata &); - void saveAllMaps(); - void saveMap(Map *); - void saveAllDataStructures(); + void saveMap(Map *map, bool skipLayout = false); void saveConfig(); void saveMapLayouts(); void saveMapGroups(); diff --git a/src/editor.cpp b/src/editor.cpp index 6a2e0c20..9912391b 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -69,28 +69,30 @@ Editor::~Editor() closeProject(); } -void Editor::saveProject() { - if (project) { - saveUiFields(); - project->saveAllMaps(); - project->saveAllDataStructures(); - } +void Editor::saveCurrent() { + save(true); } -void Editor::save() { - if (this->project && this->map) { - saveUiFields(); - this->project->saveMap(this->map); - this->project->saveAllDataStructures(); - } - else if (this->project && this->layout) { - this->project->saveLayout(this->layout); - this->project->saveAllDataStructures(); - } +void Editor::saveAll() { + save(false); } -void Editor::saveUiFields() { +void Editor::save(bool currentOnly) { + if (!this->project) + return; + saveEncounterTabData(); + + if (currentOnly) { + if (this->map) { + this->project->saveMap(this->map); + } else if (this->layout) { + this->project->saveLayout(this->layout); + } + this->project->saveGlobalData(); + } else { + this->project->saveAll(); + } } void Editor::setProject(Project * project) { @@ -651,6 +653,9 @@ void Editor::configureEncounterJSON(QWidget *window) { } void Editor::saveEncounterTabData() { + if (!this->map || !this->project) + return; + // This function does not save to disk so it is safe to use before user clicks Save. QStackedWidget *stack = ui->stackedWidget_WildMons; QComboBox *labelCombo = ui->comboBox_EncounterGroupLabel; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a38b3bd0..1cddb3cc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1307,12 +1307,6 @@ void MainWindow::onNewMapCreated(Map *newMap, const QString &groupName) { addNewEvent(Event::Type::HealLocation); } - // TODO: Creating a new map shouldn't be automatically saved. - // For one, it takes away the option to discard the new map. - // For two, if the new map uses an existing layout, any unsaved changes to that layout will also be saved. - editor->project->saveMap(newMap); - editor->project->saveAllDataStructures(); - // Add new map to the map lists this->mapGroupModel->insertMapItem(newMap->name(), groupName); this->mapLocationModel->insertMapItem(newMap->name(), newMap->header()->location()); @@ -1328,7 +1322,12 @@ void MainWindow::onNewMapCreated(Map *newMap, const QString &groupName) { ui->comboBox_EmergeMap->insertItem(mapIndex, newMap->name()); } - userSetMap(newMap->name()); + if (userSetMap(newMap->name())) { + // TODO: Creating a new map shouldn't be automatically saved. + // For one, it takes away the option to discard the new map. + // For two, if the new map uses an existing layout, any unsaved changes to that layout will also be saved. + save(true); + } } // Called any time a new layout is created (including as a byproduct of creating a new map) @@ -1551,14 +1550,19 @@ void MainWindow::updateMapList() { } void MainWindow::on_action_Save_Project_triggered() { - editor->saveProject(); - updateWindowTitle(); - updateMapList(); - saveGlobalConfigs(); + save(false); } void MainWindow::on_action_Save_triggered() { - editor->save(); + save(true); +} + +void MainWindow::save(bool currentOnly) { + if (currentOnly) { + this->editor->saveCurrent(); + } else { + this->editor->saveAll(); + } updateWindowTitle(); updateMapList(); saveGlobalConfigs(); @@ -3008,7 +3012,7 @@ bool MainWindow::closeProject() { auto reply = msgBox.exec(); if (reply == QMessageBox::Yes) { - editor->saveProject(); + save(); } else if (reply == QMessageBox::No) { logWarn("Closing project with unsaved changes."); } else if (reply == QMessageBox::Cancel) { diff --git a/src/project.cpp b/src/project.cpp index 38b1810b..3a397926 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1155,12 +1155,17 @@ void Project::writeBlockdata(QString path, const Blockdata &blockdata) { } } -void Project::saveAllMaps() { - for (auto *map : mapCache.values()) - saveMap(map); +void Project::saveAll() { + for (auto map : this->mapCache) { + saveMap(map, true); // Avoid double-saving the layouts + } + for (auto layout : this->mapLayouts) { + saveLayout(layout); + } + saveGlobalData(); } -void Project::saveMap(Map *map) { +void Project::saveMap(Map *map, bool skipLayout) { // Create/Modify a few collateral files for brand new maps. const QString folderPath = projectConfig.getFilePath(ProjectFilePath::data_map_folders) + map->name(); const QString fullPath = QString("%1/%2").arg(this->root).arg(folderPath); @@ -1289,12 +1294,15 @@ void Project::saveMap(Map *map) { jsonDoc.dump(&mapFile); mapFile.close(); - saveLayout(map->layout()); + if (!skipLayout) saveLayout(map->layout()); map->setClean(); } void Project::saveLayout(Layout *layout) { + if (!layout || !layout->loaded) + return; + saveLayoutBorder(layout); saveLayoutBlockdata(layout); @@ -1317,7 +1325,7 @@ void Project::updateLayout(Layout *layout) { } } -void Project::saveAllDataStructures() { +void Project::saveGlobalData() { saveMapLayouts(); saveMapGroups(); saveRegionMapSections(); From 1ab8b830d842e06c3550795b14ca2f4b16edc2c7 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 19 Feb 2025 11:39:45 -0500 Subject: [PATCH 2/3] Add in-game reload message --- include/config.h | 2 ++ src/config.cpp | 3 +++ src/mainwindow.cpp | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/include/config.h b/include/config.h index 7f263da0..f92566e2 100644 --- a/include/config.h +++ b/include/config.h @@ -87,6 +87,7 @@ public: this->lastUpdateCheckVersion = porymapVersion; this->rateLimitTimes.clear(); this->eventSelectionShapeMode = QGraphicsPixmapItem::MaskShape; + this->shownInGameReloadMessage = false; } void addRecentProject(QString project); void setRecentProjects(QStringList projects); @@ -146,6 +147,7 @@ public: QByteArray wildMonChartGeometry; QByteArray newMapDialogGeometry; QByteArray newLayoutDialogGeometry; + bool shownInGameReloadMessage; protected: virtual QString getConfigFilepath() override; diff --git a/src/config.cpp b/src/config.cpp index b22972a4..d0ac2115 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -422,6 +422,8 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) { } else { logWarn(QString("Invalid config value for %1: '%2'. Must be 'mask' or 'bounding_rect'.").arg(key).arg(value)); } + } else if (key == "shown_in_game_reload_message") { + this->shownInGameReloadMessage = getConfigBool(key, value); } else { logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key)); } @@ -492,6 +494,7 @@ QMap PorymapConfig::getKeyValueMap() { map.insert("rate_limit_time/" + i.key().toString(), time.toUTC().toString()); } map.insert("event_selection_shape_mode", (this->eventSelectionShapeMode == QGraphicsPixmapItem::MaskShape) ? "mask" : "bounding_rect"); + map.insert("shown_in_game_reload_message", this->shownInGameReloadMessage ? "1" : "0"); return map; } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1cddb3cc..f541dace 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1565,6 +1565,15 @@ void MainWindow::save(bool currentOnly) { } updateWindowTitle(); updateMapList(); + + if (!porymapConfig.shownInGameReloadMessage) { + // Show a one-time warning that the user may need to reload their map to see their new changes. + static const QString message = QStringLiteral("Reload your map in-game!\n\nIf your game is currently saved on a map you have edited, " + "the changes may not appear until you leave the map and return."); + InfoMessage::show(message, this); + porymapConfig.shownInGameReloadMessage = true; + } + saveGlobalConfigs(); } From c987cb322df76ac3a705546cff10788b16784168 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 19 Feb 2025 11:47:13 -0500 Subject: [PATCH 3/3] Fix default save argument --- include/mainwindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index 47f278a9..6128cc47 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -175,7 +175,7 @@ private slots: void on_action_Reload_Project_triggered(); void on_action_Close_Project_triggered(); void on_action_Save_Project_triggered(); - void save(bool all = true); + void save(bool currentOnly = false); void openWarpMap(QString map_name, int event_id, Event::Group event_group);