implement display construction percentage
This commit is contained in:
@@ -617,6 +617,36 @@ void GameWorldView::drawBuildings(QPainter& painter)
|
||||
const BuildingDef* siteDef = findBuildingDef(s.type);
|
||||
if (siteDef)
|
||||
{
|
||||
// Glyph + progress percentage
|
||||
const Tick durationTicks = secondsToTicks(siteDef->constructionTimeSeconds);
|
||||
int pct = 0;
|
||||
if (s.completesAt > 0 && durationTicks > 0)
|
||||
{
|
||||
const Tick elapsed = m_sim->currentTick()
|
||||
- (s.completesAt - durationTicks);
|
||||
pct = static_cast<int>(
|
||||
std::max(Tick(0), std::min(durationTicks, elapsed))
|
||||
* 100 / durationTicks);
|
||||
}
|
||||
const QString pctText = QString::number(pct) + "%";
|
||||
|
||||
painter.setPen(bv.outline);
|
||||
if (!bv.glyph.isEmpty())
|
||||
{
|
||||
const QRectF topHalf(bboxRect.x(), bboxRect.y(),
|
||||
bboxRect.width(), bboxRect.height() * 0.5);
|
||||
const QRectF botHalf(bboxRect.x(),
|
||||
bboxRect.y() + bboxRect.height() * 0.5,
|
||||
bboxRect.width(), bboxRect.height() * 0.5);
|
||||
painter.drawText(topHalf, Qt::AlignCenter, bv.glyph);
|
||||
painter.drawText(botHalf, Qt::AlignCenter, pctText);
|
||||
}
|
||||
else
|
||||
{
|
||||
painter.drawText(bboxRect, Qt::AlignCenter, pctText);
|
||||
}
|
||||
|
||||
// Port glyphs
|
||||
const ParsedSurfaceMask siteMask =
|
||||
parseSurfaceMask(siteDef->surfaceMask, s.rotation);
|
||||
for (const Port& port : siteMask.outputPorts)
|
||||
|
||||
Reference in New Issue
Block a user