- [FIX] Quan està el menu fora s'inhabiliten els shortcuts en l'editor - [NEW] Menu nou funcionant
83 lines
2.5 KiB
Lua
83 lines
2.5 KiB
Lua
require "ui"
|
|
require "util"
|
|
|
|
msgbox = {
|
|
title = "TITOL",
|
|
text = { "Este es el missatge.", "Pot estar en varies linies" },
|
|
buttons = { {"YES", sys.quit}, {"NO", app.pop} },
|
|
selected = 0,
|
|
w = 100,
|
|
h = 50,
|
|
|
|
show = function(title, text, buttons, default)
|
|
msgbox.selected = default or 1
|
|
msgbox.title = title
|
|
msgbox.text = text
|
|
msgbox.buttons = buttons
|
|
|
|
msgbox.w = 0
|
|
for i,v in ipairs(msgbox.text) do
|
|
local width = #v*4+8
|
|
if width > msgbox.w then msgbox.w = width end
|
|
end
|
|
|
|
msgbox.h = #msgbox.text*6+35
|
|
|
|
app.push(msgbox.update)
|
|
end,
|
|
|
|
update = function()
|
|
local top = (160-msgbox.w)//2
|
|
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.rrectf(0,0,msgbox.w, msgbox.h,4,27)
|
|
|
|
--draw.rectf(1,1,msgbox.w-2, 7, 21)
|
|
draw.text(msgbox.title, 5, 4, 4)
|
|
|
|
local y = 14
|
|
for i,v in ipairs(msgbox.text) do
|
|
draw.text(v, 5, y, 21)
|
|
y = y + 6
|
|
end
|
|
|
|
local mx, my = mouse.pos()
|
|
|
|
local x = msgbox.w - 35
|
|
y = msgbox.h - 12
|
|
for i,v in ipairs(msgbox.buttons) do
|
|
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
|
|
} |