The cards were assembled from plain labels carrying whole blocks of text. Replace those with the widget vocabulary the requirements describe, so a part means the same thing wherever it appears and a card is a list of parts rather than a string builder. The parts, all free of Simulation and GameConfig -- they take prepared values, and the contents work out what those are: - StatRow, BarRow, SectionBox: label/value line, captioned fill bar, captioned group. The bar is one part for three things: construction progress, production progress, and HP. - ItemChip / ItemChipRow: buffered items as icon, count and sub-line (REQ-UI-SINGLE-SELECTION). An input chip carries its per-cycle amount, an output chip its count against the buffer capacity. The chips are rebuilt only when the set of items changes, so a 30 Hz refresh moves numbers rather than widgets. - RecipeSummaryRow: inputs, arrow, outputs, cycle time (REQ-UI-RECIPE-SUMMARY), which is now the panel's only display of the cycle time. - CountRow, StatusPill, EmptyNote. Behaviour that changed with them: - The station card shows damage, range and fire rate as the requirement asks (REQ-UI-STATION-STATS-PANEL) rather than the combined DPS it showed before. - A ship's behaviour moves from a stats row into the card header (REQ-UI-SHIP-BEHAVIOR). ShipStatsPanel keeps setBehavior for the balancing tool's inspect window, which has no header to put it in. - A construction site's card shows a progress bar and the "no buffers until built" note (REQ-UI-SELECTION-CARD), and now also its recipe summary, since that is configuration and a site carries it (REQ-BLD-SITE-CONFIG). Costing a shipyard site's schematic needed computeShipyardRequiredMaterials to take a stored configuration as well as a live building -- one overload, so the module sum still exists once. ShipStatsPanel is rebuilt on StatRow, BarRow and SectionBox, so the selection card, the layout dialog's design preview and the balancing tool read alike. Those three parts are compiled into the balancing target, which does not link the ui library; keeping them sim-free is what makes that possible, and the build enforces it. Build clean, 541 tests pass, app and balancing tool both run with no Qt warnings. Visual check pending. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcReq7hVk4KUPhTDKWAG7K
103 lines
3.8 KiB
C++
103 lines
3.8 KiB
C++
#include "ShipyardContent.h"
|
|
|
|
#include <QPushButton>
|
|
#include <QVBoxLayout>
|
|
|
|
#include "BuildingTarget.h"
|
|
#include "EventManager.h"
|
|
#include "GameConfig.h"
|
|
#include "LayoutDialogRequestedEvent.h"
|
|
#include "ProductionRules.h"
|
|
#include "RecipeSelectionControl.h"
|
|
#include "SectionBox.h"
|
|
#include "ShipLayoutPreview.h"
|
|
|
|
ShipyardContent::ShipyardContent(const SelectionContext& context,
|
|
const SelectionRequest& request, QWidget* parent)
|
|
: BufferedBuildingContent(context, request.buildings.front(), parent)
|
|
{
|
|
m_schematicControl = new RecipeSelectionControl(context, getBuildingId(),
|
|
BuildingType::Shipyard, this);
|
|
|
|
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]() {
|
|
EventManager::getInstance()->sendEventImmediately(
|
|
std::make_shared<LayoutDialogRequestedEvent>(id));
|
|
});
|
|
}
|
|
|
|
void ShipyardContent::refreshControls(const BuildingTarget& target)
|
|
{
|
|
m_schematicControl->setRecipeId(target.recipeId);
|
|
|
|
// The preview and Configure button are always shown for a shipyard and are only
|
|
// enabled once a schematic is selected (REQ-MOD-UI-PREVIEW). The schematic arrives
|
|
// by queued command, so this refresh is what picks it up rather than the click that
|
|
// chose it.
|
|
const ShipDef* shipDef = target.recipeId.empty()
|
|
? nullptr
|
|
: getContext().config->ships.findShipDef(target.recipeId);
|
|
const bool hasSchematic = shipDef && !shipDef->layout.empty();
|
|
if (hasSchematic)
|
|
{
|
|
m_layoutPreview->setShipAndLayout(
|
|
shipDef->layout,
|
|
target.shipLayout.has_value() ? *target.shipLayout : ShipLayoutConfig(),
|
|
&getContext().config->modules);
|
|
}
|
|
else
|
|
{
|
|
m_layoutPreview->showPlaceholder();
|
|
}
|
|
m_layoutPreview->setEnabled(hasSchematic);
|
|
m_configureButton->setEnabled(hasSchematic);
|
|
}
|
|
|
|
BufferedBuildingContent::CycleInfo ShipyardContent::getCycleInfo(
|
|
const BuildingTarget& target) const
|
|
{
|
|
CycleInfo info;
|
|
const ShipDef* shipDef = target.recipeId.empty()
|
|
? nullptr
|
|
: getContext().config->ships.findShipDef(target.recipeId);
|
|
if (!shipDef)
|
|
{
|
|
return info;
|
|
}
|
|
|
|
// 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, 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 (target.shipLayout.has_value())
|
|
{
|
|
for (const PlacedModule& placed : target.shipLayout->placedModules)
|
|
{
|
|
const ModuleDef* moduleDef =
|
|
getContext().config->modules.findModuleDef(placed.moduleId);
|
|
if (moduleDef)
|
|
{
|
|
info.durationSeconds += moduleDef->productionTimeSeconds;
|
|
}
|
|
}
|
|
}
|
|
info.runsProduction = true;
|
|
return info;
|
|
}
|