12.07.2015 Views

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

Wiley-World.of.Warcraft.Programming.A.Guide.and.Reference.for.Creating.WoW.Addons

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

470 Part III ■ Advanced Addon TechniquesThese define the consistent parts <strong>of</strong> the button behavior. All these menuitems will be spell buttons, <strong>and</strong> they will cast on the unit whose frame wasclicked to bring up the spell menu. Note that you use the type tag attributeheretosettheframeattributetoavaluewiththeLuatype“boolean“.Add a Scripts section immediately after the Attributes block <strong>and</strong> be<strong>for</strong>ethe tag:self:GetFontString():SetPoint(“LEFT“, self.icon, “RIGHT“, 2, 1)self:RegisterEvent(“PLAYER_ENTERING_WORLD“)The first line ensures that the button’s text is placed correctly in the button(because the icon texture is created using a key rather than a name, you can’tcurrently refer to it from an XML tag’s relativeTo attribute). The lastline prepares the button to deal with the fact that its spell icon isn’t availablewhen your addon first loads, which is fully addressed in the next h<strong>and</strong>ler (addit right be<strong>for</strong>e the tag):self.icon:SetTexture(GetSpellTexture(self:GetAttribute(“spell“)))This h<strong>and</strong>ler is run in response to the PLAYER_ENTERING_WORLD event, whenthe client has fully loaded spell icons. These icons are actually loaded by theearlier SPELLS_CHANGED event, but that event does not fire when you reload theUI, so the more reliable PLAYER_ENTERING_WORLD is used. Also, if you watchevent traces, you will see that the SPELL_CHANGED event fires quite a number<strong>of</strong> times during logging in. Waiting until the PLAYER_ENTERING_WORLD eventhelps you avoid all <strong>of</strong> these.Paladins use three major groups <strong>of</strong> beneficial spells, so you’ll create threemenus, one <strong>for</strong> each. To facilitate that, create a menu template in the same file,right be<strong>for</strong>e the tag:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!