Fix bug where dimensions of current selection would be incorrect after a prefab was selected

This commit is contained in:
Marcus Huderle 2022-09-24 11:16:03 -05:00
parent 9f69e433f0
commit a081af85c4
3 changed files with 16 additions and 4 deletions

View file

@ -33,6 +33,7 @@ class MetatileSelector: public SelectablePixmapItem {
public:
MetatileSelector(int numMetatilesWide, Map *map): SelectablePixmapItem(16, 16) {
this->externalSelection = false;
this->prefabSelection = false;
this->numMetatilesWide = numMetatilesWide;
this->map = map;
this->primaryTileset = map->layout->tileset_primary;
@ -46,7 +47,7 @@ public:
bool selectFromMap(uint16_t metatileId, uint16_t collision, uint16_t elevation);
void setTilesets(Tileset*, Tileset*);
MetatileSelection getMetatileSelection();
void setDirectSelection(MetatileSelection selection);
void setPrefabSelection(MetatileSelection selection);
void setExternalSelection(int, int, QList<uint16_t>, QList<QPair<uint16_t, uint16_t>>);
QPoint getMetatileIdCoordsOnWidget(uint16_t);
void setMap(Map*);
@ -60,6 +61,7 @@ protected:
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
private:
bool externalSelection;
bool prefabSelection;
int numMetatilesWide;
Map *map;
int externalSelectionWidth;

View file

@ -36,7 +36,7 @@ void MetatileSelector::draw() {
painter.end();
this->setPixmap(QPixmap::fromImage(image));
if (!this->externalSelection || (this->externalSelectionWidth == 1 && this->externalSelectionHeight == 1)) {
if (!this->prefabSelection && (!this->externalSelection || (this->externalSelectionWidth == 1 && this->externalSelectionHeight == 1))) {
this->drawSelection();
}
}
@ -44,6 +44,13 @@ void MetatileSelector::draw() {
bool MetatileSelector::select(uint16_t metatileId) {
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false;
this->externalSelection = false;
this->prefabSelection = false;
this->selection = MetatileSelection{
QPoint(1, 1),
false,
QList<MetatileSelectionItem>({MetatileSelectionItem{true, metatileId}}),
QList<CollisionSelectionItem>(),
};
QPoint coords = this->getMetatileIdCoords(metatileId);
SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0);
this->updateSelectedMetatiles();
@ -73,6 +80,7 @@ MetatileSelection MetatileSelector::getMetatileSelection() {
}
void MetatileSelector::setExternalSelection(int width, int height, QList<uint16_t> metatiles, QList<QPair<uint16_t, uint16_t>> collisions) {
this->prefabSelection = false;
this->externalSelection = true;
this->externalSelectionWidth = width;
this->externalSelectionHeight = height;
@ -95,8 +103,9 @@ void MetatileSelector::setExternalSelection(int width, int height, QList<uint16_
emit selectedMetatilesChanged();
}
void MetatileSelector::setDirectSelection(MetatileSelection selection) {
void MetatileSelector::setPrefabSelection(MetatileSelection selection) {
this->externalSelection = false;
this->prefabSelection = true;
this->externalSelectedMetatiles.clear();
this->selection = selection;
this->draw();
@ -142,6 +151,7 @@ void MetatileSelector::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
void MetatileSelector::updateSelectedMetatiles() {
this->externalSelection = false;
this->prefabSelection = false;
this->selection.metatileItems.clear();
this->selection.collisionItems.clear();
this->selection.hasCollision = false;

View file

@ -208,7 +208,7 @@ void Prefab::updatePrefabUi(Map *map) {
// Clicking on the prefab graphics item selects it for painting.
QObject::connect(frame->ui->graphicsView_Prefab, &ClickableGraphicsView::clicked, [this, item](){
selector->setDirectSelection(item.selection);
selector->setPrefabSelection(item.selection);
});
// Clicking the delete button removes it from the list of known prefabs and updates the UI.