-local f = OmaRF.frames;
-local majorFrames = OmaRF.majorFrames;
-local positions = OmaRF.positions;
-local pad = 2;
-local paddings = {
- TOPLEFT = {pad, -pad},
- TOPRIGHT = {-pad, -pad},
- CENTER = {0, 0},
- BOTTOMLEFT = {pad, pad},
- BOTTOMRIGHT = {-pad, pad}
-};
-local watchedAuras;
-local majorAuras;
-local majorMax;
-local auraFilters = {"HELPFUL", "HARMFUL"};
-local DEFAULT_ICON = "Interface\\AddOns\\OmaRF\\images\\rhomb";
-local _;
-
--- global functions used every update
-local C_TimerAfter = C_Timer.After;
+-- Indicators.lua
+local pairs, ipairs = pairs, ipairs;
+local floor = math.floor;
local GetTime = GetTime;
local UnitAura = UnitAura;
-local UnitIsPlayer = UnitIsPlayer;
-local UnitIsConnected = UnitIsConnected;
-local UnitIsDeadOrGhost = UnitIsDeadOrGhost;
-local CompactRaidFrameContainer_ApplyToFrames = CompactRaidFrameContainer_ApplyToFrames;
-local format = string.format;
-local unpack = unpack;
-local floor = floor;
-local ceil = ceil;
+local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
+local CTimerAfter = C_Timer.After;
-local function configureIndicators(frame, name)
- local frameName = name or frame:GetName();
- if not f[frameName] then return end
+local Settings = OmaRFSettings;
+local majorAuras = Settings.MajorAuras;
+local indSize = Settings.IndSize;
+local positions = nil;
+local watchedAuras = nil;
- local config = OmaRF.db.profile.indicators;
- for pos, ind in pairs(f[frameName]) do
- ind.text:SetFont(STANDARD_TEXT_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"]));
- end
+local updaters = {};
+local updating = {};
+local auraFilters = {"HELPFUL", "HARMFUL"};
- config = OmaRF.db.profile.majorAuras;
- for i, ind in ipairs(majorFrames[frameName]) do
- if i == 1 then
- ind.icon:ClearAllPoints();
- ind.icon:SetPoint("CENTER", frame, "CENTER", -config.iconSize, 0);
- end
- ind.icon:SetWidth(config.iconSize);
- ind.icon:SetHeight(config.iconSize);
- ind.expire:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE");
- ind.stack:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE");
- end
-end
+local M = {};
+OmaRFIndicators = M;
--- 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]);
+function M.SetupIndicators(frame)
+ if not watchedAuras then
+ watchedAuras = Settings.Character["WatchedAuras"];
+ positions = Settings.Character.Positions;
end
- local config = OmaRF.db.profile.majorAuras;
- majorFrames[name] = {};
- for i = 1, config.max do
- majorFrames[name][i] = {};
- majorFrames[name][i].icon = frame:CreateTexture(nil, "OVERLAY");
- if i > 1 then
- majorFrames[name][i].icon:SetPoint("TOPLEFT", majorFrames[name][i-1].icon, "TOPRIGHT");
+ frame.inds = CreateFrame("Frame", nil, frame);
+ frame.inds:SetAllPoints();
+ frame.inds:Hide();
+ for _, pos in pairs(positions) do
+ frame.inds[pos] = frame.inds:CreateTexture(nil, "OVERLAY");
+ frame.inds[pos]:SetPoint(pos, frame.inds, pos);
+ frame.inds[pos]:SetWidth(indSize);
+ frame.inds[pos]:SetHeight(indSize);
+ frame.inds[pos]:SetTexture("Interface\\AddOns\\OmaRF\\images\\rhomb");
+ frame.inds[pos]:SetVertexColor(1, 0, 0);
+ frame.inds[pos]:Hide();
+ frame.inds[pos].text = frame.inds:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
+ frame.inds[pos].text:SetPoint("BOTTOMRIGHT", frame.inds[pos], "BOTTOMRIGHT");
+ frame.inds[pos].text:Hide();
+ end
+ frame.major = CreateFrame("Frame", nil, frame);
+ frame.major:SetPoint("TOPLEFT", frame, "TOPLEFT", 4, -indSize + 4);
+ frame.major:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT");
+ for i = 1,3 do
+ frame.major[i] = frame.major:CreateTexture(nil, "OVERLAY");
+ if i == 1 then
+ frame.major[i]:SetPoint("TOPLEFT", frame.major, "TOPLEFT");
+ else
+ frame.major[i]:SetPoint("TOPLEFT", frame.major[i-1], "TOPRIGHT");
end
- majorFrames[name][i].expire = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
- majorFrames[name][i].expire:SetPoint("BOTTOMRIGHT", majorFrames[name][i].icon, "BOTTOMRIGHT");
- majorFrames[name][i].stack = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
- majorFrames[name][i].stack:SetPoint("TOPLEFT", majorFrames[name][i].icon, "TOPLEFT");
+ frame.major[i]:SetWidth(indSize*2);
+ frame.major[i]:SetHeight(indSize*2);
+ frame.major[i]:Hide();
+ frame.major[i].text = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
+ frame.major[i].text:SetPoint("BOTTOMRIGHT", frame.major[i], "BOTTOMRIGHT");
+ frame.major[i].text:Hide();
+ frame.major[i].stack = frame.major:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
+ frame.major[i].stack:SetPoint("TOPLEFT", frame.major[i], "TOPLEFT");
+ frame.major[i].stack:Hide();
end
-
- configureIndicators(frame, name);
end
-local function remaining(expires, current)
+local function remaining(text, expires, current)
+ if expires == 0 then
+ text:SetText("");
+ return false;
+ end
local remain = expires - current;
- if remain > 60 then
- return format("%dm", ceil(remain/60));
+ if remain > 8 then
+ text:SetText("");
+ else
+ text:SetText(floor(remain+0.5));
end
- return floor(remain+0.5);
+ return true;
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;
- if not unit then return end -- possible if the frame is just being hidden
+local function updateIndicators(frame, unit)
+ if not frame:IsShown() or not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit) then
+ updating[frame] = nil;
+ return;
+ end
- -- Create indicators if needed
- if not f[frameName] then setupCompactUnitFrame(frame, frameName) end
- -- Reset current
- for _, ind in pairs(f[frameName]) do
- ind.text:Hide();
- ind.icon:Hide();
+ local needUpdate = false;
+ local current = GetTime();
+ for _, pos in pairs(positions) do
+ local ind = frame.inds[pos];
+ if ind.expires ~= nil then
+ needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
+ end
end
- for _, ind in ipairs(majorFrames[frameName]) do
- ind.icon:Hide();
- ind.expire:Hide();
- ind.stack:Hide();
+ for i = 1,3 do
+ local ind = frame.major[i];
+ if ind.expires ~= nil then
+ needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
+ end
end
- -- Hide if unit is dead/disconnected
- if (not UnitIsConnected(unit)) or UnitIsDeadOrGhost(frame.displayedUnit) then
- return;
+ if needUpdate then
+ CTimerAfter(0.16, updaters[frame]);
+ else
+ updating[frame] = nil;
end
+end
+function M.CheckIndicators(frame, unit)
+ for _, pos in pairs(positions) do
+ frame.inds[pos].expires = nil;
+ frame.inds[pos]:Hide();
+ frame.inds[pos].text:Hide();
+ end
+ for i = 1,3 do
+ frame.major[i].expires = nil;
+ frame.major[i]:Hide();
+ frame.major[i].text:Hide();
+ frame.major[i].stack:Hide();
+ end
local name, icon, count, expires, caster, id;
+ local showInds, showMajors, needUpdate = false, false, false;
+ local majorPos = 1;
+ local alert = false; -- color the whole bar
local current = GetTime();
- local majorI = 1;
for _, filter in ipairs(auraFilters) do
local i = 1;
while true do
name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
if not id then break end
local pos = watchedAuras[id] or watchedAuras[name];
- if pos then
- local ind = f[frameName][pos];
- local config = OmaRF.db.profile.indicators[pos];
- if not config.mine or UnitIsPlayer(caster) then
- if config.showIcon then
- -- show icon
- if config.useDefaultIcon then
- ind.icon:SetTexture(DEFAULT_ICON);
- else
- ind.icon:SetTexture(icon);
- end
- ind.icon:Show()
- end
- if config.showText then
- -- show text
- ind.text:SetText(remaining(expires, current));
- ind.text:Show();
- end
- end
+ if pos and caster == "player" then
+ needUpdate = remaining(frame.inds[pos].text, expires, current);
+ frame.inds[pos].expires = expires;
+ frame.inds[pos]:Show();
+ frame.inds[pos].text:Show();
+ showInds = true;
end
-
- if (majorAuras[id] or majorAuras[name]) and majorI <= majorMax then
- local ind = majorFrames[frameName][majorI];
- ind.icon:SetTexture(icon);
- ind.icon:Show();
- ind.expire:SetText(remaining(expires, current));
- ind.expire:Show();
+ local major = majorAuras[id] or majorAuras[name];
+ if major and majorPos <= 3 then
+ needUpdate = remaining(frame.major[majorPos].text, expires, current);
+ frame.major[majorPos].expires = expires;
+ frame.major[majorPos]:SetTexture(icon);
+ frame.major[majorPos]:Show();
+ frame.major[majorPos].text:Show();
if count > 1 then
- ind.stack:SetText(count);
- ind.stack:Show();
+ frame.major[majorPos].stack:SetText(count);
+ frame.major[majorPos].stack:Show();
end
- majorI = majorI + 1;
+ if major.bar then
+ alert = true;
+ end
+ showMajors = true;
+ majorPos = majorPos + 1;
end
i = i + 1;
end
end
-end
-
--- Update all indicators
-function OmaRF:UpdateAllIndicators()
- CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", updateIndicators);
- if OmaRF.running then
- C_TimerAfter(0.15, OmaRF.UpdateAllIndicators);
- end
-end
-
--- Used to update everything that is affected by the configuration
-function OmaRF:RefreshConfig()
- self:OnDisable(); -- clear everything
- if self.db.profile.enabled then
- CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", configureIndicators);
- watchedAuras = {};
- for _, pos in ipairs(positions) do
- for _, aura in ipairs(self.db.profile.indicators[pos]["auras"]) do
- watchedAuras[aura] = pos; -- TODO single aura only in one position
+ if showInds or showMajors then
+ frame.inds:Show();
+ frame.major:Show();
+ if needUpdate and not updating[frame] then
+ updating[frame] = true; -- race?
+ -- create a function for updating the indicator
+ local func = updaters[frame];
+ if not func then
+ func = function() updateIndicators(frame, unit) end;
+ updaters[frame] = func;
end
+ CTimerAfter(0.16, func);
end
- majorAuras = {};
- for _, aura in ipairs(self.db.profile.majorAuras["auras"]) do
- majorAuras[aura] = true;
- end
- majorMax = OmaRF.db.profile.majorAuras["max"];
-
- if next(watchedAuras) ~= nil or next(majorAuras) ~= nil then
- self.running = true;
- C_TimerAfter(0.15, self.UpdateAllIndicators);
- end
+ else
+ frame.inds:Hide();
+ frame.major:Hide();
end
+
+ return alert;
end