2012-01-20 02:12:26 +01:00
|
|
|
function UIItem:onDragEnter(mousePos)
|
|
|
|
local item = self:getItem()
|
|
|
|
if not item then return false 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
|
|
|
|
setTargetCursor()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function UIItem:onDragLeave(widget, mousePos)
|
2012-01-26 02:11:05 +01:00
|
|
|
if not self.parsed then
|
|
|
|
self.currentDragThing = nil
|
|
|
|
end
|
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
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)
|
|
|
|
if not widget or not widget.currentDragThing then return false end
|
2012-01-20 03:48:38 +01:00
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
local pos = self.position
|
2012-01-26 02:11:05 +01:00
|
|
|
local data = widget.currentDragThing:getData()
|
|
|
|
if widget.currentDragThing:isStackable() and data > 1 then
|
|
|
|
widget.parsed = true
|
|
|
|
local moveWindow = displayUI('/game/movewindow.otui')
|
|
|
|
local spinbox = moveWindow:getChildById('spinbox')
|
|
|
|
spinbox:setMaximum(data)
|
|
|
|
spinbox:setMinimum(1)
|
|
|
|
spinbox:setCurrentIndex(data)
|
|
|
|
|
|
|
|
local okButton = moveWindow:getChildById('buttonOk')
|
|
|
|
okButton.onClick = function() Game.move(widget.currentDragThing, pos, spinbox:getCurrentIndex()) okButton:getParent():destroy() widget.currentDragThing = nil end
|
|
|
|
moveWindow.onEnter = okButton.onClick
|
|
|
|
else
|
|
|
|
Game.move(widget.currentDragThing, pos, 1)
|
|
|
|
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)
|
|
|
|
if g_ui.getDraggingWidget() and self ~= g_ui.getDraggingWidget() then
|
|
|
|
if hovered then
|
|
|
|
self:setBorderWidth(1)
|
|
|
|
else
|
|
|
|
self:setBorderWidth(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-13 01:31:39 +01:00
|
|
|
function UIItem:onMouseRelease(mousePosition, mouseButton)
|
|
|
|
local item = self:getItem()
|
|
|
|
if not item or not self:containsPoint(mousePosition) then return false end
|
|
|
|
return Game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item)
|
|
|
|
end
|
|
|
|
|