Files
dota_factory/src/ui/MessageDialog.cpp
Malte Langkabel 9b88deff69 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
2026-08-18 12:14:31 +02:00

76 lines
2.0 KiB
C++

#include "MessageDialog.h"
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
namespace
{
const int kSpacingPx = 8;
}
MessageDialog::MessageDialog(const QString& title, const QString& text, QWidget* parent)
: ModalDialog(parent)
, m_buttonLayout(nullptr)
, m_buttonCount(0)
{
QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->setContentsMargins(kSpacingPx, kSpacingPx, kSpacingPx, kSpacingPx);
mainLayout->setSpacing(kSpacingPx);
if (!text.isEmpty())
{
QLabel* textLabel = new QLabel(text, this);
mainLayout->addWidget(textLabel);
}
// The buttons sit at the right of their row, the side a dialog is confirmed from.
m_buttonLayout = new QHBoxLayout();
m_buttonLayout->setSpacing(kSpacingPx);
m_buttonLayout->addStretch();
mainLayout->addLayout(m_buttonLayout);
// Last, so it becomes the first row (REQ-UI-MODAL-CHROME). No close button: closing
// is one of the buttons here, or nothing at all.
addHeader(mainLayout, title, false);
}
int MessageDialog::addButton(const QString& caption)
{
const int index = m_buttonCount++;
QPushButton* button = new QPushButton(caption, this);
m_buttonLayout->addWidget(button);
connect(button, &QPushButton::clicked, this, [this, index]() {
onButtonClicked(index);
});
return index;
}
void MessageDialog::setEscapeButtonIndex(int index)
{
m_escapeButtonIndex = index;
}
std::optional<int> MessageDialog::getClickedButtonIndex() const
{
return m_clickedButtonIndex;
}
void MessageDialog::reject()
{
// Escape stands for a button rather than for a dismissal of its own, so the caller
// reads one answer whichever way the player gave it (REQ-UI-GAME-MENU).
if (!m_escapeButtonIndex.has_value())
{
return;
}
onButtonClicked(*m_escapeButtonIndex);
}
void MessageDialog::onButtonClicked(int index)
{
m_clickedButtonIndex = index;
accept();
}