#include "FieldMultiContent.h" #include #include #include #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(request.actors.size() + request.debris.size())); buildSummary(request.actors); } void FieldMultiContent::buildSummary(const std::vector& 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 keys; std::map counts; std::map labels; for (entt::entity actor : actors) { if (!admin.isValid(actor)) { continue; } const bool isEnemy = admin.hasAll(actor) && admin.get(actor).isEnemy; QString key; QString label; if (admin.hasAll(actor)) { const std::string& id = admin.get(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(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(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))); } }