84 lines
2.2 KiB
Lua
84 lines
2.2 KiB
Lua
function UIItem:onDragEnter(mousePos)
|
|
if self:isVirtual() then return false end
|
|
|
|
local item = self:getItem()
|
|
if not item then return false end
|
|
|
|
self:setBorderWidth(1)
|
|
self.currentDragThing = item
|
|
g_mouse.setTargetCursor()
|
|
return true
|
|
end
|
|
|
|
function UIItem:onDragLeave(droppedWidget, mousePos)
|
|
if self:isVirtual() then return false end
|
|
self.currentDragThing = nil
|
|
g_mouse.restoreCursor()
|
|
self:setBorderWidth(0)
|
|
return true
|
|
end
|
|
|
|
function UIItem:onDrop(widget, mousePos)
|
|
if self:isVirtual() then return false end
|
|
|
|
if not widget or not widget.currentDragThing then return false end
|
|
|
|
local item = widget.currentDragThing
|
|
if not item:isItem() then return false end
|
|
|
|
local toPos = self.position
|
|
|
|
local itemPos = item:getPosition()
|
|
if itemPos.x == toPos.x and itemPos.y == toPos.y and itemPos.z == toPos.z then return false end
|
|
|
|
if item:getCount() > 1 then
|
|
modules.game_interface.moveStackableItem(item, toPos)
|
|
else
|
|
g_game.move(item, toPos, 1)
|
|
end
|
|
|
|
self:setBorderWidth(0)
|
|
return true
|
|
end
|
|
|
|
function UIItem:onHoverChange(hovered)
|
|
UIWidget.onHoverChange(self, hovered)
|
|
|
|
if self:isVirtual() then return end
|
|
|
|
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
|
|
self:setBorderWidth(1)
|
|
else
|
|
self:setBorderWidth(0)
|
|
end
|
|
end
|
|
end
|
|
|
|
function UIItem:onMouseRelease(mousePosition, mouseButton)
|
|
if self.cancelNextRelease then
|
|
self.cancelNextRelease = false
|
|
return true
|
|
end
|
|
|
|
if self:isVirtual() then return false end
|
|
|
|
local item = self:getItem()
|
|
if not item or not self:containsPoint(mousePosition) then return false end
|
|
|
|
if Options.getOption('classicControl') and
|
|
((g_mouse.isPressed(MouseLeftButton) and mouseButton == MouseRightButton) or
|
|
(g_mouse.isPressed(MouseRightButton) and mouseButton == MouseLeftButton)) then
|
|
g_game.look(item)
|
|
self.cancelNextRelease = true
|
|
return true
|
|
elseif modules.game_interface.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) then
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|