WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   GameTooltip:GetItem() empty name and link (https://www.wowinterface.com/forums/showthread.php?t=52644)

evilbib 08-23-15 03:34 AM

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.

Phanx 08-24-15 07:40 AM

Quote:

Originally Posted by pingumania (Post 310517)
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.

SDPhantom 08-24-15 01:48 PM

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

Phanx 08-24-15 07:17 PM

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.

Lombra 08-26-15 06:59 AM

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.


All times are GMT -6. The time now is 02:41 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI