View Single Post
02/13/23, 01:56 AM   #8
Matoro342
Join Date: Feb 2023
Posts: 9
Here's what I have so far which miraculously solves most of the problems. It is genius that you can just write the name of the function as it would otherwise exist in the code and redefine it. My only issue is the style return from an item link is just a name or number. It's clearly possible from the CharacterKnowledge addon an many others to determine if you have, for example, the nord boots motif, but I am not sure it's possible to do the reverse and go from having nord boots to seeing if you have that motif unlocked. There are a few issues: some motif books just unlock everything at once, which would make those impossible. Clearly, something in the outfit styles collection is already tracking basically everything individually, which I want to access, but don't know how.

Lua Code:
  1. TestAddon = {} -- Initialize addon object
  2. TestAddon.name = "TestAddon" -- Give addon object a reference name
  3.  
  4.  
  5. local function TooltipHook(tooltipControl, method, linkFunc)
  6.     local origMethod = tooltipControl[method] -- Saves the original method (ex. ItemTooltip[SetBagItem])
  7.    
  8.     tooltipControl[method] = function(self, ...) -- We are now going to rewrite the original method
  9.         origMethod(self, ...) -- Let it do what it originally did
  10.         if (GetItemLinkItemType(linkFunc(...)) == ITEMTYPE_ARMOR) or (GetItemLinkItemType(linkFunc(...)) == ITEMTYPE_WEAPON) then -- Check if item is armor or a weapon (visual equipment with styles)
  11.             local style = GetItemLinkItemStyle(linkFunc(...)) -- Get the item style
  12.             self:AddVerticalPadding(20) -- Add some space away from the rest of the tooltip
  13.             self:AddLine(GetItemStyleName(style)) -- Write the style name
  14.         end
  15.     end
  16. end
  17.  
  18. local function HookBagTips() -- We are going to hook functions into the itemtooltips for most kinds that we want to see.
  19.     TooltipHook(ItemTooltip, "SetBagItem", GetItemLink) -- Inventory bags
  20.     TooltipHook(ItemTooltip, "SetTradeItem", GetTradeItemLink) -- Trade screens
  21.     TooltipHook(ItemTooltip, "SetBuybackItem", GetBuybackItemLink)
  22.     TooltipHook(ItemTooltip, "SetStoreItem", GetStoreItemLink) -- Stores, etc.
  23.     TooltipHook(ItemTooltip, "SetAttachedMailItem", GetAttachedItemLink)
  24.     TooltipHook(ItemTooltip, "SetLootItem", GetLootItemLink) -- Loot, you get the idea
  25.     TooltipHook(ItemTooltip, "SetTradingHouseItem", GetTradingHouseSearchResultItemLink)
  26.     TooltipHook(ItemTooltip, "SetTradingHouseListing", GetTradingHouseListingItemLink)
  27.     TooltipHook(ItemTooltip, "SetLink", ReturnItemLink)
  28.  
  29.     TooltipHook(PopupTooltip, "SetLink", ReturnItemLink)
  30. end
  31.  
  32. local function OnAddOnLoaded(event, name)
  33.     if name ~= TestAddon.name then return end -- If it's not our addon loaded, don't run this. Would get errors.
  34.  
  35.     HookBagTips();
  36.     EVENT_MANAGER:UnregisterForEvent(TestAddon.name, event) -- We no longer want this to run as the game loads addons. It only needs to run once.
  37. end
  38.  
  39. EVENT_MANAGER:RegisterForEvent(TestAddon.name, EVENT_ADD_ON_LOADED, OnAddOnLoaded) -- As the game loads, the event manager registers our addon for an event. It takes the name of the addon, and upon the event of loading the addon, it runs the function "OnAddOnLoaded".)
  Reply With Quote