Files
sporel-module-lib-managemen…/panels/modal.lua
Calic 89b7b060d1 feat(launcher): launch button + dep-conflict modal
Detail-panel bottom-right Launch button: switches to the selected
module via engine.switch_module if dep-check is clean, otherwise
opens a modal listing conflicts with Cancel + 'Launch anyway'. The
latter is greyed out unless engine.module.switch_module_supports_fallback
is exposed (separate engine slice). FSM adds STATE_MODAL_CONFLICT
with transitions to/from STATE_LIST via cancel/launch_anyway/esc.

Generic panels/modal.lua takes a def-table (title/body/buttons) and
returns the clicked button id from handle_click; reusable for future
modals beyond the conflict case.
2026-06-11 02:54:55 +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 = "Confirm",
-- body = "text or array of lines",
-- buttons = { { id="cancel", label="Cancel" }, { id="ok", label="Launch anyway", disabled=false } },
-- }
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