View Single Post
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: 324
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