openOMSI GitHub Discord
Plugin API reference

Docs / Plugins / Plugin API reference

Screen and panels

4 min readEdit this pagedocs/PLUGIN_API.md

On this page
  1. omsi.message
  2. omsi.ui.clear
  3. omsi.ui.dock
  4. omsi.ui.focus
  5. omsi.ui.focused
  6. omsi.ui.moved
  7. omsi.ui.panels
  8. omsi.ui.remove
  9. omsi.ui.remove_menu_item
  10. omsi.ui.screen
  11. omsi.ui.set
  12. omsi.ui.set_menu_item
  13. omsi.ui.set_theme
  14. omsi.ui.show
  15. omsi.ui.theme
  16. omsi.ui.themes
  17. omsi.ui.toast
  18. omsi.ui.toggle
  19. omsi.ui.typing
  20. omsi.ui.update
  21. omsi.ui.value

omsi.ui.* puts panels, notifications and pause-menu lines of the plugin on the screen. The panel table and every element type are described in Panels. omsi.ui.version (currently 8) tells which panel features the game has.

omsi.message#

omsi.message(text, [seconds]) → nil

A line of text on the screen (5 seconds when not given).

Parameters: text string; seconds number, optional.

Since 0.1.5. Permission: ui.

Lua
omsi.message("Good morning!", 6)

omsi.ui.clear#

omsi.ui.clear() → nil

Removes every panel of the plugin.

Since 0.2.21. Permission: ui.

omsi.ui.dock#

omsi.ui.dock() → width, room, height, mine, frame

The navigator's board, where a panel with anchor = "navigator" goes, in that panel's pixels: its width, the most height there is room for, the height the panel there came to (0 before it is laid out; more than room: it is cut off at the bottom), whether that panel is this plugin's (the first one asked for has the board, another waits), and whether it fills the navigator's whole frame (frame = true, ui version 6; false under the map, and nothing in an older game).

Nothing while the navigator shows no board: it is off, or Shift+N put its lower part away.

Since 0.3.36.

Lua
local width, room, height, mine, frame = omsi.ui.dock()

omsi.ui.focus#

omsi.ui.focus(on) → boolean

true: the panels get the mouse (the cursor shows, a click goes to the panel under it and none to the bus); false, Esc or a menu of the game gives it back. Returns the new state.

Parameters: on bool.

Since 0.2.21. Permission: ui.

Lua
omsi.input.hotkey("F10", function() omsi.ui.focus(not omsi.ui.focused()) end)

omsi.ui.focused#

omsi.ui.focused() → boolean

Whether the panels have the mouse.

Since 0.2.21.

omsi.ui.moved#

omsi.ui.moved(panel) → dx, dy

How far the player dragged a panel from where its table puts it (pixels).

Parameters: panel string.

Since 0.2.22.

omsi.ui.panels#

omsi.ui.panels() → list of strings

The ids of the plugin's panels.

Since 0.2.22.

omsi.ui.remove#

omsi.ui.remove(id) → boolean

Removes a panel; true when there was one.

Parameters: id string.

Since 0.2.21. Permission: ui.

omsi.ui.remove_menu_item#

omsi.ui.remove_menu_item(id) → boolean

Takes the plugin's line id out of the pause menu; true when there was one.

Parameters: id string.

Since 0.3.36. Permission: ui.

omsi.ui.screen#

omsi.ui.screen() → width, height, scale

The screen in the panels' pixels, and how many of the screen's own pixels one of them is.

Since 0.2.21.

omsi.ui.set#

omsi.ui.set(id, panel) → true, or false and the reason

Creates the panel id or replaces it; a table that is not right gives false and where ("children[2].size: a number is expected"). The same table again changes nothing.

Parameters: id string; panel table.

Since 0.2.21. Permission: ui.

The panel table, its keys and all element types are in Panels.

Lua
omsi.ui.set("speed", {
  anchor = "top_left", x = 16, y = 60, width = 220,
  children = {
    { type = "text", id = "kmh", text = "0 km/h", size = 24, weight = "bold" },
  },
})

omsi.ui.set_menu_item#

omsi.ui.set_menu_item(id, label, [icon]) → true, or false and the reason

Puts a line in the game's pause menu, or changes the plugin's line id: its label (40 characters at most, shown as it is) and a Material Symbols icon of the game's ("departure_board"; the plugins' own icon without one). Choosing it closes the menu and sends menu_item with id - to open the plugin's panel, say. A plugin has 3 lines at most; they go when it stops.

Parameters: id string; label string; icon string, optional.

Since 0.3.36. Permission: ui.

Lua
omsi.ui.set_menu_item("board", "Duty board", "departure_board")
omsi.on("menu_item", function(id)
  if id == "board" then omsi.ui.toggle("board") end
end)

omsi.ui.set_theme#

omsi.ui.set_theme(id) → true, or false and the reason

Switches the game's interface to theme id ("" or "openomsi": openOMSI's own look), as if the player chose it in Options › Interface: it is kept for the next start. Ask the player first; they can switch back there.

Parameters: id string.

Since 0.3.42. Permission: ui.

Lua
if omsi.ui.theme() == "" then omsi.ui.set_theme("myplugin") end

omsi.ui.show#

omsi.ui.show(panel, [on]) → boolean

Shows a panel (or hides it with false; it is kept); false when there is none.

Parameters: panel string; on bool, optional.

Since 0.2.22. Permission: ui.

omsi.ui.theme#

omsi.ui.theme() → string

The id of the interface theme in use ("": openOMSI's own look).

Since 0.3.42.

omsi.ui.themes#

omsi.ui.themes() → list of tables

The game's interface themes: each { id, name }, openOMSI's own look first (its id ""). A theme is a folder with a theme.json (Themes/<id>/, or a plugin's own folder: see docs/THEMES.md).

Since 0.3.42.

omsi.ui.toast#

omsi.ui.toast(text, [opts]) → true, or false and the reason

A notification card at the top right, newest at the top; it goes after opts.seconds (1 to 60, default 5). opts: title, icon, color. A plugin shows 8 at most: a ninth makes its oldest go.

Parameters: text string; opts table, optional.

Since 0.2.21. Permission: ui.

Lua
omsi.ui.toast("Next stop: Markt", { title = "Line 5", icon = "directions_bus", seconds = 4 })

omsi.ui.toggle#

omsi.ui.toggle(panel) → boolean

Shows a hidden panel or hides a shown one; whether it shows now.

Parameters: panel string.

Since 0.2.22. Permission: ui.

omsi.ui.typing#

omsi.ui.typing() → boolean

Whether the player types into a text field of a plugin now (the keys then go to the field, not to the bus).

Since 0.2.22.

omsi.ui.update#

omsi.ui.update(panel, element, values) → true, or false and the reason

Changes one element of a panel in place, by its id: text, color, value (a bar, a slider), segments (a bar), checked, selected, name (an icon), values (a chart), rows and aligns (a table), stops (a stop list), src (an image) - cheaper than setting the whole panel again.

Parameters: panel string; element string; values table.

Since 0.2.22. Permission: ui.

Lua
omsi.ui.update("speed", "kmh", { text = omsi.fmt.speed(omsi.speed()) })

omsi.ui.value#

omsi.ui.value(panel, element) → any

The value of a checkbox, slider, text field or tabs element now (as ui_change gives it).

Parameters: panel string; element string.

Since 0.2.22. Permission: ui.

Something wrong or missing? Fix it on GitHub or open an issue.

↑↓ to move↵ to open