Thread Tools Display Modes
05-01-14, 04:33 PM   #1
Wilcoh
A Defias Bandit
Join Date: Mar 2011
Posts: 2
How do you make name/cast text, class colored?

how would you make the name/cast text, class colored?
  Reply With Quote
05-02-14, 07:36 AM   #2
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Code:
local function ClassColouredName(name)
	if not name then return "|cffcccccc".. UNKNOWN.. "|r" end
	local _, class = UnitClass(name)
	if not class then return "|cffcccccc"..name.."|r" end
	local c = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
	return format("|cff%02x%02x%02x%s|r", c.r * 255, c.g * 255, c.b * 255, name)
end
You don't need to change the input variable name, although you could; once you have the unit's name via UnitName, just pass it to the function above.

To set the text colour, once you have the rgb values above, then use SetTextColour.

Last edited by myrroddin : 05-02-14 at 07:38 AM. Reason: Added setting text colour.
  Reply With Quote
05-02-14, 10:22 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
@myrroddin:
Since Cataclysm the RAID_CLASS_COLORS table for each class has included a preformatted color string, so if you're using them inline in a font string, there's no need to construct your own color string from the r/g/b keys; just use the preformatted one from the "colorStr" key.

@Wilcoh:
I believe this was originally posted in an unrelated thread about LuaTexts, so I assume you to color something using LuaTexts, in which case it would be helpful if you posted whatever LuaTexts strings you're already using, but generally speaking:

Code:
function(unit)
	-- insert whatever code you already have,
	-- but instead of the "return" line, assign the text
	-- to a variable called "text", eg.
	local text = "Hello!"

	if UnitIsPlayer(unit) then
		local _, class = UnitClass(unit)
		local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class].colorStr
		return format("|c%s%s|r", color, text)
	else
		return text
	end
end
If you need more specific help, please post (a) which addon you are using and (b) what LuaTexts strings you are already using.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 05-02-14 at 10:26 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » How do you make name/cast text, class colored?


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