0c3ccc0 - Small fixes from normal unit frame side
[wowui.git] / OmaUF / Events.lua
index 7b39aeb..cbc8b0a 100644 (file)
@@ -24,7 +24,6 @@ local Settings = OmaUFSettings;
 local baseColor = Settings.BaseColor;
 local healthColor = Settings.HealthColor;
 local powerColors = Settings.PowerColors;
-local width = Settings.Width;
 
 local M = {};
 OmaUFEvents = M;
@@ -62,13 +61,13 @@ local function updateHealth(frame, unit)
         max = frame.health.max;
         if current > max then
             -- error state, still over maximum
-            frame.health:SetWidth(width);
+            frame.health:SetWidth(frame.width);
             return;
         end
     elseif max > 0 then
-        frame.health:SetWidth(current/frame.health.max*width);
+        frame.health:SetWidth(current/frame.health.max*frame.width);
     else
-        frame.health:SetWidth(width);
+        frame.health:SetWidth(frame.width);
         return;
     end
 
@@ -85,8 +84,16 @@ local function updateHealthText(frame, unit)
     elseif not UnitIsConnected(unit) then
         frame.healthText:SetText("DC");
         frame.healthText:Show();
-    elseif max > 0 and current < max then
-        frame.healthText:SetText(ceil(current/max*100));
+    elseif max > 0 then
+        if current > 1200000000 then -- 1.2B
+            frame.healthText:SetFormattedText("%.1fB", current / 1000000000);
+        elseif current > 1200000 then -- 1.2M
+            frame.healthText:SetFormattedText("%.1fM", current / 1000000);
+        elseif current > 1000 then -- 1K
+            frame.healthText:SetFormattedText("%.1fK", current / 1000);
+        else
+            frame.healthText:SetFormattedText("%d", current)
+        end
         frame.healthText:Show();
     else
         frame.healthText:Hide();
@@ -109,15 +116,15 @@ local function updatePower(frame, unit)
         max = frame.mana.max;
         if current > max then
             -- error
-            frame.mana:SetWidth(width);
+            frame.mana:SetWidth(frame.width);
             return;
         end
     end
     if max > 0 then
-        frame.mana:SetWidth(UnitPower(unit)/max*width);
+        frame.mana:SetWidth(UnitPower(unit)/max*frame.width);
         frame.mana:Show();
     else
-        frame.mana:SetWidth(width);
+        frame.mana:SetWidth(frame.width);
         frame.mana:Show();
     end
 end
@@ -143,6 +150,7 @@ local function updatePowerColor(frame, unit)
 end
 
 local function updateName(frame, unit)
+    if not frame.name then return end
     local name = UnitName(unit);
     if not name then return end
     frame.name:SetText(ssub(name, 1, 10));
@@ -152,8 +160,8 @@ local function updateHealPred(frame, unit)
     local incoming = UnitGetIncomingHeals(unit) or 0;
     if incoming > 0 then
         local max = frame.health.max;
-        local space = width - frame.health:GetWidth() + 1;
-        local pred = (incoming / max) * width;
+        local space = frame.width - frame.health:GetWidth() + 1;
+        local pred = (incoming / max) * frame.width;
         frame.healpred:SetWidth(min(space, pred));
         frame.healpred:Show();
     else
@@ -165,8 +173,8 @@ local function updateShield(frame, unit)
     local shield = UnitGetTotalAbsorbs(unit) or 0;
     if shield > 0 then
         local max = frame.health.max;
-        local space = width - frame.health:GetWidth();
-        shield = (shield / max) * width;
+        local space = frame.width - frame.health:GetWidth();
+        shield = (shield / max) * frame.width;
         if space == 0 then
             frame.shield:Hide();
             frame.shieldhl:Show();
@@ -190,7 +198,7 @@ local function updateHealAbsorb(frame, unit)
     if absorb > 0 then
         local max = frame.health.max;
         local space = frame.health:GetWidth();
-        absorb = (absorb / max) * width;
+        absorb = (absorb / max) * frame.width;
         frame.healabsorb:SetWidth(min(space, absorb));
         frame.healabsorb:Show();
     else
@@ -237,6 +245,7 @@ local function updateRole(frame, unit)
 end
 
 local function updateLevelText(frame, unit, levelup)
+    if not frame.level then return end
     if levelup then
         -- PLAYER_LEVEL_UP
         frame.level:SetText(levelup);
@@ -388,7 +397,7 @@ local eventFuncs = {
     end,
     ["UNIT_NAME_UPDATE"] = function(frame)
         updateName(frame, frame.displayed);
-        updateHealthColor(frame, frame.unit);
+        updateHealthColor(frame, frame.displayed);
     end,
     ["UNIT_CONNECTION"] = function(frame)
         updateHealthText(frame, frame.displayed);
@@ -416,7 +425,7 @@ local eventFuncs = {
     end,
     ["UNIT_FACTION"] = function(frame)
         updatePVP(frame, frame.unit);
-        updateHealthColor(frame, frame.unit);
+        updateHealthColor(frame, frame.displayed);
     end,
     ["PARTY_LEADER_CHANGED"] = function(frame)
         updateLeaderIcon(frame, frame.unit);
@@ -441,7 +450,7 @@ local eventFuncs = {
         updateStatus(frame, frame.unit);
         updatePVP(frame, frame.unit);
         updateLeaderIcon(frame, frame.unit);
-        updateHealthColor(frame, frame.unit);
+        updateHealthColor(frame, frame.displayed);
     end,
 };
 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];