make HeaderBar read block stock and expansion cost from the simulation

This commit is contained in:
2026-08-03 21:04:43 +02:00
parent 932b57720c
commit 594c3b93c5
3 changed files with 27 additions and 19 deletions

View File

@@ -20,6 +20,7 @@
class QLabel;
class QPushButton;
class ItemIconCache;
class Simulation;
class HeaderBar : public QWidget,
public CombinedEventHandler<TickAdvancedEvent,
@@ -35,8 +36,8 @@ public:
// itemsIconDir holds the per-item icon SVGs (REQ-UI-ITEM-ICON); used to show the
// building_block icon in the stock display and expand button (REQ-UI-BLOCKS-ICON,
// REQ-UI-EXPAND-BUTTON).
HeaderBar(const GameConfig* config, const std::string& itemsIconDir,
QWidget* parent = nullptr);
HeaderBar(const Simulation* sim, const GameConfig* config,
const std::string& itemsIconDir, QWidget* parent = nullptr);
~HeaderBar() override;
private slots:
@@ -54,9 +55,10 @@ private:
// expansion cost and building block stock (REQ-UI-EXPAND-BUTTON).
void updateExpandButton();
// Refreshes the building blocks stock display from m_blocks: `Stock: <n>` with
// the building_block icon after it, or the `Stock: <n> Blocks` text fallback when
// no icon file exists (REQ-UI-BLOCKS-ICON).
// Refreshes the building blocks stock display from the simulation:
// `Stock: <n>` with the building_block icon after it, or the
// `Stock: <n> Blocks` text fallback when no icon file exists
// (REQ-UI-BLOCKS-ICON).
void updateBlocksLabel();
// The building_block icon at the header's text height, or a null pixmap when no
@@ -73,8 +75,9 @@ private:
std::unique_ptr<ItemIconCache> m_itemIcons;
int m_blocks = 0;
int m_expansionCost = 0;
// The simulation is the single source of truth for the block stock and the
// expansion cost; the change events are only refresh signals.
const Simulation* m_sim;
static const double kSpeeds[];
static const int kSpeedCount;