Fixes to trade npc module:

* Will now update player goods on inventory change
* Sell all no longer shows inventory items when ignore is checked
* Sell all tooltip now updates properly
* Will tell you the sell all total
This commit is contained in:
BeniS 2013-02-21 00:19:30 +13:00
parent 88c59afb8c
commit f4c7d98bd5
1 changed files with 34 additions and 16 deletions

View File

@ -41,6 +41,7 @@ selectedItem = nil
cancelNextRelease = nil cancelNextRelease = nil
function init() function init()
connect(LocalPlayer, {onInventoryChange = refreshPlayerGoods})
npcWindow = g_ui.displayUI('npctrade') npcWindow = g_ui.displayUI('npctrade')
npcWindow:setVisible(false) npcWindow:setVisible(false)
@ -353,6 +354,8 @@ end
function refreshPlayerGoods() function refreshPlayerGoods()
if not initialized then return end if not initialized then return end
checkSellAllTooltip()
moneyLabel:setText(formatCurrency(playerMoney)) moneyLabel:setText(formatCurrency(playerMoney))
capacityLabel:setText(string.format('%.2f', playerFreeCapacity) .. ' ' .. WEIGHT_UNIT) capacityLabel:setText(string.format('%.2f', playerFreeCapacity) .. ' ' .. WEIGHT_UNIT)
@ -436,21 +439,6 @@ function onPlayerGoods(money, items)
end end
end end
local first = true
local info = ''
for key, amount in pairs(playerItems) do
if amount > 0 then
local data = getTradeItemData(key, SELL)
if data then
info = info..(not first and "\n" or "")..amount.." "..data.name.." ("..data.price*amount.." gold)"
if first then first = false end
end
end
end
if info ~= '' then
sellAllButton:setTooltip(info)
end
refreshPlayerGoods() refreshPlayerGoods()
end end
@ -491,6 +479,36 @@ function getTradeItemData(id, type)
return false return false
end end
function checkSellAllTooltip()
sellAllButton:setEnabled(true)
sellAllButton:removeTooltip()
local total = 0
local info = ''
local first = true
for key, amount in pairs(playerItems) do
if amount > 0 then
local data = getTradeItemData(key, SELL)
if data and canTradeItem(data) then
info = info..(not first and "\n" or "")..
amount.." "..
data.name.." ("..
data.price*amount.." gold)"
total = total+(data.price*amount)
if first then first = false end
end
end
end
if info ~= '' then
info = info.."\nTotal: "..total.." gold"
sellAllButton:setTooltip(info)
else
sellAllButton:setEnabled(false)
end
end
function formatCurrency(amount) function formatCurrency(amount)
if CURRENCY_DECIMAL then if CURRENCY_DECIMAL then
return string.format("%.02f", amount/100.0) .. ' ' .. CURRENCY return string.format("%.02f", amount/100.0) .. ' ' .. CURRENCY