diff --git a/WeightsWatcher.lua b/WeightsWatcher.lua
index d39771f..938cd8e 100644
--- a/WeightsWatcher.lua
+++ b/WeightsWatcher.lua
@@ -19,50 +19,42 @@ function open_config()
WeightsWatcherConfig:Show()
end
+currentHooks = {}
+
+function WeightsWatcher:HookTooltip(objectName, funcName)
+ local object = getglobal(objectName)
+ self:SecureHook(object, funcName, function(self, ...) DisplayItemInfo(self, objectName, ...) end)
+ table.insert(currentHooks, {object, func})
+end
+
function WeightsWatcher:OnEnable()
- self:SecureHook(GameTooltip, "SetAuctionItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetAuctionSellItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetBagItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetBuybackItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetGuildBankItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetInboxItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetInventoryItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetLootItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetLootRollItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetMerchantItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetQuestItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetQuestLogItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetSendMailItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetTradePlayerItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetTradeSkillItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
- self:SecureHook(GameTooltip, "SetTradeTargetItem", function(self, ...) DisplayItemInfo(self, "GameTooltip", ...) end)
+ WeightsWatcher:HookTooltip("GameTooltip", "SetAuctionItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetAuctionSellItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetBagItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetBuybackItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetGuildBankItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetInboxItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetInventoryItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetLootItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetLootRollItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetMerchantItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetQuestItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetQuestLogItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetSendMailItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetTradePlayerItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetTradeSkillItem")
+ WeightsWatcher:HookTooltip("GameTooltip", "SetTradeTargetItem")
-- Item link tooltips
- self:SecureHook(ItemRefTooltip, "SetHyperlink", function(self, ...) DisplayItemInfo(self, "ItemRefTooltip", ...) end)
+ WeightsWatcher:HookTooltip("ItemRefTooltip", "SetHyperlink")
-- Secondary and tertiary comparison tooltips
- self:SecureHook(ShoppingTooltip1, "SetHyperlinkCompareItem", function(self, ...) DisplayItemInfo(self, "ShoppingTooltip1", ...) end)
- self:SecureHook(ShoppingTooltip2, "SetHyperlinkCompareItem", function(self, ...) DisplayItemInfo(self, "ShoppingTooltip2", ...) end)
+ WeightsWatcher:HookTooltip("ShoppingTooltip1", "SetHyperlinkCompareItem")
+ WeightsWatcher:HookTooltip("ShoppingTooltip2", "SetHyperlinkCompareItem")
end
function WeightsWatcher:OnDisable()
- self:Unhook(GameTooltip, "SetAuctionItem")
- self:Unhook(GameTooltip, "SetAuctionSellItem")
- self:Unhook(GameTooltip, "SetBagItem")
- self:Unhook(GameTooltip, "SetBuybackItem")
- self:Unhook(GameTooltip, "SetGuildBankItem")
- self:Unhook(GameTooltip, "SetInboxItem")
- self:Unhook(GameTooltip, "SetInventoryItem")
- self:Unhook(GameTooltip, "SetLootItem")
- self:Unhook(GameTooltip, "SetLootRollItem")
- self:Unhook(GameTooltip, "SetMerchantItem")
- self:Unhook(GameTooltip, "SetQuestItem")
- self:Unhook(GameTooltip, "SetQuestLogItem")
- self:Unhook(GameTooltip, "SetSendMailItem")
- self:Unhook(GameTooltip, "SetTradePlayerItem")
- self:Unhook(GameTooltip, "SetTradeSkillItem")
- self:Unhook(GameTooltip, "SetTradeTargetItem")
- self:unhook(ItemRefTooltip, "SetHyperlink")
- self:Unhook(ShoppingTooltip1, "SetHyperlinkCompareItem")
- self:Unhook(ShoppingTooltip2, "SetHyperlinkCompareItem")
+ for _, hook in currentHooks do
+ self:Unhook(unpack(hook))
+ end
end
function DisplayItemInfo(tooltip, ttname)