ctrl+g kinda working, but login/logout events still need a remake

This commit is contained in:
Eduardo Bart
2011-08-29 11:14:21 -03:00
parent b859f66952
commit 8b2cb410c2
27 changed files with 323 additions and 148 deletions

View File

@@ -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

View File

@@ -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
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
local function onCharacterList(protocol, characters, premDays)
CharacterList.create(characters, premDays)
end
function EnterGame_connectToLoginServer()
local protocolLogin = ProtocolLogin.create()
local recreateEnterGame = function()
UI.loadAndDisplayLocked('/mainmenu/ui/entergamewindow.otui')
end
local loadBox = displayCancelBox('Please wait', 'Connecting to login server...')
loadBox.onCancel = function(msgbox)
-- cancel protocol and reacreate enter game window
protocolLogin:cancelLogin()
recreateEnterGame()
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)
-- public functions
function EnterGame.create()
enterGameWindow = UI.loadAndDisplayLocked('/mainmenu/ui/entergamewindow.otui')
end
function EnterGame.destroy()
enterGameWindow:destroy()
enterGameWindow = nil
end
function EnterGame.doLogin()
EnterGame.account = enterGameWindow:getChildById('accountNameLineEdit'):getText()
EnterGame.password = enterGameWindow:getChildById('accountPasswordLineEdit'):getText()
EnterGame.destroy()
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)
protocolLogin:cancelLogin()
EnterGame.create()
end
protocolLogin:login(EnterGame.account, EnterGame.password)
end

View File

@@ -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

View File

@@ -9,17 +9,17 @@ Module
- core
onLoad: |
require('entergame')
require 'mainmenu'
require 'entergame'
require 'characterlist'
if not initialized then
mainMenu = UI.loadAndDisplay("/mainmenu/ui/mainmenu.otui")
MainMenu.create()
initialized = true
end
return true
onUnload: |
mainMenu:destroy()
mainMenu = nil
MainMenu.destroy()
initialized = false

View File

@@ -1,4 +1,4 @@
CharactersListLabel < Label
CharacterListLabel < Label
image: /core_ui/images/empty_rect.png
font: tibia-10px-monochrome
background-color: #00000000
@@ -16,11 +16,11 @@ MainWindow
id: charactersWindow
title: Charlist
size: 250 250
onEnter: EnterGame_characterWindow_okClicked()
onEnter: CharacterList.doLogin()
onEscape: function(self) self:destroy() end
TextList
id: charactersList
id: characterList
anchors.fill: parent
anchors.bottom: next.top
margin.top: 30
@@ -29,10 +29,12 @@ MainWindow
margin.right: 16
Label
id: accountStatusLabel
text: |-
Account Status:
Free Account
id: accountStatusLabel
font: helvetica-11px-bold
color: #33cc66
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: next.top
@@ -55,7 +57,7 @@ MainWindow
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
onClick: EnterGame_characterWindow_okClicked()
onClick: CharacterList.doLogin()
Button
id: buttonCancel
@@ -65,4 +67,8 @@ MainWindow
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
onClick: function(self) self:getParent():destroy() end
onClick: |
function(self)
self:getParent():unlock()
self:getParent():hide()
end

View File

@@ -2,7 +2,7 @@ MainWindow
id: enterGameWindow
title: Enter Game
size: 236 160
onEnter: EnterGame_connectToLoginServer()
onEnter: EnterGame.doLogin()
onEscape: function(self) self:destroy() end
LargerLabel
@@ -43,7 +43,7 @@ MainWindow
anchors.bottom: parent.bottom
margin.bottom: 16
margin.right: 16
onClick: EnterGame_connectToLoginServer()
onClick: EnterGame.doLogin()
Button
text: Cancel

View File

@@ -24,7 +24,7 @@ Panel
MenuButton
text: Enter Game
margin.top: 18
onClick: UI.loadAndDisplayLocked("/mainmenu/ui/entergamewindow.otui")
onClick: EnterGame.create()
MenuButton
text: Options