make HeaderBar read block stock and expansion cost from the simulation
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "EventManager.h"
|
||||
#include "IconCaption.h"
|
||||
#include "ItemIconCache.h"
|
||||
#include "Simulation.h"
|
||||
#include "SpeedChangeRequestedEvent.h"
|
||||
#include "Tick.h"
|
||||
|
||||
@@ -30,11 +31,12 @@ namespace
|
||||
const double HeaderBar::kSpeeds[] = { 0.0, 0.5, 1.0, 2.0, 10.0 };
|
||||
const int HeaderBar::kSpeedCount = 5;
|
||||
|
||||
HeaderBar::HeaderBar(const GameConfig* config, const std::string& itemsIconDir,
|
||||
QWidget* parent)
|
||||
HeaderBar::HeaderBar(const Simulation* sim, const GameConfig* config,
|
||||
const std::string& itemsIconDir, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_itemIcons(std::make_unique<ItemIconCache>(
|
||||
QString::fromStdString(itemsIconDir)))
|
||||
, m_sim(sim)
|
||||
{
|
||||
QHBoxLayout* layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(8, 4, 8, 4);
|
||||
@@ -115,16 +117,14 @@ void HeaderBar::handleEvent(std::shared_ptr<const TickAdvancedEvent> event)
|
||||
.arg(totalSeconds % 60, 2, 10, QChar('0')));
|
||||
}
|
||||
|
||||
void HeaderBar::handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event)
|
||||
void HeaderBar::handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> /*event*/)
|
||||
{
|
||||
m_blocks = event->blocks;
|
||||
updateBlocksLabel();
|
||||
updateExpandButton();
|
||||
}
|
||||
|
||||
void HeaderBar::handleEvent(std::shared_ptr<const ExpansionCostChangedEvent> event)
|
||||
void HeaderBar::handleEvent(std::shared_ptr<const ExpansionCostChangedEvent> /*event*/)
|
||||
{
|
||||
m_expansionCost = event->cost;
|
||||
updateExpandButton();
|
||||
}
|
||||
|
||||
@@ -138,32 +138,37 @@ QPixmap HeaderBar::blockIcon() const
|
||||
|
||||
void HeaderBar::updateBlocksLabel()
|
||||
{
|
||||
const int blocks = m_sim->getBuildingBlocksStock();
|
||||
|
||||
const QPixmap icon = blockIcon();
|
||||
if (icon.isNull())
|
||||
{
|
||||
// Fallback text form when no building_block icon exists (REQ-UI-BLOCKS-ICON).
|
||||
m_blocksLabel->setText(tr("Stock: %1 Blocks").arg(m_blocks));
|
||||
m_blocksLabel->setText(tr("Stock: %1 Blocks").arg(blocks));
|
||||
return;
|
||||
}
|
||||
m_blocksLabel->setPixmap(renderCaptionWithIcon(
|
||||
tr("Stock: %1").arg(m_blocks), icon, font(),
|
||||
tr("Stock: %1").arg(blocks), icon, font(),
|
||||
m_blocksLabel->palette().color(QPalette::WindowText)));
|
||||
}
|
||||
|
||||
void HeaderBar::updateExpandButton()
|
||||
{
|
||||
m_expandButton->setEnabled(m_blocks >= m_expansionCost);
|
||||
const int blocks = m_sim->getBuildingBlocksStock();
|
||||
const int expansionCost = m_sim->getCurrentExpansionCost();
|
||||
|
||||
m_expandButton->setEnabled(blocks >= expansionCost);
|
||||
|
||||
const QPixmap icon = blockIcon();
|
||||
if (icon.isNull())
|
||||
{
|
||||
// Fallback text form when no building_block icon exists (REQ-UI-EXPAND-BUTTON).
|
||||
m_expandButton->setIcon(QIcon());
|
||||
m_expandButton->setText(tr("Expand: %1 Blocks").arg(m_expansionCost));
|
||||
m_expandButton->setText(tr("Expand: %1 Blocks").arg(expansionCost));
|
||||
return;
|
||||
}
|
||||
|
||||
const QString text = tr("Expand: %1").arg(m_expansionCost);
|
||||
const QString text = tr("Expand: %1").arg(expansionCost);
|
||||
const QPalette& pal = m_expandButton->palette();
|
||||
const QPixmap normal = renderCaptionWithIcon(
|
||||
text, icon, m_expandButton->font(), pal.color(QPalette::ButtonText));
|
||||
|
||||
Reference in New Issue
Block a user