PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/misc/altpowerbar.lua

http://github.com/Asphyxia/Tukui
Lua | 56 lines | 49 code | 7 blank | 0 comment | 4 complexity | 25745b04c2ff10074a8836d93081cf18 MD5 | raw file
 1local T, C, L = unpack(select(2, ...))
 2if IsAddOnLoaded("SmellyPowerBar") then return end
 3
 4PlayerPowerBarAlt:UnregisterEvent("UNIT_POWER_BAR_SHOW")
 5PlayerPowerBarAlt:UnregisterEvent("UNIT_POWER_BAR_HIDE")
 6PlayerPowerBarAlt:UnregisterEvent("PLAYER_ENTERING_WORLD")
 7	
 8local AltPowerBar = CreateFrame("Frame", "TukuiAltPowerBar", TukuiInfoLeft)
 9AltPowerBar:SetAllPoints()
10AltPowerBar:SetFrameStrata("HIGH")
11AltPowerBar:SetFrameLevel(2)
12AltPowerBar:EnableMouse(true)
13AltPowerBar:SetTemplate("Default")
14
15local AltPowerBarStatus = CreateFrame("StatusBar", "TukuiAltPowerBarStatus", AltPowerBar)
16AltPowerBarStatus:SetFrameLevel(AltPowerBar:GetFrameLevel() + 1)
17AltPowerBarStatus:SetStatusBarTexture(C.media.normTex)
18AltPowerBarStatus:SetMinMaxValues(0, 100)
19AltPowerBarStatus:Point("TOPLEFT", TukuiInfoLeft, "TOPLEFT", 2, -2)
20AltPowerBarStatus:Point("BOTTOMRIGHT", TukuiInfoLeft, "BOTTOMRIGHT", -2, 2)
21
22local AltPowerText = AltPowerBarStatus:CreateFontString(nil, "OVERLAY")
23AltPowerText:SetFont(C.media.font, 12)
24AltPowerText:Point("CENTER", AltPowerBar, "CENTER", 0, 0)
25AltPowerText:SetShadowColor(0, 0, 0)
26AltPowerText:SetShadowOffset(1.25, -1.25)
27
28AltPowerBar:RegisterEvent("UNIT_POWER")
29AltPowerBar:RegisterEvent("UNIT_POWER_BAR_SHOW")
30AltPowerBar:RegisterEvent("UNIT_POWER_BAR_HIDE")
31AltPowerBar:RegisterEvent("PLAYER_ENTERING_WORLD")
32AltPowerBar:SetScript("OnEvent", function(self)
33	self:UnregisterEvent("PLAYER_ENTERING_WORLD")
34	if UnitAlternatePowerInfo("player") then
35		self:Show()
36	else
37		self:Hide()
38	end
39end)
40
41local TimeSinceLastUpdate = 1
42AltPowerBarStatus:SetScript("OnUpdate", function(self, elapsed)
43	if not AltPowerBar:IsShown() then return end
44	TimeSinceLastUpdate = TimeSinceLastUpdate + elapsed
45	
46	if (TimeSinceLastUpdate >= 1) then
47		self:SetMinMaxValues(0, UnitPowerMax("player", ALTERNATE_POWER_INDEX))
48		local power = UnitPower("player", ALTERNATE_POWER_INDEX)
49		local mpower = UnitPowerMax("player", ALTERNATE_POWER_INDEX)
50		self:SetValue(power)
51		AltPowerText:SetText(power.." / "..mpower)
52		local r, g, b = oUFTukui.ColorGradient(power/mpower, 0,.8,0,.8,.8,0,.8,0,0)
53		AltPowerBarStatus:SetStatusBarColor(r, g, b)
54		self.TimeSinceLastUpdate = 0
55	end
56end)