Files
pfUI/modules/infight.lua
T
Brues 54e66fea11 Drive range, offline, aggro and combat state from events
Every unit frame re-checked its range fade, offline state, combat and
aggro glow and indicator icons on a 0.2-0.5s tick, and infight polled
aggro every 0.3s. Each now comes from an event.

Aggro: the 270-token scan and its cache are gone. UNIT_TARGET fires for
every unit in view (SuperWoW registers them all), so a table of which
hostile unit attacks which friendly one, by GUID, follows every attacker,
including ones no token reaches. A unit that comes into view mid-fight
is noted when a token first reaches it (target, focus, mouseover, a
nameplate, a member's target). A read drops attackers that left view,
where nothing fires, and a loading screen resets the table. Changes go
out as "aggro:changed" with the old and the new victim, so only the
frames showing those redraw; infight listens too.

Combat square and glow follow UNIT_FLAGS. Range fade follows ClassicAPI's
UNIT_IN_RANGE_UPDATE, registered only by frames that fade, by GUID for a
chained unit; with the 40y check off, frames fade by sight through
UNIT_DISTANCE_CHECK_UPDATE, which also swaps a portrait's question mark
for the model. A UnitXP threshold has no event and keeps its poll.
UNIT_CONNECTION refreshes a member who goes offline or comes back; the
PARTY_MEMBER_ENABLE/DISABLE branches were never registered.

A full refresh now draws the indicator icons and combat state, so a new
unit brings its own. UNIT_FACTION redraws the PvP icon and reaction
colour; its "pvp" refresh step drew nothing. Unlock mode and /pftest
re-apply the fade on entry and exit.

What stays on the tick: the pet frames and the UnitXP range check.
2026-10-31 13:10:46 -05:00

66 lines
2.3 KiB
Lua

pfUI:RegisterModule("infight", function ()
pfUI.infight = CreateFrame("Frame", "pfUICombatScreen", WorldFrame)
pfUI.infight:SetAllPoints(WorldFrame)
pfUI.infight:EnableMouse(false)
pfUI.infight:Hide()
-- 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()
-- Combat, health, death and aggro all come from events.
local combat, health, dead, aggro
local function Refresh()
pfUI.infight:SetShown((combat or health or aggro) and not dead)
end
local function UpdateAggro()
aggro = C.appearance.infight.aggro == "1" and UnitHasAggro("player") > 0
Refresh()
end
-- a combat drop is also when an attacker that left view is let go
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")
UpdateAggro()
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.events:RegisterCallback("aggro:changed", function(_, old, new)
local player = UnitGUID("player")
if old == player or new == player then UpdateAggro() end
end, "infight")
pfUI.infight.UpdateConfig = function(self)
pfUI.infight:SetBackdrop({
edgeFile = pfUI.media["img:glow"], edgeSize = tonumber(C.appearance.infight.intensity),
insets = {left = 0, right = 0, top = 0, bottom = 0},
})
UpdatePlayer()
end
pfUI.infight:UpdateConfig()
end)