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.

Chapter 26 ■ <strong>Creating</strong> Unit Frames with Group Templates 511the unit’s name is on the OVERLAY layer, be<strong>for</strong>e graphical layers are checked,frame levels are used to layer the graphics. Because both <strong>of</strong> the status bars arechildren <strong>of</strong> the unit frame, they are at least one frame level higher than thebutton, causing the textures <strong>for</strong> the status bars to appear above the font string.There is no good way to fix this, but one way is to manually lower the framelevel <strong>of</strong> the status bars to match the main button. This may not work in allcases, but in these simple unit frames it works quite well.Nudging Frame LevelsBecause the status bar frame levels only need to be adjusted when the frame isfirst created, this is a great place to utilize initialConfigFunction.Atthetop<strong>of</strong> SquareUnitFrames.lua, add the following function definition:function SquareUnitFrames_InitialConfig(frame)-- Nudge the status bar frame levels downframe.unit.healthBar:SetFrameLevel(frame.unit:GetFrameLevel())frame.unit.powerBar:SetFrameLevel(frame.unit:GetFrameLevel())endThen, right be<strong>for</strong>e the line that calls SquareUnitFrames_Header:Show():SquareUnitFrames_Header.initialConfigFunction = iSquareUnitFrames_InitialConfigNow whenever a frame is created, the initial configuration function is called<strong>and</strong> the frame levels are nudged so the frame displays correctly. Figure 26-2shows SquareUnitFrames at this stage, with the names <strong>and</strong> colored status barsvisible.Figure 26-2: SquareUnitFrames showing the player frame, after nudging frame levels.Responding to Events <strong>and</strong> ClicksThe names are a bit squished <strong>and</strong> the frames don’t actually update when theplayer’s health or power change, but if you have people leave <strong>and</strong> join yourparty you should see the frames reconfiguring during combat. This sectionmakes the frames a bit more responsive by responding to events.Targeting the Unit on Left-ClickCurrently when you click the unit frames, they do nothing other than eat themouse click. As you learned in Chapter 15, you can fix this by setting attributes

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

Saved successfully!

Ooh no, something went wrong!