zz_Bags/broker.lua

39 lines
1.4 KiB
Lua
Executable File

local addonName, addon = ...
local childName = addon['childName']
local child = addon[childName]
local zzLDB = LibStub:GetLibrary("zzLDB")
local folder = addonName ~= childName and format("Interface\\AddOns\\%s\\%s", addonName, childName) or format("Interface\\AddOns\\%s", childName)
local db
local function OnClick(self, button)
zzLDB:DefaultOnClick(self, button, addon, childName)
end
local function OnTooltipShow(tip)
tip:AddLine(childName)
local full, free, bagTypes = child['bagStatus']['full'], child['bagStatus']['free'], child['bagStatus']['bagTypes']
local x, y = 0, 0
while(x<8000) do
if(full[x] and full[x] > 0) then
local 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
child.OnText = zzLDB.DefaultOnText
child['ldb'] = { -- https://github.com/tekkub/libdatabroker-1-1/wiki/Data-Specifications
['type'] = 'data source', -- required: 'data source' or 'launcher'
['text'] = childName, -- required/optional for launcher
['icon'] = format("%s\\icon2.tga", folder), -- optional/required for launcher
['OnClick'] = OnClick, -- optional/required for launcher
['OnTooltipShow'] = OnTooltipShow, -- optional
}
local init = {
Setup = function(self, childName, event)
db = child['db']
end
}
addon.RegisterCallback(init, format("Init%s", childName), 'Setup', childName)