Esc to clear, Enter to open the best match, click an export to open it in its page
Interactions & UI
Screens in the world (DUI)
A DUI is a page from your resource, drawn by a browser of its own into a texture the game can draw in the world: over a head, on a wall, on the ground. WHIP draws its prompts, /me bubbles, NPC conversations, garage bays and the Director's marks this way.
The rules
Each DUI is a whole browser that keeps rendering whether or not anything draws it. WHIP's own keep these rules, and yours should too:
- One browser per system, not per thing. Lay the page out as an atlas of cells: thirty garage bays are thirty quads from one texture.
- A change is a message, never a new browser. Send one only when a cell's content changes, never every frame.
- Made on first use, given back when idle. Create it the first time something draws from it; destroy it a while after the last.
- A still page. Animate only while something is happening; an endless animation renders all the time.
Your own DUI
One browser for every sign your resource shows, made on the first draw, sent a sign's words only when they change, and destroyed a minute after the last draw.
local PAGE = ('nui://%s/html/signs.html'):format(GetCurrentResourceName())
local TXD, TEX = 'mysigns', 'signs'
local IDLE_MS = 60000
local dui, up, waiting, painted, lastUsed = nil, false, {}, {}, 0
local function release()
if not dui then return end
DestroyDui(dui)
dui, up, waiting, painted = nil, false, {}, {}
end
-- Given back IDLE_MS after the last draw: a timer, not a loop
local function checkIdle()
if not dui then return end
local left = lastUsed + IDLE_MS - GetGameTimer()
if left > 0 then SetTimeout(left, checkIdle) else release() end
end
-- Every draw calls this: made the first time, and counted as used
local function ensure()
lastUsed = GetGameTimer()
if dui then return end
dui = CreateDui(PAGE, 1024, 1024)
CreateRuntimeTextureFromDuiHandle(CreateRuntimeTxd(TXD), TEX, GetDuiHandle(dui))
local mine = dui
CreateThread(function()
while dui == mine and not IsDuiAvailable(mine) do Wait(50) end
if dui ~= mine then return end
up = true
for _, msg in ipairs(waiting) do SendDuiMessage(dui, json.encode(msg)) end
waiting = {}
end)
SetTimeout(IDLE_MS, checkIdle)
end
-- A sign's words, sent only when they change (held until the page is up)
local function paint(cell, text)
ensure()
if painted[cell] == text then return end
painted[cell] = text
local msg = { cell = cell, text = text }
if up then SendDuiMessage(dui, json.encode(msg)) else waiting[#waiting + 1] = msg end
end
-- Each frame a sign is near: its cell of the 4 x 4 atlas, over that spot
local function drawSign(cell, x, y, z)
ensure()
if not up then return end
local col, row = cell % 4, cell // 4
SetDrawOrigin(x, y, z, 0)
DrawSpriteUv(TXD, TEX, 0.0, 0.0, 0.1, 0.1, col / 4, row / 4, (col + 1) / 4, (row + 1) / 4, 0.0, 255, 255, 255, 255)
ClearDrawOrigin()
endThe page reads each message as a JSON string and paints only the cell it names:
window.addEventListener('message', (e) => {
const d = typeof e.data === 'string' ? JSON.parse(e.data) : e.data;
if (d && d.cell !== undefined) document.querySelectorAll('.cell')[d.cell].textContent = d.text;
});Keep an atlas inside the game's limit.
CreateDui throws for a page wider than the game allows: 8192 pixels on GTA V Enhanced. Pack cells into more rows rather than one long strip.