rework ui related scripting stuff

This commit is contained in:
Eduardo Bart
2011-07-17 03:56:57 -03:00
parent 571801ae39
commit bddcfb08fd
46 changed files with 740 additions and 507 deletions

View File

@@ -1,34 +1,86 @@
MessageBox = {}
MessageBox.__index = MessageBox
function MessageBox.create(title, text)
local msgBox = {}
setmetatable(msgBox, MessageBox)
-- messagebox flags
MessageBoxOk = 1
MessageBoxCancel = 2
local window = UI.load("messagebox.yml")
window.locked = true
window.title = title
window:child("textLabel").text = text
window:child("okButton").onClick = function()
self.parent:destroy()
end
window.onDestroy = function()
if msgBox.onDestroy then
msgBox.onDestroy()
end
end
function MessageBox.create(title, text, flags)
local box = {}
setmetatable(box, MessageBox)
msgBox.window = window
return msgBox
-- create messagebox window
local window = UIWindow.new("messageBoxWindow", rootUI)
window.title = title
window:centerIn(rootUI)
window:setLocked()
-- create messagebox label
local label = UILabel.new("messageBoxLabel", window)
label.text = text
label:addAnchor(AnchorHorizontalCenter, window, AnchorHorizontalCenter)
label:addAnchor(AnchorTop, window, AnchorTop)
label:setMargin(27, 0)
-- set window size based on label size
window.width = label.width + 40
window.height = label.height + 64
-- setup messagebox first button
local buttonText
local button1 = UIButton.new("messageBoxButton1", window)
button1:addAnchor(AnchorBottom, window, AnchorBottom)
button1:addAnchor(AnchorRight, window, AnchorRight)
button1:setMargin(10)
if flags == MessageBoxOk then
buttonText = "Ok"
box.onOk = createEmptyFunction()
button1.onClick = function()
box.onOk()
box:destroy()
end
elseif flags == MessageBoxCancel then
buttonText = "Cancel"
box.onCancel = createEmptyFunction()
button1.onClick = function()
box.onCancel()
box:destroy()
end
end
button1.text = buttonText
box.window = window
return box
end
function MessageBox:destroy()
if self.window then
self.window:destroy()
self.window = nil
end
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
function messageBox(title, text)
return MessageBox.create(title, text)
-- 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)
end
function displayCancelBox(title, text)
return MessageBox.create(title, text, MessageBoxCancel)
end

View File

@@ -1,18 +0,0 @@
%window#messageBoxWindow
size: [192, 78]
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
%label#textLabel
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
margin.top: 27
%button#okButton
text: Ok
size: [43, 20]
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 10
margin.right: 10

View File

@@ -0,0 +1,8 @@
title: Message box
notes: Functions for creating message boxes
author: edubart
version: 1
website: https://github.com/edubart/otclient
enabled: true
script: messagebox.lua