mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-01 19:30:00 +00:00
nameplates: source totem icons from UnitCreatedBySpell
Read the totem's icon from the totem-drop spell (UnitCreatedBySpell + GetSpellTexture) instead of the self-aura at index 1 plus a UNIT_SPELLCAST_SUCCEEDED capture for active totems. The drop spell is a broadcast descriptor field present for every summoned unit in range, so it resolves immediately for passive and active totems alike and gives the totem's own icon rather than the attack-spell proxy. Drops the UNIT_SPELLCAST_SUCCEEDED registration and handler. Re-read the spell each render and key the cached texture on the spell id so an in-place totem swap (same unit, new drop spell -- no plate re-add) refreshes the icon without needing the plate to leave and re-enter view.
This commit is contained in:
+16
-27
@@ -296,18 +296,23 @@ pfUI:RegisterModule("nameplates", function ()
|
||||
return plate.creatureType
|
||||
end
|
||||
|
||||
-- Totem icon, read straight from the game:
|
||||
-- * Passive totems self-cast their provided buff, so they carry exactly one
|
||||
-- aura whose icon IS the totem's icon (Totem::Summon TOTEM_PASSIVE).
|
||||
-- * Active totems (Searing/Magma/Fire Nova) cast at enemies and hold no
|
||||
-- self-aura, so their icon arrives via UNIT_SPELLCAST_SUCCEEDED (cached
|
||||
-- into plate.totemIcon by the event handler); nil here until then.
|
||||
-- Totem icon: UnitCreatedBySpell returns the totem-drop spell, whose icon IS
|
||||
-- the totem's icon. It's a broadcast descriptor field the client has for every
|
||||
-- summoned unit in range, so it resolves immediately for passive and active
|
||||
-- totems alike -- no self-aura read or attack-cast capture needed.
|
||||
--
|
||||
-- Re-read the spell every call rather than caching the icon outright: a shaman
|
||||
-- can swap the totem in place (same unit, new drop spell) with no plate re-add
|
||||
-- to invalidate a cache, so key the cached texture on the spell id and refresh
|
||||
-- it only when the spell changes.
|
||||
local function TotemPlate(plate)
|
||||
if C.nameplates.totemicons ~= "1" then return nil end
|
||||
if CreatureType(plate) ~= 11 then return nil end
|
||||
if plate.totemIcon then return plate.totemIcon end
|
||||
local aura = C_UnitAuras.GetBuffDataByIndex(plate.cachedGuid, 1)
|
||||
if aura then plate.totemIcon = aura.icon end
|
||||
local spellId = UnitCreatedBySpell(plate.cachedGuid)
|
||||
if spellId ~= plate.totemSpell then
|
||||
plate.totemSpell = spellId
|
||||
plate.totemIcon = spellId and C_Spell.GetSpellTexture(spellId) or nil
|
||||
end
|
||||
return plate.totemIcon
|
||||
end
|
||||
|
||||
@@ -499,7 +504,6 @@ nameplates:RegisterEvent("UNIT_SPELLCAST_START")
|
||||
nameplates:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
|
||||
nameplates:RegisterEvent("UNIT_SPELLCAST_STOP")
|
||||
nameplates:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
|
||||
nameplates:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
|
||||
nameplates:RegisterEvent("PLAYER_GUILD_UPDATE")
|
||||
|
||||
nameplates:SetScript("OnEvent", function()
|
||||
@@ -588,6 +592,7 @@ nameplates:RegisterEvent("PLAYER_GUILD_UPDATE")
|
||||
plate.nameplate.unit = arg1
|
||||
plate.nameplate.creatureType = nil -- recompute for the new unit
|
||||
plate.nameplate.totemIcon = nil
|
||||
plate.nameplate.totemSpell = nil
|
||||
if guid then
|
||||
plateByGuid[guid] = plate.nameplate
|
||||
-- Seed: the unit may already be mid-cast (its UNIT_SPELLCAST_START
|
||||
@@ -665,22 +670,6 @@ nameplates:RegisterEvent("PLAYER_GUILD_UPDATE")
|
||||
end
|
||||
end
|
||||
|
||||
elseif event == "UNIT_SPELLCAST_SUCCEEDED" then
|
||||
-- Active totems (Searing/Magma/Fire Nova) carry no self-aura, so their
|
||||
-- attack cast is the only icon source. Capture it once per totem, gated on
|
||||
-- creature type so a normal caster's spell never styles it as a totem.
|
||||
if arg1 and strfind(arg1, "^nameplate") then
|
||||
local guid = UnitGUID(arg1)
|
||||
local plate = guid and plateByGuid[guid]
|
||||
if plate and not plate.totemIcon and arg3 and CreatureType(plate) == 11 then
|
||||
local tex = C_Spell.GetSpellTexture(arg3)
|
||||
if tex then
|
||||
plate.totemIcon = tex
|
||||
plate.castUpdate = true -- re-render now so the icon shows
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elseif event == "UNIT_AURA" then
|
||||
-- ClassicAPI: fires with arg1 == "nameplateN" when a unit's aura set
|
||||
-- changes (add/remove/modify). Flag the matching plate so OnUpdate does a
|
||||
@@ -1110,7 +1099,7 @@ nameplates:RegisterEvent("PLAYER_GUILD_UPDATE")
|
||||
local TotemIcon = TotemPlate(plate)
|
||||
|
||||
if TotemIcon then
|
||||
-- icon resolved from the totem's aura / attack cast (already a full path)
|
||||
-- icon resolved from the totem-drop spell (already a full path)
|
||||
plate.totem.icon:SetTexture(TotemIcon)
|
||||
|
||||
plate.glow:Hide()
|
||||
|
||||
Reference in New Issue
Block a user