c39801d - Add simple red alert aura tracking
[wowui.git] / OmaRF / Events.lua
index 204ac8b..2ffe946 100644 (file)
@@ -20,7 +20,8 @@ local READY_CHECK_READY_TEXTURE = READY_CHECK_READY_TEXTURE;
 local READY_CHECK_NOT_READY_TEXTURE = READY_CHECK_NOT_READY_TEXTURE;
 local READY_CHECK_WAITING_TEXTURE = READY_CHECK_WAITING_TEXTURE;
 
-local checkIndicators = OmaRFIndicators.CheckIndicators;
+local updateIndicatorAuras = OmaRFIndicators.UpdateAuras;
+local updateMajorAuras = OmaRFIndicators.UpdateMajorAuras;
 
 local Settings = OmaRFSettings;
 local baseColor = Settings.BaseColor;
@@ -64,6 +65,7 @@ local registerUnitEvents = M.RegisterUnitEvents;
 
 local function updateText(frame, unit)
     if UnitIsDeadOrGhost(unit) then
+        frame.dead = true;
         frame.text:SetText("Dead");
         frame.text:Show();
     elseif not UnitIsConnected(unit) then
@@ -79,10 +81,12 @@ local function updateText(frame, unit)
         frame.text:Hide();
     end
 end
+M.UpdateText = updateText;
 
 local function updateMaxHealth(frame, unit)
     frame.health.max = UnitHealthMax(unit);
 end
+M.UpdateMaxHealth = updateMaxHealth;
 
 local function updateHealth(frame, unit)
     local current, max = UnitHealth(unit), frame.health.max;
@@ -90,14 +94,16 @@ local function updateHealth(frame, unit)
         -- somehow current health has gone over the maximum (missed maxhealth event possibly)
         -- just put health bar full and update max health for next event
         frame.health:SetWidth(width);
+        frame.health.width = width;
         updateMaxHealth(frame, unit);
         frame.health:Show();
     elseif current <= 0 or UnitIsDeadOrGhost(unit) then
-        frame.dead = true;
         frame.health:Hide();
-        updateText(frame, unit); -- update death
+        return updateText(frame, unit); -- update death
     else
-        frame.health:SetWidth(current/max*width);
+        local w = current/max*width;
+        frame.health:SetWidth(w);
+        frame.health.width = w;
         frame.health:Show();
     end
 
@@ -106,35 +112,41 @@ local function updateHealth(frame, unit)
         updateText(frame, unit); -- update revive
     end
 end
+M.UpdateHealth = updateHealth;
 
--- TODO maybe add a prefix when in vehicle
 local function updateName(frame, unit)
     local name = UnitName(unit);
     if not name then return end
-    frame.name:SetText(ssub(name, 1, 6));
+    name = ssub(name, 1, 6);
+    if frame.unit == unit then
+        frame.name:SetText(name);
+    else
+        frame.name:SetFormattedText("-%s", name);
+    end
 
     local _, class = UnitClass(unit);
     local color = RAID_CLASS_COLORS[class];
     if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
 end
+M.UpdateName = updateName;
 
 local function updateHealPred(frame, unit)
     local incoming = UnitGetIncomingHeals(unit) or 0;
     if incoming > 0 then
-        -- always at least 1 pixel space for heal prediction
-        local space = width - frame.health:GetWidth() + 1;
         incoming = (incoming / frame.health.max) * width;
-        frame.healpred:SetWidth(min(space, incoming));
+        -- always at least 1 pixel space for heal prediction
+        frame.healpred:SetWidth(min(width - frame.health.width + 1, incoming));
         frame.healpred:Show();
     else
         frame.healpred:Hide();
     end
 end
+M.UpdateHealPred = updateHealPred;
 
 local function updateShield(frame, unit)
     local shield = UnitGetTotalAbsorbs(unit) or 0;
     if shield > 0 then
-        local space = width - frame.health:GetWidth();
+        local space = width - frame.health.width;
         shield = (shield / frame.health.max) * width;
         if space == 0 then
             frame.shield:Hide();
