Disallow empty prefabs
Some checks failed
Build Porymap / build-linux (, 5.14.2) (push) Has been cancelled
Build Porymap / build-linux (, 6.8.*) (push) Has been cancelled
Build Porymap / build-linux (minimal, 5.14.2) (push) Has been cancelled
Build Porymap / build-macos (macos-15-intel) (push) Has been cancelled
Build Porymap / build-macos (macos-latest) (push) Has been cancelled
Build Porymap / build-static-windows (push) Has been cancelled

This commit is contained in:
GriffinR
2026-05-15 22:23:32 -04:00
parent a4b8dd70e6
commit 80b35d6ade
5 changed files with 27 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ and this project somewhat adheres to [Semantic Versioning](https://semver.org/sp
- Fix not being able to minimize/maximize some windows.
- Fix some menu items under `Tools` not being disabled when their corresponding button is disabled.
- Fix the map list search bar stealing keyboard focus whenever a map layout was opened.
- Disallow creating prefabs with no metatiles.
## [6.3.1] - 2026-04-12
### Added

View File

@@ -34,6 +34,18 @@ struct MetatileSelection
bool hasCollision;
QList<MetatileSelectionItem> metatileItems;
QList<CollisionSelectionItem> collisionItems;
bool isEmpty() const {
for (const auto& metatileItem : metatileItems) {
if (metatileItem.enabled) return false;
}
if (hasCollision) {
for (const auto& collisionItem : collisionItems) {
if (collisionItem.enabled) return false;
}
}
return true;
};
};
class MetatileSelector: public SelectablePixmapItem {

View File

@@ -24,6 +24,8 @@ private:
Layout *layout = nullptr;
Ui::PrefabCreationDialog *ui;
MetatileSelection selection;
void validate();
};
#endif // PREFABCREATIONDIALOG_H

View File

@@ -82,6 +82,7 @@ void Prefab::loadPrefabs() {
selection.metatileItems[index].enabled = true;
selection.collisionItems[index].enabled = true;
}
if (selection.isEmpty()) continue;
this->items.append(PrefabItem{QUuid::createUuid(), name, primaryTileset, secondaryTileset, selection});
}

View File

@@ -5,6 +5,7 @@
#include "prefab.h"
#include <QObject>
#include <QPushButton>
PrefabCreationDialog::PrefabCreationDialog(QWidget *parent, MetatileSelector *metatileSelector, Layout *layout) :
QDialog(parent),
@@ -36,9 +37,12 @@ PrefabCreationDialog::PrefabCreationDialog(QWidget *parent, MetatileSelector *me
this->selection.collisionItems[index].enabled = toggledState;
}
pixmapItem->setPixmap(drawMetatileSelection(this->selection, layout));
validate();
});
connect(this, &PrefabCreationDialog::accepted, this, &PrefabCreationDialog::savePrefab);
validate();
}
PrefabCreationDialog::~PrefabCreationDialog()
@@ -46,6 +50,13 @@ PrefabCreationDialog::~PrefabCreationDialog()
delete ui;
}
void PrefabCreationDialog::validate() {
bool valid = !this->selection.isEmpty();
QPushButton* okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
if (okButton) okButton->setEnabled(valid);
}
void PrefabCreationDialog::savePrefab() {
prefab.addPrefab(this->selection, this->layout, this->ui->lineEdit_PrefabName->text());
}