#include "RecipeSelectionControl.h" #include #include #include #include "EventManager.h" #include "RecipeSelectionDialog.h" #include "RecipeSelectionRequestedEvent.h" #include "Simulation.h" RecipeSelectionControl::RecipeSelectionControl(const SelectionContext& context, BuildingId id, BuildingType type, QWidget* parent) : QWidget(parent) , m_context(context) , m_id(id) , m_type(type) { QVBoxLayout* layout = new QVBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); m_button = new QPushButton(this); layout->addWidget(m_button); connect(m_button, &QPushButton::clicked, this, [this]() { // Sent synchronously: MainWindow pauses the game, runs the modal dialog, and // restores the speed before this returns. The chosen recipe is only enqueued as // a command though, and drains on a later frame -- so the caption follows from // the next refresh, not from here. EventManager::getInstance()->sendEventImmediately( std::make_shared(m_id)); }); } void RecipeSelectionControl::setRecipeId(const std::string& recipeId) { const std::vector options = buildRecipeSelectionOptions(m_type, *m_context.sim, *m_context.config); for (const RecipeSelectionOption& option : options) { if (option.id == recipeId && !option.id.empty()) { m_button->setText(option.caption); m_button->setToolTip(option.tooltip); return; } } m_button->setText(m_type == BuildingType::Shipyard ? tr("Select schematic") : tr("Select recipe")); m_button->setToolTip(QString()); }