feat(map-editor): Mode-pill render + click handler
Sticky two-segment pill anchored to the menu bar's right edge. Click on a segment calls actions.set_mode; Tab hotkey continues to toggle and the pill reflects the new state next frame. Pill visually overlaps the legacy toolbar in this slice; the toolbar is removed in a later commit. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
38
init.lua
38
init.lua
@@ -544,6 +544,32 @@ local ui = (function()
|
|||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- 0.3.0: Mode-pill anchored to the right end of the menu bar.
|
||||||
|
local function mode_pill_layout()
|
||||||
|
local screen_w = engine.window.size()
|
||||||
|
local x = screen_w - MODE_PILL_MARGIN - MODE_PILL_W
|
||||||
|
local y = (MENU_BAR_H - MODE_PILL_H) / 2
|
||||||
|
return {
|
||||||
|
x = x, y = y,
|
||||||
|
auto = { x = x, y = y, w = MODE_PILL_SEG_W, h = MODE_PILL_H, mode = "auto-tile" },
|
||||||
|
direct = { x = x + MODE_PILL_SEG_W, y = y, w = MODE_PILL_SEG_W, h = MODE_PILL_H, mode = "direct" },
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local function draw_mode_pill()
|
||||||
|
local lay = mode_pill_layout()
|
||||||
|
local current = state.get_mode()
|
||||||
|
for _, seg in ipairs({ lay.auto, lay.direct }) do
|
||||||
|
local active = (current == seg.mode)
|
||||||
|
local bg = active and COL_BUTTON_BG_ACTIVE or COL_BUTTON_BG
|
||||||
|
local fg = active and COL_TEXT_ACTIVE or COL_TEXT
|
||||||
|
engine.render.draw_rect(seg.x, seg.y, seg.w, seg.h, rgba(bg, 0xFF))
|
||||||
|
engine.render.draw_rect_lines(seg.x, seg.y, seg.w, seg.h, rgba(COL_BUTTON_BORDER, 0x40))
|
||||||
|
local label = (seg.mode == "auto-tile") and "Auto-Tile" or "Direct"
|
||||||
|
engine.render.draw_text(label, seg.x + 8, seg.y + 3, 11, rgba(fg, 0xFF))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function side_panel_layout()
|
local function side_panel_layout()
|
||||||
local screen_w, screen_h = engine.window.size()
|
local screen_w, screen_h = engine.window.size()
|
||||||
return {
|
return {
|
||||||
@@ -800,6 +826,7 @@ local ui = (function()
|
|||||||
function M.draw()
|
function M.draw()
|
||||||
local mx, my = engine.input.get_mouse_pos()
|
local mx, my = engine.input.get_mouse_pos()
|
||||||
draw_top_toolbar(mx, my)
|
draw_top_toolbar(mx, my)
|
||||||
|
draw_mode_pill()
|
||||||
draw_side_panel(mx, my)
|
draw_side_panel(mx, my)
|
||||||
draw_palette(mx, my)
|
draw_palette(mx, my)
|
||||||
draw_status(mx, my)
|
draw_status(mx, my)
|
||||||
@@ -910,6 +937,17 @@ local ui = (function()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Mode-pill
|
||||||
|
local pill = mode_pill_layout()
|
||||||
|
for _, seg in ipairs({ pill.auto, pill.direct }) do
|
||||||
|
if in_rect(mx, my, seg.x, seg.y, seg.w, seg.h) then
|
||||||
|
if button == "left" then
|
||||||
|
actions.set_mode(seg.mode)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Top toolbar buttons
|
-- Top toolbar buttons
|
||||||
for _, b in ipairs(toolbar_buttons_layout()) do
|
for _, b in ipairs(toolbar_buttons_layout()) do
|
||||||
if in_rect(mx, my, b.x, b.y, b.w, b.h) then
|
if in_rect(mx, my, b.x, b.y, b.w, b.h) then
|
||||||
|
|||||||
Reference in New Issue
Block a user