Quantcast

Add a demonic fury element

Adrian L Lange [08-19-14 - 16:56]
Add a demonic fury element
Filename
elements/demonicfury.lua
oUF_P3lim.lua
oUF_P3lim.toc
diff --git a/elements/demonicfury.lua b/elements/demonicfury.lua
new file mode 100644
index 0000000..bc88299
--- /dev/null
+++ b/elements/demonicfury.lua
@@ -0,0 +1,88 @@
+local parent, ns = ...
+local oUF = ns.oUF
+
+oUF.Tags.Events['demonicfury'] = 'UNIT_POWER SPELLS_CHANGED'
+oUF.Tags.Methods['demonicfury'] = function(unit)
+	if(not IsPlayerSpell(WARLOCK_METAMORPHOSIS)) then return end
+
+	local cur = UnitPower(unit, SPELL_POWER_DEMONIC_FURY)
+	if(cur > 0) then
+		return cur
+	end
+end
+
+local function UNIT_POWER(self, event, unit, powerType)
+	if(self.unit ~= unit or (event == 'UNIT_POWER_FREQUENT' and powerType ~= 'DEMONIC_FURY')) then
+		return
+	end
+
+	local element = self.DemonicFury
+
+	local cur = UnitPower('player', SPELL_POWER_DEMONIC_FURY)
+	local max = UnitPowerMax('player', SPELL_POWER_DEMONIC_FURY)
+
+	element:SetMinMaxValues(0, max)
+	element:SetValue(cur)
+
+	if(element.PostUpdatePower) then
+		return element:PostUpdatePower(unit, cur, max)
+	end
+end
+
+local function UPDATE_VISIBILITY(self)
+	local element = self.DemonicFury
+
+	local showElement
+	if(IsPlayerSpell(WARLOCK_METAMORPHOSIS)) then
+		showElement = true
+	end
+
+	if(UnitHasVehicleUI('player')) then
+		showElement = false
+	end
+
+	if(showElement) then
+		element:Show()
+	else
+		element:Hide()
+	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.DemonicFury
+	if(element and unit == 'player') then
+		element.__owner = self
+		element.ForceUpdate = ForceUpdate
+
+		self:RegisterEvent('SPELLS_CHANGED', UPDATE_VISIBILITY, true)
+		self:RegisterEvent('UNIT_POWER_FREQUENT', UNIT_POWER)
+
+		if(element:GetObjectType() == 'StatusBar' and not element:GetStatusBarTexture()) then
+			element:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
+		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('DemonicFury', Update, Enable, Disable)
diff --git a/oUF_P3lim.lua b/oUF_P3lim.lua
index 7c9783f..a6a9f1b 100644
--- a/oUF_P3lim.lua
+++ b/oUF_P3lim.lua
@@ -122,7 +122,7 @@ local UnitSpecific = {
 		PowerValue:SetFont(FONT, 8, 'OUTLINEMONOCHROME')
 		PowerValue:SetJustifyH('LEFT')
 		PowerValue.frequentUpdates = 0.1
-		self:Tag(PowerValue, '[p3lim:power][ |cff00ff96>chi][ |cfffff568>holypower][ |cff7b68ee>shadoworbs][ |cffba55d3>p3lim:shards][ |cff997fcc>p3lim:fury<|r][ |cff0090ff>p3lim:mana<|r][ | >p3lim:spell]')
+		self:Tag(PowerValue, '[p3lim:power][ |cff00ff96>chi][ |cfffff568>holypower][ |cff7b68ee>shadoworbs][ |cffba55d3>p3lim:shards][ |cff997fcc>demonicfury<|r][ |cff0090ff>p3lim:mana<|r][ | >p3lim:spell]')

 		local Experience = CreateFrame('StatusBar', nil, self)
 		Experience:SetPoint('BOTTOM', 0, -20)
@@ -220,6 +220,19 @@ local UnitSpecific = {
 				BurningEmbers[index] = Ember
 			end
 			self.BurningEmbers = BurningEmbers
+
+			local DemonicFury = CreateFrame('StatusBar', nil, self)
+			DemonicFury:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', 0, -4)
+			DemonicFury:SetSize(230, 6)
+			DemonicFury:SetStatusBarTexture(TEXTURE)
+			DemonicFury:SetStatusBarColor(3/5, 1/2, 4/5)
+			DemonicFury:SetBackdrop(BACKDROP)
+			DemonicFury:SetBackdropColor(0, 0, 0)
+			self.DemonicFury = DemonicFury
+
+			local DemonicFuryBG = DemonicFury:CreateTexture(nil, 'BORDER')
+			DemonicFuryBG:SetAllPoints()
+			DemonicFuryBG:SetTexture(1/5, 1/6, 1/4)
 		end

 		self.Debuffs.size = 22
diff --git a/oUF_P3lim.toc b/oUF_P3lim.toc
index 83bc713..298f50f 100644
--- a/oUF_P3lim.toc
+++ b/oUF_P3lim.toc
@@ -9,5 +9,6 @@ embeds\oUF_Experience\oUF_Experience.lua

 elements\tags.lua
 elements\burningembers.lua
+elements\demonicfury.lua

 oUF_P3lim.lua