Перейти к содержимому
Gothic MultiplayerMultiplayer
Gothic MP Wiki

MenuPage

A tab of a menu window: adding headers, texts, toggles, sliders, lists and buttons.

since 0.1.30-alpha

Tabs are created with menu:addPage. In the examples page is any MenuPage.

Every add... method returns the new control - keep it in a variable to react to the player (control:onChange, see each method's example) or to read and change it later (getValue, setValue).

Methods

addHeader

since 0.1.30-alpha
page:addHeader(text)

Adds a section header - a title separating groups of controls, like the headers in the game's Settings.

ParameterTypeDescription
textstringText of the header.

Returns: MenuControl | nil - The header, or nil when the tab was removed.

addText

since 0.1.30-alpha
page:addText(text)

Adds a paragraph of text (wrapped to the width of the tab; \n starts a new line) - rules, information, help. The text can be changed later with setText.

ParameterTypeDescription
textstringThe text (UTF-8).

Returns: MenuControl | nil - The text, or nil when the tab was removed.

addToggle

since 0.1.30-alpha
page:addToggle(text, value, options?)

Adds an on/off switch. getValue returns a boolean; onChange gets the new value when the player switches it.

local toggle = page:addToggle("Lorem ipsum", true, { save = "loremToggle" })
toggle:onChange(function(on)
  if on then
    addChatMessage("Lorem ipsum: on")
  else
    addChatMessage("Lorem ipsum: off")
  end
end)
ParameterTypeDescription
textstringName shown in the row.
valuebooleanInitial value (and the value restored by the window's RESET button).
options (optional)MenuControlOptionsDescription, remembered value (save), enabled state.

Returns: MenuControl | nil - The switch, or nil when the tab was removed.

addSlider

since 0.1.30-alpha
page:addSlider(text, value, min, max, options?)

Adds a slider for a number between min and max. getValue returns a number; onChange gets the new number at every step the player moves it.

local slider = page:addSlider("Dolor sit amet", 50, 0, 100, { step = 5 })
slider:onChange(function(value)
  triggerServerEvent("loremSlider", value)   -- the server gets it with addEventHandler("loremSlider", function(pid, value) ... end)
end)
ParameterTypeDescription
textstringName shown in the row.
valuenumberInitial value (clamped to min-max; also the value restored by RESET).
minnumberLowest value.
maxnumberHighest value (greater than min).
options (optional)MenuControlOptionsstep sets the step of the slider.

Returns: MenuControl | nil - The slider, or nil when the tab was removed.

addList

since 0.1.30-alpha
page:addList(text, items, selected?, options?)

Adds a choice from a list of options, shown with arrows (or as a drop-down with dropdown = true). getValue returns the index of the selected item (1 = the first one); onChange gets the new index.

local items = { "Lorem", "Ipsum", "Dolor" }
local list = page:addList("Consectetur", items, 1)
list:onChange(function(index)
  addChatMessage("Consectetur: " .. items[index])   -- index -> the item's name
end)
ParameterTypeDescription
textstringName shown in the row.
itemsstring[]Names of the options (1-64).
selected (optional)integerIndex of the initially selected option. Default 1.
options (optional)MenuControlOptionsDescription, remembered value (save), enabled state, drop-down.

Returns: MenuControl | nil - The list, or nil when the tab was removed.

addButton

since 0.1.30-alpha
page:addButton(text, action, options?)

Adds a button. Clicking it calls the function, or opens the given window - a submenu.

page:addButton("Lorem ipsum", submenu)   -- opens another window
page:addButton("Dolor sit amet", function()
  triggerServerEvent("loremIpsum")       -- runs on every click
  closeMenu()                            -- and back to the game
end)
ParameterTypeDescription
textstringText of the button.
actionfun() | MenuFunction called on click (no arguments), or a window to open.
options (optional)MenuControlOptionsOnly enabled applies.

Returns: MenuControl | nil - The button, or nil when the tab was removed.

setTitle

since 0.1.30-alpha
page:setTitle(title)

Changes the name of the tab. It is shown the next time the window opens.

ParameterTypeDescription
titlestringNew name.

Returns: boolean - false when the tab was removed.

remove

since 0.1.30-alpha
page:remove()

Removes the tab with all its controls. A tab of an open window disappears the next time it opens.

Returns: boolean - false when it was already removed.

getMenu

since 0.1.30-alpha
page:getMenu()

Returns the window the tab belongs to.

Returns: Menu | nil - nil when the tab was removed.

isValid

since 0.1.30-alpha
page:isValid()

Tells whether the tab still exists.

Returns: boolean

Types

since 0.1.30-alpha

Options of the add... methods. All fields are optional.

FieldTypeDescription
description?stringText in the description panel on the right while the control is selected (hovered with the mouse, focused with the keyboard or a gamepad).
save?stringKey under which the value is remembered on this computer, separately for every server (1-64 characters, no = or line breaks). The next time the control is created with the same key it starts with the remembered value instead of the given one. Toggles, sliders and lists only.
step?numberSlider step (greater than 0). Default 1.
enabled?booleanfalse = the control starts greyed out (see MenuControl:setEnabled). Default true.
dropdown?booleanList only: true = a drop-down list instead of arrows. Default false.