b13d011 - Re-add basic indicators
[wowui.git] / OmaRF / Indicators.lua
index f583eac..c408815 100644 (file)
-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 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 GetTime = GetTime;
 local UnitAura = UnitAura;
 local UnitIsPlayer = UnitIsPlayer;
 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 CTimerAfter = C_Timer.After;
 
 
-local function configureIndicators(frame, name)
-    local frameName = name or frame:GetName();
-    if not f[frameName] then return end
+local watchedAuras = {
+    [53563] = "TOPRIGHT",
+    [156910] = "TOPRIGHT",
+    [200025] = "TOPRIGHT",
+    [200654] = "BOTTOMLEFT",
+};
+local majorAuras = {
+    ["Psychic Assault"] = true,
+    ["Everburning Flames"] = true,
+    ["Corrupt"] = true,
+    ["Sleep Canister"] = true,
+    ["Misery"] = true,
+    ["Necrotic Embrace"] = true,
+    ["Fulminating Pulse"] = true,
+    ["Chilled Blood"] = true,
+    ["Soulblight"] = true,
+    ["Soulburst"] = true,
+    ["Soulbomb"] = true,
+    ["Aqua Bomb"] = true,
+};
 
 
-    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 positions = {"TOPRIGHT", "BOTTOMLEFT"};
+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");
+-- TODO text
+--[[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
     end
-end
+    return floor(remain+0.5);
+end]]
 
 
--- 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]);
+--[[local function updateIndicators(frame, unit)
+    if not frame:IsShown() then
+        return;
+    elseif not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit) then
+        if frame.inds:IsShown() then frame.inds:Hide() end
+        return;
+    elseif not frame.inds:IsShown() then
+        frame.inds:Show();
     end
 
     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");
+    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
-        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");
     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]]
 
 
-    configureIndicators(frame, name);
-end
-
-local function remaining(expires, current)
-    local remain = expires - current;
-    if remain > 60 then
-        return format("%dm", ceil(remain/60));
+--local function showIndicator(ind, caster, expires, current, config)
+local function showIndicator(ind, caster)
+    --if not config.mine or UnitIsPlayer(caster) then
+    if UnitIsPlayer(caster) then
+        --if config.showIcon and not ind:IsShown() then
+        if not ind:IsShown() then
+            ind:Show();
+        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
-    return floor(remain+0.5);
 end
 
 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
-
-    -- 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();
+function OmaCheckIndicators(frame, unit)
+    for _, pos in pairs(positions) do
+        --ind.expires = nil;
+        if frame.inds[pos]:IsShown() then frame.inds[pos]:Hide() end
     end
     end
-    for _, ind in ipairs(majorFrames[frameName]) do
-        ind.icon:Hide();
-        ind.expire:Hide();
-        ind.stack:Hide();
-    end
-    -- Hide if unit is dead/disconnected
-    if (not UnitIsConnected(unit)) or UnitIsDeadOrGhost(frame.displayedUnit) then
-        return;
+    for i = 1,3 do
+        --ind.expires = nil;
+        if frame.major[1]:IsShown() then frame.major[1]:Hide() end
     end
     end
+    frame.showInds = false;
+    frame.showMajors = false;
 
 
-    local name, icon, count, debuff, expires, caster, id;
+    local name, icon, count, expires, caster, id;
+    local majorPos = 1;
     local current = GetTime();
     local current = GetTime();
-    local majorI = 1;
-    local majorMax = OmaRF.db.profile.majorAuras["max"];
     for _, filter in ipairs(auraFilters) do
         local i = 1;
         while true do
     for _, filter in ipairs(auraFilters) do
         local i = 1;
         while true do
-            name, _, icon, count, debuff, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
+            name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
             if not id then break end
             if not id then break end
-            local pos = watchedAuras[name] or watchedAuras[id] or watchedAuras[debuff];
+            local pos = watchedAuras[id] or watchedAuras[name];
             if pos then
             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
+                frame.showInds = true;
+                if UnitIsPlayer(caster) and not frame.inds[pos]:IsShown() then
+                    frame.inds[pos]:Show();
                 end
             end
                 end
             end
-
-            if majorI <= majorMax and (majorAuras[id] or majorAuras[name]) then
-                local ind = majorFrames[frameName][majorI];
-                ind.icon:SetTexture(icon);
-                ind.icon:Show();
-                ind.expire:SetText(remaining(expires, current));
-                ind.expire:Show();
-                if count > 1 then
-                    ind.stack:SetText(count);
-                    ind.stack:Show();
-                end
-                majorI = majorI + 1;
+            if (majorAuras[id] or majorAuras[name]) and majorPos <= 3 then
+                frame.major[majorPos]:SetTexture(icon);
+                frame.major[majorPos]:Show();
+                frame.showMajors = true;
+                majorPos = majorPos + 1;
             end
             i = i + 1;
         end
     end
             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
-            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
-            self.running = true;
-            C_TimerAfter(0.15, self.UpdateAllIndicators);
+    if frame.showInds then
+        if not frame.inds:IsShown() then frame.inds:Show() end
+        -- create a function for updating the indicator each second
+        --[[local func = updaters[frame];
+        if not func then
+            func = function() updateIndicators(frame, unit) end;
+            updaters[frame] = func;
         end
         end
+        CTimerAfter(1, func);]]
+    elseif frame.inds:IsShown() then
+        frame.inds:Hide();
+    end
+    if frame.showMajors then
+        if not frame.major:IsShown() then frame.major:Show() end
+    elseif frame.major:IsShown() then
+        frame.major:Hide();
     end
 end
     end
 end
+