1 local f = OmaRF.frames;
2 local positions = OmaRF.positions;
6 TOPRIGHT = {-pad, -pad},
8 BOTTOMLEFT = {pad, pad},
9 BOTTOMRIGHT = {-pad, pad}
11 local watchedAuras; -- all watched auras
12 local auraFilters = {"HELPFUL", "HARMFUL"};
13 local DEFAULT_ICON = "Interface\\AddOns\\OmaRF\\images\\rhomb";
16 -- global functions used every update
17 local C_TimerAfter = C_Timer.After;
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;
24 local format = string.format;
25 local unpack = unpack;
27 -- list of important auras TODO try to use spellIDs
32 local function configureIndicators(frame, name)
33 local frameName = name or frame:GetName();
34 if not f[frameName] then return end
36 local config = OmaRF.db.profile.indicators;
37 for pos, ind in pairs(f[frameName]) do
38 ind.text:SetFont(STANDARD_TEXT_FONT, config[pos]["textSize"]);
39 ind.text:SetTextColor(unpack(config[pos]["textColor"]));
40 ind.icon:SetWidth(config[pos]["iconSize"]);
41 ind.icon:SetHeight(config[pos]["iconSize"]);
42 ind.icon:SetTexture(DEFAULT_ICON);
43 ind.icon:SetVertexColor(unpack(config[pos]["iconColor"]));
44 if config[pos]["showIcon"] then
52 -- Create the FontStrings used for indicators
53 local function setupCompactUnitFrame(frame, name)
55 for _, pos in ipairs(positions) do
57 f[name][pos].text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
58 f[name][pos].text:SetPoint(pos, frame, pos, paddings[pos][1], paddings[pos][2]);
59 f[name][pos].icon = frame:CreateTexture(nil, "OVERLAY");
60 f[name][pos].icon:SetPoint(pos, frame, pos, paddings[pos][1], paddings[pos][2]);
62 configureIndicators(frame, name);
65 -- Check the indicators on a frame and update the times on them
66 local function updateIndicators(frame)
67 local frameName = frame:GetName();
68 local unit = frame.unit;
69 if not unit then return end -- possible if the frame is just being hidden
71 -- Create indicators if needed
72 if not f[frameName] then setupCompactUnitFrame(frame, frameName) end
74 for _, ind in pairs(f[frameName]) do
76 ind.icon:SetTexture("");
78 -- Hide if unit is dead/disconnected
79 if (not UnitIsConnected(unit)) or UnitIsDeadOrGhost(frame.displayedUnit) then
83 local name, icon, count, debuff, expires, caster, id;
84 local current = GetTime();
85 for _, filter in ipairs(auraFilters) do
88 name, _, icon, count, debuff, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
89 if not id then break end
90 local pos = watchedAuras[name] or watchedAuras[id] or watchedAuras[debuff];
92 local ind = f[frameName][pos];
93 local config = OmaRF.db.profile.indicators[pos];
94 if not config.mine or UnitIsPlayer(caster) then
95 if config.showIcon then
97 if config.useDefaultIcon then
98 ind.icon:SetTexture(DEFAULT_ICON);
100 ind.icon:SetTexture(icon);
103 if config.showText then
106 local remaining = expires - current;
107 if remaining > 60 then
108 text = format("%dm", ceil(remaining/60));
110 text = format("%d", floor(remaining+0.5));
112 if count > 1 and config.stack then
114 text = count.."-"..text;
120 ind.text:SetText(text);
129 -- Update all indicators
130 function OmaRF:UpdateAllIndicators()
131 CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", updateIndicators);
132 if OmaRF.running then
133 C_TimerAfter(0.15, OmaRF.UpdateAllIndicators);
137 -- Used to update everything that is affected by the configuration
138 function OmaRF:RefreshConfig()
139 self:OnDisable(); -- clear everything
140 if self.db.profile.enabled then
141 CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", configureIndicators);
142 -- Format aura strings
144 for _, pos in ipairs(positions) do
145 for _, aura in ipairs(self.db.profile.indicators[pos]["auras"]) do
146 watchedAuras[aura] = pos; -- TODO single aura only in one position
150 if next(watchedAuras) ~= nil then
152 C_TimerAfter(0.15, self.UpdateAllIndicators);