From 988460d8b5a860a5884eff656a04ae86a5877621 Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Wed, 22 Feb 2023 20:39:24 +0100 Subject: [PATCH] Fixed stuff --- states/menu.lua | 41 +++++++++++++++++++++++++++++------------ states/rules.lua | 6 +++--- ui.lua | 6 ++---- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/states/menu.lua b/states/menu.lua index e936d57..9e84b2c 100644 --- a/states/menu.lua +++ b/states/menu.lua @@ -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 diff --git a/states/rules.lua b/states/rules.lua index 307d1d5..8614e91 100644 --- a/states/rules.lua +++ b/states/rules.lua @@ -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 diff --git a/ui.lua b/ui.lua index 0a03274..de3b6f9 100644 --- a/ui.lua +++ b/ui.lua @@ -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)