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.

Chapter 10 ■ Saving Time with Frame Templates 177item:SetPoint(“TOPLEFT“, self.items[idx-6], “BOTTOMLEFT“, 0, -7)elseitem:SetPoint(“TOPLEFT“, self.items[idx-1], “TOPRIGHT“, 12, 0)endendYou first create a table that will be used to store the individual buttons.This will make it easier to iterate over the buttons when displaying items. Foreach index you create a new button from the template you created. Then youprogrammatically set the anchors:If you’re creating the first button, anchor it to the frame itself in the firstbutton slot.When creating the first button in any subsequent row, anchor the newbutton to the first column <strong>of</strong> the prior row.For all other buttons, anchor the new button to the previous button onthe row.By contrast, accomplishing the same thing in XML would require 3 to 5lines <strong>for</strong> each button <strong>for</strong> a total <strong>of</strong> somewhere between 70 <strong>and</strong> 250 lines. Whencreating just a few instances <strong>of</strong> a template, I tend to include them in the XML,but whenever I’m doing something very repetitive like this I prefer to createthe frames in Lua.As you move your mouse over the item buttons you can see the highlighttexture appear. This allows you to easily see which button you are currentlyhovering over.Exploring Font DefinitionsFont definitions are a bit <strong>of</strong> an exception when it comes to the template systemin <strong>World</strong> <strong>of</strong> <strong>Warcraft</strong>. Although they use the same inheritance mechanism,they work quite differently. This section looks at a specific font definition toprovide an underst<strong>and</strong>ing <strong>of</strong> how they work. You can find the definition <strong>of</strong>GameFontNormalSmall in FontStyles.xml, which can be extracted using theBlizzard Interface Toolkit, introduced in Chapter 8. The code <strong>for</strong> the templateis as follows:The font definition includes the virtual attribute, but it’s essentially ignored.Remember, you are creating a font definition (which is an actual in-game object)

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

Saved successfully!

Ooh no, something went wrong!