From c1484655cdd499a5cdd00b3ef67e162e2ca9ea64 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Thu, 23 Feb 2023 08:14:29 +0100 Subject: [PATCH] Fixed some buttons stuff --- main.lua | 3 ++- states/menu.lua | 37 +++++++++++++++++++++---------------- ui.lua | 8 +++++--- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/main.lua b/main.lua index aa985e0..39dc1cd 100644 --- a/main.lua +++ b/main.lua @@ -132,5 +132,6 @@ function _draw() for overlay in all(overlays) do overlay:_draw() end - spr(1, stat(32), stat(33)) + -- mouse cursor + spr(1, mouse_x, mouse_y) end diff --git a/states/menu.lua b/states/menu.lua index 5e49d9f..c2b8d47 100644 --- a/states/menu.lua +++ b/states/menu.lua @@ -1,26 +1,28 @@ function state_menu() local selected = 1 - 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, - }), - } + 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, + -- }), + -- } local game_sizes = { - {"mINI bOARD - 4x4", 4}, - {"sMALL bOARD - 6x6", 6}, - {"mEDIUM bOARD - 8x8", 8}, - {"lARGE bOARD - 10x10", 10} + {"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}, + x=10, y=10+k*10, + selected_color=7, + text=item[1], on_click=function() board_size=item[2] set_state(states.loading) end, - on_hover=function(btn) selected=k+1 end, + on_hover=function() selected=k end, }) ) end @@ -28,9 +30,10 @@ function state_menu() local rulesId = #buttons+1 add(buttons, - make_button({x=10, y=10+(#game_sizes+1)*10, w=30, text="rULES", data={i=2}, + make_button({x=10, y=20+(#game_sizes+1)*10, w=30, text="rULES", + color=13, selected_color=12, on_click=function() set_state(states.rules) end, - on_hover=function(btn) selected=rulesId end, + on_hover=function() selected=rulesId end, }) ) @@ -42,7 +45,9 @@ function state_menu() local function _draw() cls() draw_bg_menu() - -- printh(selected) + + print("pLAY", 10, 8, 8) + for k,button in ipairs(buttons) do button:draw(selected == k) end diff --git a/ui.lua b/ui.lua index de3b6f9..e718ebc 100644 --- a/ui.lua +++ b/ui.lua @@ -11,12 +11,14 @@ function make_button(options) on_click = options.on_click, on_hover = options.on_hover, ogColor = options.color or 5, + selected_color = options.selected_color or 5, color = options.color or 5, draw=function(self, selected) standard_font() - local color = selected and 7 or self.color - print(self.text, self.x+1, self.y+1, color) + local color = selected and self.selected_color or self.color + print(self.text, self.x, self.y, color) + -- rect(self.x, self.y, self.x+self.w, self.y+self.h, color) end, update=function(self) @@ -29,7 +31,7 @@ function make_button(options) if stat(34)&1 == 1 then state = 2 else - if self.on_hover then self.on_hover(self) end + if self.on_hover then self:on_hover() end state = 1 end else