This seems to work. I changed it to initialize on
PLAYER_LOGIN and listen for
SPELL_POWER_CHANGED. Many character-related data functions don't return meaningful values on load and require initial data from the server. This is what
PLAYER_LOGIN signifies. Blizzard's
PaperDollFrame reacts to
PLAYER_DAMAGE_DONE_MODS along with a handful of others. As these events tend to fire in rapid bursts, Blizzard opts to hand the events off to an OnUpdate script in order to consolidate these bursts into a single update call for performance reasons. This code doesn't do any significant processing, so it isn't really a problem for us.
I utilize the AnimationGroup's
OnPlay and
OnFinished scripts to trigger show/hide. It may not be necessary. I didn't find documentation on
AlphaAnimation:SetChange() existing. It may be a depreciated function.
:SetFromAlpha() and
:SetToAlpha() work fine. I added a short fade in animation to smooth out the effect. This also uses Blizzard's
EventRegistry instead of creating an invisible frame to handle events.
This was tested on Wrath Classic, other clients may need further adjustments.
Lua Code:
local AlertText=UIParent:CreateFontString(nil,"OVERLAY","GameTooltipText");
AlertText:SetPoint("CENTER");
AlertText:SetFont("Fonts\\FRIZQT__.TTF",24,"OUTLINE");
AlertText:SetText("Shadow power increased!");
AlertText:SetAlpha(0);
AlertText:Hide();
local AlertAnimationGroup=AlertText:CreateAnimationGroup();
AlertAnimationGroup:SetLooping("NONE");
AlertAnimationGroup:SetScript("OnPlay",function() AlertText:Show(); end);
AlertAnimationGroup:SetScript("OnFinished",function() AlertText:Hide(); end);
local AlertAnimationFadeIn=AlertAnimationGroup:CreateAnimation("Alpha");
AlertAnimationFadeIn:SetOrder(1);
AlertAnimationFadeIn:SetDuration(0.5);
AlertAnimationFadeIn:SetFromAlpha(0);
AlertAnimationFadeIn:SetToAlpha(1);
local AlertAnimationFadeOut=AlertAnimationGroup:CreateAnimation("Alpha");
AlertAnimationFadeIn:SetOrder(2);
AlertAnimationFadeIn:SetDuration(4.5);
AlertAnimationFadeIn:SetFromAlpha(1);
AlertAnimationFadeIn:SetToAlpha(0);
local OnShadowPowerChanged; do
local ShadowPowerCache;
function OnShadowPowerChanged()
local bonus=GetSpellBonusDamage(6);
if ShadowPowerCache and bonus>ShadowPowerCache then
if AlertAnimationGroup:IsPlaying() then
AlertAnimationGroup:Restart();
else AlertAnimationGroup:Play(); end
end
ShadowPowerCache=bonus;
end
end
EventRegistry:RegisterFrameEventAndCallback("PLAYER_LOGIN",OnShadowPowerChanged);
EventRegistry:RegisterFrameEventAndCallback("SPELL_POWER_CHANGED",OnShadowPowerChanged);