fix issue where HP bar is drawn below belts

This commit is contained in:
2026-08-02 15:50:42 +02:00
parent 5fc30efde2
commit 76d0ccdbb7

View File

@@ -1382,21 +1382,6 @@ void GameWorldView::drawBuildings(QPainter& painter)
painter.setPen(QPen(m_visuals->statusLight.outline, 1)); painter.setPen(QPen(m_visuals->statusLight.outline, 1));
painter.drawEllipse(center, r, r); painter.drawEllipse(center, r, r);
} }
// HP bar below the HQ footprint; the HQ's HP lives on its proxy entity.
if (b.type == BuildingType::Hq)
{
m_sim->getAdmin().forEach<HqProxyComponent, FactionComponent, HealthComponent>(
[&](entt::entity /*e*/, const HqProxyComponent& /*hq*/,
const FactionComponent& f, const HealthComponent& h)
{
if (h.maxHp > 0.0f)
{
drawHpBar(painter, bboxRect.left(), bboxRect.bottom() + 1.0,
bboxRect.width(), h.hp / h.maxHp, f.isEnemy);
}
});
}
} }
painter.setOpacity(0.5); painter.setOpacity(0.5);
@@ -1473,6 +1458,29 @@ void GameWorldView::drawBuildings(QPainter& painter)
} }
painter.setOpacity(1.0); painter.setOpacity(1.0);
// HP bar below the HQ footprint; the HQ's HP lives on its proxy entity. Drawn
// after every building and construction site fill so a belt (or other tile)
// placed directly below the HQ cannot overpaint the bar (REQ-UI-STATUS-LIGHT
// neighbours case, same rationale as the selection highlights below).
for (const Building& b : m_sim->getBuildings().getAllBuildings())
{
if (b.type != BuildingType::Hq) { continue; }
const QPointF tl = tileToWidget(b.anchor);
const QRectF bboxRect(tl.x(), tl.y(),
b.footprint.width() * static_cast<qreal>(getTilePx()),
b.footprint.height() * static_cast<qreal>(getTilePx()));
m_sim->getAdmin().forEach<HqProxyComponent, FactionComponent, HealthComponent>(
[&](entt::entity /*e*/, const HqProxyComponent& /*hq*/,
const FactionComponent& f, const HealthComponent& h)
{
if (h.maxHp > 0.0f)
{
drawHpBar(painter, bboxRect.left(), bboxRect.bottom() + 1.0,
bboxRect.width(), h.hp / h.maxHp, f.isEnemy);
}
});
}
// Selection highlights are drawn last, after every building and construction // Selection highlights are drawn last, after every building and construction
// site fill, so a selected building surrounded by neighbours keeps its outline: // site fill, so a selected building surrounded by neighbours keeps its outline:
// the highlight sits 1px outside the footprint (into adjacent tiles), and drawing // the highlight sits 1px outside the footprint (into adjacent tiles), and drawing