tibia-client/modules/core_lib/widgets/uimessagebox.lua

66 lines
1.9 KiB
Lua
Raw Normal View History

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)
local messagebox = UIMessageBox.internalCreate()
2012-02-06 20:19:47 +01:00
rootWidget:addChild(messagebox)
2012-02-06 20:19:47 +01:00
messagebox:setStyle('MessageBoxWindow')
messagebox:setText(title)
2012-02-06 20:19:47 +01:00
local messageLabel = createWidget('MessageBoxLabel', messagebox)
messageLabel:setText(message)
messageLabel:resizeToText()
messagebox:setWidth(math.max(messageLabel:getWidth() + 48, messagebox:getWidth()))
messagebox:setHeight(math.max(messageLabel:getHeight() + 64, messagebox:getHeight()))
-- setup messagebox first button
local buttonRight = createWidget('MessageBoxRightButton', messagebox)
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
messagebox:lock()
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()
end
2012-02-06 20:19:47 +01:00
function UIMessageBox:cancel()
signalcall(self.onCancel, self)
self.onCancel = nil
self:destroy()
end