Quantcast

Add rested bar support

p3lim-52096 [08-27-08 - 22:30]
Add rested bar support
Bail out early if at max level

git-svn-id: svn://svn.wowinterface.com/oUF_Experience-227/trunk@4 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 0ed1741..50c8b82 100644
--- a/oUF_Experience/oUF_Experience.lua
+++ b/oUF_Experience/oUF_Experience.lua
@@ -1,18 +1,18 @@
 local function UpdateElement(self, bar)
-	if(UnitLevel('player') < 70) then
-		local min, max = UnitXP('player'), UnitXPMax('player')
+	local min, max = UnitXP('player'), UnitXPMax('player')
+	bar:SetMinMaxValues(0, max)
+	bar:SetValue(min)
+	bar:SetFrameLevel(3)

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

-		if(bar.text) then
-			bar.text:SetFormattedText('%s / %s', min, max)
-		end
-	else
-		bar:Hide()
-		self:UnregisterEvent('PLAYER_XP_UPDATE')
-		self:UnregisterEvent('PLAYER_LEVEL_UP')
-		self:UnregisterEvent('UPDATE_EXHAUSTION')
+	if(bar.text) then
+		bar.text:SetFormattedText('%s / %s', min, max)
 	end
 end

@@ -22,15 +22,23 @@ function oUF:PLAYER_XP_UPDATE()
 	end
 end

+oUF:RegisterSubTypeMapping('PLAYER_XP_UPDATE')
 oUF:RegisterInitCallback(function(self)
 	if(self.Experience) then
-		self:RegisterEvent('PLAYER_XP_UPDATE')
-		self:RegisterEvent('PLAYER_LEVEL_UP')
-		self:RegisterEvent('UPDATE_EXHAUSTION')
+		if(UnitLevel('player') < 70) then
+			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
-		-- force update at load
-		UpdateElement(self, self.Experience)
+			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