View Single Post
11-08-08, 01:43 AM   #223
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by saulhudson View Post
Hi guys

How can I colour the health text value by there health status.

So for say 2890 hp or 30% make the text red. Not the bar colour but the text itself.

I currently basically do this atm.

bar.value:SetText("|cff33EE44"..numberize(cur) .."|r.".. d.."%")

Which is Lyns code giving something like this 5000.50%.

Any help greatlt appreciated.

Originally Posted by Slakah View Post
Stick this at the top of your layout somewhere.

Code:
local function ColourGradient(perc) -- for colouring in
	if perc <= 0.5 then
		return 255, perc*510, 0
	else
		return 510 - perc*510, 255, 0
	end
end
and then replace
Code:
bar.value:SetText("|cff33EE44"..numberize(cur) .."|r.".. d.."%")
with
Code:
bar.value:SetText(string.format("|cff%02x%02x%02x%s|r.%s%%", ColourGradient(min/max), numberize(cur), d)
Hope this helps.

Using :SetText(string.format()) was replaced with :SetFormattedText() a while back.
Also, oUF has its own color gradient function, which can be used instead of creating a new one.


Code:
bar.value:SetFormattedText('|cff%02x%02x%02x%s|r%s.%%', self.ColorGradient(min/max, unpack(self.colors.smooth)), numberize(cur), d)

Last edited by p3lim : 11-08-08 at 01:49 AM.