tibia-client/modules/mainmenu/entergame.lua

86 lines
2.9 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()
2011-08-26 20:44:18 +02:00
else
displayErrorBox('Error', 'You must select a character to login!')
2011-08-26 20:00:22 +02:00
end
end
2011-08-26 20:44:18 +02:00
local function showMotd(motdNumber, motdMessage)
if motdNumber ~= Configs.get("motd") then
displayInfoBox("Message of the day", motdMessage)
Configs.set("motd", motdNumber)
end
end
local function createCharactersWindow(characters, premDays)
local charactersWindow = UI.loadAndDisplayLocked('/mainmenu/ui/charlist.otui')
local charactersList = charactersWindow:getChildById('charactersList')
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
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
if premDays > 0 then
accountStatusLabel:setText("Account Status:\nPremium Account (" .. premDays .. ' days left)')
end
end
2011-08-26 20:00:22 +02:00
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()
2011-08-26 20:44:18 +02:00
UI.loadAndDisplayLocked('/mainmenu/ui/entergamewindow.otui')
2011-07-17 08:56:57 +02:00
end
2011-08-26 20:44:18 +02:00
local loadBox = displayCancelBox('Please wait', 'Connecting to login server...')
2011-07-17 08:56:57 +02:00
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()
2011-08-26 20:44:18 +02:00
local errorBox = displayErrorBox('Login Error', error)
2011-07-17 08:56:57 +02:00
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"))
2011-08-26 20:44:18 +02:00
local motdMessage = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
showMotd(motdNumber, motdMessage)
2011-08-26 20:00:22 +02:00
end
protocolLogin.onCharacterList = function(protocol, characters, premDays)
loadBox:destroy()
2011-08-26 20:44:18 +02:00
createCharactersWindow(characters, premDays)
2011-07-17 08:56:57 +02:00
end
2011-08-26 20:44:18 +02:00
local enterGameWindow = UI.root:getChildById('enterGameWindow')
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