Files
paku/data/menu.lua
Raimon Zamora de873a7a25 - [NEW] Redimensionades les habitacions per a ocupar tota la pantalla
- [FIX] Ajustada posició inici segons nou tamany de habitacions
- [FIX] Ajustat nivell de l'aigua segons nou tamany de habitacions
- [WIP] Treballant en el nou menú
2026-03-11 07:42:24 +01:00

140 lines
5.3 KiB
Lua

require "popup"
menu = {
hidden = true,
pos_y = 0,
draw = function()
view.origin(0,menu.pos_y)
view.clip()
local y = menu.pos_y
draw.rrectf(1,0,8,8,1,21)
draw.rrectf(1,-1,8,8,1,6)
draw.hline(3,1,6,21)
draw.hline(3,3,6,21)
draw.hline(3,5,6,21)
draw.rectf(6,0,2,2,8)
if y<=0 then return end
view.origin(0,menu.pos_y-24)
draw.rectf(0,0,160,24,6)
menu.pushbutton("PLAY",1,3,16,13,10,editor.play)
menu.pushbutton("SAVE",22,3,7,22,21,function() rooms.save() editor.modified=false end)
menu.pushbutton("QUIT",22,12,7,12,5,editor.quit)
draw.rrect(44,6,29,14,3,21)
draw.rectf(48,6,17,1,6)
draw.text("EDIT",49,3,21)
menu.togglebutton("F",44+3,6+3,7,14,9,15,7,editor.layer==LAYER_FOREGROUND,function() editor.layer=LAYER_FOREGROUND end)
menu.togglebutton("B",52+3,6+3,7,14,9,15,7,editor.layer==LAYER_BACKGROUND,function() editor.layer=LAYER_BACKGROUND end)
menu.togglebutton("I",60+3,6+3,7,14,9,15,7,editor.layer==LAYER_ITEMS,function() editor.layer=LAYER_ITEMS end)
draw.rrect(75,6,37,14,3,21)
draw.rectf(79,6,17,1,6)
draw.text("SHOW",80,3,21)
menu.togglebutton("F",75+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_FOREGROUND),function() rooms.toggle_visibility(LAYER_FOREGROUND) end)
menu.togglebutton("B",83+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_BACKGROUND),function() rooms.toggle_visibility(LAYER_BACKGROUND) end)
menu.togglebutton("S",91+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_SHADOWS),function() rooms.toggle_visibility(LAYER_SHADOWS) end)
menu.togglebutton("I",99+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_ITEMS),function() rooms.toggle_visibility(LAYER_ITEMS) end)
end,
toggle = function()
if menu.hidden then
menu.hidden = false
tweening.add(0,24,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end)
else
menu.hidden = true
tweening.add(24,0,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end)
end
end,
pushbutton = function(label,x,y,h,col1,col2,callback)
local size = (#label*4)-1+4
local text_y = (h-5)//2
local button_h=0
local mx, my = mouse.pos()
if mx>=x and mx<x+size and my>=y and my<y+h then
button_h = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end
end
draw.rrectf(x,y+1,size,h,1,col2)
draw.rrectf(x,y-button_h,size,h,1,col1)
draw.text(label,x+2,y+text_y-button_h,col2)
end,
togglebutton = function(label,x,y,h,col1,col2,dis1,dis2,state,callback)
local size = (#label*4)-1+4
local text_y = (h-5)//2
local bh=0
local mx, my = mouse.pos()
if mx>=x and mx<x+size and my>=y and my<y+h then
bh = mouse.down(mouse.LEFT) and -1 or 1
if mouse.press(mouse.LEFT) then callback() end
end
if not state then
col1,col2 = dis1,dis2
else
if bh>-1 then bh=bh-1 end
end
draw.rrectf(x,y+1,size,h,1,col2)
draw.rrectf(x,y-bh,size,h,1,col1)
draw.text(label,x+2,y+text_y-bh,col2)
end,
-- current_x = 0,
--
-- init = function()
-- end,
--
-- draw = function()
-- view.origin(0,0)
-- view.clip()
-- draw.rectf(0,0,160,7,23)
-- draw.hline(0,7,160,16)
-- menu.current_x = 1
--
-- menu.option("FILE")
-- popup.create("FILE", 1, 8)
-- popup.addOption("FILE", "Play", editor.play)
-- popup.addOption("FILE", "Save", function() rooms.save() editor.modified=false end)
-- popup.addOption("FILE", "Quit", editor.quit)
--
-- menu.option("VIEW")
-- popup.create("VIEW", 1, 8)
-- popup.addOption("VIEW", "Background", function() rooms.toggle_visibility(LAYER_BACKGROUND) end)
-- popup.addOption("VIEW", "Shadows", function() rooms.toggle_visibility(LAYER_SHADOWS) end)
-- popup.addOption("VIEW", "Foreground", function() rooms.toggle_visibility(LAYER_FOREGROUND) end)
-- popup.addOption("VIEW", "Sprites", function() rooms.toggle_visibility(LAYER_SPRITES) end)
--
-- menu.option("EDIT")
-- popup.create("EDIT", 1, 8)
-- popup.addOption("EDIT", "Background", function() editor.layer=LAYER_BACKGROUND end)
-- popup.addOption("EDIT", "Foreground", function() editor.layer=LAYER_FOREGROUND end)
-- popup.addOption("EDIT", "Items", function() editor.layer=LAYER_ITEMS end)
-- --popup.addOption("EDIT", "Sprites", function() rooms.toggle_visibility(LAYER_SPRITES) end)
--
-- menu.option("TOOLS")
-- if editor.modified then
-- draw.text("*",160-5,1,8)
-- end
--
-- end,
--
-- option = function(label)
-- local next_x = menu.current_x + (#label + 2)*4
-- local mx, my = mouse.pos()
-- if my < 8 and mx >= menu.current_x and mx < next_x then
-- draw.rectf(menu.current_x, 0, next_x-menu.current_x, 7, 21)
-- if mouse.down(mouse.LEFT) then
-- mouse.discard()
-- popup.show(label)
-- end
-- end
-- draw.text(label,menu.current_x+4,1,28)
-- menu.current_x = next_x
-- end
}