Fixed some buttons stuff
This commit is contained in:
parent
3432f5d36e
commit
c1484655cd
3
main.lua
3
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
|
||||
|
|
|
@ -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
|
||||
|
|
8
ui.lua
8
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user