split the selection panel into one card per kind of selection
This commit is contained in:
42
src/ui/selection/HqContent.cpp
Normal file
42
src/ui/selection/HqContent.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "HqContent.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "EntityAdmin.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "HqProxyComponent.h"
|
||||
#include "SelectionNames.h"
|
||||
#include "Simulation.h"
|
||||
|
||||
HqContent::HqContent(const SelectionContext& context, const SelectionRequest& request,
|
||||
QWidget* parent)
|
||||
// The HQ is placed before the game starts and can never be deconstructed
|
||||
// (REQ-BLD-DECONSTRUCT), so it is never a construction site.
|
||||
: SelectionContent(context, std::nullopt, parent)
|
||||
{
|
||||
m_stockLabel = new QLabel(this);
|
||||
m_hpLabel = new QLabel(this);
|
||||
getRuntimeLayout()->addWidget(m_stockLabel);
|
||||
getRuntimeLayout()->addWidget(m_hpLabel);
|
||||
|
||||
setBuildingIdentity(BuildingType::Hq, getBuildingTypeName(BuildingType::Hq));
|
||||
}
|
||||
|
||||
void HqContent::refreshRuntime()
|
||||
{
|
||||
m_stockLabel->setText(
|
||||
tr("Building blocks: %1").arg(getContext().sim->getBuildingBlocksStock()));
|
||||
|
||||
// The HQ's health lives on its proxy entity, not on the building
|
||||
// (REQ-HQ-STATS, REQ-UI-HP-BARS).
|
||||
EntityAdmin& admin = getContext().sim->getAdmin();
|
||||
admin.forEach<HqProxyComponent, HealthComponent>(
|
||||
[this](entt::entity /*entity*/, const HqProxyComponent& /*proxy*/,
|
||||
const HealthComponent& health)
|
||||
{
|
||||
m_hpLabel->setText(tr("HP: %1 / %2")
|
||||
.arg(static_cast<int>(health.hp + 0.5f))
|
||||
.arg(static_cast<int>(health.maxHp + 0.5f)));
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user