fix issue where building selection outline is hidden by other buildings drawn later

This commit is contained in:
2026-07-08 21:29:44 +02:00
parent f11db0c072
commit 2cedd5d433
2 changed files with 37 additions and 26 deletions

View File

@@ -871,18 +871,6 @@ void GameWorldView::drawBuildings(QPainter& painter)
drawPortGlyph(painter, portBodyTile(port.tile, port.direction), drawPortGlyph(painter, portBodyTile(port.tile, port.direction),
port.direction, bv.outline); 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); painter.setOpacity(0.5);
@@ -906,20 +894,6 @@ void GameWorldView::drawBuildings(QPainter& painter)
painter.setBrush(Qt::NoBrush); painter.setBrush(Qt::NoBrush);
painter.drawRect(bboxRect); 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); const BuildingDef* siteDef = findBuildingDef(s.type);
if (siteDef) if (siteDef)
{ {
@@ -964,6 +938,42 @@ void GameWorldView::drawBuildings(QPainter& painter)
} }
} }
painter.setOpacity(1.0); 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<QPoint> anchor;
std::optional<QSize> 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<qreal>(tilePx()),
footprint->height() * static_cast<qreal>(tilePx()));
painter.drawRect(bboxRect.adjusted(-1, -1, 1, 1));
}
} }
void GameWorldView::drawBeltItems(QPainter& painter) void GameWorldView::drawBeltItems(QPainter& painter)

View File

@@ -115,6 +115,7 @@ private:
void drawTiles(QPainter& painter); void drawTiles(QPainter& painter);
void drawBuildings(QPainter& painter); void drawBuildings(QPainter& painter);
void drawSelectionHighlights(QPainter& painter);
void drawStations(QPainter& painter); void drawStations(QPainter& painter);
void drawBeltItems(QPainter& painter); void drawBeltItems(QPainter& painter);
void drawScrap(QPainter& painter); void drawScrap(QPainter& painter);