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-01 08:36:32 +01:00
|
|
|
if not item then return true end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
|
|
|
self:setBorderWidth(1)
|
2012-01-20 03:48:38 +01:00
|
|
|
|
2012-01-26 02:11:05 +01:00
|
|
|
self.parsed = false
|
2012-01-20 02:12:26 +01:00
|
|
|
self.currentDragThing = item
|
2012-02-06 05:39:52 +01:00
|
|
|
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-01-26 02:11:05 +01:00
|
|
|
if not self.parsed then
|
|
|
|
self.currentDragThing = nil
|
|
|
|
end
|
2012-02-01 08:36:32 +01:00
|
|
|
|
2012-02-06 05:39:52 +01:00
|
|
|
Mouse.restoreCursor()
|
2012-01-24 19:39:16 +01:00
|
|
|
self:setBorderWidth(0)
|
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
|
|
|
|
|
|
|
|
if not widget or not widget.currentDragThing then return true end
|
2012-01-20 03:48:38 +01:00
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
local pos = self.position
|
2012-02-02 17:37:52 +01:00
|
|
|
local count = widget.currentDragThing:getCount()
|
|
|
|
if widget.currentDragThing:isStackable() and count > 1 then
|
2012-01-26 02:11:05 +01:00
|
|
|
widget.parsed = true
|
|
|
|
local moveWindow = displayUI('/game/movewindow.otui')
|
|
|
|
local spinbox = moveWindow:getChildById('spinbox')
|
2012-02-02 17:37:52 +01:00
|
|
|
spinbox:setMaximum(count)
|
2012-01-26 02:11:05 +01:00
|
|
|
spinbox:setMinimum(1)
|
2012-02-02 17:37:52 +01:00
|
|
|
spinbox:setCurrentIndex(count)
|
2012-02-01 08:36:32 +01:00
|
|
|
|
2012-01-26 02:11:05 +01:00
|
|
|
local okButton = moveWindow:getChildById('buttonOk')
|
2012-02-08 22:23:15 +01:00
|
|
|
okButton.onClick = function() g_game.move(widget.currentDragThing, pos, spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
|
2012-01-26 02:11:05 +01:00
|
|
|
moveWindow.onEnter = okButton.onClick
|
|
|
|
else
|
2012-02-08 22:23:15 +01:00
|
|
|
g_game.move(widget.currentDragThing, pos, 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-01-24 19:39:16 +01:00
|
|
|
function UIItem:onHoverChange(hovered)
|
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)
|
|
|
|
else
|
|
|
|
self:setBorderWidth(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-13 01:31:39 +01:00
|
|
|
function UIItem:onMouseRelease(mousePosition, mouseButton)
|
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-02-08 22:23:15 +01:00
|
|
|
return g_game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item)
|
2012-01-13 01:31:39 +01:00
|
|
|
end
|
|
|
|
|