Add building status light
This commit is contained in:
@@ -124,6 +124,20 @@ QPoint portBodyTile(QPoint portTile, Rotation direction)
|
||||
return portTile;
|
||||
}
|
||||
|
||||
// Fill color for a building's status light per its production state
|
||||
// (REQ-UI-STATUS-LIGHT).
|
||||
QColor statusLightFill(ProductionStatus status, const StatusLightVisuals& sl)
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case ProductionStatus::Unconfigured: return sl.grey;
|
||||
case ProductionStatus::Producing: return sl.green;
|
||||
case ProductionStatus::Starved: return sl.red;
|
||||
case ProductionStatus::Blocked: return sl.yellow;
|
||||
}
|
||||
return sl.grey;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -1039,6 +1053,35 @@ void GameWorldView::drawBuildings(QPainter& painter)
|
||||
port.direction, bv.outline, /*centered*/ false);
|
||||
}
|
||||
|
||||
// Status light: a small circle in the building's upper-right corner
|
||||
// (in default/East orientation), anchored to that footprint corner and
|
||||
// rotating with the building (REQ-UI-STATUS-LIGHT). All status-light
|
||||
// building footprints are rectangular, so a corner of the axis-aligned
|
||||
// bounding box is the true corner.
|
||||
if (const std::optional<ProductionStatus> status =
|
||||
m_sim->getBuildings().getProductionStatus(b))
|
||||
{
|
||||
const float px = getTilePx();
|
||||
const float r = px * 0.18f;
|
||||
const float inset = r + px * 0.12f;
|
||||
// Default orientation (East) puts the light at the top-right corner;
|
||||
// clockwise rotation carries it around the footprint.
|
||||
QPointF center(bboxRect.right() - inset, bboxRect.top() + inset);
|
||||
switch (b.rotation)
|
||||
{
|
||||
case Rotation::East: break;
|
||||
case Rotation::South: center = QPointF(bboxRect.right() - inset,
|
||||
bboxRect.bottom() - inset); break;
|
||||
case Rotation::West: center = QPointF(bboxRect.left() + inset,
|
||||
bboxRect.bottom() - inset); break;
|
||||
case Rotation::North: center = QPointF(bboxRect.left() + inset,
|
||||
bboxRect.top() + inset); break;
|
||||
}
|
||||
painter.setBrush(statusLightFill(*status, m_visuals->statusLight));
|
||||
painter.setPen(QPen(m_visuals->statusLight.outline, 1));
|
||||
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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user