Skip to content

Commit

Permalink
[Baggins] Fix Bag Count on Classic
Browse files Browse the repository at this point in the history
  • Loading branch information
doadin committed May 10, 2020
1 parent 45a7913 commit 9caa4f4
Showing 1 changed file with 163 additions and 70 deletions.
233 changes: 163 additions & 70 deletions Baggins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2960,7 +2960,26 @@ function Baggins:UpdateItemButton(bagframe,button,bag,slot)
--@end-retail@

--[===[@non-retail@
count = bagtype..LBU:CountSlots(LBU:IsBank(bag) and "BANK" or "BAGS", itemFamily)
if itemFamily == 0 then
-- lbu is screwing this up because it doesn't support classic keyring
-- So we do it manually
freeslots = 0
local startslot, endslot = 0, NUM_BAG_SLOTS
if LBU:IsBank(bag) then
startslot, endslot = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS
else
startslot, endslot = 0, NUM_BAG_SLOTS
end
for i=startslot, endslot do
local freeCount, bagType = GetContainerNumFreeSlots( i )
if bagType == 0 then
freeslots = freeslots + freeCount
end
end
count = bagtype..freeslots
else
count = bagtype..LBU:CountSlots(LBU:IsBank(bag) and "BANK" or "BAGS", itemFamily)
end
--@end-non-retail@]===]
else
count = GetItemCount(itemid)
Expand Down Expand Up @@ -3303,85 +3322,159 @@ end

local texts={}
function Baggins:OnTextUpdate()
local p = self.db.profile
local color

if p.combinecounts then
local normalempty,normaltotal = LBU:CountSlots("BAGS", 0)
local itemFamilies
if p.showspecialcount then
itemFamilies = 2047-256-4-2-1 -- all except keyring, ammo, quiver, soul
else
itemFamilies = 0
end
if p.showammocount then
itemFamilies = itemFamilies +1 +2
end
if p.showsoulcount then
itemFamilies = itemFamilies +4
end

local empty, total = LBU:CountSlots("BAGS", itemFamilies)
empty=empty+normalempty
total=total+normaltotal

local fullness = 1 - (empty/total)
local r, g
r = min(1,fullness * 2)
g = min(1,(1-fullness) *2)
color = ("|cFF%2X%2X00"):format(r*255,g*255)
local p = self.db.profile
local color

if p.combinecounts then
local normalempty, normaltotal = Baggins:CountNormalSlots("BAGS")
local specialempty, specialtotal = 0,0
local e, t

if p.showspecialcount then
e, t = Baggins:CountSpecialSlots("BAGS")
specialempty = specialempty + e
specialtotal = specialtotal + t
end
if p.showammocount then
e, t = Baggins:CountAmmoSlots("BAGS")
specialempty = specialempty + e
specialtotal = specialtotal + t
end
if p.showsoulcount then
e, t = Baggins.CountSoulSlots("BAGS")
specialempty = specialempty + e --luacheck: ignore 311
specialtotal = specialtotal + t --luacheck: ignore 311
end

local empty, total = 0,0
empty=empty+normalempty
total=total+normaltotal

local fullness = 1 - (empty/total)
local r, g
r = min(1,fullness * 2)
g = min(1,(1-fullness) *2)
color = ("|cFF%2X%2X00"):format(r*255,g*255)

self:SetText(self:BuildCountString(empty,total,color))
return
end

-- separate normal/ammo/soul/special counts

local n=0 -- count of strings in texts{}

local normalempty, normaltotal = Baggins:CountNormalSlots("BAGS")

local fullness = 1 - (normalempty/normaltotal)
local r, g
r = min(1,fullness * 2)
g = min(1,(1-fullness) *2)
color = ("|cFF%2X%2X00"):format(r*255,g*255)

n=n+1
texts[n] = self:BuildCountString(normalempty,normaltotal,color)

if self.db.profile.showsoulcount then
local soulempty, soultotal = Baggins:CountSoulSlots("BAGS")
if soultotal>0 then
color = self.colors.purple.hex
n=n+1
texts[n] = self:BuildCountString(soulempty,soultotal,color)
end
end

if self.db.profile.showammocount then
local ammoempty, ammototal = Baggins:CountAmmoSlots("BAGS")
if ammototal>0 then
color = self.colors.white.hex
n=n+1
texts[n] = self:BuildCountString(ammoempty,ammototal,color)
end
end

