Quantcast
GameTooltip:GetItem() empty name and link - WoWInterface
Thread Tools Display Modes
08-23-15, 03:34 AM   #1
evilbib
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Jun 2010
Posts: 30
GameTooltip:GetItem() empty name and link

Hey there,

so some tooltips return empty values (name = "" and link = []) if you use GameTooltip:GetItem(), for example tooltips from the QuestFrame and I believe the TradeSkillFrame.
My interface has item quality border coloring for tooltips but obviously not for said tooltips.

Lua Code:
  1. GameTooltip:HookScript('OnTooltipSetItem', function(self)
  2.     local name, item = self:GetItem()
  3.     if (item) then
  4.         local quality = select(3, GetItemInfo(item))
  5.         if (quality) then
  6.             local r, g, b = GetItemQualityColor(quality)
  7.             self:SetBeautyBorderTexture('white')
  8.             self:SetBeautyBorderColor(r, g, b)
  9.         else
  10.             self:SetBeautyBorderTexture('white')
  11.             self:SetBeautyBorderColor(1, 1, 1)
  12.         end
  13.     end
  14. end)

I tried it with this function (this probably works only for quest items though)
Lua Code:
  1. name, texture, numItems, quality, isUsable = GetQuestItemInfo("type", index)
but the problem is that I have no idea how to get the index from the item I hover over.
Anyone has an idea how to approach this?

update:
The are six QuestProgressItem buttons according to the QuestFrame.xml, so I just hooked them all.
No idea if this is a good way to do this but it seems to be working.
Lua Code:
  1. for i = 1, 6 do
  2.     local questprog = _G['QuestProgressItem'..i]
  3.     questprog:HookScript('OnEnter', function(self)
  4.         local ID = self:GetID()
  5.         local questitemtype = self.type
  6.         local link = GetQuestItemLink(questitemtype, ID)
  7.         if (link) then
  8.             local quality = select(3, GetItemInfo(link))
  9.             if (quality) then
  10.                 local r, g, b = GetItemQualityColor(quality)
  11.                 GameTooltip:SetBeautyBorderTexture('white')
  12.                 GameTooltip:SetBeautyBorderColor(r, g, b)
  13.             end
  14.         end
  15.     end)
  16. end

update2:
and here for the TradeSkillFrame
Lua Code:
  1. if (not TradeSkillFrame) then
  2.     LoadAddOn('Blizzard_TradeSkillUI')
  3. end
  4. for i = 1, 8 do
  5.     local tsr = _G['TradeSkillReagent'..i]
  6.     tsr:HookScript('OnEnter', function(self)
  7.         local ID = self:GetID()
  8.         local skillindex = TradeSkillFrame.selectedSkill
  9.         local link = GetTradeSkillReagentItemLink(skillindex, ID)
  10.         if (link) then
  11.             local quality = select(3, GetItemInfo(link))
  12.             if (quality) then
  13.                 local r, g, b = GetItemQualityColor(quality)
  14.                 GameTooltip:SetBeautyBorderTexture('white')
  15.                 GameTooltip:SetBeautyBorderColor(r, g, b)
  16.             end
  17.         end
  18.     end)
  19. end
  20. hooksecurefunc('TradeSkillItem_OnEnter', function(self)
  21.     local link = GetTradeSkillItemLink(TradeSkillFrame.selectedSkill)
  22.     if (link) then
  23.         local quality = select(3, GetItemInfo(link))
  24.         if (quality) then
  25.             local r, g, b = GetItemQualityColor(quality)
  26.             GameTooltip:SetBeautyBorderTexture('white')
  27.             GameTooltip:SetBeautyBorderColor(r, g, b)
  28.         end
  29.     end
  30. end)

But still I wonder if this is a good way to do it.

Last edited by evilbib : 08-23-15 at 04:28 AM.
  Reply With Quote
08-24-15, 07:40 AM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by pingumania View Post
and here for the TradeSkillFrame
Lua Code:
  1. if (not TradeSkillFrame) then
  2.     LoadAddOn('Blizzard_TradeSkillUI')
  3. end
  4. -- stuff happens here
But still I wonder if this is a good way to do it.
That isn't; you should avoid forcibly loading any Blizzard addons, as they're not designed to handle that and you may cause other problems. A better way:

Code:
local function setupTradeSkillUI()
   -- stuff happens here
end
if TradeSkillFrame then
   setupTradeSkillUI()
else
   local f = CreateFrame("Frame")
   f:RegisterEvent("ADDON_LOADED")
   f:SetScript("OnEvent", function(f, event, name)
      if name == "Blizzard_TradeSkillUI" then
         setupTradeSkillUI()
      end
   end)
end
If you end up needing to wait for multiple addons to load, you can do it all from one frame:
Code:
local setupFuncs = {}

-- Blizzard_TradeSkillUI
tinsert(setupFuncs, function()
   if not TradeSkillFrame then
      return true
   end
   -- do your stuff here
end)

-- Some other addon
tinsert(setupFuncs, function()
   if not MagicalUnicornsFrame then
      return true
   end
   -- do stuff with MagicalUnicornsFrame and/or the addon that created it
end)

local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:SetScript("OnEvent", function()
   for i = #setupFuncs, 1, -1 do
      local tryAgain = setupFuncs[i]()
      -- If it returned true, keep it and try again on the next event,
      -- otherwise it's done, so remove it from the table.
      if not tryAgain then
         tremove(setupFuncs, i)
         -- ^ Removing entries as we go is why we're looping backwards.
      end
   end
end)
I use this tactic in a few personal addons (border, general mods, etc.). The reason for using a simple list (indexed table) instead of using addon names as table keys is that not all addons are ready to hook/modify as soon as they load. Depending on what addons you're waiting for, you may need to listen for additional events to detect when they're ready to do stuff with.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
08-24-15, 01:48 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 1,991
If your addon isn't doing anything until Blizzard_TradeSkillUI loads, then you should use the LoadWith tag in your TOC to tell the game to load your addon when Blizzard_TradeSkillUI does.

Code:
## LoadWith: Blizzard_TradeskillUI
__________________
ESOUI AddOns | WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
08-24-15, 07:17 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Based on the rest of the first post it appears to be a general tooltip modification, so it's handling all tooltips, not just ones coming from the tradeskill UI.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Donít message me about addon bugs or programming questions.
  Reply With Quote
08-26-15, 06:59 AM   #5
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Not fixed on PTR, so I'm looking at implementing workarounds for this, too. Not sure if it's better, but I'm leaning towards hooking the tooltip functions instead. (GameTooltip:SetQuestItem) Then you don't need to bother with waiting for addons to load, and it should be compatible with addons that replace the default quest frame.
__________________
Grab your sword and fight the Horde!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » GameTooltip:GetItem() empty name and link

Thread Tools
Display Modes

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