pico8-0hh1/states/menu.lua

78 lines
1.7 KiB
Lua

function state_menu()
local selected = 1
local buttons = {}
-- local buttons = {
-- make_button({x=10, y=10, w=30, text="pLAY", data={i=1},
-- on_click=function() set_state(states.loading) end,
-- on_hover=function(btn) selected=1 end,
-- }),
-- }
local game_sizes = {
{ "mINI bOARD - 4X4", 4 },
{ "sMALL bOARD - 6X6", 6 },
{ "mEDIUM bOARD - 8X8", 8 },
{ "lARGE bOARD - 10X10", 10 }
}
for k, item in ipairs(game_sizes) do
add(
buttons,
make_button({
x = 10, y = 10 + k * 10,
selected_color = 7,
text = item[1],
on_click = function() board_size = item[2] set_state(states.loading) end,
on_hover = function() selected = k end
})
)
end
local rulesId = #buttons + 1
add(
buttons,
make_button({
x = 10, y = 20 + (#game_sizes + 1) * 10, w = 30, text = "rULES",
color = 13, selected_color = 12,
on_click = function() set_state(states.rules) end,
on_hover = function() selected = rulesId end
})
)
local function _enter()
-- mouse not bound to buttons
end
local function _draw()
cls()
draw_bg_menu()
print("pLAY", 10, 8, 8)
for k, button in ipairs(buttons) do
button:draw(selected == k)
end
print("pRESS ❎/X TO CONTINUE", 8, 120, 7)
end
return {
_enter = _enter,
_update = function()
for button in all(buttons) do
button:update()
end
if btnp(UP) then
selected -= 1
elseif btnp(DOWN) then
selected += 1
elseif btnp(BTN_X) then
buttons[selected]:on_click()
end
selected = mid(1, selected, #buttons)
end,
_draw = _draw
}
end