2011-04-22 15:49:46 +02:00
|
|
|
-- menu state
|
|
|
|
function onEnterMenuState()
|
2011-05-19 19:11:05 +02:00
|
|
|
mainMenu = UI.load("mainmenu.yml")
|
2011-04-22 15:49:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function onLeaveMenuState()
|
2011-05-09 22:38:01 +02:00
|
|
|
|
2011-04-22 15:49:46 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function onApplicationClose()
|
|
|
|
onLeaveMenuState()
|
2011-05-02 06:13:57 +02:00
|
|
|
App.exit()
|
2011-04-22 15:49:46 +02:00
|
|
|
end
|
|
|
|
|
2011-05-31 03:55:34 +02:00
|
|
|
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()
|
2011-05-31 07:24:30 +02:00
|
|
|
|
|
|
|
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)
|
2011-05-31 03:55:34 +02:00
|
|
|
msgBox.onDestroy = function()
|
|
|
|
enterGameWindow.visible = true
|
|
|
|
end
|
|
|
|
protocolLogin = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
local account = enterGameWindow:child("accountNameTextEdit").text
|
|
|
|
local password = enterGameWindow:child("passwordTextEdit").text
|
2011-05-31 07:24:30 +02:00
|
|
|
account = "tibialua0"
|
|
|
|
password = "lua123456"
|
2011-05-31 03:55:34 +02:00
|
|
|
|
|
|
|
protocolLogin:login(account, password)
|
|
|
|
end
|
|
|
|
|
2011-04-22 15:49:46 +02:00
|
|
|
-- here is where everything starts
|
|
|
|
if not initialStateLoaded then
|
|
|
|
onEnterMenuState()
|
2011-05-03 00:48:41 +02:00
|
|
|
App.onClose = onApplicationClose
|
2011-04-22 15:49:46 +02:00
|
|
|
initialStateLoaded = true
|
2011-05-01 20:47:35 +02:00
|
|
|
end
|