1 local media = LibStub:GetLibrary("LibSharedMedia-3.0");
2 local f = RaidFrameCustomization.frames;
3 local positions = RaidFrameCustomization.positions;
7 TOPRIGHT = {-pad, -pad},
9 BOTTOMLEFT = {pad, pad},
10 BOTTOMRIGHT = {-pad, pad}
12 local watchedAuras; -- all watched auras
13 local auraFilters = {"HELPFUL", "HARMFUL"};
14 local DEFAULT_ICON = "Interface\\AddOns\\RaidFrameCustomization\\images\\rhomb";
17 -- global functions used every update
18 local GetTime = GetTime;
19 local UnitAura = UnitAura;
20 local UnitIsPlayer = UnitIsPlayer;
21 local UnitIsConnected = UnitIsConnected;
22 local UnitIsDeadOrGhost = UnitIsDeadOrGhost;
23 local CompactRaidFrameContainer_ApplyToFrames = CompactRaidFrameContainer_ApplyToFrames;
25 -- list of important auras TODO try to use spellIDs
30 local function configureIndicators(frame, name)
31 local frameName = name or frame:GetName();
32 if not f[frameName] then return end
34 local config = RaidFrameCustomization.db.profile;
35 local font = media and media:Fetch('font', config.indicatorFont) or STANDARD_TEXT_FONT;
36 for pos, ind in pairs(f[frameName]) do
37 ind.text:SetFont(font, config[pos]["textSize"]);
38 ind.text:SetTextColor(unpack(config[pos]["textColor"]));
39 ind.icon:SetWidth(config[pos]["iconSize"]);
40 ind.icon:SetHeight(config[pos]["iconSize"]);
41 ind.icon:SetTexture(DEFAULT_ICON);
42 ind.icon:SetVertexColor(unpack(config[pos]["iconColor"]));
43 if config[pos]["showIcon"] then
51 -- Create the FontStrings used for indicators
52 local function setupCompactUnitFrame(frame, name)
54 for _, pos in ipairs(positions) do
56 f[name][pos].text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
57 f[name][pos].text:SetPoint(pos, frame, pos, paddings[pos][1], paddings[pos][2]);
58 f[name][pos].icon = frame:CreateTexture(nil, "OVERLAY");
59 f[name][pos].icon:SetPoint(pos, frame, pos, paddings[pos][1], paddings[pos][2]);
61 configureIndicators(frame, name);
64 -- Check the indicators on a frame and update the times on them
65 local function updateIndicators(frame)
66 local frameName = frame:GetName();
67 local unit = frame.unit;
69 -- Create indicators if needed
70 if not f[frameName] then setupCompactUnitFrame(frame, frameName) end
72 for _, ind in pairs(f[frameName]) do
74 ind.icon:SetTexture("");
76 -- Hide if unit is dead/disconnected
77 if (not UnitIsConnected(unit)) or UnitIsDeadOrGhost(frame.displayedUnit) then
81 local name, icon, count, debuff, expires, caster, id;
82 local current = GetTime();
83 for _, filter in ipairs(auraFilters) do
86 name, _, icon, count, debuff, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
87 if not id then break end
88 local pos = watchedAuras[name] or watchedAuras[id] or watchedAuras[debuff];
90 local config = RaidFrameCustomization.db.profile[pos];
91 if not config.mine or UnitIsPlayer(caster) then
92 if config.showIcon and not config.useDefaultIcon then
93 -- show icon TODO coloring
94 ind.icon:SetTexture(icon);
96 if config.showText then
99 local remaining = expires - current;
100 if remaining > 60 then
101 text = string.format("%dm", ceil(remaining/60));
103 text = string.format("%d", floor(remaining+0.5));
105 if count > 1 and config.stack then
107 text = count.."-"..text;
113 ind.text:SetText(text);
122 -- Update all indicators
123 function RaidFrameCustomization:UpdateAllIndicators()
124 CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", updateIndicators);
127 -- Used to update everything that is affected by the configuration
128 function RaidFrameCustomization:RefreshConfig()
129 self:OnDisable(); -- clear everything
130 if self.db.profile.enabled then
131 CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", configureIndicators);
132 -- Format aura strings
134 for _, pos in ipairs(positions) do
135 for _, aura in ipairs(self.db.profile[pos]["auras"]) do
136 watchedAuras[aura] = pos; -- TODO single aura only in one position
140 if next(watchedAuras) ~= nil then
141 self.updateTimer = self:ScheduleRepeatingTimer("UpdateAllIndicators", 0.15);