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

View file

@ -36,7 +36,7 @@ void MetatileSelector::draw() {
painter.end(); painter.end();
this->setPixmap(QPixmap::fromImage(image)); 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(); this->drawSelection();
} }
} }
@ -44,6 +44,13 @@ void MetatileSelector::draw() {
bool MetatileSelector::select(uint16_t metatileId) { bool MetatileSelector::select(uint16_t metatileId) {
if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false; if (!Tileset::metatileIsValid(metatileId, this->primaryTileset, this->secondaryTileset)) return false;
this->externalSelection = 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); QPoint coords = this->getMetatileIdCoords(metatileId);
SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0); SelectablePixmapItem::select(coords.x(), coords.y(), 0, 0);
this->updateSelectedMetatiles(); 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) { 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->externalSelection = true;
this->externalSelectionWidth = width; this->externalSelectionWidth = width;
this->externalSelectionHeight = height; this->externalSelectionHeight = height;
@ -95,8 +103,9 @@ void MetatileSelector::setExternalSelection(int width, int height, QList<uint16_
emit selectedMetatilesChanged(); emit selectedMetatilesChanged();
} }
void MetatileSelector::setDirectSelection(MetatileSelection selection) { void MetatileSelector::setPrefabSelection(MetatileSelection selection) {
this->externalSelection = false; this->externalSelection = false;
this->prefabSelection = true;
this->externalSelectedMetatiles.clear(); this->externalSelectedMetatiles.clear();
this->selection = selection; this->selection = selection;
this->draw(); this->draw();
@ -142,6 +151,7 @@ void MetatileSelector::hoverLeaveEvent(QGraphicsSceneHoverEvent*) {
void MetatileSelector::updateSelectedMetatiles() { void MetatileSelector::updateSelectedMetatiles() {
this->externalSelection = false; this->externalSelection = false;
this->prefabSelection = false;
this->selection.metatileItems.clear(); this->selection.metatileItems.clear();
this->selection.collisionItems.clear(); this->selection.collisionItems.clear();
this->selection.hasCollision = false; 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. // Clicking on the prefab graphics item selects it for painting.
QObject::connect(frame->ui->graphicsView_Prefab, &ClickableGraphicsView::clicked, [this, item](){ 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. // Clicking the delete button removes it from the list of known prefabs and updates the UI.