X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/ac5ca8a9cb3cd9c2a6f5850ba5774bd81307fb51..6e06bfb151855f946ceb1885d310598e612fa128:/OmaUF/Auras.lua diff --git a/OmaUF/Auras.lua b/OmaUF/Auras.lua index deb62fa..3af6ac5 100644 --- a/OmaUF/Auras.lua +++ b/OmaUF/Auras.lua @@ -1,15 +1,107 @@ -- Auras.lua local _; local CreateFrame = CreateFrame; +local UnitAura = UnitAura; +local GameTooltip = nil; + +local auraFilters = {"HELPFUL", "HARMFUL"}; local M = {}; OmaUFAuras = M; -function M.CreateAuraFrame(parent) - parent.auras = CreateFrame("Frame", nil, parent); - parent.auras:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, -2); +local function updateTooltip(frame) + if GameTooltip:IsOwned(frame) then + GameTooltip:SetUnitAura(frame.unit, frame.index, frame.filter); + else + frame:SetScript("OnUpdate", nil); + end +end + +local function showTooltip(frame) + -- tooltip handling from TargetFrame.xml + GameTooltip:SetOwner(frame, "ANCHOR_BOTTOMRIGHT", 15, -25); + GameTooltip:SetUnitAura(frame.unit, frame.index, frame.filter); + frame:SetScript("OnUpdate", updateTooltip); +end + +local function hideTooltip(frame) + GameTooltip:Hide(); + frame:SetScript("OnUpdate", nil); +end + +local function createAura(parent, prev, anchor, name, unit) + local aura = CreateFrame("Frame", name, parent); + aura:SetPoint("TOPLEFT", prev, anchor); + aura:SetWidth(16); + aura:SetHeight(16); + aura.icon = aura:CreateTexture(nil, "ARTWORK"); + aura.icon:SetAllPoints(); + aura.cd = CreateFrame("Cooldown", name.."CD", aura, "CooldownFrameTemplate"); + aura.cd:SetReverse(true); + aura.cd:SetHideCountdownNumbers(true); + aura.cd:SetAllPoints(); + aura.unit = unit; + aura:SetScript("OnEnter", showTooltip); + aura:SetScript("OnLeave", hideTooltip); + aura:Hide(); + return aura; +end + +function M.CreateAuraFrame(parent, unit) + GameTooltip = _G["GameTooltip"]; + local name = parent:GetName().."Auras"; + parent.auras = CreateFrame("Frame", name, parent); + parent.auras:SetPoint("TOPLEFT", parent, "BOTTOMLEFT", 0, -8); + parent.auras:SetWidth(10); + parent.auras:SetHeight(10); + local i = 1; + -- max auras per row + for x=1,10 do + local auraName = name..i; + if i == 1 then + parent.auras[i] = createAura(parent.auras, parent.auras, "TOPLEFT", auraName, unit); + else + parent.auras[i] = createAura(parent.auras, parent.auras[i-1], "TOPRIGHT", auraName, unit); + end + i = i + 1; + end + -- max rows + for y=0,1 do + for x=1,10 do + local auraName = name..i; + parent.auras[i] = createAura(parent.auras, parent.auras[y*10+x], "BOTTOMLEFT", auraName, unit); + i = i + 1; + end + end end function M.UpdateAuras(frame, unit) local auras = frame.auras; + if not auras then return end + for _, aura in ipairs(auras) do + if not aura:IsShown() then break end + aura:Hide(); + end + local icon, count, duration, expires, caster, id; + local pos = 1; + for _, filter in ipairs(auraFilters) do + local i = 1; + while true do + _, _, icon, count, _, duration, expires, caster, _, _, id = UnitAura(unit, i, filter); + if not id or not auras[pos] then break end + -- aura filter self-applied, player-applied, list of important auras TODO + local aura = auras[pos]; + aura.icon:SetTexture(icon); + aura.index = i; + aura.filter = filter; + if expires > 0 then + aura.cd:SetCooldown(expires - duration, duration); + else + aura.cd:Hide(); + end + aura:Show(); + pos = pos + 1; + i = i + 1; + end + end end