X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/001062c21d0a4b6600278f45ee096fc587c745df..306a5758edfa15a3005853642548eb57a4fba236:/OmaRF/Indicators.lua?ds=sidebyside diff --git a/OmaRF/Indicators.lua b/OmaRF/Indicators.lua index 6b4e04a..abd52ec 100644 --- a/OmaRF/Indicators.lua +++ b/OmaRF/Indicators.lua @@ -2,17 +2,19 @@ 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; 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; @@ -50,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) @@ -86,7 +95,7 @@ local function updateIndicators(frame) end end if needUpdate then - CTimerAfter(0.16, updaters[frame]); + CTimerAfter(0.20, updaters[frame]); else updating[frame] = nil; end @@ -119,40 +128,78 @@ 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; + if UnitIsDeadOrGhost(unit) then return end + local name, 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 + local i = 1; + while true do + name, icon, count, _, _, expires, _, _, _, id = UnitAura(unit, i, "HARMFUL"); + if not id or majorPos > 3 then break end + local major = majorAuras[id] or majorAuras[name]; + if major then + if not major.noicon 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; + if major.bar then alert = major.bar 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? @@ -162,10 +209,9 @@ function M.CheckIndicators(frame, unit) func = function() updateIndicators(frame) end; updaters[frame] = func; end - CTimerAfter(0.16, func); + CTimerAfter(0.20, func); end else - frame.indBase:Hide(); frame.majorBase:Hide(); end