-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathORB_RunicPower.lua
More file actions
141 lines (108 loc) · 3.73 KB
/
ORB_RunicPower.lua
File metadata and controls
141 lines (108 loc) · 3.73 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
if select(2, UnitClass("player")) ~= "DEATHKNIGHT" then
return
end
------------------------------------------------------------------------
ORB_RunicPower = ORB_Module:create("RunicPower");
-- Register Disease module
OneRuneBar:RegisterModule(ORB_RunicPower);
------------------------------------------------------------------------
function ORB_RunicPower:OnDisable()
self.frame:SetScript("OnEvent", nil);
self.frame:SetScript("OnUpdate", nil);
end
function ORB_RunicPower:getDefault(val)
if( val == "Position" ) then
return { "CENTER", nil, "CENTER", 160, -25 };
end
return nil;
end
function ORB_RunicPower:CreateFrame()
local f = CreateFrame("frame", nil, UIParent);
-- Set Position and size
f:ClearAllPoints();
f:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
f:Show();
f.owner = self;
self.frame = f;
self:CreateBorder(self.frame);
self:CreateMoveFrame();
-- Runic Power
local rp = self:CreateBar("ORB_RunicPower", self.frame);
rp:SetValue( UnitPower("player") );
rp:SetMinMaxValues( 0, UnitPowerMax("player", 6) );
rp:SetStatusBarColor( unpack(ORB_Config[self.name].Colors) );
-- Text for Runic Power
rp.text:SetText(UnitPower("player") or 0);
self.Bar = rp;
end
function ORB_RunicPower:PositionFrame()
local borderSize = self:Config_GetBorderSize();
local barSize = self:Config_GetBarSize();
self.frame:SetWidth(barSize[1] + 2 * borderSize);
self.frame:SetHeight(barSize[2] + 2 * borderSize);
self.Bar:SetPoint("TOPLEFT", self.frame, "TOPLEFT", borderSize, -(borderSize));
self.Bar:SetPoint("BOTTOMRIGHT", self.frame, "BOTTOMRIGHT", -(borderSize), borderSize);
self:UpdateBorderSizes( self.frame );
end
function ORB_RunicPower:OnInit()
if( not self.frame ) then
self:CreateFrame();
end
self:PositionFrame();
if(self.cfg.Texture) then
self:SetBarTexture(self.cfg.Texture);
end
-- Runic Power
self.frame:RegisterEvent("UNIT_POWER_FREQUENT");
self.frame:RegisterEvent("UNIT_MAXPOWER");
self.frame:SetScript("OnEvent", function(frame, event, ...) frame.owner[event](frame.owner, ...); end );
self.frame:SetScript("OnUpdate", function(frame, elapsed) frame.owner:OnUpdate(elapsed); end );
end
function ORB_RunicPower:getDefault(val)
if( val == "Position" ) then
return ORB_Config_Defaults[self.name].Position or { "CENTER", nil, "CENTER", 0, -150 };
elseif( val == "Color" ) then
return ORB_Config_Defaults[self.name].Colors or { [1] = 0.2, [2] = 0.7, [3] = 1, [4] = 1 };
end
return nil;
end
-- Runic Power EVENTS
function ORB_RunicPower:UNIT_POWER_FREQUENT(unit, power)
if( unit == "player" ) then
local rp = UnitPower("player")
self.Bar:SetMinMaxValues( 0, UnitPowerMax("player", 6) );
self.Bar:SetValue(rp);
self.Bar.text:SetText(rp);
end
end
function ORB_RunicPower:UNIT_MAXPOWER(unit, power)
self.Bar:SetMinMaxValues( 0, UnitPowerMax("player", 6) );
end
-- OnUpdate
function ORB_RunicPower:OnUpdate(elapsed)
self.last = (self.last or 0) + elapsed;
if( self.last > 2.0 ) then
self:UNIT_POWER_FREQUENT("player", "RUNIC_POWER");
self.last = 0;
end
end
function ORB_RunicPower:SetBarTexture(texture)
self.cfg.Texture = texture;
if( not SM ) then
return;
end
self.Bar:SetStatusBarTexture(SM:Fetch(SM.MediaType.STATUSBAR,texture));
self.Bar:GetStatusBarTexture():SetHorizTile(false);
self.Bar:GetStatusBarTexture():SetVertTile(false);
end
function ORB_RunicPower:OnInitOptions(panel, bottomObject)
local btn, tex = self:CreateColorButtonOption(panel, "RPower");
btn:SetPoint( "LEFT", self.TextureDD, "RIGHT", 20, 0 );
end
function ORB_RunicPower:GetConfigColor(module, name)
return unpack(ORB_Config[module.name].Colors);
end
function ORB_RunicPower:SetBarColor(module, name, r, g, b)
module.panel.barcolor[name]:SetColorTexture(r, g, b);
ORB_Config[module.name].Colors = { r, g, b, 1 };
end