Quantcast

Updated TOC for Patch 3.2

p3lim-52096 [08-04-09 - 19:26]
Updated TOC for Patch 3.2
Added support for xp enabling/disabling
Removed MouseOver boolean
Removed OverrideTooltip function
Major cleanup, should work flawless

git-svn-id: svn://svn.wowinterface.com/oUF_Experience-227/trunk@38 f81be506-7a38-4956-9b9f-d707db2888a5
Filename
oUF_Experience/oUF_Experience.lua
oUF_Experience/oUF_Experience.toc
diff --git a/oUF_Experience/oUF_Experience.lua b/oUF_Experience/oUF_Experience.lua
index 82fc775..890c701 100644
--- a/oUF_Experience/oUF_Experience.lua
+++ b/oUF_Experience/oUF_Experience.lua
@@ -5,34 +5,30 @@
 	 .Experience.Text [fontstring] (optional)
 	 .Experience.Rested [statusbar] (optional)

-	Shared:
-	 - MouseOver [boolean]
-	 - Tooltip [boolean]
+	Booleans:
+	 - Tooltip

 	Functions that can be overridden from within a layout:
-	 - :PostUpdate(event, unit, bar, min, max)
-	 - :OverrideText(unit, min, max)
-	 - :OverrideTooltip(unit, min, max, bars)
+	 - PostUpdate(self, event, unit, bar, min, max)
+	 - OverrideText(bar, unit, min, max)

 --]]

-local function showTooltip(self, unit, min, max, bars)
-	if(self.MouseOver) then
-		self:SetAlpha(1)
-	end
+local function tooltip(self, unit, min, max)
+	local bars = unit == 'pet' and 6 or 20

 	GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT', 5, -5)
-	GameTooltip:AddLine(format('XP: %d/%d (%.1f%%)', min, max, min / max * 100))
-	GameTooltip:AddLine(format('%d needed (%.1f%% - %.1f bars)', max - min, (max - min) / max * 100, bars * (max - min) / max))
+	GameTooltip:AddLine(format('XP: %d / %d (%d%% - %d bars)', min, max, min / max * 100), bars)
+	GameTooltip:AddLine(format('Left: %d (%d%% - %d bars)', max - min, (max - min) / max * 100, bars * (max - min) / max))

-	if(unit == 'player' and GetXPExhaustion() and GetXPExhaustion() > 0) then
-		GameTooltip:AddLine(format('|cff0090ffRested: +%d (%.1f%%)', GetXPExhaustion(), GetXPExhaustion() / max * 100))
+	if(self.exhaustion) then
+		GameTooltip:AddLine(format('|cff0090ffRested: +%d (%d%%)', self.exhaustion, self.exhaustion / max * 100))
 	end

 	GameTooltip:Show()
 end

-local function getXP(unit)
+local function xp(unit)
 	if(unit == 'pet') then
 		return GetPetExperience()
 	else
@@ -40,9 +36,9 @@ local function getXP(unit)
 	end
 end

-local function Update(self)
+local function update(self)
 	local bar, unit = self.Experience, self.unit
-	local min, max = getXP(unit)
+	local min, max = xp(unit)
 	bar:SetMinMaxValues(0, max)
 	bar:SetValue(min)

@@ -54,122 +50,103 @@ local function Update(self)
 		end
 	end

-	if(bar.Rested and unit == 'player') then
-		if(GetXPExhaustion() and GetXPExhaustion() > 0) then
+	if(bar.Rested) then
+		local exhaustion = GetXPExhaustion()
+
+		if(unit == 'player' and exhaustion and exhaustion > 0) then
 			bar.Rested:SetMinMaxValues(0, max)
-			bar.Rested:SetValue(math.min(min + GetXPExhaustion(), max))
+			bar.Rested:SetValue(math.min(min + exhaustion, max))
+			bar.exhaustion = exhaustion
 		else
 			bar.Rested:SetMinMaxValues(0, 1)
 			bar.Rested:SetValue(0)
+			bar.exhaustion = nil
 		end
-	elseif(bar.Rested and unit ~= 'player') then
-		bar.Rested:SetMinMaxValues(0, 1)
-		bar.Rested:SetValue(0)
-	end
-
-	if(bar.PostUpdate) then
-		bar.PostUpdate(self, event, unit, bar, min, max)
 	end

 	if(bar.Tooltip) then
 		bar:SetScript('OnEnter', function()
-			return (bar.OverrideTooltip or showTooltip) (bar, unit, min, max, unit == 'pet' and 6 or 20)
+			tooltip(bar, unit, min, max)
 		end)
 	end
-end

-local function LevelCheck(self)
-	if(UnitLevel(self.unit) == MAX_PLAYER_LEVEL) then
-		return self:DisableElement('Experience')
-	else
-		Update(self)
+	if(bar.PostUpdate) then
+		bar.PostUpdate(self, event, unit, bar, min, max)
 	end
+end

