2012-07-24 07:30:08 +02:00
|
|
|
tradeWindow = nil
|
2012-05-01 02:20:27 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function init()
|
|
|
|
g_ui.importStyle('tradewindow.otui')
|
|
|
|
|
|
|
|
connect(g_game, { onOwnTrade = onGameOwnTrade,
|
|
|
|
onCounterTrade = onGameCounterTrade,
|
|
|
|
onCloseTrade = onGameCloseTrade,
|
|
|
|
onGameEnd = onGameCloseTrade })
|
|
|
|
end
|
|
|
|
|
|
|
|
function terminate()
|
|
|
|
disconnect(g_game, { onOwnTrade = onGameOwnTrade,
|
|
|
|
onCounterTrade = onGameCounterTrade,
|
|
|
|
onCloseTrade = onGameCloseTrade,
|
|
|
|
onGameEnd = onGameCloseTrade })
|
2012-05-01 15:06:38 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
if tradeWindow then
|
|
|
|
tradeWindow:destroy()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function createTrade()
|
|
|
|
tradeWindow = g_ui.createWidget('TradeWindow', modules.game_interface.getRightPanel())
|
2012-05-09 14:24:35 +02:00
|
|
|
tradeWindow.onClose = function()
|
|
|
|
g_game.rejectTrade()
|
|
|
|
tradeWindow:hide()
|
2012-05-01 15:06:38 +02:00
|
|
|
end
|
2012-08-24 10:18:15 +02:00
|
|
|
tradeWindow:setup()
|
2012-05-01 15:06:38 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function fillTrade(name, items, counter)
|
2012-05-09 14:24:35 +02:00
|
|
|
if not tradeWindow then
|
|
|
|
createTrade()
|
|
|
|
end
|
2012-05-01 15:06:38 +02:00
|
|
|
|
|
|
|
local tradeItemWidget = tradeWindow:getChildById('tradeItem')
|
2012-05-09 14:24:35 +02:00
|
|
|
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
|
2012-06-26 00:13:30 +02:00
|
|
|
local itemWidget = g_ui.createWidget('Item', tradeContainer)
|
2012-05-09 14:24:35 +02:00
|
|
|
itemWidget:setItem(item)
|
|
|
|
itemWidget:setVirtual(true)
|
2012-08-24 10:18:15 +02:00
|
|
|
itemWidget:setMargin(0)
|
2012-05-09 14:24:35 +02:00
|
|
|
itemWidget.onClick = function()
|
|
|
|
g_game.inspectTrade(counter, index-1)
|
|
|
|
end
|
|
|
|
end
|
2012-05-01 15:06:38 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onGameOwnTrade(name, items)
|
2012-05-09 14:24:35 +02:00
|
|
|
fillTrade(name, items, false)
|
|
|
|
end
|
2012-05-01 15:06:38 +02:00
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onGameCounterTrade(name, items)
|
2012-05-09 14:24:35 +02:00
|
|
|
fillTrade(name, items, true)
|
2012-05-01 15:06:38 +02:00
|
|
|
end
|
|
|
|
|
2012-07-24 07:30:08 +02:00
|
|
|
function onGameCloseTrade()
|
2012-08-24 10:18:15 +02:00
|
|
|
if tradeWindow then
|
|
|
|
tradeWindow:destroy()
|
|
|
|
tradeWindow = nil
|
|
|
|
end
|
2012-05-01 15:06:38 +02:00
|
|
|
end
|