Quantcast

Fixed pet update

p3lim-52096 [02-06-09 - 16:04]
Fixed pet update
Fixed pet "bubbles"

git-svn-id: svn://svn.wowinterface.com/oUF_Experience-227/trunk@27 f81be506-7a38-4956-9b9f-d707db2888a5
Filename
oUF_Experience/oUF_Experience.lua
diff --git a/oUF_Experience/oUF_Experience.lua b/oUF_Experience/oUF_Experience.lua
index 1d63a81..7d5f606 100644
--- a/oUF_Experience/oUF_Experience.lua
+++ b/oUF_Experience/oUF_Experience.lua
@@ -13,10 +13,18 @@
 	 - :OverrideText(min, max)

 --]]
+
+local localized, class = UnitClass('player')
+
 local function Tooltip(self, unit, min, max)
 	GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT', 5, -5)
 	GameTooltip:AddLine(string.format('XP: %d/%d (%.1f%%)', min, max, min/max*100))
-	GameTooltip:AddLine(string.format('%d needed (%.1f%% - %.1f bars)', max-min, (max-min)/max*100,(max-min)/max*20))
+
+	if(unit == 'pet') then
+		GameTooltip:AddLine(string.format('%d needed (%.1f%% - %.1f bars)', max-min, (max-min)/max*100, 6*(max-min)/max))
+	else
+		GameTooltip:AddLine(string.format('%d needed (%.1f%% - %.1f bars)', max-min, (max-min)/max*100, 20*(max-min)/max))
+	end

 	if(unit == 'player' and GetXPExhaustion()) then
 		GameTooltip:AddLine(string.format('|cff0090ffRested: +%d (%.1f%%)', GetXPExhaustion(), GetXPExhaustion()/max*100))
@@ -25,20 +33,22 @@ local function Tooltip(self, unit, min, max)
 	GameTooltip:Show()
 end

+local function GetXP(unit)
+	if(unit == 'pet') then
+		return GetPetExperience()
+	else
+		return UnitXP(unit), UnitXPMax(unit)
+	end
+end
+
 local function Update(self, event, unit)
 	local bar = self.Experience
-	local min, max

-	if(self.unit == 'player' and (UnitLevel(self.unit) ~= MAX_PLAYER_LEVEL) or self.unit == 'pet' and (UnitLevel(self.unit) ~= UnitLevel('player'))) then
-		if(self.unit == 'pet') then
-			min, max = GetPetExperience()
-		elseif(self.unit == 'player') then
-			min, max = UnitXP(self.unit), UnitXPMax(self.unit)
-		end
+	if(self.unit == 'player' and (UnitLevel(self.unit) ~= MAX_PLAYER_LEVEL) or (self.unit == 'pet' and class == 'HUNTER') and (UnitLevel(self.unit) < UnitLevel('player'))) then
+		local min, max = GetXP(self.unit)

 		bar:SetMinMaxValues(0, max)
 		bar:SetValue(min)
-		bar:EnableMouse()
 		bar:Show()

 		if(bar.Text) then
@@ -61,11 +71,19 @@ local function Update(self, event, unit)
 	end
 end

-local function Enable(self)
+local function Enable(self, unit)
 	local experience = self.Experience
-	if(experience) then
+	if(experience and (unit == 'pet' or unit == 'player')) then
 		self:RegisterEvent('PLAYER_XP_UPDATE', Update)
-		self:RegisterEvent('UNIT_PET_EXPERIENCE', Update)
+		self:RegisterEvent('UNIT_PET', Update)
+
+		if(class == 'HUNTER') then
+			self:RegisterEvent('UNIT_PET_EXPERIENCE', Update)
+		end
+
+		if(experience.MouseOver or experience.Tooltip) then
+			experience:EnableMouse()
+		end

 		if(not experience:GetStatusBarTexture()) then
 			experience:SetStatusBarTexture([=[Interface\TargetingFrame\UI-StatusBar]=])
@@ -89,7 +107,11 @@ end
 local function Disable(self)
 	if(self.Experience) then
 		self:UnregisterEvent('PLAYER_XP_UPDATE', Update)
-		self:UnregisterEvent('UNIT_PET_EXPERIENCE', Update)
+		self:UnregisterEvent('UNIT_PET', Update)
+
+		if(class == 'HUNTER') then
+			self:UnregisterEvent('UNIT_PET_EXPERIENCE', Update)
+		end
 	end
 end