X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/4a66dd6d6fe87c9e881b0c7d62ca339907619d4d..ba69982de70da5d761e9f1bda67f94ab0e218fe7:/OmaRF/Indicators.lua diff --git a/OmaRF/Indicators.lua b/OmaRF/Indicators.lua index f90ff60..77b4535 100644 --- a/OmaRF/Indicators.lua +++ b/OmaRF/Indicators.lua @@ -2,6 +2,7 @@ local pairs, ipairs = pairs, ipairs; local floor = math.floor; local GetTime = GetTime; +local UnitExists = UnitExists; local UnitAura = UnitAura; local CreateFrame = CreateFrame; local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected; @@ -9,11 +10,11 @@ local CTimerAfter = C_Timer.After; local Settings = OmaRFSettings; local majorAuras = Settings.MajorAuras; -local watchedAuras = {}; +local watchedAuras = {}; local updaters = {}; local updating = {}; -local auraFilters = {"HELPFUL", "HARMFUL"}; +local updateAuras; local M = {}; OmaRFIndicators = M; @@ -51,6 +52,13 @@ function M.SetupIndicators(frame, class) tex.icon = true; frame.majors[i] = tex; end + + frame.throttle = function() + frame.throttled = nil; + if UnitExists(frame.displayed) then + return updateAuras(frame, frame.displayed); + end + end; end local function remaining(text, expires, current) @@ -120,40 +128,75 @@ local function hideInd(ind) ind:Hide(); end -function M.CheckIndicators(frame, unit) +function M.UpdateAuras(frame, unit) + local current = GetTime(); + if frame.throttled then + return; + elseif frame.prevUpdate and current - frame.prevUpdate < 0.2 then + frame.throttled = true; + return CTimerAfter(0.2, frame.throttle); + end + + frame.prevUpdate = current; for _, ind in pairs(frame.inds) do hideInd(ind); end + local icon, count, expires, id; + local showInds, needUpdate = false, false; + local i = 1; + while true do + _, _, icon, count, _, _, expires, _, _, _, id = UnitAura(unit, i, "PLAYER HELPFUL"); + if not id then break end + local pos = watchedAuras[id]; + if pos then + needUpdate = showInd(frame.inds[pos], expires, current, count, icon) or needUpdate; + showInds = true; + end + i = i + 1; + end + + if showInds then + frame.indBase:Show(); + if needUpdate and not updating[frame] then + updating[frame] = true; -- race? + -- create a function for updating the indicator + local func = updaters[frame]; + if not func then + func = function() updateIndicators(frame) end; + updaters[frame] = func; + end + CTimerAfter(0.20, func); + end + else + frame.indBase:Hide(); + end +end +updateAuras = M.UpdateAuras; + +function M.UpdateMajorAuras(frame, unit) for _, ind in pairs(frame.majors) do hideInd(ind); end - local name, icon, count, expires, caster, id; - local showInds, showMajors, needUpdate = false, false, false; + local icon, count, expires, id; + local showMajors, needUpdate = false, false; local majorPos = 1; local alert = false; -- color the whole bar local current = GetTime(); - for _, filter in ipairs(auraFilters) do - local i = 1; - while true do - name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter); - if not id then break end - local pos = watchedAuras[id] or watchedAuras[name]; - if pos and caster == "player" then - needUpdate = showInd(frame.inds[pos], expires, current, count, icon) or needUpdate; - showInds = true; - end - local major = majorAuras[id] or majorAuras[name]; - if major and majorPos <= 3 then - needUpdate = showInd(frame.majors[majorPos], expires, current, count, icon) or needUpdate; - if major.bar then alert = true end - showMajors = true; - majorPos = majorPos + 1; - end - i = i + 1; + local i = 1; + while true do + _, _, icon, count, _, _, expires, _, _, _, id = UnitAura(unit, i, "HARMFUL"); + if not id or majorPos > 3 then break end + local major = majorAuras[id]; + if major then + needUpdate = showInd(frame.majors[majorPos], expires, current, count, icon) or needUpdate; + if major.bar then alert = true end + showMajors = true; + majorPos = majorPos + 1; end + i = i + 1; end - if showInds or showMajors then - frame.indBase:Show(); + + if showMajors then frame.majorBase:Show(); if needUpdate and not updating[frame] then updating[frame] = true; -- race? @@ -166,7 +209,6 @@ function M.CheckIndicators(frame, unit) CTimerAfter(0.20, func); end else - frame.indBase:Hide(); frame.majorBase:Hide(); end