From 71694413433b2aaf3105d68b2a522d991f4c5e34 Mon Sep 17 00:00:00 2001 From: Tuller Date: Wed, 12 Jan 2011 19:57:31 -0500 Subject: [PATCH] refactored a bit --- Tipachu.lua | 64 +++++++++++++++++++++++++++-------------------------------- Tipachu.toc | 2 +- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/Tipachu.lua b/Tipachu.lua index b3f8ac9..99e15b6 100644 --- a/Tipachu.lua +++ b/Tipachu.lua @@ -5,53 +5,47 @@ local DEFAULT_ICON_SIZE = 24 -local function addIcon(self, icon) +--add icon to the tooltip +local function setTooltipIcon(self, icon) local title = icon and _G[self:GetName() .. 'TextLeft1'] if title then title:SetFormattedText('|T%s:%d|t %s', icon, _G['TipachuSize'] or DEFAULT_ICON_SIZE, title:GetText()) end end ---[[ tooltip hooking ]]-- +--tooltip hooking generator +local function newTooltipHooker(method, func) + return function(tooltip) + local modified = false -local function hookItem(tip) - local tooltipModified = false + tooltip:HookScript('OnTooltipCleared', function(self, ...) + modified = false + end) - tip:HookScript('OnTooltipCleared', function(self, ...) - tooltipModified = false - end) - - tip:HookScript('OnTooltipSetItem', function(self, ...) - if not tooltipModified then - tooltipModified = true - - local name, link = self:GetItem() - local icon = link and GetItemIcon(link) - addIcon(self, icon) - end - end) + tooltip:HookScript(method, function(self, ...) + if not modified then + modified = true + func(self, ...) + end + end) + end end -local function hookSpell(tip) - local tooltipModified = false - - tip:HookScript('OnTooltipCleared', function(self, ...) - tooltipModified = false - end) - - tip:HookScript('OnTooltipSetSpell', function(self, ...) - if not tooltipModified then - tooltipModified = true +local hookItem = newTooltipHooker('OnTooltipSetItem', function(self, ...) + local name, link = self:GetItem() + if link then + setTooltipIcon(self, GetItemIcon(link)) + end +end) - local spellName, spellRank, spellID = GameTooltip:GetSpell() - if spellId then - local icon = select(3, GetSpellInfo(spellID)) - addIcon(self, icon) - end - end - end) -end +local hookSpell = newTooltipHooker('OnTooltipSetSpell', function(self, ...) + local name, rank, id = self:GetSpell() + if id then + setTooltipIcon(self, select(3, GetSpellInfo(id))) + end +end) +--hook tooltips for _, tooltip in pairs{GameTooltip, ItemRefTooltip} do hookItem(tooltip) hookSpell(tooltip) diff --git a/Tipachu.toc b/Tipachu.toc index 8b1d242..9529eb4 100644 --- a/Tipachu.toc +++ b/Tipachu.toc @@ -3,5 +3,5 @@ ## Author: Tuller ## Notes: Adds an items icon to its tooltip ## SavedVariables: TipachuSize -## Version: 1.0 +## Version: 1.1 Tipachu.lua \ No newline at end of file -- 1.7.9.5