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.

512 Part III ■ Advanced Addon Techniqueson the secure frame. Add the following to the XML definition <strong>for</strong> the unitbutton, inside the main template. The code goes between the tag<strong>and</strong> the tag:The first attribute directs the frame to use the unit attribute from its parent.Remember that the unit button isn’t the one being created by the group header,so the attribute won’t be set on it. Inheriting the parent’s attribute in this wayensures that any changes during combat work correctly. The second attributetells the frame to set all left-clicks to target the unit. In addition to this, youcould actually bind spells, macros, <strong>and</strong> other types <strong>of</strong> actions supported by theSecureUnitButton template.Moving the HeaderAs fun as creating unit frames is, having them stuck in the middle <strong>of</strong> yourscreen can seriously impact your playing! You’ve done this a few times alreadyin this book, so add the following scripts to the unit button’s definition insidethe template (after the tag <strong>and</strong> be<strong>for</strong>e the element):And add the corresponding functions to SquareUnitFrames.lua anywherebe<strong>for</strong>e the last three lines that show the header:function SquareUnitFrames_Button_OnDragStart(self, button)SquareUnitFrames_Header:StartMoving()SquareUnitFrames_Header.isMoving = trueendfunction SquareUnitFrames_Button_OnDragStop(self, button)if SquareUnitFrames_Header.isMoving thenSquareUnitFrames_Header:StopMovingOrSizing()endendNote that these functions call StartMoving() <strong>and</strong> StopMovingOrSizing()on the header, rather than on the frame itself. This ensures that the entire set<strong>of</strong> unit frames moves together. Now add the final line to your initialization

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

Saved successfully!

Ooh no, something went wrong!