- Classe menu bàsica

This commit is contained in:
2023-01-27 14:51:28 +01:00
parent 4f67b8307b
commit 43ac9f26a2
3 changed files with 41 additions and 18 deletions

View File

@@ -3,4 +3,4 @@ config=ja2
width=160 width=160
height=144 height=144
zoom=5 zoom=5
files=mapa.lua,editor.lua,main.lua files=mapa.lua,editor.lua,menu.lua,main.lua

View File

@@ -1,3 +1,4 @@
function _init() function _init()
menu_option=0 menu_option=0
sprites=loadsurf("sprites.gif") sprites=loadsurf("sprites.gif")
@@ -5,7 +6,15 @@ function _init()
setsource(tiles) setsource(tiles)
local pal=loadpal("tiles.gif") local pal=loadpal("tiles.gif")
setpal(pal) setpal(pal)
set_update(menu_update) set_update(menu_update)
second_menu = {{"PEIV", function() end},{"TORNAR",show_main_menu}}
main_menu = { {"EDITOR", editor_init}, {"EIXIR", quit}, {"TEST", function() menu.show(second_menu) end } }
show_main_menu()
end
function show_main_menu()
menu.show(main_menu)
end end
function set_update(new_update) function set_update(new_update)
@@ -20,21 +29,4 @@ function menu_update()
cls() cls()
color(1) color(1)
prnt("JAIL'S ADVENTURE 2",10,10) prnt("JAIL'S ADVENTURE 2",10,10)
color(4) if menu_option==0 then color(15) prnt(">",10,30) end
prnt("EDITOR",14,30)
color(4) if menu_option==1 then color(15) prnt(">",10,40) end
prnt("EIXIR",14,40)
if btnp(KEY_DOWN) then menu_option=menu_option+1 end
if btnp(KEY_UP) then menu_option=menu_option-1 end
if menu_option<0 then menu_option=1 end
if menu_option>1 then menu_option=0 end
if btnp(KEY_RETURN) then
if menu_option==0 then
editor_init()
elseif menu_option==1 then
quit()
end
end
end end

31
data/menu.lua Normal file
View File

@@ -0,0 +1,31 @@
menu = {
options=nil,
old_update=nil,
selected=1,
show=function(op)
menu.options=op
menu.old_update=update
update=menu.update
menu.selected=1
end,
update=function()
menu.old_update()
for i,v in ipairs(menu.options) do
color(4) if menu.selected==i then color(15) prnt(">",10,20+i*10) end
prnt(v[1],14,20+i*10)
end
if btnp(KEY_DOWN) then menu.selected=menu.selected+1 end
if btnp(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
if btnp(KEY_RETURN) then
update=menu.old_update
menu.options[menu.selected][2]()
end
end
}