Advertisement
Wetxius

Untitled

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