WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   class coloring text help (https://www.wowinterface.com/forums/showthread.php?t=30123)

alimjocox 01-20-10 04:09 AM

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

Xrystal 01-20-10 04:27 AM

This page may help you http://www.wowwiki.com/Class_colors. Looks like there is a global table containing all the colors.

alimjocox 01-20-10 04:38 AM

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 :(

Bruners 01-20-10 04:59 AM

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

suicidalkatt 01-20-10 05:08 AM

Quote:

Originally Posted by alimjocox (Post 175252)
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?

alimjocox 01-20-10 05:16 AM

thx alot !! that works perfectly. and thank you very much for the explanation really appreciate it.

Xrystal 01-20-10 05:22 AM

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.

Bruners 01-20-10 05:38 AM

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))

suicidalkatt 01-20-10 07:36 AM

Quote:

Originally Posted by Bruners (Post 175262)
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.

Bruners 01-20-10 08:19 AM

Quote:

Originally Posted by suicidalkatt (Post 175269)
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

suicidalkatt 01-20-10 08:25 AM

Quote:

Originally Posted by Bruners (Post 175271)
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

alimjocox 01-21-10 10:34 AM

thx for the replys guys.. please dont delte ur posts very helpful for an overall understand :D

alimjocox 01-25-10 02:00 AM

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

SDPhantom 01-26-10 05:02 PM

Quote:

Originally Posted by Bruners (Post 175271)
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,...)

SDPhantom 01-26-10 05:03 PM

Quote:

Originally Posted by alimjocox (Post 175981)
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.


All times are GMT -6. The time now is 05:23 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI