Advertisement
Guest User

QualityID.lua

a guest
Nov 30th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. --######################
  2. -- Interface: 40300
  3. -- Title: QualityID
  4. -- Notes: Displays an items basic info in the color of the item's quality, in the tooltip.
  5. -- License: GNUv2GPL
  6. -- Author: Anaral
  7. -- Version: 3.20
  8. --#######################
  9.  
  10. QualityID = {}
  11.  
  12. QIDDB = {
  13. enabled = true;
  14. showid = true;
  15. showitemLvl = true;
  16. showStackCount = true;
  17. showIcon = true;
  18. showType = true;
  19. addTopLine = true;
  20. addBotLine = true;
  21. QualityIDVersion = "3.2";
  22. };
  23.  
  24. QIDDB.enabled = true
  25. QIDDB.showid = true
  26. QIDDB.showitemLvl = true
  27. QIDDB.showStackCount = true
  28. QIDDB.showIcon = true
  29. QIDDB.showitemType = true
  30. QIDDB.addTopLine = true
  31. QIDDB.addBotLine = true
  32. QIDDB.QualityIDVersion = "3.11"
  33.  
  34.  
  35. --Run once when first loaded.
  36.  
  37. QID = CreateFrame("Frame", "QID")
  38. QID:RegisterEvent("ADDON_LOADED")
  39.  
  40. --DEFAULT_CHAT_FRAME:AddMessage("|cff00dd88" .. "QualityID: v."..QIDDB.QualityIDVersion.." enabled! For options type /qid.");
  41.  
  42.  
  43. function QualityID:InitializeDB()
  44. if (not (QIDDB)) then DEFAULT_CHAT_FRAME:AddMessage("Setting up QIDDB.") end
  45. if (not (QIDDB)) then QIDDB = {} end
  46. if (not (QIDDB.enabled)) then QIDDB.enabled = self.enabled end
  47. if (not (QIDDB.showId)) then QIDDB.showId = self.showId end
  48. if (not (QIDDB.showitemLvl)) then QIDDB.showitemLvl = self.showitemLvl end
  49. if (not (QIDDB.showStackCount)) then QIDDB.showStackCount = self.showStackCount end
  50. if (not (QIDDB.showIcon)) then QIDDB.showIcon = self.showIcon end
  51. if (not (QIDDB.showitemType)) then QIDDB.showitemType = self.showitemType end
  52. if (not (QIDDB.addTopLine)) then QIDDB.addTopLine = self.addTopLine end
  53. if (not (QIDDB.addBotLine)) then QIDDB.addBotLine = self.addBotLine end
  54. if (not (QIDDB.QualityIDVersion)) then QIDDB.QualityIDVersion = self.QualityIDVersion end
  55. end
  56.  
  57. function QualityID:OnEvent(event, arg1)
  58. if event == 'ADDON_LOADED' and arg1 == 'QualityID' then
  59. QualityID:InitializeDB();
  60. end
  61. end
  62.  
  63. function chat(text)
  64. if(type(text) == "boolean") then
  65. if(text) then
  66. text = "True";
  67. else
  68. text = "False";
  69. end
  70. end
  71. if(text ~= nil) then
  72. DEFAULT_CHAT_FRAME:AddMessage("|cff00dd88" .. text .. "|r");
  73. end
  74. end
  75. SLASH_QUALITYID1 = "/qualityid"
  76. SLASH_QUALITYID2 = "/qid"
  77. -- SlashCmdList["SLASHCMD"] = function (msg, editBox) end; <--- blizz function for 3.0
  78. SlashCmdList["QUALITYID"] = function(msg)
  79. QualityID_SlashCommandHandler(msg);
  80. end
  81. --slashcommand functions
  82. function QualityID_SlashCommandHandler(msg)
  83. if(msg ~= "") or (msg~= "help") then
  84. chat("QualityID: " .. msg .. " toggled.");
  85. end
  86. if(msg:lower() == "toggle") then
  87. QIDDB.enabled = not QIDDB.enabled;
  88. elseif(msg:lower() == "on") then
  89. QIDDB.enabled = true;
  90. elseif(msg:lower() == "off") then
  91. QIDDB.enabled = false;
  92. elseif(msg:lower() == "id") then
  93. QIDDB.showid = not QIDDB.showid;
  94. elseif(msg:lower() == "ilvl") then
  95. QIDDB.showitemLvl = not QIDDB.showitemLvl;
  96. elseif(msg:lower() == "stack") then
  97. QIDDB.showStackCount = not QIDDB.showStackCount;
  98. elseif(msg:lower() == "itemtype") then
  99. QIDDB.showitemType = not QIDDB.showitemType;
  100. elseif(msg:lower() == "icon") then
  101. QIDDB.showIcon = not QIDDB.showIcon;
  102. elseif(msg:lower()== "topline") then
  103. QIDDB.addTopLine = not QIDDB.addTopLine;
  104. elseif(msg:lower()== "botline") then
  105. QIDDB.addBotLine = not QIDDB.addBotLine;
  106. elseif(msg == "") or (msg == "help") then
  107. chat("QualityID options: /qid {toggle | on | off}");
  108. chat("/qid id {toggle} ");
  109. chat("/qid ilvl {toggle} ");
  110. chat("/qid stack {toggle}");
  111. chat("/qid itemtype {toggle}");
  112. chat("/qid icon {toggle}");
  113. chat("/qid topline {toggle}");
  114. chat("/qid botline {toggle}");
  115. end
  116. end
  117.  
  118. local origs = {}
  119. --Thanks to jnwhiteh for the code that finally removed the double info in recipe tooltips
  120. local lineAdded = false
  121. --calls id, ilvl, stkct, and type for our tooltip.
  122. local function OnTooltipSetItem(frame, ...)
  123. local name, link = frame:GetItem()
  124. if not link then return end
  125. if QIDDB.enabled and link then
  126. local _, _, id, id2 = strfind(link, "item:(%d+).+:(.+:.+)%[")
  127. --While not all returns will be called, all are listed for personal reference.
  128. local name,link,quality,ilvl,reqLevel,type,subType,stackCount = GetItemInfo(link)
  129. local rarity = select(3,GetItemInfo(id))
  130. if not rarity then return end
  131. --Tooltip info
  132. if link and GetItemInfo(link) and (rarity) then
  133. local r, g , b, hex = GetItemQualityColor(rarity)
  134. if not lineAdded then
  135. if QIDDB.addTopLine then
  136. frame:AddLine(" ")
  137. end
  138. if QIDDB.showid then
  139. frame:AddLine( "Item ID: |c"..hex..id.."|r")
  140. end
  141. if QIDDB.showitemLvl then
  142. frame:AddLine( "Item Lvl: |c"..hex..ilvl.."|r")
  143. end
  144. if QIDDB.showitemType then
  145. frame:AddLine( ""..type..": |c"..hex..subType.."|r")
  146. end
  147. if QIDDB.showStackCount and stackCount ~= 1 then
  148. frame:AddLine( "Stacks in lots of |c"..hex..stackCount.."|r")
  149. end
  150. if QIDDB.addBotLine then
  151. frame:AddLine(" ")
  152. end
  153. lineAdded = true
  154. end
  155. end
  156. end
  157.  
  158. if origs[frame] then
  159. return origs[frame](frame, ...)
  160. end
  161.  
  162. end
  163. --Add item icon to the tooltip.
  164. --Tooltip code yanked from Tuller's Tipachu.
  165. local function hookTip(frame, ...)
  166. local _G = getfenv(0)
  167. local set = frame:GetScript('OnTooltipSetItem')
  168. frame:SetScript('OnTooltipSetItem', function(self, ...)
  169. local link = select(2, self:GetItem())
  170. if link and GetItemInfo(link) then
  171. --make sure the icon does not display twice on recipies, which fire OnTooltipSetItem twice
  172. local text = _G[self:GetName() .. 'TextLeft1']
  173. if QIDDB.showIcon and text and text:GetText():sub(1, 2) ~= '|T' then
  174. text:SetFormattedText('|T%s:%d|t%s', GetItemIcon(link), 36, text:GetText())
  175. end
  176. end
  177.  
  178. if set then
  179. return set(self, ...)
  180. end
  181. end)
  182. end
  183. hookTip(GameTooltip)
  184. hookTip(ItemRefTooltip)
  185. hookTip(ShoppingTooltip1)
  186. hookTip(ShoppingTooltip2)
  187.  
  188. local function OnTooltipCleared(frame, ...)
  189. lineAdded = false
  190. end
  191. --Hookers of the standard GameTooltip variety.
  192. for _,frame in pairs{GameTooltip, ItemRefTooltip, ShoppingTooltip1, ShoppingTooltip2} do
  193. origs[frame] = frame:GetScript("OnTooltipSetItem")
  194. GameTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
  195. GameTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
  196. frame:SetScript("OnTooltipSetItem", OnTooltipSetItem)
  197. end
  198. -- AtlasLootTooltip flavored Hookers, if that's what you're into ;)!
  199. --AtlasLootTooltip:HookScript("OnTooltipSetItem", OnTooltipSetItem)
  200. --AtlasLootTooltip:HookScript("OnTooltipCleared", OnTooltipCleared)
  201.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement