The cards were assembled from plain labels carrying whole blocks of text. Replace those with the widget vocabulary the requirements describe, so a part means the same thing wherever it appears and a card is a list of parts rather than a string builder. The parts, all free of Simulation and GameConfig -- they take prepared values, and the contents work out what those are: - StatRow, BarRow, SectionBox: label/value line, captioned fill bar, captioned group. The bar is one part for three things: construction progress, production progress, and HP. - ItemChip / ItemChipRow: buffered items as icon, count and sub-line (REQ-UI-SINGLE-SELECTION). An input chip carries its per-cycle amount, an output chip its count against the buffer capacity. The chips are rebuilt only when the set of items changes, so a 30 Hz refresh moves numbers rather than widgets. - RecipeSummaryRow: inputs, arrow, outputs, cycle time (REQ-UI-RECIPE-SUMMARY), which is now the panel's only display of the cycle time. - CountRow, StatusPill, EmptyNote. Behaviour that changed with them: - The station card shows damage, range and fire rate as the requirement asks (REQ-UI-STATION-STATS-PANEL) rather than the combined DPS it showed before. - A ship's behaviour moves from a stats row into the card header (REQ-UI-SHIP-BEHAVIOR). ShipStatsPanel keeps setBehavior for the balancing tool's inspect window, which has no header to put it in. - A construction site's card shows a progress bar and the "no buffers until built" note (REQ-UI-SELECTION-CARD), and now also its recipe summary, since that is configuration and a site carries it (REQ-BLD-SITE-CONFIG). Costing a shipyard site's schematic needed computeShipyardRequiredMaterials to take a stored configuration as well as a live building -- one overload, so the module sum still exists once. ShipStatsPanel is rebuilt on StatRow, BarRow and SectionBox, so the selection card, the layout dialog's design preview and the balancing tool read alike. Those three parts are compiled into the balancing target, which does not link the ui library; keeping them sim-free is what makes that possible, and the build enforces it. Build clean, 541 tests pass, app and balancing tool both run with no Qt warnings. Visual check pending. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcReq7hVk4KUPhTDKWAG7K
106 lines
3.3 KiB
C++
106 lines
3.3 KiB
C++
#include "FieldMultiContent.h"
|
|
|
|
#include <map>
|
|
#include <string>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include "CountRow.h"
|
|
#include "DebrisScrap.h"
|
|
#include "DisplayName.h"
|
|
#include "EntityAdmin.h"
|
|
#include "FactionComponent.h"
|
|
#include "ShipIdentityComponent.h"
|
|
#include "Simulation.h"
|
|
#include "StatRow.h"
|
|
#include "StationBodyComponent.h"
|
|
|
|
FieldMultiContent::FieldMultiContent(const SelectionContext& context,
|
|
const SelectionRequest& request, QWidget* parent)
|
|
: SelectionContent(context, std::nullopt, parent)
|
|
, m_debris(request.debris)
|
|
, m_scrapRow(nullptr)
|
|
{
|
|
setIdentity(QPixmap(), tr("Mixed selection"));
|
|
setCountSlot(static_cast<int>(request.actors.size() + request.debris.size()));
|
|
|
|
buildSummary(request.actors);
|
|
}
|
|
|
|
void FieldMultiContent::buildSummary(const std::vector<entt::entity>& actors)
|
|
{
|
|
EntityAdmin& admin = getContext().sim->getAdmin();
|
|
|
|
// Grouped by faction, kind and ship schematic, in the order the groups are first
|
|
// seen (REQ-UI-FIELD-MULTI-SELECTION).
|
|
std::vector<QString> keys;
|
|
std::map<QString, int> counts;
|
|
std::map<QString, QString> labels;
|
|
|
|
for (entt::entity actor : actors)
|
|
{
|
|
if (!admin.isValid(actor)) { continue; }
|
|
const bool isEnemy = admin.hasAll<FactionComponent>(actor)
|
|
&& admin.get<FactionComponent>(actor).isEnemy;
|
|
|
|
QString key;
|
|
QString label;
|
|
if (admin.hasAll<ShipIdentityComponent>(actor))
|
|
{
|
|
const std::string& id = admin.get<ShipIdentityComponent>(actor).schematicId;
|
|
const QString name = QString::fromStdString(toDisplayName(id));
|
|
key = (isEnemy ? QStringLiteral("ship:enemy:")
|
|
: QStringLiteral("ship:player:"))
|
|
+ QString::fromStdString(id);
|
|
label = isEnemy ? tr("Enemy %1").arg(name) : name;
|
|
}
|
|
else if (admin.hasAll<StationBodyComponent>(actor))
|
|
{
|
|
key = isEnemy ? QStringLiteral("station:enemy")
|
|
: QStringLiteral("station:player");
|
|
label = isEnemy ? tr("Enemy Defence Station") : tr("Player Defence Station");
|
|
}
|
|
else
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (counts.find(key) == counts.end())
|
|
{
|
|
keys.push_back(key);
|
|
labels[key] = label;
|
|
}
|
|
counts[key] += 1;
|
|
}
|
|
|
|
for (const QString& key : keys)
|
|
{
|
|
getRuntimeLayout()->addWidget(
|
|
new CountRow(QPixmap(), labels[key], counts[key], this));
|
|
}
|
|
|
|
if (!m_debris.empty())
|
|
{
|
|
getRuntimeLayout()->addWidget(new CountRow(
|
|
QPixmap(), tr("Debris"), static_cast<int>(m_debris.size()), this));
|
|
|
|
// Indented under the debris row, so the total reads as belonging to it
|
|
// (REQ-UI-DEBRIS-PANEL).
|
|
m_scrapRow = new StatRow(tr("holding"), this);
|
|
m_scrapRow->setIndented(true);
|
|
m_scrapRow->setValueEmphasized(true);
|
|
getRuntimeLayout()->addWidget(m_scrapRow);
|
|
}
|
|
}
|
|
|
|
void FieldMultiContent::refreshRuntime()
|
|
{
|
|
// The counts are fixed for a given selection -- an actor leaving it re-publishes the
|
|
// selection and rebuilds this card -- but the scrap falls as the debris is collected.
|
|
if (m_scrapRow)
|
|
{
|
|
m_scrapRow->setValue(tr("%1 scrap")
|
|
.arg(sumDebrisScrap(getContext().sim->getAdmin(), m_debris)));
|
|
}
|
|
}
|