2012-03-18 14:34:39 +01:00
|
|
|
UIGameMap = extends(UIMap)
|
|
|
|
|
|
|
|
function UIGameMap.create()
|
|
|
|
local gameMap = UIGameMap.internalCreate()
|
|
|
|
return gameMap
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function UIGameMap:onDragEnter(mousePos)
|
2012-01-20 03:33:11 +01:00
|
|
|
local tile = self:getTile(mousePos)
|
2012-01-20 02:12:26 +01:00
|
|
|
if not tile then return false end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
local thing = tile:getTopMoveThing()
|
|
|
|
if not thing then return false end
|
2012-01-20 03:33:11 +01:00
|
|
|
|
2012-01-26 02:11:05 +01:00
|
|
|
self.parsed = false
|
2012-01-20 02:12:26 +01:00
|
|
|
self.currentDragThing = thing
|
2012-02-06 05:39:52 +01:00
|
|
|
Mouse.setTargetCursor()
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
function UIGameMap:onDragLeave(droppedWidget, mousePos)
|
2012-01-26 02:11:05 +01:00
|
|
|
if not self.parsed then
|
|
|
|
self.currentDragThing = nil
|
|
|
|
end
|
2012-02-02 17:37:52 +01:00
|
|
|
|
2012-02-06 05:39:52 +01:00
|
|
|
Mouse.restoreCursor()
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
function UIGameMap:onDrop(widget, mousePos)
|
2012-01-20 02:12:26 +01:00
|
|
|
if not widget or not widget.currentDragThing then return false end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
2012-01-21 02:01:11 +01:00
|
|
|
local tile = self:getTile(mousePos)
|
|
|
|
if not tile then return false end
|
2012-02-02 17:37:52 +01:00
|
|
|
|
|
|
|
local count = widget.currentDragThing:getCount()
|
2012-02-07 03:06:48 +01:00
|
|
|
if widget.currentDragThing:isStackable() and count > 1 then
|
2012-01-26 02:11:05 +01:00
|
|
|
widget.parsed = true
|
2012-03-18 14:34:39 +01:00
|
|
|
local moveWindow = createWidget('CountWindow', rootWidget)
|
2012-01-26 02:11:05 +01:00
|
|
|
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-01-26 02:11:05 +01:00
|
|
|
local okButton = moveWindow:getChildById('buttonOk')
|
2012-02-08 23:58:27 +01:00
|
|
|
okButton.onClick = function()
|
2012-03-18 14:34:39 +01:00
|
|
|
g_game.move(widget.currentDragThing, tile:getPosition(), 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, tile:getPosition(), 1)
|
2012-01-26 02:11:05 +01:00
|
|
|
end
|
2012-01-24 19:39:16 +01:00
|
|
|
|
2012-01-20 02:12:26 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2012-03-18 14:34:39 +01:00
|
|
|
function UIGameMap:onMouseRelease(mousePosition, mouseButton)
|
2012-01-09 21:54:37 +01:00
|
|
|
local tile = self:getTile(mousePosition)
|
2012-03-23 15:48:00 +01:00
|
|
|
if tile == nil then return false end
|
|
|
|
if GameInterface.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then
|
|
|
|
return true
|
2012-03-25 19:10:19 +02:00
|
|
|
elseif mouseButton == MouseLeftButton and self:isPressed() then
|
|
|
|
local dirs = g_map.findPath(g_game.getLocalPlayer():getPosition(), tile:getPosition(), 255)
|
|
|
|
if #dirs == 0 then
|
|
|
|
TextMessage.displayStatus('There is no way.')
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
g_game.autoWalk(dirs)
|
|
|
|
return true
|
2012-03-23 15:48:00 +01:00
|
|
|
end
|
2012-01-09 19:06:16 +01:00
|
|
|
return false
|
|
|
|
end
|