Advertisement
Wetxius

Untitled

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