give the selection cards their own parts instead of label blobs
This commit is contained in:
@@ -2,16 +2,26 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
#include <QLabel>
|
||||
#include <QStringList>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "Building.h"
|
||||
#include "BuildingIconCache.h"
|
||||
#include "ClearBeltControl.h"
|
||||
#include "CountRow.h"
|
||||
#include "FactoryQueries.h"
|
||||
#include "GameConfig.h"
|
||||
#include "SelectionNames.h"
|
||||
#include "Simulation.h"
|
||||
#include "StatRow.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Size the type symbol is drawn at on a count row, matching the card header's chip.
|
||||
const int kCountSymbolSizePx = 20;
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
MultiBuildingContent::MultiBuildingContent(const SelectionContext& context,
|
||||
const SelectionRequest& request,
|
||||
@@ -19,10 +29,11 @@ MultiBuildingContent::MultiBuildingContent(const SelectionContext& context,
|
||||
: SelectionContent(context, std::nullopt, parent)
|
||||
, m_ids(request.buildings)
|
||||
{
|
||||
m_countsLabel = new QLabel(this);
|
||||
m_totalCostLabel = new QLabel(this);
|
||||
getRuntimeLayout()->addWidget(m_countsLabel);
|
||||
getRuntimeLayout()->addWidget(m_totalCostLabel);
|
||||
// The header names the size of the selection instead of an object
|
||||
// (REQ-UI-MULTI-SELECTION).
|
||||
setIdentity(QPixmap(), tr("%1 buildings").arg(static_cast<int>(m_ids.size())));
|
||||
|
||||
buildSummary();
|
||||
|
||||
// A selection holding any belt-subsystem tile can still be cleared as a whole
|
||||
// (REQ-UI-BELT-CLEAR), even though the mixture is what kept it from aggregating.
|
||||
@@ -40,12 +51,6 @@ MultiBuildingContent::MultiBuildingContent(const SelectionContext& context,
|
||||
{
|
||||
getRuntimeLayout()->addWidget(new ClearBeltControl(context, m_ids, this));
|
||||
}
|
||||
|
||||
// The header names the size of the selection instead of an object
|
||||
// (REQ-UI-MULTI-SELECTION).
|
||||
setIdentity(QPixmap(), tr("%1 buildings").arg(static_cast<int>(m_ids.size())));
|
||||
|
||||
buildSummary();
|
||||
}
|
||||
|
||||
void MultiBuildingContent::buildSummary()
|
||||
@@ -68,11 +73,13 @@ void MultiBuildingContent::buildSummary()
|
||||
}
|
||||
}
|
||||
|
||||
QStringList lines;
|
||||
int totalCost = 0;
|
||||
for (const std::pair<const BuildingType, int>& entry : counts)
|
||||
{
|
||||
lines << tr("%1 x %2").arg(getBuildingTypeName(entry.first)).arg(entry.second);
|
||||
getRuntimeLayout()->addWidget(new CountRow(
|
||||
getContext().buildingIcons->getChip(buildingTypeId(entry.first),
|
||||
kCountSymbolSizePx),
|
||||
getBuildingTypeName(entry.first), entry.second, this));
|
||||
|
||||
// Only player-placeable buildings count toward the total; the HQ and defence
|
||||
// stations are excluded (REQ-UI-MULTI-SELECTION). A construction site counts at
|
||||
@@ -85,6 +92,8 @@ void MultiBuildingContent::buildSummary()
|
||||
}
|
||||
}
|
||||
|
||||
m_countsLabel->setText(lines.join('\n'));
|
||||
m_totalCostLabel->setText(tr("Total: %1 Building Blocks").arg(totalCost));
|
||||
StatRow* totalRow = new StatRow(tr("Total cost"), this);
|
||||
totalRow->setValue(QString::number(totalCost));
|
||||
totalRow->setValueEmphasized(true);
|
||||
getRuntimeLayout()->addWidget(totalRow);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user