Custom collision/event graphics cleanup

This commit is contained in:
GriffinR 2023-12-08 12:53:04 -05:00
parent 4f0e8716f2
commit 61b1789d4b
5 changed files with 31 additions and 24 deletions

View file

@ -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<uint16_t> metatileIds);
QList<uint16_t> 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<uint16_t> newMapBorderMetatileIds;
QString defaultPrimaryTileset;
QString defaultSecondaryTileset;

View file

@ -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<QString> 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<QString, QString> 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<uint16_t> 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();

View file

@ -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.

View file

@ -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() {

View file

@ -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);
}