Thread Tools Display Modes
01-20-10, 04:09 AM   #1
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
class coloring text help

Code:
Text:SetText(floor(GetFramerate()).." |cfffffffffps || |r"..select(3, GetNetStats()).." |cffffffffms|r")
I want ms and fps to be class colored. can anyone help pls. thx
  Reply With Quote
01-20-10, 04:27 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
This page may help you http://www.wowwiki.com/Class_colors. Looks like there is a global table containing all the colors.
__________________
  Reply With Quote
01-20-10, 04:38 AM   #3
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
i know how to make borders and things that use class colored::
blah:Set...Color(r,g,b,a)

but not text or specific parts of the text
  Reply With Quote
01-20-10, 04:59 AM   #4
Bruners
A Flamescale Wyrmkin
 
Bruners's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 125
what you are looking for is string.format

SetText(string.format("|cffffffffFPS|r %d || |cffffffffMS|r %d", fpsfunc, msfunc))


http://lua-users.org/wiki/StringLibraryTutorial
  Reply With Quote
01-20-10, 05:08 AM   #5
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by alimjocox View Post
i know how to make borders and things that use class colored::
blah:Set...Color(r,g,b,a)

but not text or specific parts of the text

I believe what you're looking for is the proper way to use the " |c " and the " |r " right? I don't know the correct terminology but here goes.

Here's an example(For direct string usage):

"|cff00ff00TEXT|r"

So what is happening here is we have just like in HTML or BBC you have beginning and ending tags to show where the color is placed. The first "ff" I BELIEVE is intensity? I have no idea tbh, and the next 6 numbers/letters are the hex equivalent of the color you're wanting.

Now how do we make it the color of your character?

Since there isn't a hex color relationship from the RAID_CLASS_COLORS * from my crap knowledge * you can set a table to represent each class with the color corresponding:

Code:
local classColor = { 
SHAMAN 		= "2459FF", 
MAGE 		= "69CCF0",
WARLOCK 	= "9482C9",
HUNTER		= "ABD473",
ROGUE		= "FFF569",
PRIEST		= "FFFFFF",
DRUID 		= "FF7D0A",
DEATHKNIGHT = "C41F3B",
WARRIOR 	= "C79C6E",
PALADIN 	= "F58CBA",
}
From here we have a nice footing to make a "plugin" to our texts.

To ensure the name of our class is exact to the table, we want to avoid using the localized name of the class:

Code:
local _, pClass = UnitClass("player")
The variable pClass will now give whichever character you're on the value of your unlocalized class.

Now for the text:

Code:
string = "|cff"..classColor[pClass].."TEXT|r"
This text will now always be corresponding to your player's class color.

So looking at your code here:
Code:
Text:SetText(floor(GetFramerate()).." |cff"..classColor[pClass].."fps || |r"..select(3, GetNetStats()).." |cff"..classColor[pClass].."ms|r")
Now I'm not actually 100% sure this will work for a SetText function as there is a "SetTextColor(r,g,b,a)" which you could use a completely different function to set their colors according to class.

...but I think I got what you were looking for?

Last edited by suicidalkatt : 01-20-10 at 05:16 AM.
  Reply With Quote
01-20-10, 05:16 AM   #6
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
thx alot !! that works perfectly. and thank you very much for the explanation really appreciate it.
  Reply With Quote
01-20-10, 05:22 AM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
Well it looks like you have the right format but maybe something not quite right if it isn't working. Also though there is http://www.wowwiki.com/API_FontInstance_SetTextColor which you can use to color a full fontinstance object.

For text portions though this is what I use in my TOCs.

|cffeda55fYourTextGoesHere|r

It might be that the || in between the |c and |r in your code may be messing it up somewhat.

D'oh, beaten by Katt rofl.
__________________
  Reply With Quote
01-20-10, 05:38 AM   #8
Bruners
A Flamescale Wyrmkin
 
Bruners's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 125
Spoon feeding

