pico8-0hh1/states/menu.lua

52 lines
1.0 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
2022-06-02 20:18:02 +02:00
local function on_btn_draw(btn)
2022-06-01 21:26:57 +02:00
if selected == btn.data.i then
btn.color = 7
end
end
2022-05-29 19:49:59 +02:00
local buttons = {
2022-06-02 20:18:02 +02:00
make_button({x=10, y=10, w=30, text="play", data={i=1},
2022-07-02 13:52:31 +02:00
on_click=function() set_state(states.loading) end,
2022-06-02 20:18:02 +02:00
on_hover=function(btn) btn.color = 7 selected = 1 end,
on_draw=on_btn_draw}),
make_button({x=10, y=20, w=30, text="rules", data={i=2},
on_click=function() set_state(states.rules) end,
on_hover=function(btn) btn.color = 7 selected = 2 end,
on_draw=on_btn_draw})
2022-05-29 19:49:59 +02:00
}
2022-05-29 18:38:07 +02:00
2022-06-01 23:14:22 +02:00
local function _enter()
2022-05-29 19:49:59 +02:00
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
elseif btnp(BTN_O) 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,
_draw = function()
2022-07-02 13:52:31 +02:00
cls()
2022-05-29 19:49:59 +02:00
for k,button in ipairs(buttons) do
button:draw(selected == k)
2022-05-29 18:38:07 +02:00
end
2022-05-29 22:55:43 +02:00
print("press 🅾️/c to continue", 8, 120, 7)
2022-05-29 18:38:07 +02:00
end
}
end