View Single Post
08-15-15, 12:45 AM   #7
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,325
Since all the code is doing is matching items to set names, the lookup table doesn't need to be so complicated to use. Here's my example. There can be more optimizations depending on how you want the tooltip to look.

Lua Code:
  1. local TransmogSets={
  2.     {
  3.         name="Mystic's Regalia (Recolor)",
  4.         items={14090, 26008, 14094},
  5.     },
  6.     {
  7.         name="Imperial Plate",
  8.         items={31436, 30002, 12424, 12425, 12422, 12427, 12429},
  9.     },
  10. --  And so on ...
  11. };
  12.  
  13. --  Lookup Table
  14. local ItemSetNames={}; do
  15.     for _,set in ipairs(TransmogSets) do--  Scan through all sets
  16.         for _,itemid in ipairs(set.items) do--  Scan through items
  17. --          Add set name to list in lookup table
  18.             if not ItemSetNames[itemid] then ItemSetNames[itemid]={}; end
  19.             table.insert(ItemSetNames[itemid],set.name);
  20.         end
  21.     end
  22.  
  23. --  Sorts set names
  24.     for _,list in pairs(ItemSetNames) do table.sort(list); end
  25. end
  26.  
  27. --  Tooltip Hook
  28. GameTooltip:HookScript("OnTooltipSetItem",function(self)
  29.     local _,link=self:GetItem();
  30.     if not link then return; end--  Exit if we have no item
  31.  
  32.     local id=tonumber(link:match("|Hitem:(%d+)")) or 0;--   Force nil to zero if we have an invalid link (no items exist at index zero)
  33.     if ItemSetNames[id] then
  34.         for i,name in ipairs(ItemSetNames[id]) do
  35. --          Only show our label on the first line
  36.             self:AddDoubleLine(i<=1 and "Transmog Set:" or " ",name);
  37.         end
  38.     end
  39. end);
  40.  
  41. --  Chat Hook
  42. ChatFrame_AddMessageEventFilter("CHAT_MSG_LOOT",function(self,event,msg,...)
  43.     local id=tonumber(msg:match("|Hitem:(%d+)")) or 0;--    Force nil to zero if we have an invalid link (no items exist at index zero)
  44.     if ItemSetNames[id] then return false,msg.." (|cff9400d3Transmog Sets: "..table.concat(ItemSetNames[id],", ").."|r).",...; end
  45. end);

Edit: Replaced string.join() section with more efficient table.concat() call.
__________________
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)

Last edited by SDPhantom : 08-17-15 at 03:15 PM.
  Reply With Quote