-
Notifications
You must be signed in to change notification settings - Fork 0
/
FuryMonitor.AbilityFrame.lua
305 lines (268 loc) · 9.74 KB
/
FuryMonitor.AbilityFrame.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
--[[
This program is free software. It comes without any warranty, to
the extent permitted by applicable law. You can redistribute it
and/or modify it under the terms of the Do What The Fuck You Want
To Public Liscence, Version 2, as published by Sam Hocevar. See
http://sam.zoy.org/wtfpl/COPYING for more details.
]]--
FuryMonitor.AbilityFrame = {};
FuryMonitor.AbilityFrame.__index = FuryMonitor.AbilityFrame;
FuryMonitor.AbilityFrame.Active = {};
FuryMonitor.AbilityFrame.Inactive = {};
function FuryMonitor.AbilityFrame:new(ability, useId, time, parentFrame, rageStatus)
local instance = nil;
if #FuryMonitor.AbilityFrame.Inactive > 0 then
-- We have an old frame that is not in use, so we'll use that
instance = FuryMonitor.AbilityFrame.Inactive[#FuryMonitor.AbilityFrame.Inactive];
table.remove(FuryMonitor.AbilityFrame.Inactive, #FuryMonitor.AbilityFrame.Inactive);
else
local fm = FuryMonitor.Main:GetInstance();
-- We've run out of frames, so create a new one
local iconFrame = CreateFrame("Frame", nil, fm:GetFrame());
local rageIndicatorFrame = CreateFrame("Frame", nil, fm:GetFrame());
local damageTextFrame = CreateFrame("Frame", nil, fm:GetFrame());
local text = damageTextFrame:CreateFontString(nil);
local members = {
_ability = nil,
_time = nil,
_iconFrame = iconFrame,
_damageTextFrame = damageTextFrame,
_damageText = text,
_rageIndicatorFrame = rageIndicatorFrame,
_rageStatus = nil,
_parent = nil,
_useId = nil,
_x = 0,
_y = 0,
_active = nil
};
instance = setmetatable(members, FuryMonitor.AbilityFrame);
end
instance:SetAbility(ability);
instance:SetUseId(useId);
instance._time = time;
instance._parent = parentFrame;
instance._active = true;
instance._rageStatus = rageStatus;
instance:LoadFrameConfiguration();
-- Add the instance to the table of active instances
if not FuryMonitor.AbilityFrame.Active[instance:GetAbility()] then
FuryMonitor.AbilityFrame.Active[instance:GetAbility()] = {};
end
FuryMonitor.AbilityFrame.Active[instance:GetAbility()][instance:GetUseId()]
= instance;
-- Set up event subscriptions
FuryMonitor.Main:GetInstance():SubscribeToConfigurationChanges(instance);
FuryMonitor.Main:GetInstance():SubscribeToStatChanges(instance);
return instance;
end
function FuryMonitor.AbilityFrame:recycle()
-- Cancel event subscriptions
FuryMonitor.Main:GetInstance():UnSubscribeToConfigurationChanges(self);
FuryMonitor.Main:GetInstance():UnSubscribeToStatChanges(self);
self._active = false;
-- Add this to the inactive list
table.insert(FuryMonitor.AbilityFrame.Inactive, self);
-- Remove this from the active list
FuryMonitor.AbilityFrame.Active[self:GetAbility()][self:GetUseId()] = nil;
self:GetIconFrame():Hide();
self:GetDamageText():Hide();
self:GetRageIndicatorFrame():Hide();
end
function FuryMonitor.AbilityFrame:LoadFrameConfiguration()
-- Set up the icon frame
self:GetIconFrame():SetWidth(FuryMonitor.Configuration.AbilityFrame.Width);
self:GetIconFrame():SetHeight(FuryMonitor.Configuration.AbilityFrame.Height);
self:GetIconFrame():SetBackdrop({
bgFile = self:GetAbility():GetTexture(),
edgeFile = FuryMonitor.Configuration.AbilityFrame.EdgeFile,
edgeSize = FuryMonitor.Configuration.AbilityFrame.EdgeSize,
tile = 0,
tileSize = math.max(
FuryMonitor.Configuration.AbilityFrame.Width,
FuryMonitor.Configuration.AbilityFrame.Height
),
insets = {
top = FuryMonitor.Configuration.AbilityFrame.BackgroundInset,
bottom = FuryMonitor.Configuration.AbilityFrame.BackgroundInset,
left = FuryMonitor.Configuration.AbilityFrame.BackgroundInset,
right = FuryMonitor.Configuration.AbilityFrame.BackgroundInset
}
});
self:GetIconFrame():SetAlpha(
FuryMonitor.Configuration.AbilityFrame.Alpha
);
self:GetIconFrame():SetFrameStrata(FuryMonitor.Configuration.Display.FrameStrata);
self:GetIconFrame():SetFrameLevel(
FuryMonitor.Configuration.Display.FrameLevel
+ 2
);
if FuryMonitor.Configuration.Enabled then
self:GetIconFrame():Show();
else
self:GetIconFrame():Hide();
end
-- Set up rage indicator
self:GetRageIndicatorFrame():SetWidth(
FuryMonitor.Configuration.AbilityFrame.RageIndicator.Width
);
self:GetRageIndicatorFrame():SetHeight(
FuryMonitor.Configuration.AbilityFrame.RageIndicator.Height
);
self:GetRageIndicatorFrame():SetBackdrop({
bgFile = FuryMonitor.Configuration.AbilityFrame.RageIndicator.BackgroundFile,
tile = 0,
insets = {
top = FuryMonitor.Configuration.AbilityFrame.RageIndicator.BackgroundInset,
bottom = FuryMonitor.Configuration.AbilityFrame.RageIndicator.BackgroundInset,
left = FuryMonitor.Configuration.AbilityFrame.RageIndicator.BackgroundInset,
right = FuryMonitor.Configuration.AbilityFrame.RageIndicator.BackgroundInset
}
});
self:GetRageIndicatorFrame():SetPoint(
FuryMonitor.Configuration.AbilityFrame.RageIndicator.Position,
self:GetIconFrame(),
FuryMonitor.Configuration.AbilityFrame.RageIndicator.Position
);
self:GetRageIndicatorFrame():SetFrameStrata(FuryMonitor.Configuration.Display.FrameStrata);
self:GetRageIndicatorFrame():SetFrameLevel(
FuryMonitor.Configuration.Display.FrameLevel
+ 3
);
self:UpdateRageIndicator();
if FuryMonitor.Configuration.AbilityFrame.RageIndicator.Show
and FuryMonitor.Configuration.Enabled and not self:GetAbility():IsFake() then
self:GetRageIndicatorFrame():Show();
else
self:GetRageIndicatorFrame():Hide();
end
-- Set up damage text
self:GetDamageTextFrame():SetFrameStrata(FuryMonitor.Configuration.Display.FrameStrata);
self:GetDamageTextFrame():SetFrameLevel(
FuryMonitor.Configuration.Display.FrameLevel
+ 4
);
self:GetDamageText():SetFont(
FuryMonitor.Configuration.AbilityFrame.FontFile,
FuryMonitor.Configuration.AbilityFrame.FontSize,
"OUTLINE"
);
self:GetDamageText():SetTextColor(
FuryMonitor.Configuration.AbilityFrame.FontColor.R,
FuryMonitor.Configuration.AbilityFrame.FontColor.G,
FuryMonitor.Configuration.AbilityFrame.FontColor.B,
FuryMonitor.Configuration.AbilityFrame.FontColor.A
);
self:GetDamageText():SetPoint("TOP", self:GetIconFrame(), "CENTER", 0,
- FuryMonitor.Util.round(FuryMonitor.Configuration.AbilityFrame.Height * 0.5)
+ FuryMonitor.Configuration.AbilityFrame.FontSize
);
self:UpdateDamageText();
if FuryMonitor.Configuration.Enabled then
self:GetDamageText():Show();
else
self:GetDamageText():Hide();
end
end
function FuryMonitor.AbilityFrame:OnConfigurationChanged()
self:LoadFrameConfiguration();
end
function FuryMonitor.AbilityFrame:OnStatsChanged()
self:UpdateDamageText();
self:UpdateRageIndicator();
end
function FuryMonitor.AbilityFrame.RecycleOldAbilityFrames()
-- Recycles AbilityFrames in the Active table whose UseIds are lower
-- than the current (pending) usecount of the ability
-- USE BEFORE DISABLING THEORETICAL USE
for i, abilityTable in pairs(FuryMonitor.AbilityFrame.Active) do
for k, af in pairs(abilityTable) do
if af:GetUseId() < af:GetAbility():GetUseCount() then
af:recycle();
end
end
end
end
function FuryMonitor.AbilityFrame.RecycleUnusedAbilityFrames()
-- Recycles AbilityFrames in the Active table whose UseIds are higher
-- than or equal to the current (pending) usecount of their ability
-- USE AFTER DISABLING THEORETICAL USE
for i, abilityTable in pairs(FuryMonitor.AbilityFrame.Active) do
for j, af in pairs(abilityTable) do
if af:GetUseId() >= af:GetAbility():GetUseCount() then
af:recycle();
end
end
end
end
function FuryMonitor.AbilityFrame:UpdateDamageText()
local damage = self:GetAbility():GetDamage();
local text = damage;
if damage <= 0 then
text = "";
end
self:GetDamageText():SetText(text);
end
function FuryMonitor.AbilityFrame:UpdateRageIndicator()
local color = nil;
if self._rageStatus then
color = FuryMonitor.Configuration.AbilityFrame.RageIndicator.OnColor;
else
color = FuryMonitor.Configuration.AbilityFrame.RageIndicator.OffColor;
end
self:GetRageIndicatorFrame():SetBackdropColor(
color.R, color.G, color.B, color.A
);
end
function FuryMonitor.AbilityFrame:GetAbilityFrame(ability, useNumber)
if (not FuryMonitor.AbilityFrame.Active[ability])
or (not FuryMonitor.AbilityFrame.Active[ability][useNumber]) then
return nil;
end
return FuryMonitor.AbilityFrame.Active[ability][useNumber]
end
function FuryMonitor.AbilityFrame:GetAbility()
return self._ability;
end
function FuryMonitor.AbilityFrame:SetAbility(ability)
self._ability = ability;
end
function FuryMonitor.AbilityFrame:GetIconFrame()
return self._iconFrame;
end
function FuryMonitor.AbilityFrame:GetRageIndicatorFrame()
return self._rageIndicatorFrame;
end
function FuryMonitor.AbilityFrame:GetDamageText()
return self._damageText;
end
function FuryMonitor.AbilityFrame:GetParentFrame()
return self._parent;
end
function FuryMonitor.AbilityFrame:GetDamageTextFrame()
return self._damageTextFrame;
end
function FuryMonitor.AbilityFrame:GetUseId()
return self._useId;
end
function FuryMonitor.AbilityFrame:SetUseId(useId)
self._useId = useId;
end
function FuryMonitor.AbilityFrame:SetRageAvailable(available)
self._rageStatus = available;
self:UpdateRageIndicator();
end
function FuryMonitor.AbilityFrame:GetX(value)
return self._x;
end
function FuryMonitor.AbilityFrame:SetX(value)
self._x = value;
self:GetIconFrame():SetPoint("TOPLEFT", self:GetParentFrame(), "TOPLEFT", self:GetX(), self:GetY());
end
function FuryMonitor.AbilityFrame:GetY()
return self._y;
end
function FuryMonitor.AbilityFrame:SetY(value)
self._y = -value;
self:GetIconFrame():SetPoint("TOPLEFT", self:GetParentFrame(), "TOPLEFT", self:GetX(), self:GetY());
end