tibia-client/modules/client_entergame/entergame.lua

116 lines
3.4 KiB
Lua
Raw Normal View History

EnterGame = { }
2011-08-26 20:00:22 +02:00
-- private variables
local loadBox
2011-11-02 04:02:56 +01:00
local enterGame
2011-11-02 02:55:36 +01:00
local motdNumber
local motdMessage
-- private functions
2011-11-16 22:00:40 +01:00
local function clearAccountFields()
enterGame:getChildById('accountNameLineEdit'):clearText()
enterGame:getChildById('accountPasswordLineEdit'):clearText()
enterGame:getChildById('accountNameLineEdit'):focus()
g_configs.set('account', nil)
g_configs.set('password', nil)
2011-11-16 22:00:40 +01:00
end
local function onError(protocol, error)
loadBox:destroy()
2011-11-16 22:00:40 +01:00
clearAccountFields()
local errorBox = displayErrorBox('Login Error', error)
errorBox.onOk = EnterGame.show
2011-08-26 20:00:22 +02:00
end
local function onMotd(protocol, motd)
2011-12-07 01:31:55 +01:00
motdNumber = tonumber(motd:sub(0, motd:find("\n")))
motdMessage = motd:sub(motd:find("\n") + 1, #motd)
2011-11-16 19:08:42 +01:00
TopMenu.getButton('motdButton'):show()
2011-08-26 20:44:18 +02:00
end
local function onCharacterList(protocol, characters, premDays)
if enterGame:getChildById('rememberPasswordBox'):isChecked() then
g_configs.set('account', EnterGame.account)
g_configs.set('password', EnterGame.password)
g_configs.set('autologin', tostring(enterGame:getChildById('autoLoginBox'):isChecked()))
else
2011-11-16 22:00:40 +01:00
clearAccountFields()
end
2011-11-02 02:55:36 +01:00
loadBox:destroy()
CharacterList.create(characters, premDays)
2011-11-02 02:55:36 +01:00
local lastMotdNumber = tonumber(g_configs.get("motd"))
2011-11-02 02:55:36 +01:00
if motdNumber and motdNumber ~= lastMotdNumber then
g_configs.set("motd", motdNumber)
2011-11-02 02:55:36 +01:00
local motdBox = displayInfoBox("Message of the day", motdMessage)
motdBox.onOk = CharacterList.show
2011-10-31 18:56:00 +01:00
CharacterList.hide()
end
end
-- public functions
2011-11-02 04:02:56 +01:00
function EnterGame.create()
2011-11-17 21:40:31 +01:00
enterGame = UI.display('entergame.otui')
local account = g_configs.get('account')
local password = g_configs.get('password')
local host = g_configs.get('host')
local port = tonumber(g_configs.get('port'))
local autologin = toboolean(g_configs.get('autologin'))
enterGame:getChildById('accountNameLineEdit'):setText(account)
enterGame:getChildById('accountPasswordLineEdit'):setText(password)
enterGame:getChildById('serverHostLineEdit'):setText(host)
enterGame:getChildById('serverPortLineEdit'):setText(port)
enterGame:getChildById('autoLoginBox'):setChecked(autologin)
enterGame:getChildById('rememberPasswordBox'):setChecked(#account > 0)
2011-11-16 22:00:40 +01:00
enterGame:getChildById('accountNameLineEdit'):focus()
if #account > 0 and autologin then
addEvent(EnterGame.doLogin)
end
2011-11-02 02:55:36 +01:00
end
2011-11-02 04:02:56 +01:00
function EnterGame.destroy()
enterGame:destroy()
enterGame = nil
2011-08-26 20:44:18 +02:00
end
2011-08-26 20:00:22 +02:00
2011-11-02 04:02:56 +01:00
function EnterGame.show()
enterGame:show()
enterGame:focus()
2011-11-02 04:02:56 +01:00
end
function EnterGame.hide()
enterGame:hide()
end
2011-07-17 08:56:57 +02:00
function EnterGame.doLogin()
2011-11-02 04:02:56 +01:00
EnterGame.account = enterGame:getChildById('accountNameLineEdit'):getText()
EnterGame.password = enterGame:getChildById('accountPasswordLineEdit'):getText()
EnterGame.host = enterGame:getChildById('serverHostLineEdit'):getText()
EnterGame.port = enterGame:getChildById('serverPortLineEdit'):getText()
2011-11-02 02:55:36 +01:00
EnterGame.hide()
2011-07-17 08:56:57 +02:00
g_configs.set('host', EnterGame.host)
g_configs.set('port', EnterGame.port)
local protocolLogin = ProtocolLogin.create()
protocolLogin.onError = onError
protocolLogin.onMotd = onMotd
protocolLogin.onCharacterList = onCharacterList
2011-07-17 08:56:57 +02:00
loadBox = displayCancelBox('Please wait', 'Connecting to login server...')
2011-07-27 01:55:39 +02:00
loadBox.onCancel = function(msgbox)
2011-08-16 06:24:20 +02:00
protocolLogin:cancelLogin()
2011-11-02 02:55:36 +01:00
EnterGame.show()
2011-07-17 08:56:57 +02:00
end
protocolLogin:login(EnterGame.host, EnterGame.port, EnterGame.account, EnterGame.password)
2011-07-17 08:56:57 +02:00
end
2011-11-16 19:08:42 +01:00
function EnterGame.displayMotd()
displayInfoBox("Message of the day", motdMessage)
end