Quantcast

Rewrite to reflect changes in oUF

p3lim-52096 [12-21-08 - 03:46]
Rewrite to reflect changes in oUF
Removed Reputation

git-svn-id: svn://svn.wowinterface.com/oUF_Experience-227/trunk@21 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 dae5a07..eaab2a1 100644
--- a/oUF_Experience/oUF_Experience.lua
+++ b/oUF_Experience/oUF_Experience.lua
@@ -2,153 +2,77 @@

 	Elements handled:
 	 .Experience [statusbar]
-	 .Experience.Text [fontstring]
+	 .Experience.Text [fontstring] (optional)

 	Shared:
-	 - colorReputation [table] - will use blizzard colors if not set
-	 - colorExperience [table] - will use a green color if not set
+	 - Color [table] - will use oUF.colors.health if not set
 	 - Tooltip [boolean]
 	 - MouseOver [boolean]
-	 - XPOnly [boolean]
-	 - RepOnly [boolean]

 --]]
 local localized, english = UnitClass('player')
-local _format = string.format

-local function PlayerXPTip(self, min, max)
-	local rested = GetXPExhaustion()
+local function Tooltip(self, unit, min, max)
 	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,(max-min)/max*20))
-	if(rested) then
-		GameTooltip:AddLine(_format('|cff0090ffRested: +%d (%.1f%%)', rested, rested/max*100))
+	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 == 'player' and GetXPExhaustion()) then
+		GameTooltip:AddLine(string.format('|cff0090ffRested: +%d (%.1f%%)', GetXPExhaustion(), GetXPExhaustion()/max*100))
 	end
-	GameTooltip:Show()
-end

-local function PlayerRepTip(self, name, id, min, max)
-	GameTooltip:SetOwner(self, 'ANCHOR_BOTTOMRIGHT', 5, -5)
-	GameTooltip:AddLine(_format('%s (%s)', name, _G['FACTION_STANDING_LABEL'..id]))
-	GameTooltip:AddLine(_format('%d/%d (%.1f%%)', min, max, min/max*100))
 	GameTooltip:Show()
 end

-local function PetTip(self, min, max)
-	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,(max-min)/max*20))
-	GameTooltip:Show()
-end
+local function Update(self, event, unit)
+	local bar = self.Experience
+
+	if(event == 'UNIT_PET' and self.unit ~= 'player') then
+		return
+	elseif(self.unit == 'player' and UnitLevel('player') == MAX_PLAYER_LEVEL) then
+		bar:SetAlpha(0)
+	elseif(self.unit == 'pet' and (UnitLevel('pet') == UnitLevel('player') and english ~= 'HUNTER')) then
+		bar:SetAlpha(0)
+	else
+		local min, max
+		if(self.unit == 'pet' and not bar.RepOnly) then
+			min, max = GetPetExperience()
+		elseif(self.unit == 'player' and not bar.RepOnly) then
+			min, max = UnitXP(self.unit), UnitXPMax(self.unit)
+		end
+
+		bar:SetMinMaxValues(0, max)
+		bar:SetValue(min)
+		bar:EnableMouse()
+		bar:SetStatusBarColor(unpack(self.Color or self.colors.health))

-function oUF:PLAYER_XP_UPDATE(event, unit)
-	if(self.unit == 'player') then
-		local bar = self.Experience
-
-		if(GetWatchedFactionInfo() and not self.Experience.XPOnly) then
-			local name, id, min, max, value = GetWatchedFactionInfo()
-			bar:SetMinMaxValues(min, max)
-			bar:SetValue(value)
-			bar:EnableMouse()
-			bar:SetStatusBarColor(unpack(self.colorReputation or {FACTION_BAR_COLORS[id].r, FACTION_BAR_COLORS[id].g, FACTION_BAR_COLORS[id].b}))
-
-			if(not bar.MouseOver) then
-				bar:SetAlpha(1)
-			end
-
-			if(bar.Text) then
-				bar.Text:SetFormattedText('%d / %d - %s', value - min, max - min, name)
-			end
-
-			if(bar.Tooltip and bar.MouseOver) then
-				bar:SetScript('OnEnter', function() bar:SetAlpha(1); PlayerRepTip(bar, name, id, value - min, max - min) end)
-				bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
-			elseif(bar.Tooltip and not bar.MouseOver) then
-				bar:SetScript('OnEnter', function() PlayerRepTip(bar, name, id, value - min, max - min) end)
-				bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
-			elseif(bar.MouseOver and not bar.Tooltip) then
-				bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
-				bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
-			end
-		elseif(UnitLevel('player') ~= MAX_PLAYER_LEVEL and not self.Experience.RepOnly) then
-			local min, max = UnitXP('player'), UnitXPMax('player')
-			bar:SetMinMaxValues(0, max)
-			bar:SetValue(min)
-			bar:EnableMouse()
-			bar:SetStatusBarColor(unpack(self.colorExperience or self.colors.health))
-
-			if(not bar.MouseOver) then
-				bar:SetAlpha(1)
-			end
-
-			if(bar.Text) then
-				bar.Text:SetFormattedText('%d / %d', min, max)
-			end
-
-			if(bar.Tooltip and bar.MouseOver) then
-				bar:SetScript('OnEnter', function() bar:SetAlpha(1); PlayerXPTip(bar, min, max) end)
-				bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
-			elseif(bar.Tooltip and not bar.MouseOver) then
-				bar:SetScript('OnEnter', function() PlayerXPTip(bar, min, max) end)
-				bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
-			elseif(bar.MouseOver and not bar.Tooltip) then
-				bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
-				bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
-			end
-		else
-			bar:SetAlpha(0)
+		if(not bar.MouseOver) then
+			bar:SetAlpha(1)
 		end
