From c6843f31e3e56b92d55a84fbd4da40b555809d31 Mon Sep 17 00:00:00 2001 From: Aleksi Blinnikka Date: Thu, 11 Jan 2018 23:44:42 +0200 Subject: [PATCH] Refactor updateIndicators to get auras when they're applied --- OmaRF/Core.lua | 15 +++-- OmaRF/Indicators.lua | 151 ++++++++++++++++++++++++++---------------- OmaRF/UpdateAuras.lua | 5 +- 3 files changed, 105 insertions(+), 66 deletions(-) diff --git a/OmaRF/Core.lua b/OmaRF/Core.lua index 34b4657..d39b6e6 100644 --- a/OmaRF/Core.lua +++ b/OmaRF/Core.lua @@ -1,18 +1,21 @@ +local unpack = unpack; +local wipe = wipe; +local next = next; +local pairs = pairs; +local ipairs = ipairs; + OmaRF = CreateFrame("Frame"); OmaRF.normalBarColor = CreateColor(0.3, 0.3, 0.3); OmaRF.dispelBarColor = CreateColor(1, 0.5, 0); OmaRF.normalBackColor = {0.7, 0.7, 0.7}; OmaRF.dispelBackColor = {0.5, 0.2, 0}; - OmaRF.frames = {}; OmaRF.majorFrames = {}; OmaRF.positions = { "TOPLEFT", "TOPRIGHT", "CENTER", "BOTTOMLEFT", "BOTTOMRIGHT" }; - OmaRF.running = false; - OmaRF.ooc_queue = {}; local defaults = { @@ -61,8 +64,8 @@ function OmaRF:OnDisable() end for _, ind in ipairs(self.majorFrames[name]) do ind.icon:Hide(); - ind.expire:Hide(); - ind.stack:Hide(); + ind.expireText:Hide(); + ind.stackText:Hide(); end end end @@ -70,7 +73,7 @@ end local function onEvent(self, event, ...) if event == "PLAYER_REGEN_ENABLED" then for _, t in pairs(self.ooc_queue) do - t.func(t.args); + t.func(unpack(t.args)); end if next(self.ooc_queue) ~= nil then wipe(self.ooc_queue); diff --git a/OmaRF/Indicators.lua b/OmaRF/Indicators.lua index 36d03cc..9557258 100644 --- a/OmaRF/Indicators.lua +++ b/OmaRF/Indicators.lua @@ -29,6 +29,50 @@ local unpack = unpack; local floor = floor; local ceil = ceil; +-- update current auras +hooksecurefunc("CompactUnitFrame_UpdateAuras", function(frame) + local frameName = frame:GetName(); + if f[frameName] then + for _, ind in pairs(f[frameName]) do ind.expires = nil end + for _, ind in ipairs(majorFrames[frameName]) do ind.expires = nil end + + local name, icon, count, expires, caster, id; + local unit = frame.displayedUnit; + local majorI = 1; + 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 then + local ind = f[frameName][pos]; + local config = OmaRF.db.profile.indicators[pos]; + if not config.mine or UnitIsPlayer(caster) then + if config.useDefaultIcon then + ind.icon:SetTexture(DEFAULT_ICON); + else + ind.icon:SetTexture(icon); + end + ind.expires = expires; + end + end + + if (majorAuras[id] or majorAuras[name]) and majorI <= majorMax then + local ind = majorFrames[frameName][majorI]; + ind.icon:SetTexture(icon); + ind.expires = expires; + if count > 1 then + ind.stackText:SetText(count); + end + majorI = majorI + 1; + end + i = i + 1; + end + end + end +end); + local function configureIndicators(frame, name) local frameName = name or frame:GetName(); if not f[frameName] then return end @@ -51,8 +95,8 @@ local function configureIndicators(frame, name) end ind.icon:SetWidth(config.iconSize); ind.icon:SetHeight(config.iconSize); - ind.expire:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE"); - ind.stack:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE"); + ind.expireText:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE"); + ind.stackText:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE"); end end @@ -75,16 +119,17 @@ local function setupCompactUnitFrame(frame, name) if i > 1 then majorFrames[name][i].icon:SetPoint("TOPLEFT", majorFrames[name][i-1].icon, "TOPRIGHT"); end - majorFrames[name][i].expire = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"); - majorFrames[name][i].expire:SetPoint("BOTTOMRIGHT", majorFrames[name][i].icon, "BOTTOMRIGHT"); - majorFrames[name][i].stack = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"); - majorFrames[name][i].stack:SetPoint("TOPLEFT", majorFrames[name][i].icon, "TOPLEFT"); + majorFrames[name][i].expireText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"); + majorFrames[name][i].expireText:SetPoint("BOTTOMRIGHT", majorFrames[name][i].icon, "BOTTOMRIGHT"); + majorFrames[name][i].stackText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"); + majorFrames[name][i].stackText:SetPoint("TOPLEFT", majorFrames[name][i].icon, "TOPLEFT"); end configureIndicators(frame, name); end local function remaining(expires, current) + if expires == 0 then return "" end local remain = expires - current; if remain > 60 then return format("%dm", ceil(remain/60)); @@ -92,72 +137,64 @@ local function remaining(expires, current) return floor(remain+0.5); end --- Check the indicators on a frame and update the times on them -local function updateIndicators(frame) - local frameName = frame:GetName(); - local unit = frame.unit; - if not unit then return end -- possible if the frame is just being hidden - - -- Create indicators if needed - if not f[frameName] then setupCompactUnitFrame(frame, frameName) end - -- Reset current +local function hide(frameName) for _, ind in pairs(f[frameName]) do ind.text:Hide(); ind.icon:Hide(); end for _, ind in ipairs(majorFrames[frameName]) do ind.icon:Hide(); - ind.expire:Hide(); - ind.stack:Hide(); + ind.expireText:Hide(); + ind.stackText:Hide(); end +end + +-- Check the indicators on a frame and update the times on them +local function updateIndicators(frame) + local frameName = frame:GetName(); + local unit = frame.unit; + if not unit then return end -- possible if the frame is just being hidden + + -- Create indicators if needed, out of combat if forbidden + if not f[frameName] then + if frame:IsForbidden() then + if not OmaRF.ooc_queue[frameName] then + OmaRF.ooc_queue[frameName] = { + func = setupCompactUnitFrame, + args = { frame, frameName } + }; + end + return; + else + setupCompactUnitFrame(frame, frameName); + end + end + -- Reset current + hide(frameName); -- Hide if unit is dead/disconnected if (not UnitIsConnected(unit)) or UnitIsDeadOrGhost(frame.displayedUnit) then return; end - local name, icon, count, expires, caster, id; local current = GetTime(); - local majorI = 1; - 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 then - local ind = f[frameName][pos]; - local config = OmaRF.db.profile.indicators[pos]; - if not config.mine or UnitIsPlayer(caster) then - if config.showIcon then - -- show icon - if config.useDefaultIcon then - ind.icon:SetTexture(DEFAULT_ICON); - else - ind.icon:SetTexture(icon); - end - ind.icon:Show() - end - if config.showText then - -- show text - ind.text:SetText(remaining(expires, current)); - ind.text:Show(); - end - end - end - - if (majorAuras[id] or majorAuras[name]) and majorI <= majorMax then - local ind = majorFrames[frameName][majorI]; - ind.icon:SetTexture(icon); + for pos, ind in pairs(f[frameName]) do + if ind.expires ~= nil then + local config = OmaRF.db.profile.indicators[pos]; + if config.showIcon then ind.icon:Show(); - ind.expire:SetText(remaining(expires, current)); - ind.expire:Show(); - if count > 1 then - ind.stack:SetText(count); - ind.stack:Show(); - end - majorI = majorI + 1; end - i = i + 1; + if config.showText then + ind.text:SetText(remaining(ind.expires, current)); + ind.text:Show(); + end + end + end + for _, ind in ipairs(majorFrames[frameName]) do + if ind.expires ~= nil then + ind.icon:Show(); + ind.expireText:SetText(remaining(ind.expires, current)); + ind.expireText:Show(); + ind.stackText:Show(); end end end diff --git a/OmaRF/UpdateAuras.lua b/OmaRF/UpdateAuras.lua index cf5fccf..e6d82f0 100644 --- a/OmaRF/UpdateAuras.lua +++ b/OmaRF/UpdateAuras.lua @@ -2,13 +2,13 @@ local normalBarColor = OmaRF.normalBarColor; local dispelBarColor = OmaRF.dispelBarColor; local normalBackColor = OmaRF.normalBackColor; local dispelBackColor = OmaRF.dispelBackColor; + local UnitDebuff = UnitDebuff; local CompactUnitFrame_UpdateHealthColor = CompactUnitFrame_UpdateHealthColor; local unpack = unpack; hooksecurefunc("CompactUnitFrame_UpdateAuras", function(frame) - -- allowClassColorsForNPCs only in regular raid frames, - -- match only to them + -- allowClassColorsForNPCs only in regular raid frames if frame.optionTable.allowClassColorsForNPCs ~= nil then -- try to find dispellable debuff if UnitDebuff(frame.displayedUnit, 1, "RAID") ~= nil then @@ -18,7 +18,6 @@ hooksecurefunc("CompactUnitFrame_UpdateAuras", function(frame) frame.optionTable.healthBarColorOverride = normalBarColor; frame.background:SetColorTexture(unpack(normalBackColor)); end - -- update color CompactUnitFrame_UpdateHealthColor(frame); end end); -- 2.39.5