diff --git a/init/libs.xml b/init/libs.xml index 4f19e93e..98aa92ca 100644 --- a/init/libs.xml +++ b/init/libs.xml @@ -5,4 +5,5 @@ + diff --git a/libs/libtooltip.lua b/libs/libtooltip.lua new file mode 100644 index 00000000..97e0c62c --- /dev/null +++ b/libs/libtooltip.lua @@ -0,0 +1,149 @@ +-- load pfUI environment +setfenv(1, pfUI:GetEnvironment()) + +--[[ libtooltip ]]-- +-- A pfUI library that provides additional GameTooltip information. +-- +-- libtooltip:GetItemID() +-- returns the itemID of the current GameTooltip +-- `nil` when no item is displayed +-- +-- libtooltip:GetItemLink() +-- returns the itemLink of the current GameTooltip +-- `nil` when no item is displayed +-- +-- libtooltip:GetItemCount() +-- returns the item count (bags) of the current GameTooltip +-- `nil` when no item is displayed + +-- return instantly when another libtooltip is already active +if pfUI.api.libtooltip then return end + +local _ +local libtooltip = CreateFrame("Frame" , "pfLibTooltip", GameTooltip) +libtooltip:SetScript("OnHide", function() + this.itemID = nil + this.itemLink = nil + this.itemCount = nil +end) + +-- core functions +libtooltip.GetItemID = function(self) + if not libtooltip.itemLink then return end + if not libtooltip.itemID then + local _, _, itemID = string.find(libtooltip.itemLink, "item:(%d+):%d+:%d+:%d+") + libtooltip.itemID = tonumber(itemID) + end + + return libtooltip.itemID +end + +libtooltip.GetItemLink = function(self) + return libtooltip.itemLink +end + +libtooltip.GetItemCount = function(self) + return libtooltip.itemCount +end + +pfUI.api.libtooltip = libtooltip + +-- setup item hooks +local pfHookSetBagItem = GameTooltip.SetBagItem +function GameTooltip.SetBagItem(self, container, slot) + libtooltip.itemLink = GetContainerItemLink(container, slot) + _, libtooltip.itemCount = GetContainerItemInfo(container, slot) + return pfHookSetBagItem(self, container, slot) +end + +local pfHookSetQuestLogItem = GameTooltip.SetQuestLogItem +function GameTooltip.SetQuestLogItem(self, itemType, index) + libtooltip.itemLink = GetQuestLogItemLink(itemType, index) + if not libtooltip.itemLink then return end + return pfHookSetQuestLogItem(self, itemType, index) +end + +local pfHookSetQuestItem = GameTooltip.SetQuestItem +function GameTooltip.SetQuestItem(self, itemType, index) + libtooltip.itemLink = GetQuestItemLink(itemType, index) + return pfHookSetQuestItem(self, itemType, index) +end + +local pfHookSetLootItem = GameTooltip.SetLootItem +function GameTooltip.SetLootItem(self, slot) + libtooltip.itemLink = GetLootSlotLink(slot) + pfHookSetLootItem(self, slot) +end + +local pfHookSetInboxItem = GameTooltip.SetInboxItem +function GameTooltip.SetInboxItem(self, mailID, attachmentIndex) + local itemName, itemTexture, inboxItemCount, inboxItemQuality = GetInboxItem(mailID) + libtooltip.itemLink = GetItemLinkByName(itemName) + return pfHookSetInboxItem(self, mailID, attachmentIndex) +end + +local pfHookSetInventoryItem = GameTooltip.SetInventoryItem +function GameTooltip.SetInventoryItem(self, unit, slot) + libtooltip.itemLink = GetInventoryItemLink(unit, slot) + return pfHookSetInventoryItem(self, unit, slot) +end + +local pfHookSetLootRollItem = GameTooltip.SetLootRollItem +function GameTooltip.SetLootRollItem(self, id) + libtooltip.itemLink = GetLootRollItemLink(id) + return pfHookSetLootRollItem(self, id) +end + +local pfHookSetLootRollItem = GameTooltip.SetLootRollItem +function GameTooltip.SetLootRollItem(self, id) + libtooltip.itemLink = GetLootRollItemLink(id) + return pfHookSetLootRollItem(self, id) +end + +local pfHookSetMerchantItem = GameTooltip.SetMerchantItem +function GameTooltip.SetMerchantItem(self, merchantIndex) + libtooltip.itemLink = GetMerchantItemLink(merchantIndex) + return pfHookSetMerchantItem(self, merchantIndex) +end + +local pfHookSetCraftItem = GameTooltip.SetCraftItem +function GameTooltip.SetCraftItem(self, skill, slot) + libtooltip.itemLink = GetCraftReagentItemLink(skill, slot) + return pfHookSetCraftItem(self, skill, slot) +end + +local pfHookSetCraftSpell = GameTooltip.SetCraftSpell +function GameTooltip.SetCraftSpell(self, slot) + libtooltip.itemLink = GetCraftItemLink(slot) + return pfHookSetCraftSpell(self, slot) +end + +local pfHookSetTradeSkillItem = GameTooltip.SetTradeSkillItem +function GameTooltip.SetTradeSkillItem(self, skillIndex, reagentIndex) + if reagentIndex then + libtooltip.itemLink = GetTradeSkillReagentItemLink(skillIndex, reagentIndex) + else + libtooltip.itemLink = GetTradeSkillItemLink(skillIndex) + end + return pfHookSetTradeSkillItem(self, skillIndex, reagentIndex) +end + +local pfHookSetAuctionSellItem = GameTooltip.SetAuctionSellItem +function GameTooltip.SetAuctionSellItem(self) + local itemName, _, itemCount = GetAuctionSellItemInfo() + libtooltip.itemCount = itemCount + libtooltip.itemLink = GetItemLinkByName(itemName) + return pfHookSetAuctionSellItem(self) +end + +local pfHookSetTradePlayerItem = GameTooltip.SetTradePlayerItem +function GameTooltip.SetTradePlayerItem(self, index) + libtooltip.itemLink = GetTradePlayerItemLink(index) + return pfHookSetTradePlayerItem(self, index) +end + +local pfHookSetTradeTargetItem = GameTooltip.SetTradeTargetItem +function GameTooltip.SetTradeTargetItem(self, index) + libtooltip.itemLink = GetTradeTargetItemLink(index) + return pfHookSetTradeTargetItem(self, index) +end diff --git a/modules/sellvalue.lua b/modules/sellvalue.lua index aad4cf19..d4f64825 100644 --- a/modules/sellvalue.lua +++ b/modules/sellvalue.lua @@ -1,16 +1,9 @@ pfUI:RegisterModule("sellvalue", "vanilla:tbc", function () pfUI.sellvalue = CreateFrame( "Frame" , "pfGameTooltip", GameTooltip ) - - pfUI.sellvalue:SetScript("OnHide", function() - GameTooltip.itemLink = nil - GameTooltip.itemCount = nil - end) - pfUI.sellvalue:SetScript("OnShow", function() - if GameTooltip.itemLink then - local _, _, itemID = string.find(GameTooltip.itemLink, "item:(%d+):%d+:%d+:%d+") - local itemID = tonumber(itemID) - local count = GameTooltip.itemCount or 1 + if libtooltip:GetItemLink() then + local itemID = libtooltip:GetItemID() + local count = libtooltip:GetItemCount() or 1 if pfSellData[itemID] then local _, _, sell, buy = strfind(pfSellData[itemID], "(.*),(.*)") @@ -40,104 +33,4 @@ pfUI:RegisterModule("sellvalue", "vanilla:tbc", function () end end end) - - local pfHookSetBagItem = GameTooltip.SetBagItem - function GameTooltip.SetBagItem(self, container, slot) - GameTooltip.itemLink = GetContainerItemLink(container, slot) - local _ - _, GameTooltip.itemCount = GetContainerItemInfo(container, slot) - return pfHookSetBagItem(self, container, slot) - end - - local pfHookSetQuestLogItem = GameTooltip.SetQuestLogItem - function GameTooltip.SetQuestLogItem(self, itemType, index) - GameTooltip.itemLink = GetQuestLogItemLink(itemType, index) - if not GameTooltip.itemLink then return end - return pfHookSetQuestLogItem(self, itemType, index) - end - - local pfHookSetQuestItem = GameTooltip.SetQuestItem - function GameTooltip.SetQuestItem(self, itemType, index) - GameTooltip.itemLink = GetQuestItemLink(itemType, index) - return pfHookSetQuestItem(self, itemType, index) - end - - local pfHookSetLootItem = GameTooltip.SetLootItem - function GameTooltip.SetLootItem(self, slot) - GameTooltip.itemLink = GetLootSlotLink(slot) - pfHookSetLootItem(self, slot) - end - - local pfHookSetInboxItem = GameTooltip.SetInboxItem - function GameTooltip.SetInboxItem(self, mailID, attachmentIndex) - local itemName, itemTexture, inboxItemCount, inboxItemQuality = GetInboxItem(mailID) - GameTooltip.itemLink = GetItemLinkByName(itemName) - return pfHookSetInboxItem(self, mailID, attachmentIndex) - end - - local pfHookSetInventoryItem = GameTooltip.SetInventoryItem - function GameTooltip.SetInventoryItem(self, unit, slot) - GameTooltip.itemLink = GetInventoryItemLink(unit, slot) - return pfHookSetInventoryItem(self, unit, slot) - end - - local pfHookSetLootRollItem = GameTooltip.SetLootRollItem - function GameTooltip.SetLootRollItem(self, id) - GameTooltip.itemLink = GetLootRollItemLink(id) - return pfHookSetLootRollItem(self, id) - end - - local pfHookSetLootRollItem = GameTooltip.SetLootRollItem - function GameTooltip.SetLootRollItem(self, id) - GameTooltip.itemLink = GetLootRollItemLink(id) - return pfHookSetLootRollItem(self, id) - end - - local pfHookSetMerchantItem = GameTooltip.SetMerchantItem - function GameTooltip.SetMerchantItem(self, merchantIndex) - GameTooltip.itemLink = GetMerchantItemLink(merchantIndex) - return pfHookSetMerchantItem(self, merchantIndex) - end - - local pfHookSetCraftItem = GameTooltip.SetCraftItem - function GameTooltip.SetCraftItem(self, skill, slot) - GameTooltip.itemLink = GetCraftReagentItemLink(skill, slot) - return pfHookSetCraftItem(self, skill, slot) - end - - local pfHookSetCraftSpell = GameTooltip.SetCraftSpell - function GameTooltip.SetCraftSpell(self, slot) - GameTooltip.itemLink = GetCraftItemLink(slot) - return pfHookSetCraftSpell(self, slot) - end - - local pfHookSetTradeSkillItem = GameTooltip.SetTradeSkillItem - function GameTooltip.SetTradeSkillItem(self, skillIndex, reagentIndex) - if reagentIndex then - GameTooltip.itemLink = GetTradeSkillReagentItemLink(skillIndex, reagentIndex) - else - GameTooltip.itemLink = GetTradeSkillItemLink(skillIndex) - end - return pfHookSetTradeSkillItem(self, skillIndex, reagentIndex) - end - - local pfHookSetAuctionSellItem = GameTooltip.SetAuctionSellItem - function GameTooltip.SetAuctionSellItem(self) - local itemName, _, itemCount = GetAuctionSellItemInfo() - GameTooltip.itemCount = itemCount - GameTooltip.itemLink = GetItemLinkByName(itemName) - return pfHookSetAuctionSellItem(self) - end - - local pfHookSetTradePlayerItem = GameTooltip.SetTradePlayerItem - function GameTooltip.SetTradePlayerItem(self, index) - GameTooltip.itemLink = GetTradePlayerItemLink(index) - return pfHookSetTradePlayerItem(self, index) - end - - local pfHookSetTradeTargetItem = GameTooltip.SetTradeTargetItem - function GameTooltip.SetTradeTargetItem(self, index) - GameTooltip.itemLink = GetTradeTargetItemLink(index) - return pfHookSetTradeTargetItem(self, index) - end end)