#include "ProductionSection.h" #include #include #include #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( 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(); }