split the selection panel into one card per kind of selection
This commit is contained in:
53
src/ui/selection/ProductionSection.cpp
Normal file
53
src/ui/selection/ProductionSection.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user