tibia-client/modules/game/game.lua

83 lines
2.3 KiB
Lua
Raw Normal View History

-- private functions
local function onGameKeyPress(self, keyCode, keyboardModifiers, wouldFilter)
if wouldFilter then return end
if keyboardModifiers == KeyboardCtrlModifier then
if keyCode == KeyG then
CharacterList.show()
return true
elseif keyCode == KeyQ then
2011-08-30 01:20:30 +02:00
Game.logout(false)
return true
end
end
return false
end
-- public functions
function Game.createInterface()
Background.hide()
CharacterList.destroyLoadBox()
Game.gameUi = displayUI('game.otui')
--Hotkeys.bindKeyPress('Up', function() Game.walk(North) end)
--Hotkeys.bindKeyPress('Down', function() Game.walk(South) end)
--Hotkeys.bindKeyPress('Left', function() Game.walk(West) end)
--Hotkeys.bindKeyPress('Right', function() Game.walk(East) end)
Hotkeys.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end)
Hotkeys.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end)
Hotkeys.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end)
Hotkeys.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end)
rootWidget:moveChildToIndex(Game.gameUi, 1)
Game.gameMapPanel = Game.gameUi:getChildById('gameMapPanel')
Game.gameRightPanel = Game.gameUi:getChildById('gameRightPanel')
Game.gameBottomPanel = Game.gameUi:getChildById('gameBottomPanel')
2011-08-30 17:12:57 +02:00
Game.gameUi.onKeyPress = onGameKeyPress
2011-08-29 05:44:02 +02:00
end
function Game.destroyInterface()
2011-08-31 01:39:14 +02:00
if Game.gameUi then
2011-08-30 17:12:57 +02:00
Game.gameUi:destroy()
Game.gameUi = nil
end
Background.show()
CharacterList.show()
end
function Game.show()
Game.gameUi:show()
Game.gameUi:focus()
Game.gameMapPanel:focus()
end
function Game.hide()
Game.gameUi:hide()
end
-- hooked events
2011-08-30 01:20:30 +02:00
function Game.onLoginError(message)
CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Login error: " .. message)
errorBox.onOk = CharacterList.show
end
2011-08-29 20:38:01 +02:00
function Game.onConnectionError(message)
CharacterList.destroyLoadBox()
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
errorBox.onOk = CharacterList.show
end
2012-01-07 06:35:50 +01:00
local function onApplicationClose()
print('close app')
if Game.isOnline() then
2012-01-19 05:12:53 +01:00
Game.logout(true)
2012-01-07 06:35:50 +01:00
else
exit()
end
end
setonclose(onApplicationClose)
2011-12-05 19:27:07 +01:00
connect(Game, { onLogin = Game.createInterface }, true)
connect(Game, { onLogout = Game.destroyInterface })