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 indicatorAuras; -- watched auras per indicator
14 local auraFilters = {"HELPFUL", "HARMFUL"};
15 local DEFAULT_ICON = "Interface\\AddOns\\RaidFrameCustomization\\images\\rhomb";
18 -- global functions used every update
19 local GetTime = GetTime;
20 local UnitAura = UnitAura;
21 local UnitIsPlayer = UnitIsPlayer;
22 local UnitIsConnected = UnitIsConnected;
23 local UnitIsDeadOrGhost = UnitIsDeadOrGhost;
24 local CompactRaidFrameContainer_ApplyToFrames = CompactRaidFrameContainer_ApplyToFrames;
26 -- list of important auras TODO try to use spellIDs
31 local function configureIndicators(frame)
32 local frameName = frame:GetName();
33 if not f[frameName] then return end
35 local config = RaidFrameCustomization.db.profile;
36 local font = media and media:Fetch('font', config.indicatorFont) or STANDARD_TEXT_FONT;
37 for pos, ind in pairs(f[frameName]) do
38 ind.text:SetFont(font, config[pos]["textSize"]);
39 ind.text:SetTextColor(unpack(config[pos]["color"]));
40 ind.icon:SetWidth(config[pos]["iconSize"]);
41 ind.icon:SetHeight(config[pos]["iconSize"]);
42 ind.icon:SetTexture(DEFAULT_ICON);
43 if config[pos]["showIcon"] then
51 -- Create the FontStrings used for indicators
52 local function setupCompactUnitFrame(frame)
53 local name = frame:GetName();
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);
65 -- Get all unit auras TODO change to event driven, only remaining updating with timer
66 local function getAuras(unit)
68 local auraName, icon, count, expires, caster, debuffType, spellId;
71 for _, filter in ipairs(auraFilters) do
74 auraName, _, icon, count, debuffType, _, expires, caster, _, _, spellId = UnitAura(unit, i, filter);
75 if not spellId then break end
76 if watchedAuras[auraName] or watchedAuras[spellId] or watchedAuras[debuffType] then
78 aura.auraName = auraName;
79 aura.spellId = spellId;
81 aura.expires = expires;
82 aura.mine = UnitIsPlayer(caster);
84 aura.debuffType = debuffType;
85 table.insert(unitAuras, aura);
93 -- Check the indicators on a frame and update the times on them
94 local function updateIndicators(frame)
95 if not frame.unit then return end
96 local unit = frame.unit;
97 local frameName = frame:GetName();
99 -- Check if the indicator object exists, else create it
100 if not f[frameName] then setupCompactUnitFrame(frame) end
101 -- Hide if unit is dead/disconnected
102 if (not UnitIsConnected(unit)) or UnitIsDeadOrGhost(frame.displayedUnit) then
103 for _, ind in pairs(f[frameName]) do
104 ind.text:SetText("");
105 ind.icon:SetTexture("");
110 local unitAuras = getAuras(unit);
111 for pos, ind in pairs(f[frameName]) do
112 -- try to find matching aura
114 for _, aura in pairs(unitAuras) do
115 if indicatorAuras[pos][aura.auraName] or indicatorAuras[pos][aura.spellId] or
116 indicatorAuras[pos][aura.debuffType] then
118 -- break on first matching buff/debuff cast by me
119 -- otherwise continue through
120 if aura.mine then break end
124 local config = RaidFrameCustomization.db.profile[pos];
126 if config.mine and not found.mine then
128 ind.icon:SetTexture("");
129 ind.text:SetText("");
131 if config.showIcon and not config.useDefaultIcon then
132 -- show icon TODO coloring
133 ind.icon:SetTexture(found.icon);
135 if config.showText then
138 local remaining = found.expires - GetTime();
139 if remaining > 60 then
140 text = string.format("%dm", ceil(remaining/60));
142 text = string.format("%d", floor(remaining+0.5));
145 if config.stack and found.count > 0 then
147 text = found.count.."-"..text;
153 ind.text:SetText(text);
157 -- not found, show nothing
158 ind.icon:SetTexture("");
159 ind.text:SetText("");
164 -- Update all indicators
165 function RaidFrameCustomization:UpdateAllIndicators()
166 CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", updateIndicators);
169 -- Used to update everything that is affected by the configuration
170 function RaidFrameCustomization:RefreshConfig()
171 self:OnDisable(); -- clear everything
172 if self.db.profile.enabled then
173 CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", configureIndicators);
174 -- Format aura strings
177 for _, pos in ipairs(positions) do
178 indicatorAuras[pos] = {};
179 for _, aura in ipairs(self.db.profile[pos]["auras"]) do
180 watchedAuras[aura] = true;
181 indicatorAuras[pos][aura] = true;
185 if next(watchedAuras) ~= nil then
186 self.updateTimer = self:ScheduleRepeatingTimer("UpdateAllIndicators", 0.15);