function moveStackableItem(item, toPos)
if countWindow then
return
end
if g_keyboard.isCtrlPressed() then
local count = item:getCount()
countWindow = g_ui.createWidget('CountWindow', rootWidget)
local itembox = countWindow:getChildById('item')
local scrollbar = countWindow:getChildById('countScrollBar')
itembox:setItemId(item:getId())
itembox:setItemCount(count)
scrollbar:setMaximum(count)
scrollbar:setMinimum(1)
scrollbar:setValue(count)
local spinbox = countWindow:getChildById('spinBox')
spinbox:setMaximum(count)
spinbox:setMinimum(0)
spinbox:setValue(0)
spinbox:hideButtons()
spinbox:focus()
spinbox.firstEdit = true
local spinBoxValueChange = function(self, value)
spinbox.firstEdit = false
scrollbar:setValue(value)
end
spinbox.onValueChange = spinBoxValueChange
local check = function()
if spinbox.firstEdit then
spinbox:setValue(spinbox:getMaximum())
spinbox.firstEdit = false
end
end
g_keyboard.bindKeyPress("Up", function() check() spinbox:up() end, spinbox)
g_keyboard.bindKeyPress("Down", function() check() spinbox:down() end, spinbox)
g_keyboard.bindKeyPress("Right", function() check() spinbox:up() end, spinbox)
g_keyboard.bindKeyPress("Left", function() check() spinbox:down() end, spinbox)
g_keyboard.bindKeyPress("PageUp", function() check() spinbox:setValue(spinbox:getValue()+10) end, spinbox)
g_keyboard.bindKeyPress("PageDown", function() check() spinbox:setValue(spinbox:getValue()-10) end, spinbox)
scrollbar.onValueChange = function(self, value)
itembox:setItemCount(value)
spinbox.onValueChange = nil
spinbox:setValue(value)
spinbox.onValueChange = spinBoxValueChange
end
local okButton = countWindow:getChildById('buttonOk')
local moveFunc = function()
g_game.move(item, toPos, itembox:getItemCount())
okButton:getParent():destroy()
countWindow = nil
end
local cancelButton = countWindow:getChildById('buttonCancel')
local cancelFunc = function()
cancelButton:getParent():destroy()
countWindow = nil
end
countWindow.onEnter = moveFunc
countWindow.onEscape = cancelFunc
okButton.onClick = moveFunc
cancelButton.onClick = cancelFunc
elseif g_keyboard.isShiftPressed() then
g_game.move(item, toPos, 1)
return
else
g_game.move(item, toPos, item:getCount())
end
end