d9dbaac - Fix overlay back and hide power bar properly
[wowui.git] / OmaUF / Events.lua
index d68affe..cbc8b0a 100644 (file)
@@ -23,11 +23,7 @@ local updateAuraFrames = OmaUFAuras.UpdateAuras;
 local Settings = OmaUFSettings;
 local baseColor = Settings.BaseColor;
 local healthColor = Settings.HealthColor;
-local overlayColorDispel = Settings.OverlayColorDispel;
-local overlayColorCharm = Settings.OverlayColorCharm;
-local overlayColorAlert = Settings.OverlayColorAlert;
 local powerColors = Settings.PowerColors;
-local width = 10;
 
 local M = {};
 OmaUFEvents = M;
@@ -42,6 +38,8 @@ function M.RegisterEvents(frame)
     frame:RegisterUnitEvent("UNIT_POWER", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_MAXPOWER", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", frame.unit, displayed);
+    frame:RegisterUnitEvent("UNIT_POWER_BAR_SHOW", frame.unit, displayed);
+    frame:RegisterUnitEvent("UNIT_POWER_BAR_HIDE", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_NAME_UPDATE", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_AURA", frame.unit, displayed);
     frame:RegisterUnitEvent("UNIT_HEAL_PREDICTION", frame.unit, displayed);
@@ -63,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
 
@@ -86,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();
@@ -110,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
@@ -144,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));
@@ -153,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
@@ -166,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();
@@ -191,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
@@ -201,26 +208,6 @@ end
 
 local function updateAuras(frame, unit)
     updateAuraFrames(frame, unit);
-    if UnitIsFriend("player", unit) and 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;
-        end
-    -- don't overlay charmed when in vehicle
-    elseif UnitIsCharmed(unit) and not frame.inVehicle then
-        if frame.overlay.color ~= overlayColorCharm then
-            frame.overlay:SetVertexColor(unpack(overlayColorCharm));
-            frame.overlay:Show();
-            frame.overlay.color = overlayColorCharm;
-        end
-    else
-        if frame.overlay.color ~= nil then
-            frame.overlay:Hide();
-            frame.overlay.color = nil;
-        end
-    end
 end
 
 local function updateAggro(frame, unit)
@@ -258,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);
@@ -403,10 +391,13 @@ local eventFuncs = {
     end,
     ["UNIT_DISPLAYPOWER"] = function(frame)
         updatePowerColor(frame, frame.displayed);
+        updateMaxPower(frame, frame.displayed);
+        updatePower(frame, frame.displayed);
+        updatePowerText(frame, frame.displayed);
     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);
@@ -434,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);
@@ -459,10 +450,12 @@ 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"];
+eventFuncs["UNIT_POWER_BAR_SHOW"] = eventFuncs["UNIT_DISPLAYPOWER"];
+eventFuncs["UNIT_POWER_BAR_HIDE"] = eventFuncs["UNIT_DISPLAYPOWER"];
 eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
 eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
 eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
@@ -473,7 +466,3 @@ eventFuncs["PLAYER_TARGET_CHANGED"] = eventFuncs["UPDATE_ALL_BARS"];
 function M.UnitEvent(self, event, arg1)
     eventFuncs[event](self, arg1);
 end
-
-function M.LoadChar()
-    width = Settings.Character.Width;
-end