Advertisement
Wetxius

Untitled

Feb 9th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.29 KB | None | 0 0
  1. local T, C, L, _ = unpack(select(2, ...))
  2. if C.misc.already_known ~= true then return end
  3.  
  4. ----------------------------------------------------------------------------------------
  5. -- Colorizes recipes/mounts/pets that is already known(AlreadyKnown by Villiv)
  6. ----------------------------------------------------------------------------------------
  7. local color = {r = 0.1, g = 1, b = 0.1}
  8. local knowns, lines = {}, {}
  9. local _, _, _, _, glyph, _, recipe = GetAuctionItemClasses()
  10. local _, _, pet, _, _, mount = GetAuctionItemSubClasses(9)
  11. local knowables = {[glyph] = true, [recipe] = true, [pet] = true, [mount] = true}
  12.  
  13. local pattern = ITEM_PET_KNOWN:gsub("%(", "%%(")
  14. pattern = pattern:gsub("%)", "%%)")
  15.  
  16. local tooltip = CreateFrame("GameTooltip")
  17. tooltip:SetOwner(WorldFrame, "ANCHOR_NONE")
  18.  
  19. for i = 1, 40 do
  20. lines[i] = tooltip:CreateFontString()
  21. tooltip:AddFontStrings(lines[i], tooltip:CreateFontString())
  22. end
  23.  
  24. local function Scan(line, numLines)
  25. if line > numLines then return end
  26.  
  27. local text = lines[line]:GetText()
  28. if not text or text == "" or text ~= ITEM_SPELL_KNOWN and not text:match(pattern) then return Scan(line + 1, numLines) end
  29.  
  30. return true
  31. end
  32.  
  33. local function IsKnown(itemLink)
  34. if not itemLink then return end
  35.  
  36. local speciesID = itemLink:match("battlepet:(%d+):")
  37. if speciesID then return C_PetJournal.GetNumCollectedInfo(speciesID) > 0 and true end
  38.  
  39. local itemID = itemLink:match("item:(%d+):")
  40. if not itemID then return end
  41. if knowns[itemID] then return true end
  42.  
  43. print(C_Heirloom.PlayerHasHeirloom(itemID))
  44. print(itemID)
  45.  
  46. if C_Heirloom.PlayerHasHeirloom(itemID) then return true end
  47.  
  48. if PlayerHasToy(itemID) then return true end
  49.  
  50. local _, _, _, _, _, itemType, itemSubType = GetItemInfo(itemID)
  51. if not (knowables[itemType] or knowables[itemSubType]) then return end
  52.  
  53. tooltip:ClearLines()
  54. tooltip:SetHyperlink(itemLink)
  55. if not Scan(1, tooltip:NumLines()) then return end
  56.  
  57. if itemSubType ~= pet then knowns[itemID] = true end
  58. return true
  59. end
  60.  
  61. -- Mail frame
  62. local function OpenMailFrame_UpdateButtonPositions()
  63. for i = 1, ATTACHMENTS_MAX_RECEIVE do
  64. local button = _G["OpenMailAttachmentButton"..i]
  65. if button then
  66. local name, _, _, _, canUse = GetInboxItem(InboxFrame.openMailID, i)
  67. if name and canUse and IsKnown(GetInboxItemLink(InboxFrame.openMailID, i)) then
  68. SetItemButtonTextureVertexColor(button, color.r, color.g, color.b)
  69. end
  70. end
  71. end
  72. end
  73. hooksecurefunc("OpenMailFrame_UpdateButtonPositions", OpenMailFrame_UpdateButtonPositions)
  74.  
  75. -- Loot frame
  76. local function LootFrame_UpdateButton(index)
  77. local numLootItems = LootFrame.numLootItems
  78. local numLootToShow = LOOTFRAME_NUMBUTTONS
  79. if numLootItems > LOOTFRAME_NUMBUTTONS then
  80. numLootToShow = numLootToShow - 1
  81. end
  82.  
  83. local button = _G["LootButton"..index]
  84. if button and button:IsShown() then
  85. local slot = (numLootToShow * (LootFrame.page - 1)) + index
  86. if slot <= numLootItems and LootSlotHasItem(slot) and index <= numLootToShow then
  87. local texture, _, _, _, locked = GetLootSlotInfo(slot)
  88. if texture and not locked and IsKnown(GetLootSlotLink(slot)) then
  89. SetItemButtonTextureVertexColor(button, color.r, color.g, color.b)
  90. end
  91. end
  92. end
  93. end
  94. hooksecurefunc("LootFrame_UpdateButton", LootFrame_UpdateButton)
  95.  
  96. -- Merchant frame
  97. local function MerchantFrame_UpdateMerchantInfo()
  98. local numItems = GetMerchantNumItems()
  99.  
  100. for i = 1, MERCHANT_ITEMS_PER_PAGE do
  101. local index = (MerchantFrame.page - 1) * MERCHANT_ITEMS_PER_PAGE + i
  102. if index > numItems then return end
  103.  
  104. local button = _G["MerchantItem"..i.."ItemButton"]
  105. if button and button:IsShown() then
  106. local _, _, _, _, _, isUsable = GetMerchantItemInfo(index)
  107. if isUsable and IsKnown(GetMerchantItemLink(index)) then
  108. SetItemButtonTextureVertexColor(button, color.r, color.g, color.b)
  109. end
  110. end
  111. end
  112. end
  113. hooksecurefunc("MerchantFrame_UpdateMerchantInfo", MerchantFrame_UpdateMerchantInfo)
  114.  
  115. local function MerchantFrame_UpdateBuybackInfo()
  116. local numItems = GetNumBuybackItems()
  117.  
  118. for i = 1, BUYBACK_ITEMS_PER_PAGE do
  119. if i > numItems then return end
  120.  
  121. local button = _G["MerchantItem"..i.."ItemButton"]
  122. if button and button:IsShown() then
  123. local _, _, _, _, _, isUsable = GetBuybackItemInfo(i)
  124. if isUsable and IsKnown(GetBuybackItemLink(i)) then
  125. SetItemButtonTextureVertexColor(button, color.r, color.g, color.b)
  126. end
  127. end
  128. end
  129. end
  130. hooksecurefunc("MerchantFrame_UpdateBuybackInfo", MerchantFrame_UpdateBuybackInfo)
  131.  
  132. -- Quest frame
  133. local function QuestInfo_ShowRewards()
  134. local numQuestRewards, numQuestChoices
  135. if QuestInfoFrame.questLog then
  136. numQuestRewards, numQuestChoices = GetNumQuestLogRewards(), GetNumQuestLogChoices()
  137. else
  138. numQuestRewards, numQuestChoices = GetNumQuestRewards(), GetNumQuestChoices()
  139. end
  140.  
  141. local totalRewards = numQuestRewards + numQuestChoices
  142. if totalRewards == 0 then return end
  143.  
  144. local rewardsCount = 0
  145.  
  146. if numQuestChoices > 0 then
  147. local baseIndex = rewardsCount
  148. for i = 1, numQuestChoices do
  149. local button = _G["QuestInfoItem"..i + baseIndex]
  150. if button and button:IsShown() then
  151. local isUsable
  152. if QuestInfoFrame.questLog then
  153. _, _, _, _, isUsable = GetQuestLogChoiceInfo(i)
  154. else
  155. _, _, _, _, isUsable = GetQuestItemInfo("choice", i)
  156. end
  157. if isUsable and IsKnown(QuestInfoFrame.questLog and GetQuestLogItemLink("choice", i) or GetQuestItemLink("choice", i)) then
  158. SetItemButtonTextureVertexColor(button, color.r, color.g, color.b)
  159. end
  160. end
  161. rewardsCount = rewardsCount + 1
  162. end
  163. end
  164.  
  165. if numQuestRewards > 0 then
  166. local baseIndex = rewardsCount
  167. for i = 1, numQuestRewards do
  168. local button = _G["QuestInfoItem"..i + baseIndex]
  169. if button and button:IsShown() then
  170. local isUsable
  171. if QuestInfoFrame.questLog then
  172. _, _, _, _, isUsable = GetQuestLogRewardInfo(i)
  173. else
  174. _, _, _, _, isUsable = GetQuestItemInfo("reward", i)
  175. end
  176. if isUsable and IsKnown(QuestInfoFrame.questLog and GetQuestLogItemLink("reward", i) or GetQuestItemLink("reward", i)) then
  177. SetItemButtonTextureVertexColor(button, color.r, color.g, color.b)
  178. end
  179. rewardsCount = rewardsCount + 1
  180. end
  181. end
  182. end
  183. end
  184. hooksecurefunc("QuestInfo_ShowRewards", QuestInfo_ShowRewards)
  185.  
  186. -- Guild rewards frame
  187. local function GuildRewards_Update()
  188. local offset = HybridScrollFrame_GetOffset(GuildRewardsContainer)
  189. local buttons = GuildRewardsContainer.buttons
  190. local _, _, standingID = GetGuildFactionInfo()
  191.  
  192. for i = 1, #buttons do
  193. local button = buttons[i]
  194. if button and button:IsShown() then
  195. local achievementID, itemID, itemName, _, repLevel = GetGuildRewardInfo(offset + i)
  196. if itemName and not (achievementID and achievementID > 0) and repLevel <= standingID then
  197. local _, itemLink = GetItemInfo(itemID)
  198. if IsKnown(itemLink) then
  199. button.icon:SetVertexColor(color.r, color.g, color.b)
  200. end
  201. end
  202. end
  203. end
  204. end
  205.  
  206. local isBlizzard_GuildUILoaded
  207. if IsAddOnLoaded("Blizzard_GuildUI") then
  208. isBlizzard_GuildUILoaded = true
  209. hooksecurefunc("GuildRewards_Update", GuildRewards_Update)
  210. hooksecurefunc(GuildRewardsContainer, "update", GuildRewards_Update)
  211. end
  212.  
  213. -- GuildBank frame
  214. local function GuildBankFrame_Update()
  215. if GuildBankFrame.mode ~= "bank" then return end
  216.  
  217. local tab = GetCurrentGuildBankTab()
  218.  
  219. for i = 1, MAX_GUILDBANK_SLOTS_PER_TAB do
  220. local index = math.fmod(i, NUM_SLOTS_PER_GUILDBANK_GROUP)
  221. if index == 0 then index = 14 end
  222. local column = math.ceil((i - 0.5) / NUM_SLOTS_PER_GUILDBANK_GROUP)
  223. local button = _G["GuildBankColumn"..column.."Button"..index]
  224.  
  225. if button and button:IsShown() then
  226. local texture, _, locked = GetGuildBankItemInfo(tab, i)
  227. if texture and not locked then
  228. if IsKnown(GetGuildBankItemLink(tab, i)) then
  229. SetItemButtonTextureVertexColor(button, color.r, color.g, color.b)
  230. else
  231. SetItemButtonTextureVertexColor(button, 1, 1, 1)
  232. end
  233. end
  234. end
  235. end
  236. end
  237.  
  238. local isBlizzard_GuildBankUILoaded
  239. if IsAddOnLoaded("Blizzard_GuildBankUI") then
  240. isBlizzard_GuildBankUILoaded = true
  241. hooksecurefunc("GuildBankFrame_Update", GuildBankFrame_Update)
  242. end
  243.  
  244. -- Auction frame
  245. local function AuctionFrameBrowse_Update()
  246. local numItems = GetNumAuctionItems("list")
  247. local offset = FauxScrollFrame_GetOffset(BrowseScrollFrame)
  248.  
  249. for i = 1, NUM_BROWSE_TO_DISPLAY do
  250. local index = offset + i + NUM_AUCTION_ITEMS_PER_PAGE * AuctionFrameBrowse.page
  251. if index > numItems + NUM_AUCTION_ITEMS_PER_PAGE * AuctionFrameBrowse.page then return end
  252.  
  253. local texture = _G["BrowseButton"..i.."ItemIconTexture"]
  254. if texture and texture:IsShown() then
  255. local _, _, _, _, canUse, _, _, _, _, _, _, _, _, _, _, hasAllInfo = GetAuctionItemInfo("list", offset + i)
  256. if canUse and hasAllInfo and IsKnown(GetAuctionItemLink("list", offset + i)) then
  257. texture:SetVertexColor(color.r, color.g, color.b)
  258. end
  259. end
  260. end
  261. end
  262.  
  263. local function AuctionFrameBid_Update()
  264. local numItems = GetNumAuctionItems("bidder")
  265. local offset = FauxScrollFrame_GetOffset(BidScrollFrame)
  266.  
  267. for i = 1, NUM_BIDS_TO_DISPLAY do
  268. local index = offset + i
  269. if index > numItems then return end
  270.  
  271. local texture = _G["BidButton"..i.."ItemIconTexture"]
  272. if texture and texture:IsShown() then
  273. local _, _, _, _, canUse = GetAuctionItemInfo("bidder", index)
  274. if canUse and IsKnown(GetAuctionItemLink("bidder", index)) then
  275. texture:SetVertexColor(color.r, color.g, color.b)
  276. end
  277. end
  278. end
  279. end
  280.  
  281. local function AuctionFrameAuctions_Update()
  282. local numItems = GetNumAuctionItems("owner")
  283. local offset = FauxScrollFrame_GetOffset(AuctionsScrollFrame)
  284.  
  285. for i = 1, NUM_AUCTIONS_TO_DISPLAY do
  286. local index = offset + i + NUM_AUCTION_ITEMS_PER_PAGE * AuctionFrameAuctions.page
  287. if index > numItems + NUM_AUCTION_ITEMS_PER_PAGE * AuctionFrameAuctions.page then return end
  288.  
  289. local texture = _G["AuctionsButton"..i.."ItemIconTexture"]
  290. if texture and texture:IsShown() then
  291. local _, _, _, _, canUse = GetAuctionItemInfo("owner", offset + i)
  292. if canUse and IsKnown(GetAuctionItemLink("owner", index)) then
  293. texture:SetVertexColor(color.r, color.g, color.b)
  294. end
  295. end
  296. end
  297. end
  298.  
  299. local isBlizzard_AuctionUILoaded
  300. if IsAddOnLoaded("Blizzard_AuctionUI") then
  301. isBlizzard_AuctionUILoaded = true
  302. hooksecurefunc("AuctionFrameBrowse_Update", AuctionFrameBrowse_Update)
  303. hooksecurefunc("AuctionFrameBid_Update", AuctionFrameBid_Update)
  304. hooksecurefunc("AuctionFrameAuctions_Update", AuctionFrameAuctions_Update)
  305. end
  306.  
  307. -- Black market frame
  308. local function BlackMarketFrame_UpdateHotItem(self)
  309. local texture = self.HotDeal.Item.IconTexture
  310. if not (texture and texture:IsShown()) then return end
  311.  
  312. local name, _, _, _, usable, _, _, _, _, _, _, _, _, _, link = C_BlackMarket.GetHotItem()
  313. if name and usable and IsKnown(link) then
  314. texture:SetVertexColor(color.r, color.g, color.b)
  315. end
  316. end
  317.  
  318. local function BlackMarketScrollFrame_Update()
  319. local numItems = C_BlackMarket.GetNumItems()
  320. local offset = HybridScrollFrame_GetOffset(BlackMarketScrollFrame)
  321. local buttons = BlackMarketScrollFrame.buttons
  322.  
  323. for i = 1, #buttons do
  324. local index = offset + i
  325. if index > numItems then return end
  326.  
  327. local texture = buttons[i].Item.IconTexture
  328. if texture and texture:IsShown() then
  329. local name, _, _, _, usable, _, _, _, _, _, _, _, _, _, link = C_BlackMarket.GetItemInfoByIndex(index)
  330. if name and usable and IsKnown(link) then
  331. texture:SetVertexColor(color.r, color.g, color.b)
  332. end
  333. end
  334. end
  335. end
  336.  
  337. local isBlizzard_BlackMarketUILoaded
  338. if IsAddOnLoaded("Blizzard_BlackMarketUI") then
  339. isBlizzard_BlackMarketUILoaded = true
  340. hooksecurefunc("BlackMarketFrame_UpdateHotItem", BlackMarketFrame_UpdateHotItem)
  341. hooksecurefunc("BlackMarketScrollFrame_Update", BlackMarketScrollFrame_Update)
  342. hooksecurefunc(BlackMarketScrollFrame, "update", BlackMarketScrollFrame_Update)
  343. end
  344.  
  345. -- LoD addons
  346. if not (isBlizzard_GuildUILoaded and isBlizzard_GuildBankUILoaded and isBlizzard_AuctionUILoaded and isBlizzard_BlackMarketUILoaded) then
  347. local function OnEvent(self, event, addon)
  348. if addon == "Blizzard_GuildUI" then
  349. isBlizzard_GuildUILoaded = true
  350. hooksecurefunc("GuildRewards_Update", GuildRewards_Update)
  351. hooksecurefunc(GuildRewardsContainer, "update", GuildRewards_Update)
  352. elseif addon == "Blizzard_GuildBankUI" then
  353. isBlizzard_GuildBankUILoaded = true
  354. hooksecurefunc("GuildBankFrame_Update", GuildBankFrame_Update)
  355. elseif addon == "Blizzard_AuctionUI" then
  356. isBlizzard_AuctionUILoaded = true
  357. hooksecurefunc("AuctionFrameBrowse_Update", AuctionFrameBrowse_Update)
  358. hooksecurefunc("AuctionFrameBid_Update", AuctionFrameBid_Update)
  359. hooksecurefunc("AuctionFrameAuctions_Update", AuctionFrameAuctions_Update)
  360. elseif addon == "Blizzard_BlackMarketUI" then
  361. isBlizzard_BlackMarketUILoaded = true
  362. hooksecurefunc("BlackMarketFrame_UpdateHotItem", BlackMarketFrame_UpdateHotItem)
  363. hooksecurefunc("BlackMarketScrollFrame_Update", BlackMarketScrollFrame_Update)
  364. hooksecurefunc(BlackMarketScrollFrame, "update", BlackMarketScrollFrame_Update)
  365. end
  366.  
  367. if isBlizzard_GuildUILoaded and isBlizzard_GuildBankUILoaded and isBlizzard_AuctionUILoaded and isBlizzard_BlackMarketUILoaded then
  368. self:UnregisterEvent(event)
  369. self:SetScript("OnEvent", nil)
  370. OnEvent = nil
  371. end
  372. end
  373.  
  374. tooltip:SetScript("OnEvent", OnEvent)
  375. tooltip:RegisterEvent("ADDON_LOADED")
  376. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement