View Single Post
10-03-12, 04:30 PM   #26
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
You both missed the last argument of the ClassIcons' PostUpdate function, which tells you whether the number of bars changed. Here is what I use for reference:

Register the element:
lua Code:
  1. local AddClassPowerIcons = function(self, width, height, spacing)
  2.     self.ClassIcons = {}
  3.  
  4.     self.ClassIcons.width  = width
  5.     self.ClassIcons.height = height
  6.     self.ClassIcons.spacing = spacing
  7.  
  8.     local maxPower = 5
  9.  
  10.     for i = 1, maxPower do
  11.         self.ClassIcons[i] = self.Overlay:CreateTexture("oUF_Rain_ComboPoint_"..i, "OVERLAY")
  12.         self.ClassIcons[i]:SetSize((width - spacing * (maxPower - 1)) / maxPower, height)
  13.         self.ClassIcons[i]:SetPoint("BOTTOMLEFT", self.Overlay, (i - 1) * self.ClassIcons[i]:GetWidth() + i * spacing, 1)
  14.         self.ClassIcons[i]:SetTexture(ns.media.TEXTURE)
  15.     end
  16.  
  17.     self.ClassIcons.PostUpdate = ns.PostUpdateClassPowerIcons
  18. end
  19. ns.AddClassPowerIcons = AddClassPowerIcons

The PostUpdate function:
lua Code:
  1. local PostUpdateClassPowerIcons = function(element, power, maxPower, maxPowerChanged)
  2.     if (not maxPowerChanged) then return end
  3.  
  4.     local self = element.__owner
  5.     local width = element.width
  6.     local height = element.height
  7.     local spacing = element.spacing
  8.  
  9.     for i = 1, maxPower do
  10.         element[i]:SetSize((width - spacing * (maxPower - 1)) / maxPower, height)
  11.         element[i]:SetPoint("BOTTOMLEFT", self.Overlay, (i - 1) * element[i]:GetWidth() + i * spacing, 1)
  12.     end
  13. end
  14. ns.PostUpdateClassPowerIcons = PostUpdateClassPowerIcons

Add the element to the frame appropriate unit frames:
lua Code:
  1. if (playerClass == "DEATHKNIGHT") then
  2.     ns.AddRuneBar(self, 215, 5, 1)
  3.     ns.AddTotems(self, 60, 5)
  4. elseif (playerClass == "DRUID") then
  5.     ns.AddEclipseBar(self, 230, 7)
  6.     ns.AddTotems(self, 30, 5)
  7. elseif (playerClass == "HUNTER") then
  8.     ns.AddFocusHelper(self)
  9. elseif (playerClass == "MONK") then
  10.     ns.AddClassPowerIcons(self, 215, 5, 1)
  11. elseif (playerClass == "PALADIN") then
  12.     ns.AddClassPowerIcons(self, 215, 5, 1)
  13. elseif (playerClass == "PRIEST") then
  14.     ns.AddClassPowerIcons(self, 215, 5, 1)
  15. elseif (playerClass == "SHAMAN") then
  16.     ns.AddTotems(self, nil, 5)
  17. elseif (playerClass == "WARLOCK") then
  18.     ns.AddWarlockPowerBar(self, 215, 5, 1)
  19. end

Apart from that, adding combo points only for druid and rogue is a bad idea, as other classes can use them too when in vehicle (Aces High! comes to mind)

EDIT: Ouch, Phanx got it right of course, I kind of have the annoying habit of reading too fast and thinking to slow. I don't think the call to ForceUpdate is needed, as oUF does this for you when it sets up the unit frame. But I would trust Phanx more than me, so you'd better check.

Last edited by Rainrider : 10-03-12 at 04:36 PM.
  Reply With Quote