tibia-client/modules/mainmenu/entergame.lua

73 lines
2.4 KiB
Lua
Raw Normal View History

2011-08-26 20:00:22 +02:00
local account
local password
function EnterGame_characterWindow_okClicked()
local charactersWindow = UI.root:getChildById('charactersWindow')
local selected = charactersWindow:getChildById('charactersList'):getFocusedChild()
if selected then
Game.loginWorld(account, password, selected.worldHost, selected.worldPort, selected.characterName)
charactersWindow:destroy()
mainMenu:hide()
end
end
2011-07-17 08:56:57 +02:00
function EnterGame_connectToLoginServer()
local protocolLogin = ProtocolLogin.create()
2011-07-17 08:56:57 +02:00
local recreateEnterGame = function()
UI.loadAndDisplayLocked("/mainmenu/ui/entergamewindow.otui")
2011-07-17 08:56:57 +02:00
end
local loadBox = displayCancelBox("Please wait", "Connecting..")
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-08-16 06:24:20 +02:00
protocolLogin:cancelLogin()
2011-07-17 08:56:57 +02:00
recreateEnterGame()
end
protocolLogin.onError = function(protocol, error)
2011-07-17 08:56:57 +02:00
loadBox:destroy()
local errorBox = displayErrorBox("Login Error", error)
errorBox.onOk = recreateEnterGame
end
protocolLogin.onMotd = function(protocol, motd)
2011-07-17 08:56:57 +02:00
loadBox:destroy()
local motdNumber = string.sub(motd, 0, string.find(motd, "\n"))
local motdText = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
if motdNumber ~= Configs.get("motd") then
displayInfoBox("Message of the day", motdText)
Configs.set("motd", motdNumber)
end
2011-08-26 20:00:22 +02:00
end
protocolLogin.onCharacterList = function(protocol, characters, premDays)
loadBox:destroy()
local charactersWindow = UI.loadAndDisplayLocked('/mainmenu/ui/charlist.otui')
local charactersList = charactersWindow:getChildById('charactersList')
for i,characterInfo in ipairs(characters) do
local characterName = characterInfo[1]
local worldName = characterInfo[2]
local worldHost = characterInfo[3]
local worldIp = characterInfo[4]
local label = UILabel.create()
charactersList:addChild(label)
label:setText(characterName .. ' (' .. worldName .. ')')
label:setStyle('CharactersListLabel')
label.characterName = characterName
label.worldHost = worldHost
label.worldPort = worldIp
end
2011-07-17 08:56:57 +02:00
end
local enterGameWindow = UI.root:getChildById("enterGameWindow")
2011-08-26 20:00:22 +02:00
account = enterGameWindow:getChildById("accountNameLineEdit"):getText()
password = enterGameWindow:getChildById("accountPasswordLineEdit"):getText()
2011-07-17 08:56:57 +02:00
protocolLogin:login(account, password)
enterGameWindow:destroy()
end