local media = LibStub:GetLibrary("LibSharedMedia-3.0"); local f = RaidFrameCustomization.frames; local positions = RaidFrameCustomization.positions; local pad = 2; local paddings = { TOPLEFT = {pad, -pad}, TOPRIGHT = {-pad, -pad}, CENTER = {0, 0}, BOTTOMLEFT = {pad, pad}, BOTTOMRIGHT = {-pad, pad} }; local watchedAuras; -- all watched auras local auraFilters = {"HELPFUL", "HARMFUL"}; local DEFAULT_ICON = "Interface\\AddOns\\RaidFrameCustomization\\images\\rhomb"; local _; -- global functions used every update local GetTime = GetTime; local UnitAura = UnitAura; local UnitIsPlayer = UnitIsPlayer; local UnitIsConnected = UnitIsConnected; local UnitIsDeadOrGhost = UnitIsDeadOrGhost; local CompactRaidFrameContainer_ApplyToFrames = CompactRaidFrameContainer_ApplyToFrames; -- list of important auras TODO try to use spellIDs local centerAuras = { "Power Word: Shield" }; local function configureIndicators(frame, name) local frameName = name or frame:GetName(); if not f[frameName] then return end local config = RaidFrameCustomization.db.profile; local font = media and media:Fetch('font', config.indicatorFont) or STANDARD_TEXT_FONT; for pos, ind in pairs(f[frameName]) do ind.text:SetFont(font, config[pos]["textSize"]); ind.text:SetTextColor(unpack(config[pos]["textColor"])); ind.icon:SetWidth(config[pos]["iconSize"]); ind.icon:SetHeight(config[pos]["iconSize"]); ind.icon:SetTexture(DEFAULT_ICON); ind.icon:SetVertexColor(unpack(config[pos]["iconColor"])); if config[pos]["showIcon"] then ind.icon:Show(); else ind.icon:Hide(); end end end -- Create the FontStrings used for indicators local function setupCompactUnitFrame(frame, name) f[name] = {}; for _, pos in ipairs(positions) do f[name][pos] = {}; f[name][pos].text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall"); f[name][pos].text:SetPoint(pos, frame, pos, paddings[pos][1], paddings[pos][2]); f[name][pos].icon = frame:CreateTexture(nil, "OVERLAY"); f[name][pos].icon:SetPoint(pos, frame, pos, paddings[pos][1], paddings[pos][2]); end configureIndicators(frame, name); 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; -- Create indicators if needed if not f[frameName] then setupCompactUnitFrame(frame, frameName) end -- Reset current for _, ind in pairs(f[frameName]) do ind.text:SetText(""); ind.icon:SetTexture(""); end -- Hide if unit is dead/disconnected if (not UnitIsConnected(unit)) or UnitIsDeadOrGhost(frame.displayedUnit) then return; end local name, icon, count, debuff, expires, caster, id; local current = GetTime(); for _, filter in ipairs(auraFilters) do local i = 1; while true do name, _, icon, count, debuff, _, expires, caster, _, _, id = UnitAura(unit, i, filter); if not id then break end local pos = watchedAuras[name] or watchedAuras[id] or watchedAuras[debuff]; if pos then local config = RaidFrameCustomization.db.profile[pos]; if not config.mine or UnitIsPlayer(caster) then if config.showIcon and not config.useDefaultIcon then -- show icon TODO coloring ind.icon:SetTexture(icon); end if config.showText then -- show text local text; local remaining = expires - current; if remaining > 60 then text = string.format("%dm", ceil(remaining/60)); else text = string.format("%d", floor(remaining+0.5)); end if count > 1 and config.stack then if text then text = count.."-"..text; else text = count; end end ind.text:SetText(text); end end end i = i + 1; end end end -- Update all indicators function RaidFrameCustomization:UpdateAllIndicators() CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", updateIndicators); end -- Used to update everything that is affected by the configuration function RaidFrameCustomization:RefreshConfig() self:OnDisable(); -- clear everything if self.db.profile.enabled then CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", configureIndicators); -- Format aura strings watchedAuras = {}; for _, pos in ipairs(positions) do for _, aura in ipairs(self.db.profile[pos]["auras"]) do watchedAuras[aura] = pos; -- TODO single aura only in one position end end if next(watchedAuras) ~= nil then self.updateTimer = self:ScheduleRepeatingTimer("UpdateAllIndicators", 0.15); end end end