Logic & UI

Game UI

Canvases, panels, text and buttons for menus and HUDs.

Trisgine's UI system draws canvases of elements, either on screen (menus, HUD) or in the world (signs, screens on a wall).

Building UI in the editor

  1. Right-click the Hierarchy, then UI > Canvas (Screen) for a HUD or menu, or Canvas (World) for something placed in 3D.
  2. With the canvas selected, add elements: UI > Panel, Button, Text, Image, Toggle, Slider, Scroll View, Dropdown.
  3. Select an element to edit its anchors, size, colour, text style and more in the Inspector. Add Component offers UI extras: Text Style, Auto-Layout Container, State Style, Toggle, Slider, Scroll View, Dropdown and 3D Viewport.
  4. Save Scene also writes the canvas to a .uidoc file.

The .uidoc format

Canvases are stored as indented text:

canvas UiDocMenu space=screen w=1920 h=1080
  panel UiDocPanel preset=center w=50% h=50% tint=1,0.2,0.2,1
    text UiDocTitle preset=top-center w=320 h=48 size=40 align=center valign=middle [email protected]
    button UiDocPlay w=200 h=64
  • Two spaces of indentation per level.
  • Element kinds: panel, button, text, image, toggle, slider, scroll, dropdown.
  • Common keys: preset= (anchoring, e.g. center, top-center), w= / h= (pixels or %), tint=, text= (a literal, or @key for a localized string), size=, align= / valign=, sprite=, layout=hstack|vstack|grid.

A scene lists its canvases by UUID in a ui: block, and needs the UI systems in update: and render::

tgscene
ui:
	-7D1C4B90A3E52611
update:
	-UiCanvasMetrics
	-UiHierarchy
	-UiTextShape
	-UiLayout
	-UiViewport
	-UiInput
	-UiShortcut
	-UiScriptRun
render:
	-UiScreenRendering
	-UiWorldRendering

Making buttons do things

Attach a visual script to a UI element and use OnUiEvent + UiClicked → Branch → UiCommand. Commands are the built-in game-menu actions: game.new, game.continue, page and tab navigation, settings, save-slot actions, dialog.yes / dialog.no and app.exit. They need the GameMenuModel system in the scene.

tgscript
//! node 1 OnUiEvent pos=(60,80)
export function onUiEvent(ctx) {
    //! node 2 UiClicked pos=(60,200)
    const n2_value = ctx.uiClicked();
    //! node 3 Branch pos=(260,80)
    if (n2_value) {
        //! node 4 UiCommand pos=(460,80) command="game.new"
        ctx.uiCommand("game.new");
    }
}

Commands with dots or colons are written in quotes, as above.

Changing text from gameplay

SetText writes a fixed string into a UI Text element, and SetTextNumber writes a prefix followed by a number (Score: and 12 show Score: 12). Wire FindEntity with the element's name into their element input. A SetText string that starts with @ is a localization key. See Meadow Quest's quest line for a worked example.

Localization

Text that starts with @ is a key looked up in the active language: [email protected]. See Localization for the panel, the CSV workflow and what works on web.