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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

174 Part II ■ <strong>Programming</strong> in <strong>World</strong> <strong>of</strong> <strong>Warcraft</strong>SetTexture <strong>of</strong> the resulting texture, to color it red. Although accesses such asthis are better h<strong>and</strong>led using the parentKey attribute, naming frames is stillvery important. As shown at the end <strong>of</strong> Chapter 9, users <strong>and</strong> developers canuse the /framestack comm<strong>and</strong> to determine what frames are on screen at agiven point in time. If you make lots <strong>of</strong> unnamed frames, it is very difficult todistinguish among them. For that reason, you are encouraged to create namedframes in addition to utilizing the parentKey attribute where appropriate.Setting Keys Using the parentKey AttributeIn addition to being useful in normal frame definitions, the parentKey attributecan be used in template definitions to make textures, font strings, <strong>and</strong>sub-frames accessible. Rather than per<strong>for</strong>m a name lookup, you could setthe texture <strong>of</strong> a button’s icon using the following code (assuming that thevariable self is set to one <strong>of</strong> the three buttons):self.icon:SetTexture(1, 0, 0)In addition to being more efficient, this method is easier to read <strong>and</strong>doesn’t require the code to know whether or not frames are named. Althoughthe majority <strong>of</strong> the templates in the default user interface do not yet takeadvantage <strong>of</strong> this feature, it’s a nice <strong>and</strong> easy way to define <strong>and</strong> access theelements <strong>of</strong> a frame.<strong>Creating</strong> a Template <strong>for</strong> BagBuddy’s Item ButtonsEach item slot in BagBuddy will show the item’s icon <strong>and</strong> the number <strong>of</strong> items<strong>of</strong> a given type in your inventory. In addition, there will be a colored borderaround each item showing its rarity (that is, purple <strong>for</strong> epic, blue <strong>for</strong> rare, <strong>and</strong>so on). The default user interface already has a template that contains all <strong>of</strong>these elements, called ItemButtonTemplate.In fact, you could inherit directly from ItemButtonTemplate, but thatwouldn’t be a very good example. In addition, if Blizzard makes any changesto its template, your addon might break. Instead you will copy the code fromthe FrameXML definition <strong>and</strong> adapt it to your own needs. Open BagBuddy.xml<strong>and</strong> add the following at the top <strong>of</strong> the file, inside the element:

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

Saved successfully!

Ooh no, something went wrong!