pico8-0hh1/states/menu.lua

78 lines
1.5 KiB
Lua
Raw Normal View History

2022-06-02 20:18:02 +02:00
function state_menu()
2022-05-29 19:49:59 +02:00
local selected = 1
2022-06-01 21:26:57 +02:00
2023-02-23 08:14:29 +01:00
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,
-- }),
-- }
2023-02-22 20:39:24 +01:00
local game_sizes = {
2023-02-23 08:14:29 +01:00
{"mINI bOARD - 4X4", 4},
{"sMALL bOARD - 6X6", 6},
{"mEDIUM bOARD - 8X8", 8},
{"lARGE bOARD - 10X10", 10}
2022-05-29 19:49:59 +02:00
}
2023-02-22 20:39:24 +01:00
for k, item in ipairs(game_sizes) do
add(buttons,
make_button({
2023-02-23 08:14:29 +01:00
x=10, y=10+k*10,
selected_color=7,
text=item[1],
2023-02-22 21:06:16 +01:00
on_click=function() board_size=item[2] set_state(states.loading) end,
2023-02-23 08:14:29 +01:00
on_hover=function() selected=k end,
2023-02-22 20:39:24 +01:00
})
)
end
local rulesId = #buttons+1
add(buttons,
2023-02-23 08:14:29 +01:00
make_button({x=10, y=20+(#game_sizes+1)*10, w=30, text="rULES",
color=13, selected_color=12,
2023-02-22 20:39:24 +01:00
on_click=function() set_state(states.rules) end,
2023-02-23 08:14:29 +01:00
on_hover=function() selected=rulesId end,
2023-02-22 20:39:24 +01:00
})
)
2022-05-29 18:38:07 +02:00
2022-06-01 23:14:22 +02:00
local function _enter()
2022-07-12 21:47:10 +02:00
-- mouse not bound to buttons
poke(0x5F2D, 1)
end
2022-05-29 19:49:59 +02:00
2022-07-12 21:47:10 +02:00
local function _draw()
cls()
draw_bg_menu()
2023-02-23 08:14:29 +01:00
print("pLAY", 10, 8, 8)
2022-07-12 21:47:10 +02:00
for k,button in ipairs(buttons) do
button:draw(selected == k)
end
print("pRESS ❎/X TO CONTINUE", 8, 120, 7)
2022-05-29 18:38:07 +02:00
end
return {
_enter = _enter,
2022-05-29 22:55:43 +02:00
2022-05-29 18:38:07 +02:00
_update = function()
for button in all(buttons) do
button:update()
end
2022-05-29 22:55:43 +02:00
if btnp(UP) then
selected -= 1
elseif btnp(DOWN) then
selected += 1
2022-07-12 21:47:10 +02:00
elseif btnp(BTN_X) then
2022-06-02 20:18:02 +02:00
buttons[selected]:on_click()
2022-05-29 22:55:43 +02:00
end
selected = mid(1, selected, #buttons)
2022-05-29 18:38:07 +02:00
end,
2022-07-12 21:47:10 +02:00
_draw = _draw
2022-05-29 18:38:07 +02:00
}
end