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
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.safeLogout()
|
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)
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.selectedThing == nil then return false end
|
2012-01-24 19:39:16 +01:00
|
|
|
if mouseButton == MouseLeftButton then
|
2012-02-08 22:23:15 +01:00
|
|
|
local clickedWidget = g_game.gameUi:recursiveGetChildByPos(mousePosition)
|
2012-01-24 19:39:16 +01:00
|
|
|
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
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.useWith(g_game.selectedThing, tile:getTopMultiUseThing())
|
2012-01-24 19:39:16 +01:00
|
|
|
end
|
2012-02-01 16:20:13 +01:00
|
|
|
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.useWith(g_game.selectedThing, clickedWidget:getItem())
|
2012-02-09 08:26:52 +01:00
|
|
|
elseif clickedWidget.isBattleButton then
|
|
|
|
g_game.useWith(g_game.selectedThing, clickedWidget.creature)
|
2012-01-24 19:39:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-02-08 22:23:15 +01:00
|
|
|
g_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-02-08 22:23:15 +01:00
|
|
|
function g_game.startUseWith(thing)
|
|
|
|
g_game.selectedThing = thing
|
2012-01-24 19:39:16 +01:00
|
|
|
m_mouseGrabberWidget:grabMouse()
|
2012-02-06 05:39:52 +01:00
|
|
|
Mouse.setTargetCursor()
|
2012-01-24 19:39:16 +01:00
|
|
|
end
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
function g_game.createInterface()
|
2012-01-15 22:19:52 +01:00
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
rootWidget:moveChildToIndex(g_game.gameUi, 1)
|
|
|
|
g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel')
|
|
|
|
g_game.gameRightPanel = g_game.gameUi:getChildById('gameRightPanel')
|
|
|
|
g_game.gameBottomPanel = g_game.gameUi:getChildById('gameBottomPanel')
|
|
|
|
m_mouseGrabberWidget = g_game.gameUi:getChildById('mouseGrabber')
|
|
|
|
connect(g_game.gameUi, { onKeyPress = onGameKeyPress })
|
2012-01-24 19:39:16 +01:00
|
|
|
connect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease })
|
2011-08-29 05:44:02 +02:00
|
|
|
end
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
function g_game.destroyInterface()
|
|
|
|
if g_game.gameUi then
|
|
|
|
g_game.gameUi:destroy()
|
|
|
|
g_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
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
function g_game.show()
|
|
|
|
g_game.gameUi:show()
|
|
|
|
g_game.gameUi:focus()
|
|
|
|
g_game.gameMapPanel:focus()
|
2011-11-03 10:59:11 +01:00
|
|
|
end
|
|
|
|
|
2012-02-08 22:23:15 +01:00
|
|
|
function g_game.hide()
|
|
|
|
g_game.gameUi:hide()
|
2011-11-03 10:59:11 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- hooked events
|
2011-08-29 20:38:01 +02:00
|
|
|
|
2012-01-07 06:35:50 +01:00
|
|
|
local function onApplicationClose()
|
2012-02-08 22:23:15 +01:00
|
|
|
if g_game.isOnline() then
|
|
|
|
g_game.forceLogout()
|
2012-01-07 06:35:50 +01:00
|
|
|
else
|
|
|
|
exit()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
setonclose(onApplicationClose)
|
2012-02-08 22:23:15 +01:00
|
|
|
connect(g_game, { onGameStart = g_game.createInterface }, true)
|
|
|
|
connect(g_game, { onGameEnd = g_game.destroyInterface })
|