Quantcast

Move the burning embers into it's own element

Adrian L Lange [08-19-14 - 16:54]
Move the burning embers into it's own element
Filename
elements/burningembers.lua
oUF_P3lim.lua
oUF_P3lim.toc
diff --git a/elements/burningembers.lua b/elements/burningembers.lua
new file mode 100644
index 0000000..fe8a37f
--- /dev/null
+++ b/elements/burningembers.lua
@@ -0,0 +1,92 @@
+local parent, ns = ...
+local oUF = ns.oUF
+
+local function UNIT_POWER(self, event, unit, powerType)
+	if(self.unit ~= unit or (event == 'UNIT_POWER_FREQUENT' and powerType ~= 'BURNING_EMBERS')) then
+		return
+	end
+
+	local element = self.BurningEmbers
+
+	local total = UnitPower('player', SPELL_POWER_BURNING_EMBERS, true)
+	local max = UnitPowerMax('player', SPELL_POWER_BURNING_EMBERS, true)
+
+	local cur = total
+	for index = 1, 4 do
+		element[index]:SetValue(cur)
+		cur = cur - 10
+	end
+
+	if(element.PostUpdatePower) then
+		return element:PostUpdatePower(unit, total, max)
+	end
+end
+
+local function UPDATE_VISIBILITY(self)
+	local element = self.BurningEmbers
+
+	local showElement
+	if(IsPlayerSpell(WARLOCK_BURNING_EMBERS)) then
+		showElement = true
+	end
+
+	if(UnitHasVehicleUI('player')) then
+		showElement = false
+	end
+
+	if(showElement) then
+		for index = 1, 4 do
+			element[index]:Show()
+		end
+	else
+		for index = 1, 4 do
+			element[index]:Hide()
+		end
+	end
+
+	if(element.PostUpdateVisibility) then
+		return element:PostUpdateVisibility(self.unit)
+	end
+end
+
+local function Update(self, ...)
+	UPDATE_VISIBILITY(self, ...)
+	UNIT_POWER(self, ...)
+end
+
+local function ForceUpdate(element)
+	return Update(element.__owner, 'ForceUpdate', element.__owner.unit)
+end
+
+local function Enable(self, unit)
+	local element = self.BurningEmbers
+	if(element and unit == 'player') then
+		element.__owner = self
+		element.ForceUpdate = ForceUpdate
+
+		for index = 1, 4 do
+			element[index]:SetMinMaxValues(0, 10)
+		end
+
+		self:RegisterEvent('SPELLS_CHANGED', UPDATE_VISIBILITY, true)
+		self:RegisterEvent('UNIT_POWER_FREQUENT', UNIT_POWER)
+
+		for index = 1, 4 do
+			local Ember = element[index]
+			if(Ember:GetObjectType() == 'StatusBar' and not Ember:GetStatusBarTexture()) then
+				Ember:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
+			end
+		end
+
+		return true
+	end
+end
+
+local function Disable(self)
+	if(self.BurningEmbers) then
+		self:UnregisterEvent('SPELLS_CHANGED', UPDATE_VISIBILITY)
+		self:UnregisterEvent('UNIT_POWER_FREQUENT', UNIT_POWER)
+	end
+end
+
+oUF:AddElement('BurningEmbers', Update, Enable, Disable)
diff --git a/oUF_P3lim.lua b/oUF_P3lim.lua
index 68e6908..7c9783f 100644
--- a/oUF_P3lim.lua
+++ b/oUF_P3lim.lua
@@ -28,32 +28,6 @@ local function PostUpdateCast(element, unit)
 	end
 end

