give the escape menu and the name prompts the game's own frame
The last dialogs wearing system chrome were the three QMessageBoxes -- the escape menu, the game-over and win screens -- and the two QInputDialogs that name a blueprint. They are the ones the player meets at the sharpest moments of a run, and they looked like alerts from the operating system. MessageDialog and NameInputDialog replace them on the layer. The message dialog names its buttons by the index addButton hands back and reports which was clicked, with Escape standing for a button the caller nominates rather than for a dismissal of its own -- Continue in the escape menu, as it was explicitly set to before, and Quit on the two state screens, which is where the reject role sent it. Neither dialog takes Q or a click outside: every button is a decision, and a half-typed name is work in progress (REQ-UI-DIALOG-DISMISS). Two things the layer needed for the nested case: it now tracks the scroll area each modal is shown in, so a modal opened with no anchor centers on the one it was opened from rather than on the window -- which is where the Create Blueprint prompt belongs (REQ-UI-PANEL-MODAL) -- and findFor() walks a widget's parents to the layer, so the blueprint panel buried in the layout dialog can open a modal without every widget in between carrying a pointer. The three error boxes stay system dialogs on purpose: config load, config reload, and blueprint file load all report a failure that may leave nothing to draw on (REQ-UI-MODAL-CHROME). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ne3mejABZoLWKLh8fgpM3x
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "ModalLayer.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
|
||||
#include <QEventLoop>
|
||||
#include <QFrame>
|
||||
@@ -12,6 +12,20 @@
|
||||
|
||||
#include "ModalDialog.h"
|
||||
|
||||
ModalLayer* ModalLayer::findFor(const QWidget& widget)
|
||||
{
|
||||
for (QWidget* candidate = widget.parentWidget(); candidate != nullptr;
|
||||
candidate = candidate->parentWidget())
|
||||
{
|
||||
ModalLayer* layer = qobject_cast<ModalLayer*>(candidate);
|
||||
if (layer != nullptr)
|
||||
{
|
||||
return layer;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ModalLayer::ModalLayer(const QColor& dimColor, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
, m_dimColor(dimColor)
|
||||
@@ -30,13 +44,31 @@ int ModalLayer::execute(ModalDialog& content, const QRect& anchorRect)
|
||||
host->setWidgetResizable(false);
|
||||
host->setWidget(&content);
|
||||
|
||||
m_stack.push_back(&content);
|
||||
// Resolved before the new modal joins the stack, so a null rect means the modal it
|
||||
// was opened from -- the Create Blueprint dialog opens on the layout dialog beneath
|
||||
// it (REQ-UI-PANEL-MODAL).
|
||||
const QRect anchor = !anchorRect.isNull() ? anchorRect
|
||||
: (m_stack.empty() ? rect()
|
||||
: m_stack.back().host->geometry());
|
||||
|
||||
m_stack.push_back(HostedModal{ &content, host });
|
||||
updateVisibility();
|
||||
raise();
|
||||
place(*host, content, anchorRect);
|
||||
place(*host, content, anchor);
|
||||
host->show();
|
||||
content.show();
|
||||
content.setFocus();
|
||||
|
||||
// The modal's own focus widget where it has one -- a name dialog puts the caret in
|
||||
// its line edit -- and the modal itself otherwise, so keys reach it and not the game
|
||||
// world behind (REQ-UI-MODAL-CHROME).
|
||||
if (content.focusWidget() != nullptr)
|
||||
{
|
||||
content.focusWidget()->setFocus();
|
||||
}
|
||||
else
|
||||
{
|
||||
content.setFocus();
|
||||
}
|
||||
|
||||
// The dialog's own loop, run here rather than by QDialog::exec(), so the layer knows
|
||||
// what is open and can place it, dim behind it, and take the clicks beside it.
|
||||
@@ -52,7 +84,14 @@ int ModalLayer::execute(ModalDialog& content, const QRect& anchorRect)
|
||||
content.hide();
|
||||
delete host;
|
||||
|
||||
m_stack.erase(std::remove(m_stack.begin(), m_stack.end(), &content), m_stack.end());
|
||||
for (std::size_t i = m_stack.size(); i > 0; --i)
|
||||
{
|
||||
if (m_stack[i - 1].content == &content)
|
||||
{
|
||||
m_stack.erase(m_stack.begin() + static_cast<std::ptrdiff_t>(i - 1));
|
||||
break;
|
||||
}
|
||||
}
|
||||
updateVisibility();
|
||||
return content.result();
|
||||
}
|
||||
@@ -104,9 +143,8 @@ void ModalLayer::place(QScrollArea& host, ModalDialog& content,
|
||||
const QSize hostSize = content.size().boundedTo(size());
|
||||
host.resize(hostSize);
|
||||
|
||||
const QRect anchor = anchorRect.isNull() ? rect() : anchorRect;
|
||||
QPoint topLeft(anchor.center().x() - hostSize.width() / 2,
|
||||
anchor.center().y() - hostSize.height() / 2);
|
||||
QPoint topLeft(anchorRect.center().x() - hostSize.width() / 2,
|
||||
anchorRect.center().y() - hostSize.height() / 2);
|
||||
|
||||
// Pushed back inside the layer, which is the game window (REQ-UI-PANEL-MODAL). The
|
||||
// far edge is clamped first and the near edge second, which is what aligns a modal
|
||||
|
||||
Reference in New Issue
Block a user