From 61282115a3fb91af6cd6917b6700f3b62a447a68 Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 31 Oct 2026 00:36:43 -0500 Subject: [PATCH] Pulse the screen edge glow smoothly and drive it from events The glow stepped its color ten times a second and re-checked combat, health and death on every step. An animation group now shifts the color along an IN_OUT curve and pauses while the glow is hidden. Combat, health and death update from their events. Aggro has no event, so a ticker polls it every .3s, matching UnitHasAggro's cache, and only while that glow is enabled. --- modules/infight.lua | 83 ++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/modules/infight.lua b/modules/infight.lua index 895b9cfc..8caa7ca1 100644 --- a/modules/infight.lua +++ b/modules/infight.lua @@ -1,51 +1,64 @@ pfUI:RegisterModule("infight", function () - local function OnUpdate() - if not this.infight and not this.aggro and not this.health then return end - if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .1 end + pfUI.infight = CreateFrame("Frame", "pfUICombatScreen", WorldFrame) + pfUI.infight:SetAllPoints(WorldFrame) + pfUI.infight:EnableMouse(false) + pfUI.infight:Hide() - if not this.fadeValue then this.fadeValue = 1 end - if this.fadeValue >= 0.3 then - this.fadeModifier = -0.1 - end - if this.fadeValue <= 0 then - this.fadeModifier = 0.1 - end - this.fadeValue = this.fadeValue + this.fadeModifier + -- Shift the glow between red and a paler orange for good. The group only + -- advances while the glow is shown, so a hidden glow costs nothing. + local pulse = pfUI.infight:CreateAnimationGroup() + pulse:SetLooping("BOUNCE") + local shift = pulse:CreateAnimation() + shift:SetDuration(.3) + shift:SetSmoothing("IN_OUT") + shift:SetScript("OnUpdate", function(self) + local fade = self:GetSmoothProgress() * .3 + pfUI.infight:SetBackdropBorderColor(1, .2 + fade, fade, 1 - fade) + end) + pulse:Play() - local visible = nil - if this.infight and UnitAffectingCombat("player") then visible = true end - if this.aggro and UnitHasAggro("player") > 0 then visible = true end - if this.health and UnitHealth("player")/UnitHealthMax("player")*100 <= 25 then visible = true end - if UnitIsDeadOrGhost("player") then visible = nil end + -- Combat, health and death come from events. Aggro has no event, so a + -- ticker polls it while that glow is enabled. + local combat, health, dead, aggro, poll - if visible then - this.screen:Show() - this.screen:SetBackdropBorderColor(1,0.2+this.fadeValue, this.fadeValue, 1-this.fadeValue) - else - this.screen:Hide() - end + local function Refresh() + pfUI.infight:SetShown((combat or health or aggro) and not dead) end - pfUI.infight = CreateFrame("Frame", "pfUICombat", UIParent) - pfUI.infight:SetScript("OnUpdate", OnUpdate) + local function UpdatePlayer() + combat = C.appearance.infight.screen == "1" and UnitAffectingCombat("player") + health = C.appearance.infight.health == "1" and UnitHealth("player") / UnitHealthMax("player") <= .25 + dead = UnitIsDeadOrGhost("player") + Refresh() + end - pfUI.infight.screen = CreateFrame("Frame", "pfUICombatScreen", WorldFrame) - pfUI.infight.screen:SetAllPoints(WorldFrame) - pfUI.infight.screen:EnableMouse(false) - pfUI.infight.screen:Hide() + local function UpdateAggro() + aggro = UnitHasAggro("player") > 0 + Refresh() + end + + pfUI.infight:RegisterEvent("PLAYER_ENTERING_WORLD") + pfUI.infight:RegisterEvent("PLAYER_REGEN_DISABLED") + pfUI.infight:RegisterEvent("PLAYER_REGEN_ENABLED") + pfUI.infight:RegisterEvent("PLAYER_DEAD") + pfUI.infight:RegisterEvent("PLAYER_ALIVE") + pfUI.infight:RegisterEvent("PLAYER_UNGHOST") + pfUI.infight:RegisterUnitEvent("UNIT_HEALTH", "player") + pfUI.infight:RegisterUnitEvent("UNIT_MAXHEALTH", "player") + pfUI.infight:SetScript("OnEvent", UpdatePlayer) pfUI.infight.UpdateConfig = function(self) - pfUI.infight.infight = C.appearance.infight.screen == "1" and true or nil - pfUI.infight.aggro = C.appearance.infight.aggro == "1" and true or nil - pfUI.infight.health = C.appearance.infight.health == "1" and true or nil - - pfUI.infight.screen:SetBackdrop({ + pfUI.infight:SetBackdrop({ edgeFile = pfUI.media["img:glow"], edgeSize = tonumber(C.appearance.infight.intensity), insets = {left = 0, right = 0, top = 0, bottom = 0}, }) - pfUI.infight.screen:Hide() + if poll then poll:Cancel() end + poll = C.appearance.infight.aggro == "1" and C_Timer.NewTicker(.3, UpdateAggro) + aggro = nil + + UpdatePlayer() end - pfUI.infight.UpdateConfig() + pfUI.infight:UpdateConfig() end)