-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathORB_Diseases.lua
More file actions
262 lines (211 loc) · 7.92 KB
/
ORB_Diseases.lua
File metadata and controls
262 lines (211 loc) · 7.92 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
if select(2, UnitClass("player")) ~= "DEATHKNIGHT" then
return
end
------------------------------------------------------------------------
local FF_Icon = "Interface\\Icons\\Spell_DeathKnight_FrostFever";
local BP_Icon = "Interface\\Icons\\Spell_DeathKnight_BloodPlague";
local VP_Icon = "Interface\\Icons\\ability_creature_disease_02";
local IconGap = 2;
------------------------------------------------------------------------
ORB_Diseases = ORB_Module:create("Diseases");
-- Register Disease module
OneRuneBar:RegisterModule(ORB_Diseases);
------------------------------------------------------------------------
function ORB_Diseases:OnDisable()
self.frame:SetScript("OnEvent", nil);
self.frame:SetScript("OnUpdate", nil);
end
function ORB_Diseases:getDefault(val)
if( val == "Position" ) then
return { "CENTER", nil, "CENTER", 160, -25 };
end
return nil;
end
function ORB_Diseases:CreateFrame()
local f = CreateFrame("frame", nil, UIParent);
-- Set Position and size
f:ClearAllPoints();
f:SetPoint("CENTER", UIParent, "CENTER", 0, 0);
f.owner = self;
self.frame = f;
self.DiseaseBarContainer = CreateFrame("frame", nil, self.frame)
self.DiseaseBarContainer:Show();
self:CreateBorder(self.DiseaseBarContainer);
-- Create Icons
local icon = self.frame:CreateTexture(nil, "OVERLAY");
icon:ClearAllPoints();
self.icon = icon;
self:CreateMoveFrame();
local bar = self:CreateBar("Disease_Bar", self.frame);
bar:SetValue(0);
bar:Show();
self.DiseaseBar = bar;
end
function ORB_Diseases:PositionFrame()
local borderSize = self:Config_GetBorderSize();
local barSize = self:Config_GetBarSize();
local iconSize = self:Config_GetIconSize();
self.frame:SetWidth(barSize[1] + 2 * borderSize + IconGap + iconSize );
self.frame:SetHeight(iconSize);
self.DiseaseBarContainer:SetHeight(barSize[2] + 2 * borderSize );
self.DiseaseBarContainer:SetPoint("CENTER", self.frame, "CENTER", 0, 0);
self.DiseaseBarContainer:SetPoint("LEFT", self.frame, "LEFT", IconGap + iconSize, 0 );
self.DiseaseBarContainer:SetPoint("RIGHT", self.frame, "RIGHT", 0, 0);
self.icon:SetPoint("TOP", self.frame, "TOP", 0, 0);
self.icon:SetPoint("BOTTOM", self.frame, "BOTTOM", 0, 0);
self.icon:SetPoint("LEFT", self.frame, "LEFT", 0, 0);
self.icon:SetPoint("RIGHT", self.frame, "LEFT", iconSize, 0);
self.DiseaseBar:SetPoint("TOPLEFT", self.DiseaseBarContainer, "TOPLEFT", borderSize, -(borderSize));
self.DiseaseBar:SetPoint("BOTTOMRIGHT", self.DiseaseBarContainer, "BOTTOMRIGHT", -(borderSize), borderSize);
self:UpdateBorderSizes( self.DiseaseBarContainer );
end
function ORB_Diseases:OnInit()
if( not self.frame ) then
self:CreateFrame();
end
self:PositionFrame();
if(self.cfg.Texture) then
self:SetBarTexture(self.cfg.Texture);
end
self:UpdateDiseaseNameAndIcon();
self.frame:RegisterEvent("UNIT_AURA");
self.frame:RegisterEvent("PLAYER_TARGET_CHANGED");
self.frame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED");
self.last = 0;
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 );
self.frame:Hide();
end
function ORB_Diseases:PLAYER_SPECIALIZATION_CHANGED()
self:UpdateDiseaseNameAndIcon();
end
function ORB_Diseases:UpdateDiseaseNameAndIcon()
local specId = GetSpecialization();
if( not specId ) then return; end
if ( specId == 1 ) then
self.icon:SetTexture(BP_Icon);
self.DiseaseBar.id = "Blood Plague";
self.DiseaseBar:SetStatusBarColor( ORB_Config[self.name].Colors["bp"][1], ORB_Config[self.name].Colors["bp"][2], ORB_Config[self.name].Colors["bp"][3] );
elseif( specId == 2 ) then
self.icon:SetTexture(FF_Icon);
self.DiseaseBar.id = "Frost Fever";
self.DiseaseBar:SetStatusBarColor( ORB_Config[self.name].Colors["ff"][1], ORB_Config[self.name].Colors["ff"][2], ORB_Config[self.name].Colors["ff"][3] );
else
self.icon:SetTexture(VP_Icon);
self.DiseaseBar.id = "Virulent Plague";
self.DiseaseBar:SetStatusBarColor( ORB_Config[self.name].Colors["vp"][1], ORB_Config[self.name].Colors["vp"][2], ORB_Config[self.name].Colors["vp"][3] );
end
end
function ORB_Diseases:UpdateDiseaseBar()
local bar = self.DiseaseBar;
local duration, expirationTime, name;
local found = false;
for i = 1, 40 do
name, _, _, _, duration, expirationTime = UnitAura("target", i, "PLAYER|HARMFUL");
if name == bar.id then
found = true;
break;
end
end
if found and expirationTime ~= nil and duration ~= nil then
local val = expirationTime - GetTime();
local valT = format("%.0f", val);
if( val < 5 ) then valT = format("%.1f", val); end
if( val < 0 ) then valT = ""; end;
local val = (val / duration) * 100;
bar:SetValue(val);
bar.text:SetText( valT );
else
bar:SetValue(0);
bar.text:SetText();
end
end
function ORB_Diseases:showBars(v)
if(v) then
self.frame:Show();
self.needUpdate = true;
else
self.frame:Hide();
self.needUpdate = false;
self.DiseaseBar:SetValue(0);
end
end
function ORB_Diseases:UNIT_AURA(unit)
end
function ORB_Diseases:PLAYER_TARGET_CHANGED()
if( UnitExists("target")) then
self:showBars(true);
else
self:showBars(false);
end
end
function ORB_Diseases:OnUpdate(elapsed)
self.last = self.last + elapsed;
if( self.last > 0.01 ) then
if( self.needUpdate) then
self:UpdateDiseaseBar();
end
self.last = 0;
end
end
function ORB_Diseases:SetBarTexture(texture)
self.cfg.Texture = texture;
if( not SM ) then
return;
end
self.DiseaseBar:SetStatusBarTexture(SM:Fetch(SM.MediaType.STATUSBAR,texture));
self.DiseaseBar:GetStatusBarTexture():SetHorizTile(false);
self.DiseaseBar:GetStatusBarTexture():SetVertTile(false);
end
function ORB_Diseases:OnInitOptions(panel, bottomObject)
local btn, tex = self:CreateColorButtonOption(panel, "FFever");
btn:SetPoint( "LEFT", self.TextureDD, "RIGHT", 20, 0 );
local btn2, tex2 = self:CreateColorButtonOption(panel, "BPlague");
btn2:SetPoint( "LEFT", tex, "RIGHT", 20, 0 );
local btn3, tex3 = self:CreateColorButtonOption(panel, "VPlague");
btn3:SetPoint( "LEFT", tex2, "RIGHT", 20, 0 );
local iconSizeLabel = self:CreateLabel( panel, "Icon Size:");
iconSizeLabel:SetPoint("TOPLEFT", bottomObject, "BOTTOMLEFT", 0, -20);
local barHeightBox = self:CreateEditBox( panel, "ORB_IconSizeEditBox"..self.name,
function(self) return self:Config_GetIconSize(); end,
function(self, value) self:Config_SetIconSize(value); end );
barHeightBox:SetPoint("TOPLEFT", iconSizeLabel, "TOPRIGHT", 4, 0);
barHeightBox:SetPoint("BOTTOMLEFT", iconSizeLabel, "BOTTOMRIGHT", 0, 0);
end
function ORB_Diseases:GetConfigColor(module, name)
if( name == "FFever" ) then
if( not ORB_Config[module.name].Colors["ff"] ) then
ORB_Config[module.name].Colors["ff"] = ORB_Config_Defaults[module.name].Colors["ff"];
end
return unpack(ORB_Config[module.name].Colors["ff"]);
elseif( name == "BPlague" ) then
if( not ORB_Config[module.name].Colors["bp"] ) then
ORB_Config[module.name].Colors["bp"] = ORB_Config_Defaults[module.name].Colors["bp"];
end
return unpack(ORB_Config[module.name].Colors["bp"]);
elseif( name == "VPlague" ) then
if( not ORB_Config[module.name].Colors["vp"] ) then
ORB_Config[module.name].Colors["vp"] = ORB_Config_Defaults[module.name].Colors["vp"];
end
return unpack(ORB_Config[module.name].Colors["vp"]);
end
module:Print("ORB BUG: Didn't find color config name: "..name);
end
function ORB_Diseases:SetBarColor(module, name, r, g, b)
module.panel.barcolor[name]:SetColorTexture(r, g, b);
local newColor = {r, g, b, 1};
if( name == "FFever" ) then
ORB_Config[module.name].Colors["ff"] = newColor;
elseif( name == "BPlague" ) then
ORB_Config[module.name].Colors["bp"] = newColor;
elseif( name == "VPlague" ) then
ORB_Config[module.name].Colors["np"] = newColor;
end
end
function ORB_Module:Config_GetIconSize()
return ORB_Config[self.name].IconSize or ORB_Config_Defaults[self.name].IconSize;
end
function ORB_Module:Config_SetIconSize(val)
ORB_Config[self.name].IconSize = val;
self:PositionFrame();
end