X-Git-Url: https://www.aleksib.fi/git/wowui.git/blobdiff_plain/d9a8d3fef13473aa64470d876c63d0a1a464199f..92fe6f25185f79a8c40a382d1e420fbea08f12f5:/OmaRF/CFrame.lua?ds=inline diff --git a/OmaRF/CFrame.lua b/OmaRF/CFrame.lua index 753b90a..ff674d3 100644 --- a/OmaRF/CFrame.lua +++ b/OmaRF/CFrame.lua @@ -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,12 @@ local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected; local UnitHasIncomingResurrection = UnitHasIncomingResurrection; local UnitGetTotalHealAbsorbs = UnitGetTotalHealAbsorbs; local IsInGroup, IsInRaid = IsInGroup, IsInRaid; +local UnitHasVehicleUI, UnitTargetsVehicleInRaidUI = UnitHasVehicleUI, UnitTargetsVehicleInRaidUI; 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; @@ -85,7 +87,6 @@ end local function updateMaxHealth(frame, unit) frame.health.max = UnitHealthMax(unit); - updateHealth(frame, unit); end local function updatePower(frame, unit) @@ -108,7 +109,6 @@ end local function updateMaxPower(frame, unit) frame.mana.max = UnitPowerMax(unit); - updatePower(frame, unit); end local function updatePowerColor(frame, unit) @@ -180,7 +180,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 +204,98 @@ 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 eventFuncs = { - ["UNIT_HEALTH"] = function(frame, unit) - updateHealth(frame, unit); - updateShield(frame, unit); - updateHealAbsorb(frame, unit); + ["UNIT_HEALTH"] = function(frame) + updateHealth(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); + 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) + updateHealth(frame, frame.displayed); end, - ["INCOMING_RESURRECT_CHANGED"] = function(frame, unit) + ["INCOMING_RESURRECT_CHANGED"] = function(frame) -- TODO have an icon - updateHealth(frame, unit); + updateHealth(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, - ["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); + 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); 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"]; +--local function unitEvent(self, event, ...) +local function unitEvent(self, event) + --local arg1, arg2, arg3, arg4 = ...; + eventFuncs[event](self); end local function initialize()