1. #1

    Displaying item level below the item title

    Hi,

    I have the following code that displays the item level of any item (weapon, armor, reagents, objects etc.).

    Code:
    local function Add_Item_Level(tooltip)
    	local item = tooltip:GetItem()
    	local itemLevel = select(4, GetItemInfo(item))
    	
    	tooltip:AddLine("Item Level "..itemLevel)
    end
    
    GameTooltip:HookScript("OnTooltipSetItem", Add_Item_Level)

    This code displays the item level at the bottom of the item tooltip. Is there a way to display it just below the item title (like how it is displayed on weapon and armor)? Basically, it will check

    if the item is weapon or armor
    > don't do anything
    else
    > display the item level below the item title.

    Thanks.
    Last edited by Eommus; 2017-05-06 at 06:09 PM.

  2. #2
    Use AppendText with a \n instead of AddLine. AppendText adds text to the first line of the tooltip and the \n forces what you add into the second line.

    tooltip:AppendText("\nItem Level "..itemLevel)
    Originally Posted by Zarhym (Blue Tracker)
    this thread is a waste of internet

  3. #3
    I am Murloc! Phookah's Avatar
    10+ Year Old Account
    Join Date
    Mar 2012
    Location
    Zebes, SR-21
    Posts
    5,886
    I don't understand why you need a code to see ilevels? It's in game, unless I'm missing something.

  4. #4
    Deleted
    Quote Originally Posted by Phookah View Post
    I don't understand why you need a code to see ilevels? It's in game, unless I'm missing something.
    Some people want to make sure they got the purest Chaos Crystals on the AH.

  5. #5
    Quote Originally Posted by Phookah View Post
    I don't understand why you need a code to see ilevels? It's in game, unless I'm missing something.
    As I mentioned in my post, I want to display the item level on any item. The game displays only on armor and weapon type of items.

    Why I need to display the item level on items that are not armor or weapon? I am a certain type of collector (the details of which are not relevant here), who likes to sort his collection by item levels.

    Quote Originally Posted by Kanegasi View Post
    Use AppendText with a \n instead of AddLine. AppendText adds text to the first line of the tooltip and the \n forces what you add into the second line.

    tooltip:AppendText("\nItem Level "..itemLevel)
    Thanks to your tip, I was able to achieve what I want using the following (also added color):

    Code:
    local function Add_Item_Level(tooltip)
    	local item = tooltip:GetItem()
    	local itemLevel = select(4, GetItemInfo(item))
    	local itemType = select(6, GetItemInfo(item))
    
    	if itemType ~= "Armor" and itemType ~= "Weapon" then
    		tooltip:AppendText("\n|cffffd100Item Level "..itemLevel)
    	end
    end
    
    GameTooltip:HookScript("OnTooltipSetItem", Add_Item_Level)

    I just need to make that text's font size 1 or 2 points smaller. How can I do that?

    Thank you very much.
    Last edited by Eommus; 2017-05-07 at 06:44 AM.

  6. #6
    Quote Originally Posted by Eommus View Post
    Thanks to your tip, I was able to achieve what I want using the following (also added color):

    Code:
    local function Add_Item_Level(tooltip)
    	local item = tooltip:GetItem()
    	local itemLevel = select(4, GetItemInfo(item))
    	local itemType = select(6, GetItemInfo(item))
    
    	if itemType ~= "Armor" and itemType ~= "Weapon" then
    		tooltip:AppendText("\n|cffffd100Item Level "..itemLevel)
    	end
    end
    
    GameTooltip:HookScript("OnTooltipSetItem", Add_Item_Level)

    I just need to make that text's font size 1 or 2 points smaller. How can I do that?

    Thank you very much.
    Unfortunately, there's no in-string way to change the size of text. That item level is the same part of the item's name FontString (line 1 of the tooltip) and changing its size will change the name's size. There may be a complicated way where you go back to AddLine but keep the AppendText with only the \n, loop through the tooltip to find the line number added, and then manually adjust the FontString anchor and offset to rest in the blank space provided by the \n. It's similar to how I add the number of times completed line in the paragon tooltip in my ExaltedPlus addon, since there's no way to just add the line after the item.
    Originally Posted by Zarhym (Blue Tracker)
    this thread is a waste of internet

  7. #7
    Quote Originally Posted by Kanegasi View Post
    Unfortunately, there's no in-string way to change the size of text. That item level is the same part of the item's name FontString (line 1 of the tooltip) and changing its size will change the name's size.
    I see. It's still nice its color can be changed as I did. So, I understand there's no way to "insert" a line after, say, 1st line of the tooltip. Still curious about how the game displays the item level line on armor and weapon items.

    Quote Originally Posted by Kanegasi View Post
    There may be a complicated way where you go back to AddLine but keep the AppendText with only the \n, loop through the tooltip to find the line number added, and then manually adjust the FontString anchor and offset to rest in the blank space provided by the \n. It's similar to how I add the number of times completed line in the paragon tooltip in my ExaltedPlus addon, since there's no way to just add the line after the item.
    I also checked your addon code but couldn't understand what you meant.
    Last edited by Eommus; 2017-05-07 at 03:41 PM.

  8. #8
    Quote Originally Posted by Eommus View Post
    I see. It's still nice its color can be changed as I did. So, I understand there's no way to "insert" a line after, say, 1st line of the tooltip. Still curious about how the game displays the item level line on armor and weapon items.
    From what I understand, the function that decides what to display in an item tooltip is the inherited frame function GameTooltip:SetItemByID(id), which I haven't looked into and could be internal C/C++/basic C code since searching for that in the UI code doesn't reveal a declaration.


    Quote Originally Posted by Eommus View Post
    I also checked your addon code but couldn't understand what you meant.
    Here's the function in question.

    Code:
    hooksecurefunc('EmbeddedItemTooltip_SetItemByQuestReward',function(t) update()
    	if t==rpt.ItemTooltip and rpt.factionID and f[rpt.factionID] and f[rpt.factionID].c then
    		local c=format(ARCHAEOLOGY_COMPLETION,f[rpt.factionID].c)
    		rpt:AddLine(c) t.Tooltip:AddLine('\n') t.Tooltip:Show()
    		for i=1,rpt:NumLines() do if _G[rpt:GetName()..'TextLeft'..i]:GetText()==c then
    			_G[rpt:GetName()..'TextLeft'..i]:SetPoint('BOTTOMLEFT',0,-70)
    		end end
    	end
    end)

    Boiling that down to just the tooltip interaction. Also note that the paragon tooltip is a special double tooltip, with the faction description and rep bar in the main part and the reward item a tooltip-within-a-tooltip. Screenshot of the tooltip. I add a blank line to the itemtooltip and then manually move an added line in the maintooltip down to that new space. I can't directly add a line to the itemtooltip since the text is indented due to the item icon. In the screenshot, the "number of times completed" line is actually supposed to be directly under "rewards".

    Code:
    local text="text"
    maintooltip:AddLine(c)
    itemtooltip:AddLine('\n')
    itemtooltip:Show() -- refreshes the tooltip to show the new line
    for i=1,maintooltip:NumLines() do -- loops through maintooltip lines
    	if _G[maintooltip:GetName()..'TextLeft'..i]:GetText()==text then -- gets the text of each line and looks for "text"
    		_G[maintooltip:GetName()..'TextLeft'..i]:SetPoint('BOTTOMLEFT',0,-70) -- changes anchor and moves 70 units down
    	end
    end
    Originally Posted by Zarhym (Blue Tracker)
    this thread is a waste of internet

  9. #9
    Thanks.

    Thinking again, I decided to display it like this:

    Code:
    tooltip:AppendText(" |cffffd100("..itemLevel..")")

    So, it will display the item level without adding an extra line. Ex:

    Iron Ore (30)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •