PageRenderTime 153ms CodeModel.GetById 131ms app.highlight 5ms RepoModel.GetById 15ms app.codeStats 0ms

/Tukui/modules/unitframes/core/oUF/elements/runebar.lua

http://github.com/Asphyxia/Tukui
Lua | 110 lines | 81 code | 20 blank | 9 comment | 10 complexity | 2bc84fead28bd24df91f41dbf54de8f4 MD5 | raw file
  1--[[ Runebar:
  2	Authors: Zariel, Haste
  3]]
  4
  5if select(2, UnitClass("player")) ~= "DEATHKNIGHT" then return end
  6
  7local parent, ns = ...
  8local oUF = ns.oUF
  9
 10oUF.colors.runes = {
 11	{1, 0, 0};
 12	{0, .5, 0};
 13	{0, 1, 1};
 14	{.9, .1, 1};
 15}
 16
 17local OnUpdate = function(self, elapsed)
 18	local duration = self.duration + elapsed
 19	if(duration >= self.max) then
 20		return self:SetScript("OnUpdate", nil)
 21	else
 22		self.duration = duration
 23		return self:SetValue(duration)
 24	end
 25end
 26
 27local UpdateType = function(self, event, rune, alt)
 28	local colors = self.colors.runes[GetRuneType(rune) or alt]
 29	local rune = self.Runes[rune]
 30	local r, g, b = colors[1], colors[2], colors[3]
 31
 32	rune:SetStatusBarColor(r, g, b)
 33
 34	if(rune.bg) then
 35		local mu = rune.bg.multiplier or 1
 36		rune.bg:SetVertexColor(r * mu, g * mu, b * mu)
 37	end
 38end
 39
 40local UpdateRune = function(self, event, rid)
 41	local rune = self.Runes[rid]
 42	if(rune) then
 43		local start, duration, runeReady = GetRuneCooldown(rune:GetID())
 44		if(runeReady) then
 45			rune:SetMinMaxValues(0, 1)
 46			rune:SetValue(1)
 47			rune:SetScript("OnUpdate", nil)
 48		else
 49			rune.duration = GetTime() - start
 50			rune.max = duration
 51			rune:SetMinMaxValues(1, duration)
 52			rune:SetScript("OnUpdate", OnUpdate)
 53		end
 54	end
 55end
 56
 57local Update = function(self, event)
 58	for i=1, 6 do
 59		UpdateRune(self, event, i)
 60	end
 61end
 62
 63local ForceUpdate = function(element)
 64	return Update(element.__owner, 'ForceUpdate')
 65end
 66
 67local Enable = function(self, unit)
 68	local runes = self.Runes
 69	if(runes and unit == 'player') then
 70		runes.__owner = self
 71		runes.ForceUpdate = ForceUpdate
 72
 73		for i=1, 6 do
 74			local rune = runes[i]
 75			rune:SetID(i)
 76			-- From my minor testing this is a okey solution. A full login always remove
 77			-- the death runes, or at least the clients knowledge about them.
 78			UpdateType(self, nil, i, math.floor((i+1)/2))
 79
 80			if(not rune:GetStatusBarTexture()) then
 81				rune:SetStatusBarTexture[[Interface\TargetingFrame\UI-StatusBar]]
 82			end
 83		end
 84
 85		self:RegisterEvent("RUNE_POWER_UPDATE", UpdateRune)
 86		self:RegisterEvent("RUNE_TYPE_UPDATE", UpdateType)
 87
 88		runes:Show()
 89
 90		-- oUF leaves the vehicle events registered on the player frame, so
 91		-- buffs and such are correctly updated when entering/exiting vehicles.
 92		--
 93		-- This however makes the code also show/hide the RuneFrame.
 94		RuneFrame.Show = RuneFrame.Hide
 95		RuneFrame:Hide()
 96
 97		return true
 98	end
 99end
100
101local Disable = function(self)
102	self.Runes:Hide()
103	RuneFrame.Show = nil
104	RuneFrame:Show()
105
106	self:UnregisterEvent("RUNE_POWER_UPDATE", UpdateRune)
107	self:UnregisterEvent("RUNE_TYPE_UPDATE", UpdateType)
108end
109
110oUF:AddElement("Runes", Update, Enable, Disable)