View Single Post
05-27-11, 10:30 AM   #6
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
@Kraut
There are events to track the druid shapeshift.

Your arrow frame needs to hook them and change it's color accordingly.

The unit powertype colors of oUF are initiated on login.

By the time it loads it may be possible that UnitPowerType("player") still returns nil. But not sure about that. I think it should work, at least UnitClass etc. does.

EVENT: UNIT_DISPLAYPOWER
"Fired when the unit's mana stype is changed. Occurs when a druid shapeshifts as well as in certain other cases."
http://wowprogramming.com/docs/events/UNIT_DISPLAYPOWER
Basically...register the event to your arrow frame and then call UnitPowerType player and set the color of the arrow.

I recommend registering PLAYER_LOGIN aswell. By that time the function will be working and you should be able to set the color correctly.

Sth like this should work...

lua Code:
  1. --set color
  2.   lib.setArrowColor = function(self)
  3.     local _, pType = UnitPowerType("player")
  4.     local pcolor = oUF.colors.power[pType] or {.3,.45,.65}
  5.     self.arrow:SetVertexColor(unpack(pcolor))
  6.   end
  7.  
  8.   --hook events  
  9.   self:RegisterEvent("PLAYER_LOGIN", lib.setArrowColor)
  10.   self:RegisterEvent("PLAYER_ENTERING_WORLD", lib.setArrowColor)
  11.   self:RegisterEvent("UNIT_DISPLAYPOWER", lib.setArrowColor)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Btw I found a neat trick for threat coloring (I guess I'm the last one to find out about forceUpdate O_O).
It is awesome because if color is set via self.Health.colorHealth = true then if you don't have aggro the color will stay and the color is updated as soon as any of the events if fired.

lua Code:
  1. --update health func
  2.   lib.updateHealth = function(bar, unit, min, max)
  3.     --color the hp bar in red if the unit has aggro
  4.     if unit and UnitThreatSituation(unit) == 3 then
  5.       bar:SetStatusBarColor(1,0,0)
  6.       if bar.bg then bar.bg:SetVertexColor(1*bar.bg.multiplier,0,0) end
  7.     end  
  8.   end
  9.  
  10.   --check threat
  11.   lib.checkThreat = function(self,event,unit)
  12.     --force an update on the health frame
  13.     self.Health:ForceUpdate()
  14.   end
  15.  
  16.   self.Health.PostUpdate = lib.updateHealth
  17.   self:RegisterEvent("PLAYER_TARGET_CHANGED", lib.checkThreat)
  18.   self:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", lib.checkThreat)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 05-27-11 at 10:43 AM.
  Reply With Quote