local name, addon = ... local parentName = addon['parentName'] or "BrokerPack" local childName = "zz_Bags" local defaults = { } local options = { } local ldbicon = LibStub:GetLibrary("LibDBIcon-1.0") local L = LibStub("AceLocale-3.0"):GetLocale(childName, true) local db,modDB --[[ 4 Leatherworking Supplies 5 Inscription Supplies 6 Herbs 7 Enchanting Supplies 8 Engineering Supplies 10 Gems 11 Mining Supplies 12 Soulbound Equipment 16 Fishing Supplies 17 Cooking Supplies 20 Toys 21 Archaeology 22 Alchemy 23 Blacksmithing 24 First Aid 25 Jewelcrafting 26 Skinning 27 Tailoring ]] local bagTypes = { [0] = L['Unspecified'], [1] = L['Quiver'], [2] = L['Ammo Pouch'], [4] = L['Soul Bag'], [8] = L['Leatherworking Bag'],--4 [16] = L['Inscription Bag'],--5 [32] = L['Herb Bag'],--6 [64] = L['Enchanting Bag'],--7 [128] = L['Engineering Bag'],--8 [256] = L['Keyring'],--9? [512] = L['Gem Bag'], --10 [1024] = L['Mining Bag'], --11 [2048] = L['Unknown'], --12 [4096] = L['Vanity Pets'], --13 [32768] = L['Fishing Supplies'], --16 [65536] = L['Cooking Supplies'], --17 [524288] = L['Toys'], --20 [1048576] = L['Archaeology'], --21 [2097152] = L['Alchemy'], --22 [4194304] = L['Blacksmithing'], --23 [8388608] = L['First Aid'], --24 [16777216] = L['Jewelcrafting'], --25 [33554432] = L['Skinning'], --26 [67108864] = L['Tailoring'], --27 } local refillframe local x,y,n,m,b,c local free, full local bagID,bagType local NUM_BAG_SLOTS = NUM_BAG_SLOTS local NUM_BANKBAGSLOTS = NUM_BANKBAGSLOTS local BANK_CONTAINER = BANK_CONTAINER local currentFrame local function OnText(message) addon:OnText(childName, message) end local function OnDataUpdate() bagID = 0 n,m = 0,0 free,full = {},{} while(bagID<=NUM_BAG_SLOTS) do b = GetContainerNumSlots(bagID) c = GetContainerNumFreeSlots(bagID) bagType = GetItemFamily(GetBagName(bagID)) if(not bagType or bagType==0) then bagType = 0 full[0] = full[0] or 0 free[0] = free[0] or 0 free[0] = free[0] + c full[0] = full[0] + b else full[bagType] = full[bagType] or 0 free[bagType] = free[bagType] or 0 free[bagType] = free[bagType] + c full[bagType] = full[bagType] + b end if(db['bagTypes'][bagTypes[bagType]]==true) then n = n + c m = m + b end bagID = bagID + 1 end if(not db['showFree']) then n = m - n end OnText(format("%d/%d",n,m)) end local function getPref2(info) return db['bagTypes'][info[#info]] end local function setPref2(info,value) db['bagTypes'][info[#info]] = value OnDataUpdate() end local function getPref(info) return db[info[#info]] end local function setPref(info,value) db[info[#info]] = value OnDataUpdate() end local function OnClick(self, button) if(IsShiftKeyDown() and button == "LeftButton") then addon['db']['global']['ldbicons'][childName]['hide'] = not addon['db']['global']['ldbicons'][childName]['hide'] if(ldbicon) then if(addon['db']['global']['ldbicons'][childName]['hide']) then ldbicon:Hide(childName) else ldbicon:Show(childName) end end else if(InterfaceOptionsFrame:IsVisible() and not InCombatLockdown()) then InterfaceOptionsFrame:Hide() else InterfaceOptionsFrame_OpenToCategory(childName) InterfaceOptionsFrame_OpenToCategory(childName) -- Twice because of a bug in InterfaceOptionsFrame_OpenToCategory end end end local function OnTooltip(tip) tip:AddLine(childName) x, y = 0, 0 while(x<8000) do if(full[x] and full[x] > 0) then n = free[x] if(not db['showFree']) then n = full[x] - n end tip:AddDoubleLine(bagTypes[x],n.."/"..full[x]) end x = 2^y y = y + 1 end end local function init() options = addon:InitConfig(childName, true, { ['name'] = childName, ['type'] = "data source", ['OnClick'] = OnClick, ['OnTooltipShow'] = OnTooltip, }, getPref, setPref) db = addon['db']['profile'][childName] addon:AddConfigMenu({ ['name'] = L['Bagtypes'], ['order'] = 2, ['childGroups'] = 'tab', ['menuGet'] = getPref2, ['menuSet'] = setPref2 }, options) db['bagTypes'] = db['bagTypes'] or { [bagTypes[0]] = true, } addon:AddConfigEntry(childName, "toggle","showFree",L['Show free space'],L['Show free space instead of used space'],1,nil,nil,nil,nil,options['args'][childName]) for k,v in pairs(bagTypes) do addon:AddConfigEntry(childName, "toggle",v,v,nil,1,nil,nil,nil,nil,options['args'][L['Bagtypes']]) end addon:RegisterEventThrottle(childName,"BAG_UPDATE", 1, OnDataUpdate) OnDataUpdate() end addon:startup(name, childName, init, true, defaults)