X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/d51d314274936814dec7d124c9ec5e5165666918..e3bfc6ab17284d1a62b6a19fcb5b5916040f94ed:/OmaUF/Auras.lua?ds=sidebyside diff --git a/OmaUF/Auras.lua b/OmaUF/Auras.lua index 95ef2c6..0ca1e0a 100644 --- a/OmaUF/Auras.lua +++ b/OmaUF/Auras.lua @@ -2,9 +2,12 @@ local _; local CreateFrame = CreateFrame; local UnitAura = UnitAura; -local GameTooltip = nil; +local GameTooltip = GameTooltip; +local GetTime = GetTime; +local CTimerAfter = C_Timer.After; local auraFilters = {"HELPFUL", "HARMFUL"}; +local updateAuras; local M = {}; OmaUFAuras = M; @@ -18,7 +21,7 @@ local function updateTooltip(frame) end local function showTooltip(frame) - -- tooltip handling from TargetFrame.xml + -- tooltip handling from FrameXML/TargetFrame.xml GameTooltip:SetOwner(frame, "ANCHOR_BOTTOMRIGHT", 15, -25); GameTooltip:SetUnitAura(frame.unit, frame.index, frame.filter); frame:SetScript("OnUpdate", updateTooltip); @@ -32,10 +35,12 @@ 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:SetWidth(20); + aura:SetHeight(20); aura.icon = aura:CreateTexture(nil, "ARTWORK"); aura.icon:SetAllPoints(); + aura.stack = aura:CreateFontString(nil, "OVERLAY", "NumberFontNormalSmall"); + aura.stack:SetPoint("BOTTOMRIGHT"); aura.cd = CreateFrame("Cooldown", name.."CD", aura, "CooldownFrameTemplate"); aura.cd:SetReverse(true); aura.cd:SetHideCountdownNumbers(true); @@ -48,7 +53,6 @@ local function createAura(parent, prev, anchor, name, unit) 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); @@ -66,22 +70,33 @@ function M.CreateAuraFrame(parent, unit) i = i + 1; end -- max rows - for y=0,1 do + for y=0,0 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 + + parent.throttle = function() + parent.throttled = nil; + if UnitExists(unit) then + return updateAuras(parent, unit); + 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(); + local current = GetTime(); + if frame.throttled then + return; + elseif frame.prevUpdate and current - frame.prevUpdate < 0.2 then + frame.throttled = true; + return CTimerAfter(0.1, frame.throttle); -- faster timer here to reduce the delay, gets called twice end + + frame.prevUpdate = current; + local auras = frame.auras; local icon, count, duration, expires, caster, id; local pos = 1; for _, filter in ipairs(auraFilters) do @@ -93,6 +108,12 @@ function M.UpdateAuras(frame, unit) aura.icon:SetTexture(icon); aura.index = i; aura.filter = filter; + if count > 1 then + aura.stack:SetText(count); + aura.stack:Show(); + else + aura.stack:Hide(); + end if expires > 0 then aura.cd:SetCooldown(expires - duration, duration); else @@ -103,4 +124,11 @@ function M.UpdateAuras(frame, unit) i = i + 1; end end + + while auras[pos] do + if not auras[pos]:IsShown() then return end + auras[pos]:Hide(); + pos = pos + 1; + end end +updateAuras = M.UpdateAuras;