Przejdź do treści
Gothic MultiplayerMultiplayer
Gothic MP Wiki

Menu

Windows in the style of the game's Settings screen: tabs with toggles, sliders, lists, buttons and texts; extra tabs in the game's Settings.

since 0.1.30-alpha

A Menu is a window in the game's own style - tabs (MenuPage) holding controls (MenuControl). Windows are created with createMenu and opened from the ESC menu (addMenuButton), from a button of another window or from code; getSettingsMenu returns the game's own Settings window. In the examples menu is any Menu.

Your code runs when the player does something in the window:

  • a toggle, slider or list - the function given to control:onChange gets the new value;
  • a button - the function given as its action is called (or the given window opens);
  • the current value can be read at any time with control:getValue().
local menu = createMenu("Lorem ipsum")
local page = menu:addPage("Dolor sit")
page:addHeader("Amet")

local toggle = page:addToggle("Consectetur", true)
toggle:onChange(function(on)              -- on = true / false
  addChatMessage("Consectetur: " .. tostring(on))
end)

local slider = page:addSlider("Adipiscing", 50, 0, 100, { step = 5 })
slider:onChange(function(value)           -- value = number
  triggerServerEvent("loremSlider", value)   -- tell the server
end)

local list = page:addList("Elit", { "Lorem", "Ipsum", "Dolor" }, 1)
list:onChange(function(index)             -- index = 1, 2 or 3
  addChatMessage("Elit: item " .. index)
end)

page:addButton("Sed do eiusmod", function()   -- a button calls its function
  addChatMessage("toggle " .. tostring(toggle:getValue()) .. ", slider " .. slider:getValue() .. ", list " .. list:getValue())
end)

addMenuButton("Lorem ipsum", menu)   -- the ESC menu gets a LOREM IPSUM button that opens the window

Methods

addPage

since 0.1.30-alpha
menu:addPage(title)

Adds a tab to the window. Tabs appear in the order they were added. When the window opens no tab is selected yet - the player clicks one, as in the game's Settings. A tab added while the window is open appears the next time it opens.

ParameterTypeDescription
titlestringName of the tab.

Returns: MenuPage | nil - The new tab, or nil when the window was removed.

open

since 0.1.30-alpha
menu:open()

Opens the window. It opens over the ESC menu like the game's Settings (the ESC menu opens first when it is closed; the game stays paused). Opened while another window is shown (e.g. from its button), it replaces that window - a submenu: BACK or Esc returns to the window under it. BACK of the first window returns to the ESC menu. Not available for the game's Settings window (getSettingsMenu()).

Returns: boolean - true when the window is open (also when it already was); false when the window was removed, is the game's Settings window, or the game's HUD does not exist yet.

close

since 0.1.30-alpha
menu:close()

Closes the window like its BACK button: a submenu returns to the window under it, the first window to the ESC menu. Not available for the game's Settings window.

Returns: boolean - false when the window is not the one shown now.

isOpen

since 0.1.30-alpha
menu:isOpen()

Tells whether the window is open and active.

Returns: boolean

setTitle

since 0.1.30-alpha
menu:setTitle(title)

Changes the title at the top of the window; an open window shows it at once. Not available for the game's Settings window.

ParameterTypeDescription
titlestringNew title.

Returns: boolean - false when the window was removed or is the game's Settings window.

remove

since 0.1.30-alpha
menu:remove()

Removes the window with all its tabs and controls; an open window is closed first. ESC menu buttons and page buttons that opened it do nothing from now on. The game's Settings window cannot be removed.

Returns: boolean - false when it was already removed or is the game's Settings window.

onOpen

since 0.1.30-alpha
menu:onOpen(handler)

Sets the function called when the window opens. For the game's Settings window: when the player opens Settings. One function per window - a new call replaces the previous one; nil removes it.

ParameterTypeDescription
handlerfun() | nilFunction without arguments.

Returns: boolean - false when the window was removed.

onClose

since 0.1.30-alpha
menu:onClose(handler)

Sets the function called when the window closes. One function per window - a new call replaces the previous one; nil removes it.

ParameterTypeDescription
handlerfun() | nilFunction without arguments.

Returns: boolean - false when the window was removed.

isValid

since 0.1.30-alpha
menu:isValid()

Tells whether the window still exists (was not removed with remove).

Returns: boolean