give the selection cards their own parts instead of label blobs
This commit is contained in:
@@ -1,11 +1,16 @@
|
||||
#include "HqContent.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <vector>
|
||||
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "BarRow.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "HqProxyComponent.h"
|
||||
#include "IconCaption.h"
|
||||
#include "ItemChipRow.h"
|
||||
#include "SectionBox.h"
|
||||
#include "SelectionNames.h"
|
||||
#include "Simulation.h"
|
||||
|
||||
@@ -15,18 +20,28 @@ HqContent::HqContent(const SelectionContext& context, const SelectionRequest& re
|
||||
// (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);
|
||||
m_stockSection = new SectionBox(tr("Building blocks"), this);
|
||||
m_stockChips = new ItemChipRow(context.itemIcons, m_stockSection);
|
||||
m_stockSection->getContentLayout()->addWidget(m_stockChips);
|
||||
|
||||
m_hpBar = new BarRow(tr("HP"), this);
|
||||
|
||||
getRuntimeLayout()->addWidget(m_stockSection);
|
||||
getRuntimeLayout()->addWidget(m_hpBar);
|
||||
|
||||
setBuildingIdentity(BuildingType::Hq, getBuildingTypeName(BuildingType::Hq));
|
||||
}
|
||||
|
||||
void HqContent::refreshRuntime()
|
||||
{
|
||||
m_stockLabel->setText(
|
||||
tr("Building blocks: %1").arg(getContext().sim->getBuildingBlocksStock()));
|
||||
// Not a buffer: blocks delivered by belt go straight into the global stock
|
||||
// (REQ-HQ-BELT-INPUT). Showing it here is what tells the player to route them here
|
||||
// (REQ-UI-HQ-PANEL).
|
||||
ItemChipRow::Entry stock;
|
||||
stock.itemId = kBlockItemId;
|
||||
stock.countText = QString::number(getContext().sim->getBuildingBlocksStock());
|
||||
stock.subLine = tr("in stock");
|
||||
m_stockChips->setEntries(std::vector<ItemChipRow::Entry>{ stock });
|
||||
|
||||
// The HQ's health lives on its proxy entity, not on the building
|
||||
// (REQ-HQ-STATS, REQ-UI-HP-BARS).
|
||||
@@ -35,7 +50,10 @@ void HqContent::refreshRuntime()
|
||||
[this](entt::entity /*entity*/, const HqProxyComponent& /*proxy*/,
|
||||
const HealthComponent& health)
|
||||
{
|
||||
m_hpLabel->setText(tr("HP: %1 / %2")
|
||||
const double fraction = (health.maxHp > 0.0f)
|
||||
? static_cast<double>(health.hp) / health.maxHp
|
||||
: 0.0;
|
||||
m_hpBar->setValue(fraction, tr("%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