split the selection panel into one card per kind of selection

This commit is contained in:
2026-08-07 18:38:55 +02:00
parent cc0ef856e3
commit 2289277e12
60 changed files with 3014 additions and 1559 deletions

View File

@@ -0,0 +1,66 @@
#include "StationContent.h"
#include <QLabel>
#include <QVBoxLayout>
#include "EntityAdmin.h"
#include "FactionComponent.h"
#include "HealthComponent.h"
#include "ModuleOwnerComponent.h"
#include "Simulation.h"
#include "WeaponComponent.h"
StationContent::StationContent(const SelectionContext& context,
const SelectionRequest& request, QWidget* parent)
: SelectionContent(context, std::nullopt, parent)
, m_entity(request.actors.front())
{
m_statsLabel = new QLabel(this);
m_statsLabel->setWordWrap(true);
getRuntimeLayout()->addWidget(m_statsLabel);
EntityAdmin& admin = context.sim->getAdmin();
const bool isEnemy = admin.isValid(m_entity)
&& admin.hasAll<FactionComponent>(m_entity)
&& admin.get<FactionComponent>(m_entity).isEnemy;
setIdentity(QPixmap(), isEnemy ? tr("Enemy Defence Station")
: tr("Player Defence Station"));
}
void StationContent::refreshRuntime()
{
EntityAdmin& admin = getContext().sim->getAdmin();
if (!admin.isValid(m_entity) || !admin.hasAll<HealthComponent>(m_entity))
{
return;
}
const HealthComponent& health = admin.get<HealthComponent>(m_entity);
// A station's weapons are child module entities pointing back at it, so its combined
// damage and range are summed over those rather than read off the station itself.
float totalDps = 0.0f;
float maxRange = 0.0f;
bool hasWeapon = false;
const entt::entity station = m_entity;
admin.forEach<ModuleOwnerComponent, WeaponComponent>(
[&](entt::entity /*child*/, const ModuleOwnerComponent& owner,
const WeaponComponent& weapon)
{
if (owner.owner != station) { return; }
hasWeapon = true;
totalDps += weapon.damage * weapon.fireRateHz;
if (weapon.range_tiles > maxRange) { maxRange = weapon.range_tiles; }
});
QString text = tr("HP: %1 / %2")
.arg(static_cast<int>(health.hp + 0.5f))
.arg(static_cast<int>(health.maxHp + 0.5f));
if (hasWeapon)
{
text += tr("\nDPS: %1")
.arg(QString::number(static_cast<double>(totalDps), 'f', 1));
text += tr("\nRange: %1 tiles")
.arg(QString::number(static_cast<double>(maxRange), 'f', 1));
}
m_statsLabel->setText(text);
}