tibia-client/modules/mainmenu/entergame.lua

56 lines
1.6 KiB
Lua
Raw Normal View History

2011-07-17 08:56:57 +02:00
function EnterGame_connectToLoginServer()
-- create login protocol
local protocolLogin = ProtocolLogin.create()
2011-07-17 08:56:57 +02:00
-- used to recreate enter game window
local recreateEnterGame = function()
2011-08-14 04:09:11 +02:00
loadUI("/mainmenu/ui/entergamewindow.otui")
2011-07-17 08:56:57 +02:00
end
-- display loading message box
local loadBox = displayCancelBox("Please wait", "Connecting..")
-- cancel loading callback
2011-07-27 01:55:39 +02:00
loadBox.onCancel = function(msgbox)
2011-07-17 08:56:57 +02:00
-- cancel protocol and reacreate enter game window
2011-07-27 01:55:39 +02:00
protocolLogin:cancel()
2011-07-17 08:56:57 +02:00
recreateEnterGame()
end
-- error callback
protocolLogin.onError = function(protocol, error)
2011-07-17 08:56:57 +02:00
-- destroy loading message box
loadBox:destroy()
-- display error message
local errorBox = displayErrorBox("Login Error", error)
-- cancel protocol and reacreate enter game window
2011-07-27 01:55:39 +02:00
protocol:cancel()
2011-07-17 08:56:57 +02:00
errorBox.onOk = recreateEnterGame
end
-- motd callback
protocolLogin.onMotd = function(protocol, motd)
2011-07-17 08:56:57 +02:00
-- 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)
2011-08-14 04:09:11 +02:00
-- hide main menu
mainMenu.visible = false
2011-07-17 08:56:57 +02:00
end
-- get account and password then login
2011-08-14 04:09:11 +02:00
local enterGameWindow = rootWidget:getChild("enterGameWindow")
local account = enterGameWindow:getChild("accountNameLineEdit").text
local password = enterGameWindow:getChild("accountPasswordLineEdit").text
2011-07-17 08:56:57 +02:00
protocolLogin:login(account, password)
-- destroy enter game window
enterGameWindow:destroy()
end