2012-01-24 19:39:16 +01:00
|
|
|
-- private variables
|
|
|
|
local m_mouseGrabberWidget
|
|
|
|
|
2011-08-29 16:14:21 +02:00
|
|
|
-- private functions
|
2012-02-06 13:53:28 +01:00
|
|
|
local function onGameKeyPress(self, keyCode, keyboardModifiers)
|
2011-08-29 16:14:21 +02:00
|
|
|
if keyboardModifiers == KeyboardCtrlModifier then
|
|
|
|
if keyCode == KeyG then
|
|
|
|
CharacterList.show()
|
|
|
|
return true
|
2011-08-29 21:35:58 +02:00
|
|
|
elseif keyCode == KeyQ then
|
2011-08-30 01:20:30 +02:00
|
|
|
Game.logout(false)
|
2011-08-29 21:35:58 +02:00
|
|
|
return true
|
2011-08-29 16:14:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-01-24 19:39:16 +01:00
|
|
|
local function onUseWithMouseRelease(self, mousePosition, mouseButton)
|
|
|
|
if Game.selectedThing == nil then return false end
|
|
|
|
if mouseButton == MouseLeftButton then
|
|
|
|
local clickedWidget = Game.gameUi:recursiveGetChildByPos(mousePosition)
|
|
|
|
if clickedWidget then
|
2012-02-01 20:37:40 +01:00
|
|
|
if clickedWidget:getClassName() == 'UIMap' then
|
2012-01-24 19:39:16 +01:00
|
|
|
local tile = clickedWidget:getTile(mousePosition)
|
|
|
|
if tile then
|
|
|
|
Game.useWith(Game.selectedThing, tile:getTopMultiUseThing())
|
|
|
|
end
|
2012-02-01 16:20:13 +01:00
|
|
|
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
|
2012-01-24 19:39:16 +01:00
|
|
|
Game.useWith(Game.selectedThing, clickedWidget:getItem())
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Game.selectedThing = nil
|
2012-02-06 05:39:52 +01:00
|
|
|
Mouse.restoreCursor()
|
2012-01-24 19:39:16 +01:00
|
|
|
self:ungrabMouse()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2011-11-03 10:59:11 +01:00
|
|
|
-- public functions
|
2012-01-24 19:39:16 +01:00
|
|
|
function Game.startUseWith(thing)
|
|
|
|
Game.selectedThing = thing
|
|
|
|
m_mouseGrabberWidget:grabMouse()
|
2012-02-06 05:39:52 +01:00
|
|
|
Mouse.setTargetCursor()
|
2012-01-24 19:39:16 +01:00
|
|
|
end
|
|
|
|
|
2011-11-03 21:54:53 +01:00
|
|
|
function Game.createInterface()
|
|
|
|
Background.hide()
|
|
|
|
CharacterList.destroyLoadBox()
|
2012-01-03 01:42:53 +01:00
|
|
|
Game.gameUi = displayUI('game.otui')
|
2012-01-15 22:19:52 +01:00
|
|
|
|
2012-02-06 05:39:52 +01:00
|
|
|
--Keyboard.bindKeyPress('Up', function() Game.walk(North) end)
|
|
|
|
--Keyboard.bindKeyPress('Down', function() Game.walk(South) end)
|
|
|
|
--Keyboard.bindKeyPress('Left', function() Game.walk(West) end)
|
|
|
|
--Keyboard.bindKeyPress('Right', function() Game.walk(East) end)
|
2012-01-15 22:19:52 +01:00
|
|
|
|
2012-02-06 05:39:52 +01:00
|
|
|
Keyboard.bindKeyPress('Ctrl+Shift+Up', function() Game.forceWalk(North) end)
|
|
|
|
Keyboard.bindKeyPress('Ctrl+Shift+Down', function() Game.forceWalk(South) end)
|
|
|
|
Keyboard.bindKeyPress('Ctrl+Shift+Left', function() Game.forceWalk(West) end)
|
|
|
|
Keyboard.bindKeyPress('Ctrl+Shift+Right', function() Game.forceWalk(East) end)
|
2012-01-15 22:19:52 +01:00
|
|
|
|
2012-01-03 01:42:53 +01:00
|
|
|
rootWidget:moveChildToIndex(Game.gameUi, 1)
|
2012-01-13 21:37:44 +01:00
|
|
|
Game.gameMapPanel = Game.gameUi:getChildById('gameMapPanel')
|
|
|
|
Game.gameRightPanel = Game.gameUi:getChildById('gameRightPanel')
|
|
|
|
Game.gameBottomPanel = Game.gameUi:getChildById('gameBottomPanel')
|
2012-01-24 19:39:16 +01:00
|
|
|
m_mouseGrabberWidget = Game.gameUi:getChildById('mouseGrabber')
|
|
|
|
connect(Game.gameUi, { onKeyPress = onGameKeyPress })
|
|
|
|
connect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease })
|
2011-08-29 05:44:02 +02:00
|
|
|
end
|
|
|
|
|
2011-11-03 21:54:53 +01:00
|
|
|
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
|
2011-08-29 16:14:21 +02:00
|
|
|
end
|
2011-11-03 21:54:53 +01:00
|
|
|
Background.show()
|
|
|
|
CharacterList.show()
|
2011-08-29 16:14:21 +02:00
|
|
|
end
|
|
|
|
|
2011-11-03 10:59:11 +01:00
|
|
|
function Game.show()
|
|
|
|
Game.gameUi:show()
|
|
|
|
Game.gameUi:focus()
|
2011-11-03 13:17:10 +01:00
|
|
|
Game.gameMapPanel:focus()
|
2011-11-03 10:59:11 +01:00
|
|
|
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)
|
2012-02-06 20:19:47 +01:00
|
|
|
connect(errorBox, { onOk = CharacterList.show })
|
2011-08-30 01:20:30 +02:00
|
|
|
end
|
|
|
|
|
2011-08-29 20:38:01 +02:00
|
|
|
function Game.onConnectionError(message)
|
|
|
|
CharacterList.destroyLoadBox()
|
|
|
|
local errorBox = displayErrorBox("Login Error", "Connection error: " .. message)
|
2012-02-06 20:19:47 +01:00
|
|
|
connect(errorBox, { onOk = CharacterList.show })
|
2011-08-29 20:38:01 +02:00
|
|
|
end
|
|
|
|
|
2012-01-07 06:35:50 +01:00
|
|
|
local function onApplicationClose()
|
|
|
|
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)
|
2012-02-08 00:54:33 +01:00
|
|
|
connect(Game, { onGameStart = Game.createInterface }, true)
|
|
|
|
connect(Game, { onGameEnd = Game.destroyInterface })
|