request trade

This commit is contained in:
Henrique Santiago 2012-04-24 19:09:48 -03:00
parent 49fbbf6506
commit 9afe4e012b
1 changed files with 36 additions and 10 deletions

View File

@ -18,7 +18,7 @@ function GameInterface.init()
gameRootPanel:lower() gameRootPanel:lower()
mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber') mouseGrabberWidget = gameRootPanel:getChildById('mouseGrabber')
mouseGrabberWidget.onMouseRelease = GameInterface.onUseWithMouseRelease mouseGrabberWidget.onMouseRelease = GameInterface.onMouseGrabberRelease
gameMapPanel = gameRootPanel:getChildById('gameMapPanel') gameMapPanel = gameRootPanel:getChildById('gameMapPanel')
gameRightPanel = gameRootPanel:getChildById('gameRightPanel') gameRightPanel = gameRootPanel:getChildById('gameRightPanel')
@ -104,28 +104,54 @@ function GameInterface.tryLogout()
end end
end end
function GameInterface.onUseWithMouseRelease(self, mousePosition, mouseButton) function GameInterface.onMouseGrabberRelease(self, mousePosition, mouseButton)
if GameInterface.selectedThing == nil then return false end if GameInterface.selectedThing == nil then return false end
if mouseButton == MouseLeftButton then if mouseButton == MouseLeftButton then
local clickedWidget = gameRootPanel:recursiveGetChildByPos(mousePosition, false) local clickedWidget = gameRootPanel:recursiveGetChildByPos(mousePosition, false)
if clickedWidget then if clickedWidget then
if clickedWidget:getClassName() == 'UIMap' then if GameInterface.selectedType == 'use' then
local tile = clickedWidget:getTile(mousePosition) GameInterface.onUseWith(clickedWidget, mousePosition)
if tile then elseif GameInterface.selectedType == 'trade' then
g_game.useWith(GameInterface.selectedThing, tile:getTopMultiUseThing()) GameInterface.onTradeWith(clickedWidget, mousePosition)
end
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
g_game.useWith(GameInterface.selectedThing, clickedWidget:getItem())
end end
end end
end end
GameInterface.selectedThing = nil GameInterface.selectedThing = nil
Mouse.restoreCursor() Mouse.restoreCursor()
self:ungrabMouse() self:ungrabMouse()
return true return true
end end
function GameInterface.onUseWith(clickedWidget, mousePosition)
if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
g_game.useWith(GameInterface.selectedThing, tile:getTopMultiUseThing())
elseif clickedWidget:getClassName() == 'UIItem' and not clickedWidget:isVirtual() then
g_game.useWith(GameInterface.selectedThing, clickedWidget:getItem())
end
end
end
function GameInterface.onTradeWith(clickedWidget, mousePosition)
if clickedWidget:getClassName() == 'UIMap' then
local tile = clickedWidget:getTile(mousePosition)
if tile then
g_game.requestTrade(GameInterface.selectedThing, tile:getTopCreature())
end
end
end
function GameInterface.startUseWith(thing) function GameInterface.startUseWith(thing)
GameInterface.selectedType = 'use'
GameInterface.selectedThing = thing
mouseGrabberWidget:grabMouse()
Mouse.setTargetCursor()
end
function GameInterface.startTradeWith(thing)
GameInterface.selectedType = 'trade'
GameInterface.selectedThing = thing GameInterface.selectedThing = thing
mouseGrabberWidget:grabMouse() mouseGrabberWidget:grabMouse()
Mouse.setTargetCursor() Mouse.setTargetCursor()
@ -162,7 +188,7 @@ function GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatu
if lookThing and not lookThing:asCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then if lookThing and not lookThing:asCreature() and not lookThing:isNotMoveable() and lookThing:isPickupable() then
menu:addSeparator() menu:addSeparator()
menu:addOption('Trade with ...', function() print('trade with') end) menu:addOption('Trade with ...', function() GameInterface.startTradeWith(lookThing) end)
end end
if lookThing then if lookThing then