976f219 - Add major aura indicator
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sat, 6 Jan 2018 23:59:28 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Sat, 6 Jan 2018 23:59:28 +0000
OmaRF/Core.lua
OmaRF/Indicators.lua
OmaRFConfig/IndicatorsConfig.lua

index 0b44b48..74f5aed 100644 (file)
@@ -6,6 +6,7 @@ OmaRF.normalBackColor = {0.7, 0.7, 0.7};
 OmaRF.dispelBackColor = {0.5, 0.2, 0};
 
 OmaRF.frames = {};
+OmaRF.majorFrames = {};
 OmaRF.positions = {
     "TOPLEFT", "TOPRIGHT", "CENTER", "BOTTOMLEFT", "BOTTOMRIGHT"
 };
@@ -15,6 +16,12 @@ OmaRF.running = false;
 local defaults = {
     profile = {
         enabled = true,
+        majorAuras = {
+            auras = {"Aqua Bomb"},
+            max = 3;
+            iconSize = 24,
+            textSize = 10,
+        },
         indicators = {
             ['**'] = {
                 auras = {},
@@ -45,10 +52,15 @@ end
 
 function OmaRF:OnDisable()
     self.running = false;
-    for _, frame in pairs(self.frames) do
+    for name, frame in pairs(self.frames) do
         for _, ind in pairs(frame) do
-            ind.text:SetText("");
-            ind.icon:SetTexture("");
+            ind.text:Hide();
+            ind.icon:Hide();
+        end
+        for _, ind in ipairs(self.majorFrames[name]) do
+            ind.icon:Hide();
+            ind.expire:Hide();
+            ind.stack:Hide();
         end
     end
 end
index 929b960..f583eac 100644 (file)
@@ -1,4 +1,5 @@
 local f = OmaRF.frames;
+local majorFrames = OmaRF.majorFrames;
 local positions = OmaRF.positions;
 local pad = 2;
 local paddings = {
@@ -8,7 +9,8 @@ local paddings = {
     BOTTOMLEFT = {pad, pad},
     BOTTOMRIGHT = {-pad, pad}
 };
-local watchedAuras; -- all watched auras
+local watchedAuras;
+local majorAuras;
 local auraFilters = {"HELPFUL", "HARMFUL"};
 local DEFAULT_ICON = "Interface\\AddOns\\OmaRF\\images\\rhomb";
 local _;
@@ -23,11 +25,8 @@ local UnitIsDeadOrGhost = UnitIsDeadOrGhost;
 local CompactRaidFrameContainer_ApplyToFrames = CompactRaidFrameContainer_ApplyToFrames;
 local format = string.format;
 local unpack = unpack;
-
--- list of important auras TODO try to use spellIDs
-local centerAuras = {
-    "Power Word: Shield"
-};
+local floor = floor;
+local ceil = ceil;
 
 local function configureIndicators(frame, name)
     local frameName = name or frame:GetName();
@@ -41,11 +40,18 @@ local function configureIndicators(frame, name)
         ind.icon:SetHeight(config[pos]["iconSize"]);
         ind.icon:SetTexture(DEFAULT_ICON);
         ind.icon:SetVertexColor(unpack(config[pos]["iconColor"]));
-        if config[pos]["showIcon"] then
-            ind.icon:Show();
-        else
-            ind.icon:Hide();
+    end
+
+    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
 
@@ -59,9 +65,32 @@ local function setupCompactUnitFrame(frame, name)
         f[name][pos].icon = frame:CreateTexture(nil, "OVERLAY");
         f[name][pos].icon:SetPoint(pos, frame, pos, paddings[pos][1], paddings[pos][2]);
     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");
+        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
+
     configureIndicators(frame, name);
 end
 
+local function remaining(expires, current)
+    local remain = expires - current;
+    if remain > 60 then
+        return format("%dm", ceil(remain/60));
+    end
+    return floor(remain+0.5);
+end
+
 -- Check the indicators on a frame and update the times on them
 local function updateIndicators(frame)
     local frameName = frame:GetName();
@@ -72,8 +101,13 @@ local function updateIndicators(frame)
     if not f[frameName] then setupCompactUnitFrame(frame, frameName) end
     -- Reset current
     for _, ind in pairs(f[frameName]) do
-        ind.text:SetText("");
-        ind.icon:SetTexture("");
+        ind.text:Hide();
+        ind.icon:Hide();
+    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
@@ -82,6 +116,8 @@ local function updateIndicators(frame)
 
     local name, icon, count, debuff, expires, caster, id;
     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
@@ -99,28 +135,28 @@ local function updateIndicators(frame)
                         else
                             ind.icon:SetTexture(icon);
                         end
+                        ind.icon:Show()
                     end
                     if config.showText then
                         -- show text
-                        local text;
-                        local remaining = expires - current;
-                        if remaining > 60 then
-                            text = format("%dm", ceil(remaining/60));
-                        else
-                            text = format("%d", floor(remaining+0.5));
-                        end
-                        if count > 1 and config.stack then
-                            if text then
-                                text = count.."-"..text;
-                            else
-                                text = count;
-                            end
-                        end
-
-                        ind.text:SetText(text);
+                        ind.text:SetText(remaining(expires, current));
+                        ind.text:Show();
                     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;
+            end
             i = i + 1;
         end
     end
@@ -139,15 +175,18 @@ function OmaRF:RefreshConfig()
     self:OnDisable(); -- clear everything
     if self.db.profile.enabled then
         CompactRaidFrameContainer_ApplyToFrames(CompactRaidFrameContainer, "normal", configureIndicators);
-        -- Format aura strings
         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 then
+        if next(watchedAuras) ~= nil or next(majorAuras) ~= nil then
             self.running = true;
             C_TimerAfter(0.15, self.UpdateAllIndicators);
         end
index 0075ced..8783860 100644 (file)
@@ -8,6 +8,63 @@ local function createOptionsTable(self)
                 type = "toggle",
                 name = "Enable",
             },
+            majorAuras = {
+                type = "group",
+                name = "Major Auras",
+                get = function(item) return self.db.profile.majorAuras[item[#item]] end,
+                set = function(item, value)
+                    self.db.profile.majorAuras[item[#item]] = value;
+                    self:RefreshConfig()
+                end,
+                args = {
+                    auras = {
+                        type = "input",
+                        name = "Auras",
+                        multiline = true,
+                        width = "full",
+                        get = function(item)
+                            return table.concat(self.db.profile.majorAuras["auras"], "\n");
+                        end,
+                        set = function(item, value)
+                            local t = {};
+                            for aura in string.gmatch(value, "[^\n]+") do
+                                aura = string.gsub(aura, "^%s*(.-)%s$", "%1");
+                                if tonumber(aura) then
+                                    table.insert(t, tonumber(aura));
+                                else
+                                    table.insert(t, aura);
+                                end
+                            end
+                            self.db.profile.majorAuras["auras"] = t;
+                            self:RefreshConfig();
+                        end,
+                    },
+                    max = {
+                        type = "range",
+                        name = "Number shown",
+                        min = 1,
+                        max = 10,
+                        step = 1,
+                        width = "full",
+                    },
+                    iconSize = {
+                        type = "range",
+                        name = "Icon size",
+                        min = 1,
+                        max = 30,
+                        step = 1,
+                        width = "full",
+                    },
+                    textSize = {
+                        type = "range",
+                        name = "Text size",
+                        min = 1,
+                        max = 30,
+                        step = 1,
+                        width = "full",
+                    },
+                }
+            },
         }
     };