2011-08-29 16:14:21 +02:00
|
|
|
CharacterList = { }
|
|
|
|
|
|
|
|
-- private variables
|
|
|
|
local charactersWindow
|
|
|
|
local loadBox
|
|
|
|
local characterList
|
|
|
|
|
|
|
|
-- private functions
|
2012-02-06 13:53:28 +01:00
|
|
|
local function onCharactersWindowKeyPress(self, keyCode, keyboardModifiers)
|
2011-08-29 16:14:21 +02:00
|
|
|
if keyboardModifiers == KeyboardNoModifier then
|
2012-01-13 21:37:44 +01:00
|
|
|
if keyCode == KeyUp then
|
2012-02-06 13:53:28 +01:00
|
|
|
characterList:focusPreviousChild(KeyboardFocusReason)
|
2012-01-11 00:13:38 +01:00
|
|
|
return true
|
2012-01-13 21:37:44 +01:00
|
|
|
elseif keyCode == KeyDown or keyCode == KeyTab then
|
2012-02-06 13:53:28 +01:00
|
|
|
characterList:focusNextChild(KeyboardFocusReason)
|
2012-01-11 00:13:38 +01:00
|
|
|
return true
|
2011-08-29 16:14:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2011-08-30 01:20:30 +02:00
|
|
|
local function tryLogin(charInfo, tries)
|
|
|
|
tries = tries or 1
|
|
|
|
|
|
|
|
if tries > 4 then
|
|
|
|
CharacterList.destroyLoadBox()
|
|
|
|
displayErrorBox('Error', 'Could not logout.')
|
|
|
|
return
|
|
|
|
end
|
2011-08-29 20:38:01 +02:00
|
|
|
|
|
|
|
if Game.isOnline() then
|
2011-08-30 01:20:30 +02:00
|
|
|
Game.logout(false)
|
|
|
|
if tries == 1 then
|
|
|
|
loadBox = displayCancelBox('Please wait', 'Loggin out...')
|
|
|
|
end
|
|
|
|
scheduleEvent(function() tryLogin(charInfo, tries+1) end, 250)
|
2011-08-29 20:38:01 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2011-08-30 01:20:30 +02:00
|
|
|
CharacterList.destroyLoadBox()
|
|
|
|
|
2011-08-29 20:38:01 +02:00
|
|
|
Game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName)
|
|
|
|
|
|
|
|
loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
|
2012-02-06 20:19:47 +01:00
|
|
|
connect(loadBox, { onCancel = function()
|
|
|
|
loadBox = nil
|
|
|
|
Game.cancelLogin()
|
|
|
|
CharacterList.show()
|
|
|
|
end })
|
2011-08-29 20:38:01 +02:00
|
|
|
|
|
|
|
-- save last used character
|
2012-01-06 10:35:48 +01:00
|
|
|
Settings.set('lastUsedCharacter', charInfo.characterName)
|
2011-08-29 20:38:01 +02:00
|
|
|
end
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
-- public functions
|
2012-02-05 23:42:35 +01:00
|
|
|
function CharacterList.terminate()
|
|
|
|
characterList = nil
|
|
|
|
if charactersWindow then
|
|
|
|
charactersWindow:destroy()
|
|
|
|
charactersWindow = nil
|
|
|
|
end
|
|
|
|
if loadBox then
|
|
|
|
loadBox:destroy()
|
|
|
|
loadBox = nil
|
|
|
|
end
|
2012-02-07 01:41:53 +01:00
|
|
|
CharacterList = nil
|
2012-02-05 23:42:35 +01:00
|
|
|
end
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
function CharacterList.create(characters, premDays)
|
|
|
|
if charactersWindow then
|
|
|
|
charactersWindow:destroy()
|
|
|
|
end
|
|
|
|
|
2012-01-03 01:42:53 +01:00
|
|
|
charactersWindow = displayUI('characterlist.otui')
|
2011-08-29 16:14:21 +02:00
|
|
|
characterList = charactersWindow:getChildById('characterList')
|
|
|
|
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
|
2012-01-11 00:13:38 +01:00
|
|
|
connect(charactersWindow, {onKeyPress = onCharactersWindowKeyPress })
|
2011-08-29 16:14:21 +02:00
|
|
|
|
2011-12-09 16:01:04 +01:00
|
|
|
local focusLabel
|
2011-08-29 16:14:21 +02:00
|
|
|
for i,characterInfo in ipairs(characters) do
|
|
|
|
local characterName = characterInfo[1]
|
|
|
|
local worldName = characterInfo[2]
|
|
|
|
local worldHost = characterInfo[3]
|
|
|
|
local worldIp = characterInfo[4]
|
|
|
|
|
2012-01-03 01:42:53 +01:00
|
|
|
local label = createWidget('CharacterListLabel', characterList)
|
2011-08-29 16:14:21 +02:00
|
|
|
label:setText(characterName .. ' (' .. worldName .. ')')
|
2012-02-03 07:20:58 +01:00
|
|
|
label:setPhantom(false)
|
2011-08-29 16:14:21 +02:00
|
|
|
label.characterName = characterName
|
|
|
|
label.worldHost = worldHost
|
|
|
|
label.worldPort = worldIp
|
2012-02-05 23:42:35 +01:00
|
|
|
|
2012-02-04 18:04:44 +01:00
|
|
|
connect(label, { onDoubleClick = function () CharacterList.doLogin() return true end } )
|
2011-08-29 16:14:21 +02:00
|
|
|
|
2012-01-06 10:35:48 +01:00
|
|
|
if i == 1 or Settings.get('lastUsedCharacter') == characterName then
|
2011-12-09 16:01:04 +01:00
|
|
|
focusLabel = label
|
2011-08-29 16:14:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-09 16:01:04 +01:00
|
|
|
characterList:focusChild(focusLabel, ActiveFocusReason)
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
if premDays > 0 then
|
|
|
|
accountStatusLabel:setText("Account Status:\nPremium Account (" .. premDays .. ' days left)')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function CharacterList.hide()
|
|
|
|
charactersWindow:hide()
|
|
|
|
end
|
|
|
|
|
2011-11-02 04:02:56 +01:00
|
|
|
function CharacterList.destroy()
|
2011-11-02 02:55:36 +01:00
|
|
|
CharacterList.hide()
|
2011-11-03 11:10:39 +01:00
|
|
|
if not Game.isOnline() then
|
2011-11-03 10:59:11 +01:00
|
|
|
EnterGame.show()
|
|
|
|
end
|
2011-11-02 02:55:36 +01:00
|
|
|
end
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
function CharacterList.show()
|
2011-08-30 01:20:30 +02:00
|
|
|
if not loadBox then
|
|
|
|
charactersWindow:show()
|
2011-11-03 10:59:11 +01:00
|
|
|
charactersWindow:focus()
|
2011-08-30 01:20:30 +02:00
|
|
|
end
|
2011-08-29 16:14:21 +02:00
|
|
|
end
|
|
|
|
|
2012-01-07 01:08:08 +01:00
|
|
|
function CharacterList.isVisible()
|
|
|
|
if charactersWindow and charactersWindow:isVisible() then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
function CharacterList.doLogin()
|
|
|
|
local selected = charactersWindow:getChildById('characterList'):getFocusedChild()
|
|
|
|
if selected then
|
2011-08-29 20:38:01 +02:00
|
|
|
local charInfo = { worldHost = selected.worldHost,
|
|
|
|
worldPort = selected.worldPort,
|
|
|
|
characterName = selected.characterName }
|
2011-08-30 01:20:30 +02:00
|
|
|
CharacterList.hide()
|
2011-08-29 20:38:01 +02:00
|
|
|
tryLogin(charInfo)
|
2011-08-29 16:14:21 +02:00
|
|
|
else
|
|
|
|
displayErrorBox('Error', 'You must select a character to login!')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function CharacterList.destroyLoadBox()
|
|
|
|
if loadBox then
|
|
|
|
loadBox:destroy()
|
|
|
|
loadBox = nil
|
|
|
|
end
|
|
|
|
end
|