bags: introduce GetBagFamily function

This commit is contained in:
shagu
2017-09-24 20:21:45 +02:00
parent cb75a3e71a
commit bf514590af
2 changed files with 25 additions and 17 deletions
+22
View File
@@ -124,6 +124,28 @@ function pfUI.api.GetItemCount(itemName)
return count
end
-- [ GetBagFamily ]
-- Returns information about the type of a bag such as Soul Bags or Quivers.
-- Available bagtypes are "BAG", "KEYRING", "SOULBAG", "QUIVER" and "SPECIAL"
-- 'bag' [int] the bag id
-- returns: [string] the type of the bag, e.g "QUIVER"
function pfUI.api.GetBagFamily(bag)
if bag == -2 then return "KEYRING" end
local _, _, id = strfind(GetInventoryItemLink("player", ContainerIDToInventoryID(bag)) or "", "item:(%d+)")
if id then
local _, _, _, _, itemType, subType = GetItemInfo(id)
local bagtype = L["bagtypes"][itemType]
local bagsubtype = L["bagtypes"][subType]
if bagsubtype == "SOULBAG" then return "SOULBAG" end
if bagsubtype == "QUIVER" then return "QUIVER" end
if not bagtype and not bagsubtype then return "SPECIAL" end
end
return "BAG"
end
-- [ Abbreviate ]
-- Abbreviates a number from 1234 to 1.23k
-- 'number' [number] the number that should be abbreviated
+3 -17
View File
@@ -309,21 +309,7 @@ pfUI:RegisterModule("bags", function ()
if quality and quality > tonumber(C.appearance.bags.borderlimit) then
pfUI.bags[bag].slots[slot].frame.backdrop:SetBackdropBorderColor(GetItemQualityColor(quality))
else
local bagtype
if bag > 0 then
local _, _, id = strfind(GetInventoryItemLink("player", ContainerIDToInventoryID(bag)) or "", "item:(%d+)")
if id then
local _, _, _, _, itemType, subType = GetItemInfo(id)
bagtype = L["bagtypes"][itemType]
bagsubtype = L["bagtypes"][subType]
if bagsubtype == "SOULBAG" then
bagtype = "SOULBAG"
elseif not (bagsubtype and bagsubtype == "DEFAULT") and bagtype ~= "QUIVER" and bagtype ~= "SOULBAG" then
bagtype = "SPECIAL"
end
end
end
local bagtype = GetBagFamily(bag)
if bagtype == "QUIVER" then
pfUI.bags[bag].slots[slot].frame.backdrop:SetBackdropBorderColor(.8,.8,.2,1)
@@ -331,9 +317,9 @@ pfUI:RegisterModule("bags", function ()
pfUI.bags[bag].slots[slot].frame.backdrop:SetBackdropBorderColor(.5,.2,.2,1)
elseif bagtype == "SPECIAL" then
pfUI.bags[bag].slots[slot].frame.backdrop:SetBackdropBorderColor(.2,.2,.8,1)
elseif bag == -2 then
elseif bagtype == "KEYRING" then
pfUI.bags[bag].slots[slot].frame.backdrop:SetBackdropBorderColor(.2,.8,.8,1)
else
elseif bagtype == "BAG" then
pfUI.bags[bag].slots[slot].frame.backdrop:SetBackdropBorderColor(.3,.3,.3,1)
end
end