if self.db.profile.showspecialcount then
local specialempty, specialtotal = Baggins:CountSpecialSlots("BAGS")
if specialtotal>0 then
color = self.colors.blue.hex
n=n+1
texts[n] = self:BuildCountString(specialempty,specialtotal,color)
end
end

if n==1 then
self:SetText(texts[1])
else
self:SetText(tconcat(texts, " ", 1, n))
end
end

function Baggins:CountNormalSlots(which) --luacheck: ignore 212
return LBU:CountSlots(which, 0)
end

function Baggins:CountAmmoSlots(which) --luacheck: ignore 212
--[===[@non-retail@
-- This version of LBU doesn't index special bags properly. but we can work around it by looking up each type individually.
local qiverempty, quivertotal = LBU:CountSlots(which, 1)
local ammoempty, ammototal = LBU:CountSlots(which, 2)
return qiverempty+ammoempty, quivertotal+ammototal
--@end-non-retail@]===]
--@retail@
return LBU:CountSlots(which, 1+2)
--@end-retail@
end

self:SetText(self:BuildCountString(empty,total,color))
return
end
function Baggins:CountSoulSlots(which) --luacheck: ignore 212
return LBU:CountSlots(which, 3)
end

-- separate normal/ammo/soul/special counts
function Baggins:CountSpecialSlots(which) --luacheck: ignore 212
--[===[@non-retail@
local empty, total = 0,0
-- This version of LBU doesn't index special bags properly. but we can work around it by looking up each type individually.
local e, t = LBU:CountSlots(which, 4) -- leather?
empty = empty + e
total = total + t
local n=0 -- count of strings in texts{}
local e, t = LBU:CountSlots(which, 5) --luacheck: ignore 411 -- inscription?
empty = empty + e
total = total + t
local normalempty, normaltotal = LBU:CountSlots("BAGS", 0)
local e, t = LBU:CountSlots(which, 6) --luacheck: ignore 411 -- herb
empty = empty + e
total = total + t
local fullness = 1 - (normalempty/normaltotal)
local r, g
r = min(1,fullness * 2)
g = min(1,(1-fullness) *2)
color = ("|cFF%2X%2X00"):format(r*255,g*255)
local e, t = LBU:CountSlots(which, 7) --luacheck: ignore 411 -- enchant
empty = empty + e
total = total + t
n=n+1
texts[n] = self:BuildCountString(normalempty,normaltotal,color)
local e, t = LBU:CountSlots(which, 8) --luacheck: ignore 411 -- engineering?
empty = empty + e
total = total + t
if self.db.profile.showsoulcount then
local soulempty, soultotal = LBU:CountSlots("BAGS", 4)
if soultotal>0 then
color = self.colors.purple.hex
n=n+1
texts[n] = self:BuildCountString(soulempty,soultotal,color)
end
end
local e, t = LBU:CountSlots(which, 10) --luacheck: ignore 411 -- gems?
empty = empty + e
total = total + t
if self.db.profile.showammocount then
local ammoempty, ammototal = LBU:CountSlots("BAGS", 1+2)
if ammototal>0 then
color = self.colors.white.hex
n=n+1
texts[n] = self:BuildCountString(ammoempty,ammototal,color)
end
end
local e, t = LBU:CountSlots(which, 11) --luacheck: ignore 411 -- mining?
empty = empty + e
total = total + t
if self.db.profile.showspecialcount then
local specialempty, specialtotal = LBU:CountSlots("BAGS", 2047-256-4-2-1)
if specialtotal>0 then
color = self.colors.blue.hex
n=n+1
texts[n] = self:BuildCountString(specialempty,specialtotal,color)
end
end
return empty, total
--@end-non-retail@]===]
--@retail@
return LBU:CountSlots(which, 2047-256-4-2-1)
--@end-retail@
end

if n==1 then
self:SetText(texts[1])
else
self:SetText(tconcat(texts, " ", 1, n))
end
function Baggins:CountKeySlots(which) --luacheck: ignore 212
--[===[@non-retail@
return LBU:CountSlots(which, 9)
--@end-non-retail@]===]
--@retail@
return LBU:CountSlots(which,256)
--@end-retail@
end

---------------------
Expand Down

0 comments on commit 9caa4f4

Please sign in to comment.