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-05-29 19:49:59 +02:00
|
|
|
local buttons = {
|
2022-07-12 21:47:10 +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,
|
2023-02-22 20:39:24 +01:00
|
|
|
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}
|
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({
|
|
|
|
x=10, y=10+k*10, w=200,
|
|
|
|
text=item[1], data={i=2},
|
2023-02-22 21:06:16 +01:00
|
|
|
on_click=function() board_size=item[2] set_state(states.loading) end,
|
2023-02-22 20:39:24 +01:00
|
|
|
on_hover=function(btn) selected=k+1 end,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local rulesId = #buttons+1
|
|
|
|
add(buttons,
|
|
|
|
make_button({x=10, y=10+(#game_sizes+1)*10, w=30, text="rULES", data={i=2},
|
|
|
|
on_click=function() set_state(states.rules) end,
|
|
|
|
on_hover=function(btn) selected=rulesId end,
|
|
|
|
})
|
|
|
|
)
|
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-22 20:39:24 +01:00
|
|
|
-- printh(selected)
|
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
|