Replace recipe/schematic dropdowns with button and selection dialog

This commit is contained in:
2026-06-22 12:17:42 +02:00
parent c43225b6fa
commit c7218c7c1e
10 changed files with 318 additions and 50 deletions

View File

@@ -6,7 +6,6 @@
#include <set>
#include <string>
#include <QComboBox>
#include <QLabel>
#include <QListWidget>
#include <QPushButton>
@@ -32,6 +31,8 @@
#include "ItemType.h"
#include "LayoutDialogRequestedEvent.h"
#include "ModulesConfig.h"
#include "RecipeSelectionDialog.h"
#include "RecipeSelectionRequestedEvent.h"
#include "Rotation.h"
#include "ShipLayoutPreview.h"
#include "Simulation.h"
@@ -110,7 +111,7 @@ SelectedBuildingPanel::SelectedBuildingPanel(Simulation* sim,
m_layout->setAlignment(Qt::AlignTop);
m_titleLabel = new QLabel(this);
m_recipeCombo = new QComboBox(this);
m_recipeSelectButton = new QPushButton(this);
m_clearBeltBtn = new QPushButton(tr("Clear Items"), this);
m_filterALabel = new QLabel(this);
m_filterAList = new QListWidget(this);
@@ -125,7 +126,7 @@ SelectedBuildingPanel::SelectedBuildingPanel(Simulation* sim,
m_filterBList->setMaximumHeight(100);
m_layout->addWidget(m_titleLabel);
m_layout->addWidget(m_recipeCombo);
m_layout->addWidget(m_recipeSelectButton);
m_layout->addWidget(m_layoutPreview);
m_layout->addWidget(m_configureLayoutBtn);
m_layout->addWidget(m_clearBeltBtn);
@@ -135,8 +136,8 @@ SelectedBuildingPanel::SelectedBuildingPanel(Simulation* sim,
m_layout->addWidget(m_filterBList);
m_layout->addWidget(m_buffersLabel);
connect(m_recipeCombo, qOverload<int>(&QComboBox::currentIndexChanged),
this, &SelectedBuildingPanel::onRecipeChanged);
connect(m_recipeSelectButton, &QPushButton::clicked,
this, &SelectedBuildingPanel::onSelectRecipeClicked);
connect(m_clearBeltBtn, &QPushButton::clicked,
this, &SelectedBuildingPanel::onClearBelt);
connect(m_configureLayoutBtn, &QPushButton::clicked, this, [this]() {
@@ -206,7 +207,7 @@ void SelectedBuildingPanel::rebuild()
void SelectedBuildingPanel::hideAllWidgets()
{
m_titleLabel->hide();
m_recipeCombo->hide();
m_recipeSelectButton->hide();
m_layoutPreview->hide();
m_configureLayoutBtn->hide();
m_clearBeltBtn->hide();
@@ -285,43 +286,33 @@ void SelectedBuildingPanel::buildSingle(BuildingId id)
if (isProductionBuilding(b->type))
{
m_recipeCombo->blockSignals(true);
m_recipeCombo->clear();
const std::vector<RecipeSelectionOption> options =
buildRecipeSelectionOptions(*b, *m_sim, *m_config);
m_recipeCombo->addItem(tr("(none)"), QString());
if (b->type == BuildingType::Shipyard)
const RecipeSelectionOption* current = nullptr;
for (const RecipeSelectionOption& option : options)
{
for (const ShipDef& def : m_config->ships.ships)
if (option.id == b->recipeId)
{
if (m_sim->isSchematicUnlocked(def.id))
{
m_recipeCombo->addItem(
QString::fromStdString(def.id),
QString::fromStdString(def.id));
}
current = &option;
break;
}
}
if (current && !current->id.empty())
{
m_recipeSelectButton->setText(current->caption);
m_recipeSelectButton->setToolTip(current->tooltip);
}
else
{
for (const RecipeDef& recipe : m_config->recipes.recipes)
{
if (recipe.building != b->type) { continue; }
if ((b->type == BuildingType::Miner || b->type == BuildingType::Assembler)
&& !m_sim->isRecipeUnlocked(recipe.id))
{
continue;
}
m_recipeCombo->addItem(
QString::fromStdString(recipe.id),
QString::fromStdString(recipe.id));
}
const QString placeholder = (b->type == BuildingType::Shipyard)
? tr("Select schematic")
: tr("Select recipe");
m_recipeSelectButton->setText(placeholder);
m_recipeSelectButton->setToolTip(QString());
}
const int currentIdx = m_recipeCombo->findData(QString::fromStdString(b->recipeId));
m_recipeCombo->setCurrentIndex(currentIdx >= 0 ? currentIdx : 0);
m_recipeCombo->blockSignals(false);
m_recipeCombo->show();
m_recipeSelectButton->show();
if (b->type == BuildingType::Shipyard && !b->recipeId.empty())
{
@@ -352,7 +343,7 @@ void SelectedBuildingPanel::buildSingle(BuildingId id)
}
else
{
m_recipeCombo->hide();
m_recipeSelectButton->hide();
m_layoutPreview->hide();
m_configureLayoutBtn->hide();
}
@@ -582,7 +573,7 @@ void SelectedBuildingPanel::handleEvent(std::shared_ptr<const TickAdvancedEvent>
void SelectedBuildingPanel::buildMulti(const std::vector<BuildingId>& ids)
{
m_singleBuildingId = kInvalidBuildingId;
m_recipeCombo->hide();
m_recipeSelectButton->hide();
m_clearBeltBtn->hide();
m_filterALabel->hide();
m_filterAList->hide();
@@ -626,14 +617,18 @@ void SelectedBuildingPanel::buildMulti(const std::vector<BuildingId>& ids)
}
}
void SelectedBuildingPanel::onRecipeChanged(int comboIndex)
void SelectedBuildingPanel::onSelectRecipeClicked()
{
if (m_singleBuildingId == kInvalidBuildingId)
{
return;
}
const QString recipeId = m_recipeCombo->itemData(comboIndex).toString();
m_sim->buildings().setRecipe(m_singleBuildingId, recipeId.toStdString());
// The emit is synchronous: MainWindow pauses the game, runs the modal
// selection dialog, applies the chosen recipe/schematic, and restores the
// speed before this returns. rebuild() then refreshes the button caption,
// tooltip, preview, and buffers for the new selection.
EventManager::getInstance()->sendEventImmediately(
std::make_shared<RecipeSelectionRequestedEvent>(m_singleBuildingId));
rebuild();
}