Quantcast

Create tooltips once

Adrian L Lange [08-06-09 - 14:47]
Create tooltips once
Filename
oUF_Experience.lua
diff --git a/oUF_Experience.lua b/oUF_Experience.lua
index 79de5a0..1e8a672 100644
--- a/oUF_Experience.lua
+++ b/oUF_Experience.lua
@@ -14,7 +14,17 @@

 --]]

-local function tooltip(self, unit, min, max)
+local function xp(unit)
+	if(unit == 'pet') then
+		return GetPetExperience()
+	else
+		return UnitXP(unit), UnitXPMax(unit)
+	end
+end
+
+local function tooltip(self)
+	local unit = self:GetParent().unit
+	local min, max = xp(unit)
 	local bars = unit == 'pet' and 6 or 20

 	GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT', 5, -5)
@@ -28,14 +38,6 @@ local function tooltip(self, unit, min, max)
 	GameTooltip:Show()
 end

-local function xp(unit)
-	if(unit == 'pet') then
-		return GetPetExperience()
-	else
-		return UnitXP(unit), UnitXPMax(unit)
-	end
-end
-
 local function update(self)
 	local bar, unit = self.Experience, self.unit
 	local min, max = xp(unit)
@@ -64,12 +66,6 @@ local function update(self)
 		end
 	end

-	if(bar.Tooltip) then
-		bar:SetScript('OnEnter', function()
-			tooltip(bar, unit, min, max)
-		end)
-	end
-
 	if(bar.PostUpdate) then
 		bar.PostUpdate(self, event, unit, bar, min, max)
 	end
@@ -125,6 +121,7 @@ local function enable(self, unit)
 		if(bar.Tooltip) then
 			bar:EnableMouse()
 			bar:SetScript('OnLeave', GameTooltip_Hide)
+			bar:SetScript('OnEnter', tooltip)
 		end
 	end
 end
@@ -146,6 +143,10 @@ local function disable(self, unit)
 			self:UnregisterEvent('UNIT_PET', loadPet)
 			bar:Hide()
 		end
+
+		if(bar.Tooltip) then
+			bar:SetScript('OnEnter', nil)
+		end
 	end
 end