diff --git a/include/config.h b/include/config.h index 55efd5a0..16139d53 100644 --- a/include/config.h +++ b/include/config.h @@ -225,6 +225,7 @@ public: this->enableTripleLayerMetatiles = false; this->newMapMetatileId = 1; this->newMapElevation = 3; + this->newMapCollision = 0; this->defaultPrimaryTileset = "gTileset_General"; this->prefabFilepath = QString(); this->prefabImportPrompted = false; @@ -275,6 +276,8 @@ public: uint16_t getNewMapMetatileId(); void setNewMapElevation(int elevation); int getNewMapElevation(); + void setNewMapCollision(int collision); + int getNewMapCollision(); void setNewMapBorderMetatileIds(QList metatileIds); QList getNewMapBorderMetatileIds(); QString getDefaultPrimaryTileset(); @@ -307,8 +310,6 @@ public: void setMapAllowFlagsEnabled(bool enabled); void setEventIconPath(Event::Group group, const QString &path); QString getEventIconPath(Event::Group group); - void setCollisionIconPath(int collision, const QString &path); - QString getCollisionIconPath(int collision); void setCollisionSheetPath(const QString &path); QString getCollisionSheetPath(); void setCollisionSheetWidth(int width); @@ -339,6 +340,7 @@ private: bool enableTripleLayerMetatiles; uint16_t newMapMetatileId; int newMapElevation; + int newMapCollision; QList newMapBorderMetatileIds; QString defaultPrimaryTileset; QString defaultSecondaryTileset; diff --git a/src/config.cpp b/src/config.cpp index 67dcdf9c..b31beed3 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -640,17 +640,19 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) { } else if (key == "enable_triple_layer_metatiles") { this->enableTripleLayerMetatiles = getConfigBool(key, value); } else if (key == "new_map_metatile") { - // TODO: Update max + // TODO: Update max once Block layout can be edited this->newMapMetatileId = getConfigUint32(key, value, 0, 1023, 0); } else if (key == "new_map_elevation") { - // TODO: Update max + // TODO: Update max once Block layout can be edited this->newMapElevation = getConfigInteger(key, value, 0, 15, 3); + } else if (key == "new_map_collision") { + // TODO: Update max once Block layout can be edited + this->newMapCollision = getConfigInteger(key, value, 0, 3, 0); } else if (key == "new_map_border_metatiles") { this->newMapBorderMetatileIds.clear(); QList metatileIds = value.split(","); for (int i = 0; i < metatileIds.size(); i++) { - // TODO: The max of 1023 here should eventually reflect Project::num_metatiles_total-1, - // but the config is parsed well before that constant is. + // TODO: Update max once Block layout can be edited int metatileId = getConfigUint32(key, metatileIds.at(i), 0, 1023, 0); this->newMapBorderMetatileIds.append(metatileId); } @@ -712,7 +714,6 @@ void ProjectConfig::parseConfigKeyValue(QString key, QString value) { this->collisionSheetPath = value; } else if (key == "collision_sheet_width") { // Max for these two keys is if a user specifies blocks with 1 bit for metatile ID and 15 bits for collision or elevation - // TODO: Test to make sure there shouldn't be a stricter limit given the UI this->collisionSheetWidth = getConfigInteger(key, value, 1, 0x7FFF, 2); } else if (key == "collision_sheet_height") { this->collisionSheetHeight = getConfigInteger(key, value, 1, 0x7FFF, 16); @@ -767,6 +768,7 @@ QMap ProjectConfig::getKeyValueMap() { map.insert("enable_triple_layer_metatiles", QString::number(this->enableTripleLayerMetatiles)); map.insert("new_map_metatile", Metatile::getMetatileIdString(this->newMapMetatileId)); map.insert("new_map_elevation", QString::number(this->newMapElevation)); + map.insert("new_map_collision", QString::number(this->newMapCollision)); map.insert("new_map_border_metatiles", Metatile::getMetatileIdStringList(this->newMapBorderMetatileIds)); map.insert("default_primary_tileset", this->defaultPrimaryTileset); map.insert("default_secondary_tileset", this->defaultSecondaryTileset); @@ -1014,6 +1016,15 @@ int ProjectConfig::getNewMapElevation() { return this->newMapElevation; } +void ProjectConfig::setNewMapCollision(int collision) { + this->newMapCollision = collision; + this->save(); +} + +int ProjectConfig::getNewMapCollision() { + return this->newMapCollision; +} + void ProjectConfig::setNewMapBorderMetatileIds(QList metatileIds) { this->newMapBorderMetatileIds = metatileIds; this->save(); @@ -1131,7 +1142,6 @@ void ProjectConfig::setMapAllowFlagsEnabled(bool enabled) { this->save(); } -// TODO: Expose to project settings editor void ProjectConfig::setEventIconPath(Event::Group group, const QString &path) { this->eventIconPaths[group] = path; this->save(); @@ -1141,7 +1151,6 @@ QString ProjectConfig::getEventIconPath(Event::Group group) { return this->eventIconPaths.value(group); } -// TODO: Expose to project settings editor void ProjectConfig::setCollisionSheetPath(const QString &path) { this->collisionSheetPath = path; this->save(); diff --git a/src/editor.cpp b/src/editor.cpp index 5bf12862..a597ca6d 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -1497,7 +1497,7 @@ void Editor::displayMovementPermissionSelector() { connect(movement_permissions_selector_item, &SelectablePixmapItem::selectionChanged, [this](int x, int y, int, int) { this->setCollisionTabSpinBoxes(x, y); }); - movement_permissions_selector_item->select(0, projectConfig.getNewMapElevation()); // TODO: New map collision config? + movement_permissions_selector_item->select(projectConfig.getNewMapCollision(), projectConfig.getNewMapElevation()); } scene_collision_metatiles->addItem(movement_permissions_selector_item); @@ -2243,13 +2243,15 @@ void Editor::setCollisionTabSpinBoxes(uint16_t collision, uint16_t elevation) { ui->spinBox_SelectedElevation->setValue(elevation); } -// TODO: Bug--Images with transparency allow users to paint metatiles on the Collision tab // Custom collision graphics may be provided by the user. void Editor::setCollisionGraphics() { QString customPath = projectConfig.getCollisionSheetPath(); QImage imgSheet; - if (!customPath.isEmpty()) { + if (customPath.isEmpty()) { + // No custom collision image specified, use the default. + imgSheet = this->defaultCollisionImgSheet; + } else { // Try to load custom collision image QFileInfo info(customPath); if (info.isRelative()) { @@ -2261,12 +2263,9 @@ void Editor::setCollisionGraphics() { logWarn(QString("Failed to load custom collision image '%1', using default.").arg(customPath)); imgSheet = this->defaultCollisionImgSheet; } - } else { - // No custom collision image specified, use the default. - imgSheet = this->defaultCollisionImgSheet; } - // Like the vanilla collision image, users are not required to provide an image that gives an icon for every elevation/collision combination. + // Users are not required to provide an image that gives an icon for every elevation/collision combination. // Instead they tell us how many are provided in their image by specifying the number of columns and rows. const int imgColumns = projectConfig.getCollisionSheetWidth(); const int imgRows = projectConfig.getCollisionSheetHeight(); @@ -2286,7 +2285,6 @@ void Editor::setCollisionGraphics() { const int w = 16, h = 16; imgSheet = imgSheet.scaled(w * imgColumns, h * imgRows); for (int collision = 0; collision <= Project::getMaxCollision(); collision++) { - // If (collision >= imgColumns) here, it's a valid collision value, but it is not represented with an icon on the image sheet. // In this case we just use the rightmost collision icon. This is mostly to support the vanilla case, where technically 0-3 // are valid collision values, but 1-3 have the same meaning, so the vanilla collision selector image only has 2 columns. diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 87e385b3..714f6335 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2820,15 +2820,13 @@ void MainWindow::on_horizontalSlider_CollisionZoom_valueChanged(int value) { } void MainWindow::on_spinBox_SelectedCollision_valueChanged(int collision) { - if (!this->editor || !this->editor->movement_permissions_selector_item) - return; - this->editor->movement_permissions_selector_item->select(collision, ui->spinBox_SelectedElevation->value()); + if (this->editor && this->editor->movement_permissions_selector_item) + this->editor->movement_permissions_selector_item->select(collision, ui->spinBox_SelectedElevation->value()); } void MainWindow::on_spinBox_SelectedElevation_valueChanged(int elevation) { - if (!this->editor || !this->editor->movement_permissions_selector_item) - return; - this->editor->movement_permissions_selector_item->select(ui->spinBox_SelectedCollision->value(), elevation); + if (this->editor && this->editor->movement_permissions_selector_item) + this->editor->movement_permissions_selector_item->select(ui->spinBox_SelectedCollision->value(), elevation); } void MainWindow::on_actionRegion_Map_Editor_triggered() { diff --git a/src/project.cpp b/src/project.cpp index 9b801e2d..37ea7e23 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1114,7 +1114,7 @@ void Project::setNewMapBlockdata(Map *map) { map->layout->blockdata.clear(); int width = map->getWidth(); int height = map->getHeight(); - Block block(projectConfig.getNewMapMetatileId(), 0, projectConfig.getNewMapElevation()); + Block block(projectConfig.getNewMapMetatileId(), projectConfig.getNewMapCollision(), projectConfig.getNewMapElevation()); for (int i = 0; i < width * height; i++) { map->layout->blockdata.append(block); }