X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/b8c70450d10559c08516416bf92fb95434bd3034..6f9efe3aedbfb5f6be2277de730fa446d87bb4d7:/OmaRF/Indicators.lua diff --git a/OmaRF/Indicators.lua b/OmaRF/Indicators.lua index ba89735..929b960 100644 --- a/OmaRF/Indicators.lua +++ b/OmaRF/Indicators.lua @@ -1,4 +1,3 @@ -local media = LibStub:GetLibrary("LibSharedMedia-3.0"); local f = OmaRF.frames; local positions = OmaRF.positions; local pad = 2; @@ -15,13 +14,15 @@ local DEFAULT_ICON = "Interface\\AddOns\\OmaRF\\images\\rhomb"; local _; -- global functions used every update -local C_TimerAfter = C_Timer.After +local C_TimerAfter = C_Timer.After; local GetTime = GetTime; local UnitAura = UnitAura; local UnitIsPlayer = UnitIsPlayer; local UnitIsConnected = UnitIsConnected; local UnitIsDeadOrGhost = UnitIsDeadOrGhost; local CompactRaidFrameContainer_ApplyToFrames = CompactRaidFrameContainer_ApplyToFrames; +local format = string.format; +local unpack = unpack; -- list of important auras TODO try to use spellIDs local centerAuras = { @@ -32,10 +33,9 @@ local function configureIndicators(frame, name) local frameName = name or frame:GetName(); if not f[frameName] then return end - local config = OmaRF.db.profile; - local font = media and media:Fetch('font', config.indicatorFont) or STANDARD_TEXT_FONT; + local config = OmaRF.db.profile.indicators; for pos, ind in pairs(f[frameName]) do - ind.text:SetFont(font, config[pos]["textSize"]); + ind.text:SetFont(STANDARD_TEXT_FONT, config[pos]["textSize"]); ind.text:SetTextColor(unpack(config[pos]["textColor"])); ind.icon:SetWidth(config[pos]["iconSize"]); ind.icon:SetHeight(config[pos]["iconSize"]); @@ -66,6 +66,7 @@ end 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 @@ -88,20 +89,25 @@ local function updateIndicators(frame) if not id then break end local pos = watchedAuras[name] or watchedAuras[id] or watchedAuras[debuff]; if pos then - local config = OmaRF.db.profile[pos]; + local ind = f[frameName][pos]; + local config = OmaRF.db.profile.indicators[pos]; if not config.mine or UnitIsPlayer(caster) then - if config.showIcon and not config.useDefaultIcon then + if config.showIcon then -- show icon - ind.icon:SetTexture(icon); + if config.useDefaultIcon then + ind.icon:SetTexture(DEFAULT_ICON); + else + ind.icon:SetTexture(icon); + end end if config.showText then -- show text local text; local remaining = expires - current; if remaining > 60 then - text = string.format("%dm", ceil(remaining/60)); + text = format("%dm", ceil(remaining/60)); else - text = string.format("%d", floor(remaining+0.5)); + text = format("%d", floor(remaining+0.5)); end if count > 1 and config.stack then if text then @@ -123,8 +129,8 @@ end -- Update all indicators function OmaRF:UpdateAllIndicators() CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", updateIndicators); - if self.running then - C_TimerAfter(0.15, self:UpdateAllIndicators); + if OmaRF.running then + C_TimerAfter(0.15, OmaRF.UpdateAllIndicators); end end @@ -136,14 +142,14 @@ function OmaRF:RefreshConfig() -- Format aura strings watchedAuras = {}; for _, pos in ipairs(positions) do - for _, aura in ipairs(self.db.profile[pos]["auras"]) do + for _, aura in ipairs(self.db.profile.indicators[pos]["auras"]) do watchedAuras[aura] = pos; -- TODO single aura only in one position end end if next(watchedAuras) ~= nil then self.running = true; - C_TimerAfter(0.15, self:UpdateAllIndicators); + C_TimerAfter(0.15, self.UpdateAllIndicators); end end end