7b95a32 - Add role icon
[wowui.git] / OmaRF / CFrame.lua
index 753b90a..64db699 100644 (file)
@@ -3,7 +3,7 @@ local _;
 local unpack, pairs, ipairs = unpack, pairs, ipairs;
 local ssub = string.sub;
 local min = math.min;
-local UnitName, UnitClass = UnitName, UnitClass;
+local UnitName, UnitClass, UnitExists = UnitName, UnitClass, UnitExists;
 local UnitDebuff, UnitIsCharmed = UnitDebuff, UnitIsCharmed;
 local UnitPower, UnitPowerMax, UnitPowerType = UnitPower, UnitPowerMax, UnitPowerType;
 local UnitHealth, UnitHealthMax = UnitHealth, UnitHealthMax;
@@ -14,10 +14,13 @@ local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
 local UnitHasIncomingResurrection = UnitHasIncomingResurrection;
 local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs;
 local IsInGroup, IsInRaid = IsInGroup, IsInRaid;
+local UnitHasVehicleUI, UnitTargetsVehicleInRaidUI = UnitHasVehicleUI, UnitTargetsVehicleInRaidUI;
+local UnitGroupRolesAssigned = UnitGroupRolesAssigned;
 local CTimerAfter = C_Timer.After;
 local RAID_CLASS_COLORS = RAID_CLASS_COLORS;
 
 local Frames = OmaFrames;
+local registerEvents = OmaFrames.RegisterEvents;
 local Indicators = OmaIndicators;
 local checkIndicators = Indicators.CheckIndicators;
 
@@ -36,7 +39,6 @@ local powerColors = Frames.PowerColors;
 
 local function updateHealth(frame, unit)
     local current, max = UnitHealth(unit), frame.health.max;
-    local healthLost = max - current;
     frame.health:Show();
     -- sanity check, occasionally UnitHealthMax gives zero
     if current > max then
@@ -46,26 +48,30 @@ local function updateHealth(frame, unit)
         if current > max then
             -- error state, still over maximum
             frame.health:SetWidth(width);
-            frame.text:Hide();
             return;
         end
     elseif max > 0 then
         frame.health:SetWidth(current/frame.health.max*width);
     else
         frame.health:SetWidth(width);
-        frame.text:Hide();
         return;
     end
 
     if UnitIsDeadOrGhost(unit) then
         frame.health:Hide();
+    end
+end
+
+local function updateText(frame, unit)
+    local current, max = UnitHealth(unit), frame.health.max;
+    local healthLost = max - current;
+    if UnitIsDeadOrGhost(unit) then
         if UnitHasIncomingResurrection(unit) then
             frame.text:SetText("Rez");
         else
             frame.text:SetText("Dead");
         end
     elseif not UnitIsConnected(unit) then
-        frame.health:Hide();
         frame.text:SetText("DC");
     elseif healthLost > 0 then
         if healthLost > 1200000000 then -- 1.2B
@@ -85,7 +91,6 @@ end
 
 local function updateMaxHealth(frame, unit)
     frame.health.max = UnitHealthMax(unit);
-    updateHealth(frame, unit);
 end
 
 local function updatePower(frame, unit)
@@ -108,7 +113,6 @@ end
 
 local function updateMaxPower(frame, unit)
     frame.mana.max = UnitPowerMax(unit);
-    updatePower(frame, unit);
 end
 
 local function updatePowerColor(frame, unit)
@@ -180,7 +184,8 @@ local function updateAuras(frame, unit)
             frame.overlay:Show();
             frame.overlay.color = overlayColorDispel;
         end
-    elseif UnitIsCharmed(unit) then
+    -- 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();
@@ -203,74 +208,119 @@ local function updateAggro(frame, unit)
     end
 end
 
+local function updateVehicle(frame)
+    local shouldTargetVehicle = UnitHasVehicleUI(frame.unit) and UnitTargetsVehicleInRaidUI(frame.unit) and UnitExists(frame.vehicle);
+    if shouldTargetVehicle then
+        if not frame.inVehicle then
+            frame.inVehicle = true;
+            frame.displayed = frame.vehicle;
+            registerEvents(frame);
+        end
+    elseif frame.inVehicle then
+        frame.inVehicle = false;
+        frame.displayed = frame.unit;
+        registerEvents(frame);
+    end
+end
+
+local function updateRole(frame, unit)
+    local role = UnitGroupRolesAssigned(unit);
+    if role == "HEALER" then
+        frame.role:SetTexCoord(0.75, 1, 0, 1);
+        frame.role:Show();
+    elseif role == "TANK" then
+        frame.role:SetTexCoord(0.5, 0.75, 0, 1);
+        frame.role:Show();
+    else
+        frame.role:Hide();
+    end
+end
+
 local eventFuncs = {
-    ["UNIT_HEALTH"] = function(frame, unit)
-        updateHealth(frame, unit);
-        updateShield(frame, unit);
-        updateHealAbsorb(frame, unit);
+    ["UNIT_HEALTH"] = function(frame)
+        updateHealth(frame, frame.displayed);
+        updateText(frame, frame.displayed);
+        updateShield(frame, frame.displayed);
+        updateHealAbsorb(frame, frame.displayed);
         -- no heal prediction update, that doesn't overflow too much
     end,
-    ["UNIT_POWER"] = function(frame, unit)
-        updatePower(frame, unit);
+    ["UNIT_POWER"] = function(frame)
+        updatePower(frame, frame.displayed);
     end,
-    ["UNIT_AURA"] = function(frame, unit)
-        updateAuras(frame, unit);
+    ["UNIT_AURA"] = function(frame)
+        updateAuras(frame, frame.displayed);
     end,
-    ["UNIT_HEAL_PREDICTION"] = function(frame, unit)
-        updateHealPred(frame, unit);
+    ["UNIT_HEAL_PREDICTION"] = function(frame)
+        updateHealPred(frame, frame.displayed);
     end,
-    ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame, unit)
-        updateShield(frame, unit);
+    ["UNIT_ABSORB_AMOUNT_CHANGED"] = function(frame)
+        updateShield(frame, frame.displayed);
     end,
