openOMSI GitHub Discord

Docs / Plugins / Lua plugins

On-screen panels

12 min readEdit this pagedocs/PLUGINS.md

On this page
  1. The panel table
  2. In the navigator
  3. Elements
  4. A line in the pause menu
  5. An interface theme

omsi.ui puts panels of the plugin's own on the screen, in the game's look: Inter, the game's icons, dark rounded cards with a shadow, as large as the rest of the interface (the interface size setting and the window's height scale them).

A plugin describes a panel as a table once and sets it again when its content changes - every half second, say, not every frame; the same table again changes nothing. omsi.ui.update(panel, element, {...}) changes one element in place. The game lays the panel out and draws it again only when it did change.

Lua
-- plugins/trip_panel.lua: the next stop, the speed and a button
local function show()
  local i = omsi.info()
  omsi.ui.set("trip", {
    anchor = "top_left", x = 16, y = 60, width = 300, accent = "#F47F30",
    children = {
      { type = "row", children = {
        { type = "icon", name = "directions_bus", color = "#F47F30" },
        { type = "text", text = "Line " .. (i.line or "-"), weight = "bold", grow = true },
        { type = "badge", text = string.format("%.0f km/h", i.speed or 0) },
      } },
      { type = "text", text = "Next stop: " .. (i.next_stop or "-") },
      { type = "button", id = "horn", text = "Horn", icon = "campaign" },
    },
  })
end

omsi.every(0.5, show)
omsi.on("key", function(key, down)
  if key == "F10" and down then omsi.ui.focus(not omsi.ui.focused()) end
end)
omsi.on("ui_click", function(panel, element)
  if element == "horn" then omsi.trigger("horn") end
end)

F10 gives the panels the mouse; a click on the button sounds the horn. The whole example is docs/examples/plugins/trip_panel.lua.

