2012-04-26 17:11:03 +02:00
|
|
|
if not UIWindow then dofile 'uiwindow' end
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
-- @docclass
|
2012-01-15 16:13:22 +01:00
|
|
|
UIMessageBox = extends(UIWindow)
|
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
MessageBoxOk = 1
|
|
|
|
MessageBoxCancel = 2
|
|
|
|
|
|
|
|
-- messagebox cannot be created from otui files
|
|
|
|
UIMessageBox.create = nil
|
|
|
|
|
|
|
|
function UIMessageBox.display(title, message, flags)
|
2012-01-15 16:13:22 +01:00
|
|
|
local messagebox = UIMessageBox.internalCreate()
|
2012-02-06 20:19:47 +01:00
|
|
|
rootWidget:addChild(messagebox)
|
2012-01-15 16:13:22 +01:00
|
|
|
|
2012-08-06 21:15:20 +02:00
|
|
|
messagebox:setStyle('MainWindow')
|
2012-01-15 16:13:22 +01:00
|
|
|
messagebox:setText(title)
|
|
|
|
|
2012-06-26 00:13:30 +02:00
|
|
|
local messageLabel = g_ui.createWidget('MessageBoxLabel', messagebox)
|
2012-02-06 20:19:47 +01:00
|
|
|
messageLabel:setText(message)
|
|
|
|
messageLabel:resizeToText()
|
|
|
|
|
|
|
|
-- setup messagebox first button
|
2012-06-26 00:13:30 +02:00
|
|
|
local buttonRight = g_ui.createWidget('MessageBoxRightButton', messagebox)
|
2012-02-06 20:19:47 +01:00
|
|
|
|
|
|
|
if flags == MessageBoxOk then
|
|
|
|
buttonRight:setText('Ok')
|
|
|
|
connect(buttonRight, { onClick = function(self) self:getParent():ok() end })
|
2012-02-08 03:11:57 +01:00
|
|
|
connect(messagebox, { onEnter = function(self) self:ok() end })
|
|
|
|
connect(messagebox, { onEscape = function(self) self:ok() end })
|
2012-02-06 20:19:47 +01:00
|
|
|
elseif flags == MessageBoxCancel then
|
|
|
|
buttonRight:setText('Cancel')
|
|
|
|
connect(buttonRight, { onClick = function(self) self:getParent():cancel() end })
|
2012-02-08 03:11:57 +01:00
|
|
|
connect(messagebox, { onEnter = function(self) self:cancel() end })
|
|
|
|
connect(messagebox, { onEscape = function(self) self:cancel() end })
|
2012-02-06 20:19:47 +01:00
|
|
|
end
|
|
|
|
|
2012-08-08 04:18:36 +02:00
|
|
|
messagebox:setWidth(math.max(messageLabel:getWidth(), messagebox:getTextSize().width) + messagebox:getPaddingLeft() + messagebox:getPaddingRight())
|
2012-08-06 21:15:20 +02:00
|
|
|
messagebox:setHeight(messageLabel:getHeight() + messagebox:getPaddingTop() + messagebox:getPaddingBottom() + buttonRight:getHeight() + 10)
|
|
|
|
|
2012-07-16 21:35:14 +02:00
|
|
|
--messagebox:lock()
|
2012-01-15 16:13:22 +01:00
|
|
|
|
|
|
|
return messagebox
|
|
|
|
end
|
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
function displayInfoBox(title, message)
|
|
|
|
return UIMessageBox.display(title, message, MessageBoxOk)
|
|
|
|
end
|
|
|
|
|
|
|
|
function displayErrorBox(title, message)
|
|
|
|
return UIMessageBox.display(title, message, MessageBoxOk)
|
|
|
|
end
|
|
|
|
|
|
|
|
function displayCancelBox(title, message)
|
|
|
|
return UIMessageBox.display(title, message, MessageBoxCancel)
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIMessageBox:ok()
|
|
|
|
signalcall(self.onOk, self)
|
|
|
|
self.onOk = nil
|
|
|
|
self:destroy()
|
2012-01-15 16:13:22 +01:00
|
|
|
end
|
|
|
|
|
2012-02-06 20:19:47 +01:00
|
|
|
function UIMessageBox:cancel()
|
|
|
|
signalcall(self.onCancel, self)
|
|
|
|
self.onCancel = nil
|
|
|
|
self:destroy()
|
2012-01-15 16:13:22 +01:00
|
|
|
end
|