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.

410 Part III ■ Advanced Addon TechniquesPLAYER_REGEN_ENABLEDThe PLAYER_REGEN_ENABLED event will fire when the player leaves combat, <strong>and</strong>as a result the logic in this section is much the reverse <strong>of</strong> entering combat.You turn the combat flag <strong>of</strong>f, <strong>and</strong> update the total amount <strong>of</strong> combat time bysubtracting the current time from the start time. Next you clear the OnUpdatefunction <strong>and</strong> update the frame, which will show the total stats instead <strong>of</strong> therolling average.<strong>Creating</strong> the Frame DisplayAs an initial example, the display <strong>for</strong> this addon will be series <strong>of</strong> text stringsthat contain the damage <strong>and</strong> healing in<strong>for</strong>mation. Eventually, you’ll want toexp<strong>and</strong> it to use status bars instead <strong>of</strong> text strings. Create your CreateFrames()function:function CombatStatus:CreateFrames()self:ClearAllPoints()self:SetPoint(“TOP“, MinimapCluster, “BOTTOM“, 0, -15)self:SetWidth(300)self:SetHeight(150)self.rows = {}<strong>for</strong> i = 1, 10 dolocal row = self:CreateFontString(nil, “OVERLAY“, i“GameFontHighlight“)row:SetText(“Blah“)self.rows[i] = rowif i == 1 thenrow:SetPoint(“TOPLEFT“, 0 ,0)elserow:SetPoint(“TOPLEFT“, self.rows[i-1], “BOTTOMLEFT“, 0, 0)endendendThe frame is anchored directly below the minimap cluster <strong>and</strong> consists <strong>of</strong> 10different font strings.Updating the Frame DisplayThe actual calculations are accomplished in the UpdateFrame() method. Addthis method to your file anywhere below the TakeSnapshot() method, becauseit uses the units table defined just be<strong>for</strong>e that function.function CombatStatus:UpdateFrame(elapsed)<strong>for</strong> idx, unit in ipairs(units) dolocal row = self.rows[idx]

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

Saved successfully!

Ooh no, something went wrong!