Show total building block cost in multi-selection panel
Implement the REQ-UI-MULTI-SELECTION addition: the selected building panel now shows the total placement cost of a multi-selection, counting only player-placeable buildings (HQ and defence stations excluded). Construction sites are charged their type's full cost. Add a shared BuildingsConfig::findBuildingDef accessor and reuse it in BlueprintPanel to remove the duplicated by-type lookup loops. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DZR44tA8sn4dPqDzAVXyps
This commit is contained in:
@@ -31,4 +31,18 @@ struct BuildingDef
|
|||||||
struct BuildingsConfig
|
struct BuildingsConfig
|
||||||
{
|
{
|
||||||
std::vector<BuildingDef> buildings;
|
std::vector<BuildingDef> buildings;
|
||||||
|
|
||||||
|
// Returns the definition for the given building type, or nullptr if the
|
||||||
|
// type has no entry in buildings.toml.
|
||||||
|
const BuildingDef* findBuildingDef(BuildingType type) const
|
||||||
|
{
|
||||||
|
for (const BuildingDef& def : buildings)
|
||||||
|
{
|
||||||
|
if (def.type == type)
|
||||||
|
{
|
||||||
|
return &def;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -157,14 +157,8 @@ Blueprint BlueprintPanel::createBlueprintFromSelection() const
|
|||||||
{
|
{
|
||||||
const Building* b = m_sim->buildings().findBuilding(id);
|
const Building* b = m_sim->buildings().findBuilding(id);
|
||||||
if (!b) { continue; }
|
if (!b) { continue; }
|
||||||
const bool placeable = [&]() {
|
const BuildingDef* def = m_config->buildings.findBuildingDef(b->type);
|
||||||
for (const BuildingDef& def : m_config->buildings.buildings)
|
if (def && def->playerPlaceable) { entries.push_back({ b }); }
|
||||||
{
|
|
||||||
if (def.type == b->type) { return def.playerPlaceable; }
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}();
|
|
||||||
if (placeable) { entries.push_back({ b }); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entries.empty()) { return Blueprint{}; }
|
if (entries.empty()) { return Blueprint{}; }
|
||||||
@@ -213,14 +207,8 @@ int BlueprintPanel::computeBlueprintCost(const Blueprint& bp) const
|
|||||||
int total = 0;
|
int total = 0;
|
||||||
for (const BlueprintBuilding& bb : bp.buildings)
|
for (const BlueprintBuilding& bb : bp.buildings)
|
||||||
{
|
{
|
||||||
for (const BuildingDef& def : m_config->buildings.buildings)
|
const BuildingDef* def = m_config->buildings.findBuildingDef(bb.type);
|
||||||
{
|
if (def) { total += def->cost; }
|
||||||
if (def.type == bb.type)
|
|
||||||
{
|
|
||||||
total += def.cost;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -694,6 +694,7 @@ void SelectedBuildingPanel::buildMulti(const std::vector<BuildingId>& ids)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool hasBelt = false;
|
bool hasBelt = false;
|
||||||
|
int totalCost = 0;
|
||||||
QString text;
|
QString text;
|
||||||
for (const std::pair<const BuildingType, int>& entry : counts)
|
for (const std::pair<const BuildingType, int>& entry : counts)
|
||||||
{
|
{
|
||||||
@@ -703,7 +704,15 @@ void SelectedBuildingPanel::buildMulti(const std::vector<BuildingId>& ids)
|
|||||||
{
|
{
|
||||||
hasBelt = true;
|
hasBelt = true;
|
||||||
}
|
}
|
||||||
|
// Total placement cost counts only player-placeable buildings; the HQ
|
||||||
|
// and defence stations are excluded (REQ-UI-MULTI-SELECTION).
|
||||||
|
const BuildingDef* def = m_config->buildings.findBuildingDef(entry.first);
|
||||||
|
if (def && def->playerPlaceable)
|
||||||
|
{
|
||||||
|
totalCost += def->cost * entry.second;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
text += tr("Total: %1 Building Blocks").arg(totalCost);
|
||||||
m_titleLabel->setText(text.trimmed());
|
m_titleLabel->setText(text.trimmed());
|
||||||
m_titleLabel->show();
|
m_titleLabel->show();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user