Code:
SetText(string.format("%d |cff%02x%02x%02xfps|r ||| %d |cff%02x%02x%02xms|r", floor(GetFramerate()), RAID_CLASS_COLORS[select(2, UnitClass("player"))].r*255, RAID_CLASS_COLORS[select(2, UnitClass("player"))].g*255, RAID_CLASS_COLORS[select(2, UnitClass("player"))].b*255, select(3, GetNetStats()), RAID_CLASS_COLORS[select(2, UnitClass("player"))].r*255, RAID_CLASS_COLORS[select(2, UnitClass("player"))].g*255, RAID_CLASS_COLORS[select(2, UnitClass("player"))].b*255))
  Reply With Quote
01-20-10, 07:36 AM   #9
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Bruners View Post
Spoon feeding

Code:
SetText(string.format("%d |cff%02x%02x%02xfps|r ||| %d |cff%02x%02x%02xms|r", floor(GetFramerate()), RAID_CLASS_COLORS[select(2, UnitClass("player"))].r*255, RAID_CLASS_COLORS[select(2, UnitClass("player"))].g*255, RAID_CLASS_COLORS[select(2, UnitClass("player"))].b*255, select(3, GetNetStats()), RAID_CLASS_COLORS[select(2, UnitClass("player"))].r*255, RAID_CLASS_COLORS[select(2, UnitClass("player"))].g*255, RAID_CLASS_COLORS[select(2, UnitClass("player"))].b*255))
Lol.. excessive much.
  Reply With Quote
01-20-10, 08:19 AM   #10
Bruners
A Flamescale Wyrmkin
 
Bruners's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 125
Originally Posted by suicidalkatt View Post
Lol.. excessive much.

well its not that much now is it?

Code:
local _, player = UnitClass("player")
local colors = RAID_CLASS_COLORS
local r, g, b = colors[player].r*255, colors[player].g*255, colors[player].b*255
local string = "%d |cff%02x%02x%02xfps|r ||| %d |cff%02x%02x%02xms|r"
local fps = GetFramerate()
local ms = select(3, GetNetStats())
text:SetText(string.format(string, fps, r, g, b, ms, r, g, b))
And he can easily expand it or use the same variables elsewhere

Last edited by Bruners : 01-20-10 at 08:22 AM.
  Reply With Quote
01-20-10, 08:25 AM   #11
suicidalkatt
A Rage Talon Dragon Guard
 
suicidalkatt's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 331
Originally Posted by Bruners View Post
well its not that much now is it?

Code:
local _, player = UnitClass("player")
local colors = RAID_CLASS_COLORS
local r, g, b = colors[player].r*255, colors[player].g*255, colors[player].b*255
local string = "%d |cff%02x%02x%02xfps|r ||| %d |cff%02x%02x%02xms|r"
local fps = GetFramerate()
local ms = select(3, GetNetStats())
text:SetText(string.format(string, fps, r, g, b, ms, r, g, b))
And he can easily expand it or use the same variables elsewhere
That's better :3
  Reply With Quote
01-21-10, 10:34 AM   #12
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
thx for the replys guys.. please dont delte ur posts very helpful for an overall understand
  Reply With Quote
01-25-10, 02:00 AM   #13
alimjocox
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Oct 2009
Posts: 96
any reason why using the string.format that Bruners gave me isn't updating. When I first log on lets say I get 43 fps - 200ms. that will never change unless I /reloadui but then again it picks up the first readings and not change
  Reply With Quote
01-26-10, 05:02 PM   #14
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Bruners View Post
well its not that much now is it?

Code:
local _, player = UnitClass("player")
local colors = RAID_CLASS_COLORS
local r, g, b = colors[player].r*255, colors[player].g*255, colors[player].b*255
local string = "%d |cff%02x%02x%02xfps|r ||| %d |cff%02x%02x%02xms|r"
local fps = GetFramerate()
local ms = select(3, GetNetStats())
text:SetText(string.format(string, fps, r, g, b, ms, r, g, b))
And he can easily expand it or use the same variables elsewhere
Even though it technically would work, you're replacing the global string table with a local string value. It still works because the string library is set as the string's metatable.

There's also a new method that can be used, fontstring:SetFormattedText(formatstring,arg1,...)
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
01-26-10, 05:03 PM   #15
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by alimjocox View Post
any reason why using the string.format that Bruners gave me isn't updating. When I first log on lets say I get 43 fps - 200ms. that will never change unless I /reloadui but then again it picks up the first readings and not change
You need to keep running the code at regular intervals to keep updating it, preferably putting it in an OnUpdate script.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » class coloring text help

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