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
56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include "GameWorldView.h"
|
|
|
|
// RAII guard for the "pause the game while a modal is open" idiom (REQ-UI-SPEED).
|
|
// Constructing it snapshots the current game speed and pauses the game; on scope
|
|
// exit it restores the snapshotted speed and rebases the render frame timer, so the
|
|
// wall time the player spent in the dialog is not converted into simulation ticks.
|
|
//
|
|
// Pairs with ModalLayer, which the same call sites use to show the modal itself.
|
|
//
|
|
// Two escape hatches for the paths that must not simply restore at scope exit:
|
|
// restore() — restore now instead of at scope exit, for when more work has to run
|
|
// at the player's real speed before the scope ends (e.g. a follow-up
|
|
// dialog that snapshots the speed itself).
|
|
// release() — abandon the restore entirely, for when the game is about to be
|
|
// reset or the window closed and the old speed is meaningless.
|
|
// Both are idempotent and the destructor does nothing once either has run.
|
|
class ModalPauseScope
|
|
{
|
|
public:
|
|
explicit ModalPauseScope(GameWorldView& view)
|
|
: m_view(view)
|
|
, m_previousGameSpeed(view.getGameSpeed())
|
|
, m_restorePending(true)
|
|
{
|
|
m_view.setGameSpeed(0.0);
|
|
}
|
|
|
|
~ModalPauseScope()
|
|
{
|
|
restore();
|
|
}
|
|
|
|
void restore()
|
|
{
|
|
if (!m_restorePending) { return; }
|
|
m_restorePending = false;
|
|
m_view.setGameSpeed(m_previousGameSpeed);
|
|
m_view.resetFrameTimer();
|
|
}
|
|
|
|
void release()
|
|
{
|
|
m_restorePending = false;
|
|
}
|
|
|
|
ModalPauseScope(const ModalPauseScope&) = delete;
|
|
ModalPauseScope& operator=(const ModalPauseScope&) = delete;
|
|
|
|
private:
|
|
GameWorldView& m_view;
|
|
double m_previousGameSpeed;
|
|
bool m_restorePending;
|
|
};
|