-	end
-end

-function oUF:UNIT_PET_EXPERIENCE(event, unit)
-	if(self.unit == 'pet') then
-		local bar = self.Experience
-		if(UnitLevel('pet') ~= UnitLevel('player') and english == 'HUNTER' and not self.Experience.RepOnly) then
-			local min, max = GetPetExperience()
-			bar:SetMinMaxValues(0, max)
-			bar:SetValue(min)
-			bar:EnableMouse()
-			bar:SetStatusBarColor(unpack(self.colorExperience or self.colors.health))
-
-			if(not bar.MouseOver) then
-				bar:SetAlpha(1)
-			end
-
-			if(bar.Text) then
-				bar.Text:SetFormattedText('%d / %d', min, max)
-			end
-
-			if(bar.Tooltip and bar.MouseOver) then
-				bar:SetScript('OnEnter', function() bar:SetAlpha(1); PetTip(bar, min, max) end)
-				bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
-			elseif(bar.Tooltip and not bar.MouseOver) then
-				bar:SetScript('OnEnter', function() PetTip(bar, min, max) end)
-				bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
-			elseif(bar.MouseOver and not bar.Tooltip) then
-				bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
-				bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
-			end
-		else
-			bar:SetAlpha(0)
+		if(bar.Text) then
+			bar.Text:SetFormattedText('%d / %d', min, max)
 		end
-	end
-end

-function oUF:UNIT_PET(event, unit)
-	if(unit == 'player') then
-		self.UNIT_PET_EXPERIENCE(self, event, unit)
+		if(bar.Tooltip and bar.MouseOver) then
+			bar:SetScript('OnEnter', function() bar:SetAlpha(1); Tooltip(bar, unit, min, max) end)
+			bar:SetScript('OnLeave', function() bar:SetAlpha(0); GameTooltip:Hide() end)
+		elseif(bar.Tooltip and not bar.MouseOver) then
+			bar:SetScript('OnEnter', function() Tooltip(bar, unit, min, max) end)
+			bar:SetScript('OnLeave', function() GameTooltip:Hide() end)
+		elseif(bar.MouseOver and not bar.Tooltip) then
+			bar:SetScript('OnEnter', function() bar:SetAlpha(1) end)
+			bar:SetScript('OnLeave', function() bar:SetAlpha(0) end)
+		end
 	end
 end

-oUF:RegisterInitCallback(function(self)
+local function Enable(self)
 	local experience = self.Experience
 	if(experience) then
-		self:RegisterEvent('PLAYER_XP_UPDATE')
-		self:RegisterEvent('UNIT_PET_EXPERIENCE')
-		self:RegisterEvent('UPDATE_FACTION')
-		self:RegisterEvent('UNIT_PET')
-		self.UPDATE_FACTION = self.PLAYER_XP_UPDATE
+		self:RegisterEvent('PLAYER_XP_UPDATE', Update)
+		self:RegisterEvent('UNIT_PET_EXPERIENCE', Update)
+		self:RegisterEvent('UNIT_PET', Update)

 		if(not experience:GetStatusBarTexture()) then
 			experience:SetStatusBarTexture([=[Interface\TargetingFrame\UI-StatusBar]=])
@@ -157,9 +81,18 @@ oUF:RegisterInitCallback(function(self)
 		if(experience.MouseOver) then
 			experience:SetAlpha(0)
 		end
+
+		return true
+	end
+end
+
+local function Disable(self)
+	local experience = self.Experience
+	if(experience) then
+		self:UnregisterEvent('PLAYER_XP_UPDATE', Update)
+		self:UnregisterEvent('UNIT_PET_EXPERIENCE', Update)
+		self:UnregisterEvent('UNIT_PET', Update)
 	end
-end)
+end

-oUF:RegisterSubTypeMapping('PLAYER_XP_UPDATE')
-oUF:RegisterSubTypeMapping('UNIT_PET_EXPERIENCE')
-oUF:RegisterSubTypeMapping('UPDATE_FACTION')
\ 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 5129350..4f7e373 100644
--- a/oUF_Experience/oUF_Experience.toc
+++ b/oUF_Experience/oUF_Experience.toc
@@ -2,7 +2,7 @@
 ## Author: p3lim
 ## Version: 30000.wowi:revision
 ## Title: oUF Experience
-## Notes: Experience/Reputation Bar support for oUF layouts.
+## Notes: Experience Bar support for oUF layouts.
 ## RequiredDeps: oUF

 oUF_Experience.lua