Control GUI from Lua

  1. Adds interface I.UI with the following functionality:
  • I.UI.MODE - list of all modes (e.g. Interface, Barter, Container)

  • I.UI.WINDOW - list of all window names (e.g Inventory, Stats, Map)

  • I.UI.modes - all currently active modes

  • I.UI.getMode() - get current mode (nil is GUI is closed), equivalent to I.UI.modes[#I.UI.modes]

  • I.UI.addMode(mode, options) - add mode to stack without dropping current modes

  • I.UI.setMode(mode, options) - drop all current mode and set mode

  • I.UI.setMode() - close all GUI windows

  • I.UI.removeMode(mode) - remove specified mode from stack

  • I.UI.registerWindow(window, showFn, hideFn) - entry point for UI dehardcoding. Disables specified built-in window and calls given Lua functions when the window is supposed to be shown or hidden. Allows to fully replace some parts of GUI with Lua UI.

  1. Dehardcodes actions input.ACTION.Inventory, input.ACTION.Journal, input.ACTION.QuickKeysMenu.

Examples

-- Open barter with an NPC
I.UI.addMode('Barter', {target = actor})
-- Hotkey to show only map without other windows
onKeyPress = function(key)
    if key.code ~= input.KEY.M then return end
    if I.UI.getMode() ~= 'Interface' then
        I.UI.addMode('Interface', {windows = {'Map'}})
    else
        I.UI.removeMode('Interface')
    end
end
-- UI dehardcoding
local function showCustomStatsWindow()
    ...
end
local function hideCustomStatsWindow()
    ...
end
I.UI.registerWindow('Stats', showCustomStatsWindow, hideCustomStatsWindow)

Mod example: https://gitlab.com/ptmikheev/openmw-lua-examples#ui-modes

Video: https://streamable.com/y4pj4e

Edited by Petr Mikheev

Merge request reports

Loading