split the selection panel into one card per kind of selection

This commit is contained in:
2026-08-07 18:38:55 +02:00
parent cc0ef856e3
commit 2289277e12
60 changed files with 3014 additions and 1559 deletions

View File

@@ -0,0 +1,53 @@
#include "ProductionSection.h"
#include <algorithm>
#include <QLabel>
#include <QVBoxLayout>
#include "Building.h"
ProductionSection::ProductionSection(QWidget* parent)
: QWidget(parent)
{
QVBoxLayout* layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
m_label = new QLabel(this);
layout->addWidget(m_label);
}
void ProductionSection::setProduction(bool runsProduction, const Building& building,
double durationSeconds, Tick currentTick)
{
// Nothing selected to produce means neither a cycle time nor a progress indicator
// (REQ-UI-PRODUCTION-PROGRESS).
if (!runsProduction)
{
hide();
return;
}
QString text;
if (durationSeconds > 0.0)
{
text = tr("Cycle: %1 s\n").arg(durationSeconds, 0, 'f', 1);
}
if (durationSeconds > 0.0 && building.production.has_value())
{
const Tick cycleTicks = secondsToTicks(durationSeconds);
const Tick elapsed =
currentTick - (building.production->completesAt - cycleTicks);
const int percent = static_cast<int>(
std::max(Tick(0), std::min(cycleTicks, elapsed)) * 100 / cycleTicks);
text += tr("Progress: %1%").arg(percent);
}
else
{
text += tr("Progress: idle");
}
m_label->setText(text);
show();
}