Files
dota_factory/src/ui/RecipeSelectionDialog.h

62 lines
2.2 KiB
C++

#pragma once
#include <optional>
#include <string>
#include <vector>
#include <QDialog>
#include <QString>
#include "BuildingType.h"
#include "RecipeLineRow.h"
struct GameConfig;
class BuildingIconCache;
class ItemIconCache;
class Simulation;
class QPushButton;
// One selectable entry in the recipe/schematic selection dialog
// (REQ-UI-SELECT-BUTTON). The "(None)" entry uses an empty id.
struct RecipeSelectionOption
{
std::string id;
QString caption;
// What the option makes, drawn beneath its caption on the button
// (REQ-UI-SELECT-OPTIONS). Empty for the "(None)" option, which is a caption alone.
// A ship schematic fills the inputs and the time and leaves the outputs empty: a
// ship is not an item and has no icon, so the caption is what it produces.
RecipeLineRow::Spec line;
};
// Builds the lock-aware list of selectable options for a production building
// of the given type, with display captions and recipe lines
// (REQ-UI-SELECT-BUTTON, REQ-UI-SELECT-OPTIONS). The first entry is always a
// "(None)" option with an empty id. Shared by the selection dialog and the
// panel selection button so both render identical captions, and
// usable for construction sites which have no Building yet (REQ-BLD-SITE-CONFIG).
std::vector<RecipeSelectionOption> buildRecipeSelectionOptions(
BuildingType type, Simulation& sim, const GameConfig& config);
// Modal dialog listing the options in one vertical column (REQ-UI-SELECT-OPTIONS). The
// game is paused by the caller while it is open. Clicking an option selects it
// and closes the dialog; dismissing it (close/Esc) leaves no choice.
class RecipeSelectionDialog : public QDialog
{
Q_OBJECT
public:
// The icon caches draw each option's recipe line (REQ-UI-ITEM-ICON). Not owned.
RecipeSelectionDialog(const std::vector<RecipeSelectionOption>& options,
const QString& title, ItemIconCache* itemIcons,
BuildingIconCache* buildingIcons, QWidget* parent = nullptr);
std::optional<std::string> getChosenId() const;
private:
void onOptionClicked(int index);
std::vector<std::string> m_optionIds;
std::optional<std::string> m_chosenId;
};