diff --git a/modules/nameplates.lua b/modules/nameplates.lua index 5a46e307..1d2f3aae 100644 --- a/modules/nameplates.lua +++ b/modules/nameplates.lua @@ -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 @@ -1116,7 +1105,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()