add ship stats panel to ship layout dialog
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include "ShipLayoutDialog.h"
|
||||
#include "ShipStatsPanel.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <functional>
|
||||
@@ -397,6 +398,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
, m_currentRotation(Rotation::East)
|
||||
, m_removeButton(nullptr)
|
||||
, m_gridWidget(nullptr)
|
||||
, m_statsPanel(nullptr)
|
||||
{
|
||||
setWindowTitle(tr("Configure Ship Layout"));
|
||||
setModal(true);
|
||||
@@ -437,17 +439,24 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
rebuildOccupancy();
|
||||
|
||||
// --- UI layout ---
|
||||
QHBoxLayout* mainLayout = new QHBoxLayout(this);
|
||||
QVBoxLayout* outerLayout = new QVBoxLayout(this);
|
||||
|
||||
// Left: grid widget.
|
||||
// Top: grid widget.
|
||||
LayoutGridWidget* gridW = new LayoutGridWidget(this, this);
|
||||
gridW->setGridData(&m_grid, m_rows, m_cols, &m_placedModules, m_config);
|
||||
gridW->setGhostData(m_activeModuleIndex, m_currentRotation);
|
||||
m_gridWidget = gridW;
|
||||
mainLayout->addWidget(m_gridWidget);
|
||||
outerLayout->addWidget(m_gridWidget, 0, Qt::AlignHCenter | Qt::AlignTop);
|
||||
|
||||
// Right: module buttons + confirm/cancel.
|
||||
QVBoxLayout* rightLayout = new QVBoxLayout();
|
||||
// Middle: three-column area (stats | module buttons | blueprints).
|
||||
QHBoxLayout* columnsLayout = new QHBoxLayout();
|
||||
|
||||
// Left column: ship stats panel.
|
||||
m_statsPanel = new ShipStatsPanel(config, this);
|
||||
columnsLayout->addWidget(m_statsPanel);
|
||||
|
||||
// Center column: module selection buttons.
|
||||
QVBoxLayout* centerLayout = new QVBoxLayout();
|
||||
|
||||
QGridLayout* buttonGrid = new QGridLayout();
|
||||
buttonGrid->setSpacing(4);
|
||||
@@ -508,30 +517,35 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
updateGridWidget();
|
||||
});
|
||||
|
||||
rightLayout->addLayout(buttonGrid);
|
||||
rightLayout->addStretch();
|
||||
centerLayout->addLayout(buttonGrid);
|
||||
centerLayout->addStretch();
|
||||
|
||||
// Confirm / Cancel buttons.
|
||||
QHBoxLayout* bottomBar = new QHBoxLayout();
|
||||
QPushButton* confirmBtn = new QPushButton(tr("Confirm"), this);
|
||||
QPushButton* cancelBtn = new QPushButton(tr("Cancel"), this);
|
||||
bottomBar->addWidget(confirmBtn);
|
||||
bottomBar->addWidget(cancelBtn);
|
||||
rightLayout->addLayout(bottomBar);
|
||||
columnsLayout->addLayout(centerLayout);
|
||||
|
||||
connect(confirmBtn, &QPushButton::clicked, this, &ShipLayoutDialog::onConfirm);
|
||||
connect(cancelBtn, &QPushButton::clicked, this, &ShipLayoutDialog::onCancel);
|
||||
|
||||
mainLayout->addLayout(rightLayout);
|
||||
|
||||
// Right: blueprint panel (third column).
|
||||
// Right column: blueprint panel.
|
||||
ShipLayoutBlueprintPanel* bpPanel = new ShipLayoutBlueprintPanel(
|
||||
allBlueprints,
|
||||
m_shipId,
|
||||
[this]() { return m_placedModules; },
|
||||
[this](const std::vector<PlacedModule>& mods) { loadLayoutBlueprint(mods); },
|
||||
this);
|
||||
mainLayout->addWidget(bpPanel);
|
||||
columnsLayout->addWidget(bpPanel);
|
||||
|
||||
outerLayout->addLayout(columnsLayout, 1);
|
||||
|
||||
// Bottom: confirm / cancel buttons.
|
||||
QHBoxLayout* bottomBar = new QHBoxLayout();
|
||||
QPushButton* confirmBtn = new QPushButton(tr("Confirm"), this);
|
||||
QPushButton* cancelBtn = new QPushButton(tr("Cancel"), this);
|
||||
bottomBar->addWidget(confirmBtn);
|
||||
bottomBar->addWidget(cancelBtn);
|
||||
outerLayout->addLayout(bottomBar);
|
||||
|
||||
connect(confirmBtn, &QPushButton::clicked, this, &ShipLayoutDialog::onConfirm);
|
||||
connect(cancelBtn, &QPushButton::clicked, this, &ShipLayoutDialog::onCancel);
|
||||
|
||||
// Initial stats display.
|
||||
updateStats();
|
||||
|
||||
// Grid click handler.
|
||||
connect(this, &ShipLayoutDialog::gridCellClicked, this, [this](QPoint cell) {
|
||||
@@ -551,6 +565,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
m_placedModules.erase(m_placedModules.begin() + idx);
|
||||
rebuildOccupancy();
|
||||
updateGridWidget();
|
||||
updateStats();
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -567,6 +582,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
m_placedModules.push_back(pm);
|
||||
rebuildOccupancy();
|
||||
updateGridWidget();
|
||||
updateStats();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -690,6 +706,20 @@ void ShipLayoutDialog::updateGridWidget()
|
||||
gridW->update();
|
||||
}
|
||||
|
||||
void ShipLayoutDialog::updateStats()
|
||||
{
|
||||
int level = 1;
|
||||
for (const ShipDef& def : m_config->ships.ships)
|
||||
{
|
||||
if (def.id == m_shipId)
|
||||
{
|
||||
level = def.schematic.playerProductionLevel;
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_statsPanel->refresh(m_shipId, level, m_placedModules);
|
||||
}
|
||||
|
||||
bool ShipLayoutDialog::canPlaceModule(const ModuleDef& def, QPoint position,
|
||||
Rotation rotation) const
|
||||
{
|
||||
@@ -795,4 +825,5 @@ void ShipLayoutDialog::loadLayoutBlueprint(const std::vector<PlacedModule>& modu
|
||||
|
||||
rebuildOccupancy();
|
||||
updateGridWidget();
|
||||
updateStats();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user