From 35da77ca9467a7ae136fc7bdded5a2f1b5f71ad0 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 23 Oct 2022 18:59:59 -0400 Subject: [PATCH 01/10] Treat tileset lists separately --- include/project.h | 3 ++- src/mainwindow.cpp | 11 +++++------ src/project.cpp | 23 ++++++++++++----------- src/scriptapi/apiutility.cpp | 4 ++-- src/ui/newmappopup.cpp | 8 ++++---- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/include/project.h b/include/project.h index 28c3a296..8d892cfd 100644 --- a/include/project.h +++ b/include/project.h @@ -108,7 +108,8 @@ public: QMap tilesetCache; Tileset* loadTileset(QString, Tileset *tileset = nullptr); Tileset* getTileset(QString, bool forceLoad = false); - QMap tilesetLabels; + QStringList primaryTilesetLabels; + QStringList secondaryTilesetLabels; QStringList tilesetLabelsOrdered; Blockdata readBlockdata(QString); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3c10824f..bea01b5d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -961,9 +961,9 @@ bool MainWindow::loadProjectCombos() { ui->comboBox_Location->clear(); ui->comboBox_Location->addItems(project->mapSectionValueToName.values()); ui->comboBox_PrimaryTileset->clear(); - ui->comboBox_PrimaryTileset->addItems(project->tilesetLabels.value("primary")); + ui->comboBox_PrimaryTileset->addItems(project->primaryTilesetLabels); ui->comboBox_SecondaryTileset->clear(); - ui->comboBox_SecondaryTileset->addItems(project->tilesetLabels.value("secondary")); + ui->comboBox_SecondaryTileset->addItems(project->secondaryTilesetLabels); ui->comboBox_Weather->clear(); ui->comboBox_Weather->addItems(project->weatherNames); ui->comboBox_BattleScene->clear(); @@ -1266,8 +1266,7 @@ void MainWindow::on_actionNew_Tileset_triggered() { msgBox.exec(); return; } - if (editor->project->tilesetLabels.value("primary").contains(createTilesetDialog->fullSymbolName) - || editor->project->tilesetLabels.value("secondary").contains(createTilesetDialog->fullSymbolName)) { + if (editor->project->tilesetLabelsOrdered.contains(createTilesetDialog->fullSymbolName)) { logError(QString("Could not create tileset \"%1\", the symbol \"%2\" already exists.").arg(createTilesetDialog->friendlyName, createTilesetDialog->fullSymbolName)); QMessageBox msgBox(this); msgBox.setText("Failed to add new tileset."); @@ -2547,7 +2546,7 @@ void MainWindow::on_comboBox_EmergeMap_currentTextChanged(const QString &mapName void MainWindow::on_comboBox_PrimaryTileset_currentTextChanged(const QString &tilesetLabel) { - if (editor->project->tilesetLabels["primary"].contains(tilesetLabel) && editor->map) { + if (editor->project->primaryTilesetLabels.contains(tilesetLabel) && editor->map) { editor->updatePrimaryTileset(tilesetLabel); redrawMapScene(); on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value()); @@ -2559,7 +2558,7 @@ void MainWindow::on_comboBox_PrimaryTileset_currentTextChanged(const QString &ti void MainWindow::on_comboBox_SecondaryTileset_currentTextChanged(const QString &tilesetLabel) { - if (editor->project->tilesetLabels["secondary"].contains(tilesetLabel) && editor->map) { + if (editor->project->secondaryTilesetLabels.contains(tilesetLabel) && editor->map) { editor->updateSecondaryTileset(tilesetLabel); redrawMapScene(); on_horizontalSlider_MetatileZoom_valueChanged(ui->horizontalSlider_MetatileZoom->value()); diff --git a/src/project.cpp b/src/project.cpp index f5f58261..2486f7bc 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -601,8 +601,8 @@ void Project::setNewMapLayout(Map* map) { layout->border_height = DEFAULT_BORDER_HEIGHT; layout->border_path = QString("%2%1/border.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders)); layout->blockdata_path = QString("%2%1/map.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders)); - layout->tileset_primary_label = tilesetLabels["primary"].value(0, "gTileset_General"); - layout->tileset_secondary_label = tilesetLabels["secondary"].value(0, projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg"); + layout->tileset_primary_label = this->primaryTilesetLabels.value(0, "gTileset_General"); + layout->tileset_secondary_label = this->secondaryTilesetLabels.value(0, projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg"); map->layout = layout; map->layoutId = layout->id; @@ -1046,7 +1046,7 @@ void Project::saveTilesetPalettes(Tileset *tileset) { bool Project::loadLayoutTilesets(MapLayout *layout) { layout->tileset_primary = getTileset(layout->tileset_primary_label); if (!layout->tileset_primary) { - QString defaultTileset = tilesetLabels["primary"].value(0, "gTileset_General"); + QString defaultTileset = primaryTilesetLabels.value(0, "gTileset_General"); logWarn(QString("Map layout %1 has invalid primary tileset '%2'. Using default '%3'").arg(layout->id).arg(layout->tileset_primary_label).arg(defaultTileset)); layout->tileset_primary_label = defaultTileset; layout->tileset_primary = getTileset(layout->tileset_primary_label); @@ -1058,7 +1058,7 @@ bool Project::loadLayoutTilesets(MapLayout *layout) { layout->tileset_secondary = getTileset(layout->tileset_secondary_label); if (!layout->tileset_secondary) { - QString defaultTileset = tilesetLabels["secondary"].value(0, projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg"); + QString defaultTileset = secondaryTilesetLabels.value(0, projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg"); logWarn(QString("Map layout %1 has invalid secondary tileset '%2'. Using default '%3'").arg(layout->id).arg(layout->tileset_secondary_label).arg(defaultTileset)); layout->tileset_secondary_label = defaultTileset; layout->tileset_secondary = getTileset(layout->tileset_secondary_label); @@ -1851,8 +1851,10 @@ Project::DataQualifiers Project::getDataQualifiers(QString text, QString label) } void Project::insertTilesetLabel(QString label, bool isSecondary) { - QString category = isSecondary ? "secondary" : "primary"; - this->tilesetLabels[category].append(label); + if (isSecondary) + this->primaryTilesetLabels.append(label); + else + this->secondaryTilesetLabels.append(label); this->tilesetLabelsOrdered.append(label); } @@ -1869,9 +1871,8 @@ void Project::insertTilesetLabel(QString label, QString isSecondaryStr) { bool Project::readTilesetLabels() { QStringList primaryTilesets; QStringList secondaryTilesets; - this->tilesetLabels.clear(); - this->tilesetLabels.insert("primary", primaryTilesets); - this->tilesetLabels.insert("secondary", secondaryTilesets); + this->primaryTilesetLabels.clear(); + this->secondaryTilesetLabels.clear(); this->tilesetLabelsOrdered.clear(); QString filename = projectConfig.getFilePath(ProjectFilePath::tilesets_headers); @@ -1903,11 +1904,11 @@ bool Project::readTilesetLabels() { } bool success = true; - if (this->tilesetLabels["secondary"].isEmpty()) { + if (this->secondaryTilesetLabels.isEmpty()) { logError(QString("Failed to find any secondary tilesets in %1").arg(filename)); success = false; } - if (this->tilesetLabels["primary"].isEmpty()) { + if (this->primaryTilesetLabels.isEmpty()) { logError(QString("Failed to find any primary tilesets in %1").arg(filename)); success = false; } diff --git a/src/scriptapi/apiutility.cpp b/src/scriptapi/apiutility.cpp index c37fb2c5..7445a67d 100644 --- a/src/scriptapi/apiutility.cpp +++ b/src/scriptapi/apiutility.cpp @@ -226,13 +226,13 @@ QList ScriptUtility::getTilesetNames() { QList ScriptUtility::getPrimaryTilesetNames() { if (!window || !window->editor || !window->editor->project) return QList(); - return window->editor->project->tilesetLabels["primary"]; + return window->editor->project->primaryTilesetLabels; } QList ScriptUtility::getSecondaryTilesetNames() { if (!window || !window->editor || !window->editor->project) return QList(); - return window->editor->project->tilesetLabels["secondary"]; + return window->editor->project->secondaryTilesetLabels; } QList ScriptUtility::getMetatileBehaviorNames() { diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index 1ffabf68..9f0c765f 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -108,8 +108,8 @@ void NewMapPopup::useLayout(QString layoutId) { void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { ui->lineEdit_NewMap_Name->setText(project->getNewMapName()); - ui->comboBox_NewMap_Primary_Tileset->addItems(project->tilesetLabels.value("primary")); - ui->comboBox_NewMap_Secondary_Tileset->addItems(project->tilesetLabels.value("secondary")); + ui->comboBox_NewMap_Primary_Tileset->addItems(project->primaryTilesetLabels); + ui->comboBox_NewMap_Secondary_Tileset->addItems(project->secondaryTilesetLabels); ui->comboBox_NewMap_Group->addItems(project->groupNames); ui->comboBox_NewMap_Group->setCurrentText(project->groupNames.at(groupNum)); @@ -147,8 +147,8 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) { ui->lineEdit_NewMap_Name->setText(project->getNewMapName()); - ui->comboBox_NewMap_Primary_Tileset->addItems(project->tilesetLabels.value("primary")); - ui->comboBox_NewMap_Secondary_Tileset->addItems(project->tilesetLabels.value("secondary")); + ui->comboBox_NewMap_Primary_Tileset->addItems(project->primaryTilesetLabels); + ui->comboBox_NewMap_Secondary_Tileset->addItems(project->secondaryTilesetLabels); ui->comboBox_NewMap_Group->addItems(project->groupNames); ui->comboBox_NewMap_Group->setCurrentText(project->groupNames.at(0)); From f8a92c071c977c80d8fd10cdf29fcda4381cfe9e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 23 Oct 2022 19:28:55 -0400 Subject: [PATCH 02/10] Add default tileset config options --- include/config.h | 5 +++++ include/project.h | 4 +++- src/config.cpp | 27 +++++++++++++++---------- src/project.cpp | 46 +++++++++++++++++++++--------------------- src/ui/newmappopup.cpp | 4 ++++ 5 files changed, 51 insertions(+), 35 deletions(-) diff --git a/include/config.h b/include/config.h index ed86019f..3206e034 100644 --- a/include/config.h +++ b/include/config.h @@ -209,6 +209,7 @@ public: this->newMapMetatileId = 1; this->newMapElevation = 3; this->newMapBorderMetatileIds = DEFAULT_BORDER_RSE; + this->defaultPrimaryTileset = "gTileset_General"; this->prefabFilepath = QString(); this->prefabImportPrompted = false; this->tilesetsHaveCallback = true; @@ -251,6 +252,8 @@ public: int getNewMapElevation(); void setNewMapBorderMetatileIds(QList metatileIds); QList getNewMapBorderMetatileIds(); + QString getDefaultPrimaryTileset(); + QString getDefaultSecondaryTileset(); void setFilePath(ProjectFilePath pathId, QString path); QString getFilePath(ProjectFilePath pathId); void setPrefabFilepath(QString filepath); @@ -285,6 +288,8 @@ private: int newMapMetatileId; int newMapElevation; QList newMapBorderMetatileIds; + QString defaultPrimaryTileset; + QString defaultSecondaryTileset; QStringList readKeys; QString prefabFilepath; bool prefabImportPrompted; diff --git a/include/project.h b/include/project.h index 8d892cfd..ed009374 100644 --- a/include/project.h +++ b/include/project.h @@ -211,6 +211,9 @@ public: QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels); QStringList getGlobalScriptLabels(); + QString getDefaultPrimaryTilesetLabel(); + QString getDefaultSecondaryTilesetLabel(); + static int getNumTilesPrimary(); static int getNumTilesTotal(); static int getNumMetatilesPrimary(); @@ -230,7 +233,6 @@ private: void updateMapLayout(Map*); void setNewMapHeader(Map* map, int mapIndex); - void setNewMapLayout(Map* map); void setNewMapBlockdata(Map* map); void setNewMapBorder(Map *map); void setNewMapEvents(Map *map); diff --git a/src/config.cpp b/src/config.cpp index 9beac865..335329eb 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -545,6 +545,10 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) { // Set any metatiles not provided to 0 this->newMapBorderMetatileIds.append(0); } + } else if (key == "default_primary_tileset") { + this->defaultPrimaryTileset = value; + } else if (key == "default_secondary_tileset") { + this->defaultSecondaryTileset = value; #ifdef CONFIG_BACKWARDS_COMPATABILITY } else if (key == "recent_map") { userConfig.setRecentMap(value); @@ -594,6 +598,7 @@ void ProjectConfig::setUnreadKeys() { if (!readKeys.contains("enable_floor_number")) this->enableFloorNumber = isPokefirered; if (!readKeys.contains("create_map_text_file")) this->createMapTextFile = (this->baseGameVersion != BaseGameVersion::pokeemerald); if (!readKeys.contains("new_map_border_metatiles")) this->newMapBorderMetatileIds = isPokefirered ? DEFAULT_BORDER_FRLG : DEFAULT_BORDER_RSE; + if (!readKeys.contains("default_secondary_tileset")) this->defaultSecondaryTileset = isPokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg"; } QMap ProjectConfig::getKeyValueMap() { @@ -616,6 +621,8 @@ QMap ProjectConfig::getKeyValueMap() { for (auto metatile : this->newMapBorderMetatileIds) metatiles << QString::number(metatile); map.insert("new_map_border_metatiles", metatiles.join(",")); + map.insert("default_primary_tileset", this->defaultPrimaryTileset); + map.insert("default_secondary_tileset", this->defaultSecondaryTileset); map.insert("prefabs_filepath", this->prefabFilepath); map.insert("prefabs_import_prompted", QString::number(this->prefabImportPrompted)); for (auto it = this->filePaths.constKeyValueBegin(); it != this->filePaths.constKeyValueEnd(); ++it) { @@ -652,17 +659,7 @@ void ProjectConfig::onNewConfigFileCreated() { this->baseGameVersion = static_cast(baseGameVersionComboBox->currentData().toInt()); } } - bool isPokefirered = this->baseGameVersion == BaseGameVersion::pokefirered; - this->useCustomBorderSize = isPokefirered; - this->enableEventWeatherTrigger = !isPokefirered; - this->enableEventSecretBase = !isPokefirered; - this->enableHiddenItemQuantity = isPokefirered; - this->enableHiddenItemRequiresItemfinder = isPokefirered; - this->enableHealLocationRespawnData = isPokefirered; - this->enableEventCloneObject = isPokefirered; - this->enableFloorNumber = isPokefirered; - this->createMapTextFile = (this->baseGameVersion != BaseGameVersion::pokeemerald); - this->newMapBorderMetatileIds = isPokefirered ? DEFAULT_BORDER_FRLG : DEFAULT_BORDER_RSE; + this->setUnreadKeys(); // Initialize version-specific options } void ProjectConfig::setProjectDir(QString projectDir) { @@ -835,6 +832,14 @@ QList ProjectConfig::getNewMapBorderMetatileIds() { return this->newMapBorderMetatileIds; } +QString ProjectConfig::getDefaultPrimaryTileset() { + return this->defaultPrimaryTileset; +} + +QString ProjectConfig::getDefaultSecondaryTileset() { + return this->defaultSecondaryTileset; +} + void ProjectConfig::setPrefabFilepath(QString filepath) { this->prefabFilepath = filepath; this->save(); diff --git a/src/project.cpp b/src/project.cpp index 2486f7bc..84fe470a 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -591,26 +591,6 @@ void Project::ignoreWatchedFileTemporarily(QString filepath) { modifiedFileTimestamps.insert(filepath, QDateTime::currentMSecsSinceEpoch() + 5000); } -void Project::setNewMapLayout(Map* map) { - MapLayout *layout = new MapLayout(); - layout->id = MapLayout::layoutConstantFromName(map->name); - layout->name = QString("%1_Layout").arg(map->name); - layout->width = getDefaultMapSize(); - layout->height = getDefaultMapSize(); - layout->border_width = DEFAULT_BORDER_WIDTH; - layout->border_height = DEFAULT_BORDER_HEIGHT; - layout->border_path = QString("%2%1/border.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders)); - layout->blockdata_path = QString("%2%1/map.bin").arg(map->name).arg(projectConfig.getFilePath(ProjectFilePath::data_layouts_folders)); - layout->tileset_primary_label = this->primaryTilesetLabels.value(0, "gTileset_General"); - layout->tileset_secondary_label = this->secondaryTilesetLabels.value(0, projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg"); - map->layout = layout; - map->layoutId = layout->id; - - // Insert new entry into the global map layouts. - mapLayouts.insert(layout->id, layout); - mapLayoutsTable.append(layout->id); -} - void Project::saveMapGroups() { QString mapGroupsFilepath = QString("%1/%2").arg(root).arg(projectConfig.getFilePath(ProjectFilePath::json_map_groups)); QFile mapGroupsFile(mapGroupsFilepath); @@ -1046,7 +1026,7 @@ void Project::saveTilesetPalettes(Tileset *tileset) { bool Project::loadLayoutTilesets(MapLayout *layout) { layout->tileset_primary = getTileset(layout->tileset_primary_label); if (!layout->tileset_primary) { - QString defaultTileset = primaryTilesetLabels.value(0, "gTileset_General"); + QString defaultTileset = this->getDefaultPrimaryTilesetLabel(); logWarn(QString("Map layout %1 has invalid primary tileset '%2'. Using default '%3'").arg(layout->id).arg(layout->tileset_primary_label).arg(defaultTileset)); layout->tileset_primary_label = defaultTileset; layout->tileset_primary = getTileset(layout->tileset_primary_label); @@ -1058,7 +1038,7 @@ bool Project::loadLayoutTilesets(MapLayout *layout) { layout->tileset_secondary = getTileset(layout->tileset_secondary_label); if (!layout->tileset_secondary) { - QString defaultTileset = secondaryTilesetLabels.value(0, projectConfig.getBaseGameVersion() == BaseGameVersion::pokefirered ? "gTileset_PalletTown" : "gTileset_Petalburg"); + QString defaultTileset = this->getDefaultSecondaryTilesetLabel(); logWarn(QString("Map layout %1 has invalid secondary tileset '%2'. Using default '%3'").arg(layout->id).arg(layout->tileset_secondary_label).arg(defaultTileset)); layout->tileset_secondary_label = defaultTileset; layout->tileset_secondary = getTileset(layout->tileset_secondary_label); @@ -1850,8 +1830,28 @@ Project::DataQualifiers Project::getDataQualifiers(QString text, QString label) return qualifiers; } +QString Project::getDefaultPrimaryTilesetLabel() { + QString defaultLabel = projectConfig.getDefaultPrimaryTileset(); + if (!this->primaryTilesetLabels.contains(defaultLabel)) { + QString firstLabel = this->primaryTilesetLabels.first(); + logWarn(QString("Unable to find default primary tileset '%1', using '%2' instead.").arg(defaultLabel).arg(firstLabel)); + defaultLabel = firstLabel; + } + return defaultLabel; +} + +QString Project::getDefaultSecondaryTilesetLabel() { + QString defaultLabel = projectConfig.getDefaultSecondaryTileset(); + if (!this->secondaryTilesetLabels.contains(defaultLabel)) { + QString firstLabel = this->secondaryTilesetLabels.first(); + logWarn(QString("Unable to find default secondary tileset '%1', using '%2' instead.").arg(defaultLabel).arg(firstLabel)); + defaultLabel = firstLabel; + } + return defaultLabel; +} + void Project::insertTilesetLabel(QString label, bool isSecondary) { - if (isSecondary) + if (!isSecondary) this->primaryTilesetLabels.append(label); else this->secondaryTilesetLabels.append(label); diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index 9f0c765f..c3821d9c 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -132,6 +132,10 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { ui->spinBox_NewMap_Height->setValue(project->getDefaultMapSize()); ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH); ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT); + int primaryIdx = ui->comboBox_NewMap_Primary_Tileset->findText(project->getDefaultPrimaryTilesetLabel()); + int secondaryIdx = ui->comboBox_NewMap_Secondary_Tileset->findText(project->getDefaultSecondaryTilesetLabel()); + ui->comboBox_NewMap_Primary_Tileset->setCurrentIndex(primaryIdx); + ui->comboBox_NewMap_Secondary_Tileset->setCurrentIndex(secondaryIdx); } ui->comboBox_NewMap_Type->addItems(project->mapTypes); From 1728e708dd85a5b1d7a045f62c0353828f9efb86 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 23 Oct 2022 19:47:40 -0400 Subject: [PATCH 03/10] Update changelog/manual --- CHANGELOG.md | 3 +-- docsrc/manual/settings-and-options.rst | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index da41ed29..d90e3c20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Add Cut/Copy/Paste for metatiles in the Tileset Editor. - Add button to copy the full metatile label to the clipboard in the Tileset Editor. - Add ability to export an image of the primary or secondary tileset's metatiles. -- Add option to not open the most recent project on launch. -- Add options for customizing how new maps are filled +- Add new config options for customizing how new maps are filled, setting default tilesets, and whether the most recent project should be opened on launch. - Add color picker to palette editor for taking colors from the screen. - Add new features to the scripting API, including the ability to display messages and user input windows, set the overlay's opacity, rotation, scale, and clipping, interact with map header properties and the map border, read tile pixel data, and more. diff --git a/docsrc/manual/settings-and-options.rst b/docsrc/manual/settings-and-options.rst index 198fdb56..2d85ed0b 100644 --- a/docsrc/manual/settings-and-options.rst +++ b/docsrc/manual/settings-and-options.rst @@ -52,6 +52,8 @@ your project root as ``porymap.user.cfg``. You should add this file to your giti ``new_map_metatile``, 1, project, yes, The metatile id that will be used to fill new maps ``new_map_elevation``, 3, project, yes, The elevation that will be used to fill new maps ``new_map_border_metatiles``, "``468,469,476,477`` or ``20,21,28,29``", project, yes, The list of metatile ids that will be used to fill the 2x2 border of new maps + ``default_primary_tileset``, ``gTileset_General``, project, yes, The label of the default primary tileset + ``default_secondary_tileset``, ``gTileset_Petalburg`` or ``gTileset_PalletTown``, project, yes, The label of the default secondary tileset ``custom_scripts``, , user, yes, A list of script files to load into the scripting engine ``prefabs_filepath``, ``/prefabs.json``, project, yes, The filepath containing prefab JSON data ``prefabs_import_prompted``, 0, project, no, Keeps track of whether or not the project was prompted for importing default prefabs From 5ba372040566a6b1d70cdd338a07020b125f22d4 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 23 Oct 2022 23:38:27 -0400 Subject: [PATCH 04/10] is_secondary to bool --- include/core/tileset.h | 2 +- src/core/tileset.cpp | 9 +++++---- src/mainwindow.cpp | 2 +- src/project.cpp | 7 ++++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/core/tileset.h b/include/core/tileset.h index f3ba70ba..2c6d658e 100644 --- a/include/core/tileset.h +++ b/include/core/tileset.h @@ -15,7 +15,7 @@ public: public: QString name; - QString is_secondary; + bool is_secondary; QString tiles_label; QString palettes_label; QString metatiles_label; diff --git a/src/core/tileset.cpp b/src/core/tileset.cpp index 96344f55..adfb0a13 100644 --- a/src/core/tileset.cpp +++ b/src/core/tileset.cpp @@ -128,19 +128,20 @@ QList Tileset::getPalette(int paletteId, Tileset *primaryTileset, Tileset bool Tileset::appendToHeaders(QString root, QString friendlyName, bool usingAsm) { QString headersFile = root + "/" + (usingAsm ? projectConfig.getFilePath(ProjectFilePath::tilesets_headers_asm) - : projectConfig.getFilePath(ProjectFilePath::tilesets_headers)); + : projectConfig.getFilePath(ProjectFilePath::tilesets_headers)); QFile file(headersFile); if (!file.open(QIODevice::WriteOnly | QIODevice::Append)) { logError(QString("Could not write to file \"%1\"").arg(headersFile)); return false; } + QString isSecondaryStr = this->is_secondary ? "TRUE" : "FALSE"; QString dataString = "\n"; if (usingAsm) { // Append to asm file dataString.append("\t.align 2\n"); dataString.append(QString("%1::\n").arg(this->name)); dataString.append("\t.byte TRUE @ is compressed\n"); - dataString.append(QString("\t.byte %1 @ is secondary\n").arg(this->is_secondary)); + dataString.append(QString("\t.byte %1 @ is secondary\n").arg(isSecondaryStr)); dataString.append("\t.2byte 0 @ padding\n"); dataString.append(QString("\t.4byte gTilesetTiles_%1\n").arg(friendlyName)); dataString.append(QString("\t.4byte gTilesetPalettes_%1\n").arg(friendlyName)); @@ -156,7 +157,7 @@ bool Tileset::appendToHeaders(QString root, QString friendlyName, bool usingAsm) // Append to C file dataString.append(QString("const struct Tileset %1 =\n{\n").arg(this->name)); if (projectConfig.getTilesetsHaveIsCompressed()) dataString.append(" .isCompressed = TRUE,\n"); - dataString.append(QString(" .isSecondary = %1,\n").arg(this->is_secondary)); + dataString.append(QString(" .isSecondary = %1,\n").arg(isSecondaryStr)); dataString.append(QString(" .tiles = gTilesetTiles_%1,\n").arg(friendlyName)); dataString.append(QString(" .palettes = gTilesetPalettes_%1,\n").arg(friendlyName)); dataString.append(QString(" .metatiles = gMetatiles_%1,\n").arg(friendlyName)); @@ -245,7 +246,7 @@ bool Tileset::appendToMetatiles(QString root, QString friendlyName, bool usingAs // Example: for gTileset_DepartmentStore, returns "data/tilesets/secondary/department_store" QString Tileset::getExpectedDir() { - return Tileset::getExpectedDir(this->name, ParseUtil::gameStringToBool(this->is_secondary)); + return Tileset::getExpectedDir(this->name, this->is_secondary); } QString Tileset::getExpectedDir(QString tilesetName, bool isSecondary) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bea01b5d..c01eda47 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1284,7 +1284,7 @@ void MainWindow::on_actionNew_Tileset_triggered() { newSet.tilesImagePath = fullDirectoryPath + "/tiles.png"; newSet.metatiles_path = fullDirectoryPath + "/metatiles.bin"; newSet.metatile_attrs_path = fullDirectoryPath + "/metatile_attributes.bin"; - newSet.is_secondary = createTilesetDialog->isSecondary ? "TRUE" : "FALSE"; + newSet.is_secondary = createTilesetDialog->isSecondary; int numMetaTiles = createTilesetDialog->isSecondary ? (Project::getNumTilesTotal() - Project::getNumTilesPrimary()) : Project::getNumTilesPrimary(); QImage tilesImage(":/images/blank_tileset.png"); editor->project->loadTilesetTiles(&newSet, tilesImage); diff --git a/src/project.cpp b/src/project.cpp index 84fe470a..a09ceaaa 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1062,7 +1062,7 @@ Tileset* Project::loadTileset(QString label, Tileset *tileset) { tileset = new Tileset; } tileset->name = label; - tileset->is_secondary = values.value(memberMap.key("isSecondary")); + tileset->is_secondary = ParseUtil::gameStringToBool(values.value(memberMap.key("isSecondary"))); tileset->tiles_label = values.value(memberMap.key("tiles")); tileset->palettes_label = values.value(memberMap.key("palettes")); tileset->metatiles_label = values.value(memberMap.key("metatiles")); @@ -1078,7 +1078,7 @@ Tileset* Project::loadTileset(QString label, Tileset *tileset) { } const auto tilesetAttributes = structs[label]; tileset->name = label; - tileset->is_secondary = tilesetAttributes.value("isSecondary"); + tileset->is_secondary = ParseUtil::gameStringToBool(tilesetAttributes.value("isSecondary")); tileset->tiles_label = tilesetAttributes.value("tiles"); tileset->palettes_label = tilesetAttributes.value("palettes"); tileset->metatiles_label = tilesetAttributes.value("metatiles"); @@ -1568,7 +1568,8 @@ void Project::loadTilesetMetatileLabels(Tileset* tileset) { for (QString labelName : labels.keys()) { int metatileId = labels[labelName]; // subtract Project::num_tiles_primary from secondary metatiles - Metatile *metatile = Tileset::getMetatile(metatileId - (ParseUtil::gameStringToBool(tileset->is_secondary) ? Project::num_tiles_primary : 0), tileset, nullptr); + int offset = tileset->is_secondary ? Project::num_tiles_primary : 0; + Metatile *metatile = Tileset::getMetatile(metatileId - offset, tileset, nullptr); if (metatile) { metatile->label = labelName.replace(tilesetPrefix, ""); } else { From 09ce5b59138424cb5155244dd051864d33660c55 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 24 Oct 2022 08:03:51 -0400 Subject: [PATCH 05/10] Drop path_ from path config options --- docsrc/manual/project-files.rst | 4 ++-- include/config.h | 4 ++-- src/config.cpp | 4 ++-- src/project.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docsrc/manual/project-files.rst b/docsrc/manual/project-files.rst index 0540716f..78a899dc 100644 --- a/docsrc/manual/project-files.rst +++ b/docsrc/manual/project-files.rst @@ -57,7 +57,7 @@ For example if you wanted to rename ``include/constants/items.h`` to ``headers/d include/constants/metatile_labels.h, yes, yes, ``constants_metatile_labels``, include/constants/metatile_behaviors.h, yes, no, ``constants_metatile_behaviors``, include/fieldmap.h, yes, no, ``constants_fieldmap``, reads tileset related constants - src/event_object_movement.c, yes, no, ``path_initial_facing_table``, reads ``gInitialMovementTypeFacingDirections`` - src/pokemon_icon.c, yes, no, ``path_pokemon_icon_table``, reads files in ``gMonIconTable`` + src/event_object_movement.c, yes, no, ``initial_facing_table``, reads ``gInitialMovementTypeFacingDirections`` + src/pokemon_icon.c, yes, no, ``pokemon_icon_table``, reads files in ``gMonIconTable`` diff --git a/include/config.h b/include/config.h index 3206e034..f7ff9a9d 100644 --- a/include/config.h +++ b/include/config.h @@ -183,8 +183,8 @@ enum ProjectFilePath { constants_metatile_labels, constants_metatile_behaviors, constants_fieldmap, - path_initial_facing_table, - path_pokemon_icon_table, + initial_facing_table, + pokemon_icon_table, }; class ProjectConfig: public KeyValueConfigBase diff --git a/src/config.cpp b/src/config.cpp index 335329eb..a9ce994e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -59,8 +59,8 @@ const QMap> defaultPaths = { {ProjectFilePath::constants_metatile_labels, { "constants_metatile_labels", "include/constants/metatile_labels.h"}}, {ProjectFilePath::constants_metatile_behaviors, { "constants_metatile_behaviors", "include/constants/metatile_behaviors.h"}}, {ProjectFilePath::constants_fieldmap, { "constants_fieldmap", "include/fieldmap.h"}}, - {ProjectFilePath::path_pokemon_icon_table, { "path_pokemon_icon_table", "src/pokemon_icon.c"}}, - {ProjectFilePath::path_initial_facing_table, { "path_initial_facing_table", "src/event_object_movement.c"}}, + {ProjectFilePath::pokemon_icon_table, { "pokemon_icon_table", "src/pokemon_icon.c"}}, + {ProjectFilePath::initial_facing_table, { "initial_facing_table", "src/event_object_movement.c"}}, }; ProjectFilePath reverseDefaultPaths(QString str) { diff --git a/src/project.cpp b/src/project.cpp index a09ceaaa..1ae57898 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -2166,7 +2166,7 @@ bool Project::readMovementTypes() { } bool Project::readInitialFacingDirections() { - QString filename = projectConfig.getFilePath(ProjectFilePath::path_initial_facing_table); + QString filename = projectConfig.getFilePath(ProjectFilePath::initial_facing_table); fileWatcher.addPath(root + "/" + filename); facingDirections = parser.readNamedIndexCArray(filename, "gInitialMovementTypeFacingDirections"); if (facingDirections.isEmpty()) { @@ -2507,7 +2507,7 @@ bool Project::readEventGraphics() { bool Project::readSpeciesIconPaths() { speciesToIconPath.clear(); - QString srcfilename = projectConfig.getFilePath(ProjectFilePath::path_pokemon_icon_table); + QString srcfilename = projectConfig.getFilePath(ProjectFilePath::pokemon_icon_table); QString incfilename = projectConfig.getFilePath(ProjectFilePath::data_pokemon_gfx); fileWatcher.addPath(root + "/" + srcfilename); fileWatcher.addPath(root + "/" + incfilename); From 8fbcee7f2156350e2bfa6d16bbbe62194f36ca09 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 24 Oct 2022 09:33:51 -0400 Subject: [PATCH 06/10] Insert new tilesets in sorted order --- include/mainwindow.h | 1 + include/project.h | 3 +-- src/mainwindow.cpp | 19 +++++++++++++++---- src/project.cpp | 18 ++++++------------ 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index b8653d58..973c3ed3 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -389,6 +389,7 @@ private: QObjectList shortcutableObjects() const; void addCustomHeaderValue(QString key, QJsonValue value, bool isNew = false); + int insertTilesetLabel(QStringList * list, QString label); }; enum MapListUserRoles { diff --git a/include/project.h b/include/project.h index ed009374..c5599489 100644 --- a/include/project.h +++ b/include/project.h @@ -171,8 +171,7 @@ public: QString defaultSong; QStringList getVisibilities(); - void insertTilesetLabel(QString label, bool isSecondary); - void insertTilesetLabel(QString label, QString isSecondaryStr); + void appendTilesetLabel(QString label, QString isSecondaryStr); bool readTilesetLabels(); bool readTilesetProperties(); bool readMaxMapDataSize(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c01eda47..cd3b62d0 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1239,6 +1239,15 @@ void MainWindow::on_action_NewMap_triggered() { openNewMapPopupWindow(MapSortOrder::Group, 0); } +// Insert label for newly-created tileset into sorted list of existing labels +int MainWindow::insertTilesetLabel(QStringList * list, QString label) { + int i = 0; + for (; i < list->length(); i++) + if (list->at(i) > label) break; + list->insert(i, label); + return i; +} + void MainWindow::on_actionNew_Tileset_triggered() { NewTilesetDialog *createTilesetDialog = new NewTilesetDialog(editor->project, this); if(createTilesetDialog->exec() == QDialog::Accepted){ @@ -1324,12 +1333,14 @@ void MainWindow::on_actionNew_Tileset_triggered() { newSet.appendToGraphics(editor->project->root, createTilesetDialog->friendlyName, editor->project->usingAsmTilesets); newSet.appendToMetatiles(editor->project->root, createTilesetDialog->friendlyName, editor->project->usingAsmTilesets); - if(!createTilesetDialog->isSecondary) { - this->ui->comboBox_PrimaryTileset->addItem(createTilesetDialog->fullSymbolName); + if (!createTilesetDialog->isSecondary) { + int index = insertTilesetLabel(&editor->project->primaryTilesetLabels, createTilesetDialog->fullSymbolName); + this->ui->comboBox_PrimaryTileset->insertItem(index, createTilesetDialog->fullSymbolName); } else { - this->ui->comboBox_SecondaryTileset->addItem(createTilesetDialog->fullSymbolName); + int index = insertTilesetLabel(&editor->project->secondaryTilesetLabels, createTilesetDialog->fullSymbolName); + this->ui->comboBox_SecondaryTileset->insertItem(index, createTilesetDialog->fullSymbolName); } - editor->project->insertTilesetLabel(createTilesetDialog->fullSymbolName, createTilesetDialog->isSecondary); + insertTilesetLabel(&editor->project->tilesetLabelsOrdered, createTilesetDialog->fullSymbolName); QMessageBox msgBox(this); msgBox.setText("Successfully created tileset."); diff --git a/src/project.cpp b/src/project.cpp index 1ae57898..af90cd9d 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1851,22 +1851,16 @@ QString Project::getDefaultSecondaryTilesetLabel() { return defaultLabel; } -void Project::insertTilesetLabel(QString label, bool isSecondary) { - if (!isSecondary) - this->primaryTilesetLabels.append(label); - else - this->secondaryTilesetLabels.append(label); - this->tilesetLabelsOrdered.append(label); -} - -void Project::insertTilesetLabel(QString label, QString isSecondaryStr) { +void Project::appendTilesetLabel(QString label, QString isSecondaryStr) { bool ok; bool isSecondary = ParseUtil::gameStringToBool(isSecondaryStr, &ok); if (!ok) { logError(QString("Unable to convert value '%1' of isSecondary to bool for tileset %2.").arg(isSecondaryStr).arg(label)); return; } - insertTilesetLabel(label, isSecondary); + QStringList * list = isSecondary ? &this->secondaryTilesetLabels : &this->primaryTilesetLabels; + list->append(label); + this->tilesetLabelsOrdered.append(label); } bool Project::readTilesetLabels() { @@ -1891,7 +1885,7 @@ bool Project::readTilesetLabels() { QRegularExpressionMatchIterator iter = re.globalMatch(text); while (iter.hasNext()) { QRegularExpressionMatch match = iter.next(); - insertTilesetLabel(match.captured("label"), match.captured("isSecondary")); + appendTilesetLabel(match.captured("label"), match.captured("isSecondary")); } filename = asm_filename; // For error reporting further down } else { @@ -1900,7 +1894,7 @@ bool Project::readTilesetLabels() { QStringList labels = structs.keys(); // TODO: This is alphabetical, AdvanceMap import wants the vanilla order in tilesetLabelsOrdered for (const auto tilesetLabel : labels){ - insertTilesetLabel(tilesetLabel, structs[tilesetLabel].value("isSecondary")); + appendTilesetLabel(tilesetLabel, structs[tilesetLabel].value("isSecondary")); } } From d451aaa8c05b40d86547111c10981eb40bcabc6e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 24 Oct 2022 15:23:53 -0400 Subject: [PATCH 07/10] Simplify new map popup internal --- forms/newmappopup.ui | 2 +- include/mainwindow.h | 3 +- include/ui/newmappopup.h | 27 +++++- src/mainwindow.cpp | 20 ++-- src/ui/newmappopup.cpp | 202 ++++++++++++++++++--------------------- 5 files changed, 124 insertions(+), 130 deletions(-) diff --git a/forms/newmappopup.ui b/forms/newmappopup.ui index 32369f57..b102b1cc 100644 --- a/forms/newmappopup.ui +++ b/forms/newmappopup.ui @@ -217,7 +217,7 @@ - + <html><head/><body><p>The default background music for this map.</p></body></html> diff --git a/include/mainwindow.h b/include/mainwindow.h index 973c3ed3..8aaf8a65 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -176,7 +176,7 @@ private slots: void onMapNeedsRedrawing(); void onTilesetsSaved(QString, QString); void onWildMonDataChanged(); - void openNewMapPopupWindow(int, QVariant); + void openNewMapPopupWindow(MapSortOrder, QVariant); void openNewMapPopupWindowImportMap(MapLayout *); void onNewMapCreated(); void onMapCacheCleared(); @@ -330,6 +330,7 @@ private: bool isProgrammaticEventTabChange; bool projectHasUnsavedChanges; bool projectOpenFailure = false; + bool openedNewMapDialog = false; MapSortOrder mapSortOrder; diff --git a/include/ui/newmappopup.h b/include/ui/newmappopup.h index 5c4f5761..95565276 100644 --- a/include/ui/newmappopup.h +++ b/include/ui/newmappopup.h @@ -22,10 +22,10 @@ public: bool existingLayout; bool importedMap; QString layoutId; - void init(int, int, QString, QString); + void init(MapSortOrder type, QVariant data); void initImportMap(MapLayout *); - void useLayout(QString); void connectSignals(); + static void initSettings(Project *project); signals: void applied(); @@ -35,9 +35,30 @@ private: Project *project; void setDefaultValues(int, QString); void setDefaultValuesImportMap(MapLayout *); - void setDefaultValuesProjectConfig(bool, MapLayout*); + void setDefaultValuesProjectConfig(); bool checkNewMapDimensions(); bool checkNewMapGroup(); + void populateComboBoxes(); + + struct Settings { + QString group; + int width; + int height; + int borderWidth; + int borderHeight; + QString primaryTileset; + QString secondaryTileset; + QString type; + QString location; + QString song; + bool canFlyTo; + bool showLocationName; + bool allowRunning; + bool allowBiking; + bool allowEscaping; + int floorNumber; + }; + static struct Settings settings; private slots: void on_pushButton_NewMap_Accept_clicked(); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cd3b62d0..2390f390 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1191,7 +1191,10 @@ void MainWindow::onNewMapCreated() { delete newMap; } -void MainWindow::openNewMapPopupWindow(int type, QVariant data) { +void MainWindow::openNewMapPopupWindow(MapSortOrder type, QVariant data) { + if (!openedNewMapDialog) { + NewMapPopup::initSettings(this->editor->project); + } if (!this->newMapPrompt) { this->newMapPrompt = new NewMapPopup(this, this->editor->project); } @@ -1201,18 +1204,7 @@ void MainWindow::openNewMapPopupWindow(int type, QVariant data) { this->newMapPrompt->raise(); this->newMapPrompt->activateWindow(); } - switch (type) - { - case MapSortOrder::Group: - this->newMapPrompt->init(type, data.toInt(), QString(), QString()); - break; - case MapSortOrder::Area: - this->newMapPrompt->init(type, 0, data.toString(), QString()); - break; - case MapSortOrder::Layout: - this->newMapPrompt->init(type, 0, QString(), data.toString()); - break; - } + this->newMapPrompt->init(type, data); connect(this->newMapPrompt, &NewMapPopup::applied, this, &MainWindow::onNewMapCreated); this->newMapPrompt->setAttribute(Qt::WA_DeleteOnClose); } @@ -1232,7 +1224,7 @@ void MainWindow::openNewMapPopupWindowImportMap(MapLayout *mapLayout) { connect(this->newMapPrompt, SIGNAL(applied()), this, SLOT(onNewMapCreated())); connect(this->newMapPrompt, &QObject::destroyed, [=](QObject *) { this->newMapPrompt = nullptr; }); - this->newMapPrompt->setAttribute(Qt::WA_DeleteOnClose); + this->newMapPrompt->setAttribute(Qt::WA_DeleteOnClose); } void MainWindow::on_action_NewMap_triggered() { diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index c3821d9c..c8106319 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -9,6 +9,8 @@ #include #include +struct NewMapPopup::Settings NewMapPopup::settings = {}; + NewMapPopup::NewMapPopup(QWidget *parent, Project *project) : QMainWindow(parent), ui(new Ui::NewMapPopup) @@ -24,36 +26,72 @@ NewMapPopup::~NewMapPopup() delete ui; } -void NewMapPopup::init(int type, int group, QString sec, QString layoutId) { +void NewMapPopup::initSettings(Project *project) { + settings.group = project->groupNames.at(0); + settings.width = project->getDefaultMapSize(); + settings.height = project->getDefaultMapSize(); + settings.borderWidth = DEFAULT_BORDER_WIDTH; + settings.borderHeight = DEFAULT_BORDER_HEIGHT; + settings.primaryTileset = project->getDefaultPrimaryTilesetLabel(); + settings.secondaryTileset = project->getDefaultSecondaryTilesetLabel(); + settings.type = project->mapTypes.at(0); + settings.location = project->mapSectionValueToName.values().at(0); + settings.song = project->songNames.at(0); + settings.canFlyTo = false; + settings.showLocationName = true; + settings.allowRunning = false; + settings.allowBiking = false; + settings.allowEscaping = false; + settings.floorNumber = 0; +} + +void NewMapPopup::init(MapSortOrder type, QVariant data) { + int groupNum = 0; + QString mapSec = QString(); + switch (type) { - case MapSortOrder::Group: - setDefaultValues(group, QString()); - break; - case MapSortOrder::Area: - setDefaultValues(group, sec); - break; - case MapSortOrder::Layout: - useLayout(layoutId); - setDefaultValues(group, QString()); - break; + case MapSortOrder::Group: + groupNum = data.toInt(); + break; + case MapSortOrder::Area: + mapSec = data.toString(); + break; + case MapSortOrder::Layout: + this->existingLayout = true; + this->layoutId = data.toString(); + break; } + + populateComboBoxes(); + setDefaultValues(groupNum, mapSec); + setDefaultValuesProjectConfig(); connectSignals(); } void NewMapPopup::initImportMap(MapLayout *mapLayout) { this->importedMap = true; + populateComboBoxes(); setDefaultValuesImportMap(mapLayout); + setDefaultValuesProjectConfig(); connectSignals(); } +void NewMapPopup::populateComboBoxes() { + ui->comboBox_NewMap_Primary_Tileset->addItems(project->primaryTilesetLabels); + ui->comboBox_NewMap_Secondary_Tileset->addItems(project->secondaryTilesetLabels); + ui->comboBox_NewMap_Group->addItems(project->groupNames); + ui->comboBox_NewMap_Song->addItems(project->songNames); + ui->comboBox_NewMap_Type->addItems(project->mapTypes); + ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values()); +} + bool NewMapPopup::checkNewMapDimensions() { int numMetatiles = project->getMapDataSize(ui->spinBox_NewMap_Width->value(), ui->spinBox_NewMap_Height->value()); int maxMetatiles = project->getMaxMapDataSize(); if (numMetatiles > maxMetatiles) { ui->frame_NewMap_Warning->setVisible(true); - //ui->label_NewMap_WarningMessage->setText("WARNING: The specified map dimensions are too large."); QString errorText = QString("Error: The specified width and height are too large.\n" "The maximum map width and height is the following: (width + 15) * (height + 14) <= %1\n" "The specified map width and height was: (%2 + 15) * (%3 + 14) = %4") @@ -95,32 +133,23 @@ void NewMapPopup::connectSignals() { ui->spinBox_NewMap_Width->setMaximum(project->getMaxMapWidth()); ui->spinBox_NewMap_Height->setMaximum(project->getMaxMapHeight()); - //ui->icon_NewMap_WarningIcon->setPixmap(); connect(ui->spinBox_NewMap_Width, QOverload::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();}); connect(ui->spinBox_NewMap_Height, QOverload::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();}); } -void NewMapPopup::useLayout(QString layoutId) { - this->existingLayout = true; - this->layoutId = layoutId; -} - void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { ui->lineEdit_NewMap_Name->setText(project->getNewMapName()); - ui->comboBox_NewMap_Primary_Tileset->addItems(project->primaryTilesetLabels); - ui->comboBox_NewMap_Secondary_Tileset->addItems(project->secondaryTilesetLabels); + ui->comboBox_NewMap_Group->setTextItem(project->groupNames.at(groupNum)); - ui->comboBox_NewMap_Group->addItems(project->groupNames); - ui->comboBox_NewMap_Group->setCurrentText(project->groupNames.at(groupNum)); - - ui->comboBox_Song->addItems(project->songNames); - - if (existingLayout) { - ui->spinBox_NewMap_Width->setValue(project->mapLayouts.value(layoutId)->width); - ui->spinBox_NewMap_Height->setValue(project->mapLayouts.value(layoutId)->height); - ui->comboBox_NewMap_Primary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_primary_label); - ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(project->mapLayouts.value(layoutId)->tileset_secondary_label); + if (this->existingLayout) { + MapLayout * layout = project->mapLayouts.value(layoutId); + ui->spinBox_NewMap_Width->setValue(layout->width); + ui->spinBox_NewMap_Height->setValue(layout->height); + ui->spinBox_NewMap_BorderWidth->setValue(layout->border_width); + ui->spinBox_NewMap_BorderHeight->setValue(layout->border_height); + ui->comboBox_NewMap_Primary_Tileset->setTextItem(layout->tileset_primary_label); + ui->comboBox_NewMap_Secondary_Tileset->setTextItem(layout->tileset_secondary_label); ui->spinBox_NewMap_Width->setDisabled(true); ui->spinBox_NewMap_Height->setDisabled(true); ui->spinBox_NewMap_BorderWidth->setDisabled(true); @@ -132,109 +161,60 @@ void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { ui->spinBox_NewMap_Height->setValue(project->getDefaultMapSize()); ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH); ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT); - int primaryIdx = ui->comboBox_NewMap_Primary_Tileset->findText(project->getDefaultPrimaryTilesetLabel()); - int secondaryIdx = ui->comboBox_NewMap_Secondary_Tileset->findText(project->getDefaultSecondaryTilesetLabel()); - ui->comboBox_NewMap_Primary_Tileset->setCurrentIndex(primaryIdx); - ui->comboBox_NewMap_Secondary_Tileset->setCurrentIndex(secondaryIdx); + ui->comboBox_NewMap_Primary_Tileset->setTextItem(project->getDefaultPrimaryTilesetLabel()); + ui->comboBox_NewMap_Secondary_Tileset->setTextItem(project->getDefaultSecondaryTilesetLabel()); } - ui->comboBox_NewMap_Type->addItems(project->mapTypes); - ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values()); - if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setCurrentText(mapSec); + if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setTextItem(mapSec); ui->checkBox_NewMap_Show_Location->setChecked(true); ui->frame_NewMap_Options->setEnabled(true); - - setDefaultValuesProjectConfig(false, NULL); } void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) { ui->lineEdit_NewMap_Name->setText(project->getNewMapName()); - ui->comboBox_NewMap_Primary_Tileset->addItems(project->primaryTilesetLabels); - ui->comboBox_NewMap_Secondary_Tileset->addItems(project->secondaryTilesetLabels); - - ui->comboBox_NewMap_Group->addItems(project->groupNames); - ui->comboBox_NewMap_Group->setCurrentText(project->groupNames.at(0)); - - ui->comboBox_Song->addItems(project->songNames); + ui->comboBox_NewMap_Group->setTextItem(project->groupNames.at(0)); ui->spinBox_NewMap_Width->setValue(mapLayout->width); ui->spinBox_NewMap_Height->setValue(mapLayout->height); - ui->comboBox_NewMap_Primary_Tileset->setCurrentText(mapLayout->tileset_primary_label); - ui->comboBox_NewMap_Secondary_Tileset->setCurrentText(mapLayout->tileset_secondary_label); + ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width); + ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height); + + ui->comboBox_NewMap_Primary_Tileset->setTextItem(mapLayout->tileset_primary_label); + ui->comboBox_NewMap_Secondary_Tileset->setTextItem(mapLayout->tileset_secondary_label); - ui->comboBox_NewMap_Type->addItems(project->mapTypes); - ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values()); ui->checkBox_NewMap_Show_Location->setChecked(true); ui->frame_NewMap_Options->setEnabled(true); - setDefaultValuesProjectConfig(true, mapLayout); - - map = new Map(); - map->layout = new MapLayout(); - map->layout->blockdata = mapLayout->blockdata; + this->map = new Map(); + this->map->layout = new MapLayout(); + this->map->layout->blockdata = mapLayout->blockdata; if (!mapLayout->border.isEmpty()) { - map->layout->border = mapLayout->border; + this->map->layout->border = mapLayout->border; } } -void NewMapPopup::setDefaultValuesProjectConfig(bool importedMap, MapLayout *mapLayout) { - switch (projectConfig.getBaseGameVersion()) - { - case BaseGameVersion::pokeruby: - ui->checkBox_NewMap_Allow_Running->setVisible(false); - ui->checkBox_NewMap_Allow_Biking->setVisible(false); - ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(false); - ui->label_NewMap_Allow_Running->setVisible(false); - ui->label_NewMap_Allow_Biking->setVisible(false); - ui->label_NewMap_Allow_Escape_Rope->setVisible(false); - break; - case BaseGameVersion::pokeemerald: - ui->checkBox_NewMap_Allow_Running->setVisible(true); - ui->checkBox_NewMap_Allow_Biking->setVisible(true); - ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(true); - ui->label_NewMap_Allow_Running->setVisible(true); - ui->label_NewMap_Allow_Biking->setVisible(true); - ui->label_NewMap_Allow_Escape_Rope->setVisible(true); - break; - case BaseGameVersion::pokefirered: - ui->checkBox_NewMap_Allow_Running->setVisible(true); - ui->checkBox_NewMap_Allow_Biking->setVisible(true); - ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(true); - ui->label_NewMap_Allow_Running->setVisible(true); - ui->label_NewMap_Allow_Biking->setVisible(true); - ui->label_NewMap_Allow_Escape_Rope->setVisible(true); - break; - } - if (projectConfig.getUseCustomBorderSize()) { - if (importedMap) { - ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width); - ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height); - } - ui->spinBox_NewMap_BorderWidth->setVisible(true); - ui->spinBox_NewMap_BorderHeight->setVisible(true); - ui->label_NewMap_BorderWidth->setVisible(true); - ui->label_NewMap_BorderHeight->setVisible(true); - } else { - if (importedMap) { - ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH); - ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT); - } - ui->spinBox_NewMap_BorderWidth->setVisible(false); - ui->spinBox_NewMap_BorderHeight->setVisible(false); - ui->label_NewMap_BorderWidth->setVisible(false); - ui->label_NewMap_BorderHeight->setVisible(false); - } - if (projectConfig.getFloorNumberEnabled()) { - ui->spinBox_NewMap_Floor_Number->setVisible(true); - ui->label_NewMap_Floor_Number->setVisible(true); - } else { - ui->spinBox_NewMap_Floor_Number->setVisible(false); - ui->label_NewMap_Floor_Number->setVisible(false); - } +void NewMapPopup::setDefaultValuesProjectConfig() { + bool hasFlags = (projectConfig.getBaseGameVersion() != BaseGameVersion::pokeruby); + ui->checkBox_NewMap_Allow_Running->setVisible(hasFlags); + ui->checkBox_NewMap_Allow_Biking->setVisible(hasFlags); + ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(hasFlags); + ui->label_NewMap_Allow_Running->setVisible(hasFlags); + ui->label_NewMap_Allow_Biking->setVisible(hasFlags); + ui->label_NewMap_Allow_Escape_Rope->setVisible(hasFlags); + + bool hasCustomBorders = projectConfig.getUseCustomBorderSize(); + ui->spinBox_NewMap_BorderWidth->setVisible(hasCustomBorders); + ui->spinBox_NewMap_BorderHeight->setVisible(hasCustomBorders); + ui->label_NewMap_BorderWidth->setVisible(hasCustomBorders); + ui->label_NewMap_BorderHeight->setVisible(hasCustomBorders); + + bool hasFloorNumber = projectConfig.getFloorNumberEnabled(); + ui->spinBox_NewMap_Floor_Number->setVisible(hasFloorNumber); + ui->label_NewMap_Floor_Number->setVisible(hasFloorNumber); } void NewMapPopup::on_lineEdit_NewMap_Name_textChanged(const QString &text) { @@ -268,7 +248,7 @@ void NewMapPopup::on_pushButton_NewMap_Accept_clicked() { newMap->name = newMapName; newMap->type = this->ui->comboBox_NewMap_Type->currentText(); newMap->location = this->ui->comboBox_NewMap_Location->currentText(); - newMap->song = this->ui->comboBox_Song->currentText(); + newMap->song = this->ui->comboBox_NewMap_Song->currentText(); newMap->requiresFlash = false; newMap->weather = this->project->weatherNames.value(0, "WEATHER_NONE"); newMap->show_location = this->ui->checkBox_NewMap_Show_Location->isChecked(); From c50b8d06689d2c463b6308873d8710e278282669 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 24 Oct 2022 16:18:50 -0400 Subject: [PATCH 08/10] Restore last settings for new map popup --- include/mainwindow.h | 3 +- include/ui/newmappopup.h | 17 ++- src/mainwindow.cpp | 42 ++---- src/ui/newmappopup.cpp | 275 ++++++++++++++++++++------------------- 4 files changed, 164 insertions(+), 173 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index 8aaf8a65..2e110f7f 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -176,8 +176,7 @@ private slots: void onMapNeedsRedrawing(); void onTilesetsSaved(QString, QString); void onWildMonDataChanged(); - void openNewMapPopupWindow(MapSortOrder, QVariant); - void openNewMapPopupWindowImportMap(MapLayout *); + void openNewMapPopupWindow(); void onNewMapCreated(); void onMapCacheCleared(); void importMapFromAdvanceMap1_92(); diff --git a/include/ui/newmappopup.h b/include/ui/newmappopup.h index 95565276..826e1609 100644 --- a/include/ui/newmappopup.h +++ b/include/ui/newmappopup.h @@ -22,10 +22,10 @@ public: bool existingLayout; bool importedMap; QString layoutId; + void init(); void init(MapSortOrder type, QVariant data); - void initImportMap(MapLayout *); - void connectSignals(); - static void initSettings(Project *project); + void init(MapLayout *); + static void setDefaultSettings(Project *project); signals: void applied(); @@ -33,12 +33,11 @@ signals: private: Ui::NewMapPopup *ui; Project *project; - void setDefaultValues(int, QString); - void setDefaultValuesImportMap(MapLayout *); - void setDefaultValuesProjectConfig(); bool checkNewMapDimensions(); bool checkNewMapGroup(); - void populateComboBoxes(); + void saveSettings(); + void useLayout(QString layoutId); + void useLayoutSettings(MapLayout *mapLayout); struct Settings { QString group; @@ -46,8 +45,8 @@ private: int height; int borderWidth; int borderHeight; - QString primaryTileset; - QString secondaryTileset; + QString primaryTilesetLabel; + QString secondaryTilesetLabel; QString type; QString location; QString song; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 2390f390..cb6ec632 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1141,20 +1141,20 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction) { - int groupNum = triggeredAction->data().toInt(); - openNewMapPopupWindow(MapSortOrder::Group, groupNum); + openNewMapPopupWindow(); + this->newMapPrompt->init(MapSortOrder::Group, triggeredAction->data()); } void MainWindow::onAddNewMapToAreaClick(QAction* triggeredAction) { - QString secName = triggeredAction->data().toString(); - openNewMapPopupWindow(MapSortOrder::Area, secName); + openNewMapPopupWindow(); + this->newMapPrompt->init(MapSortOrder::Area, triggeredAction->data()); } void MainWindow::onAddNewMapToLayoutClick(QAction* triggeredAction) { - QString layoutId = triggeredAction->data().toString(); - openNewMapPopupWindow(MapSortOrder::Layout, layoutId); + openNewMapPopupWindow(); + this->newMapPrompt->init(MapSortOrder::Layout, triggeredAction->data()); } void MainWindow::onNewMapCreated() { @@ -1191,9 +1191,10 @@ void MainWindow::onNewMapCreated() { delete newMap; } -void MainWindow::openNewMapPopupWindow(MapSortOrder type, QVariant data) { +void MainWindow::openNewMapPopupWindow() { if (!openedNewMapDialog) { - NewMapPopup::initSettings(this->editor->project); + NewMapPopup::setDefaultSettings(this->editor->project); + openedNewMapDialog = true; } if (!this->newMapPrompt) { this->newMapPrompt = new NewMapPopup(this, this->editor->project); @@ -1204,31 +1205,13 @@ void MainWindow::openNewMapPopupWindow(MapSortOrder type, QVariant data) { this->newMapPrompt->raise(); this->newMapPrompt->activateWindow(); } - this->newMapPrompt->init(type, data); connect(this->newMapPrompt, &NewMapPopup::applied, this, &MainWindow::onNewMapCreated); this->newMapPrompt->setAttribute(Qt::WA_DeleteOnClose); } -void MainWindow::openNewMapPopupWindowImportMap(MapLayout *mapLayout) { - if (!this->newMapPrompt) { - this->newMapPrompt = new NewMapPopup(this, this->editor->project); - } - if (!this->newMapPrompt->isVisible()) { - this->newMapPrompt->show(); - } else { - this->newMapPrompt->raise(); - this->newMapPrompt->activateWindow(); - } - - this->newMapPrompt->initImportMap(mapLayout); - - connect(this->newMapPrompt, SIGNAL(applied()), this, SLOT(onNewMapCreated())); - connect(this->newMapPrompt, &QObject::destroyed, [=](QObject *) { this->newMapPrompt = nullptr; }); - this->newMapPrompt->setAttribute(Qt::WA_DeleteOnClose); -} - void MainWindow::on_action_NewMap_triggered() { - openNewMapPopupWindow(MapSortOrder::Group, 0); + openNewMapPopupWindow(); + this->newMapPrompt->init(); } // Insert label for newly-created tileset into sorted list of existing labels @@ -2466,7 +2449,8 @@ void MainWindow::importMapFromAdvanceMap1_92() return; } - openNewMapPopupWindowImportMap(mapLayout); + openNewMapPopupWindow(); + this->newMapPrompt->init(mapLayout); } void MainWindow::showExportMapImageWindow(ImageExporterMode mode) { diff --git a/src/ui/newmappopup.cpp b/src/ui/newmappopup.cpp index c8106319..2796ae63 100644 --- a/src/ui/newmappopup.cpp +++ b/src/ui/newmappopup.cpp @@ -23,67 +23,104 @@ NewMapPopup::NewMapPopup(QWidget *parent, Project *project) : NewMapPopup::~NewMapPopup() { + saveSettings(); delete ui; } -void NewMapPopup::initSettings(Project *project) { - settings.group = project->groupNames.at(0); - settings.width = project->getDefaultMapSize(); - settings.height = project->getDefaultMapSize(); - settings.borderWidth = DEFAULT_BORDER_WIDTH; - settings.borderHeight = DEFAULT_BORDER_HEIGHT; - settings.primaryTileset = project->getDefaultPrimaryTilesetLabel(); - settings.secondaryTileset = project->getDefaultSecondaryTilesetLabel(); - settings.type = project->mapTypes.at(0); - settings.location = project->mapSectionValueToName.values().at(0); - settings.song = project->songNames.at(0); - settings.canFlyTo = false; - settings.showLocationName = true; - settings.allowRunning = false; - settings.allowBiking = false; - settings.allowEscaping = false; - settings.floorNumber = 0; -} - -void NewMapPopup::init(MapSortOrder type, QVariant data) { - int groupNum = 0; - QString mapSec = QString(); - - switch (type) - { - case MapSortOrder::Group: - groupNum = data.toInt(); - break; - case MapSortOrder::Area: - mapSec = data.toString(); - break; - case MapSortOrder::Layout: - this->existingLayout = true; - this->layoutId = data.toString(); - break; - } - - populateComboBoxes(); - setDefaultValues(groupNum, mapSec); - setDefaultValuesProjectConfig(); - connectSignals(); -} - -void NewMapPopup::initImportMap(MapLayout *mapLayout) { - this->importedMap = true; - populateComboBoxes(); - setDefaultValuesImportMap(mapLayout); - setDefaultValuesProjectConfig(); - connectSignals(); -} - -void NewMapPopup::populateComboBoxes() { +void NewMapPopup::init() { + // Populate combo boxes ui->comboBox_NewMap_Primary_Tileset->addItems(project->primaryTilesetLabels); ui->comboBox_NewMap_Secondary_Tileset->addItems(project->secondaryTilesetLabels); ui->comboBox_NewMap_Group->addItems(project->groupNames); ui->comboBox_NewMap_Song->addItems(project->songNames); ui->comboBox_NewMap_Type->addItems(project->mapTypes); ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values()); + + // Set spin box limits + ui->spinBox_NewMap_Width->setMinimum(1); + ui->spinBox_NewMap_Height->setMinimum(1); + ui->spinBox_NewMap_Width->setMaximum(project->getMaxMapWidth()); + ui->spinBox_NewMap_Height->setMaximum(project->getMaxMapHeight()); + ui->spinBox_NewMap_BorderWidth->setMinimum(1); + ui->spinBox_NewMap_BorderHeight->setMinimum(1); + ui->spinBox_NewMap_Floor_Number->setMinimum(-128); + ui->spinBox_NewMap_Floor_Number->setMaximum(127); + + // Hide config specific ui elements + bool hasFlags = (projectConfig.getBaseGameVersion() != BaseGameVersion::pokeruby); + ui->checkBox_NewMap_Allow_Running->setVisible(hasFlags); + ui->checkBox_NewMap_Allow_Biking->setVisible(hasFlags); + ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(hasFlags); + ui->label_NewMap_Allow_Running->setVisible(hasFlags); + ui->label_NewMap_Allow_Biking->setVisible(hasFlags); + ui->label_NewMap_Allow_Escape_Rope->setVisible(hasFlags); + + bool hasCustomBorders = projectConfig.getUseCustomBorderSize(); + ui->spinBox_NewMap_BorderWidth->setVisible(hasCustomBorders); + ui->spinBox_NewMap_BorderHeight->setVisible(hasCustomBorders); + ui->label_NewMap_BorderWidth->setVisible(hasCustomBorders); + ui->label_NewMap_BorderHeight->setVisible(hasCustomBorders); + + bool hasFloorNumber = projectConfig.getFloorNumberEnabled(); + ui->spinBox_NewMap_Floor_Number->setVisible(hasFloorNumber); + ui->label_NewMap_Floor_Number->setVisible(hasFloorNumber); + + // Restore previous settings + ui->lineEdit_NewMap_Name->setText(project->getNewMapName()); + ui->comboBox_NewMap_Group->setTextItem(settings.group); + ui->spinBox_NewMap_Width->setValue(settings.width); + ui->spinBox_NewMap_Height->setValue(settings.height); + ui->spinBox_NewMap_BorderWidth->setValue(settings.borderWidth); + ui->spinBox_NewMap_BorderHeight->setValue(settings.borderHeight); + ui->comboBox_NewMap_Primary_Tileset->setTextItem(settings.primaryTilesetLabel); + ui->comboBox_NewMap_Secondary_Tileset->setTextItem(settings.secondaryTilesetLabel); + ui->comboBox_NewMap_Type->setTextItem(settings.type); + ui->comboBox_NewMap_Location->setTextItem(settings.location); + ui->comboBox_NewMap_Song->setTextItem(settings.song); + ui->checkBox_NewMap_Flyable->setChecked(settings.canFlyTo); + ui->checkBox_NewMap_Show_Location->setChecked(settings.showLocationName); + ui->checkBox_NewMap_Allow_Running->setChecked(settings.allowRunning); + ui->checkBox_NewMap_Allow_Biking->setChecked(settings.allowBiking); + ui->checkBox_NewMap_Allow_Escape_Rope->setChecked(settings.allowEscaping); + ui->spinBox_NewMap_Floor_Number->setValue(settings.floorNumber); + + // Connect signals + connect(ui->spinBox_NewMap_Width, QOverload::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();}); + connect(ui->spinBox_NewMap_Height, QOverload::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();}); + + ui->frame_NewMap_Options->setEnabled(true); +} + +// Creating new map by right-clicking in the map list +void NewMapPopup::init(MapSortOrder type, QVariant data) { + switch (type) + { + case MapSortOrder::Group: + settings.group = project->groupNames.at(data.toInt()); + break; + case MapSortOrder::Area: + settings.location = data.toString(); + break; + case MapSortOrder::Layout: + useLayout(data.toString()); + break; + } + init(); +} + +// Creating new map from AdvanceMap import +void NewMapPopup::init(MapLayout *mapLayout) { + this->importedMap = true; + useLayoutSettings(mapLayout); + + this->map = new Map(); + this->map->layout = new MapLayout(); + this->map->layout->blockdata = mapLayout->blockdata; + + if (!mapLayout->border.isEmpty()) { + this->map->layout->border = mapLayout->border; + } + init(); } bool NewMapPopup::checkNewMapDimensions() { @@ -127,94 +164,66 @@ bool NewMapPopup::checkNewMapGroup() { } } -void NewMapPopup::connectSignals() { - ui->spinBox_NewMap_Width->setMinimum(1); - ui->spinBox_NewMap_Height->setMinimum(1); - ui->spinBox_NewMap_Width->setMaximum(project->getMaxMapWidth()); - ui->spinBox_NewMap_Height->setMaximum(project->getMaxMapHeight()); - - connect(ui->spinBox_NewMap_Width, QOverload::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();}); - connect(ui->spinBox_NewMap_Height, QOverload::of(&QSpinBox::valueChanged), [=](int){checkNewMapDimensions();}); +void NewMapPopup::setDefaultSettings(Project *project) { + settings.group = project->groupNames.at(0); + settings.width = project->getDefaultMapSize(); + settings.height = project->getDefaultMapSize(); + settings.borderWidth = DEFAULT_BORDER_WIDTH; + settings.borderHeight = DEFAULT_BORDER_HEIGHT; + settings.primaryTilesetLabel = project->getDefaultPrimaryTilesetLabel(); + settings.secondaryTilesetLabel = project->getDefaultSecondaryTilesetLabel(); + settings.type = project->mapTypes.at(0); + settings.location = project->mapSectionValueToName.values().at(0); + settings.song = project->songNames.at(0); + settings.canFlyTo = false; + settings.showLocationName = true; + settings.allowRunning = false; + settings.allowBiking = false; + settings.allowEscaping = false; + settings.floorNumber = 0; } -void NewMapPopup::setDefaultValues(int groupNum, QString mapSec) { - ui->lineEdit_NewMap_Name->setText(project->getNewMapName()); - - ui->comboBox_NewMap_Group->setTextItem(project->groupNames.at(groupNum)); - - if (this->existingLayout) { - MapLayout * layout = project->mapLayouts.value(layoutId); - ui->spinBox_NewMap_Width->setValue(layout->width); - ui->spinBox_NewMap_Height->setValue(layout->height); - ui->spinBox_NewMap_BorderWidth->setValue(layout->border_width); - ui->spinBox_NewMap_BorderHeight->setValue(layout->border_height); - ui->comboBox_NewMap_Primary_Tileset->setTextItem(layout->tileset_primary_label); - ui->comboBox_NewMap_Secondary_Tileset->setTextItem(layout->tileset_secondary_label); - ui->spinBox_NewMap_Width->setDisabled(true); - ui->spinBox_NewMap_Height->setDisabled(true); - ui->spinBox_NewMap_BorderWidth->setDisabled(true); - ui->spinBox_NewMap_BorderHeight->setDisabled(true); - ui->comboBox_NewMap_Primary_Tileset->setDisabled(true); - ui->comboBox_NewMap_Secondary_Tileset->setDisabled(true); - } else { - ui->spinBox_NewMap_Width->setValue(project->getDefaultMapSize()); - ui->spinBox_NewMap_Height->setValue(project->getDefaultMapSize()); - ui->spinBox_NewMap_BorderWidth->setValue(DEFAULT_BORDER_WIDTH); - ui->spinBox_NewMap_BorderHeight->setValue(DEFAULT_BORDER_HEIGHT); - ui->comboBox_NewMap_Primary_Tileset->setTextItem(project->getDefaultPrimaryTilesetLabel()); - ui->comboBox_NewMap_Secondary_Tileset->setTextItem(project->getDefaultSecondaryTilesetLabel()); - } - - if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setTextItem(mapSec); - ui->checkBox_NewMap_Show_Location->setChecked(true); - - ui->frame_NewMap_Options->setEnabled(true); +void NewMapPopup::saveSettings() { + settings.group = ui->comboBox_NewMap_Group->currentText(); + settings.width = ui->spinBox_NewMap_Width->value(); + settings.height = ui->spinBox_NewMap_Height->value(); + settings.borderWidth = ui->spinBox_NewMap_BorderWidth->value(); + settings.borderHeight = ui->spinBox_NewMap_BorderHeight->value(); + settings.primaryTilesetLabel = ui->comboBox_NewMap_Primary_Tileset->currentText(); + settings.secondaryTilesetLabel = ui->comboBox_NewMap_Secondary_Tileset->currentText(); + settings.type = ui->comboBox_NewMap_Type->currentText(); + settings.location = ui->comboBox_NewMap_Location->currentText(); + settings.song = ui->comboBox_NewMap_Song->currentText(); + settings.canFlyTo = ui->checkBox_NewMap_Flyable->isChecked(); + settings.showLocationName = ui->checkBox_NewMap_Show_Location->isChecked(); + settings.allowRunning = ui->checkBox_NewMap_Allow_Running->isChecked(); + settings.allowBiking = ui->checkBox_NewMap_Allow_Biking->isChecked(); + settings.allowEscaping = ui->checkBox_NewMap_Allow_Escape_Rope->isChecked(); + settings.floorNumber = ui->spinBox_NewMap_Floor_Number->value(); } -void NewMapPopup::setDefaultValuesImportMap(MapLayout *mapLayout) { - ui->lineEdit_NewMap_Name->setText(project->getNewMapName()); - - ui->comboBox_NewMap_Group->setTextItem(project->groupNames.at(0)); - - ui->spinBox_NewMap_Width->setValue(mapLayout->width); - ui->spinBox_NewMap_Height->setValue(mapLayout->height); - ui->spinBox_NewMap_BorderWidth->setValue(mapLayout->border_width); - ui->spinBox_NewMap_BorderHeight->setValue(mapLayout->border_height); - - ui->comboBox_NewMap_Primary_Tileset->setTextItem(mapLayout->tileset_primary_label); - ui->comboBox_NewMap_Secondary_Tileset->setTextItem(mapLayout->tileset_secondary_label); - - ui->checkBox_NewMap_Show_Location->setChecked(true); - - ui->frame_NewMap_Options->setEnabled(true); - - this->map = new Map(); - this->map->layout = new MapLayout(); - this->map->layout->blockdata = mapLayout->blockdata; - - if (!mapLayout->border.isEmpty()) { - this->map->layout->border = mapLayout->border; - } +void NewMapPopup::useLayoutSettings(MapLayout *layout) { + if (!layout) return; + settings.width = layout->width; + settings.height = layout->height; + settings.borderWidth = layout->border_width; + settings.borderHeight = layout->border_height; + settings.primaryTilesetLabel = layout->tileset_primary_label; + settings.secondaryTilesetLabel = layout->tileset_secondary_label; } -void NewMapPopup::setDefaultValuesProjectConfig() { - bool hasFlags = (projectConfig.getBaseGameVersion() != BaseGameVersion::pokeruby); - ui->checkBox_NewMap_Allow_Running->setVisible(hasFlags); - ui->checkBox_NewMap_Allow_Biking->setVisible(hasFlags); - ui->checkBox_NewMap_Allow_Escape_Rope->setVisible(hasFlags); - ui->label_NewMap_Allow_Running->setVisible(hasFlags); - ui->label_NewMap_Allow_Biking->setVisible(hasFlags); - ui->label_NewMap_Allow_Escape_Rope->setVisible(hasFlags); +void NewMapPopup::useLayout(QString layoutId) { + this->existingLayout = true; + this->layoutId = layoutId; + useLayoutSettings(project->mapLayouts.value(this->layoutId)); - bool hasCustomBorders = projectConfig.getUseCustomBorderSize(); - ui->spinBox_NewMap_BorderWidth->setVisible(hasCustomBorders); - ui->spinBox_NewMap_BorderHeight->setVisible(hasCustomBorders); - ui->label_NewMap_BorderWidth->setVisible(hasCustomBorders); - ui->label_NewMap_BorderHeight->setVisible(hasCustomBorders); - - bool hasFloorNumber = projectConfig.getFloorNumberEnabled(); - ui->spinBox_NewMap_Floor_Number->setVisible(hasFloorNumber); - ui->label_NewMap_Floor_Number->setVisible(hasFloorNumber); + // Dimensions and tilesets can't be changed for new maps using an existing layout + ui->spinBox_NewMap_Width->setDisabled(true); + ui->spinBox_NewMap_Height->setDisabled(true); + ui->spinBox_NewMap_BorderWidth->setDisabled(true); + ui->spinBox_NewMap_BorderHeight->setDisabled(true); + ui->comboBox_NewMap_Primary_Tileset->setDisabled(true); + ui->comboBox_NewMap_Secondary_Tileset->setDisabled(true); } void NewMapPopup::on_lineEdit_NewMap_Name_textChanged(const QString &text) { From d91ae9dab69ce622705f4ca56f03bfed2f2b1e30 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 24 Oct 2022 17:07:13 -0400 Subject: [PATCH 09/10] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d90e3c20..c90b0d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ The **"Breaking Changes"** listed below are changes that have been made in the d ### Changed - Overhauled the region map editor, adding support for tilemaps, and significant customization. Also now supports pokefirered. +- Previous settings will be remembered in the New Map Options window. - The Custom Attributes table for map headers and events now supports types other than strings. - If an object event is inanimate, it will always render using its first frame. - Unused metatile attribute bits are preserved instead of being cleared. @@ -62,6 +63,8 @@ The **"Breaking Changes"** listed below are changes that have been made in the d - Silence unnecessary error logging when parsing C defines Porymap doesn't use. - Fix some windows like the Tileset Editor not raising to the front when reactivated. - Metatile behaviors with no constant will now display their value in the Tileset Editor. +- Fix incorrect limits on Floor Number and Border Width/Height in the New Map Options window. +- Fix Border Width/Height being set to 0 when creating a new map from an existing layout. ## [4.5.0] - 2021-12-26 ### Added From ea19b3a08cd9f51bf70a35d53339f7b34ab7ee64 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 24 Oct 2022 19:55:06 -0400 Subject: [PATCH 10/10] Sort asm tileset lists --- src/project.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/project.cpp b/src/project.cpp index af90cd9d..4b68be4a 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1887,6 +1887,9 @@ bool Project::readTilesetLabels() { QRegularExpressionMatch match = iter.next(); appendTilesetLabel(match.captured("label"), match.captured("isSecondary")); } + this->primaryTilesetLabels.sort(); + this->secondaryTilesetLabels.sort(); + this->tilesetLabelsOrdered.sort(); filename = asm_filename; // For error reporting further down } else { this->usingAsmTilesets = false;