Reply
 
Thread Tools Display Modes
Old 05-26-11, 01:06 PM   #1
Sauerkraut
A Cyclonian
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 46
Need help coloring "widget"

I've started playing around with a new layout and I've gotten most things working, however there is a small arrow that I am using to indicate power on the power bar. I've included an image since it is a little hard to explain


I'm currently using the follow to color it

Code:
  oUF.colors.power['MANA'] = {0.0, 0.56, 1.0}
  oUF.colors.power['RAGE'] = {1.0,0,0}
  oUF.colors.power['FOCUS'] = {1.0,0.75,0.25}
  oUF.colors.power['ENERGY'] = {1.0, 0.9, 0.35}
  oUF.colors.power['RUNIC_POWER'] = {0.44,0.44,0.44}
  local _, pType = UnitPowerType("player")
  local pcolor = oUF.colors.power[pType] or {.3,.45,.65}
Code:
	s.arrow:SetVertexColor(unpack(pcolor))
It works most of the time but others I need to do a /rl to have it pick up the proper color. Also if I am on a druid and I shapeshift to a different form it doesn't update. I'm sure I'm just missing some thing but I'm not sure how to go about making it update. Any help would be appreciated.
Sauerkraut is offline   Reply With Quote
Old 05-26-11, 01:55 PM   #2
Rainrider
A Rage Talon Dragon Guard
Join Date: Nov 2008
Posts: 314
How did you created the arror? (is it a texture, what is its parent frame and what events are registered to the frame?)

You have 2 options: creating an element as an oUF module and registering the proper events so it updates correctly, or just do it directly in the layout. This is what I currently use for threat, maybe it helps you a bit

create the element and expose it to the namespace
lua Code:
  1. local AddThreatHighlight = function(self, event, unit)
  2.     if (unit ~= self.unit) then return end
  3.  
  4.     local status = UnitThreatSituation(unit)
  5.     if (status and status > 0) then
  6.         local r, g, b = GetThreatStatusColor(status)
  7.    
  8.         self.FrameBackdrop:SetBackdropBorderColor(r, g, b)
  9.     else
  10.         self.FrameBackdrop:SetBackdropBorderColor(0, 0, 0)
  11.     end
  12. end
  13. ns.AddThreatHighlight = AddThreatHighlight

enable it for the frame:
lua Code:
  1. self:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", ns.AddThreatHighlight)

I'm unsure if an element as a module has any benefits.

And if you plan to release your layout, you should use metatables for the colors and not overwrite the oUF dafault table, in case a user wants to use a diffenrent layout for say raid frames or so.
lua Code:
  1. ns.colors = setmetatable({
  2.     power = setmetatable({
  3.         ['MANA'] = {0.0, 0.56, 1.0},
  4.         ['RAGE'] = {1.0,0,0},
  5.         ['FOCUS'] = {1.0,0.75,0.25},
  6.         ['ENERGY'] = {1.0, 0.9, 0.35},
  7.         ['RUNIC_POWER'] = {0.44,0.44,0.44},
  8.     }, {__index = oUF.colors.power}),
  9. }, {__index = oUF.colors})

Last edited by Rainrider : 05-26-11 at 02:01 PM.
Rainrider is offline   Reply With Quote
Old 05-26-11, 02:43 PM   #3
Sauerkraut
A Cyclonian
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 46
The arrow is a texture spawned on the power bar frame.

Code:
		s.arrow = s:CreateTexture(nil, "OVERLAY")
		s.arrow:SetTexture([[Interface\Addons\oUF_Fail\media\textureArrow]])
		s.arrow:SetSize(16,16)
		s.arrow:SetPoint("BOTTOM", s:GetStatusBarTexture(), "RIGHT", 0, 7)
		s.arrow:SetVertexColor(unpack(pcolor))
		fixTex(s.arrow)
Thanks for the code i'll see if I can figure out how or if it will work.
Sauerkraut is offline   Reply With Quote
Old 05-27-11, 03:07 AM   #4
Rainrider
A Rage Talon Dragon Guard
Join Date: Nov 2008
Posts: 314
You could probably just use PostUpdate for the power element to change the color of the arrow.
Rainrider is offline   Reply With Quote
Old 05-27-11, 09:58 AM   #5
Sauerkraut
A Cyclonian
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 46
I'm stumped. I'm sure I am doing something stupid but I can't figure it out. I found and example of a similar postupdate in Dawn's oUF_Nivea but I can't get it to work.

Code:
local PostUpdatePower = function(f, event, unit, Power)

	local _, ptype = UnitPowerType("player")
        if(oUF.colors.power[ptype]) then
		r, g, b = unpack(oUF.colors.power[ptype])
	end

	f:SetVertexColor(r, g, b)

end
NM I figured it out. Thanks for the help.

Last edited by Sauerkraut : 05-27-11 at 10:29 AM.
Sauerkraut is offline   Reply With Quote
Old 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,314
@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.
| Roth UI | Roth UI FAQ | GoogleCode | Zork | TDMOG

"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.
zork is offline   Reply With Quote
Reply

Go BackWoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Need help coloring "widget"

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off