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.
This commit is contained in:
@@ -115,10 +115,22 @@ function M.render(ctx)
|
||||
if r and r.kind == "error" then ctx.list_tint = "error"
|
||||
elseif r and r.kind == "warn" then ctx.list_tint = "warn"
|
||||
end
|
||||
|
||||
-- L.7: Launch button at the bottom-right of the detail panel. Label
|
||||
-- runs through ctx.t() so L.8's strings.lua picks it up once wired.
|
||||
local label = ctx.t("launch_module")
|
||||
local lw, lh = engine.render.measure_text(label, 18)
|
||||
local btn_w = lw + 32
|
||||
local btn_h = lh + 16
|
||||
local btn_x = p.x + p.w - PADDING - btn_w
|
||||
local btn_y = p.y + p.h - PADDING - btn_h
|
||||
engine.render.draw_rect(btn_x, btn_y, btn_w, btn_h, 0x405080FF)
|
||||
engine.render.draw_text(label, btn_x + 16, btn_y + 8, 18, 0xFFFFFFFF)
|
||||
ctx._launch_btn = { x = btn_x, y = btn_y, w = btn_w, h = btn_h }
|
||||
end
|
||||
|
||||
function M.handle_click(ctx, mx, my)
|
||||
-- L.5: carousel arrow hit-test. L.7 will add launch-button.
|
||||
-- L.5: carousel arrow hit-test. L.7 adds the launch-button.
|
||||
if not ctx.selected_entry or ctx.selected_entry == "news" then
|
||||
return false
|
||||
end
|
||||
@@ -128,6 +140,34 @@ function M.handle_click(ctx, mx, my)
|
||||
if s and ctx.carousel_mod and ctx.carousel_mod.handle_click(s, mx, my) then
|
||||
return true
|
||||
end
|
||||
|
||||
-- L.7: Launch button → either switch directly (clean deps) or open
|
||||
-- the conflict modal (warn/error deps). The "Launch anyway" path
|
||||
-- requires engine.module.switch_module_supports_fallback (separate
|
||||
-- engine slice); until that ships the button stays disabled.
|
||||
if ctx._launch_btn and engine.spatial.aabb_contains_point(ctx._launch_btn, mx, my) then
|
||||
local r = entry.status.dep_check_result
|
||||
if r and r.ok then
|
||||
engine.switch_module(entry.id)
|
||||
else
|
||||
ctx.modal_def = {
|
||||
title = ctx.t("conflict_title"),
|
||||
body = {
|
||||
ctx.t("conflict_body_line1"),
|
||||
string.format(ctx.t("conflict_body_line2_fmt"),
|
||||
r and #r.missing or 0),
|
||||
},
|
||||
buttons = {
|
||||
{ id = "cancel", label = ctx.t("cancel") },
|
||||
{ id = "launch_anyway", label = ctx.t("launch_anyway"),
|
||||
disabled = not engine.module.switch_module_supports_fallback },
|
||||
},
|
||||
module_id = entry.id,
|
||||
}
|
||||
ctx.modal_open = "conflict"
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
57
panels/modal.lua
Normal file
57
panels/modal.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
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
|
||||
Reference in New Issue
Block a user