X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/08783ecf65f49a14ffc0c47265e488ca4efedb24..330739114047596de17fabf5182c25b065ebde39:/OmaRF/Indicators.lua diff --git a/OmaRF/Indicators.lua b/OmaRF/Indicators.lua index d37383a..49f3ba1 100644 --- a/OmaRF/Indicators.lua +++ b/OmaRF/Indicators.lua @@ -9,10 +9,11 @@ local CTimerAfter = C_Timer.After; local Settings = OmaRFSettings; local majorAuras = Settings.MajorAuras; -local watchedAuras = {}; +local watchedAuras = {}; local updaters = {}; local updating = {}; +local updateAuras; local M = {}; OmaRFIndicators = M; @@ -50,6 +51,11 @@ function M.SetupIndicators(frame, class) tex.icon = true; frame.majors[i] = tex; end + + frame.throttle = function() + frame.throttled = nil; + updateAuras(frame, frame.displayed); + end; end local function remaining(text, expires, current) @@ -119,31 +125,65 @@ local function hideInd(ind) ind:Hide(); end -function M.CheckIndicators(frame, unit) +function M.UpdateAuras(frame, unit) + local current = GetTime(); + if frame.throttled then + print("updateAuras throttled for ", unit); -- TODO debug print + return; + elseif frame.prevUpdate - current < 0.1 then + frame.throttled = true; + return CTimerAfter(0.1, frame.throttle); + end + 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 spell, pos in pairs(watchedAuras) do - name, _, icon, count, _, _, expires = UnitAura(unit, spell, nil, "PLAYER HELPFUL"); - if name then - needUpdate = showInd(frame.inds[pos], expires, current, count, icon) or needUpdate; - showInds = true; - end - end - local i = 1; while true do - name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, "HARMFUL"); + _, _, icon, count, _, _, expires, _, _, _, id = UnitAura(unit, i, "HARMFUL"); if not id or majorPos > 3 then break end - local major = majorAuras[id] or majorAuras[name]; + 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 @@ -153,8 +193,7 @@ function M.CheckIndicators(frame, unit) 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? @@ -167,7 +206,6 @@ function M.CheckIndicators(frame, unit) CTimerAfter(0.20, func); end else - frame.indBase:Hide(); frame.majorBase:Hide(); end