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() function state_menu()
local selected = 1 local selected = 1
local function on_btn_draw(btn)
if selected == btn.data.i then
btn.color = 7
end
end
local buttons = { local buttons = {
make_button({x=10, y=10, w=30, text="pLAY", data={i=1}, make_button({x=10, y=10, w=30, text="pLAY", data={i=1},
on_click=function() set_state(states.loading) end, on_click=function() set_state(states.loading) end,
on_hover=function(btn) btn.color = 7 selected = 1 end, on_hover=function(btn) 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})
} }
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() local function _enter()
-- mouse not bound to buttons -- mouse not bound to buttons
poke(0x5F2D, 1) poke(0x5F2D, 1)
@ -26,6 +42,7 @@ function state_menu()
local function _draw() local function _draw()
cls() cls()
draw_bg_menu() draw_bg_menu()
-- printh(selected)
for k,button in ipairs(buttons) do for k,button in ipairs(buttons) do
button:draw(selected == k) button:draw(selected == k)
end end

View File

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

6
ui.lua
View File

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