give the selection cards their own parts instead of label blobs

This commit is contained in:
2026-08-07 18:43:23 +02:00
parent 2289277e12
commit 075e44d295
54 changed files with 1505 additions and 533 deletions

View File

@@ -3,14 +3,13 @@
#include <QPushButton>
#include <QVBoxLayout>
#include "Building.h"
#include "BuildingTarget.h"
#include "EventManager.h"
#include "GameConfig.h"
#include "LayoutDialogRequestedEvent.h"
#include "ProductionRules.h"
#include "RecipeSelectionControl.h"
#include "SelectionNames.h"
#include "SectionBox.h"
#include "ShipLayoutPreview.h"
ShipyardContent::ShipyardContent(const SelectionContext& context,
@@ -19,12 +18,17 @@ ShipyardContent::ShipyardContent(const SelectionContext& context,
{
m_schematicControl = new RecipeSelectionControl(context, getBuildingId(),
BuildingType::Shipyard, this);
m_layoutPreview = new ShipLayoutPreview(this);
m_configureButton = new QPushButton(tr("Configure Layout"), this);
getConfigurationLayout()->addWidget(m_schematicControl);
getConfigurationLayout()->addWidget(m_layoutPreview);
getConfigurationLayout()->addWidget(m_configureButton);
m_layoutSection = new SectionBox(tr("Layout"), this);
m_layoutPreview = new ShipLayoutPreview(m_layoutSection);
m_configureButton = new QPushButton(tr("Configure Layout"), m_layoutSection);
m_layoutSection->getContentLayout()->addWidget(m_layoutPreview);
m_layoutSection->getContentLayout()->addWidget(m_configureButton);
// Ahead of the recipe summary the base adds, so the card reads schematic, layout,
// then what one ship costs.
getConfigurationLayout()->insertWidget(0, m_schematicControl);
getConfigurationLayout()->insertWidget(1, m_layoutSection);
const BuildingId id = getBuildingId();
connect(m_configureButton, &QPushButton::clicked, this, [id]() {
@@ -33,15 +37,8 @@ ShipyardContent::ShipyardContent(const SelectionContext& context,
});
}
void ShipyardContent::refreshConfiguration()
void ShipyardContent::refreshControls(const BuildingTarget& target)
{
const BuildingTarget target = resolveBuildingTarget(getContext(), getBuildingId());
if (!target.isValid())
{
return;
}
setBuildingIdentity(target.type, getBuildingTypeName(target.type));
m_schematicControl->setRecipeId(target.recipeId);
// The preview and Configure button are always shown for a shipyard and are only
@@ -68,12 +65,12 @@ void ShipyardContent::refreshConfiguration()
}
BufferedBuildingContent::CycleInfo ShipyardContent::getCycleInfo(
const Building& building) const
const BuildingTarget& target) const
{
CycleInfo info;
const ShipDef* shipDef = building.recipeId.empty()
const ShipDef* shipDef = target.recipeId.empty()
? nullptr
: getContext().config->ships.findShipDef(building.recipeId);
: getContext().config->ships.findShipDef(target.recipeId);
if (!shipDef)
{
return info;
@@ -82,13 +79,15 @@ BufferedBuildingContent::CycleInfo ShipyardContent::getCycleInfo(
// The schematic's materials plus every placed module's, which is also what sized the
// input buffers (REQ-BLD-SHIPYARD). The simulation owns that sum, so the panel asks
// it rather than adding the modules up a second time.
info.perCycleInputs =
computeShipyardRequiredMaterials(*getContext().config, building);
info.perCycleInputs = computeShipyardRequiredMaterials(
*getContext().config, target.recipeId, target.shipLayout);
// A shipyard's output is the ship itself, which never lands in an item buffer -- so
// the summary shows one ship rather than an item id.
info.durationSeconds = shipDef->schematic.productionTimeSeconds;
if (building.shipLayout.has_value())
if (target.shipLayout.has_value())
{
for (const PlacedModule& placed : building.shipLayout->placedModules)
for (const PlacedModule& placed : target.shipLayout->placedModules)
{
const ModuleDef* moduleDef =
getContext().config->modules.findModuleDef(placed.moduleId);