-local function UpdateEmbers(self, event, unit, powerType)
-	if(not self:IsShown()) then return end
-	if(powerType ~= 'BURNING_EMBERS') then return end
-
-	local cur = UnitPower(unit, SPELL_POWER_BURNING_EMBERS, true)
-	local max = UnitPowerMax(unit, SPELL_POWER_BURNING_EMBERS, true)
-
-	for index = 1, 4 do
-		local Ember = self[index]
-		Ember:SetMinMaxValues(0, 10)
-		Ember:SetValue(cur)
-
-		cur = cur - 10
-	end
-end
-
-local function UpdateEmbersVisibility(self)
-	if(GetSpecialization() == SPEC_WARLOCK_DESTRUCTION and UnitLevel('player') >= 42 and not (UnitHasVehicleUI('player') or UnitIsDeadOrGhost('player'))) then
-		self.BurningEmbers:Show()
-
-		UpdateEmbers(self.BurningEmbers, nil, 'player', 'BURNING_EMBERS')
-	else
-		self.BurningEmbers:Hide()
-	end
-end
-
 local function UpdateAura(self, elapsed)
 	if(self.expiration) then
 		if(self.expiration < 60) then
@@ -218,38 +192,34 @@ local UnitSpecific = {
 			SolarBar:SetAllPoints()
 			SolarBar:SetTexture(1/4, 2/5, 5/6)
 		elseif(playerClass == 'WARLOCK') then
-			local BurningEmbers = CreateFrame('Frame', nil, self)
-			BurningEmbers:SetPoint('BOTTOM', 0, -10)
-			BurningEmbers:SetSize(230, 6)
-			BurningEmbers:SetBackdrop(BACKDROP)
-			BurningEmbers:SetBackdropColor(0, 0, 0)
-			BurningEmbers:RegisterUnitEvent('UNIT_POWER_FREQUENT', 'player')
-			BurningEmbers:RegisterUnitEvent('UNIT_DISPLAYPOWER', 'player')
-			BurningEmbers:SetScript('OnEvent', UpdateEmbers)
-			self.BurningEmbers = BurningEmbers
-
+			local BurningEmbers = {}
 			for index = 1, 4 do
-				local Ember = CreateFrame('StatusBar', nil, BurningEmbers)
-				Ember:SetPoint('BOTTOMLEFT', (index - 1) * 58, 0)
-				Ember:SetSize(index == 4 and 56 or 57, 6)
+				local Ember = CreateFrame('StatusBar', nil, self)
+				Ember:SetSize(index > 2 and 55 or 54, 6)
 				Ember:SetStatusBarTexture(TEXTURE)
-				BurningEmbers[index] = Ember
+				Ember:SetBackdrop(BACKDROP)
+				Ember:SetBackdropColor(0, 0, 0)
+
+				if(index == 1) then
+					Ember:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -4)
+				else
+					Ember:SetPoint('LEFT', BurningEmbers[index - 1], 'RIGHT', 4, 0)
+				end

 				local EmberBG = Ember:CreateTexture(nil, 'BORDER')
 				EmberBG:SetAllPoints()

-				if(IsSpellKnown(101508)) then
+				if(IsSpellKnown(WARLOCK_GREEN_FIRE)) then
 					Ember:SetStatusBarColor(1/2, 3/4, 0.1)
 					EmberBG:SetTexture(1/5, 1/4, 0)
 				else
 					Ember:SetStatusBarColor(2/3, 1/5, 0)
 					EmberBG:SetTexture(1/7, 0.1, 0.1)
 				end
-			end

-			self:RegisterEvent('UNIT_EXITED_VEHICLE', UpdateEmbersVisibility)
-			self:RegisterEvent('UNIT_ENTERED_VEHICLE', UpdateEmbersVisibility)
-			self:RegisterEvent('SPELLS_CHANGED', UpdateEmbersVisibility)
+				BurningEmbers[index] = Ember
+			end
+			self.BurningEmbers = BurningEmbers
 		end

 		self.Debuffs.size = 22
diff --git a/oUF_P3lim.toc b/oUF_P3lim.toc
index 93666d7..83bc713 100644
--- a/oUF_P3lim.toc
+++ b/oUF_P3lim.toc
@@ -8,5 +8,6 @@ embeds\oUF\oUF.xml
 embeds\oUF_Experience\oUF_Experience.lua

 elements\tags.lua
+elements\burningembers.lua

 oUF_P3lim.lua