Quantcast

Now checks for unit (player)

p3lim-52096 [08-30-08 - 15:07]
Now checks for unit (player)
Should work for WoTLK (need feedback)
Added PostUpdateExperience

git-svn-id: svn://svn.wowinterface.com/oUF_Experience-227/trunk@8 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 ad3d4e6..6f224a2 100644
--- a/oUF_Experience/oUF_Experience.lua
+++ b/oUF_Experience/oUF_Experience.lua
@@ -1,4 +1,4 @@
-local function CreateTooltip(self)
+local function CreatePlayerTooltip(self)
 	local min, max = UnitXP('player'), UnitXPMax('player')

 	GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
@@ -14,53 +14,55 @@ local function CreateTooltip(self)
 	GameTooltip:Show()
 end

-local function UpdateElement(self, bar)
-	local min, max = UnitXP('player'), UnitXPMax('player')
-	bar:SetMinMaxValues(0, max)
-	bar:SetValue(min)
-	bar:SetFrameLevel(3)
+local function UpdateElement(self, event, unit, bar)
+	if(unit == 'player') then
+		local min, max = UnitXP('player'), UnitXPMax('player')
+		bar:SetMinMaxValues(0, max)
+		bar:SetValue(min)
+		bar:SetFrameLevel(3)

-	if(bar.rested) then
-		local rested = GetXPExhaustion() or 0
-		bar.rested:SetMinMaxValues(0, max)
-		bar.rested:SetValue(rested + min)
-		bar.rested:SetFrameLevel(2)
-	end
+		if(bar.rested) then
+			local rested = GetXPExhaustion() or 0
+			bar.rested:SetMinMaxValues(0, max)
+			bar.rested:SetValue(rested + min)
+			bar.rested:SetFrameLevel(2)
+		end

-	if(bar.text) then
-		bar.text:SetFormattedText('%s / %s', min, max)
-	end
+		if(bar.text) then
+			bar.text:SetFormattedText('%s / %s', min, max)
+		end

-	if(bar.tooltip) then
-		bar:EnableMouse()
-		bar:SetScript('OnEnter', CreateTooltip)
-		bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
+		if(bar.tooltip) then
+			bar:EnableMouse()
+			bar:SetScript('OnEnter', CreatePlayerTooltip)
+			bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
+		end
+
+		if(self.PostUpdateExperience) then self:PostUpdateExperience(self, event, unit, bar, min, max) end
 	end
 end

-function oUF:PLAYER_XP_UPDATE()
+function oUF:PLAYER_XP_UPDATE(event, unit)
 	if(self.Experience) then
-		UpdateElement(self, self.Experience)
+		UpdateElement(self, event, unit, self.Experience)
 	end
 end

 oUF:RegisterSubTypeMapping('PLAYER_XP_UPDATE')
 oUF:RegisterInitCallback(function(self)
 	if(self.Experience) then
-		if(UnitLevel('player') < 70) then
+		if(UnitLevel('player') == MAX_PLAYER_LEVEL) then
+			self.Experience:Hide()
+			if(self.Experience.rested) then
+				self.Experience.rested:Hide()
+			end
+		else
 			self:RegisterEvent('PLAYER_XP_UPDATE')
 			self:RegisterEvent('PLAYER_LEVEL_UP')
 			self:RegisterEvent('UPDATE_EXHAUSTION')

 			self.PLAYER_LEVEL_UP = self.PLAYER_XP_UPDATE
 			self.UPDATE_EXHAUSTION = self.PLAYER_XP_UPDATE
-
-			UpdateElement(self, self.Experience)
-		else
-			self.Experience:Hide()
-			if(self.Experience.rested) then
-				self.Experience.rested:Hide()
-			end
 		end
 	end
 end)
\ No newline at end of file