mirror of
https://github.com/edubart/otclient.git
synced 2025-11-30 15:26:49 +01:00
login/logout/ctrl+g working correctly
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
-- private variables
|
||||
local showCharacterListOnLogout = true
|
||||
|
||||
-- private functions
|
||||
local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
||||
if keyboardModifiers == KeyboardCtrlModifier then
|
||||
@@ -22,14 +25,28 @@ local function destroyMainInterface()
|
||||
end
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function Game.onLogin()
|
||||
MainMenu.hide()
|
||||
CharacterList.destroyLoadBox()
|
||||
createMainInterface()
|
||||
end
|
||||
|
||||
function Game.onConnectionError(message)
|
||||
CharacterList.destroyLoadBox()
|
||||
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
|
||||
errorBox.onOk = CharacterList.show
|
||||
showCharacterListOnLogout = false
|
||||
end
|
||||
|
||||
function Game.onLogout()
|
||||
MainMenu.show()
|
||||
CharacterList.show()
|
||||
|
||||
if showCharacterListOnLogout then
|
||||
CharacterList.show()
|
||||
else
|
||||
showCharacterListOnLogout = true
|
||||
end
|
||||
|
||||
destroyMainInterface()
|
||||
end
|
||||
|
||||
@@ -17,6 +17,27 @@ local function onCharactersWindowKeyPress(self, keyCode, keyChar, keyboardModifi
|
||||
return false
|
||||
end
|
||||
|
||||
local function tryLogin(charInfo)
|
||||
CharacterList.hide()
|
||||
|
||||
if Game.isOnline() then
|
||||
Game.logout()
|
||||
scheduleEvent(function() tryLogin(charInfo) end, 250)
|
||||
return
|
||||
end
|
||||
|
||||
Game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName)
|
||||
|
||||
loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
|
||||
function loadBox.onCancel()
|
||||
Game.cancelLogin()
|
||||
CharacterList.show()
|
||||
end
|
||||
|
||||
-- save last used character
|
||||
Configs.set('lastUsedCharacter', charInfo.characterName)
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function CharacterList.create(characters, premDays)
|
||||
if charactersWindow then
|
||||
@@ -65,21 +86,10 @@ end
|
||||
function CharacterList.doLogin()
|
||||
local selected = charactersWindow:getChildById('characterList'):getFocusedChild()
|
||||
if selected then
|
||||
--if Game.isOnline() then
|
||||
-- Game.logout()
|
||||
--end
|
||||
|
||||
Game.loginWorld(EnterGame.account, EnterGame.password, selected.worldHost, selected.worldPort, selected.characterName)
|
||||
CharacterList.hide()
|
||||
|
||||
loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
|
||||
function loadBox.onCancel()
|
||||
Game.logout()
|
||||
CharacterList.show()
|
||||
end
|
||||
|
||||
-- save last used character
|
||||
Configs.set('lastUsedCharacter', selected.characterName)
|
||||
local charInfo = { worldHost = selected.worldHost,
|
||||
worldPort = selected.worldPort,
|
||||
characterName = selected.characterName }
|
||||
tryLogin(charInfo)
|
||||
else
|
||||
displayErrorBox('Error', 'You must select a character to login!')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user