omsi.ui.version is 8 (7 before cards over the map, 6 before the interface themes, 5 before a navigator panel in the whole frame and the map element, 4 before grab, 3 before boxes, stop lists and the other elements and keys marked 4 below, 2 before the navigator's board, 1 before the controls): test if omsi.ui and omsi.ui.version >= 2 in a plugin that should also run in an older openOMSI.

The panels are the plugin's own: one plugin cannot change or remove another's, and when the plugin stops, or is loaded again after a change of its file, its panels go (its notifications run their time).

They show over the picture and the navigator and under the game's own lines, menus and windows, and not at all while the game menu, a list of it or the city map is open, nor in VR.

The panel table#

Lua
omsi.ui.set("trip", {
  anchor = "top_left",       -- top_left top top_right left center right bottom_left bottom bottom_right, or navigator
  x = 16, y = 16,             -- from the anchor towards the middle (from a middle: right and down)
  width = 340,                -- the height follows the content
  padding = 12,               -- default 12
  gap = 6,                    -- between the children, default 6
  background = "#14161ACC",   -- default: the game's card colour; "#RRGGBB" or "#RRGGBBAA"
  radius = 12,                -- default 12
  accent = "#F47F30",         -- a stripe along the left edge
  visible = true,             -- false hides it and keeps it
  clickable = false,          -- true: a click anywhere on it is ui_click(id, nil)
  draggable = false,          -- true: while the panels have the mouse it can be moved by its free parts
  grab = false,               -- true: it takes its clicks even while the panels do not have the mouse (ui.version 5)
  frame = false,              -- with anchor = "navigator": the navigator's whole frame, not the board under its map (ui.version 6)
  children = { ... },         -- elements, top to bottom
})

A panel with grab = true takes a left click on it even while the panels do not have the mouse (no F10 or ui.focus first): its buttons, boxes, sliders and tabs answer as with the mouse, and the cab behind it gets none of the click. Such a click starts no typing into a text field and does not drag the panel.

Elsewhere the click is the cab's as before; while the mouse turns the head (no cursor) it is the head's, and the game's own panels over it come first. It is for small cards the driver clicks away or keeps: a card that covers more than a quarter of the screen, or whose background is less than half opaque, takes no click this way.

Sizes are pixels of a 1080p screen at the normal interface size. A panel stays on the screen whatever its offset; one the player dragged keeps its new place when it is set again (omsi.ui.moved(id) says how far).

In the navigator#

A panel with anchor = "navigator" goes into the navigator's board under its map, in place of the list of the next stops: as wide as the navigator, at its scale, and on its card (no card, shadow, accent or rounded corners of its own; background still paints it).

x, y, width and draggable are left aside, and the navigator grows as tall as the panel comes to, as far as the window has room. Shift+N cycles the navigator through map, map and board, off as it does with the stop list; the first time a plugin asks for the board the navigator opens it by itself. One plugin's panel is in the board at a time: another waits until it goes.

Lua
if (omsi.ui.version or 0) >= 3 then
  omsi.ui.set("board", { anchor = "navigator", padding = 10, children = { ... } })
else
  omsi.ui.set("board", { anchor = "left", x = 16, width = 340, children = { ... } })
end

omsi.ui.dock() gives the board's width, the most height there is room for, the height the panel came to, in the panel's pixels, and whether the panel in the board is this plugin's. A panel taller than the room is cut off at the bottom (what is cut off takes no click either), so a plugin can leave out rows that do not fit.

With frame = true (omsi.ui.version 6) the panel fills the navigator's whole frame instead: from its top, as wide as the navigator and as tall as the panel comes to (as far as the window has room), on the navigator's card with its rounded corners - in the panel's background where it gives one, which the navigator paints as its card (with its corners and its opacity setting), not the panel as a square of its own.

The map, the place row and the stop list make way for it; the map shows only where the panel has a map element, with its own rounded corners, and the navigator's cards over it (the next turn, the clock, the speed, the next stop) unless the element says cards = false.

The navigator stays the navigator: it is moved and sized as before, Shift+N shows and hides it (there is no lower part to open), and a press on the map or on a part of the panel that takes no click is the navigator's - a drag moves it, a click opens the city map.

A grab panel there takes clicks without the mouse on its buttons and other clickable parts alone.

omsi.ui.dock() then gives the whole frame: its width, the most height there is room for, the height the panel came to, and true as its fifth value (a game that does not know frame lays the panel out under the map, leaves the map element out and gives no fifth value: a plugin can test for it rather than for a version).

Lua
omsi.ui.set("phone", { anchor = "navigator", frame = true, grab = true, padding = 10, children = {
  { type = "text", text = "Line 5 → Hauptbahnhof", weight = "bold" },
  { type = "map", height = 200, cards = false },
  { type = "button", id = "next", text = "Next stop: Markt 09:14" },
} })

With overlay (omsi.ui.version 8) the map element takes cards of the plugin's own over the map, in place of the navigator's or beside them: a list of small panels, each with a panel table's keys - place (the anchors, navigator aside; default top_left)

x
y
the room kept from the map's edges, default 8
width
default: what is in it needs, never more than the map less x on both sides
padding
default 10
gap
6
background
default the game's card colour
radius
10
children
any elements

a key of a card that the game does not know is left alone, so a plugin written for a later game still shows. A card is laid out at its place in the map, drawn with the panel, which lies over the map.

It is held inside the map (never wider than it, never above its top), what still crosses the map's edge - the bottom of a card taller than the map - is left out: its background stops at the edge with its corners still rounded, a text, an icon or a picture that does not wholly fit is not drawn.

Its buttons and other clickable parts take clicks as in the panel, a press on the map beside them is still the navigator's. A map element outside a panel in the whole frame is empty room, its cards are laid out in that room the same way.

An older openOMSI leaves overlay out, shows the map without them, navigator_map.lua is a whole example.

Lua
omsi.ui.set("phone", { anchor = "navigator", frame = true, padding = 10, children = {
  { type = "map", height = 360, cards = false, overlay = {
    { place = "top_left", width = 220, children = { { type = "text", text = "Line 5 → Hauptbahnhof", weight = "bold" } } },
    { place = "bottom_right", background = "#14161ACC", children = { { type = "text", text = "48 km/h" } } },
  } },
} })

Elements#

Every element can have an id, a color and visible = false (left out, no room kept).

type Keys Draws
text text, size (default 14), weight (regular, medium, bold), align (left, center, right), wrap (default true; false: one line, cut with "…") a line or a paragraph, wrapped at the width it has; a line is 1.3 × size high
icon name, size (default 20) one of the game's icons (Material Symbols names: directions_bus, schedule, payments, warning, star, emoji_events... - every one in assets/icons/material); a name the game does not have draws nothing
row children, gap (default 8), align (start, center, end, between) its children side by side, centred on each other; a child with grow = true takes the width the others leave (several share it); when they do not fit, texts, labels and buttons give up width alike
bar value (0 to 1), height (default 6), color (the filled part, default the game's amber), background; segments (4: { { value = 3, color = "#34B26E" }, ... }, up to 16) a progress bar; in a row 60 wide unless it grows. With segments: its parts side by side, each its share of their sum (early, on time, late...), in place of value
badge text, color (its fill, default amber), text_color, weight (4; default medium) a small rounded label, 20 high
box (4) children, gap (default 4), color (default amber) its children stacked in a box tinted with color, a stripe of it on the left: a note, an advice
stops (4) stops ({ { name, time, expected, expected_color, state, tag }, ... }, up to 128), size (13), color (the rail, default amber) stops on a rail, a row each: state "done" (behind the bus: grey), "now" (the one it heads for: marked, bold) or "ahead" (the default); time on the right, expected before it in expected_color, and tag ("terminus") before them
divider color a thin line (in a row: upright)
map (6) height (default: the navigator's own map's, 0.8 times the width), cards (default true), overlay (8: a list of cards, see In the navigator) in a panel that fills the navigator's frame, the navigator's map there (with its cards over it unless cards = false, and the plugin's overlay cards); elsewhere empty room of its height, with the overlay cards in it
space size (default 8) empty room (in a row: across)
button id (needed), text, icon, color a button 34 high, across the panel (in a row as wide as its label, or what it grows to); a click on it is ui_click(panel id, button id)
image src (a PNG, JPEG, BMP or TGA of the plugin's folder), width, height (default 64) the picture, made smaller to fit the width it has
checkbox id (needed), text, checked a box ticked and unticked by a click: ui_change(panel, id, true/false)
slider id (needed), value, min (0), max (1), step (0: any) a track with a knob, set where it is pressed and followed while the button is held: ui_change(panel, id, number)
input id (needed), text, placeholder, max (characters, default 100) a text field: clicked, it takes what is typed (the keys do not reach the bus meanwhile) - ui_change at every key, Enter is a ui_click on it, Esc or a click elsewhere leaves it
tabs id (needed), tabs (a list of texts), selected (from 1) a row of tabs: ui_change(panel, id, number) when one is chosen
chart values (up to 512 numbers), min, max (default: the values'), height (48), style (line, bars), fill the values over the width: a line (filled below with fill) or bars
table columns (header texts), rows (a list of lists of texts; 4: a cell may be { text = "+3:12", color = "#FF5F57" }), widths (shares of the width), size (13), aligns (4: { "left", "right", ... }, each column's) columns of texts, the header bold over a line

Another element with an id and clickable = true (a whole row, say) is clicked as a button is. Texts are shown as they are: they are not translated into the game's language.

Keys the game does not know are left alone and an element of an unknown type is left out, so a plugin written for a later openOMSI still shows its panels here. A key of the wrong kind makes set return false and the reason.

Limits, each plugin: 16 panels, 200 elements in a panel (those in rows, boxes and cards over a map counted, and each card), 500 characters in a text, 64 in an id, rows and boxes 8 deep, 512 values in a chart or cells in a table.

A line in the pause menu#

A plugin can put up to 3 lines of its own in the pause menu (Esc), in a group before the saving lines. Choosing one closes the menu and sends the plugin menu_item, for example to open the plugin's panel:

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)

The label is shown as the plugin gives it, so the plugin writes it in the player's language. The icon is one of the game's Material Symbols; without one, or with one the game does not have, the line gets the plugins' own icon. The lines go when the plugin stops (ui.remove_menu_item takes one out before that).

An interface theme#

A plugin can bring a look for the game's own screens - the colours of the menus, their panels as frosted glass over the picture, the loading screen with the plugin's logo, which may itself be the loading bar: a theme.json in the plugin's folder makes it a theme of the plugin's name (see THEMES.md).

The player chooses it in Options › Interface; the plugin may switch to it, once and after asking, with ui.set_theme:

Lua
if omsi.ui.set_theme and not omsi.data.theme_offered then
  omsi.data.theme_offered = true
  if omsi.ui.theme() == "" then omsi.ui.set_theme("myplugin") end
end

The choice is the player's setting from then on, kept for the next start; ui.themes() lists the themes there are.

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

↑↓ to move↵ to open