084e0f6 - Tidy up some events
authorAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Thu, 1 Feb 2018 21:47:42 +0000
committerAleksi Blinnikka <aleksi.blinnikka@gmail.com>
Thu, 1 Feb 2018 21:47:42 +0000
OmaRF/DruidIndicators.lua
OmaRF/Events.lua
OmaRF/PaladinIndicators.lua
OmaRF/RaidFrame.lua

index f956791..9871fdc 100644 (file)
@@ -7,7 +7,7 @@ local square = "Interface\\AddOns\\OmaRF\\images\\square";
 local positions = {"TOPLEFT"};
 
 local M = {};
-OmaRFIndicators.Class["Druid"] = M;
+OmaRFIndicators.Class["DRUID"] = M;
 M.Auras = {
     ["Lifebloom"] = "TOPLEFT",
     ["Rejuvenation"] = "TR1",
index aeafc6a..7c31381 100644 (file)
@@ -90,34 +90,28 @@ function M.RegisterUnitEvents(frame)
 end
 local registerUnitEvents = M.RegisterUnitEvents;
 
+local function updateMaxHealth(frame, unit)
+    frame.health.max = UnitHealthMax(unit);
+end
+
 local function updateHealth(frame, unit)
     local current, max = UnitHealth(unit), frame.health.max;
-    frame.health:Show();
-    -- sanity check, occasionally UnitHealthMax gives zero
-    if current > max then
-        -- somehow current health has gone over the maximum (missed maxhealth event)
-        frame.health.max = UnitHealthMax(unit);
-        max = frame.health.max;
-        if current > max then
-            -- error state, still over maximum
-            frame.health:SetWidth(width);
-            return;
-        end
-    elseif max > 0 then
-        frame.health:SetWidth(current/frame.health.max*width);
-    else
+    if current > max or max <= 0 then
+        -- 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);
-        return;
-    end
-
-    if UnitIsDeadOrGhost(unit) then
+        updateMaxHealth(frame, unit);
+        frame.health:Show();
+    elseif UnitIsDeadOrGhost(unit) then
         frame.health:Hide();
+    else
+        frame.health:SetWidth(current/max*width);
+        frame.health:Show();
     end
 end
 
 local function updateText(frame, unit)
-    local current, max = UnitHealth(unit), frame.health.max;
-    local healthLost = max - current;
+    local healthLost = frame.health.max - UnitHealth(unit);
     if UnitIsDeadOrGhost(unit) then
         frame.text:SetText("Dead");
         frame.text:Show();
@@ -147,39 +141,24 @@ local function updateText(frame, unit)
 end
 
 local function updateIncomingRes(frame, unit)
-    if UnitHasIncomingResurrection(unit) then
-        frame.rez:Show();
-    else
-        frame.rez:Hide();
-    end
+    if UnitHasIncomingResurrection(unit) then frame.rez:Show();
+    else frame.rez:Hide(); end
 end
 
-local function updateMaxHealth(frame, unit)
-    frame.health.max = UnitHealthMax(unit);
+local function updateMaxPower(frame, unit)
+    frame.mana.max = UnitPowerMax(unit);
 end
 
 local function updatePower(frame, unit)
     local current, max = UnitPower(unit), frame.mana.max;
-    -- sanity check, occasionally UnitPowerMax gives zero
-    if current > max then
-        frame.mana.max = UnitPowerMax(unit);
-        max = frame.mana.max;
-        if current > max then
-            -- error
-            frame.mana:SetWidth(width);
-            return;
-        end
-    elseif max > 0 then
-        frame.mana:SetWidth(UnitPower(unit)/max*width);
-    else
+    if current > max or max <= 0 then
         frame.mana:SetWidth(width);
+        updateMaxPower(frame, unit);
+    else
+        frame.mana:SetWidth(current/max*width);
     end
 end
 
-local function updateMaxPower(frame, unit)
-    frame.mana.max = UnitPowerMax(unit);
-end
-
 local function updatePowerColor(frame, unit)
     frame.mana:SetVertexColor(unpack(powerColors[UnitPowerType(unit)]));
 end
@@ -197,10 +176,10 @@ end
 local function updateHealPred(frame, unit)
     local incoming = UnitGetIncomingHeals(unit) or 0;
     if incoming > 0 then
-        local max = frame.health.max;
+        -- always at least 1 pixel space for heal prediction
         local space = width - frame.health:GetWidth() + 1;
