MenuList
Extends: BGE.UI.UiContainer
A panel holding an optional title, an optional wrapped message and a column of buttons, one per item. Picking an item calls listener.onUiAction(item.id, button).
The panel's children are built by open() and removed by close(), so its buttons are only focusable while it's open. open() focuses the first enabled item.
Colors come from the theme (panelBackgroundColor/panelBackgroundImage, panelTitleColor, panelTextColor, and the usual button colors); fonts from the "heading" and "body" fonts, falling back to "default". Set width/height to fix the size, or leave them 0 to fit the content. Override createButton() to use your own button class, or buildChildren() for a different layout.
Properties
title(string) — Heading drawn above the message. "" = none.message(string) — Body text, wrapped to the panel's inner width. "" = none. Use setMessage() once open.listener(BGE.UI.UiActionListener) — Told about picks - see BGE.UI.UiActionListener. Set before open().panelPadding(float) — Space between the panel's edge and its content.sectionGap(float) — Space below the title and below the message.itemHeight(float)itemGap(float)itemWidth(float) — Button width. 0 = the panel's inner width.contentAlign(string) — Horizontal alignment of the title, message and buttons: "left" or "center".minWidth(float) — Fitted width never goes below this or above maxWidth (0 = 60% of the UI canvas width).maxWidth(float)contentHeight(float) — Extra space below the message for content a subclass draws itself; contentTop is its y.centered(boolean) — Center on the parent (or the UI canvas when the parent is gameUi) when opened, insteaditems(Array.<BGE.UI.MenuItem>) — The items added with addItem(), in order.buttons(Array.<BGE.UI.Button>) — One button per item, in the same order. Only filled while open.contentTop(float)titleLabel(BGE.UI.Label)messageLabel(BGE.UI.Label)fixedWidth(float)fixedHeight(float)ownerScene(BGE.GameScene)
Example
menu = new BGE.UI.MenuList(game)
menu.title = "Adventure"
menu.listener = m ' a scene with onUiAction(actionId, button)
menu.addItem("continue", "Continue", hasSave)
menu.addItem("new", "New Game")
menu.centered = true
menu.open() ' owned by the current scene, closed when it changesConstructor
new MenuList(game: BGE.Game): MenuListParameters
game(BGE.Game)
Instance Methods
addItem(
id: string,
label: string,
enabled?: boolean,
value?: dynamic,
): BGE.UI.MenuItem
Adds an item to the end of the list. Takes effect the next time the menu opens.
Parameters
id(string) — passed to the listener asactionIdlabel(string)enabled(boolean, optional, default: true)value(dynamic, optional, default: "invalid") — copied to the button'svalue
Returns
BGE.UI.MenuItem— the new item, e.g. to setonActivate
clearItems(): void
Removes every item. Takes effect the next time the menu opens.
Returns
void
setItemEnabled(id: string, enabled: boolean): void
Enables or disables an item, including its button if the menu is open.
Parameters
id(string)enabled(boolean)
Returns
void
getButton(id: string): BGE.UI.Button
The button for an item while the menu is open, else invalid.
Parameters
id(string)
Returns
BGE.UI.Button
setTitle(text: string): void
Sets the title. Takes effect the next time the menu opens.
Parameters
text(string)
Returns
void
setMessage(text: string): void
Sets the message. On an open menu the text is replaced in place (e.g. "Not enough coins"); the panel isn't resized, so keep it to the lines it had.
Parameters
text(string)
Returns
void
open(parent?: BGE.UI.UiContainer): void
Builds the panel, adds it to parent and focuses the first enabled item. With no parent, it's added with the current scene's addUi(), so it closes when the scene changes (or to gameUi if there's no scene yet). Opening an open menu rebuilds it.
Parameters
parent(BGE.UI.UiContainer, optional, default: "invalid")
Returns
void
setSize(width: float, height: float): void
Fixes the panel's size; 0 for either fits that side to the content. Takes effect the next time the menu opens.
Parameters
width(float)height(float)
Returns
void
close(): void
Removes the panel and its buttons from wherever open() put it.
Returns
void
onDestroy(): void
Returns
void
isOpen(): boolean
Is the menu open?
Returns
boolean
focusFirstEnabled(): boolean
Focuses the first enabled item's button.
Returns
boolean— false if there's none
focusItem(id: string): boolean
Focuses an item's button.
Parameters
id(string)
Returns
boolean— false if the menu isn't open or the item is missing or disabled
centerIn(container: BGE.UI.UiContainer): void
Moves the panel so it's centered within container (the UI canvas for gameUi).
Parameters
container(BGE.UI.UiContainer)
Returns
void
draw(parent?: UiWidget): void
Parameters
parent(UiWidget, optional, default: "invalid")
Returns
void
createButton(item: BGE.UI.MenuItem): BGE.UI.Button
Parameters
item(BGE.UI.MenuItem)
Returns
BGE.UI.Button
buildChildren(): void
Returns
void
fitWidth(
titleFont: roFont,
bodyFont: roFont,
theme: BGE.UI.Theme,
buttons: Array.<BGE.UI.Button>,
): float
Parameters
titleFont(roFont)bodyFont(roFont)theme(BGE.UI.Theme)buttons(Array.<BGE.UI.Button>)
Returns
float
headingFont(): roFont
Returns
roFont
bodyFont(): roFont
Returns
roFont