MessagePanel
Extends: BGE.UI.UiContainer
A centered modal panel (translucent background, optional heading, optional body message, a vertical stack of buttons) for pause menus, win/game-over screens, and similar - promoted from the same shape hand-rolled independently by several BGE.UI-based examples, including the same focus-safety fix each needed by hand: a Button registers itself with the global FocusManager the instant it's added to any focusEnabled container, even one not yet attached to gameUi - so a panel must be built fresh right before it's shown and torn down (not just hidden) when closed, or its buttons stay focusable/clickable while invisible. show()/hide() handle this internally: hide() removes the panel (and its buttons) from its parent entirely, and show() rebuilds its children fresh each time.
Font-name assumption: the title is measured AND drawn with the same resolved "heading"-or-"default" font (self-consistent), but the message label is measured with "body"-or-"default" while actually DRAWN with whatever font its resolved theme yields (via the normal Label/resolveTheme() path). If a consumer's container theme sets a different font than what they registered as "body", the message text could measure slightly off from how it's centered.
Properties
title(string) — Panel heading, shown in a larger font above the message/buttons. Empty ("") means ' no heading is drawn.message(string) — Body message, shown below the heading. Empty ("") means no message is drawn. Call ' setMessage() (not this field directly) to update it after the panel is already ' shown - it re-measures/re-centers the label.buttons(dynamic) — Buttons, top to bottom, in the order given to the constructor.buttonWidgets(dynamic) — The actual BGE.UI.Button widgets built frombuttons, in the same order - only ' valid after show() has built the panel's children.
Constructor
new MessagePanel(
game: BGE.Game,
panelWidth: float,
panelHeight: float,
buttons: Array.<BGE.UI.MessagePanelButton>,
title?: string,
message?: string,
): MessagePanelParameters
game(BGE.Game)panelWidth(float)panelHeight(float)buttons(Array.<BGE.UI.MessagePanelButton>) — shown top to bottomtitle(string, optional, default: "\"\"") — optional heading, drawn in a larger fontmessage(string, optional, default: "\"\"") — optional body text below the heading
Instance Methods
show(
parent: BGE.UI.UiContainer,
withinWidth: float,
withinHeight: float,
): void
Centers this panel within a withinWidth x withinHeight area (typically the ui canvas size), builds its children fresh, and adds it to parent. Call hide() first if this panel is already shown - calling show() again without hiding first stacks a second copy of every child on top of the first.
Parameters
parent(BGE.UI.UiContainer)withinWidth(float)withinHeight(float)
Returns
void
hide(parent: BGE.UI.UiContainer): void
Removes this panel (and its buttons) from parent entirely - not just a visibility toggle - so its buttons unregister from the shared FocusManager instead of staying focusable/clickable while hidden. Call show() again to reopen; it rebuilds fresh children each time.
Parameters
parent(BGE.UI.UiContainer)
Returns
void
setMessage(message: string): void
Updates the body message after the panel has already been shown (e.g. a running score baked into the text) and re-centers it, since its width varies with the text.
Parameters
message(string)
Returns
void