Compare with Previous | Blame | View Log
local name, addon = ... local parentName = addon['parentName'] or "BrokerPack" local childName = "zz_Bags" local defaults = { } local options = { } local ldb = LibStub:GetLibrary("LibDataBroker-1.1") local ldbicon = LibStub("LibDBIcon-1.0") local L = LibStub("AceLocale-3.0"):GetLocale(childName, true) local db,modDB local bagTypes = { [0] = L['Unspecified'], [1] = L['Quiver'], [2] = L['Ammo Pouch'], [4] = L['Soul Bag'], [8] = L['Leatherworking Bag'], [16] = L['Inscription Bag'], [32] = L['Herb Bag'], [64] = L['Enchanting Bag'], [128] = L['Engineering Bag'], [256] = L['Keyring'], [512] = L['Gem Bag'], [1024] = L['Mining Bag'], [2048] = L['Unknown'], [4096] = L['Vanity Pets'], } 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 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", ['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)