give the selection cards their own parts instead of label blobs
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
#include "StationContent.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "BarRow.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "FactionComponent.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "ModuleOwnerComponent.h"
|
||||
#include "Simulation.h"
|
||||
#include "StatRow.h"
|
||||
#include "WeaponComponent.h"
|
||||
|
||||
StationContent::StationContent(const SelectionContext& context,
|
||||
@@ -15,9 +16,15 @@ StationContent::StationContent(const SelectionContext& context,
|
||||
: SelectionContent(context, std::nullopt, parent)
|
||||
, m_entity(request.actors.front())
|
||||
{
|
||||
m_statsLabel = new QLabel(this);
|
||||
m_statsLabel->setWordWrap(true);
|
||||
getRuntimeLayout()->addWidget(m_statsLabel);
|
||||
m_hpBar = new BarRow(tr("HP"), this);
|
||||
m_damageRow = new StatRow(tr("Damage"), this);
|
||||
m_rangeRow = new StatRow(tr("Range"), this);
|
||||
m_fireRateRow = new StatRow(tr("Fire rate"), this);
|
||||
|
||||
getRuntimeLayout()->addWidget(m_hpBar);
|
||||
getRuntimeLayout()->addWidget(m_damageRow);
|
||||
getRuntimeLayout()->addWidget(m_rangeRow);
|
||||
getRuntimeLayout()->addWidget(m_fireRateRow);
|
||||
|
||||
EntityAdmin& admin = context.sim->getAdmin();
|
||||
const bool isEnemy = admin.isValid(m_entity)
|
||||
@@ -36,11 +43,19 @@ void StationContent::refreshRuntime()
|
||||
}
|
||||
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 double hpFraction = (health.maxHp > 0.0f)
|
||||
? static_cast<double>(health.hp) / health.maxHp
|
||||
: 0.0;
|
||||
m_hpBar->setValue(hpFraction, tr("%1 / %2")
|
||||
.arg(static_cast<int>(health.hp + 0.5f))
|
||||
.arg(static_cast<int>(health.maxHp + 0.5f)));
|
||||
|
||||
// A station's weapons are child module entities pointing back at it, so its damage,
|
||||
// range and fire rate are read off those rather than off the station itself.
|
||||
float totalDamage = 0.0f;
|
||||
float maxRange = 0.0f;
|
||||
float maxFireRateHz = 0.0f;
|
||||
bool hasWeapon = false;
|
||||
const entt::entity station = m_entity;
|
||||
admin.forEach<ModuleOwnerComponent, WeaponComponent>(
|
||||
[&](entt::entity /*child*/, const ModuleOwnerComponent& owner,
|
||||
@@ -48,19 +63,21 @@ void StationContent::refreshRuntime()
|
||||
{
|
||||
if (owner.owner != station) { return; }
|
||||
hasWeapon = true;
|
||||
totalDps += weapon.damage * weapon.fireRateHz;
|
||||
if (weapon.range_tiles > maxRange) { maxRange = weapon.range_tiles; }
|
||||
totalDamage += weapon.damage;
|
||||
if (weapon.range_tiles > maxRange) { maxRange = weapon.range_tiles; }
|
||||
if (weapon.fireRateHz > maxFireRateHz) { maxFireRateHz = weapon.fireRateHz; }
|
||||
});
|
||||
|
||||
QString text = tr("HP: %1 / %2")
|
||||
.arg(static_cast<int>(health.hp + 0.5f))
|
||||
.arg(static_cast<int>(health.maxHp + 0.5f));
|
||||
m_damageRow->setVisible(hasWeapon);
|
||||
m_rangeRow->setVisible(hasWeapon);
|
||||
m_fireRateRow->setVisible(hasWeapon);
|
||||
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_damageRow->setValue(
|
||||
QString::number(static_cast<double>(totalDamage), 'f', 1));
|
||||
m_rangeRow->setValue(tr("%1 tiles")
|
||||
.arg(QString::number(static_cast<double>(maxRange), 'f', 1)));
|
||||
m_fireRateRow->setValue(tr("%1 /s")
|
||||
.arg(QString::number(static_cast<double>(maxFireRateHz), 'f', 1)));
|
||||
}
|
||||
m_statsLabel->setText(text);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user