From c9c5c30b0d7939f6cc5308d8066d4343906eb81f Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Mon, 20 Apr 2026 22:19:43 +0200 Subject: [PATCH] change input/output buffer item count display --- docs/requirements.md | 2 +- src/ui/SelectedBuildingPanel.cpp | 72 ++++++++++++++++++++++++++++---- src/ui/SelectedBuildingPanel.h | 4 ++ 3 files changed, 69 insertions(+), 9 deletions(-) diff --git a/docs/requirements.md b/docs/requirements.md index 3708a3c..2a85a7f 100644 --- a/docs/requirements.md +++ b/docs/requirements.md @@ -194,7 +194,7 @@ The screen is divided into three vertical sections: ### Selected Building Panel - REQ-UI-EMPTY-SELECTION: When no building is selected, the panel is empty. -- REQ-UI-SINGLE-SELECTION: When one building is selected, the panel shows: building name, current recipe or blueprint selection, input buffer contents, and output buffer contents. +- REQ-UI-SINGLE-SELECTION: When one building is selected, the panel shows: building name, current recipe or blueprint selection, input buffer contents, and output buffer contents. Buffer counts are displayed as `a/b` where `a` is the current item count and `b` is the per-cycle amount (items consumed per run for inputs; items produced per run for outputs). - REQ-UI-MULTI-SELECT: The player selects multiple buildings by box-drag or by Ctrl+clicking individual buildings to add or remove them from the selection. - REQ-UI-MULTI-SELECTION: When multiple buildings are selected, the panel shows how many of each building type are selected. No per-building detail is shown. - REQ-UI-CONFIG-INLINE: Recipe, blueprint, ship stance, and target priority configuration for a selected building is shown and changed inline within this panel. diff --git a/src/ui/SelectedBuildingPanel.cpp b/src/ui/SelectedBuildingPanel.cpp index 240bacf..fdb454f 100644 --- a/src/ui/SelectedBuildingPanel.cpp +++ b/src/ui/SelectedBuildingPanel.cpp @@ -193,21 +193,44 @@ void SelectedBuildingPanel::buildSingle(EntityId id) void SelectedBuildingPanel::refreshBuffers(const Building* b) { + const RecipeDef* recipe = findRecipe(b); + const ShipDef* shipDef = (b->type == BuildingType::Shipyard) + ? findShipDef(b->recipeId) + : nullptr; + QString bufText; + if (!b->inputBuffer.counts.empty()) { bufText += "Input: "; for (const std::pair& entry : b->inputBuffer.counts) { - const std::map::const_iterator cap = - b->inputBuffer.caps.find(entry.first); - const int capVal = (cap != b->inputBuffer.caps.end()) ? cap->second : 0; + int perCycle = 0; + if (recipe) + { + for (const RecipeIngredient& ing : recipe->inputs) + { + if (ing.item == entry.first.id) { perCycle = ing.amount; break; } + } + } + else if (shipDef) + { + for (const RecipeIngredient& mat : shipDef->blueprint.materials) + { + if (mat.item == entry.first.id) { perCycle = mat.amount; break; } + } + } bufText += QString::fromStdString(entry.first.id) - + ": " + QString::number(entry.second) - + "/" + QString::number(capVal) + " "; + + ": " + QString::number(entry.second); + if (perCycle > 0) + { + bufText += "/" + QString::number(perCycle); + } + bufText += " "; } bufText += "\n"; } + if (!b->outputBuffer.items.empty()) { std::map outCounts; @@ -215,17 +238,50 @@ void SelectedBuildingPanel::refreshBuffers(const Building* b) { outCounts[item.type.id]++; } - bufText += "Output(" + QString::number(static_cast(b->outputBuffer.items.size())) - + "/" + QString::number(b->outputBuffer.capacity) + "): "; + bufText += "Output: "; for (const std::pair& entry : outCounts) { + int perCycle = 0; + if (recipe) + { + for (const RecipeOutput& out : recipe->outputs) + { + if (out.item == entry.first) { perCycle = out.amount; break; } + } + } bufText += QString::fromStdString(entry.first) - + ":" + QString::number(entry.second) + " "; + + ": " + QString::number(entry.second); + if (perCycle > 0) + { + bufText += "/" + QString::number(perCycle); + } + bufText += " "; } } + m_buffersLabel->setText(bufText); } +const RecipeDef* SelectedBuildingPanel::findRecipe(const Building* b) const +{ + if (b->recipeId.empty()) { return nullptr; } + for (const RecipeDef& r : m_config->recipes.recipes) + { + if (r.id == b->recipeId && r.building == b->type) { return &r; } + } + return nullptr; +} + +const ShipDef* SelectedBuildingPanel::findShipDef(const std::string& id) const +{ + if (id.empty()) { return nullptr; } + for (const ShipDef& s : m_config->ships.ships) + { + if (s.id == id) { return &s; } + } + return nullptr; +} + void SelectedBuildingPanel::onStateUpdated(Tick /*tick*/, int /*blocks*/, double /*speed*/) { if (m_singleId == kInvalidEntityId) { return; } diff --git a/src/ui/SelectedBuildingPanel.h b/src/ui/SelectedBuildingPanel.h index ce1c7fe..b117eaa 100644 --- a/src/ui/SelectedBuildingPanel.h +++ b/src/ui/SelectedBuildingPanel.h @@ -8,6 +8,8 @@ #include "Building.h" #include "EntityId.h" #include "GameConfig.h" +#include "RecipesConfig.h" +#include "ShipsConfig.h" #include "Tick.h" class Simulation; @@ -39,6 +41,8 @@ private: void buildSingle(EntityId id); void buildMulti(const std::vector& ids); void refreshBuffers(const Building* b); + const RecipeDef* findRecipe(const Building* b) const; + const ShipDef* findShipDef(const std::string& id) const; Simulation* m_sim; const GameConfig* m_config;