Files
Calic a19dd7f1dd feat(launcher): route all UI strings through t(key) indirection
strings.lua holds English defaults. ctx.t(key, ...) looks up the key,
optionally string.formats with extra args, and falls back to '[key]'
for missing entries. All panels and init.lua sweep clean of inline
literals — verified by a grep over '"[A-Z][a-z][a-z ]+"'. This sets
up v2's localization-lib-pattern (separate slice, ADR-0036 trigger)
to swap STRINGS without touching the launcher code.
2026-06-11 07:49:38 +02:00

58 lines
2.1 KiB
Lua

local M = {}
local COLOR_BACKDROP = 0x000000C0
local COLOR_BG = 0x303030FF
local COLOR_BTN = 0x404040FF
local COLOR_BTN_HOT = 0x606060FF
local COLOR_TEXT = 0xE0E0E0FF
local FONT_TITLE = 22
local FONT_BTN = 18
local PADDING = 18
-- def = {
-- title = <localized-title-string>,
-- body = <line-or-array-of-localized-lines>,
-- buttons = { { id=<key>, label=<localized-label>, disabled=<bool> }, ... },
-- }
function M.render(def, screen_w, screen_h)
-- Backdrop.
engine.render.draw_rect(0, 0, screen_w, screen_h, COLOR_BACKDROP)
local w, h = math.min(screen_w - 80, 480), 0
-- Compute height: title + body-lines + buttons-row.
local body_lines = type(def.body) == "table" and def.body or { def.body or "" }
h = PADDING * 4 + FONT_TITLE + #body_lines * (FONT_BTN + 4) + 40
local x = (screen_w - w) / 2
local y = (screen_h - h) / 2
engine.render.draw_rect(x, y, w, h, COLOR_BG)
engine.render.draw_text(def.title, x + PADDING, y + PADDING, FONT_TITLE, COLOR_TEXT)
local cur_y = y + PADDING + FONT_TITLE + PADDING
for _, line in ipairs(body_lines) do
engine.render.draw_text(line, x + PADDING, cur_y, FONT_BTN, COLOR_TEXT)
cur_y = cur_y + FONT_BTN + 4
end
-- Buttons row at the bottom.
local btn_w = (w - PADDING * (#def.buttons + 1)) / #def.buttons
local btn_y = y + h - PADDING - 32
for i, b in ipairs(def.buttons) do
local bx = x + PADDING + (i - 1) * (btn_w + PADDING)
engine.render.draw_rect(bx, btn_y, btn_w, 32, b.disabled and 0x303030FF or COLOR_BTN)
local lw, lh = engine.render.measure_text(b.label, FONT_BTN)
engine.render.draw_text(b.label,
bx + (btn_w - lw) / 2, btn_y + (32 - lh) / 2, FONT_BTN, COLOR_TEXT)
b.rect = { x = bx, y = btn_y, w = btn_w, h = 32 }
end
end
function M.handle_click(def, mx, my)
for _, b in ipairs(def.buttons) do
if not b.disabled and b.rect
and engine.spatial.aabb_contains_point(b.rect, mx, my) then
return b.id
end
end
return nil
end
return M