Fixed stuff

This commit is contained in:
Simon Cambier 2023-02-22 20:39:24 +01:00
parent 2bd3660e5a
commit 988460d8b5
3 changed files with 34 additions and 19 deletions

View File

@ -1,23 +1,39 @@
function state_menu()
local selected = 1
local function on_btn_draw(btn)
if selected == btn.data.i then
btn.color = 7
end
end
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) 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})
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, w=200,
text=item[1], data={i=2},
on_click=function() set_state(states.rules) end,
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,
})
)
local function _enter()
-- mouse not bound to buttons
poke(0x5F2D, 1)
@ -26,6 +42,7 @@ function state_menu()
local function _draw()
cls()
draw_bg_menu()
-- printh(selected)
for k,button in ipairs(buttons) do
button:draw(selected == k)
end

View File

@ -17,14 +17,14 @@ function state_rules()
return {
_enter = function()
custom_font()
end,
_exit = function()
standard_font()
end,
_update=function()
custom_font()
if frame_count%8==0 then
color += 1
end

6
ui.lua
View File

@ -10,15 +10,13 @@ function make_button(options)
text = options.text,
on_click = options.on_click,
on_hover = options.on_hover,
on_draw = options.on_draw,
ogColor = options.color or 5,
color = options.color or 5,
draw=function(self, selected)
standard_font()
-- rect2(self.x, self.y, self.w, self.h, 8)
if self.on_draw then self.on_draw(self) end
print(self.text, self.x+1, self.y+1, self.color)
local color = selected and 7 or self.color
print(self.text, self.x+1, self.y+1, color)
end,
update=function(self)