2 local unpack, ipairs, pairs, ceil, floor = unpack, ipairs, pairs, ceil, floor;
3 local UnitIsConnected, UnitIsDeadOrGhost = UnitIsConnected, UnitIsDeadOrGhost;
4 local UnitAura, UnitIsPlayer, GetTime = UnitAura, UnitIsPlayer, GetTime;
5 local C_TimerAfter = C_Timer.After;
6 local format = string.format;
8 local positions = OmaRF.positions;
9 local auraFilters = {"HELPFUL", "HARMFUL"};
10 local DEFAULT_ICON = "Interface\\AddOns\\OmaRF\\images\\rhomb";
15 local watchedAuras = {};
16 local majorAuras = {};
19 local function remaining(expires, current)
20 if expires == 0 then return "" end
21 local remain = expires - current;
23 return format("%dm", ceil(remain/60));
25 return floor(remain+0.5);
28 local function showIndicator(ind, icon, caster, expires, current, config)
29 if not config.mine or UnitIsPlayer(caster) then
30 if config.showIcon then
31 if config.useDefaultIcon then
32 ind.icon:SetTexture(DEFAULT_ICON);
34 ind.icon:SetTexture(icon);
36 if not ind.icon:IsShown() then ind.icon:Show() end
38 ind.expires = expires;
39 if config.showText then
40 ind.text:SetText(remaining(expires, current));
41 if not ind.text:IsShown() then ind.text:Show() end
46 local function showMajorIndicator(ind, icon, count, expires, current)
47 ind.icon:SetTexture(icon);
48 ind.expires = expires;
49 ind.expireText:SetText(remaining(expires, current));
51 ind.stackText:SetText(count);
52 if not ind.stackText:IsShown() then ind.stackText:Show() end
54 if ind.stackText:IsShown() then ind.stackText:Hide() end
56 if not ind.icon:IsShown() then ind.icon:Show() end
57 if not ind.expireText:IsShown() then ind.expireText:Show() end
60 -- update current auras
61 hooksecurefunc("CompactUnitFrame_UpdateAuras", function(unitFrame)
62 local frameName = unitFrame:GetName();
63 if frames[frameName] then
64 local frame = frames[frameName];
65 for _, ind in pairs(frame.inds) do ind.expires = nil end
66 for _, ind in ipairs(frame.majorInds) do ind.expires = nil end
68 local name, icon, count, expires, caster, id;
69 local unit = unitFrame.displayedUnit;
71 local current = GetTime();
72 for _, filter in ipairs(auraFilters) do
75 name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
76 if not id then break end
77 local pos = watchedAuras[id] or watchedAuras[name];
80 frame.inds[pos], icon, caster, expires, current,
81 OmaRF.db.profile.indicators[pos]
84 if (majorAuras[id] or majorAuras[name]) and majorPos <= majorMax then
85 showMajorIndicator(frame.majorInds[majorPos], icon, count, expires, current);
86 majorPos = majorPos + 1;
94 -- Check the indicators on a frame and update the times on them
95 local function updateIndicators(frame, name)
96 local unitFrame = _G[name]; -- has to always reference global
97 if unitFrame == nil then
99 elseif not unitFrame:IsVisible() then
100 if frame:IsShown() then frame:Hide() end
104 local unit = unitFrame.unit;
105 local displayedUnit = unitFrame.displayedUnit;
106 if not unit or not UnitIsConnected(unit) or UnitIsDeadOrGhost(displayedUnit) then
107 if frame:IsShown() then frame:Hide() end
110 if not frame:IsShown() then frame:Show() end
112 local current = GetTime();
113 for pos, ind in pairs(frame.inds) do
114 if ind.expires ~= nil then
115 if OmaRF.db.profile.indicators[pos].showText then
116 ind.text:SetText(remaining(ind.expires, current));
119 if ind.icon:IsShown() then ind.icon:Hide() end
120 if ind.text:IsShown() then ind.text:Hide() end
123 for _, ind in ipairs(frame.majorInds) do
124 if ind.expires ~= nil then
125 ind.expireText:SetText(remaining(ind.expires, current));
127 if ind.icon:IsShown() then ind.icon:Hide() end
128 if ind.expireText:IsShown() then ind.expireText:Hide() end
129 if ind.stackText:IsShown() then ind.stackText:Hide() end
134 local function configureIndicators(frame)
135 local config = OmaRF.db.profile.indicators;
136 for pos, ind in pairs(frame.inds) do
137 ind.text:SetFont(STANDARD_TEXT_FONT, config[pos]["textSize"]);
138 ind.text:SetTextColor(unpack(config[pos]["textColor"]));
139 ind.icon:SetWidth(config[pos]["iconSize"]);
140 ind.icon:SetHeight(config[pos]["iconSize"]);
141 ind.icon:SetTexture(DEFAULT_ICON);
142 ind.icon:SetVertexColor(unpack(config[pos]["iconColor"]));
145 config = OmaRF.db.profile.majorAuras;
146 for i, ind in ipairs(frame.majorInds) do
148 ind.icon:ClearAllPoints();
149 ind.icon:SetPoint("CENTER", frame, "CENTER", -config["iconSize"], 0);
151 ind.icon:SetWidth(config["iconSize"]);
152 ind.icon:SetHeight(config["iconSize"]);
153 ind.expireText:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE");
154 ind.stackText:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE");
158 local function createIndicators(frame)
160 for _, pos in ipairs(positions) do
161 frame.inds[pos] = {};
162 frame.inds[pos].text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
163 frame.inds[pos].text:SetPoint(pos, frame, pos);
164 frame.inds[pos].icon = frame:CreateTexture(nil, "OVERLAY");
165 frame.inds[pos].icon:SetPoint(pos, frame, pos);
168 frame.majorInds = {};
169 majorMax = OmaRF.db.profile.majorAuras.max;
170 for i = 1, majorMax do
171 frame.majorInds[i] = {};
172 local ind = frame.majorInds[i];
173 ind.icon = frame:CreateTexture(nil, "OVERLAY");
175 ind.icon:SetPoint("TOPLEFT", frame.majorInds[i-1].icon, "TOPRIGHT");
177 ind.expireText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
178 ind.expireText:SetPoint("BOTTOMRIGHT", ind.icon, "BOTTOMRIGHT");
179 ind.stackText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
180 ind.stackText:SetPoint("TOPLEFT", ind.icon, "TOPLEFT");
183 configureIndicators(frame);
186 -- Update all indicators
187 local function updateAllIndicators()
188 for name, frame in pairs(frames) do updateIndicators(frame, name) end
189 if OmaRF.running then C_TimerAfter(0.15, updateAllIndicators) end
192 -- Used to update everything that is affected by the configuration
193 function OmaRF:RefreshConfig()
194 self:OnDisable(); -- clear everything
195 if self.db.profile.enabled then
196 for _, f in pairs(frames) do configureIndicators(f) end
199 for _, pos in ipairs(positions) do
200 for _, aura in ipairs(self.db.profile.indicators[pos]["auras"]) do
201 watchedAuras[aura] = pos; -- TODO single aura only in one position
205 for _, aura in ipairs(self.db.profile.majorAuras["auras"]) do
206 majorAuras[aura] = true;
209 if next(watchedAuras) ~= nil or next(majorAuras) ~= nil then
212 C_TimerAfter(0.15, updateAllIndicators);
217 local function updateFrames()
218 for name, frame in pairs(frames) do
219 local unitFrame = _G[name];
221 if not frame.pointsSet then
222 frame:SetAllPoints(unitFrame);
223 frame.pointsSet = true;
229 local function initialize(frame)
230 local name = "CompactRaidFrame1";
231 frames[name] = CreateFrame("Frame", "OmaRF1", frameBase);
232 frames[name]:SetAllPoints(name);
234 createIndicators(frames[name]);
237 local name = "CompactRaidFrame"..i;
238 frames[name] = CreateFrame("Frame", "OmaRF"..i, frameBase);
240 createIndicators(frames[name]);
245 local name = "CompactRaidFrame"..i;
246 frames[name] = CreateFrame("Frame", "OmaRF"..i, frameBase);
248 createIndicators(frames[name]);
254 local function onEvent(self, event, ...)
255 if event == "GROUP_ROSTER_UPDATE" then
256 -- not sure if fired before LayoutFrames, wait a bit
257 C_TimerAfter(0.01, updateFrames);
258 elseif event == "PLAYER_LOGIN" then
263 frameBase = CreateFrame("Frame", nil, UIParent);
264 frameBase:SetFrameStrata("HIGH");
265 frameBase:RegisterEvent("PLAYER_LOGIN");
266 frameBase:RegisterEvent("GROUP_ROSTER_UPDATE");
267 frameBase:SetScript("OnEvent", onEvent);
268 OmaRF.frameBase = frameBase;