Files
dota_factory/src/ui/RecipeSelectionDialog.h
Malte Langkabel f03003194f host the modals in the window instead of in windows of their own
Every dialog was an OS window with a dim widget behind it in the game
window. That is why a click beside one could not reach it: Qt drops mouse
events for a window a modal blocks, so the dim -- a child of the blocked
window -- never saw the press.

ModalLayer is that dim grown up: still a child of the main window covering
its rect, but it now hosts the open modal, places it, and runs its event
loop, so it is the widget the clicks beside a modal land on. It keeps a
stack, paints one dim however many modals are open, and a hold keeps it up
while one modal hands over to the next. ModalDimOverlay and ModalDimScope
are gone; ModalLayerHold replaces the scope at the sites that still open a
system message box.

ModalDialog is what a dialog inherits in place of the window it lost: the
panel background, the drawn header with its optional close button, and the
dismissal gestures. isDismissible() governs Q and, next, the click outside
-- one predicate because both gestures reach the same dialogs. Its default
refuses, so a dialog opts in. requestDismiss() is what a gesture asks for,
and ShipLayoutDialog overrides it with the one-step ladder its Q handler
used to spell out, which is now reached by both. DialogDismiss.h folded into
the base.

The four dialogs the player meets keep their contents unchanged and lose
their title bars: the recipe/schematic selection, blueprint selection, ship
layout, and schematic choice dialogs. Placement moved with them --
placeOnSelectionPanel became getSelectionPanelAnchor, and the layer centers
on that rectangle in window coordinates, with no global mapping and no
frame height to guess at.

Two things followed from dropping OS modality: the focus guard that hands
focus back to the game world now also asks the layer whether a modal is
open, and closeEvent refuses to close the window while one is, since its
nested loop runs over widgets the window owns.

The escape menu, the game-over and win screens, and the two name dialogs are
still system dialogs; they are dimmed by a layer hold until they are
converted next.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ne3mejABZoLWKLh8fgpM3x
2026-08-18 12:07:25 +02:00

65 lines
2.3 KiB
C++

#pragma once
#include <optional>
#include <string>
#include <vector>
#include <QString>
#include "BuildingType.h"
#include "ModalDialog.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 button, Escape, Q, or a click outside) leaves no
// choice (REQ-UI-DIALOG-DISMISS).
class RecipeSelectionDialog : public ModalDialog
{
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;
bool isDismissible() const override;
private:
void onOptionClicked(int index);
std::vector<std::string> m_optionIds;
std::optional<std::string> m_chosenId;
};