2012-01-20 02:12:26 +01:00
|
|
|
function UIItem:onDragEnter(mousePos)
|
2012-02-01 08:36:32 +01:00
|
|
|
if self:isVirtual() then return false end
|
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
local item = self:getItem()
|
2012-02-09 19:38:50 +01:00
|
|
|
if not item then return false end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
|
|
|
self:setBorderWidth(1)
|
2012-01-20 02:12:26 +01:00
|
|
|
self.currentDragThing = item
|
2012-06-26 00:13:30 +02:00
|
|
|
g_mouse.setTargetCursor()
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-02-07 01:41:53 +01:00
|
|
|
function UIItem:onDragLeave(droppedWidget, mousePos)
|
2012-02-01 08:36:32 +01:00
|
|
|
if self:isVirtual() then return false end
|
2012-03-29 15:45:40 +02:00
|
|
|
self.currentDragThing = nil
|
2012-06-26 00:13:30 +02:00
|
|
|
g_mouse.restoreCursor()
|
2012-01-24 19:39:16 +01:00
|
|
|
self:setBorderWidth(0)
|
2012-08-08 17:08:18 +02:00
|
|
|
self.hoveredWho = nil
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIItem:onDrop(widget, mousePos)
|
2012-02-01 08:36:32 +01:00
|
|
|
if self:isVirtual() then return false end
|
|
|
|
|
2012-03-28 16:10:21 +02:00
|
|
|
if not widget or not widget.currentDragThing then return false end
|
2012-01-20 03:48:38 +01:00
|
|
|
|
2012-07-12 19:29:44 +02:00
|
|
|
local item = widget.currentDragThing
|
2012-07-30 10:51:03 +02:00
|
|
|
if not item:isItem() then return false end
|
|
|
|
|
2012-03-29 15:45:40 +02:00
|
|
|
local toPos = self.position
|
2012-04-07 00:31:45 +02:00
|
|
|
|
2012-07-12 19:29:44 +02:00
|
|
|
local itemPos = item:getPosition()
|
|
|
|
if itemPos.x == toPos.x and itemPos.y == toPos.y and itemPos.z == toPos.z then return false end
|
2012-04-07 00:31:45 +02:00
|
|
|
|
2012-07-12 19:29:44 +02:00
|
|
|
if item:getCount() > 1 then
|
2012-07-24 07:30:08 +02:00
|
|
|
modules.game_interface.moveStackableItem(item, toPos)
|
2012-01-26 02:11:05 +01:00
|
|
|
else
|
2012-07-12 19:29:44 +02:00
|
|
|
g_game.move(item, toPos, 1)
|
2012-01-26 02:11:05 +01:00
|
|
|
end
|
2012-01-20 03:48:38 +01:00
|
|
|
|
2012-01-24 19:39:16 +01:00
|
|
|
self:setBorderWidth(0)
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-08-08 17:08:18 +02:00
|
|
|
function UIItem:onDestroy()
|
|
|
|
if self == g_ui.getDraggingWidget() and self.hoveredWho then
|
|
|
|
self.hoveredWho:setBorderWidth(0)
|
|
|
|
self.hoveredWho = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-24 19:39:16 +01:00
|
|
|
function UIItem:onHoverChange(hovered)
|
2012-06-08 05:02:06 +02:00
|
|
|
UIWidget.onHoverChange(self, hovered)
|
2012-06-08 18:58:08 +02:00
|
|
|
|
2012-02-01 08:36:32 +01:00
|
|
|
if self:isVirtual() then return end
|
|
|
|
|
2012-02-07 03:06:48 +01:00
|
|
|
local draggingWidget = g_ui.getDraggingWidget()
|
|
|
|
if draggingWidget and self ~= draggingWidget then
|
|
|
|
local gotMap = draggingWidget:getClassName() == 'UIMap'
|
|
|
|
local gotItem = draggingWidget:getClassName() == 'UIItem' and not draggingWidget:isVirtual()
|
|
|
|
if hovered and (gotItem or gotMap) then
|
2012-01-24 19:39:16 +01:00
|
|
|
self:setBorderWidth(1)
|
2012-08-08 17:08:18 +02:00
|
|
|
draggingWidget.hoveredWho = self
|
2012-01-24 19:39:16 +01:00
|
|
|
else
|
|
|
|
self:setBorderWidth(0)
|
2012-08-08 17:08:18 +02:00
|
|
|
draggingWidget.hoveredWho = nil
|
2012-01-24 19:39:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-13 01:31:39 +01:00
|
|
|
function UIItem:onMouseRelease(mousePosition, mouseButton)
|
2012-04-05 01:04:42 +02:00
|
|
|
if self.cancelNextRelease then
|
|
|
|
self.cancelNextRelease = false
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-02-01 08:36:32 +01:00
|
|
|
if self:isVirtual() then return false end
|
|
|
|
|
2012-01-13 01:31:39 +01:00
|
|
|
local item = self:getItem()
|
|
|
|
if not item or not self:containsPoint(mousePosition) then return false end
|
2012-04-05 01:04:42 +02:00
|
|
|
|
|
|
|
if Options.getOption('classicControl') and
|
2012-06-26 00:13:30 +02:00
|
|
|
((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or
|
|
|
|
(g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
|
2012-04-05 01:04:42 +02:00
|
|
|
g_game.look(item)
|
|
|
|
self.cancelNextRelease = true
|
|
|
|
return true
|
2012-07-24 07:30:08 +02:00
|
|
|
elseif modules.game_interface.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) then
|
2012-04-05 01:04:42 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
2012-01-13 01:31:39 +01:00
|
|
|
end
|
|
|
|
|