Files
dota_factory/src/ui/ModalDialog.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

49 lines
2.1 KiB
C++

#pragma once
#include <QDialog>
class QBoxLayout;
class QHBoxLayout;
class QKeyEvent;
class QString;
// Base of every modal the player meets while playing (REQ-UI-MODAL-CHROME). A modal is
// not an operating system window here: it is an ordinary child widget, hosted and placed
// by the ModalLayer that also paints the dim it sits on, so it has no title bar, no
// window border, and no window-manager close. What a window used to supply, this class
// supplies instead -- the panel background, the drawn header, and the dismissal gestures.
//
// It stays a QDialog for accept()/reject()/result() and the Escape handling built into
// them; only the window-ness is dropped (Qt::Widget flags). Nothing calls exec() on it:
// ModalLayer::execute() runs the modal loop, so that the layer knows what is open.
class ModalDialog : public QDialog
{
Q_OBJECT
public:
explicit ModalDialog(QWidget* parent = nullptr);
// Whether Q and a click outside this dialog dismiss it (REQ-UI-DIALOG-DISMISS). One
// predicate for both gestures because they reach exactly the same dialogs. The
// default refuses both, so a dialog takes the gestures only by saying so: the two
// name dialogs must let Q through as a character, and the schematic choice dialog
// has no way out but choosing (REQ-DEF-SCHEMATIC-DROP).
virtual bool isDismissible() const;
public slots:
// What a dismissal does, whichever gesture asked for it. Cancelling is the default;
// a dialog with modes of its own overrides this to back out of them one at a time
// (ShipLayoutDialog, REQ-UI-DIALOG-DISMISS).
virtual void requestDismiss();
protected:
// Adds the drawn header row -- the title, and a close button at the far right when
// asked for -- as the first row of mainLayout, and returns it so a subclass can
// insert its own widgets after the title (REQ-UI-MODAL-CHROME). The close button
// rejects the dialog, which is what the window-manager close used to do.
QHBoxLayout* addHeader(QBoxLayout* mainLayout, const QString& title,
bool withCloseButton);
void keyPressEvent(QKeyEvent* event) override;
};