@@ -153,26 +165,32 @@ local function updateShield(frame, unit)
         frame.shieldhl:Hide();
     end
 end
+M.UpdateShield = updateShield;
 
 local function updateHealAbsorb(frame, unit)
     local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
     if absorb > 0 then
-        local space = frame.health:GetWidth();
         absorb = (absorb / frame.health.max) * width;
-        frame.healabsorb:SetWidth(min(space, absorb));
+        frame.healabsorb:SetWidth(min(frame.health.width, absorb));
         frame.healabsorb:Show();
     else
         frame.healabsorb:Hide();
     end
 end
+M.UpdateHealAbsorb = updateHealAbsorb;
 
 local function updateAuras(frame, unit)
-    local alert = checkIndicators(frame, unit);
-    if alert then
-        if frame.overlay.color ~= overlayColorAlert then
+    updateIndicatorAuras(frame, unit); -- this is throttled
+    local barColor = updateMajorAuras(frame, unit);
+    if barColor then
+        if barColor == true and frame.overlay.color ~= overlayColorAlert then
             frame.overlay:SetVertexColor(unpack(overlayColorAlert));
             frame.overlay.color = overlayColorAlert;
             frame.overlay:Show();
+        elseif barColor ~= true and frame.overlay.color ~= barColor then
+            frame.overlay:SetVertexColor(unpack(barColor));
+            frame.overlay.color = barColor;
+            frame.overlay:Show();
         end
     elseif UnitDebuff(unit, 1, "RAID") ~= nil then
         -- something dispellable
@@ -195,6 +213,7 @@ local function updateAuras(frame, unit)
         end
     end
 end
+M.UpdateAuras = updateAuras;
 
 local function updateAggro(frame, unit)
     local status = UnitThreatSituation(unit);
@@ -204,6 +223,7 @@ local function updateAggro(frame, unit)
         frame.base:SetVertexColor(unpack(baseColor));
     end
 end
+M.UpdateAggro = updateAggro;
 
 local function updateVehicle(frame)
     local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
@@ -220,6 +240,7 @@ local function updateVehicle(frame)
         registerUnitEvents(frame);
     end
 end
+M.UpdateVehicle = updateVehicle;
 
 local function updateRole(frame, unit)
     local role = UnitGroupRolesAssigned(unit);
@@ -233,6 +254,7 @@ local function updateRole(frame, unit)
         frame.role:Hide();
     end
 end
+M.UpdateRole = updateRole;
 
 local function updateReadyCheck(frame, unit)
     local status = GetReadyCheckStatus(unit);
@@ -249,6 +271,7 @@ local function updateReadyCheck(frame, unit)
         frame.ready:Hide()
     end
 end
+M.UpdateReadyCheck = updateReadyCheck;
 
 local function updateRaidMarker(frame, unit)
     local index = GetRaidTargetIndex(unit);
@@ -259,6 +282,7 @@ local function updateRaidMarker(frame, unit)
         frame.targeticon:Hide();
     end
 end
+M.UpdateRaidMarker = updateRaidMarker;
 
 local eventFuncs = {
     ["UNIT_HEALTH"] = function(frame)
@@ -266,10 +290,6 @@ local eventFuncs = {
         updateShield(frame, frame.displayed);
         updateHealAbsorb(frame, frame.displayed);
         -- no heal prediction update, that doesn't overflow too much
-        -- raid marker update here, if needed
-        -- because marker is removed when unit dies
-        -- without a RAID_TARGET_UPDATE event
-        --updateRaidMarker(frame, frame.unit);
     end,
     ["UNIT_AURA"] = function(frame)
         updateAuras(frame, frame.displayed);
@@ -335,5 +355,5 @@ eventFuncs["PLAYER_ENTERING_WORLD"] = eventFuncs["UPDATE_ALL_BARS"];
 eventFuncs["PLAYER_FOCUS_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
 
 function M.UnitEvent(self, event)
-    eventFuncs[event](self);
+    return eventFuncs[event](self);
 end