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.

202 Part II ■ <strong>Programming</strong> in <strong>World</strong> <strong>of</strong> <strong>Warcraft</strong>Examining the FrameXML CodeA useful question whenever you are trying to accomplish something in acustom addon is to ask:‘‘Does the default user interface do this?’’Ifso,thensomewhereinthecode<strong>for</strong>thedefaultUIisthetechniqueusedto accomplish the task; it’s just a matter <strong>of</strong> finding it. For example, you mightwant to display the player’s haste rating <strong>and</strong> percentage effect somewherein your addon. A quick look at the API categories doesn’t reveal anythingimmediately so you instead look at the default user interface.That in<strong>for</strong>mation is displayed on the character panel in the stats sectionat the bottom. To find out where that panel is defined, you can do a bit<strong>of</strong> investigative work. Start by running the /framestack comm<strong>and</strong> that wasintroduced in Chapter 9. From the in<strong>for</strong>mation you get there, it appears thatPaperDollFrame <strong>and</strong> CharacterFrame are both good c<strong>and</strong>idates. Convenientlyenough, these frames are defined in files by the same name in the FrameXMLcode.Opening CharacterFrame.xml shows you the definition <strong>of</strong> the differenttabs, so it appears that that’s the outmost frame that contains the subframes.The CharacterAttributesFrame in PaperDollFrame.xml, however,looks like a good c<strong>and</strong>idate. Now that you’ve found the frame, you can openPaperDollFrame.lua to look around.At the top <strong>of</strong> the file you see a number <strong>of</strong> global constants defined. Looking<strong>for</strong> one having to do with haste, you find the following constants:CR_HASTE_MELEE = 18;CR_HASTE_RANGED = 19;CR_HASTE_SPELL = 20;When haste was first introduced in the game, there were different versions<strong>for</strong> melee, ranged, <strong>and</strong> spell. In Wrath <strong>of</strong> the Lich King they were all combinedinto a single haste rating. Pick the melee version <strong>and</strong> search <strong>for</strong> that throughoutthe whole file.The only instance in the file is in the following line <strong>of</strong> code, in the aptlynamed PaperDollFrame_SetAttackSpeed() function:statFrame.tooltip2 = <strong>for</strong>mat(CR_HASTE_RATING_TOOLTIP, iGetCombatRating(CR_HASTE_MELEE), GetCombatRatingBonus(CR_HASTE_MELEE));Now you can test these two functions to see if they work <strong>for</strong> your needs.Run the following code in-game:/run print(GetCombatRating(CR_HASTE_MELEE))/run print(GetCombatRatingBonus(CT_HASTE_MELEE))You will find that although the returns from GetCombatRating() are thesame, you may have different results <strong>for</strong> the actual percent bonus. This bonus

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

Saved successfully!

Ooh no, something went wrong!