View Single Post
10-03-18, 11:05 PM   #2
kurapica.igas
A Chromatic Dragonspawn
Join Date: Aug 2011
Posts: 152
I modify the code with my lib, if I use thread to call the myOnTooltipSetItem and make it wait until next OnUpdate, I get the require material and level texts.

So those text aren't generated together, we need a little delay to get all the result.

Lua Code:
  1. Scorpio "Test" ""
  2.  
  3. tt_frame = tt_frame or CreateFrame("GameTooltip", "MuffinItemCacheTooltip", UIParent, "GameTooltipTemplate")
  4.  
  5. __Async__()  -- mark the function as thread
  6. function myOnTooltipSetItem(self, arg1, arg2, arg3)
  7.     Next()  -- wait for the next OnUpdate
  8.    
  9.     print("myOnTooltipSetItem", arg1, arg2, arg3)
  10.     local item_name, item_link = self:GetItem()
  11.  
  12.     if(not item_link) then
  13.         print("no item link, returning", item_name, item_link);
  14.         return;
  15.     end;
  16.  
  17.     local item_id = tonumber(string.match(item_link, "item:([%d]+):"))
  18.     local printable = gsub(item_link, "\124", "\124\124");
  19.     print(item_name, item_link, printable,  item_id)
  20.  
  21.     local tt = {}
  22.  
  23.     for i=1,tt_frame:NumLines() do
  24.         local textLeft =  _G["MuffinItemCacheTooltipTextLeft"..i]:GetText()
  25.         local textRight = _G["MuffinItemCacheTooltipTextRight"..i]:GetText()
  26.         table.insert(tt, textLeft)
  27.         table.insert(tt, textRight)
  28.     end
  29.  
  30.     self:Hide();
  31.  
  32.     print("item id:", "   ", item_id, table.concat(tt," "))
  33.  
  34.  
  35. end
  36. tt_frame:SetScript("OnTooltipSetItem", myOnTooltipSetItem)
  37.  
  38. function TestTT(p_item_id)
  39.    print("----------------")
  40.    tt_frame:SetOwner(UIParent,"ANCHOR_NONE")
  41.    tt_frame:SetItemByID(p_item_id)
  42.  
  43. end
  44.  
  45. TestTT(49112)

You may use the C_Timer.After to do the trick.
  Reply With Quote