970f937 - Make exp bar contained on its own
[wowui.git] / OmaRF / Indicators.lua
index 8a5882c..3ecdcf6 100644 (file)
@@ -3,40 +3,64 @@ local pairs, ipairs = pairs, ipairs;
 local floor = math.floor;
 local GetTime = GetTime;
 local UnitAura = UnitAura;
-local UnitIsPlayer = UnitIsPlayer;
 local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
 local CTimerAfter = C_Timer.After;
 
-local Frames = OmaFrames;
-local positions = Frames.Positions;
-
-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 Settings = OmaRFSettings;
+local majorAuras = Settings.MajorAuras;
+local indSize = Settings.IndSize;
+local positions = nil;
+local watchedAuras = nil;
 
 local updaters = {};
 local updating = {};
 local auraFilters = {"HELPFUL", "HARMFUL"};
 
 local M = {};
-OmaIndicators = M;
+OmaRFIndicators = M;
+
+function M.SetupIndicators(frame)
+    if not watchedAuras then
+        watchedAuras = Settings.Character["WatchedAuras"];
+        positions = Settings.Character.Positions;
+    end
+
+    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
+        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
+end
 
 local function remaining(text, expires, current)
     if expires == 0 then
@@ -94,6 +118,7 @@ function M.CheckIndicators(frame, unit)
     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();
     for _, filter in ipairs(auraFilters) do
         local i = 1;
@@ -101,14 +126,15 @@ function M.CheckIndicators(frame, unit)
             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 and UnitIsPlayer(caster) then
+            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 majorPos <= 3 then
+            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);
@@ -118,6 +144,9 @@ function M.CheckIndicators(frame, unit)
                     frame.major[majorPos].stack:SetText(count);
                     frame.major[majorPos].stack:Show();
                 end
+                if major.bar then
+                    alert = true;
+                end
                 showMajors = true;
                 majorPos = majorPos + 1;
             end
@@ -141,4 +170,6 @@ function M.CheckIndicators(frame, unit)
         frame.inds:Hide();
         frame.major:Hide();
     end
+
+    return alert;
 end