mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 03:54:54 +02:00
reorganize modules
This commit is contained in:
124
modules/client_entergame/characterlist.lua
Normal file
124
modules/client_entergame/characterlist.lua
Normal file
@@ -0,0 +1,124 @@
|
||||
CharacterList = { }
|
||||
|
||||
-- private variables
|
||||
local charactersWindow
|
||||
local loadBox
|
||||
local characterList
|
||||
|
||||
-- private functions
|
||||
local function onCharactersWindowKeyPress(self, keyCode, keyText, 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
|
||||
|
||||
local function tryLogin(charInfo, tries)
|
||||
tries = tries or 1
|
||||
|
||||
if tries > 4 then
|
||||
CharacterList.destroyLoadBox()
|
||||
displayErrorBox('Error', 'Could not logout.')
|
||||
return
|
||||
end
|
||||
|
||||
if Game.isOnline() then
|
||||
Game.logout(false)
|
||||
if tries == 1 then
|
||||
loadBox = displayCancelBox('Please wait', 'Loggin out...')
|
||||
end
|
||||
scheduleEvent(function() tryLogin(charInfo, tries+1) end, 250)
|
||||
return
|
||||
end
|
||||
|
||||
CharacterList.destroyLoadBox()
|
||||
|
||||
Game.loginWorld(EnterGame.account, EnterGame.password, charInfo.worldHost, charInfo.worldPort, charInfo.characterName)
|
||||
|
||||
loadBox = displayCancelBox('Please wait', 'Connecting to game server...')
|
||||
function loadBox.onCancel()
|
||||
loadBox = nil
|
||||
Game.cancelLogin()
|
||||
CharacterList.show()
|
||||
end
|
||||
|
||||
-- save last used character
|
||||
g_configs.set('lastUsedCharacter', charInfo.characterName)
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function CharacterList.create(characters, premDays)
|
||||
if charactersWindow then
|
||||
charactersWindow:destroy()
|
||||
end
|
||||
|
||||
charactersWindow = UI.display('characterlist.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 == 1 or g_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:hide()
|
||||
end
|
||||
|
||||
function CharacterList.destroy()
|
||||
CharacterList.hide()
|
||||
if not Game.isOnline() then
|
||||
EnterGame.show()
|
||||
end
|
||||
end
|
||||
|
||||
function CharacterList.show()
|
||||
if not loadBox then
|
||||
charactersWindow:show()
|
||||
charactersWindow:focus()
|
||||
end
|
||||
end
|
||||
|
||||
function CharacterList.doLogin()
|
||||
local selected = charactersWindow:getChildById('characterList'):getFocusedChild()
|
||||
if selected then
|
||||
local charInfo = { worldHost = selected.worldHost,
|
||||
worldPort = selected.worldPort,
|
||||
characterName = selected.characterName }
|
||||
CharacterList.hide()
|
||||
tryLogin(charInfo)
|
||||
else
|
||||
displayErrorBox('Error', 'You must select a character to login!')
|
||||
end
|
||||
end
|
||||
|
||||
function CharacterList.destroyLoadBox()
|
||||
if loadBox then
|
||||
loadBox:destroy()
|
||||
loadBox = nil
|
||||
end
|
||||
end
|
80
modules/client_entergame/characterlist.otui
Normal file
80
modules/client_entergame/characterlist.otui
Normal file
@@ -0,0 +1,80 @@
|
||||
CharacterListLabel < Label
|
||||
image: /core_styles/images/empty_rect.png
|
||||
font: verdana-11px-monochrome
|
||||
background-color: #00000000
|
||||
offset: 2 0
|
||||
focusable: true
|
||||
margin-left: 1
|
||||
margin-right: 1
|
||||
margin-top: 1
|
||||
|
||||
$focus:
|
||||
background-color: #ffffff22
|
||||
color: #ffffff
|
||||
|
||||
MainWindow
|
||||
id: charactersWindow
|
||||
title: Character List
|
||||
size: 250 248
|
||||
@onEnter: CharacterList.doLogin()
|
||||
@onEscape: CharacterList.destroy()
|
||||
|
||||
TextList
|
||||
id: characterList
|
||||
anchors.fill: parent
|
||||
anchors.bottom: next.top
|
||||
margin-top: 30
|
||||
margin-bottom: 5
|
||||
margin-left: 16
|
||||
margin-right: 16
|
||||
|
||||
Label
|
||||
id: accountStatusLabel
|
||||
text: |-
|
||||
Account Status:
|
||||
Free Account
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: separator.top
|
||||
margin-left: 16
|
||||
margin-bottom: 5
|
||||
|
||||
HorizontalSeparator
|
||||
id: separator
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: next.top
|
||||
margin-left: 16
|
||||
margin-right: 16
|
||||
margin-bottom: 10
|
||||
|
||||
//CheckBox
|
||||
// id: charAutoLoginBox
|
||||
// text: Auto login
|
||||
// tooltip: Auto login selected character on next charlist load
|
||||
// anchors.left: parent.left
|
||||
// anchors.right: parent.right
|
||||
// anchors.bottom: next.top
|
||||
// margin-bottom: 6
|
||||
// margin-left: 18
|
||||
// margin-right: 18
|
||||
|
||||
Button
|
||||
id: buttonOk
|
||||
text: Ok
|
||||
width: 64
|
||||
anchors.right: next.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin-bottom: 16
|
||||
margin-right: 16
|
||||
@onClick: CharacterList.doLogin()
|
||||
|
||||
Button
|
||||
id: buttonCancel
|
||||
text: Cancel
|
||||
width: 64
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin-bottom: 16
|
||||
margin-right: 16
|
||||
@onClick: CharacterList.destroy()
|
115
modules/client_entergame/entergame.lua
Normal file
115
modules/client_entergame/entergame.lua
Normal file
@@ -0,0 +1,115 @@
|
||||
EnterGame = { }
|
||||
|
||||
-- private variables
|
||||
local loadBox
|
||||
local enterGame
|
||||
local motdNumber
|
||||
local motdMessage
|
||||
|
||||
-- private functions
|
||||
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)
|
||||
end
|
||||
|
||||
local function onError(protocol, error)
|
||||
loadBox:destroy()
|
||||
clearAccountFields()
|
||||
local errorBox = displayErrorBox('Login Error', error)
|
||||
errorBox.onOk = EnterGame.show
|
||||
end
|
||||
|
||||
local function onMotd(protocol, motd)
|
||||
motdNumber = tonumber(string.sub(motd, 0, string.find(motd, "\n")))
|
||||
motdMessage = string.sub(motd, string.find(motd, "\n") + 1, string.len(motd))
|
||||
TopMenu.getButton('motdButton'):show()
|
||||
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
|
||||
clearAccountFields()
|
||||
end
|
||||
|
||||
loadBox:destroy()
|
||||
CharacterList.create(characters, premDays)
|
||||
|
||||
local lastMotdNumber = tonumber(g_configs.get("motd"))
|
||||
if motdNumber and motdNumber ~= lastMotdNumber then
|
||||
g_configs.set("motd", motdNumber)
|
||||
local motdBox = displayInfoBox("Message of the day", motdMessage)
|
||||
motdBox.onOk = CharacterList.show
|
||||
CharacterList.hide()
|
||||
end
|
||||
end
|
||||
|
||||
-- public functions
|
||||
function EnterGame.create()
|
||||
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)
|
||||
enterGame:getChildById('accountNameLineEdit'):focus()
|
||||
|
||||
if #account > 0 and autologin then
|
||||
addEvent(EnterGame.doLogin)
|
||||
end
|
||||
end
|
||||
|
||||
function EnterGame.destroy()
|
||||
enterGame:destroy()
|
||||
enterGame = nil
|
||||
end
|
||||
|
||||
function EnterGame.show()
|
||||
enterGame:show()
|
||||
enterGame:focus()
|
||||
end
|
||||
|
||||
function EnterGame.hide()
|
||||
enterGame:hide()
|
||||
end
|
||||
|
||||
function EnterGame.doLogin()
|
||||
EnterGame.account = enterGame:getChildById('accountNameLineEdit'):getText()
|
||||
EnterGame.password = enterGame:getChildById('accountPasswordLineEdit'):getText()
|
||||
EnterGame.host = enterGame:getChildById('serverHostLineEdit'):getText()
|
||||
EnterGame.port = enterGame:getChildById('serverPortLineEdit'):getText()
|
||||
EnterGame.hide()
|
||||
|
||||
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
|
||||
|
||||
loadBox = displayCancelBox('Please wait', 'Connecting to login server...')
|
||||
loadBox.onCancel = function(msgbox)
|
||||
protocolLogin:cancelLogin()
|
||||
EnterGame.show()
|
||||
end
|
||||
|
||||
protocolLogin:login(EnterGame.host, EnterGame.port, EnterGame.account, EnterGame.password)
|
||||
end
|
||||
|
||||
function EnterGame.displayMotd()
|
||||
displayInfoBox("Message of the day", motdMessage)
|
||||
end
|
16
modules/client_entergame/entergame.otmod
Normal file
16
modules/client_entergame/entergame.otmod
Normal file
@@ -0,0 +1,16 @@
|
||||
Module
|
||||
name: client_entergame
|
||||
description: Manages enter game and character list windows
|
||||
author: OTClient team
|
||||
website: https://github.com/edubart/otclient
|
||||
|
||||
onLoad: |
|
||||
require 'entergame'
|
||||
require 'characterlist'
|
||||
EnterGame.create()
|
||||
return true
|
||||
|
||||
onUnload:
|
||||
EnterGame.destroy()
|
||||
|
||||
|
114
modules/client_entergame/entergame.otui
Normal file
114
modules/client_entergame/entergame.otui
Normal file
@@ -0,0 +1,114 @@
|
||||
MainWindow
|
||||
id: enterGame
|
||||
title: Enter Game
|
||||
size: 236 240
|
||||
@onEnter: EnterGame.doLogin()
|
||||
@onEscape: EnterGame.hide()
|
||||
|
||||
LargerLabel
|
||||
text: Account name
|
||||
anchors.left: parent.left
|
||||
anchors.top: parent.top
|
||||
margin-left: 18
|
||||
margin-top: 28
|
||||
|
||||
LineEdit
|
||||
id: accountNameLineEdit
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 2
|
||||
margin-left: 18
|
||||
margin-right: 18
|
||||
|
||||
LargerLabel
|
||||
text: Password
|
||||
anchors.left: prev.left
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 8
|
||||
|
||||
PasswordLineEdit
|
||||
id: accountPasswordLineEdit
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 2
|
||||
margin-left: 18
|
||||
margin-right: 18
|
||||
|
||||
LargerLabel
|
||||
id: serverLabel
|
||||
width: 140
|
||||
text: Server
|
||||
anchors.left: prev.left
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 8
|
||||
|
||||
LineEdit
|
||||
id: serverHostLineEdit
|
||||
tooltip: Only protocol 8.62 is supported
|
||||
anchors.left: serverLabel.left
|
||||
anchors.right: serverLabel.right
|
||||
anchors.top: serverLabel.bottom
|
||||
margin-top: 2
|
||||
|
||||
LargerLabel
|
||||
id: portLabel
|
||||
text: Port
|
||||
width: 50
|
||||
anchors.left: serverLabel.right
|
||||
anchors.top: serverLabel.top
|
||||
margin-left: 10
|
||||
|
||||
LineEdit
|
||||
id: serverPortLineEdit
|
||||
text: 7171
|
||||
anchors.left: portLabel.left
|
||||
anchors.right: portLabel.right
|
||||
anchors.top: portLabel.bottom
|
||||
margin-top: 2
|
||||
|
||||
CheckBox
|
||||
id: rememberPasswordBox
|
||||
text: Remember password
|
||||
tooltip: Remember account and password when starts otclient
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 10
|
||||
margin-left: 18
|
||||
margin-right: 18
|
||||
@onCheckChange: |
|
||||
function(self, checked)
|
||||
self:getParent():getChildById('autoLoginBox'):setEnabled(checked)
|
||||
end
|
||||
|
||||
CheckBox
|
||||
id: autoLoginBox
|
||||
enabled: false
|
||||
text: Auto login
|
||||
tooltip: Open charlist automatically when starting otclient
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: prev.bottom
|
||||
margin-top: 8
|
||||
margin-left: 18
|
||||
margin-right: 18
|
||||
|
||||
Button
|
||||
text: Ok
|
||||
width: 64
|
||||
anchors.right: next.left
|
||||
anchors.bottom: parent.bottom
|
||||
margin-bottom: 16
|
||||
margin-right: 16
|
||||
@onClick: EnterGame.doLogin()
|
||||
|
||||
Button
|
||||
text: Cancel
|
||||
width: 64
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
margin-bottom: 16
|
||||
margin-right: 16
|
||||
@onClick: EnterGame.hide()
|
Reference in New Issue
Block a user