mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-23 20:40:50 +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
|
return plate.creatureType
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Totem icon, read straight from the game:
|
-- Totem icon: UnitCreatedBySpell returns the totem-drop spell, whose icon IS
|
||||||
-- * Passive totems self-cast their provided buff, so they carry exactly one
|
-- the totem's icon. It's a broadcast descriptor field the client has for every
|
||||||
-- aura whose icon IS the totem's icon (Totem::Summon TOTEM_PASSIVE).
|
-- summoned unit in range, so it resolves immediately for passive and active
|
||||||
-- * Active totems (Searing/Magma/Fire Nova) cast at enemies and hold no
|
-- totems alike -- no self-aura read or attack-cast capture needed.
|
||||||
-- self-aura, so their icon arrives via UNIT_SPELLCAST_SUCCEEDED (cached
|
--
|
||||||
-- into plate.totemIcon by the event handler); nil here until then.
|
-- 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)
|
local function TotemPlate(plate)
|
||||||
if C.nameplates.totemicons ~= "1" then return nil end
|
if C.nameplates.totemicons ~= "1" then return nil end
|
||||||
if CreatureType(plate) ~= 11 then return nil end
|
if CreatureType(plate) ~= 11 then return nil end
|
||||||
if plate.totemIcon then return plate.totemIcon end
|
local spellId = UnitCreatedBySpell(plate.cachedGuid)
|
||||||
local aura = C_UnitAuras.GetBuffDataByIndex(plate.cachedGuid, 1)
|
if spellId ~= plate.totemSpell then
|
||||||
if aura then plate.totemIcon = aura.icon end
|
plate.totemSpell = spellId
|
||||||
|
plate.totemIcon = spellId and C_Spell.GetSpellTexture(spellId) or nil
|
||||||
|
end
|
||||||
return plate.totemIcon
|
return plate.totemIcon
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -499,7 +504,6 @@ nameplates:RegisterEvent("UNIT_SPELLCAST_START")
|
|||||||
nameplates:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
|
nameplates:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
|
||||||
nameplates:RegisterEvent("UNIT_SPELLCAST_STOP")
|
nameplates:RegisterEvent("UNIT_SPELLCAST_STOP")
|
||||||
nameplates:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
|
nameplates:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP")
|
||||||
nameplates:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
|
|
||||||
nameplates:RegisterEvent("PLAYER_GUILD_UPDATE")
|
nameplates:RegisterEvent("PLAYER_GUILD_UPDATE")
|
||||||
|
|
||||||
nameplates:SetScript("OnEvent", function()
|
nameplates:SetScript("OnEvent", function()
|
||||||
@@ -588,6 +592,7 @@ nameplates:RegisterEvent("PLAYER_GUILD_UPDATE")
|
|||||||
plate.nameplate.unit = arg1
|
plate.nameplate.unit = arg1
|
||||||
plate.nameplate.creatureType = nil -- recompute for the new unit
|
plate.nameplate.creatureType = nil -- recompute for the new unit
|
||||||
plate.nameplate.totemIcon = nil
|
plate.nameplate.totemIcon = nil
|
||||||
|
plate.nameplate.totemSpell = nil
|
||||||
if guid then
|
if guid then
|
||||||
plateByGuid[guid] = plate.nameplate
|
plateByGuid[guid] = plate.nameplate
|
||||||
-- Seed: the unit may already be mid-cast (its UNIT_SPELLCAST_START
|
-- Seed: the unit may already be mid-cast (its UNIT_SPELLCAST_START
|
||||||
@@ -665,22 +670,6 @@ nameplates:RegisterEvent("PLAYER_GUILD_UPDATE")
|
|||||||
end
|
end
|
||||||
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
|
elseif event == "UNIT_AURA" then
|
||||||
-- ClassicAPI: fires with arg1 == "nameplateN" when a unit's aura set
|
-- ClassicAPI: fires with arg1 == "nameplateN" when a unit's aura set
|
||||||
-- changes (add/remove/modify). Flag the matching plate so OnUpdate does a
|
-- 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)
|
local TotemIcon = TotemPlate(plate)
|
||||||
|
|
||||||
if TotemIcon then
|
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.totem.icon:SetTexture(TotemIcon)
|
||||||
|
|
||||||
plate.glow:Hide()
|
plate.glow:Hide()
|
||||||
|
|||||||
Reference in New Issue
Block a user