2011-05-31 03:55:34 +02:00
|
|
|
MessageBox = {}
|
|
|
|
MessageBox.__index = MessageBox
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
-- messagebox flags
|
|
|
|
MessageBoxOk = 1
|
|
|
|
MessageBoxCancel = 2
|
|
|
|
|
|
|
|
function MessageBox.create(title, text, flags)
|
|
|
|
local box = {}
|
|
|
|
setmetatable(box, MessageBox)
|
|
|
|
|
|
|
|
-- create messagebox window
|
2011-07-27 01:13:27 +02:00
|
|
|
local window = UIWindow.create()
|
|
|
|
id = "messageBoxWindow"
|
2011-07-17 08:56:57 +02:00
|
|
|
window.title = title
|
|
|
|
window:centerIn(rootUI)
|
2011-07-27 01:13:27 +02:00
|
|
|
window:setLocked(true)
|
|
|
|
rootUI:addChild(window)
|
2011-07-17 08:56:57 +02:00
|
|
|
|
|
|
|
-- create messagebox label
|
2011-07-27 01:13:27 +02:00
|
|
|
local label = UILabel.create()
|
|
|
|
id = "messageBoxLabel"
|
2011-07-17 08:56:57 +02:00
|
|
|
label.text = text
|
2011-07-27 01:13:27 +02:00
|
|
|
label:addAnchor(AnchorHorizontalCenter, window.id, AnchorHorizontalCenter)
|
|
|
|
label:addAnchor(AnchorTop, window.id, AnchorTop)
|
|
|
|
--label:setMargin(27, 0)
|
|
|
|
window:addChild(label)
|
2011-07-17 08:56:57 +02:00
|
|
|
|
|
|
|
-- set window size based on label size
|
|
|
|
window.width = label.width + 40
|
|
|
|
window.height = label.height + 64
|
|
|
|
|
|
|
|
-- setup messagebox first button
|
|
|
|
local buttonText
|
2011-07-27 01:13:27 +02:00
|
|
|
local button1 = UIButton.new()
|
|
|
|
id = "messageBoxButton1"
|
|
|
|
button1:addAnchor(AnchorBottom, window.id, AnchorBottom)
|
|
|
|
button1:addAnchor(AnchorRight, window.id, AnchorRight)
|
|
|
|
--button1:setMargin(10)
|
|
|
|
button1.width = 64
|
|
|
|
window:addChild(button1)
|
2011-07-17 08:56:57 +02:00
|
|
|
|
|
|
|
if flags == MessageBoxOk then
|
2011-07-27 01:13:27 +02:00
|
|
|
button1.text = "Ok"
|
2011-07-17 08:56:57 +02:00
|
|
|
box.onOk = createEmptyFunction()
|
|
|
|
button1.onClick = function()
|
|
|
|
box.onOk()
|
|
|
|
box:destroy()
|
|
|
|
end
|
|
|
|
elseif flags == MessageBoxCancel then
|
2011-07-27 01:13:27 +02:00
|
|
|
button1.text = "Cancel"
|
2011-07-17 08:56:57 +02:00
|
|
|
box.onCancel = createEmptyFunction()
|
|
|
|
button1.onClick = function()
|
|
|
|
box.onCancel()
|
|
|
|
box:destroy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
box.window = window
|
|
|
|
return box
|
2011-05-31 03:55:34 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function MessageBox:destroy()
|
2011-07-17 08:56:57 +02:00
|
|
|
if self.onDestroy then
|
|
|
|
self.onDestroy()
|
|
|
|
self.onDestroy = nil
|
|
|
|
end
|
|
|
|
if self.window then
|
|
|
|
self.window:destroy()
|
|
|
|
self.window = nil
|
|
|
|
end
|
|
|
|
self.onOk = nil
|
|
|
|
self.onCancel = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
-- shortcuts for creating message boxes
|
|
|
|
function displayMessageBox(title, text, flags)
|
|
|
|
return MessageBox.create(title, text, flags)
|
|
|
|
end
|
|
|
|
|
|
|
|
function displayErrorBox(title, text)
|
|
|
|
return MessageBox.create(title, text, MessageBoxOk)
|
|
|
|
end
|
|
|
|
|
|
|
|
function displayInfoBox(title, text)
|
|
|
|
return MessageBox.create(title, text, MessageBoxOk)
|
2011-05-03 00:48:41 +02:00
|
|
|
end
|
|
|
|
|
2011-07-17 08:56:57 +02:00
|
|
|
function displayCancelBox(title, text)
|
|
|
|
return MessageBox.create(title, text, MessageBoxCancel)
|
2011-05-01 20:47:35 +02:00
|
|
|
end
|
2011-07-17 08:56:57 +02:00
|
|
|
|