diff --git a/CHANGELOG.md b/CHANGELOG.md index da41ed29..c90b0d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,13 +19,13 @@ 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. ### 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. @@ -63,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 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/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 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/config.h b/include/config.h index ed86019f..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 @@ -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/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/include/mainwindow.h b/include/mainwindow.h index b8653d58..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(int, QVariant); - void openNewMapPopupWindowImportMap(MapLayout *); + void openNewMapPopupWindow(); void onNewMapCreated(); void onMapCacheCleared(); void importMapFromAdvanceMap1_92(); @@ -330,6 +329,7 @@ private: bool isProgrammaticEventTabChange; bool projectHasUnsavedChanges; bool projectOpenFailure = false; + bool openedNewMapDialog = false; MapSortOrder mapSortOrder; @@ -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 28c3a296..c5599489 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); @@ -170,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(); @@ -210,6 +210,9 @@ public: QCompleter *getEventScriptLabelCompleter(QStringList additionalScriptLabels); QStringList getGlobalScriptLabels(); + QString getDefaultPrimaryTilesetLabel(); + QString getDefaultSecondaryTilesetLabel(); + static int getNumTilesPrimary(); static int getNumTilesTotal(); static int getNumMetatilesPrimary(); @@ -229,7 +232,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/include/ui/newmappopup.h b/include/ui/newmappopup.h index 5c4f5761..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(int, int, QString, QString); - void initImportMap(MapLayout *); - void useLayout(QString); - void connectSignals(); + void init(); + void init(MapSortOrder type, QVariant data); + void init(MapLayout *); + static void setDefaultSettings(Project *project); signals: void applied(); @@ -33,11 +33,31 @@ signals: private: Ui::NewMapPopup *ui; Project *project; - void setDefaultValues(int, QString); - void setDefaultValuesImportMap(MapLayout *); - void setDefaultValuesProjectConfig(bool, MapLayout*); bool checkNewMapDimensions(); bool checkNewMapGroup(); + void saveSettings(); + void useLayout(QString layoutId); + void useLayoutSettings(MapLayout *mapLayout); + + struct Settings { + QString group; + int width; + int height; + int borderWidth; + int borderHeight; + QString primaryTilesetLabel; + QString secondaryTilesetLabel; + 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/config.cpp b/src/config.cpp index 9beac865..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) { @@ -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/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 3c10824f..cb6ec632 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(); @@ -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,7 +1191,11 @@ void MainWindow::onNewMapCreated() { delete newMap; } -void MainWindow::openNewMapPopupWindow(int type, QVariant data) { +void MainWindow::openNewMapPopupWindow() { + if (!openedNewMapDialog) { + NewMapPopup::setDefaultSettings(this->editor->project); + openedNewMapDialog = true; + } if (!this->newMapPrompt) { this->newMapPrompt = new NewMapPopup(this, this->editor->project); } @@ -1201,42 +1205,22 @@ 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; - } 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(); + this->newMapPrompt->init(); } -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() { @@ -1266,8 +1250,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."); @@ -1285,7 +1268,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); @@ -1325,12 +1308,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."); @@ -2464,7 +2449,8 @@ void MainWindow::importMapFromAdvanceMap1_92() return; } - openNewMapPopupWindowImportMap(mapLayout); + openNewMapPopupWindow(); + this->newMapPrompt->init(mapLayout); } void MainWindow::showExportMapImageWindow(ImageExporterMode mode) { @@ -2547,7 +2533,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 +2545,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..4b68be4a 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 = tilesetLabels["primary"].value(0, "gTileset_General"); - layout->tileset_secondary_label = tilesetLabels["secondary"].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 = tilesetLabels["primary"].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 = tilesetLabels["secondary"].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); @@ -1082,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")); @@ -1098,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"); @@ -1588,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 { @@ -1850,28 +1831,43 @@ Project::DataQualifiers Project::getDataQualifiers(QString text, QString label) return qualifiers; } -void Project::insertTilesetLabel(QString label, bool isSecondary) { - QString category = isSecondary ? "secondary" : "primary"; - this->tilesetLabels[category].append(label); - this->tilesetLabelsOrdered.append(label); +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; } -void Project::insertTilesetLabel(QString label, QString isSecondaryStr) { +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::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() { 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); @@ -1889,8 +1885,11 @@ 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")); } + this->primaryTilesetLabels.sort(); + this->secondaryTilesetLabels.sort(); + this->tilesetLabelsOrdered.sort(); filename = asm_filename; // For error reporting further down } else { this->usingAsmTilesets = false; @@ -1898,16 +1897,16 @@ 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")); } } 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; } @@ -2164,7 +2163,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()) { @@ -2505,7 +2504,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); 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..2796ae63 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) @@ -21,30 +23,104 @@ NewMapPopup::NewMapPopup(QWidget *parent, Project *project) : NewMapPopup::~NewMapPopup() { + saveSettings(); delete ui; } -void NewMapPopup::init(int type, int group, QString sec, QString layoutId) { - 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; - } - connectSignals(); +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); } -void NewMapPopup::initImportMap(MapLayout *mapLayout) { +// 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; - setDefaultValuesImportMap(mapLayout); - connectSignals(); + 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() { @@ -53,7 +129,6 @@ bool NewMapPopup::checkNewMapDimensions() { 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") @@ -89,148 +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()); +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; +} - //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::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::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::useLayout(QString layoutId) { this->existingLayout = true; this->layoutId = layoutId; -} + useLayoutSettings(project->mapLayouts.value(this->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_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); - 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_Type->addItems(project->mapTypes); - ui->comboBox_NewMap_Location->addItems(project->mapSectionValueToName.values()); - if (!mapSec.isEmpty()) ui->comboBox_NewMap_Location->setCurrentText(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->tilesetLabels.value("primary")); - ui->comboBox_NewMap_Secondary_Tileset->addItems(project->tilesetLabels.value("secondary")); - - ui->comboBox_NewMap_Group->addItems(project->groupNames); - ui->comboBox_NewMap_Group->setCurrentText(project->groupNames.at(0)); - - ui->comboBox_Song->addItems(project->songNames); - - 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->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; - - if (!mapLayout->border.isEmpty()) { - 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); - } + // 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) { @@ -264,7 +257,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();