- [NEW] 'editor' module - [NEW] 'msgbox' module - [NEW] 'score' module - [NEW] 'ui' module - [NEW] 'util' module
73 lines
1.9 KiB
Lua
73 lines
1.9 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.rectf(1,1,msgbox.w-2, 7, 21)
|
|
draw.text(msgbox.title, 2, 2, 28)
|
|
|
|
local y = 12
|
|
for i,v in ipairs(msgbox.text) do
|
|
draw.text(v, 5, y, 1)
|
|
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
|
|
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
|
|
x = x - 34
|
|
end
|
|
|
|
if key.press(key.ESCAPE) then
|
|
app.pop()
|
|
end
|
|
end
|
|
} |