forked from jordanmchavez/kdm-tts
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMessageBox.ttslua
58 lines (41 loc) · 1.92 KB
/
MessageBox.ttslua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
local Check = require("Kdm/Util/Check")
local Ui = require("Kdm/Ui")
---------------------------------------------------------------------------------------------------
local MessageBox = {}
MessageBox.func = nil
---------------------------------------------------------------------------------------------------
function MessageBox.Init()
local ui = Ui.Get2d()
MessageBox.ui = ui
local panel = ui:Panel({ id = "Main", rectAlignment = "MiddleCenter", x = 0, y = 0, z = -10, width = 300, height = 150, active = false })
MessageBox.panel = panel
panel:Image({ id = "Main", x = 0, y = 0, width = 300, height = 150, image = "MessageBox" })
MessageBox.messageText = panel:Text({ id = "Message", rectAlignment = "LowerCenter", x = 0, y = 60, width = 220, height = 85, alignment = "MiddleCenter", fontSize = 18, horizontalOverflow = "Truncate", verticalOverflow = "Truncate" })
panel:Button({ id = "OK", rectAlignment = "LowerLeft", x = 33, y = 20, width = 100, height = 30, onClick = function()
MessageBox.Hide()
if MessageBox.func then
MessageBox.func()
end
end })
panel:Button({ id = "Cancel", rectAlignment = "LowerLeft", x = 167, y = 20, width = 100, height = 30, onClick = function()
MessageBox.Hide()
end })
end
---------------------------------------------------------------------------------------------------
function MessageBox.Show(text, func)
assert(Check.Str(text))
assert(Check.Func(func))
MessageBox.func = func
MessageBox.messageText:SetText(text)
MessageBox.panel:Show()
end
---------------------------------------------------------------------------------------------------
function MessageBox.Hide()
MessageBox.panel:Hide()
end
---------------------------------------------------------------------------------------------------
return {
Init = MessageBox.Init,
Show = MessageBox.Show,
Hide = MessageBox.Hide,
}