2012-03-18 14:34:39 +01:00
|
|
|
UIGameMap = extends(UIMap)
|
|
|
|
|
|
|
|
function UIGameMap.create()
|
|
|
|
local gameMap = UIGameMap.internalCreate()
|
2012-04-07 01:12:46 +02:00
|
|
|
gameMap:setKeepAspectRatio(true)
|
|
|
|
gameMap:setVisibleDimension({width = 15, height = 11})
|
2012-03-18 14:34:39 +01:00
|
|
|
return gameMap
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIGameMap:onDragEnter(mousePos)
|
2012-01-20 03:33:11 +01:00
|
|
|
local tile = self:getTile(mousePos)
|
2012-01-20 02:12:26 +01:00
|
|
|
if not tile then return false end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
local thing = tile:getTopMoveThing()
|
|
|
|
if not thing then return false end
|
2012-01-20 03:33:11 +01:00
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
self.currentDragThing = thing
|
2012-06-26 00:13:30 +02:00
|
|
|
g_mouse.setTargetCursor()
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
function UIGameMap:onDragLeave(droppedWidget, mousePos)
|
2012-03-29 15:45:40 +02:00
|
|
|
self.currentDragThing = nil
|
2012-08-13 01:27:41 +02:00
|
|
|
self.hoveredWho = nil
|
2012-06-26 00:13:30 +02:00
|
|
|
g_mouse.restoreCursor()
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
function UIGameMap:onDrop(widget, mousePos)
|
2012-08-17 23:36:53 +02:00
|
|
|
if not self:canAcceptDrop(widget, mousePos) then return false end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
2012-01-21 02:01:11 +01:00
|
|
|
local tile = self:getTile(mousePos)
|
|
|
|
if not tile then return false end
|
2012-02-02 17:37:52 +01:00
|
|
|
|
2012-04-29 11:08:55 +02:00
|
|
|
local thing = widget.currentDragThing
|
2012-03-29 15:45:40 +02:00
|
|
|
local toPos = tile:getPosition()
|
2012-04-07 00:31:45 +02:00
|
|
|
|
2012-07-12 18:45:22 +02:00
|
|
|
local thingPos = thing:getPosition()
|
|
|
|
if thingPos.x == toPos.x and thingPos.y == toPos.y and thingPos.z == toPos.z then return false end
|
2012-04-07 00:31:45 +02:00
|
|
|
|
2012-07-29 05:34:40 +02:00
|
|
|
if thing:isItem() and thing:getCount() > 1 then
|
2012-07-24 07:30:08 +02:00
|
|
|
modules.game_interface.moveStackableItem(thing, toPos)
|
2012-01-26 02:11:05 +01:00
|
|
|
else
|
2012-04-29 11:08:55 +02:00
|
|
|
g_game.move(thing, toPos, 1)
|
2012-01-26 02:11:05 +01:00
|
|
|
end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-07-05 07:40:21 +02:00
|
|
|
function UIGameMap:onMousePress()
|
|
|
|
self.cancelNextRelease = false
|
|
|
|
end
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
function UIGameMap:onMouseRelease(mousePosition, mouseButton)
|
2012-03-29 15:45:40 +02:00
|
|
|
if self.cancelNextRelease then
|
|
|
|
self.cancelNextRelease = false
|
|
|
|
return true
|
|
|
|
end
|
2012-08-22 16:21:02 +02:00
|
|
|
|
2012-08-21 03:03:30 +02:00
|
|
|
local autoWalkPos = self:getPosition(mousePosition)
|
2012-08-22 16:21:02 +02:00
|
|
|
|
2012-08-21 13:09:48 +02:00
|
|
|
-- happens when clicking outside of map boundaries
|
|
|
|
if not autoWalkPos then return false end
|
2012-08-22 16:21:02 +02:00
|
|
|
|
|
|
|
local localPlayerPos = g_game.getLocalPlayer():getPosition()
|
2012-07-05 07:40:21 +02:00
|
|
|
if autoWalkPos.z ~= localPlayerPos.z then
|
|
|
|
local dz = autoWalkPos.z - localPlayerPos.z
|
|
|
|
autoWalkPos.x = autoWalkPos.x + dz
|
|
|
|
autoWalkPos.y = autoWalkPos.y + dz
|
|
|
|
autoWalkPos.z = localPlayerPos.z
|
|
|
|
end
|
|
|
|
|
2012-08-21 03:03:30 +02:00
|
|
|
local lookThing
|
|
|
|
local useThing
|
|
|
|
local creatureThing
|
|
|
|
local multiUseThing
|
|
|
|
|
2012-08-22 16:21:02 +02:00
|
|
|
local tile = self:getTile(mousePosition)
|
2012-08-21 03:03:30 +02:00
|
|
|
if tile then
|
|
|
|
lookThing = tile:getTopLookThing()
|
|
|
|
useThing = tile:getTopUseThing()
|
|
|
|
creatureThing = tile:getTopCreature()
|
|
|
|
multiUseThing = tile:getTopMultiUseThing()
|
|
|
|
end
|
2012-07-05 07:40:21 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
local ret = modules.game_interface.processMouseAction(mousePosition, mouseButton, autoWalkPos, lookThing, useThing, creatureThing, multiUseThing)
|
2012-07-05 07:40:21 +02:00
|
|
|
if ret then
|
2012-03-29 15:45:40 +02:00
|
|
|
self.cancelNextRelease = true
|
2012-03-23 15:48:00 +01:00
|
|
|
end
|
2012-07-05 07:40:21 +02:00
|
|
|
|
|
|
|
return ret
|
2012-01-09 19:06:16 +01:00
|
|
|
end
|
2012-08-17 23:36:53 +02:00
|
|
|
|
|
|
|
function UIGameMap:canAcceptDrop(widget, mousePos)
|
|
|
|
if not widget or not widget.currentDragThing then return false end
|
|
|
|
|
|
|
|
local children = rootWidget:recursiveGetChildrenByPos(mousePos)
|
|
|
|
for i=1,#children do
|
|
|
|
local child = children[i]
|
|
|
|
if child == self then
|
|
|
|
return true
|
|
|
|
elseif not child:isPhantom() then
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
error('Widget ' .. self:getId() .. ' not in drop list.')
|
|
|
|
return false
|
|
|
|
end
|