From 0e96183e4c508a4c215c945d10f6f9ccd9dd88c4 Mon Sep 17 00:00:00 2001 From: andrew6180 <16847730+andrew6180@users.noreply.github.com> Date: Sat, 27 May 2023 20:12:22 -0700 Subject: [PATCH] Modules/NamePlates: fix issues with threat coloring / other non target elements --- ElvUI/Libraries/oUF/elements/health.lua | 42 +++++++++++----- ElvUI/Libraries/oUF/elements/powerrage.lua | 50 +++++++++++++------ ElvUI/Libraries/oUF/elements/pvpindicator.lua | 23 ++++++--- .../oUF/elements/threatindicator.lua | 24 ++++++--- ElvUI/Modules/Nameplates/Nameplates.lua | 1 + 5 files changed, 96 insertions(+), 44 deletions(-) diff --git a/ElvUI/Libraries/oUF/elements/health.lua b/ElvUI/Libraries/oUF/elements/health.lua index e9b0c71..91522f4 100644 --- a/ElvUI/Libraries/oUF/elements/health.lua +++ b/ElvUI/Libraries/oUF/elements/health.lua @@ -86,12 +86,6 @@ local oUF = ns.oUF local Private = oUF.Private local function UpdateColor(self, event, unit) - if unit and self.isNamePlate and unit:sub(1, 9) ~= "nameplate" then - local isUnit = self.unit and UnitIsUnit(self.unit, unit) - if isUnit then - unit = self.unit - end - end if(not unit or self.unit ~= unit) then return end local element = self.Health @@ -148,16 +142,28 @@ local function ColorPath(self, ...) * event - the event triggering the update (string) * unit - the unit accompanying the event (string) --]] - (self.Health.UpdateColor or UpdateColor) (self, ...) + local _, unit = ... + local args + if unit and self.isNamePlate then + if (event == "UNIT_THREAT_SITUATION_UPDATE" or event == "UNIT_FLAGS") and unit == "player" then + args = { ... } + args[2] = self.unit + elseif unit:sub(1, 9) ~= "nameplate" then + local isUnit = self.unit and UnitIsUnit(self.unit, unit) + if isUnit then + args = { ... } + args[2] = self.unit + end + end + end + if args then + (self.Health.UpdateColor or UpdateColor) (self, unpack(args)) + else + (self.Health.UpdateColor or UpdateColor) (self, ...) + end end local function Update(self, event, unit) - if unit and self.isNamePlate and unit:sub(1, 9) ~= "nameplate" then - local isUnit = self.unit and UnitIsUnit(self.unit, unit) - if isUnit then - unit = self.unit - end - end if(not unit or self.unit ~= unit) then return end local element = self.Health @@ -212,6 +218,13 @@ local function Path(self, ...) * event - the event triggering the update (string) * unit - the unit accompanying the event (string) --]] + local _, unit = ... + if unit and self.isNamePlate and unit:sub(1, 9) ~= "nameplate" then + local isUnit = self.unit and UnitIsUnit(self.unit, unit) + if isUnit then + unit = self.unit + end + end (self.Health.Override or Update) (self, ...); ColorPath(self, ...) end @@ -392,6 +405,8 @@ local function Enable(self, unit) healthBar:SetScript("OnMinMaxChanged", function() Path(self, "UNIT_MAXHEALTH", self.unit) end) + self:RegisterEvent('UNIT_THREAT_SITUATION_UPDATE', Path) + self:RegisterEvent('UNIT_FLAGS', Path) end if(element:IsObjectType('StatusBar') and not element:GetStatusBarTexture()) then @@ -419,6 +434,7 @@ local function Disable(self) self:UnregisterEvent('UNIT_FACTION', ColorPath) self:UnregisterEvent('UNIT_HAPPINESS', ColorPath) self:UnregisterEvent('UNIT_THREAT_LIST_UPDATE', ColorPath) + self:UnregisterEvent(')UNIT_THREAT_SITUATION_UPDATE', ColorPath) end end diff --git a/ElvUI/Libraries/oUF/elements/powerrage.lua b/ElvUI/Libraries/oUF/elements/powerrage.lua index f142752..fb2d344 100644 --- a/ElvUI/Libraries/oUF/elements/powerrage.lua +++ b/ElvUI/Libraries/oUF/elements/powerrage.lua @@ -17,12 +17,6 @@ local UnitPowerType = UnitPowerType local UnitReaction = UnitReaction local function UpdateColor(self, event, unit) - if unit and self.isNamePlate and unit:sub(1, 9) ~= "nameplate" then - local isUnit = self.unit and UnitIsUnit(self.unit, unit) - if isUnit then - unit = self.unit - end - end if(self.unit ~= unit) then return end local element = self.Rage @@ -86,16 +80,25 @@ local function ColorPath(self, ...) * event - the event triggering the update (string) * unit - the unit accompanying the event (string) --]] - (self.Rage.UpdateColor or UpdateColor) (self, ...) + local _, unit = ... + local args + if unit and self.isNamePlate then + if unit:sub(1, 9) ~= "nameplate" then + local isUnit = self.unit and UnitIsUnit(self.unit, unit) + if isUnit then + args = { ... } + args[2] = self.unit + end + end + end + if args then + return (self.Rage.UpdateColor or UpdateColor) (self, unpack(args)) + else + return (self.Rage.UpdateColor or UpdateColor) (self, ...) + end end local function Update(self, event, unit) - if unit and self.isNamePlate and unit:sub(1, 9) ~= "nameplate" then - local isUnit = self.unit and UnitIsUnit(self.unit, unit) - if isUnit then - unit = self.unit - end - end if(self.unit ~= unit) then return end local element = self.Rage @@ -149,9 +152,24 @@ local function Path(self, ...) * unit - the unit accompanying the event (string) * ... - the arguments accompanying the event --]] - (self.Rage.Override or Update) (self, ...); - - ColorPath(self, ...) + local _, unit = ... + local args + if unit and self.isNamePlate then + if unit:sub(1, 9) ~= "nameplate" then + local isUnit = self.unit and UnitIsUnit(self.unit, unit) + if isUnit then + args = { ... } + args[2] = self.unit + end + end + end + if args then + (self.Rage.Override or Update) (self, unpack(args)); + ColorPath(self, unpack(args)) + else + (self.Rage.Override or Update) (self, ...); + ColorPath(self, ...) + end end local function ForceUpdate(element) diff --git a/ElvUI/Libraries/oUF/elements/pvpindicator.lua b/ElvUI/Libraries/oUF/elements/pvpindicator.lua index 4a76b07..5bd475b 100644 --- a/ElvUI/Libraries/oUF/elements/pvpindicator.lua +++ b/ElvUI/Libraries/oUF/elements/pvpindicator.lua @@ -33,12 +33,6 @@ local FFA_ICON = [[Interface\TargetingFrame\UI-PVP-FFA]] local FACTION_ICON = [[Interface\TargetingFrame\UI-PVP-]] local function Update(self, event, unit) - if unit and self.isNamePlate and unit:sub(1, 9) ~= "nameplate" then - local isUnit = self.unit and UnitIsUnit(self.unit, unit) - if isUnit then - unit = self.unit - end - end if(unit ~= self.unit) then return end local element = self.PvPIndicator @@ -93,7 +87,22 @@ local function Path(self, ...) * event - the event triggering the update (string) * ... - the arguments accompanying the event --]] - return (self.PvPIndicator.Override or Update) (self, ...) + local _, unit = ... + local args + if unit and self.isNamePlate then + if unit:sub(1, 9) ~= "nameplate" then + local isUnit = self.unit and UnitIsUnit(self.unit, unit) + if isUnit then + args = { ... } + args[2] = self.unit + end + end + end + if args then + return (self.PvPIndicator.Override or Update) (self, unpack(args)) + else + return (self.PvPIndicator.Override or Update) (self, ...) + end end local function ForceUpdate(element) diff --git a/ElvUI/Libraries/oUF/elements/threatindicator.lua b/ElvUI/Libraries/oUF/elements/threatindicator.lua index f637f8e..281a2df 100644 --- a/ElvUI/Libraries/oUF/elements/threatindicator.lua +++ b/ElvUI/Libraries/oUF/elements/threatindicator.lua @@ -36,13 +36,6 @@ local UnitExists = UnitExists local UnitThreatSituation = UnitThreatSituation local function Update(self, event, unit) - if not unit then return end - if unit and self.isNamePlate and unit:sub(1, 9) ~= "nameplate" then - local isUnit = self.unit and UnitIsUnit(self.unit, unit) - if isUnit then - unit = self.unit - end - end if(self.unit ~= unit) then return end local element = self.ThreatIndicator @@ -103,7 +96,22 @@ local function Path(self, ...) * event - the event triggering the update (string) * ... - the arguments accompanying the event --]] - return (self.ThreatIndicator.Override or Update) (self, ...) + local _, unit = ... + local args + if unit and self.isNamePlate then + if unit:sub(1, 9) ~= "nameplate" then + local isUnit = self.unit and UnitIsUnit(self.unit, unit) + if isUnit then + args = { ... } + args[2] = self.unit + end + end + end + if args then + return (self.ThreatIndicator.Override or Update) (self, unpack(args)) + else + return (self.ThreatIndicator.Override or Update) (self, ...) + end end local function ForceUpdate(element) diff --git a/ElvUI/Modules/Nameplates/Nameplates.lua b/ElvUI/Modules/Nameplates/Nameplates.lua index 442d489..ef2f0ca 100644 --- a/ElvUI/Modules/Nameplates/Nameplates.lua +++ b/ElvUI/Modules/Nameplates/Nameplates.lua @@ -539,6 +539,7 @@ function NP:ConfigureAll(init) end function NP:PlateFade(nameplate, timeToFade, startAlpha, endAlpha) + if not nameplate.nameplateAnchor:IsShown() then return end -- we need our own function because we want a smooth transition and dont want it to force update every pass. -- its controlled by fadeTimer which is reset when UIFrameFadeOut or UIFrameFadeIn code runs.