forked from wowgaming/3.3.5-interface-files
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AlternatePowerBar.lua
69 lines (59 loc) · 2.06 KB
/
AlternatePowerBar.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
ADDITIONAL_POWER_BAR_NAME = "MANA";
ADDITIONAL_POWER_BAR_INDEX = 0;
function AlternatePowerBar_OnLoad(self)
self.textLockable = 1;
self.cvar = "playerStatusText";
self.cvarLabel = "STATUS_TEXT_PLAYER";
AlternatePowerBar_Initialize(self);
TextStatusBar_Initialize(self);
end
function AlternatePowerBar_Initialize(self)
if ( not self.powerName ) then
self.powerName = ADDITIONAL_POWER_BAR_NAME;
self.powerIndex = ADDITIONAL_POWER_BAR_INDEX;
end
self:RegisterEvent("UNIT_"..self.powerName);
self:RegisterEvent("UNIT_MAX"..self.powerName);
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("UNIT_DISPLAYPOWER");
SetTextStatusBarText(self, _G[self:GetName().."Text"])
local info = PowerBarColor[self.powerName];
self:SetStatusBarColor(info.r, info.g, info.b);
end
function AlternatePowerBar_OnEvent(self, event, arg1)
local parent = self:GetParent();
if ( event == "UNIT_DISPLAYPOWER" ) then
AlternatePowerBar_UpdatePowerType(self);
elseif ( event=="PLAYER_ENTERING_WORLD" ) then
AlternatePowerBar_UpdateMaxValues(self);
AlternatePowerBar_UpdateValue(self);
AlternatePowerBar_UpdatePowerType(self);
elseif( (event == "UNIT_MAXMANA") and (arg1 == parent.unit) ) then
AlternatePowerBar_UpdateMaxValues(self);
elseif ( self:IsShown() ) then
if ( (event == "UNIT_MANA") and (arg1 == parent.unit) ) then
AlternatePowerBar_UpdateValue(self);
end
end
end
function AlternatePowerBar_OnUpdate(self, elapsed)
AlternatePowerBar_UpdateValue(self);
end
function AlternatePowerBar_UpdateValue(self)
local currmana = UnitPower(self:GetParent().unit,self.powerIndex);
self:SetValue(currmana);
self.value = currmana
end
function AlternatePowerBar_UpdateMaxValues(self)
local maxmana = UnitPowerMax(self:GetParent().unit,self.powerIndex);
self:SetMinMaxValues(0,maxmana);
end
function AlternatePowerBar_UpdatePowerType(self)
if ( (UnitPowerType(self:GetParent().unit) ~= self.powerIndex) and (UnitPowerMax(self:GetParent().unit,self.powerIndex) ~= 0) ) then
self.pauseUpdates = false;
self:Show();
else
self.pauseUpdates = true;
self:Hide();
end
end