d76a52e - Change width/height to global setting
[wowui.git] / OmaUF / Events.lua
index 6e4fa69..f745434 100644 (file)
@@ -1,11 +1,12 @@
 -- Events.lua
+-- TODO -- recheck these, pvp functions not added yet
 local _;
 local unpack = unpack;
 local ssub = string.sub;
 local min = math.min;
 local ceil = math.ceil;
 local UnitName, UnitClass, UnitExists = UnitName, UnitClass, UnitExists;
-local UnitDebuff, UnitIsCharmed = UnitDebuff, UnitIsCharmed;
+local UnitDebuff, UnitIsCharmed, UnitIsFriend = UnitDebuff, UnitIsCharmed, UnitIsFriend;
 local UnitPower, UnitPowerMax, UnitPowerType = UnitPower, UnitPowerMax, UnitPowerType;
 local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax;
 local UnitGetIncomingHeals, UnitGetTotalAbsorbs = UnitGetIncomingHeals, UnitGetTotalAbsorbs;
@@ -17,13 +18,16 @@ 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 healthColor = Settings.HealthColor;
 local overlayColorDispel = Settings.OverlayColorDispel;
 local overlayColorCharm = Settings.OverlayColorCharm;
 local overlayColorAlert = Settings.OverlayColorAlert;
 local powerColors = Settings.PowerColors;
-local width = 10;
+local width = Settings.Width;
 
 local M = {};
 OmaUFEvents = M;
@@ -143,10 +147,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)
@@ -200,7 +200,8 @@ local function updateHealAbsorb(frame, unit)
 end
 
 local function updateAuras(frame, unit)
-    if UnitDebuff(unit, 1, "RAID") ~= nil then
+    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));
@@ -208,7 +209,7 @@ local function updateAuras(frame, unit)
             frame.overlay.color = overlayColorDispel;
         end
     -- don't overlay charmed when in vehicle
-    elseif UnitIsCharmed(unit) and unit == frame.unit then
+    elseif UnitIsCharmed(unit) and not frame.inVehicle then
         if frame.overlay.color ~= overlayColorCharm then
             frame.overlay:SetVertexColor(unpack(overlayColorCharm));
             frame.overlay:Show();
@@ -249,7 +250,7 @@ end
 local function updateRole(frame, unit)
     local role = UnitGroupRolesAssigned(unit);
     if role == "HEALER" or role == "TANK" or role == "DAMAGER" then
-        frame.role:SetTexCoord(GetTexCoordsForRole(role));
+        frame.role:SetTexCoord(GetTexCoordsForRoleSmallCircle(role));
         frame.role:Show();
     else
         frame.role:Hide();
@@ -324,6 +325,43 @@ local function updatePVP(frame, unit)
     end
 end
 
+local function updateLeaderIcon(frame, unit)
+    if UnitIsGroupLeader(frame.unit) then
+        if HasLFGRestrictions() then
+            frame.leader:SetTexture("Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES");
+            frame.leader:SetTexCoord(0, 0.296875, 0.015625, 0.3125);
+        else
+            frame.leader:SetTexture("Interface\\GROUPFRAME\\UI-Group-LeaderIcon");
+            frame.leader:SetTexCoord(0, 1, 0, 1);
+        end
+        frame.leader:Show();
+    elseif UnitIsGroupAssistant(frame.unit) then
+        frame.leader:SetTexture("Interface\\GROUPFRAME\\UI-Group-AssistantIcon");
+        frame.leader:SetTexCoord(0, 1, 0, 1);
+        frame.leader:Show();
+    else
+        frame.leader:Hide();
+    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);
@@ -368,6 +406,7 @@ local eventFuncs = {
     end,
     ["UNIT_NAME_UPDATE"] = function(frame)
         updateName(frame, frame.displayed);
+        updateHealthColor(frame, frame.unit);
     end,
     ["UNIT_CONNECTION"] = function(frame)
         updateHealthText(frame, frame.displayed);
@@ -395,6 +434,10 @@ 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);
     end,
     ["UPDATE_ALL_BARS"] = function(frame)
         updateVehicle(frame);
@@ -415,6 +458,8 @@ local eventFuncs = {
         updateLevelText(frame, frame.unit);
         updateStatus(frame, frame.unit);
         updatePVP(frame, frame.unit);
+        updateLeaderIcon(frame, frame.unit);
+        updateHealthColor(frame, frame.unit);
     end,
 };
 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
@@ -428,7 +473,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