mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
trade working
* use only mouse left release in checkboxes * remvoe duplicated code in radiogroup * implement player trade
This commit is contained in:
@@ -7,26 +7,55 @@ PlayerTrade = {}
|
||||
local tradeWindow
|
||||
|
||||
local function createTrade()
|
||||
if tradeWindow then
|
||||
tradeWindow:destroy()
|
||||
tradeWindow = nil
|
||||
tradeWindow = createWidget('TradeWindow', GameInterface.getRightPanel())
|
||||
tradeWindow.onClose = function()
|
||||
g_game.rejectTrade()
|
||||
tradeWindow:hide()
|
||||
end
|
||||
end
|
||||
|
||||
local function fillTrade(name, items, counter)
|
||||
if not tradeWindow then
|
||||
createTrade()
|
||||
end
|
||||
|
||||
tradeWindow = createWidget('TradeWindow', rootWidget)
|
||||
end
|
||||
|
||||
local function onOwnTrade(name, items)
|
||||
local firstItem = items[1]
|
||||
|
||||
local tradeItemWidget = tradeWindow:getChildById('tradeItem')
|
||||
tradeItemWidget:setItem(firstItem)
|
||||
tradeItemWidget:setItemId(items[1]:getId())
|
||||
|
||||
local tradeContainer
|
||||
local label
|
||||
if counter then
|
||||
tradeContainer = tradeWindow:recursiveGetChildById('counterTradeContainer')
|
||||
label = tradeWindow:recursiveGetChildById('counterTradeLabel')
|
||||
|
||||
tradeWindow:recursiveGetChildById('acceptButton'):enable()
|
||||
else
|
||||
tradeContainer = tradeWindow:recursiveGetChildById('ownTradeContainer')
|
||||
label = tradeWindow:recursiveGetChildById('ownTradeLabel')
|
||||
end
|
||||
label:setText(name)
|
||||
|
||||
for index,item in ipairs(items) do
|
||||
local itemWidget = createWidget('Item', tradeContainer)
|
||||
itemWidget:setItem(item)
|
||||
itemWidget:setVirtual(true)
|
||||
itemWidget:setMargin(1)
|
||||
itemWidget.onClick = function()
|
||||
g_game.inspectTrade(counter, index-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function onCounterTrade(name, items)
|
||||
|
||||
local function onGameOwnTrade(name, items)
|
||||
fillTrade(name, items, false)
|
||||
end
|
||||
|
||||
local function onCloseTrade()
|
||||
local function onGameCounterTrade(name, items)
|
||||
fillTrade(name, items, true)
|
||||
end
|
||||
|
||||
local function onGameCloseTrade()
|
||||
if not tradeWindow then return end
|
||||
tradeWindow:destroy()
|
||||
tradeWindow = nil
|
||||
end
|
||||
@@ -36,11 +65,18 @@ function PlayerTrade.init()
|
||||
|
||||
connect(g_game, { onOwnTrade = onGameOwnTrade,
|
||||
onCounterTrade = onGameCounterTrade,
|
||||
onCloseTrade = onGameCloseTrade })
|
||||
onCloseTrade = onGameCloseTrade,
|
||||
onGameEnd = onGameCloseTrade })
|
||||
end
|
||||
|
||||
function PlayerTrade.terminate()
|
||||
disconnect(g_game, { onOwnTrade = onGameOwnTrade,
|
||||
onCounterTrade = onGameCounterTrade,
|
||||
onCloseTrade = onGameCloseTrade })
|
||||
onCloseTrade = onGameCloseTrade,
|
||||
onGameEnd = onGameCloseTrade })
|
||||
|
||||
if tradeWindow then
|
||||
tradeWindow:destroy()
|
||||
tradeWindow = nil
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user