From b133a21914cc9d55f80ffd98b5d7e5243bb87cd5 Mon Sep 17 00:00:00 2001 From: Malte Langkabel Date: Mon, 3 Aug 2026 21:53:19 +0200 Subject: [PATCH] make BlueprintPanel read the block stock from the simulation BlueprintPanel was the second panel caching BuildingBlocksChangedEvent's payload as truth; it already held a Simulation*, so refreshButtonStates() now re-reads getBuildingBlocksStock() at the point of use, per the "events are refresh signals" rule. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01YHcUerKAZKWNvSKJxYKbnG --- src/ui/BlueprintPanel.cpp | 8 ++++---- src/ui/BlueprintPanel.h | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ui/BlueprintPanel.cpp b/src/ui/BlueprintPanel.cpp index 8dcbdc3..f6b8c2a 100644 --- a/src/ui/BlueprintPanel.cpp +++ b/src/ui/BlueprintPanel.cpp @@ -27,7 +27,6 @@ BlueprintPanel::BlueprintPanel(Simulation* sim, const GameConfig* config, QWidge : QWidget(parent) , m_sim(sim) , m_config(config) - , m_currentBlocks(0) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setContentsMargins(4, 4, 4, 4); @@ -71,9 +70,8 @@ void BlueprintPanel::onSelectionChanged(const std::vector& ids) refreshButtonStates(); } -void BlueprintPanel::handleEvent(std::shared_ptr event) +void BlueprintPanel::handleEvent(std::shared_ptr /*event*/) { - m_currentBlocks = event->blocks; refreshButtonStates(); } @@ -247,10 +245,12 @@ void BlueprintPanel::refreshButtonStates() // A construction site counts the same as an operational building (REQ-UI-BLUEPRINT-CREATE). m_createBtn->setEnabled(selectionHasPlaceableBuilding(*m_sim, m_selectedBuildingIds)); + const int blocks = m_sim->getBuildingBlocksStock(); + for (int i = 0; i < static_cast(m_blueprintButtons.size()); ++i) { const int cost = computeBlueprintCost(m_blueprints[static_cast(i)]); - const bool canAfford = m_currentBlocks >= cost; + const bool canAfford = blocks >= cost; m_blueprintButtons[static_cast(i)]->setEnabled( canAfford || m_activeIndex == i); } diff --git a/src/ui/BlueprintPanel.h b/src/ui/BlueprintPanel.h index 513d0ef..ae4dd9c 100644 --- a/src/ui/BlueprintPanel.h +++ b/src/ui/BlueprintPanel.h @@ -53,10 +53,11 @@ private: void loadFromDisk(); void saveToDisk() const; + // The simulation is the single source of truth for the block stock; the + // change event is only a refresh signal. Simulation* m_sim; const GameConfig* m_config; std::vector m_selectedBuildingIds; - int m_currentBlocks; std::optional m_activeIndex; // nullopt = no blueprint selected std::vector m_blueprints; std::vector m_blueprintButtons;