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 519self.unit.name:SetTextColor(r, g, b)elseself.unit.name:SetTextColor(1, 1, 1)endFigure 26-5 shows a raid group with names colored to indicate threat level.Figure 26-5: SquareUnitFrames showing threat levels <strong>for</strong> party membersShowing Dead PlayersRight now if someone in your group were to die, it would be difficult to see ifthey were actually dead or just very low on health. You can fix this by changingthe status bar’s color to gray <strong>and</strong> filling it in. Change your implementation <strong>of</strong>SquareUnitFrames_ResetHealthBar to the following:function SquareUnitFrames_ResetHealthBar(button, unit)local class = select(2, UnitClass(unit)) or “WARRIOR“local classColor = RAID_CLASS_COLORS[class]local alive = not UnitIsDeadOrGhost(unit)if alive thenbutton.healthBar:SetStatusBarColor(classColor.r, iclassColor.g, classColor.b)button.healthBar:SetMinMaxValues(0, UnitHealthMax(unit))button.healthBar:SetValue(UnitHealth(unit))button.dead = falseelsebutton.healthBar:SetStatusBarColor(0.3, 0.3, 0.3)button.healthBar:SetMinMaxValues(0, 1)button.healthBar:SetValue(1)button.dead = trueendendThe first two lines are the same, but then you use the UnitIsDeadOrGhostfunction to (shockingly) check to see if the unit is either dead or a ghost. Youthen either color the status bar based on the class color, or change it to grey<strong>and</strong> fill it in. You also set a flag on the unit button that you’ll use in the eventh<strong>and</strong>ler to indicate whether the status bar is currently showing the player asdead or alive.Change the UNIT_HEALTH <strong>and</strong> UNIT_MAXHEALTH portion <strong>of</strong> the event h<strong>and</strong>lerto the following:if event == “UNIT_MAXHEALTH“ thenif self.unit.dead ~= UnitIsDeadOrGhost(unit) thenSquareUnitFrames_ResetUnitButton(self.unit, unit)

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

Saved successfully!

Ooh no, something went wrong!