WoWInterface SVN zz_BuffInfo

[/] [trunk/] [zz_BuffInfo/] [core.lua] - Rev 30

Compare with Previous | Blame | View Log

local name, addon = ...
local parentName = addon['parentName'] or "BrokerPack"
local childName = "zz_BuffInfo"
local defaults = {}
local _G = _G
local delayOOC = 0.75
local delayIC = 0.5
local delay = delayOOC
local GetTime = GetTime
local g = GetTime()
-- name, rank, icon, cost, isFunnel, powerType, castTime, minRange, maxRange = GetSpellInfo(spellId or spellName)
local auras = {
-- tank
--      [158298] = {GetSpellInfo(158298)}, -- Entschlossenheit
--      [76691] = {GetSpellInfo(76691)}, -- rache
-- monk
        [115295] = 1, -- schutz
        [124275] = 1, -- leichte staffelung
        [124274] = 1, -- moderate staffelung
        [124273] = 1, -- schwere staffelung
-- warrior
--      [112048] = {GetSpellInfo(112048)}, -- schildbarriere
        [2565] = 1, -- schildblock
        [190456] = 1, -- zahne-zusammenbeissen
-- enchants
--      [116631] = {GetSpellInfo(116631)}, -- colossus
}
for k in pairs(auras) do
        auras[k] = {GetSpellInfo(k)}
end
local function updateDisplay(self,event,...)
                delay = event == "PLAYER_REGEN_ENABLED" and delayOOC or delayIC
end
-- name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId, canApplyAura, isBossDebuff, value1, value2, value3
local types = {"HARMFUL", "HELPFUL"}
local aurainfo
local buttons = {}
local checked = {}
local function addText(b)
        local n = 1
        while(b['vText'..n]) do
                n = n + 1
        end
        b['vText'..n] = b:CreateFontString()
        b['vText'..n]:SetWidth(200); b['vText'..n]:SetHeight(8)
        b['vText'..n]:SetPoint("TOPLEFT", b, "TOPRIGHT", 0,-((n-1) * 8)+2)
        b['vText'..n]:SetFontObject("GameFontNormalSmall")
        b['vText'..n]:SetJustifyH("LEFT")
        b['vText'..n]:SetTextColor(1,1,1,1)
end
local lastbutton, defbutton
local function createButton(spellId)
        local b = CreateFrame("Button", "BuffInfo_"..auras[spellId][1], UIParent, "ActionButtonTemplate")
        b:SetSize(24,24)
        _G[format("%sIcon",b:GetName())]:SetTexture(auras[spellId][3])

        for i = 1,3 do
                addText(b)
        end
        b['spellId'] = spellId
        buttons[#buttons + 1] = b
        return b
end

local function getButton(spellId)
        for _, b in pairs(buttons) do
                if(b['spellId'] == spellId) then return b end
        end
        return createButton(spellId)
end

local function updateAura(spellId, aurainfo)
        local b = getButton(spellId)
        if(aurainfo and aurainfo[1]) then
                b:Show()
                for n = 1, 3 do
                        b['vText'..n]:SetText(aurainfo[14 + n])
                end
                checked[spellId] = true
                b:ClearAllPoints()
                if(not lastbutton) then
                        b:SetPoint("CENTER",UIParent,"CENTER")
                        lastbutton = b
                else
                        b:SetPoint("TOPLEFT", lastbutton, "BOTTOMLEFT",0,-4)
                end
        elseif(not checked[spellId]) then
                b:Hide()
        end
end
local function findAura(auraName,itype)
        for i = 1,40 do
                local aura = {UnitAura("player",i,itype)}
                if(aura[1] and aura[1] == auraName) then
                        return aura
                end
                aura = nil
        end
end
local function OnUpdate(self,event)
        local g = GetTime()
        if(self['nextUpdate'] > g) then return end
        self['nextUpdate'] = g + delay
        wipe(checked)
        lastbutton = nil
        for spellId, aura in pairs(auras) do
                for _, itype in ipairs(types) do
--                      print(tostring(aura[1]).."-"..tostring(itype))
                        if(aura[1]) then
--                              aurainfo = {UnitAura("player", aura[1],nil,itype)}
                                aurainfo = findAura(aura[1],itype)
        --                      print(aurainfo[1],aura[1],aurainfo[14],aurainfo[15],aurainfo[16])
                                updateAura(spellId,aurainfo)
                                if(aurainfo and aurainfo[1]) then
                                        checked[spellId] = true
                                end
                        end
                end
        end
end
local function init()
        local options = addon:InitConfig(childName, true, {
                ['name'] = childName,
                ['type'] = "launcher",
                ['icon'] = "Interface\\Icons\\spell_holy_powerwordshield",
        })
        local db = addon['db']['profile'][childName]
        defbutton = CreateFrame("Frame", name.."DragBar")
        defbutton['db'] = db
        defbutton['dragAble'] = function() return true end
        defbutton:SetSize(30,20)
        defbutton:SetPoint("CENTER", UIParent, "CENTER")
        addon:AddDrag(defbutton)
        addon:RegisterFunc({"PLAYER_REGEN_ENABLED", "PLAYER_REGEN_DISABLED"},"OnEvent", updateDisplay)
        addon:RegisterFunc(nil,"OnUpdate", OnUpdate)['nextUpdate'] = GetTime()
end

addon:startup(name, childName, init, true, defaults)

Compare with Previous | Blame