Thread Tools Display Modes
01-18-23, 05:57 AM   #1
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 321
Get tooltip of recipes creating an item that teaches you something

Since OnTooltipSetItem does no longer exist, we have to use TooltipDataProcessor.AddTooltipPostCall.

I am running into the following problem, when trying to read the tooltip of recipes that are themselves creating items which that teach you something (e.g. https://www.wowhead.com/item=67308).
With AddTooltipPostCall I only get the tooltip of the usable item which the recipe creates, but not of the recipe itself.

To reproduce, use this code and mouse-hover over the created frame to show the tooltip:

Lua Code:
  1. TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(self)
  2.  
  3.   local name, link = TooltipUtil.GetDisplayedItem(self)
  4.   print(name, link)
  5.  
  6.   -- Read the tootip lines.
  7.   local itemId = tonumber(string_match(link, "^.-:(%d+):"))
  8.   local tooltipLines = C_TooltipInfo.GetItemByID(itemId).lines
  9.   local numLines = 1
  10.   while tooltipLines[numLines] do
  11.     print(numLines .. ":", tooltipLines[numLines].args[2].stringVal)
  12.     numLines = numLines + 1
  13.   end
  14.  
  15. end);
  16.  
  17.  
  18.  
  19. -- To test recipe tooltip:
  20. local testframe1 = CreateFrame("Frame", _, UIParent, BackdropTemplateMixin and "BackdropTemplate")
  21. testframe1:SetBackdrop({ bgFile = "Interface/Tooltips/UI-Tooltip-Background",
  22.                       edgeFile = "Interface/DialogFrame/UI-DialogBox-Border",
  23.                       tile = true, tileSize = 16, edgeSize = 16,
  24.                       insets = { left = 4, right = 4, top = 4, bottom = 4 }})
  25. testframe1:SetBackdropColor(0.0, 0.0, 0.0, 1.0)
  26. testframe1:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
  27. testframe1:SetWidth(300)
  28. testframe1:SetHeight(100)
  29. testframe1:SetScript("OnEnter", function()
  30.   GameTooltip:SetOwner(testframe1, "ANCHOR_TOPLEFT")
  31.  
  32.   -- Recipe creating a usable item.
  33.   GameTooltip:SetHyperlink("item:67308:0:0:0:0:0:0:0")
  34.  
  35.   -- Another recipe for which there is no problem:
  36.   -- GameTooltip:SetHyperlink("item:198132:0:0:0:0:0:0:0")
  37.  
  38.   GameTooltip:Show()
  39. end )

Any ideas how to handle this?

When OnTooltipSetItem still existed, we used to get two OnTooltipSetItem when the tooltip was created: one for the recipe and one for the create item.
But now it seems we only get the equivalent of the latter.
__________________
~ Be the change you want to see in the world... of warcraft interface! ~

Last edited by LudiusMaximus : 01-23-23 at 01:31 PM. Reason: typo
  Reply With Quote
01-20-23, 02:21 AM   #2
LudiusMaximus
A Rage Talon Dragon Guard
 
LudiusMaximus's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 321
I solved it myself. Turns out that for recipes, which create usable items, the hyperlink returned by GetItem() does not match the returned id. The hyperlink is of the created item but the id is of the recipe. So when I use the returned id I am good.


Lua Code:
  1. TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(self)
  2.  
  3.   local name, link, idFromTooltip = self:GetItem()
  4.   local idFromLink = tonumber(string_match(link, "^.-:(%d+):"))
  5.  
  6.   if idFromTooltip ~= idFromLink then
  7.     print("This recipe has the id", idFromTooltip, "and creates another teaching item with the id", idFromLink)
  8.    
  9.     print("Tooltip of created item:")
  10.     local tooltipLines = C_TooltipInfo.GetItemByID(idFromLink).lines
  11.     local numLines = 1
  12.     while tooltipLines[numLines] do
  13.       print(numLines .. ":", tooltipLines[numLines].args[2].stringVal)
  14.       numLines = numLines + 1
  15.     end
  16.   end
  17.  
  18.   print("Tooltip of recipe:")
  19.   local tooltipLines = C_TooltipInfo.GetItemByID(idFromTooltip).lines
  20.   local numLines = 1
  21.   while tooltipLines[numLines] do
  22.     print(numLines .. ":", tooltipLines[numLines].args[2].stringVal)
  23.     numLines = numLines + 1
  24.   end
  25.  
  26. end)
__________________
~ Be the change you want to see in the world... of warcraft interface! ~

Last edited by LudiusMaximus : 01-23-23 at 01:31 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Get tooltip of recipes creating a usable item


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