From 40c3dcd6d01dcfd323d0b3e16a57d485b50ea74f Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Wed, 11 Mar 2026 10:21:21 +0100 Subject: [PATCH] =?UTF-8?q?-=20[FIX]=20msgbox=20arreglat=20i=20redissenyat?= =?UTF-8?q?=20-=20[FIX]=20Quan=20est=C3=A0=20el=20menu=20fora=20s'inhabili?= =?UTF-8?q?ten=20els=20shortcuts=20en=20l'editor=20-=20[NEW]=20Menu=20nou?= =?UTF-8?q?=20funcionant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/editor.lua | 123 ++++++++++++++++++++++++------------------------ data/menu.lua | 85 ++++++++++++++++----------------- data/msgbox.lua | 52 +++++++++++--------- data/ui.lua | 39 +++++++++++++++ 4 files changed, 172 insertions(+), 127 deletions(-) diff --git a/data/editor.lua b/data/editor.lua index 77be13f..dfe7eb8 100644 --- a/data/editor.lua +++ b/data/editor.lua @@ -125,68 +125,67 @@ editor = { draw.surf(k.visual.x, k.visual.y, k.visual.w, k.visual.h, mx, my, k.visual.w, k.visual.h, editor.flip) end end - end + if key.press(key.ESCAPE) then + --editor.quit() + menu.toggle() + elseif key.press(key.RIGHT) and rooms.pos.x < 20*7 then + rooms.pos.x = rooms.pos.x + 20 + sprites.remove_out_of_room() + sprites.add_from_room(rooms.pos.x, rooms.pos.y) + elseif key.press(key.LEFT) and rooms.pos.x > 0 then + rooms.pos.x = rooms.pos.x - 20 + sprites.remove_out_of_room() + sprites.add_from_room(rooms.pos.x, rooms.pos.y) + elseif key.press(key.DOWN) and rooms.pos.y < 13*7 then + rooms.pos.y = rooms.pos.y + 13 + sprites.remove_out_of_room() + sprites.add_from_room(rooms.pos.x, rooms.pos.y) + elseif key.press(key.UP) and rooms.pos.y > 0 then + rooms.pos.y = rooms.pos.y - 13 + sprites.remove_out_of_room() + sprites.add_from_room(rooms.pos.x, rooms.pos.y) + elseif key.press(key.TAB) or key.press(key.ESCAPE) then + if editor.layer==LAYER_BACKGROUND or editor.layer==LAYER_FOREGROUND then + editor.tilepicker.show() + else + editor.itempicker.show() + end + elseif key.press(key.P) then + sprites.hero.pos.x = tx*8-4 + sprites.hero.pos.y = ty*8-9 + elseif key.press(key.F9) then + editor.play() + elseif key.press(key.F11) then + reload_textures() + end + + if editor.layer==LAYER_ITEMS then + if key.press(key.F) then + if editor.item_selected then + editor.flip = not editor.flip + elseif editor.item_hovered then + local sprite = sprites.list[editor.item_hovered] + sprite.flipped = not sprite.flipped + map.surf(rooms.surf_items) + local tile = map.tile(sprite.pos.x//8, sprite.pos.y//8) + if tile > 0x7f then tile = tile & 0x7f else tile = tile | 0x80 end + map.tile(sprite.pos.x//8, sprite.pos.y//8, tile) + editor.modified = true + end + end + if editor.item_hovered and key.press(key.DELETE) then + local sprite = sprites.list[editor.item_hovered] + map.surf(rooms.surf_items) + map.tile(sprite.pos.x//8,sprite.pos.y//8,0) + sprites.remove(sprite) + end + end + end view.origin(0,0) draw.text(rooms.pos.x//20,1,96,28) draw.text(rooms.pos.y//13,5,96,28) - if key.press(key.ESCAPE) then - --editor.quit() - menu.toggle() - elseif key.press(key.RIGHT) and rooms.pos.x < 20*7 then - rooms.pos.x = rooms.pos.x + 20 - sprites.remove_out_of_room() - sprites.add_from_room(rooms.pos.x, rooms.pos.y) - elseif key.press(key.LEFT) and rooms.pos.x > 0 then - rooms.pos.x = rooms.pos.x - 20 - sprites.remove_out_of_room() - sprites.add_from_room(rooms.pos.x, rooms.pos.y) - elseif key.press(key.DOWN) and rooms.pos.y < 13*7 then - rooms.pos.y = rooms.pos.y + 13 - sprites.remove_out_of_room() - sprites.add_from_room(rooms.pos.x, rooms.pos.y) - elseif key.press(key.UP) and rooms.pos.y > 0 then - rooms.pos.y = rooms.pos.y - 13 - sprites.remove_out_of_room() - sprites.add_from_room(rooms.pos.x, rooms.pos.y) - elseif key.press(key.TAB) or key.press(key.ESCAPE) then - if editor.layer==LAYER_BACKGROUND or editor.layer==LAYER_FOREGROUND then - editor.tilepicker.show() - else - editor.itempicker.show() - end - elseif key.press(key.P) then - sprites.hero.pos.x = tx*8-4 - sprites.hero.pos.y = ty*8-9 - elseif key.press(key.F9) then - editor.play() - elseif key.press(key.F11) then - reload_textures() - end - - if editor.layer==LAYER_ITEMS then - if key.press(key.F) then - if editor.item_selected then - editor.flip = not editor.flip - elseif editor.item_hovered then - local sprite = sprites.list[editor.item_hovered] - sprite.flipped = not sprite.flipped - map.surf(rooms.surf_items) - local tile = map.tile(sprite.pos.x//8, sprite.pos.y//8) - if tile > 0x7f then tile = tile & 0x7f else tile = tile | 0x80 end - map.tile(sprite.pos.x//8, sprite.pos.y//8, tile) - editor.modified = true - end - end - if editor.item_hovered and key.press(key.DELETE) then - local sprite = sprites.list[editor.item_hovered] - map.surf(rooms.surf_items) - map.tile(sprite.pos.x//8,sprite.pos.y//8,0) - sprites.remove(sprite) - end - end - -- Pintar el menĂº (el marcador serĂ  en el modul game.lua) --score.draw() menu.draw() @@ -237,12 +236,12 @@ editor = { quit=function() if editor.modified then - msgbox.show("IE MEN!", - {"Hi ha canvis sense guardar.", "Vols guardar-los abans d'eixir?"}, + msgbox.show("SAVE CHANGES BEFORE CLOSING?", + {"YOU HAVE UNSAVED CHANGES. IF YOU EXIT", "WITHOUT SAVING, CHANGES WILL BE LOST."}, { - {"Cancel", app.pop}, - {"No", sys.quit}, - {"Yes", function() rooms.save() sys.quit() end} + {"CANCEL", app.pop}, + {" EXIT ", sys.quit}, + {" SAVE ", function() rooms.save() sys.quit() end} } ) else sys.quit() diff --git a/data/menu.lua b/data/menu.lua index 72e4135..a70f685 100644 --- a/data/menu.lua +++ b/data/menu.lua @@ -1,10 +1,26 @@ require "popup" +require "ui" menu = { hidden = true, pos_y = 0, + selected = 1, draw = function() + actions = { + editor.play, + function() rooms.save() editor.modified=false end, + editor.quit, + function() editor.layer=LAYER_FOREGROUND end, + function() editor.layer=LAYER_BACKGROUND end, + function() editor.layer=LAYER_ITEMS end, + function() rooms.toggle_visibility(LAYER_FOREGROUND) end, + function() rooms.toggle_visibility(LAYER_BACKGROUND) end, + function() rooms.toggle_visibility(LAYER_SHADOWS) end, + function() rooms.toggle_visibility(LAYER_ITEMS) end + } + + local sel = menu.selected view.origin(0,menu.pos_y) view.clip() local y = menu.pos_y @@ -13,38 +29,52 @@ menu = { 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 editor.modified then draw.rectf(6,0,2,2,8) end 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) + ui.pushbutton("PLAY",1,3,16,13,10,actions[1], sel==1) + ui.pushbutton("SAVE",22,3,7,22,21,actions[2], sel==2) + if editor.modified then draw.rectf(37,4,2,2,8) end + ui.pushbutton("QUIT",22,12,7,12,5,actions[3], sel==3) 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) + ui.togglebutton("F",44+3,6+3,7,14,9,15,7,editor.layer==LAYER_FOREGROUND,actions[4], sel==4) + ui.togglebutton("B",52+3,6+3,7,14,9,15,7,editor.layer==LAYER_BACKGROUND,actions[5], sel==5) + ui.togglebutton("I",60+3,6+3,7,14,9,15,7,editor.layer==LAYER_ITEMS,actions[6], sel==6) 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) + ui.togglebutton("F",75+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_FOREGROUND),actions[7], sel==7) + ui.togglebutton("B",83+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_BACKGROUND),actions[8], sel==8) + ui.togglebutton("S",91+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_SHADOWS),actions[9], sel==9) + ui.togglebutton("I",99+3,6+3,7,14,9,15,7,rooms.is_visible(LAYER_ITEMS),actions[10], sel==10) + local tab = key.press(key.TAB) + if key.press(key.ESCAPE) then + menu.toggle() + elseif key.press(key.LEFT) or (tab and key.down(key.LSHIFT)) then + menu.selected=menu.selected-1 + if menu.selected < 1 then menu.selected = 10 end + elseif key.press(key.RIGHT) or (tab and not key.down(key.LSHIFT)) then + menu.selected=menu.selected+1 + if menu.selected > 10 then menu.selected = 1 end + elseif key.press(key.RETURN) or key.press(key.SPACE) then + actions[menu.selected]() + end end, toggle = function() if menu.hidden then menu.hidden = false + menu.selected = 1 tweening.add(0,24,0.25,easing.easeOutBounce,function(value,n,finished)menu.pos_y=value end) else menu.hidden = true @@ -52,39 +82,6 @@ menu = { 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=y and my=x and mx=y and my-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() diff --git a/data/msgbox.lua b/data/msgbox.lua index 1aeaee5..6286511 100644 --- a/data/msgbox.lua +++ b/data/msgbox.lua @@ -31,14 +31,15 @@ msgbox = { local left = (104-msgbox.h)//2 view.clip(top, left, msgbox.w, msgbox.h) view.origin(top, left) - draw.outset(0, 0, msgbox.w, msgbox.h) + --draw.outset(0, 0, msgbox.w, msgbox.h) + draw.rrectf(0,0,msgbox.w, msgbox.h,4,27) - draw.rectf(1,1,msgbox.w-2, 7, 21) - draw.text(msgbox.title, 2, 2, 28) + --draw.rectf(1,1,msgbox.w-2, 7, 21) + draw.text(msgbox.title, 5, 4, 4) - local y = 12 + local y = 14 for i,v in ipairs(msgbox.text) do - draw.text(v, 5, y, 1) + draw.text(v, 5, y, 21) y = y + 6 end @@ -47,27 +48,36 @@ msgbox = { local x = msgbox.w - 35 y = msgbox.h - 12 for i,v in ipairs(msgbox.buttons) do - local inside = util.inside(mx, my, {x, y, 32, 9}) - draw.outset(x, y, 32, 9) - if inside then - draw.rectf(x+1,y+1,30,7,27) - if mouse.down(mouse.LEFT) then draw.inset(x, y, 32, 9) end - end - local offset = (32-#v[1]*4)//2 - draw.text(v[1], x+1+offset, y+2, 1) - if (i==msgbox.selected) then - draw.rect(x-1, y-1, 34, 11, 1) - end - if mouse.press(mouse.LEFT) then - if inside then - v[2]() - end - end + ui.pushbutton(v[1],x,y,7,22,21,v[2],msgbox.selected==i) + --local inside = util.inside(mx, my, {x, y, 32, 9}) + --draw.outset(x, y, 32, 9) + --if inside then + -- draw.rectf(x+1,y+1,30,7,27) + -- if mouse.down(mouse.LEFT) then draw.inset(x, y, 32, 9) end + --end + --local offset = (32-#v[1]*4)//2 + --draw.text(v[1], x+1+offset, y+2, 1) + --if (i==msgbox.selected) then + -- draw.rrect(x-1, y-1, 29, 10, 3, 1) + --end + --if mouse.press(mouse.LEFT) then + -- if inside then + -- v[2]() + -- end + --end x = x - 34 end if key.press(key.ESCAPE) then app.pop() + elseif key.press(key.RIGHT) then + msgbox.selected=msgbox.selected-1 + if msgbox.selected==0 then msgbox.selected = #msgbox.buttons end + elseif key.press(key.LEFT) then + msgbox.selected=msgbox.selected+1 + if msgbox.selected>#msgbox.buttons then msgbox.selected = 1 end + elseif key.press(key.RETURN) then + msgbox.buttons[msgbox.selected][2]() end end } \ No newline at end of file diff --git a/data/ui.lua b/data/ui.lua index d784c96..360b650 100644 --- a/data/ui.lua +++ b/data/ui.lua @@ -1,4 +1,43 @@ +ui = { + pushbutton = function(label,x,y,h,col1,col2,callback,selected) + 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=y and my=x and mx=y and my-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) + if selected then + draw.rrect(x-1,y-bh-1,size+2,h+3+bh,3,1) + end + end, +} function draw.outset(x, y, w, h) draw.rectf(x, y, w, h, 23) w,h = w+x,h+y