new npc trade feature, show only holding items for sell tab

This commit is contained in:
AndreFaramir 2012-04-09 18:50:10 -03:00
parent 1d2f6c7e9f
commit 94984e0795
2 changed files with 23 additions and 4 deletions

View File

@ -24,6 +24,7 @@ local cacheGoods
local buyWithBackpack = false local buyWithBackpack = false
local ignoreCapacity = false local ignoreCapacity = false
local ignoreEquipped = true local ignoreEquipped = true
local showOnlyHolding = false
-- public functions -- public functions
function NPCTrade.init() function NPCTrade.init()
@ -221,6 +222,7 @@ function NPCTrade.itemPopup(self, mousePosition, mouseButton)
menu:addOption((ignoreCapacity and 'Consider capacity' or 'Ignore capacity'), function() ignoreCapacity = not ignoreCapacity return true end) menu:addOption((ignoreCapacity and 'Consider capacity' or 'Ignore capacity'), function() ignoreCapacity = not ignoreCapacity return true end)
else else
menu:addOption((ignoreEquipped and 'Consider equipped' or 'Ignore equipped'), function() ignoreEquipped = not ignoreEquipped return true end) menu:addOption((ignoreEquipped and 'Consider equipped' or 'Ignore equipped'), function() ignoreEquipped = not ignoreEquipped return true end)
menu:addOption((showOnlyHolding and 'Show all items' or 'Show only holding items'), function() showOnlyHolding = not showOnlyHolding NPCTrade.refreshFilters() return true end)
end end
menu:display(mousePosition) menu:display(mousePosition)
end end
@ -261,18 +263,35 @@ function NPCTrade.createItemsOnPanel()
layout:update() layout:update()
end end
function NPCTrade.searchFilter(filter) function NPCTrade.extraFilters(widget, showOnlyHolding)
if setupButton:getText() == 'Sell' then
if not showOnlyHolding or cacheGoods[widget.offer[1]:getId()] then
return true
else
return false
end
end
return true
end
function NPCTrade.refreshFilters()
local filter = searchText:getText()
local items = itemsPanel:getChildCount() local items = itemsPanel:getChildCount()
for i = 1, items do for i = 1, items do
local itemWidget = itemsPanel:getChildByIndex(i) local itemWidget = itemsPanel:getChildByIndex(i)
if filter ~= "" then if filter ~= "" then
if string.find(itemWidget.offer[2], filter) then if string.find(itemWidget.offer[2], filter) and NPCTrade.extraFilters(itemWidget, showOnlyHolding) then
itemWidget:show() itemWidget:show()
else else
itemWidget:hide() itemWidget:hide()
end end
else else
if NPCTrade.extraFilters(itemWidget, showOnlyHolding) then
itemWidget:show() itemWidget:show()
else
itemWidget:hide()
end
end end
end end
end end

View File

@ -97,7 +97,7 @@ MainWindow
anchors.left: prev.right anchors.left: prev.right
anchors.top: prev.top anchors.top: prev.top
margin-left: 5 margin-left: 5
@onTextChange: NPCTrade.searchFilter(self:getText()) @onTextChange: NPCTrade.refreshFilters()
NPCPanel NPCPanel
height: 250 height: 250