-	if(self.unit == 'pet') then
-		if(UnitLevel(self.unit) == UnitLevel('player')) then
-			self.Experience:Hide()
+local function argChecks(self, event, unit, ...)
+	if(self.unit == 'player') then
+		if(IsXPUserDisabled()) then
+			self:DisableElement('Experience')
+			self:RegisterEvent('ENABLE_XP_GAIN', argChecks)
+		elseif(UnitLevel('player') == MAX_PLAYER_LEVEL) then
+			self:DisableElement('Experience')
 		else
+			update(self)
+		end
+	elseif(self.unit == 'pet') then
+		if(UnitLevel('pet') ~= UnitLevel('player')) then
 			self.Experience:Show()
+			update(self)
+		else
+			self.Experience:Hide()
 		end
 	end
 end

-local function PetCheck(self, event, unit)
+local function loadPet(self, event, unit)
 	if(unit == 'player') then
-		LevelCheck(self)
+		argChecks(self)
 	end
 end

-local function Enable(self, unit)
+local function enable(self, unit)
 	local bar = self.Experience
 	if(bar) then
 		if(not bar:GetStatusBarTexture()) then
-			bar:SetStatusBarTexture([=[Interface\TargetingFrame\UI-StatusBar]=])
+			bar:SetStatusBarTexture()
 		end

 		if(unit == 'player') then
-			if(UnitLevel(unit) ~= MAX_PLAYER_LEVEL) then
-				self:RegisterEvent('PLAYER_XP_UPDATE', Update)
-				self:RegisterEvent('PLAYER_LEVEL_UP', LevelCheck)
-
-				if(bar.Rested) then
-					self:RegisterEvent('UPDATE_EXHAUSTION', Update)
-				end
-			else
-				bar:Hide()
-
-				if(bar.Rested) then
-					bar.Rested:Hide()
-				end
+			self:RegisterEvent('PLAYER_XP_UPDATE', argChecks)
+			self:RegisterEvent('PLAYER_LEVEL_UP', argChecks)
+
+			if(bar.Rested) then
+				self:RegisterEvent('UPDATE_EXHAUSTION', argChecks)
 			end
 		elseif(unit == 'pet') then
 			if(select(2, UnitClass('player')) == 'HUNTER') then
-				if(UnitLevel(unit) ~= MAX_PLAYER_LEVEL) then
-					self:RegisterEvent('UNIT_PET_EXPERIENCE', LevelCheck)
-					self:RegisterEvent('UNIT_PET', PetCheck)
-				else
-					bar:Hide()
-				end
-			else
-				bar:Hide()
+				self:RegisterEvent('UNIT_PET_EXPERIENCE', argChecks)
+				self:RegisterEvent('UNIT_PET', loadPet)
 			end
 		end

-		if(bar.MouseOver or bar.Tooltip) then
+		if(bar.Tooltip) then
 			bar:EnableMouse()
+			bar:SetScript('OnLeave', GameTooltip_Hide)
 		end
-
-		if(bar.MouseOver and bar.Tooltip) then
-			bar:SetAlpha(0)
-			bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
-		elseif(bar.MouseOver and not bar.Tooltip) then
-			bar:SetAlpha(0)
-			bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
-			bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
-		elseif(not bar.MouseOver and bar.Tooltip) then
-			bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
-		end
-
-		return true
 	end
 end

-local function Disable(self, unit)
+local function disable(self, unit)
 	local bar = self.Experience
 	if(bar) then
-		if(unit == 'player') then
-			self:UnregisterEvent('PLAYER_XP_UPDATE', Update)
+		if(unit == 'player')
+			self:UnregisterEvent('PLAYER_XP_UPDATE', argChecks)
+			self:UnregisterEvent('PLAYER_LEVEL_UP', argChecks)
 			bar:Hide()

 			if(bar.Rested) then
-				self:UnregisterEvent('UPDATE_EXHAUSTION', Update)
-				bar:Hide()
+				self:UnregisterEvent('UPDATE_EXHAUSTION', argChecks)
+				bar.Rested:Hide()
 			end
 		elseif(unit == 'pet') then
-			self:UnregisterEvent('UNIT_PET_EXPERIENCE', Update)
+			self:UnregisterEvent('UNIT_PET_EXPERIENCE', argChecks)
+			self:UnregisterEvent('UNIT_PET', loadPet)
 			bar:Hide()
 		end
 	end
 end

-oUF:AddElement('Experience', Update, Enable, Disable)
\ No newline at end of file
+oUF:AddElement('Experience', update, enable, disable)
\ No newline at end of file
diff --git a/oUF_Experience/oUF_Experience.toc b/oUF_Experience/oUF_Experience.toc
index d3a5722..b3892be 100644
--- a/oUF_Experience/oUF_Experience.toc
+++ b/oUF_Experience/oUF_Experience.toc
@@ -1,6 +1,6 @@
-## Interface: 30100
+## Interface: 30200
 ## Author: p3lim
-## Version: 30100.wowi:revision
+## Version: 30200.wowi:revision
 ## Title: oUF Experience
 ## Notes: Experience Bar support for oUF layouts.
 ## RequiredDeps: oUF