diff --git a/src/ui/GameWorldView.cpp b/src/ui/GameWorldView.cpp index 1abd308..2caff0d 100644 --- a/src/ui/GameWorldView.cpp +++ b/src/ui/GameWorldView.cpp @@ -871,18 +871,6 @@ void GameWorldView::drawBuildings(QPainter& painter) drawPortGlyph(painter, portBodyTile(port.tile, port.direction), port.direction, bv.outline); } - - bool selected = false; - for (BuildingId selId : m_selectedBuildingIds) - { - if (selId == b.id) { selected = true; break; } - } - if (selected) - { - painter.setPen(QPen(m_visuals->overlays.selectedOutline, 2)); - painter.setBrush(Qt::NoBrush); - painter.drawRect(bboxRect.adjusted(-1, -1, 1, 1)); - } } painter.setOpacity(0.5); @@ -906,20 +894,6 @@ void GameWorldView::drawBuildings(QPainter& painter) painter.setBrush(Qt::NoBrush); painter.drawRect(bboxRect); - bool selected = false; - for (BuildingId selId : m_selectedBuildingIds) - { - if (selId == s.id) { selected = true; break; } - } - if (selected) - { - painter.setOpacity(1.0); - painter.setPen(QPen(m_visuals->overlays.selectedOutline, 2)); - painter.setBrush(Qt::NoBrush); - painter.drawRect(bboxRect.adjusted(-1, -1, 1, 1)); - painter.setOpacity(0.5); - } - const BuildingDef* siteDef = findBuildingDef(s.type); if (siteDef) { @@ -964,6 +938,42 @@ void GameWorldView::drawBuildings(QPainter& painter) } } painter.setOpacity(1.0); + + // Selection highlights are drawn last, after every building and construction + // site fill, so a selected building surrounded by neighbours keeps its outline: + // the highlight sits 1px outside the footprint (into adjacent tiles), and drawing + // it inline would let later-drawn neighbours overpaint it with their body fill. + drawSelectionHighlights(painter); +} + +void GameWorldView::drawSelectionHighlights(QPainter& painter) +{ + painter.setPen(QPen(m_visuals->overlays.selectedOutline, 2)); + painter.setBrush(Qt::NoBrush); + + for (BuildingId selId : m_selectedBuildingIds) + { + std::optional anchor; + std::optional footprint; + + if (const Building* b = m_sim->buildings().findBuilding(selId)) + { + anchor = b->anchor; + footprint = b->footprint; + } + else if (const ConstructionSite* s = m_sim->buildings().findSite(selId)) + { + anchor = s->anchor; + footprint = s->footprint; + } + if (!anchor.has_value() || !footprint.has_value()) { continue; } + + const QPointF tl = tileToWidget(*anchor); + const QRectF bboxRect(tl.x(), tl.y(), + footprint->width() * static_cast(tilePx()), + footprint->height() * static_cast(tilePx())); + painter.drawRect(bboxRect.adjusted(-1, -1, 1, 1)); + } } void GameWorldView::drawBeltItems(QPainter& painter) diff --git a/src/ui/GameWorldView.h b/src/ui/GameWorldView.h index 22cde0a..11edfc9 100644 --- a/src/ui/GameWorldView.h +++ b/src/ui/GameWorldView.h @@ -115,6 +115,7 @@ private: void drawTiles(QPainter& painter); void drawBuildings(QPainter& painter); + void drawSelectionHighlights(QPainter& painter); void drawStations(QPainter& painter); void drawBeltItems(QPainter& painter); void drawScrap(QPainter& painter);