new script engine, and things maybe be bugged for a while

This commit is contained in:
Eduardo Bart
2011-07-26 20:13:27 -03:00
parent ab7394f357
commit 70f0b0dace
137 changed files with 2905 additions and 2578 deletions

View File

@@ -1,4 +0,0 @@
-- some aliases
loadUI = UI.load
rootUI = UI.getRootContainer()

View File

@@ -3,6 +3,6 @@ AnchorNone = 0
AnchorTop = 1
AnchorBottom = 2
AnchorLeft = 3
AnchorRight = 4
AnchorRight = 4
AnchorVerticalCenter = 5
AnchorHorizontalCenter = 6

View File

@@ -1,4 +1,3 @@
require 'aliases'
require 'enums'
require 'constants'
require 'util'
require 'messagebox'

View File

@@ -0,0 +1,92 @@
MessageBox = {}
MessageBox.__index = MessageBox
-- messagebox flags
MessageBoxOk = 1
MessageBoxCancel = 2
function MessageBox.create(title, text, flags)
local box = {}
setmetatable(box, MessageBox)
-- create messagebox window
local window = UIWindow.create()
id = "messageBoxWindow"
window.title = title
window:centerIn(rootUI)
window:setLocked(true)
rootUI:addChild(window)
-- create messagebox label
local label = UILabel.create()
id = "messageBoxLabel"
label.text = text
label:addAnchor(AnchorHorizontalCenter, window.id, AnchorHorizontalCenter)
label:addAnchor(AnchorTop, window.id, AnchorTop)
--label:setMargin(27, 0)
window:addChild(label)
-- 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()
id = "messageBoxButton1"
button1:addAnchor(AnchorBottom, window.id, AnchorBottom)
button1:addAnchor(AnchorRight, window.id, AnchorRight)
--button1:setMargin(10)
button1.width = 64
window:addChild(button1)
if flags == MessageBoxOk then
button1.text = "Ok"
box.onOk = createEmptyFunction()
button1.onClick = function()
box.onOk()
box:destroy()
end
elseif flags == MessageBoxCancel then
button1.text = "Cancel"
box.onCancel = createEmptyFunction()
button1.onClick = function()
box.onCancel()
box:destroy()
end
end
box.window = window
return box
end
function MessageBox:destroy()
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)
end
function displayCancelBox(title, text)
return MessageBox.create(title, text, MessageBoxCancel)
end

View File

@@ -1,8 +0,0 @@
title: Core
notes: Core utilities used by other modules
author: edubart
version: 1
website: https://github.com/edubart/otclient
enabled: true
script: core.lua