52e5175 - Fix power bars, remove overlay color for basic unit frames
[wowui.git] / OmaUF / Events.lua
index cd8bd7f..7b39aeb 100644 (file)
@@ -18,13 +18,13 @@ local UnitGroupRolesAssigned = UnitGroupRolesAssigned;
 local UnitLevel, UnitClassification = UnitLevel, UnitClassification;
 local RAID_CLASS_COLORS = RAID_CLASS_COLORS;
 
+local updateAuraFrames = OmaUFAuras.UpdateAuras;
+
 local Settings = OmaUFSettings;
 local baseColor = Settings.BaseColor;
-local overlayColorDispel = Settings.OverlayColorDispel;
-local overlayColorCharm = Settings.OverlayColorCharm;
-local overlayColorAlert = Settings.OverlayColorAlert;
+local healthColor = Settings.HealthColor;
 local powerColors = Settings.PowerColors;
-local width = 10;
+local width = Settings.Width;
 
 local M = {};
 OmaUFEvents = M;
@@ -39,6 +39,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);
@@ -144,10 +146,6 @@ local function updateName(frame, unit)
     local name = UnitName(unit);
     if not name then return end
     frame.name:SetText(ssub(name, 1, 10));
-
-    local _, class = UnitClass(unit);
-    local color = RAID_CLASS_COLORS[class];
-    if color then frame.name:SetVertexColor(color.r, color.g, color.b) end
 end
 
 local function updateHealPred(frame, unit)
@@ -201,26 +199,7 @@ local function updateHealAbsorb(frame, unit)
 end
 
 local function updateAuras(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 unit == frame.unit 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
+    updateAuraFrames(frame, unit);
 end
 
 local function updateAggro(frame, unit)
@@ -344,6 +323,24 @@ local function updateLeaderIcon(frame, unit)
     end
 end
 
+local function updateHealthColor(frame, unit)
+    if not UnitPlayerControlled(unit) and UnitIsTapDenied(unit) then
+        frame.health:SetVertexColor(0.5, 0.5, 0.5);
+    elseif UnitIsPlayer(unit) then
+        local _, class = UnitClass(unit);
+        local color = RAID_CLASS_COLORS[class];
+        if color then
+            frame.health:SetVertexColor(color.r, color.g, color.b)
+        else
+            frame.health:SetVertexColor(unpack(healthColor))
+        end
+    elseif UnitPlayerControlled(unit) then
+        frame.health:SetVertexColor(0, 1, 0);
+    else
+        frame.health:SetVertexColor(UnitSelectionColor(unit));
+    end
+end
+
 local eventFuncs = {
     ["UNIT_HEALTH"] = function(frame)
         updateHealth(frame, frame.displayed);
@@ -385,9 +382,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);
     end,
     ["UNIT_CONNECTION"] = function(frame)
         updateHealthText(frame, frame.displayed);
@@ -415,6 +416,7 @@ local eventFuncs = {
     end,
     ["UNIT_FACTION"] = function(frame)
         updatePVP(frame, frame.unit);
+        updateHealthColor(frame, frame.unit);
     end,
     ["PARTY_LEADER_CHANGED"] = function(frame)
         updateLeaderIcon(frame, frame.unit);
@@ -439,9 +441,12 @@ local eventFuncs = {
         updateStatus(frame, frame.unit);
         updatePVP(frame, frame.unit);
         updateLeaderIcon(frame, frame.unit);
+        updateHealthColor(frame, frame.unit);
     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"];
@@ -452,7 +457,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