From 480889cb05829485d0950247721ac13735e2ce1a Mon Sep 17 00:00:00 2001 From: Brues <5278969+brues-code@users.noreply.github.com> Date: Sat, 31 Oct 2026 11:55:54 -0500 Subject: [PATCH] Drive power from UNIT_POWER_UPDATE and UNIT_MAXPOWER 1.12's UNIT_MANA, UNIT_RAGE and the rest fire for every power a unit has, not only the one it shows, so a druid in cat or bear form redrew every frame showing them, health colours and texts included, on each mana tick. ClassicAPI's generic power events name the power in arg2. Unit frames register them on their own token and redraw only for the power their bar shows, or for mana under a druid mana bar. They fire for tokens only, so the GUID-followed target-of-X frames keep the per-type events; those now share one list with UNIT_AURA, so a frame swaps auras and power on the same check. energytick counts gains on the power it tracks alone, so a cat druid's mana regen is no longer read as energy. It forgets the power while hidden, so a bear's mana ticks are not measured against rage, and re-baselines on a shift, so leaving cat form is not a fake mana gain. The equipment manager's dining trigger wakes on mana changes only. --- api/unitframes.lua | 43 +++++++++++++++++++++++++----------- modules/energytick.lua | 10 +++++---- modules/equipmentmanager.lua | 7 +++--- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/api/unitframes.lua b/api/unitframes.lua index 05d705d5..c1bd9413 100644 --- a/api/unitframes.lua +++ b/api/unitframes.lua @@ -1137,6 +1137,13 @@ function pfUI.uf.OnEvent() else this.update_auratime = true end + elseif event == "UNIT_POWER_UPDATE" or event == "UNIT_MAXPOWER" then + -- every power of the unit reports, a cat druid's mana regen too; redraw + -- for the one the bar shows, and for mana under a druid mana bar + local _, shown = UnitPowerType(arg1) + if arg2 == shown or (arg2 == "MANA" and this.druidmana) then + this.update_base = true + end elseif event == "UNIT_FACTION" then this.update_pvp = true elseif event == "UNIT_COMBAT" then @@ -1376,13 +1383,22 @@ end local UNIT_EVENTS = { "UNIT_DISPLAYPOWER", "UNIT_HEALTH", "UNIT_MAXHEALTH", + "UNIT_PORTRAIT_UPDATE", "UNIT_MODEL_CHANGED", + "UNIT_FACTION", + "INCOMING_RESURRECT_CHANGED", -- frame=ressIcon +} + +-- Auras and power. ClassicAPI's UNIT_AURA_DELTA also reports refreshes and new +-- durations and says what changed; its generic power events name the power, so +-- a frame skips the ones it does not draw. Both fire for tokens only, so a +-- chained unit, followed by GUID, keeps 1.12's events instead. +local TOKEN_EVENTS = { "UNIT_AURA_DELTA", "UNIT_POWER_UPDATE", "UNIT_MAXPOWER" } +local GUID_EVENTS = { + "UNIT_AURA", "UNIT_MANA", "UNIT_MAXMANA", "UNIT_RAGE", "UNIT_MAXRAGE", "UNIT_ENERGY", "UNIT_MAXENERGY", "UNIT_FOCUS", - "UNIT_PORTRAIT_UPDATE", "UNIT_MODEL_CHANGED", - "UNIT_FACTION", - "INCOMING_RESURRECT_CHANGED", -- frame=ressIcon } -- Point this frame's unit-event subscriptions at `unit` (a token, or a chained @@ -1401,16 +1417,17 @@ function pfUI.uf:RegisterUnitEvents(unit) end end - -- auras (frame=buff, frame=debuff, indicators): UNIT_AURA_DELTA, which also - -- reports refreshes and new durations and says what changed. It fires for - -- tokens only, so a chained unit, followed by GUID, keeps UNIT_AURA. - local aura, other = "UNIT_AURA_DELTA", "UNIT_AURA" - if self.chain then aura, other = other, aura end - self:UnregisterEvent(other) - if unit then - self:RegisterUnitEvent(aura, unit) - else - self:UnregisterEvent(aura) + local events, other = TOKEN_EVENTS, GUID_EVENTS + if self.chain then events, other = other, events end + for i = 1, table.getn(other) do + self:UnregisterEvent(other[i]) + end + for i = 1, table.getn(events) do + if unit then + self:RegisterUnitEvent(events[i], unit) + else + self:UnregisterEvent(events[i]) + end end -- UNIT_COMBAT rides along only while the frame draws combat feedback text. diff --git a/modules/energytick.lua b/modules/energytick.lua index 8e8d074e..9728b076 100644 --- a/modules/energytick.lua +++ b/modules/energytick.lua @@ -132,8 +132,7 @@ pfUI:RegisterModule("energytick", function() energytick:SetAllPoints(pfUI.uf.player.power.bar) energytick:RegisterEvent("PLAYER_ENTERING_WORLD") energytick:RegisterUnitEvent("UNIT_DISPLAYPOWER", "player") - energytick:RegisterUnitEvent("UNIT_ENERGY", "player") - energytick:RegisterUnitEvent("UNIT_MANA", "player") + energytick:RegisterUnitEvent("UNIT_POWER_UPDATE", "player") energytick:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player") energytick:RegisterUnitEvent("UNIT_SPELLCAST_CHANNEL_STOP", "player") energytick:RegisterEvent("SPELLS_CHANGED") @@ -147,6 +146,7 @@ pfUI:RegisterModule("energytick", function() this.mode = "ENERGY" this:Show() else + this.mode = nil this:Hide() end @@ -155,7 +155,8 @@ pfUI:RegisterModule("energytick", function() return end - if event == "PLAYER_ENTERING_WORLD" then + -- a shift swaps the power the gains are measured on + if event == "PLAYER_ENTERING_WORLD" or event == "UNIT_DISPLAYPOWER" then this.lastPower = UnitPower("player") end @@ -179,7 +180,8 @@ pfUI:RegisterModule("energytick", function() return end - if (event == "UNIT_MANA" or event == "UNIT_ENERGY") and arg1 == "player" then + -- only the shown power: a cat druid's mana regen is not an energy gain + if event == "UNIT_POWER_UPDATE" and arg2 == this.mode then local power = UnitPower("player") local diff = this.lastPower and (power - this.lastPower) or 0 this.lastPower = power diff --git a/modules/equipmentmanager.lua b/modules/equipmentmanager.lua index ba442d35..81cfe11c 100644 --- a/modules/equipmentmanager.lua +++ b/modules/equipmentmanager.lua @@ -1517,10 +1517,10 @@ pfUI:RegisterModule("equipmentmanager", function() -- constantly in combat, so only listen while a dining trigger exists. if dining then engineEvents:RegisterUnitEvent("UNIT_HEALTH", "player") - engineEvents:RegisterUnitEvent("UNIT_MANA", "player") + engineEvents:RegisterUnitEvent("UNIT_POWER_UPDATE", "player") else engineEvents:UnregisterEvent("UNIT_HEALTH") - engineEvents:UnregisterEvent("UNIT_MANA") + engineEvents:UnregisterEvent("UNIT_POWER_UPDATE") end if poll and not engine.poll then @@ -1554,7 +1554,8 @@ pfUI:RegisterModule("equipmentmanager", function() engine.ready = true Schedule() end) - else + elseif event ~= "UNIT_POWER_UPDATE" or arg2 == "MANA" then + -- the dining set waits on mana alone, not on rage or energy Schedule() end end)