feat(map-editor): mode-pill 3 segments for Auto/Cell/Direct
MODE_PILL_W widens 130 -> 195 (3 x 65). mode_pill_layout returns
the new cell segment between auto and direct; draw_mode_pill
iterates the new triple; the click-handler dispatches the cell
segment to actions.set_mode("cell-tile"). Self-test t9 confirms
the three segments sit at consecutive SEG_W offsets.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
30
init.lua
30
init.lua
@@ -387,7 +387,7 @@ local ui = (function()
|
||||
-- Menu bar
|
||||
local MENU_BAR_H = 24
|
||||
local MENU_LABEL_PAD_X = 12
|
||||
local MODE_PILL_W = 130
|
||||
local MODE_PILL_W = 195
|
||||
local MODE_PILL_H = 18
|
||||
local MODE_PILL_SEG_W = 65
|
||||
local MODE_PILL_MARGIN = 4
|
||||
@@ -668,21 +668,26 @@ local ui = (function()
|
||||
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" },
|
||||
auto = { x = x, y = y, w = MODE_PILL_SEG_W, h = MODE_PILL_H, mode = "auto-tile" },
|
||||
cell = { x = x + MODE_PILL_SEG_W, y = y, w = MODE_PILL_SEG_W, h = MODE_PILL_H, mode = "cell-tile" },
|
||||
direct = { x = x + MODE_PILL_SEG_W * 2, 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
|
||||
for _, seg in ipairs({ lay.auto, lay.cell, 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"
|
||||
local label
|
||||
if seg.mode == "auto-tile" then label = "Auto-Tile"
|
||||
elseif seg.mode == "cell-tile" then label = "Cell-Tile"
|
||||
else label = "Direct"
|
||||
end
|
||||
engine.render.draw_text(label, seg.x + 8, seg.y + 3, 11, rgba(fg, 0xFF))
|
||||
end
|
||||
end
|
||||
@@ -1310,7 +1315,7 @@ local ui = (function()
|
||||
|
||||
-- Mode-pill
|
||||
local pill = mode_pill_layout()
|
||||
for _, seg in ipairs({ pill.auto, pill.direct }) do
|
||||
for _, seg in ipairs({ pill.auto, pill.cell, 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)
|
||||
@@ -1444,6 +1449,8 @@ local ui = (function()
|
||||
M._VIEW_ITEMS = VIEW_ITEMS
|
||||
M._EDIT_ITEMS = EDIT_ITEMS
|
||||
M._LAYER_PANEL_ROWS = LAYER_PANEL_ROWS
|
||||
M._mode_pill_layout = mode_pill_layout
|
||||
M._MODE_PILL_SEG_W = MODE_PILL_SEG_W
|
||||
|
||||
return M
|
||||
end)()
|
||||
@@ -1560,6 +1567,17 @@ local function self_test()
|
||||
engine.test.equals(state.get_mode(), "cell-tile",
|
||||
"t8: set_mode('cell-tile') sets mode")
|
||||
|
||||
-- t9: mode_pill_layout returns 3 segments at consecutive x positions
|
||||
local pill = ui._mode_pill_layout and ui._mode_pill_layout() or nil
|
||||
engine.test.assert(pill ~= nil,
|
||||
"t9: mode_pill_layout accessible from self_test")
|
||||
engine.test.assert(pill.cell ~= nil and pill.direct ~= nil,
|
||||
"t9: pill has all three segments (auto, cell, direct)")
|
||||
engine.test.equals(pill.cell.x - pill.auto.x, ui._MODE_PILL_SEG_W,
|
||||
"t9: cell segment sits one SEG_W right of auto")
|
||||
engine.test.equals(pill.direct.x - pill.cell.x, ui._MODE_PILL_SEG_W,
|
||||
"t9: direct segment sits one SEG_W right of cell")
|
||||
|
||||
-- t12: cycle_mode cycles auto -> cell -> direct -> auto
|
||||
state.set_mode("auto-tile")
|
||||
state.cycle_mode()
|
||||
|
||||
Reference in New Issue
Block a user