parent
b859f66952
commit
8b2cb410c2
@ -1,13 +1,35 @@
|
||||
function Game.createMainInterface()
|
||||
-- private functions
|
||||
local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
||||
if keyboardModifiers == KeyboardCtrlModifier then
|
||||
if keyCode == KeyG then
|
||||
CharacterList.show()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function createMainInterface()
|
||||
gameUi = loadUI('/game/ui/gameinterface.otui', UI.root)
|
||||
gameUi.onKeyPress = onGameKeyPress
|
||||
end
|
||||
|
||||
function Game.onLogin()
|
||||
|
||||
local function destroyMainInterface()
|
||||
if gameUi then
|
||||
gameUi:destroy()
|
||||
gameUi = nil
|
||||
end
|
||||
end
|
||||
|
||||
function Game.onLogin()
|
||||
MainMenu.hide()
|
||||
CharacterList.destroyLoadBox()
|
||||
createMainInterface()
|
||||
end
|
||||
|
||||
function Game.onLogout()
|
||||
gameUi:destroy()
|
||||
gameUi = nil
|
||||
mainMenu:show()
|
||||
MainMenu.show()
|
||||
CharacterList.show()
|
||||
destroyMainInterface()
|
||||
end
|
||||
|
@ -0,0 +1,93 @@
|
||||
CharacterList = { }
|
||||
|
||||
-- private variables
|
||||
local charactersWindow
|
||||
local loadBox
|
||||
local characterList
|
||||
|
||||
-- private functions
|
||||
local function onCharactersWindowKeyPress(self, keyCode, keyChar, keyboardModifiers)
|
||||
if keyboardModifiers == KeyboardNoModifier then
|
||||
if keyCode == KeyUp or keyCode == KeyTab then
|
||||
characterList:focusPreviousChild(ActiveFocusReason)
|
||||
elseif keyCode == KeyDown then
|
||||
characterList:focusNextChild(ActiveFocusReason)
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function CharacterList.create(characters, premDays)
|
||||
if charactersWindow then
|
||||
charactersWindow:destroy()
|
||||
end
|
||||
|
||||
charactersWindow = UI.loadAndDisplayLocked('/mainmenu/ui/charlist.otui')
|
||||
characterList = charactersWindow:getChildById('characterList')
|
||||
local accountStatusLabel = charactersWindow:getChildById('accountStatusLabel')
|
||||
charactersWindow.onKeyPress = onCharactersWindowKeyPress
|
||||
|
||||
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()
|
||||
characterList:addChild(label)
|
||||
label:setText(characterName .. ' (' .. worldName .. ')')
|
||||
label:setStyle('CharacterListLabel')
|
||||
label.characterName = characterName
|
||||
label.worldHost = worldHost
|
||||
label.worldPort = worldIp
|
||||
|
||||
if i == 0 or Configs.get('lastUsedCharacter') == characterName then
|
||||
characterList:focusChild(label, ActiveFocusReason)
|
||||
end
|
||||
end
|
||||
|
||||
if premDays > 0 then
|
||||
accountStatusLabel:setText("Account Status:\nPremium Account (" .. premDays .. ' days left)')
|
||||
end
|
||||
end
|
||||
|
||||
function CharacterList.hide()
|
||||
charactersWindow:unlock()
|
||||
charactersWindow:hide()
|
||||
end
|
||||
|
||||
function CharacterList.show()
|
||||
charactersWindow:show()
|
||||
charactersWindow:lock()
|
||||
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)
|
||||
else
|
||||
displayErrorBox('Error', 'You must select a character to login!')
|
||||
end
|
||||
end
|
||||
|
||||
function CharacterList.destroyLoadBox()
|
||||
if loadBox then
|
||||
loadBox:destroy()
|
||||
loadBox = nil
|
||||
end
|
||||
end
|
@ -1,103 +1,56 @@
|
||||
local account
|
||||
local password
|
||||
EnterGame = { }
|
||||
|
||||
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)
|
||||
Configs.set('lastUsedCharacter', selected.characterName)
|
||||
charactersWindow:destroy()
|
||||
mainMenu:hide()
|
||||
Game.createMainInterface()
|
||||
else
|
||||
displayErrorBox('Error', 'You must select a character to login!')
|
||||
end
|
||||
-- private variables
|
||||
local password
|
||||
local loadBox
|
||||
local enterGameWindow
|
||||
|
||||
-- private functions
|
||||
local function onError(protocol, error)
|
||||
loadBox:destroy()
|
||||
local errorBox = displayErrorBox('Login Error', error)
|
||||
errorBox.onOk = EnterGame.create()
|
||||
end
|
||||
|
||||
local function showMotd(motdNumber, motdMessage)
|
||||
local function onMotd(protocol, motd)
|
||||
loadBox:destroy()
|
||||
local motdNumber = string.sub(motd, 0, string.find(motd, "\n"))
|
||||
local motdMessage = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
|
||||
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')
|
||||
|
||||
function charactersWindow:onKeyPress(keyCode, keyChar, keyboardModifiers)
|
||||
if keyboardModifiers == KeyboardNoModifier then
|
||||
if keyCode == KeyUp or keyCode == KeyTab then
|
||||
charactersList:focusPreviousChild(ActiveFocusReason)
|
||||
elseif keyCode == KeyDown then
|
||||
charactersList:focusNextChild(ActiveFocusReason)
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
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
|
||||
local function onCharacterList(protocol, characters, premDays)
|
||||
CharacterList.create(characters, premDays)
|
||||
end
|
||||
|
||||
if i == 0 or Configs.get('lastUsedCharacter') == characterName then
|
||||
charactersList:focusChild(label, ActiveFocusReason)
|
||||
end
|
||||
end
|
||||
if premDays > 0 then
|
||||
accountStatusLabel:setText("Account Status:\nPremium Account (" .. premDays .. ' days left)')
|
||||
end
|
||||
-- public functions
|
||||
function EnterGame.create()
|
||||
enterGameWindow = UI.loadAndDisplayLocked('/mainmenu/ui/entergamewindow.otui')
|
||||
end
|
||||
|
||||
function EnterGame_connectToLoginServer()
|
||||
local protocolLogin = ProtocolLogin.create()
|
||||
function EnterGame.destroy()
|
||||
enterGameWindow:destroy()
|
||||
enterGameWindow = nil
|
||||
end
|
||||
|
||||
local recreateEnterGame = function()
|
||||
UI.loadAndDisplayLocked('/mainmenu/ui/entergamewindow.otui')
|
||||
end
|
||||
function EnterGame.doLogin()
|
||||
EnterGame.account = enterGameWindow:getChildById('accountNameLineEdit'):getText()
|
||||
EnterGame.password = enterGameWindow:getChildById('accountPasswordLineEdit'):getText()
|
||||
EnterGame.destroy()
|
||||
|
||||
local loadBox = displayCancelBox('Please wait', 'Connecting to login server...')
|
||||
local protocolLogin = ProtocolLogin.create()
|
||||
protocolLogin.onError = onError
|
||||
protocolLogin.onMotd = onMotd
|
||||
protocolLogin.onCharacterList = onCharacterList
|
||||
|
||||
loadBox = displayCancelBox('Please wait', 'Connecting to login server...')
|
||||
loadBox.onCancel = function(msgbox)
|
||||
-- cancel protocol and reacreate enter game window
|
||||
protocolLogin:cancelLogin()
|
||||
recreateEnterGame()
|
||||
EnterGame.create()
|
||||
end
|
||||
|
||||
protocolLogin.onError = function(protocol, error)
|
||||
loadBox:destroy()
|
||||
local errorBox = displayErrorBox('Login Error', error)
|
||||
errorBox.onOk = recreateEnterGame
|
||||
end
|
||||
|
||||
protocolLogin.onMotd = function(protocol, motd)
|
||||
loadBox:destroy()
|
||||
local motdNumber = string.sub(motd, 0, string.find(motd, "\n"))
|
||||
local motdMessage = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
|
||||
showMotd(motdNumber, motdMessage)
|
||||
end
|
||||
|
||||
protocolLogin.onCharacterList = function(protocol, characters, premDays)
|
||||
loadBox:destroy()
|
||||
createCharactersWindow(characters, premDays)
|
||||
end
|
||||
|
||||
local enterGameWindow = UI.root:getChildById('enterGameWindow')
|
||||
account = enterGameWindow:getChildById('accountNameLineEdit'):getText()
|
||||
password = enterGameWindow:getChildById('accountPasswordLineEdit'):getText()
|
||||
protocolLogin:login(account, password)
|
||||
|
||||
enterGameWindow:destroy()
|
||||
protocolLogin:login(EnterGame.account, EnterGame.password)
|
||||
end
|
||||
|
@ -0,0 +1,22 @@
|
||||
MainMenu = { }
|
||||
|
||||
-- private variables
|
||||
local mainMenu
|
||||
|
||||
-- public functions
|
||||
function MainMenu.create()
|
||||
mainMenu = UI.loadAndDisplay("/mainmenu/ui/mainmenu.otui")
|
||||
end
|
||||
|
||||
function MainMenu.destroy()
|
||||
mainMenu:destroy()
|
||||
mainMenu = nil
|
||||
end
|
||||
|
||||
function MainMenu.hide()
|
||||
mainMenu:hide()
|
||||
end
|
||||
|
||||
function MainMenu.show()
|
||||
mainMenu:show()
|
||||
end
|
Loading…
Reference in new issue