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

@@ -0,0 +1,57 @@
function EnterGame_connectToLoginServer()
-- create login protocol
local protocolLogin = ProtocolLogin.new()
-- used to recreate enter game window
local recreateEnterGame = function()
loadUI("ui/entergamewindow")
end
-- display loading message box
local loadBox = displayCancelBox("Please wait", "Connecting..")
-- cancel loading callback
loadBox.onCancel = function()
-- cancel protocol and reacreate enter game window
protocolLogin:cancel()
recreateEnterGame()
end
-- error callback
protocolLogin.onError = function(error)
-- destroy loading message box
loadBox:destroy()
-- display error message
local errorBox = displayErrorBox("Login Error", error)
-- cancel protocol and reacreate enter game window
self.cancel()
errorBox.onOk = recreateEnterGame
end
-- motd callback
protocolLogin.onMotd = function(motd)
-- destroy loading message box
loadBox:destroy()
-- display motd
local motdNumber = string.sub(motd, 0, string.find(motd, "\n"))
local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
local motdBox = displayInfoBox("Message of the day", motdText)
-- cancel protocol and reacreate enter game window
self.cancel()
motdBox.onOk = recreateEnterGame
end
-- get account and password and login
local enterGameWindow = rootUI:child("enterGameWindow")
local account = enterGameWindow:child("accountNameTextEdit").text
local password = enterGameWindow:child("passwordTextEdit").text
protocolLogin:login(account, password)
-- destroy enter game window
enterGameWindow:destroy()
end

View File

@@ -0,0 +1,16 @@
require 'entergame'
function initializeApplication()
mainMenu = loadUI("ui/mainmenu")
end
function terminateApplication()
App.exit()
end
-- here is where everything starts
if not initialized then
initializeApplication()
App.onClose = terminateApplication
initialized = true
end

View File

@@ -1,63 +0,0 @@
-- menu state
function onEnterMenuState()
mainMenu = UI.load("mainmenu.yml")
end
function onLeaveMenuState()
end
function onApplicationClose()
onLeaveMenuState()
App.exit()
end
function enterGame_onOkClicked()
local enterGameWindow = UI.getRootContainer():child("enterGameWindow")
enterGameWindow.visible = false
local loadMessageBox = messageBox("Please wait", "Connecting..")
loadMessageBox.onDestroy = function()
--TODO: cancel protocol
enterGameWindow.visible = true
protocolLogin = nil
end
protocolLogin = ProtocolLogin.new()
protocolLogin.onError = function(error)
loadMessageBox.onDestroy = nil
loadMessageBox:destroy()
local msgBox = messageBox("Login Error", error)
msgBox.onDestroy = function()
enterGameWindow.visible = true
end
protocolLogin = nil
end
protocolLogin.onMotd = function(motd)
loadMessageBox.onDestroy = nil
loadMessageBox:destroy()
local motdNumber = string.sub(motd, 0, string.find(motd, "\n"))
local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
local msgBox = messageBox("Message of the day", motdText)
msgBox.onDestroy = function()
enterGameWindow.visible = true
end
protocolLogin = nil
end
local account = enterGameWindow:child("accountNameTextEdit").text
local password = enterGameWindow:child("passwordTextEdit").text
account = "tibialua0"
password = "lua123456"
protocolLogin:login(account, password)
end
-- here is where everything starts
if not initialStateLoaded then
onEnterMenuState()
App.onClose = onApplicationClose
initialStateLoaded = true
end

View File

@@ -3,7 +3,7 @@
size: [236, 178]
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
onLoad: self.locked = true
onLoad: self:setLocked()
%label#accountNameLabel
text: Account name
@@ -34,7 +34,7 @@
anchors.top: parent.top
margin.top: 94
margin.left: 132
onClick: messageBox("Error", "Not implemented yet")
onClick: displayErrorBox("Error", "Not implemented yet")
%button#okButton
text: Ok
@@ -43,7 +43,7 @@
anchors.bottom: parent.bottom
margin.bottom: 10
margin.right: 66
onClick: enterGame_onOkClicked()
onClick: EnterGame_connectToLoginServer()
%button#cancelButton
text: Cancel

View File

@@ -5,22 +5,6 @@
anchors.top: parent.top
anchors.bottom: parent.bottom
%panel#icos4d
skin:
image: /skins/lightness/mouse.png
anchors.left: parent.left
anchors.top: parent.top
margin.left: -2
margin.top: 70
%panel#mouse
skin:
image: /skins/lightness/icos4d.png
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.left: 60
margin.top: 70
%panel#mainMenu
skin: roundedGridPanel
size: [117, 171]
@@ -34,32 +18,32 @@
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 16
onClick: UI.load("entergamewindow.yml")
onClick: UI.load("entergamewindow")
%button#accessAccountButton
text: Access Account
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 46
onClick: messageBox("Error", "Not implemented yet")
onClick: displayErrorBox("Error", "Not implemented yet")
%button#optionsButton
text: Options
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 76
onClick: UI.load("optionswindow.yml")
onClick: UI.load("optionswindow")
%button#infoButton
text: Info
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 106
onClick: UI.load("infowindow.yml")
onClick: UI.load("infowindow")
%button#exitGameButton
text: Exit
anchors.top: parent.top
anchors.horizontalCenter: parent.horizontalCenter
margin.top: 136
onClick: onApplicationClose()
onClick: terminateApplication()