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 26 ■ <strong>Creating</strong> Unit Frames with Group Templates 513function SquareUnitFrames_InitialConfig, to register the button <strong>for</strong> dragevents:button.unit:RegisterForDrag(“LeftButton“)Reload your user interface <strong>and</strong> you should be able to drag the framesaround the screen, <strong>and</strong> click them to target the unit. If you are in the middle<strong>of</strong> dragging the frame when someone joins or leaves the party, the header willstop moving. This is because when the button you are dragging (the actualunit frame you click) is hidden, the game client will not fire an OnMouseUpevent. If the OnHide script wasn’t set that way, the header would get stuck toyour mouse.Health Update EventsUnit frames aren’t very useful without an accurate depiction <strong>of</strong> the unit’shealth, so you should register <strong>for</strong> three events, by adding the following codeto the bottom <strong>of</strong> your initial configuration function:frame:RegisterEvent(“UNIT_HEALTH“)frame:RegisterEvent(“UNIT_MAXHEALTH“)frame:RegisterEvent(“PLAYER_ENTERING_WORLD“)The first two events you should already be familiar with from your workearlier in this book, but PLAYER_ENTERING_WORLD is a bit peculiar. Without it,your unit frames would work in most situations, but in specific circumstances(such as when the player releases in Tempest Keep <strong>and</strong> is resurrected outside)the unit frames could get ‘‘stuck’’ on the wrong health display until anotherevent occurred. To prevent this, all unit frames will reset themselves wheneverthis event occurs.Add the OnEvent script to the definition <strong>of</strong> SquareUnitFrames_UnitTemplate,not the sub-button you’ve been working on previously, putting the followingdirectly after the OnShow definition:Create the corresponding h<strong>and</strong>ler by defining a new function:function SquareUnitFrames_Frame_OnEvent(self, event, arg1, ...)local unit = self:GetAttribute(“unit“)if not unit thenreturnend-- H<strong>and</strong>le any events that don’t accept a unit argumentif event == “PLAYER_ENTERING_WORLD“ thenSquareUnitFrames_ResetUnitButton(self.unit, unit)elseif arg1 <strong>and</strong> UnitIsUnit(unit, arg1) then

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

Saved successfully!

Ooh no, something went wrong!