I ran several test cases, if you access the item for the first time(start the game from the client), the require material and skill are query from the server, so wait a phase may not be enough, if you have accessed the item before, wait one phase will get those datas.
So, I re-modify the code like
Lua Code:
Scorpio "Test" ""
tt_frame = tt_frame or CreateFrame("GameTooltip", "MuffinItemCacheTooltip", UIParent, "GameTooltipTemplate")
__Async__() -- mark the function as thread
function myOnTooltipSetItem(self, arg1, arg2, arg3)
self:SetScript("OnTooltipSetItem", nil)
Next() -- wait for the next OnUpdate
print("myOnTooltipSetItem", arg1, arg2, arg3)
local item_name, item_link = self:GetItem()
if(not item_link) then
print("no item link, returning", item_name, item_link);
return;
end;
local item_id = tonumber(string.match(item_link, "item:([%d]+):"))
local printable = gsub(item_link, "\124", "\124\124");
print(item_name, item_link, printable, item_id)
local tt = {}
for i=1,tt_frame:NumLines() do
local textLeft = _G["MuffinItemCacheTooltipTextLeft"..i]:GetText()
local textRight = _G["MuffinItemCacheTooltipTextRight"..i]:GetText()
table.insert(tt, textLeft)
table.insert(tt, textRight)
end
self:Hide();
print("item id:", " ", item_id, table.concat(tt," "))
end
__Async__()
function TestTT(p_item_id)
if not GetItemInfo(p_item_id) then
-- wait 1 sec or the GET_ITEM_INFO_RECEIVED event
local evt, id = Wait(1, "GET_ITEM_INFO_RECEIVED")
if not (evt and id == p_item_id) then
return -- failed to fetch the item data
end
end
print("----------------")
tt_frame:SetOwner(UIParent,"ANCHOR_NONE")
tt_frame:SetScript("OnTooltipSetItem", myOnTooltipSetItem)
tt_frame:SetItemByID(p_item_id)
end
TestTT(49112)
This time I run the TestTT as thread, and use the GetItemInfo to check if we have already cached the item's info, if not, we need wait the GET_ITEM_INFO_RECEIVED system event and check its first argument.
The API Wait I used is suspend the curoutine until the system event is fired or the delay of 1 sec is meet(since I can't make sure whether the item existed).
Then I check if the received item id is the target item, and continue the job.
-------------
I add the widget event handler in TestTT and remove it in the myOnTooltipSetItem, it seems the widget event would be fired several times since I delayed the hide of the gametooltip.