ee0624a - Fix name, health and mana texts in some cases
authorAleksi Blinnikka <aleksi.blinnikka@iki.fi>
Sun, 17 May 2020 20:49:55 +0000
committerAleksi Blinnikka <aleksi.blinnikka@iki.fi>
Sun, 17 May 2020 20:49:55 +0000
kehys/events.lua
kehys/updater.lua

index 6b82322..170c029 100644 (file)
@@ -56,6 +56,7 @@ function addon.RegisterUnitEvents(frame)
     end
     if frame.raid or frame.unit ~= "player" then
         frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
+        frame:RegisterUnitEvent("UNIT_FACTION", frame.unit, displayed);
     end
     if frame.raid then
         frame:RegisterUnitEvent("UNIT_THREAT_SITUATION_UPDATE", frame.unit, displayed);
@@ -78,12 +79,14 @@ local function updateName(frame, unit)
     local color = RAID_CLASS_COLORS[class];
     if color then
         if not frame.raid then
-            if UnitIsEnemy("player", unit) then
-                frame.health:SetVertexColor(1, 0, 0);
+            if not UnitPlayerControlled(unit) and UnitIsTapDenied(unit) then
+                frame.health:SetVertexColor(0.5, 0.5, 0.5);
             elseif UnitIsPlayer(unit) then
                 frame.health:SetVertexColor(color.r, color.g, color.b);
-            else
+            elseif UnitPlayerControlled(unit) then
                 frame.health:SetVertexColor(0, 1, 0);
+            else
+                frame.health:SetVertexColor(UnitSelectionColor(unit));
             end
         else
             frame.name:SetVertexColor(color.r, color.g, color.b);
@@ -177,6 +180,9 @@ local eventFuncs = {
             end
         end
     end,
+    ["UNIT_FACTION"] = function(frame)
+        updateName(frame, frame.unit);
+    end,
     ["PLAYER_ROLES_ASSIGNED"] = function(frame)
         updateRole(frame, frame.unit);
     end,
index 8e1fcc6..d7d3cb5 100644 (file)
@@ -75,10 +75,12 @@ function addon.FrameUpdate(frame)
     else
         if UnitIsAFK(unit) then
             frame.text.status = true;
+            frame.prev.htext = nil;
             frame.text:SetText("afk");
             if not frame.text:IsShown() then frame.text:Show() end
         elseif UnitIsDND(unit) then
             frame.text.status = true;
+            frame.prev.htext = nil;
             frame.text:SetText("dnd");
             if not frame.text:IsShown() then frame.text:Show() end
         else
@@ -101,29 +103,6 @@ function addon.FrameUpdate(frame)
         -- health
         local current, hmax = UnitHealth(unit), UnitHealthMax(unit);
         if frame.prev.health ~= current or frame.prev.hmax ~= hmax then
-            if not frame.raid and not frame.text.status and frame.prev.htext ~= current then
-                frame.prev.htext = current;
-                if frame.boss then
-                    if hmax < current or hmax <= 1 then
-                        frame.text:SetText("100");
-                        if not frame.text:IsShown() then frame.text:Show() end
-                    elseif current <= 0 then
-                        if frame.text:IsShown() then frame.text:Hide() end
-                    else
-                        frame.text:SetFormattedText("%.1f", current/hmax*100);
-                        if not frame.text:IsShown() then frame.text:Show() end
-                    end
-                else
-                    if current > 1000000000 then -- 1.0B
-                        frame.text:SetFormattedText("%.2fB", current / 1000000000);
-                    elseif current > 1000000 then -- 1.0M
-                        frame.text:SetFormattedText("%.2fM", current / 1000000);
-                    elseif current > 1000 then -- 1.0K
-                        frame.text:SetFormattedText("%.1fK", current / 1000);
-                    end
-                    if not frame.text:IsShown() then frame.text:Show() end
-                end
-            end
             frame.prev.health = current;
             frame.prev.hmax = hmax;
             if hmax < current or hmax <= 1 then
@@ -139,6 +118,30 @@ function addon.FrameUpdate(frame)
                 if not frame.health:IsShown() then frame.health:Show() end
             end
         end
+        -- health text
+        if not frame.raid and not frame.text.status and frame.prev.htext ~= current then
+            frame.prev.htext = current;
+            if frame.boss then
+                if hmax < current or hmax <= 1 then
+                    frame.text:SetText("100");
+                    if not frame.text:IsShown() then frame.text:Show() end
+                elseif current <= 0 then
+                    if frame.text:IsShown() then frame.text:Hide() end
+                else
+                    frame.text:SetFormattedText("%.1f", current/hmax*100);
+                    if not frame.text:IsShown() then frame.text:Show() end
+                end
+            else
+                if current > 1000000000 then -- 1.0B
+                    frame.text:SetFormattedText("%.2fB", current / 1000000000);
+                elseif current > 1000000 then -- 1.0M
+                    frame.text:SetFormattedText("%.2fM", current / 1000000);
+                elseif current > 1000 then -- 1.0K
+                    frame.text:SetFormattedText("%.1fK", current / 1000);
+                end
+                if not frame.text:IsShown() then frame.text:Show() end
+            end
+        end
         -- shield
         local hwidth = frame.health.width;
         current = UnitGetTotalAbsorbs(unit) or 0;
@@ -191,7 +194,10 @@ function addon.FrameUpdate(frame)
             if frame.prev.mana ~= current or frame.prev.mmax ~= max then
                 frame.prev.mana = current;
                 frame.prev.mmax = max;
-                if max < current or max <= 1 then
+                if max < 1 then
+                    if frame.mana:IsShown() then frame.mana:Hide() end
+                    if frame.manatext:IsShown() then frame.manatext:Hide() end
+                elseif max < current then
                     frame.mana:SetWidth(width);
                     frame.manatext:SetText("100");
                     if not frame.mana:IsShown() then frame.mana:Show() end