Advertisement
Wetxius

Untitled

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