-    ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame, unit)
-        updateHealAbsorb(frame, unit);
+    ["UNIT_HEAL_ABSORB_AMOUNT_CHANGED"] = function(frame)
+        updateHealAbsorb(frame, frame.displayed);
     end,
-    ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame, unit)
-        updateAggro(frame, unit);
+    ["UNIT_THREAT_SITUATION_UPDATE"] = function(frame)
+        updateAggro(frame, frame.displayed);
     end,
-    ["UNIT_MAXHEALTH"] = function(frame, unit)
-        updateMaxHealth(frame, unit);
+    ["UNIT_MAXHEALTH"] = function(frame)
+        updateMaxHealth(frame, frame.displayed);
+        updateHealth(frame, frame.displayed);
+        updateText(frame, frame.displayed);
+        updateShield(frame, frame.displayed);
+        updateHealAbsorb(frame, frame.displayed);
     end,
-    ["UNIT_MAXPOWER"] = function(frame, unit)
-        updateMaxPower(frame, unit);
+    ["UNIT_MAXPOWER"] = function(frame)
+        updateMaxPower(frame, frame.displayed);
+        updatePower(frame, frame.displayed);
     end,
-    ["UNIT_DISPLAYPOWER"] = function(frame, unit)
-        updatePowerColor(frame, unit);
+    ["UNIT_DISPLAYPOWER"] = function(frame)
+        updatePowerColor(frame, frame.displayed);
     end,
-    ["UNIT_NAME_UPDATE"] = function(frame, unit)
-        updateName(frame, unit);
+    ["UNIT_NAME_UPDATE"] = function(frame)
+        updateName(frame, frame.displayed);
     end,
-    ["UNIT_CONNECTION"] = function(frame, unit)
-        updateHealth(frame, unit);
+    ["UNIT_CONNECTION"] = function(frame)
+        updateText(frame, frame.displayed);
     end,
-    ["INCOMING_RESURRECT_CHANGED"] = function(frame, unit)
+    ["INCOMING_RESURRECT_CHANGED"] = function(frame)
         -- TODO have an icon
-        updateHealth(frame, unit);
+        updateText(frame, frame.displayed);
     end,
     ["PARTY_MEMBER_ENABLE"] = function(frame)
         -- new power info possibly (FrameXML/CompactUnitFrame.lua)
-        updateMaxPower(frame, frame.unit);
-        updatePowerColor(frame, frame.unit);
+        updateMaxPower(frame, frame.displayed);
+        updatePowerColor(frame, frame.displayed);
+    end,
+    ["PLAYER_ROLES_ASSIGNED"] = function(frame)
+        updateRole(frame, frame.unit);
     end,
-    ["UPDATE_ALL_BARS"] = function(frame, unit)
-        updateMaxHealth(frame, unit);
-        updateMaxPower(frame, unit);
-        --updateHealth(frame, unit); -- MaxHealth covers this
-        --updatePower(frame, unit); -- MaxPower covers this
-        updateAuras(frame, unit);
-        updateShield(frame, unit);
-        updateHealPred(frame, unit);
-        updateHealAbsorb(frame, unit);
-        updatePowerColor(frame, unit);
-        updateAggro(frame, unit);
-        updateName(frame, unit);
+    ["UPDATE_ALL_BARS"] = function(frame)
+        updateVehicle(frame);
+        updateMaxHealth(frame, frame.displayed);
+        updateMaxPower(frame, frame.displayed);
+        updateHealth(frame, frame.displayed);
+        updateText(frame, frame.displayed);
+        updatePower(frame, frame.displayed);
+        updateAuras(frame, frame.displayed);
+        updateShield(frame, frame.displayed);
+        updateHealPred(frame, frame.displayed);
+        updateHealAbsorb(frame, frame.displayed);
+        updatePowerColor(frame, frame.displayed);
+        updateAggro(frame, frame.displayed);
+        updateName(frame, frame.displayed);
+        updateRole(frame, frame.unit);
     end,
 };
 eventFuncs["UNIT_HEALTH_FREQUENT"] = eventFuncs["UNIT_HEALTH"];
 eventFuncs["PARTY_MEMBER_DISABLE"] = eventFuncs["PARTY_MEMBER_ENABLE"];
-local function unitEvent(self, event, ...)
-    local arg1, arg2, arg3, arg4 = ...;
-    eventFuncs[event](self, arg1);
+eventFuncs["UNIT_ENTERED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
+eventFuncs["UNIT_EXITED_VEHICLE"] = eventFuncs["UPDATE_ALL_BARS"];
+eventFuncs["UNIT_PET"] = eventFuncs["UPDATE_ALL_BARS"];
+eventFuncs["GROUP_ROSTER_UPDATE"] = eventFuncs["UPDATE_ALL_BARS"];
+--local function unitEvent(self, event, ...)
+local function unitEvent(self, event)
+    --local arg1, arg2, arg3, arg4 = ...;
+    eventFuncs[event](self);
 end
 
 local function initialize()