+++ /dev/null
--- Indicators.lua
-local unpack, ipairs, pairs, ceil, floor = unpack, ipairs, pairs, ceil, floor;
-local UnitIsConnected, UnitIsDeadOrGhost = UnitIsConnected, UnitIsDeadOrGhost;
-local UnitAura, UnitIsPlayer, GetTime = UnitAura, UnitIsPlayer, GetTime;
-local UnitName, C_TimerAfter = UnitName, C_Timer.After;
-local IsInGroup, IsInRaid, GetNumGroupMembers = IsInGroup, IsInRaid, GetNumGroupMembers;
-local format = string.format;
-
-local positions = OmaRF.positions;
-local auraFilters = {"HELPFUL", "HARMFUL"};
-local DEFAULT_ICON = "Interface\\AddOns\\OmaRF\\images\\rhomb";
-local _;
-
-local frameBase;
-local frames = {};
-local watchedAuras = {};
-local majorAuras = {};
-local majorMax;
-local partyState = "solo";
-local partyMembers = {"player", "party1", "party2", "party3", "party4"};
-
-local function remaining(expires, current)
- if expires == 0 then return "" end
- local remain = expires - current;
- if remain > 60 then
- return format("%dm", ceil(remain/60));
- end
- return floor(remain+0.5);
-end
-
-local function showIndicator(ind, icon, caster, expires, current, config)
- if not config.mine or UnitIsPlayer(caster) then
- if config.showIcon then
- if config.useDefaultIcon then
- ind.icon:SetTexture(DEFAULT_ICON);
- else
- ind.icon:SetTexture(icon);
- end
- if not ind.icon:IsShown() then ind.icon:Show() end
- end
- ind.expires = expires;
- if config.showText then
- ind.text:SetText(remaining(expires, current));
- if not ind.text:IsShown() then ind.text:Show() end
- end
- end
-end
-
-local function showMajorIndicator(ind, icon, count, expires, current)
- ind.icon:SetTexture(icon);
- ind.expires = expires;
- ind.expireText:SetText(remaining(expires, current));
- if count > 1 then
- ind.stackText:SetText(count);
- if not ind.stackText:IsShown() then ind.stackText:Show() end
- else
- if ind.stackText:IsShown() then ind.stackText:Hide() end
- end
- if not ind.icon:IsShown() then ind.icon:Show() end
- if not ind.expireText:IsShown() then ind.expireText:Show() end
-end
-
--- update current auras TODO add bar coloring back with extra options
-local function updateAuras(frame, unit)
- for _, ind in pairs(frame.inds) do ind.expires = nil end
- for _, ind in ipairs(frame.majorInds) do ind.expires = nil end
-
- local name, icon, count, expires, caster, id;
- local majorPos = 1;
- local current = GetTime();
- 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
- showIndicator(
- frame.inds[pos], icon, caster, expires, current,
- OmaRF.db.profile.indicators[pos]
- );
- end
- if (majorAuras[id] or majorAuras[name]) and majorPos <= majorMax then
- showMajorIndicator(frame.majorInds[majorPos], icon, count, expires, current);
- majorPos = majorPos + 1;
- end
- i = i + 1;
- end
- end
-end
-
--- Check the indicators on a frame and update the times on them
-local function updateIndicators(frame, i)
- local unit = "player";
- if partyState == "solo" then
- if frame:IsShown() then frame:Hide() end
- return;
- elseif partyState == "raid" then
- unit = partyState..i;
- elseif i ~= 1 then
- -- party frames have player separate
- unit = partyState..(i-1);
- end
-
- if not UnitExists(unit) then
- return;
- elseif not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit) then
- if frame:IsShown() then frame:Hide() end
- return;
- elseif not frame:IsShown() then
- frame:Show();
- end
-
- local current = GetTime();
- for pos, ind in pairs(frame.inds) do
- if ind.expires ~= nil then
- if OmaRF.db.profile.indicators[pos].showText then
- ind.text:SetText(remaining(ind.expires, current));
- end
- else
- if ind.icon:IsShown() then ind.icon:Hide() end
- if ind.text:IsShown() then ind.text:Hide() end
- end
- end
- for _, ind in ipairs(frame.majorInds) do
- if ind.expires ~= nil then
- ind.expireText:SetText(remaining(ind.expires, current));
- else
- if ind.icon:IsShown() then ind.icon:Hide() end
- if ind.expireText:IsShown() then ind.expireText:Hide() end
- if ind.stackText:IsShown() then ind.stackText:Hide() end
- end
- end
-end
-
-local function configureIndicators(frame)
- local config = OmaRF.db.profile.indicators;
- for pos, ind in pairs(frame.inds) 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
-
- config = OmaRF.db.profile.majorAuras;
- for i, ind in ipairs(frame.majorInds) 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.expireText:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE");
- ind.stackText:SetFont(STANDARD_TEXT_FONT, config["textSize"], "OUTLINE");
- end
-end
-
-local function createIndicators(frame)
- frame.inds = {};
- for _, pos in ipairs(positions) do
- frame.inds[pos] = {};
- frame.inds[pos].text = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
- frame.inds[pos].text:SetPoint(pos, frame, pos);
- frame.inds[pos].icon = frame:CreateTexture(nil, "OVERLAY");
- frame.inds[pos].icon:SetPoint(pos, frame, pos);
- end
-
- frame.majorInds = {};
- majorMax = OmaRF.db.profile.majorAuras.max;
- for i = 1, majorMax do
- frame.majorInds[i] = {};
- local ind = frame.majorInds[i];
- ind.icon = frame:CreateTexture(nil, "OVERLAY");
- if i > 1 then
- ind.icon:SetPoint("TOPLEFT", frame.majorInds[i-1].icon, "TOPRIGHT");
- end
- ind.expireText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
- ind.expireText:SetPoint("BOTTOMRIGHT", ind.icon, "BOTTOMRIGHT");
- ind.stackText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
- ind.stackText:SetPoint("TOPLEFT", ind.icon, "TOPLEFT");
- end
-
- configureIndicators(frame);
-end
-
--- Update all indicators
-local function updateAllIndicators()
- for i, frame in ipairs(frames) do
- updateIndicators(frame, i);
- end
- if OmaRF.running then C_TimerAfter(0.15, 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
- for _, f in pairs(frames) do configureIndicators(f) end
-
- 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
- end
- end
- majorAuras = {};
- for _, aura in ipairs(self.db.profile.majorAuras["auras"]) do
- majorAuras[aura] = true;
- end
-
- if next(watchedAuras) ~= nil or next(majorAuras) ~= nil then
- if not frameBase:IsShown() then frameBase:Show() end
- self.running = true;
- C_TimerAfter(0.15, updateAllIndicators);
- end
- end
-end
-
-local function updateStatusText(self, unit)
- if not UnitIsConnected(unit) then
- self.statusText:SetText("DC");
- elseif UnitIsDeadOrGhost(unit) then
- self.statusText:SetText("rip");
- else
- local healthLost = UnitHealthMax(unit) - UnitHealth(unit);
- if healthLost <= 0 then
- self.statusText:SetText("");
- return;
- end
-
- local prettyHealth;
- if healthLost > 1200000000 then -- 1.2B
- prettyHealth = format("-%.1fB", healthLost / 1000000000);
- elseif healthLost > 1200000 then -- 1.2M
- prettyHealth = format("-%.1fM", healthLost / 1000000);
- elseif healthLost > 1000 then -- 1K
- prettyHealth = format("-%dK", healthLost / 1000);
- else
- prettyHealth = format("-%d", healthLost)
- end
-
- self.statusText:SetText(prettyHealth);
- end
-end
-
-local function frameEvent(self, event, ...)
- local arg1, arg2, arg3, arg4 = ...;
- if event == "UNIT_HEALTH" or event == "UNIT_HEALTH_FREQUENT" then
- updateStatusText(self, arg1);
- elseif event == "UNIT_AURA" then
- updateAuras(self, arg1);
- end
-end
-
---[[ TODO powerBar display and bar coloring
- if options.displayPowerBar and role ~= "HEALER" then
- frame.healthBar:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1);
- frame.powerBar:Hide();
- end
-]]
-
---local update_ooc = false;
-local function updateFrames()
- if not IsInGroup() or GetNumGroupMembers() == 1 then
- -- solo
- partyState = "solo";
- local frame = frames[1];
- frame:UnregisterAllEvents();
- frame:RegisterUnitEvent("UNIT_AURA", "player");
- frame:RegisterUnitEvent("UNIT_HEALTH", "player");
- frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", "player");
- else
- if IsInRaid() then
- partyState = "raid";
- for i, frame in ipairs(frames) do
- local name = partyState..i;
- if not UnitExists(name) then break end
- frame:UnregisterAllEvents();
- frame:RegisterUnitEvent("UNIT_AURA", name);
- frame:RegisterUnitEvent("UNIT_HEALTH", name);
- frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", name);
- end
- else
- partyState = "party";
- for i, name in ipairs(partyMembers) do
- local frame = frames[i];
- if not UnitExists(name) then break end
- frame:UnregisterAllEvents();
- frame:RegisterUnitEvent("UNIT_AURA", name);
- frame:RegisterUnitEvent("UNIT_HEALTH", name);
- frame:RegisterUnitEvent("UNIT_HEALTH_FREQUENT", name);
- end
- end
- end
- --[[for name, frame in pairs(frames) do
- local unitFrame = _G[name];
- if unitFrame then
- if not frame.unitFrameSetup then
- if InCombatLockdown() then
- update_ooc = true;
- else
- unitFrame.name:SetFont(STANDARD_TEXT_FONT, 12, "");
- unitFrame.optionTable.displayBuffs = false;
- unitFrame.optionTable.displayDebuffs = false;
- unitFrame.optionTable.displayDispelDebuffs = false;
- frame.unitFrameSetup = true;
- end
- end
- local unit = unitFrame.unit;
- if unit then
- if InCombatLockdown() then
- update_ooc = true;
- else
- local name = UnitName(unit);
- unitFrame.name:SetText(name);
- end
- end
- end
- end]]
-end
-
-local function createStatusText(frame)
- frame.statusText = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall");
- frame.statusText:SetPoint("CENTER", frame, "CENTER");
- frame.statusText:SetFont(STANDARD_TEXT_FONT, 14, "");
-end
-
-local function initialize(frame)
- frames[1] = CreateFrame("Frame", "OmaRF1", frameBase);
- frames[1]:SetAllPoints("CompactRaidFrame1"); -- only connection to blizzard frames
- frames[1]:SetScript("OnEvent", frameEvent);
- frames[1]:Hide();
- createStatusText(frames[1]);
- createIndicators(frames[1]);
- local i = 2;
- -- TODO size could change
- local width, height = frames[1]:GetWidth(), frames[1]:GetHeight();
- for y = 2,5 do
- frames[i] = CreateFrame("Frame", "OmaRF"..i, frameBase);
- frames[i]:SetPoint("TOPLEFT", frames[i-1], "BOTTOMLEFT");
- frames[i]:SetWidth(width);
- frames[i]:SetHeight(height);
- frames[i]:SetScript("OnEvent", frameEvent);
- frames[i]:Hide();
- createStatusText(frames[i]);
- createIndicators(frames[i]);
- i = i + 1;
- end
- for x = 0,6 do
- for y = 1,5 do
- frames[i] = CreateFrame("Frame", "OmaRF"..i, frameBase);
- frames[i]:SetPoint("TOPLEFT", frames[x*5+y], "TOPRIGHT");
- frames[i]:SetWidth(width);
- frames[i]:SetHeight(height);
- frames[i]:SetScript("OnEvent", frameEvent);
- frames[i]:Hide();
- createStatusText(frames[i]);
- createIndicators(frames[i]);
- i = i + 1;
- end
- end
- C_TimerAfter(0.01, updateFrames);
-end
-
-local function baseEvent(self, event, ...)
- if event == "GROUP_ROSTER_UPDATE" then
- -- not sure if fired before LayoutFrames, wait a bit
- C_TimerAfter(0.01, updateFrames);
- --[[elseif event == "PLAYER_REGEN_ENABLED" then
- if update_ooc then
- updateFrames();
- update_ooc = false;
- end]]
- elseif event == "PLAYER_LOGIN" then
- initialize();
- end
-end
-
-frameBase = CreateFrame("Frame", nil, UIParent);
-frameBase:SetFrameStrata("HIGH");
-frameBase:RegisterEvent("PLAYER_LOGIN");
-frameBase:RegisterEvent("PLAYER_REGEN_ENABLED");
-frameBase:RegisterEvent("GROUP_ROSTER_UPDATE");
-frameBase:SetScript("OnEvent", baseEvent);
-OmaRF.frameBase = frameBase;
-
--- hide buffs, debuffs from Blizzard frames
---DefaultCompactUnitFrameOptions.displayBuffs = false;
---DefaultCompactUnitFrameOptions.displayDebuffs = false;
---DefaultCompactUnitFrameOptions.displayDispelDebuffs = false;