ctrl+g kinda working, but login/logout events still need a remake
This commit is contained in:
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 = loadUI('/game/ui/gameinterface.otui', UI.root)
|
||||||
|
gameUi.onKeyPress = onGameKeyPress
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local function destroyMainInterface()
|
||||||
|
if gameUi then
|
||||||
|
gameUi:destroy()
|
||||||
|
gameUi = nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Game.onLogin()
|
function Game.onLogin()
|
||||||
|
MainMenu.hide()
|
||||||
|
CharacterList.destroyLoadBox()
|
||||||
|
createMainInterface()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Game.onLogout()
|
function Game.onLogout()
|
||||||
gameUi:destroy()
|
MainMenu.show()
|
||||||
gameUi = nil
|
CharacterList.show()
|
||||||
mainMenu:show()
|
destroyMainInterface()
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,4 @@ UIWidget
|
||||||
anchors.left: gameMap.right
|
anchors.left: gameMap.right
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
text: Logout
|
text: Logout
|
||||||
onClick: |
|
onClick: Game.logout()
|
||||||
Game.logout()
|
|
||||||
Game.onLogout()
|
|
|
@ -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
|
EnterGame = { }
|
||||||
|
|
||||||
|
-- private variables
|
||||||
local password
|
local password
|
||||||
|
local loadBox
|
||||||
|
local enterGameWindow
|
||||||
|
|
||||||
function EnterGame_characterWindow_okClicked()
|
-- private functions
|
||||||
local charactersWindow = UI.root:getChildById('charactersWindow')
|
local function onError(protocol, error)
|
||||||
local selected = charactersWindow:getChildById('charactersList'):getFocusedChild()
|
loadBox:destroy()
|
||||||
if selected then
|
local errorBox = displayErrorBox('Login Error', error)
|
||||||
Game.loginWorld(account, password, selected.worldHost, selected.worldPort, selected.characterName)
|
errorBox.onOk = EnterGame.create()
|
||||||
Configs.set('lastUsedCharacter', selected.characterName)
|
|
||||||
charactersWindow:destroy()
|
|
||||||
mainMenu:hide()
|
|
||||||
Game.createMainInterface()
|
|
||||||
else
|
|
||||||
displayErrorBox('Error', 'You must select a character to login!')
|
|
||||||
end
|
|
||||||
end
|
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
|
if motdNumber ~= Configs.get("motd") then
|
||||||
displayInfoBox("Message of the day", motdMessage)
|
displayInfoBox("Message of the day", motdMessage)
|
||||||
Configs.set("motd", motdNumber)
|
Configs.set("motd", motdNumber)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function createCharactersWindow(characters, premDays)
|
local function onCharacterList(protocol, characters, premDays)
|
||||||
local charactersWindow = UI.loadAndDisplayLocked('/mainmenu/ui/charlist.otui')
|
CharacterList.create(characters, premDays)
|
||||||
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
|
end
|
||||||
|
|
||||||
for i,characterInfo in ipairs(characters) do
|
-- public functions
|
||||||
local characterName = characterInfo[1]
|
function EnterGame.create()
|
||||||
local worldName = characterInfo[2]
|
enterGameWindow = UI.loadAndDisplayLocked('/mainmenu/ui/entergamewindow.otui')
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function EnterGame_connectToLoginServer()
|
function EnterGame.destroy()
|
||||||
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)
|
|
||||||
|
|
||||||
enterGameWindow: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
|
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
|
|
@ -9,17 +9,17 @@ Module
|
||||||
- core
|
- core
|
||||||
|
|
||||||
onLoad: |
|
onLoad: |
|
||||||
require('entergame')
|
require 'mainmenu'
|
||||||
|
require 'entergame'
|
||||||
|
require 'characterlist'
|
||||||
|
|
||||||
if not initialized then
|
if not initialized then
|
||||||
mainMenu = UI.loadAndDisplay("/mainmenu/ui/mainmenu.otui")
|
MainMenu.create()
|
||||||
initialized = true
|
initialized = true
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
||||||
onUnload: |
|
onUnload: |
|
||||||
mainMenu:destroy()
|
MainMenu.destroy()
|
||||||
mainMenu = nil
|
|
||||||
initialized = false
|
initialized = false
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
CharactersListLabel < Label
|
CharacterListLabel < Label
|
||||||
image: /core_ui/images/empty_rect.png
|
image: /core_ui/images/empty_rect.png
|
||||||
font: tibia-10px-monochrome
|
font: tibia-10px-monochrome
|
||||||
background-color: #00000000
|
background-color: #00000000
|
||||||
|
@ -16,11 +16,11 @@ MainWindow
|
||||||
id: charactersWindow
|
id: charactersWindow
|
||||||
title: Charlist
|
title: Charlist
|
||||||
size: 250 250
|
size: 250 250
|
||||||
onEnter: EnterGame_characterWindow_okClicked()
|
onEnter: CharacterList.doLogin()
|
||||||
onEscape: function(self) self:destroy() end
|
onEscape: function(self) self:destroy() end
|
||||||
|
|
||||||
TextList
|
TextList
|
||||||
id: charactersList
|
id: characterList
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.bottom: next.top
|
anchors.bottom: next.top
|
||||||
margin.top: 30
|
margin.top: 30
|
||||||
|
@ -29,10 +29,12 @@ MainWindow
|
||||||
margin.right: 16
|
margin.right: 16
|
||||||
|
|
||||||
Label
|
Label
|
||||||
|
id: accountStatusLabel
|
||||||
text: |-
|
text: |-
|
||||||
Account Status:
|
Account Status:
|
||||||
Free Account
|
Free Account
|
||||||
id: accountStatusLabel
|
font: helvetica-11px-bold
|
||||||
|
color: #33cc66
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
anchors.bottom: next.top
|
anchors.bottom: next.top
|
||||||
|
@ -55,7 +57,7 @@ MainWindow
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin.bottom: 16
|
margin.bottom: 16
|
||||||
margin.right: 16
|
margin.right: 16
|
||||||
onClick: EnterGame_characterWindow_okClicked()
|
onClick: CharacterList.doLogin()
|
||||||
|
|
||||||
Button
|
Button
|
||||||
id: buttonCancel
|
id: buttonCancel
|
||||||
|
@ -65,4 +67,8 @@ MainWindow
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin.bottom: 16
|
margin.bottom: 16
|
||||||
margin.right: 16
|
margin.right: 16
|
||||||
onClick: function(self) self:getParent():destroy() end
|
onClick: |
|
||||||
|
function(self)
|
||||||
|
self:getParent():unlock()
|
||||||
|
self:getParent():hide()
|
||||||
|
end
|
|
@ -2,7 +2,7 @@ MainWindow
|
||||||
id: enterGameWindow
|
id: enterGameWindow
|
||||||
title: Enter Game
|
title: Enter Game
|
||||||
size: 236 160
|
size: 236 160
|
||||||
onEnter: EnterGame_connectToLoginServer()
|
onEnter: EnterGame.doLogin()
|
||||||
onEscape: function(self) self:destroy() end
|
onEscape: function(self) self:destroy() end
|
||||||
|
|
||||||
LargerLabel
|
LargerLabel
|
||||||
|
@ -43,7 +43,7 @@ MainWindow
|
||||||
anchors.bottom: parent.bottom
|
anchors.bottom: parent.bottom
|
||||||
margin.bottom: 16
|
margin.bottom: 16
|
||||||
margin.right: 16
|
margin.right: 16
|
||||||
onClick: EnterGame_connectToLoginServer()
|
onClick: EnterGame.doLogin()
|
||||||
|
|
||||||
Button
|
Button
|
||||||
text: Cancel
|
text: Cancel
|
||||||
|
|
|
@ -24,7 +24,7 @@ Panel
|
||||||
MenuButton
|
MenuButton
|
||||||
text: Enter Game
|
text: Enter Game
|
||||||
margin.top: 18
|
margin.top: 18
|
||||||
onClick: UI.loadAndDisplayLocked("/mainmenu/ui/entergamewindow.otui")
|
onClick: EnterGame.create()
|
||||||
|
|
||||||
MenuButton
|
MenuButton
|
||||||
text: Options
|
text: Options
|
||||||
|
|
|
@ -59,8 +59,18 @@ void LuaInterface::registerFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setMarginLeft", &UIWidget::setMarginLeft);
|
g_lua.bindClassMemberFunction<UIWidget>("setMarginLeft", &UIWidget::setMarginLeft);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getMarginRight", &UIWidget::getMarginRight);
|
g_lua.bindClassMemberFunction<UIWidget>("getMarginRight", &UIWidget::getMarginRight);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("setMarginRight", &UIWidget::setMarginRight);
|
g_lua.bindClassMemberFunction<UIWidget>("setMarginRight", &UIWidget::setMarginRight);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isVisible", &UIWidget::isVisible);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isHidden", &UIWidget::isHidden);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isHovered", &UIWidget::isHovered);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isFocused", &UIWidget::isFocused);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isPressed", &UIWidget::isPressed);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isEnabled", &UIWidget::isEnabled);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isDisabled", &UIWidget::isDisabled);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("isActive", &UIWidget::isActive);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("hide", &UIWidget::hide);
|
g_lua.bindClassMemberFunction<UIWidget>("hide", &UIWidget::hide);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show);
|
g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("lock", &UIWidget::lock);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("unlock", &UIWidget::unlock);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getChildById", &UIWidget::getChildById);
|
g_lua.bindClassMemberFunction<UIWidget>("getChildById", &UIWidget::getChildById);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getChildByIndex", &UIWidget::getChildByIndex);
|
g_lua.bindClassMemberFunction<UIWidget>("getChildByIndex", &UIWidget::getChildByIndex);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
|
g_lua.bindClassMemberFunction<UIWidget>("getChildCount", &UIWidget::getChildCount);
|
||||||
|
@ -72,6 +82,7 @@ void LuaInterface::registerFunctions()
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("focusNextChild", &UIWidget::focusNextChild);
|
g_lua.bindClassMemberFunction<UIWidget>("focusNextChild", &UIWidget::focusNextChild);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("focusPreviousChild", &UIWidget::focusPreviousChild);
|
g_lua.bindClassMemberFunction<UIWidget>("focusPreviousChild", &UIWidget::focusPreviousChild);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild);
|
g_lua.bindClassMemberFunction<UIWidget>("lockChild", &UIWidget::lockChild);
|
||||||
|
g_lua.bindClassMemberFunction<UIWidget>("unlockChild", &UIWidget::unlockChild);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("updateLayout", &UIWidget::updateLayout);
|
g_lua.bindClassMemberFunction<UIWidget>("updateLayout", &UIWidget::updateLayout);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("updateParentLayout", &UIWidget::updateParentLayout);
|
g_lua.bindClassMemberFunction<UIWidget>("updateParentLayout", &UIWidget::updateParentLayout);
|
||||||
g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy);
|
g_lua.bindClassMemberFunction<UIWidget>("destroy", &UIWidget::destroy);
|
||||||
|
|
|
@ -775,6 +775,16 @@ void LuaInterface::getGlobal(const std::string& key)
|
||||||
lua_getglobal(L, key.c_str());
|
lua_getglobal(L, key.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LuaInterface::getGlobalField(const std::string& globalKey, const std::string& fieldKey)
|
||||||
|
{
|
||||||
|
getGlobal(globalKey);
|
||||||
|
if(!isNil()) {
|
||||||
|
assert(isTable() || isUserdata());
|
||||||
|
getField(fieldKey);
|
||||||
|
remove(-2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LuaInterface::setGlobal(const std::string& key)
|
void LuaInterface::setGlobal(const std::string& key)
|
||||||
{
|
{
|
||||||
assert(hasIndex(-1));
|
assert(hasIndex(-1));
|
||||||
|
|
|
@ -164,6 +164,12 @@ public:
|
||||||
/// prevents new variables in this new environment to be set on the global environment
|
/// prevents new variables in this new environment to be set on the global environment
|
||||||
void newEnvironment();
|
void newEnvironment();
|
||||||
|
|
||||||
|
template<typename... T>
|
||||||
|
int callGlobalField(const std::string& global, const std::string& field, const T&... args);
|
||||||
|
|
||||||
|
template<typename R, typename... T>
|
||||||
|
R callGlobalField(const std::string& global, const std::string& field, const T&... args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Load scripts requested by lua 'require'
|
/// Load scripts requested by lua 'require'
|
||||||
static int luaScriptLoader(lua_State* L);
|
static int luaScriptLoader(lua_State* L);
|
||||||
|
@ -221,6 +227,7 @@ public:
|
||||||
void setEnv(int index = -2);
|
void setEnv(int index = -2);
|
||||||
|
|
||||||
void getGlobal(const std::string& key);
|
void getGlobal(const std::string& key);
|
||||||
|
void getGlobalField(const std::string& globalKey, const std::string& fieldKey);
|
||||||
void setGlobal(const std::string& key);
|
void setGlobal(const std::string& key);
|
||||||
|
|
||||||
void rawGet(int index = -1);
|
void rawGet(int index = -1);
|
||||||
|
@ -347,4 +354,27 @@ T LuaInterface::castValue(int index) {
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename... T>
|
||||||
|
int LuaInterface::callGlobalField(const std::string& global, const std::string& field, const T&... args) {
|
||||||
|
g_lua.getGlobalField(global, field);
|
||||||
|
if(!g_lua.isNil()) {
|
||||||
|
g_lua.polymorphicPush(args...);
|
||||||
|
return g_lua.protectedCall(sizeof...(args));
|
||||||
|
} else
|
||||||
|
g_lua.pop(1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename R, typename... T>
|
||||||
|
R LuaInterface::callGlobalField(const std::string& global, const std::string& field, const T&... args) {
|
||||||
|
R result;
|
||||||
|
int rets = callGlobalField(global, field, args...);
|
||||||
|
if(rets > 0) {
|
||||||
|
assert(rets == 1);
|
||||||
|
result = g_lua.polymorphicPop<R>();
|
||||||
|
} else
|
||||||
|
result = R();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -188,13 +188,7 @@ UIWidgetPtr UIManager::loadWidgetFromOTML(const OTMLNodePtr& widgetNode, const U
|
||||||
std::string widgetType = styleNode->valueAt("__widgetType");
|
std::string widgetType = styleNode->valueAt("__widgetType");
|
||||||
|
|
||||||
// call widget creation from lua
|
// call widget creation from lua
|
||||||
//g_lua.getGlobalField(widgetType, "create");
|
UIWidgetPtr widget = g_lua.callGlobalField<UIWidgetPtr>(widgetType, "create");
|
||||||
g_lua.getGlobal(widgetType);
|
|
||||||
g_lua.getField("create");
|
|
||||||
g_lua.remove(-2);
|
|
||||||
g_lua.protectedCall(0, 1);
|
|
||||||
|
|
||||||
UIWidgetPtr widget = g_lua.polymorphicPop<UIWidgetPtr>();
|
|
||||||
if(parent)
|
if(parent)
|
||||||
parent->addChild(widget);
|
parent->addChild(widget);
|
||||||
|
|
||||||
|
|
|
@ -167,6 +167,18 @@ void UIWidget::setRect(const Rect& rect)
|
||||||
m_updateEventScheduled = true;
|
m_updateEventScheduled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIWidget::lock()
|
||||||
|
{
|
||||||
|
if(UIWidgetPtr parent = getParent())
|
||||||
|
parent->lockChild(asUIWidget());
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIWidget::unlock()
|
||||||
|
{
|
||||||
|
if(UIWidgetPtr parent = getParent())
|
||||||
|
parent->unlockChild(asUIWidget());
|
||||||
|
}
|
||||||
|
|
||||||
bool UIWidget::isVisible()
|
bool UIWidget::isVisible()
|
||||||
{
|
{
|
||||||
if(!m_visible)
|
if(!m_visible)
|
||||||
|
@ -365,8 +377,11 @@ void UIWidget::removeChild(const UIWidgetPtr& child)
|
||||||
auto it = std::find(m_children.begin(), m_children.end(), child);
|
auto it = std::find(m_children.begin(), m_children.end(), child);
|
||||||
if(it != m_children.end()) {
|
if(it != m_children.end()) {
|
||||||
// defocus if needed
|
// defocus if needed
|
||||||
if(m_focusedChild == child)
|
bool focusAnother = false;
|
||||||
|
if(m_focusedChild == child) {
|
||||||
focusChild(nullptr, Fw::ActiveFocusReason);
|
focusChild(nullptr, Fw::ActiveFocusReason);
|
||||||
|
focusAnother = true;
|
||||||
|
}
|
||||||
|
|
||||||
// unlock child if it was locked
|
// unlock child if it was locked
|
||||||
unlockChild(child);
|
unlockChild(child);
|
||||||
|
@ -381,6 +396,9 @@ void UIWidget::removeChild(const UIWidgetPtr& child)
|
||||||
|
|
||||||
// update child states
|
// update child states
|
||||||
child->updateStates();
|
child->updateStates();
|
||||||
|
|
||||||
|
if(focusAnother)
|
||||||
|
focusPreviousChild(Fw::ActiveFocusReason);
|
||||||
} else
|
} else
|
||||||
logError("attempt to remove an unknown child from a UIWidget");
|
logError("attempt to remove an unknown child from a UIWidget");
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,8 @@ public:
|
||||||
void show() { setVisible(true); }
|
void show() { setVisible(true); }
|
||||||
void disable() { setEnabled(false); }
|
void disable() { setEnabled(false); }
|
||||||
void enable() { setEnabled(true); }
|
void enable() { setEnabled(true); }
|
||||||
|
void lock();
|
||||||
|
void unlock();
|
||||||
|
|
||||||
bool isActive() const { return hasState(Fw::ActiveState); }
|
bool isActive() const { return hasState(Fw::ActiveState); }
|
||||||
bool isEnabled() const { return !hasState(Fw::DisabledState); }
|
bool isEnabled() const { return !hasState(Fw::DisabledState); }
|
||||||
|
@ -81,6 +83,7 @@ public:
|
||||||
bool isHovered() const { return hasState(Fw::HoverState); }
|
bool isHovered() const { return hasState(Fw::HoverState); }
|
||||||
bool isPressed() const { return hasState(Fw::PressedState); }
|
bool isPressed() const { return hasState(Fw::PressedState); }
|
||||||
bool isVisible();
|
bool isVisible();
|
||||||
|
bool isHidden() { return !isVisible(); }
|
||||||
bool isExplicitlyEnabled() const { return m_enabled; }
|
bool isExplicitlyEnabled() const { return m_enabled; }
|
||||||
bool isExplicitlyVisible() const { return m_visible; }
|
bool isExplicitlyVisible() const { return m_visible; }
|
||||||
bool isFocusable() const { return m_focusable; }
|
bool isFocusable() const { return m_focusable; }
|
||||||
|
@ -143,9 +146,6 @@ public:
|
||||||
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
UIWidgetPtr asUIWidget() { return std::static_pointer_cast<UIWidget>(shared_from_this()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void internalDestroy();
|
|
||||||
void internalDestroyCheck();
|
|
||||||
|
|
||||||
bool m_updateEventScheduled;
|
bool m_updateEventScheduled;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "thing.h"
|
#include "thing.h"
|
||||||
#include <framework/graphics/fontmanager.h>
|
#include <framework/graphics/fontmanager.h>
|
||||||
|
|
||||||
|
//TODO: create Outfit class and move to a separate file
|
||||||
struct Outfit {
|
struct Outfit {
|
||||||
uint16 type;
|
uint16 type;
|
||||||
uint8 head;
|
uint8 head;
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#include "datmanager.h"
|
#include "datmanager.h"
|
||||||
#include "spritemanager.h"
|
#include "spritemanager.h"
|
||||||
|
#include "thing.h"
|
||||||
#include <framework/core/resourcemanager.h>
|
#include <framework/core/resourcemanager.h>
|
||||||
|
|
||||||
DatManager g_dat;
|
DatManager g_dat;
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#define DATMANAGER_H
|
#define DATMANAGER_H
|
||||||
|
|
||||||
#include <framework/global.h>
|
#include <framework/global.h>
|
||||||
#include "thing.h"
|
#include "thingattributes.h"
|
||||||
|
|
||||||
class DatManager
|
class DatManager
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,17 +46,19 @@ void Game::loginWorld(const std::string& account, const std::string& password, c
|
||||||
void Game::logout()
|
void Game::logout()
|
||||||
{
|
{
|
||||||
m_protocolGame->sendLogout();
|
m_protocolGame->sendLogout();
|
||||||
onLogout();
|
processLogout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::onLogin()
|
void Game::processLogin(const LocalPlayerPtr& localPlayer)
|
||||||
{
|
{
|
||||||
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
m_localPlayer = localPlayer;
|
||||||
m_online = true;
|
m_online = true;
|
||||||
|
g_lua.callGlobalField("Game", "onLogin", m_localPlayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::onLogout()
|
void Game::processLogout()
|
||||||
{
|
{
|
||||||
|
g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
|
||||||
if(m_protocolGame) {
|
if(m_protocolGame) {
|
||||||
m_protocolGame->disconnect();
|
m_protocolGame->disconnect();
|
||||||
m_protocolGame.reset();
|
m_protocolGame.reset();
|
||||||
|
@ -72,7 +74,7 @@ void Game::walk(Otc::Direction direction)
|
||||||
|
|
||||||
// TODO: check if we can walk.
|
// TODO: check if we can walk.
|
||||||
|
|
||||||
m_localPlayer->setDirection(direction);
|
//m_localPlayer->setDirection(direction);
|
||||||
|
|
||||||
switch(direction) {
|
switch(direction) {
|
||||||
case Otc::North:
|
case Otc::North:
|
||||||
|
|
|
@ -36,10 +36,11 @@ public:
|
||||||
const std::string& password,
|
const std::string& password,
|
||||||
const std::string& worldHost, int worldPort,
|
const std::string& worldHost, int worldPort,
|
||||||
const std::string& characterName);
|
const std::string& characterName);
|
||||||
|
void cancelLogin();
|
||||||
void logout();
|
void logout();
|
||||||
|
|
||||||
void onLogin();
|
void processLogin(const LocalPlayerPtr& localPlayer);
|
||||||
void onLogout();
|
void processLogout();
|
||||||
|
|
||||||
void walk(Otc::Direction direction);
|
void walk(Otc::Direction direction);
|
||||||
void turn(Otc::Direction direction);
|
void turn(Otc::Direction direction);
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "localplayer.h"
|
#include "localplayer.h"
|
||||||
|
#include "tile.h"
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
#include <framework/graphics/framebuffer.h>
|
#include <framework/graphics/framebuffer.h>
|
||||||
|
|
||||||
|
@ -187,7 +188,7 @@ void Map::cleanTile(const Position& pos)
|
||||||
|
|
||||||
CreaturePtr Map::getCreatureById(uint32 id)
|
CreaturePtr Map::getCreatureById(uint32 id)
|
||||||
{
|
{
|
||||||
if(g_game.getLocalPlayer()->getId() == id)
|
if(g_game.getLocalPlayer() && g_game.getLocalPlayer()->getId() == id)
|
||||||
return g_game.getLocalPlayer();
|
return g_game.getLocalPlayer();
|
||||||
return m_creatures[id];
|
return m_creatures[id];
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#ifndef MAP_H
|
#ifndef MAP_H
|
||||||
#define MAP_H
|
#define MAP_H
|
||||||
|
|
||||||
#include "tile.h"
|
|
||||||
#include "creature.h"
|
#include "creature.h"
|
||||||
#include <framework/graphics/declarations.h>
|
#include <framework/graphics/declarations.h>
|
||||||
|
|
||||||
|
|
|
@ -99,12 +99,6 @@ void Tile::addThing(ThingPtr thing, int stackpos)
|
||||||
|
|
||||||
const ThingAttributes& thingAttributes = thing->getAttributes();
|
const ThingAttributes& thingAttributes = thing->getAttributes();
|
||||||
|
|
||||||
if(thing->getPosition() == g_game.getLocalPlayer()->getPosition() + Position(-1, 0, 0) && thingAttributes.group == Otc::ThingGroundGroup) {
|
|
||||||
logDebug((int)thing->getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(thing->asItem()) {
|
if(thing->asItem()) {
|
||||||
if(thingAttributes.group == Otc::ThingGroundGroup)
|
if(thingAttributes.group == Otc::ThingGroundGroup)
|
||||||
m_ground = thing;
|
m_ground = thing;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
|
|
||||||
#include <otclient/net/protocolgame.h>
|
#include <otclient/net/protocolgame.h>
|
||||||
#include <otclient/core/game.h>
|
#include <otclient/core/game.h>
|
||||||
|
#include <otclient/core/player.h>
|
||||||
|
#include <otclient/core/item.h>
|
||||||
|
|
||||||
ProtocolGame::ProtocolGame()
|
ProtocolGame::ProtocolGame()
|
||||||
{
|
{
|
||||||
|
@ -69,6 +71,6 @@ void ProtocolGame::onRecv(InputMessage& inputMessage)
|
||||||
void ProtocolGame::onError(const boost::system::error_code& error)
|
void ProtocolGame::onError(const boost::system::error_code& error)
|
||||||
{
|
{
|
||||||
// already disconnected, just fire onLogout
|
// already disconnected, just fire onLogout
|
||||||
g_game.onLogout();
|
g_game.processLogout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,9 @@
|
||||||
#define PROTOCOLGAME_H
|
#define PROTOCOLGAME_H
|
||||||
|
|
||||||
#include "declarations.h"
|
#include "declarations.h"
|
||||||
|
#include <otclient/core/declarations.h>
|
||||||
#include <framework/net/protocol.h>
|
#include <framework/net/protocol.h>
|
||||||
|
#include <otclient/core/creature.h>
|
||||||
#include <otclient/core/player.h>
|
|
||||||
#include <otclient/core/item.h>
|
|
||||||
|
|
||||||
class ProtocolGame : public Protocol
|
class ProtocolGame : public Protocol
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
#include <otclient/core/datmanager.h>
|
#include <otclient/core/datmanager.h>
|
||||||
#include <otclient/core/game.h>
|
#include <otclient/core/game.h>
|
||||||
#include <otclient/core/map.h>
|
#include <otclient/core/map.h>
|
||||||
|
#include <otclient/core/item.h>
|
||||||
#include <otclient/core/effect.h>
|
#include <otclient/core/effect.h>
|
||||||
|
#include <framework/core/eventdispatcher.h>
|
||||||
|
|
||||||
void ProtocolGame::parseMessage(InputMessage& msg)
|
void ProtocolGame::parseMessage(InputMessage& msg)
|
||||||
{
|
{
|
||||||
|
@ -258,9 +260,7 @@ void ProtocolGame::parsePlayerLogin(InputMessage& msg)
|
||||||
int playerDrawSpeed = msg.getU16();
|
int playerDrawSpeed = msg.getU16();
|
||||||
int playerCanReportBugs = msg.getU8();
|
int playerCanReportBugs = msg.getU8();
|
||||||
|
|
||||||
g_game.onLogin();
|
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
||||||
|
|
||||||
m_localPlayer = g_game.getLocalPlayer();
|
|
||||||
m_localPlayer->setId(playerId);
|
m_localPlayer->setId(playerId);
|
||||||
m_localPlayer->setDrawSpeed(playerDrawSpeed);
|
m_localPlayer->setDrawSpeed(playerDrawSpeed);
|
||||||
m_localPlayer->setCanReportBugs(playerCanReportBugs);
|
m_localPlayer->setCanReportBugs(playerCanReportBugs);
|
||||||
|
@ -975,9 +975,8 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
|
||||||
|
|
||||||
g_map.removeCreatureById(removeId);
|
g_map.removeCreatureById(removeId);
|
||||||
|
|
||||||
LocalPlayerPtr localPlayer = g_game.getLocalPlayer();
|
if(m_localPlayer->getId() == id)
|
||||||
if(localPlayer->getId() == id)
|
creature = m_localPlayer->asCreature();
|
||||||
creature = localPlayer->asCreature();
|
|
||||||
|
|
||||||
creature->setId(id);
|
creature->setId(id);
|
||||||
creature->setName(name);
|
creature->setName(name);
|
||||||
|
@ -1013,6 +1012,11 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
|
||||||
|
|
||||||
thing = creature;
|
thing = creature;
|
||||||
|
|
||||||
|
// login event is generated the first time that local player gets known
|
||||||
|
if(!g_game.isOnline() && creature == m_localPlayer) {
|
||||||
|
// this event must be scheduled because the entire map description is not known yet
|
||||||
|
g_dispatcher.addEvent(std::bind(&Game::processLogin, &g_game, m_localPlayer));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(thingId == 0x0063) { // creature turn
|
else if(thingId == 0x0063) { // creature turn
|
||||||
parseCreatureTurn(msg);
|
parseCreatureTurn(msg);
|
||||||
|
|
|
@ -24,6 +24,12 @@
|
||||||
|
|
||||||
#include <framework/luascript/luainterface.h>
|
#include <framework/luascript/luainterface.h>
|
||||||
#include <otclient/core/game.h>
|
#include <otclient/core/game.h>
|
||||||
|
#include <otclient/core/tile.h>
|
||||||
|
#include <otclient/core/item.h>
|
||||||
|
#include <otclient/core/creature.h>
|
||||||
|
#include <otclient/core/player.h>
|
||||||
|
#include <otclient/core/localplayer.h>
|
||||||
|
#include <otclient/core/map.h>
|
||||||
#include <otclient/core/datmanager.h>
|
#include <otclient/core/datmanager.h>
|
||||||
#include <otclient/core/spritemanager.h>
|
#include <otclient/core/spritemanager.h>
|
||||||
#include <otclient/net/protocollogin.h>
|
#include <otclient/net/protocollogin.h>
|
||||||
|
@ -44,6 +50,14 @@ void OTClient::registerLuaFunctions()
|
||||||
|
|
||||||
g_lua.registerClass<ProtocolGame, Protocol>();
|
g_lua.registerClass<ProtocolGame, Protocol>();
|
||||||
|
|
||||||
|
g_lua.registerClass<Thing>();
|
||||||
|
g_lua.registerClass<Creature>();
|
||||||
|
g_lua.registerClass<Player, Creature>();
|
||||||
|
g_lua.registerClass<LocalPlayer, Player>();
|
||||||
|
g_lua.registerClass<Item>();
|
||||||
|
g_lua.registerClass<Tile>();
|
||||||
|
g_lua.registerClass<Map>();
|
||||||
|
|
||||||
g_lua.registerClass<Game>();
|
g_lua.registerClass<Game>();
|
||||||
g_lua.bindClassStaticFunction<Game>("loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
|
g_lua.bindClassStaticFunction<Game>("loginWorld", std::bind(&Game::loginWorld, &g_game, _1, _2, _3, _4, _5));
|
||||||
g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game));
|
g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game));
|
||||||
|
|
Loading…
Reference in New Issue