Files
jailsadventure2/data/menu.lua

56 lines
1.6 KiB
Lua

menu = {
options=nil,
old_update=nil,
selected=1,
return_function=nil,
show=function(op, retfun)
menu.options=op
menu.old_update=update
update=menu.update
menu.selected=1
menu.return_function=retfun
end,
update=function()
--menu.old_update()
draw.rectf(9,20, 141, 14+#menu.options*10,6)
draw.rect(9,20, 141, 14+#menu.options*10,8)
draw.rect(8,19, 143, 16+#menu.options*10,6)
for i,v in ipairs(menu.options) do
local color=4
if menu.selected==i then color=15 draw.text(">",20,20+i*10,color) end
draw.text(v[1],24,20+i*10,color)
end
if key.press(key.DOWN) then menu.selected=menu.selected+1 end
if key.press(key.UP) then menu.selected=menu.selected-1 end
if menu.selected==0 then menu.selected=#menu.options end
if menu.selected>#menu.options then menu.selected=1 end
local mx,my=mouse.pos()
if mx>=20 and mx<=140 and my>=28 and my<=(28+#menu.options*10) then
menu.selected=math.min(1+math.floor((my-28)/10),#menu.options)
if mouse.press(mouse.LEFT) then
update=menu.old_update
menu.options[menu.selected][2]()
end
end
if key.press(key.RETURN) then
update=menu.old_update
menu.options[menu.selected][2]()
end
if key.press(key.ESCAPE) then
if menu.return_function then
update=menu.old_update
menu.return_function()
end
end
end
}