Thread Tools Display Modes
03-21-13, 04:37 AM   #1
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
font color from tooltip

So i would like to know font color from a given tooltip line
cant find anything useful in lua documentation for that

And if its possible, that color would be same for all or could be changed by some addons already?
  Reply With Quote
03-21-13, 02:05 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If the text is colored using inline color codes:

Code:
-- turns "|cffff0000" into 255, 0, 0 for example
local r, g, b = GameTooltipTextLeft1:GetText():match("|cff(%x%x)(%x%x)(%x%x)")
r, g, b = tonumber(r, 16), tonumber(g, 16), tonumber(b, 16)
If it's colored using the SetTextColor API:

Code:
local r, g, b = GameTooltipTextLeft1:GetTextColor()
__________________
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.
  Reply With Quote
03-21-13, 05:40 PM   #3
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
Thanks, maybe i dont need compare strings and can get all i want from color
  Reply With Quote
03-21-13, 05:45 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
When the text is using inline color codes, GetTextColor will still return the default color (usually white), so you still need to use string matching to determine whether there are inline color codes overriding the deafult color.
__________________
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.
  Reply With Quote
03-21-13, 06:23 PM   #5
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
some things i dont get here
basically i want scan dropped item and know if they are thunderforged, elite etc.
that info is in 2nd tooltip line, so knowing that line is green (if item is normal, there is item level in that line written in different color) is better than comparing strings from all languages.

but when i do print(GameTooltipTextLeft2:GetText()) its coming in white, but still got green from GameTooltipTextLeft2:GetTextColor(), well greenish, gets me g 0.99999779462814
when doing it with itemLevel line, print "pass" correct color

well, i wrote something and need wait for debug till wednesday probably
  Reply With Quote
03-21-13, 08:39 PM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
SetTextColor only affects the individual font string object it's called on. The text and the color are not intriniscally connected, so if you take the text from that font string object, and display it on another font string object, or pass it to a function -- like print() -- you only get the text, not the color or alignment or size or any other properties of the original font string object.

If you got a color when print()-ing the item level line, that means that the item level line uses inline color codes (eg. "|cffffd000Item Level: 496|r") which override the text color set on the font object.

Also, based on what you described, you will need to use string matching on the actual text content, as that green text can be "Heroic" -- or it can be "Raid Finder", or it could be something else. Fortunately, you don't need to do any of the work translating the string; you can just use the pre-defined Blizzard global strings. For example:

Code:
if GameTooltipTextLeft2:GetText() == ITEM_HEROIC then
    -- text is "Heroic" in an English client, "Heroisch" in a German client, etc.
end
Finally, the values returned by GetTextColor can be a bit odd. If you need to match them to detect something, you can "fix" them via rounding to the nearest 100th, like so:

Code:
local r, g, b = GameTooltipTextLeft2:GetTextColor()
r = floor(r * 100 + 0.5) / 100
g = floor(g * 100 + 0.5) / 100
g = floor(b * 100 + 0.5) / 100
__________________
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 : 03-21-13 at 08:42 PM.
  Reply With Quote
03-22-13, 03:04 AM   #7
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
thanks fro explanation
i dont mind getting all other green information text, yours idea seems much more elegant tho

have problem with global strings, at http://wow.go-hero.net/framexml/1665...rings.lua/diff nothing about Thunderforged . From where i can get latest build? 16733. Checked ingame and guesses like THUNDERFORGED or ITEM_THUNDERFORGED not working
  Reply With Quote
03-22-13, 03:32 AM   #8
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
yea, found how to export current build via console, but nothing there
  Reply With Quote
03-22-13, 03:38 AM   #9
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Reposted from earlier:
I'm not seeing "Thunderforged" as a constant in the current GlobalStrings.lua
My post got messed up while I was trying to edit it with an explanation on how to extract the UI files, but it seems you stumbled upon that anyway.
__________________
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)

Last edited by SDPhantom : 03-22-13 at 03:40 AM.
  Reply With Quote
03-22-13, 06:03 AM   #10
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Oh, I should have posted a link... you can see the GlobalStrings.lua file for all locales here:
https://github.com/phanx/wow-globalstrings

Unfortunately it looks like there isn't a global string for "Thunderforged". But, I'm fairly certain that all the other possibilities for that line (Heroic, Raid Finder, is there anything else?) do have global strings, so if you see green text in GameTooltipTextLeft2 and it isn't ITEM_HEROIC or RAID_FINDER, then it's probably safe to assume it's "Thunderforged".
__________________
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.
  Reply With Quote
03-22-13, 08:04 AM   #11
Mazzop
A Cliff Giant
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 74
Elite, Heroic Elite, Thunderforged, Heroic Thunderforged are strings interesting me here
i get tooltip from SetLootItem(index), Raid Finder cannot occur, so my scan look like

Lua Code:
  1. if not (LootTooltipTextLeft2:GetText():match(ITEM_LEVEL) or LootTooltipTextLeft2:GetText() == ITEM_HEROIC) then

I crate that tooltip frame with GameTooltipTemplate, so strings there are as before any addons touch them?

i could use just values item levels to determine if weapon/armor is upgraded, but that way, when Blizz add Favored, Blessed or Cinnamon items, i dont need to change a thing
  Reply With Quote
03-23-13, 07:23 PM   #12
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Mazzop View Post
I crate that tooltip frame with GameTooltipTemplate, so strings there are as before any addons touch them?
Correct; addons that modify the GameTooltip frame don't affect other frames that also inherited from the GameTooltipTemplate or have the GameTooltip frame type. (Blizzard's naming choices here are a little silly... it's like creating a Button type frames and naming it "Button" even though there are also hundreds of other Button type frames in the UI.)

If you did want to try item level matching, you can capture it like so:

Code:
-- Construct your pattern once at the top of the file:
local ITEM_LEVEL_PATTERN = "^" .. gsub(ITEM_LEVEL, "%%d", "(%d+)") .. "$"

-- Then use it:
for i = 2, GameTooltip:GetNumLines() do
    local text = _G["GameTooltipTextLeft"..i]:GetText()
    if text then -- it can be nil, which is fine for == checks but will break string.match
        local iLevel = strmatch(text, ITEM_LEVEL_PATTERN)
        if iLevel then
             -- do something here
             break -- stop looking
        end
    end
end
__________________
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.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » font color from tooltip

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