-        local pred = (incoming / max) * width;
-        frame.healpred:SetWidth(min(space, pred));
+        incoming = (incoming / frame.health.max) * width;
+        frame.healpred:SetWidth(min(space, incoming));
         frame.healpred:Show();
     else
         frame.healpred:Hide();
@@ -212,7 +191,7 @@ local function updateShield(frame, unit)
     if shield > 0 then
         local max = frame.health.max;
         local space = width - frame.health:GetWidth();
-        shield = (shield / max) * width;
+        shield = (shield / frame.health.max) * width;
         if space < shield then
             frame.shield:SetWidth(space);
             frame.shieldhl:Show();
@@ -230,9 +209,8 @@ end
 local function updateHealAbsorb(frame, unit)
     local absorb = UnitGetTotalHealAbsorbs(unit) or 0;
     if absorb > 0 then
-        local max = frame.health.max;
         local space = frame.health:GetWidth();
-        absorb = (absorb / max) * width;
+        absorb = (absorb / frame.health.max) * width;
         frame.healabsorb:SetWidth(min(space, absorb));
         frame.healabsorb:Show();
     else
@@ -245,27 +223,27 @@ local function updateAuras(frame, unit)
     if alert then
         if frame.overlay.color ~= overlayColorAlert then
             frame.overlay:SetVertexColor(unpack(overlayColorAlert));
-            frame.overlay:Show();
             frame.overlay.color = overlayColorAlert;
+            frame.overlay:Show();
         end
     elseif UnitDebuff(unit, 1, "RAID") ~= nil then
         -- something dispellable
         if frame.overlay.color ~= overlayColorDispel then
             frame.overlay:SetVertexColor(unpack(overlayColorDispel));
-            frame.overlay:Show();
             frame.overlay.color = overlayColorDispel;
+            frame.overlay:Show();
         end
     -- don't overlay charmed when in vehicle
     elseif UnitIsCharmed(unit) and unit == frame.unit then
         if frame.overlay.color ~= overlayColorCharm then
             frame.overlay:SetVertexColor(unpack(overlayColorCharm));
-            frame.overlay:Show();
             frame.overlay.color = overlayColorCharm;
+            frame.overlay:Show();
         end
     else
         if frame.overlay.color ~= nil then
-            frame.overlay:Hide();
             frame.overlay.color = nil;
+            frame.overlay:Hide();
         end
     end
 end
@@ -280,7 +258,8 @@ local function updateAggro(frame, unit)
 end
 
 local function updateVehicle(frame)
-    local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
+    local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and
+        UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
     if shouldTargetVehicle then
         if not frame.inVehicle then
             frame.inVehicle = true;
index becda9b..fdb5950 100644 (file)
@@ -6,7 +6,7 @@ local rhomb = "Interface\\AddOns\\OmaRF\\images\\rhomb";
 local positions = {"TOPRIGHT", "BOTTOMLEFT"};
 
 local M = {};
-OmaRFIndicators.Class["Paladin"] = M;
+OmaRFIndicators.Class["PALADIN"] = M;
 M.Auras = {
     [53563] = "TOPRIGHT", -- Beacon of Light
     [156910] = "TOPRIGHT", -- Beacon of Faith
index 955c816..6e2c6c9 100644 (file)
@@ -129,7 +129,7 @@ local function setupFrame(frame, secure, unit)
     frame.overlay = frame:CreateTexture(nil, "ARTWORK", nil, 1);
     frame.overlay:SetPoint("TOPLEFT", frame.background, "TOPLEFT");
     frame.overlay:SetPoint("BOTTOMRIGHT", frame.background, "BOTTOMRIGHT");
-    frame.overlay:SetColorTexture(1, 1, 1);
+    frame.overlay:SetTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill");
     frame.overlay:Hide();
     frame.name = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight");
     frame.name:SetPoint("CENTER", frame.background, "CENTER", 0, 11);
@@ -273,8 +273,8 @@ local function initialize()
     -- let other addons hook these to anchor tooltip elsewhere
     GameTooltip = _G["GameTooltip"];
     GameTooltip_SetDefaultAnchor = _G["GameTooltip_SetDefaultAnchor"];
+    _, class = UnitClass("player");
     loadCharSettings();
-    class = UnitClass("player");
     CFrame:SetPoint("CENTER", nil, "CENTER", anchorX, anchorY);
     CFrame:SetHeight((height+2)*8);
     CFrame:SetWidth((width+2)*5);