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() rectfill(9,20, 150, 34+#menu.options*10,6) rect(9,20, 150, 34+#menu.options*10,8) rect(8,19, 151, 35+#menu.options*10,6) for i,v in ipairs(menu.options) do color(4) if menu.selected==i then color(15) prnt(">",20,20+i*10) end prnt(v[1],24,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 local mx,my=mouse() 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 mbtnp(1) then update=menu.old_update menu.options[menu.selected][2]() end end if btnp(KEY_RETURN) then update=menu.old_update menu.options[menu.selected][2]() end if btnp(KEY_ESCAPE) then if menu.return_function then update=menu.old_update menu.return_function() end end end }