-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.lua
More file actions
227 lines (185 loc) · 5.04 KB
/
Display.lua
File metadata and controls
227 lines (185 loc) · 5.04 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
local _, Cooldowns = ...
local Display = {}
Display.__index = Display
Cooldowns.Display = Display
local ICON_ATTACH = {
LEFTDOWN = "TOPLEFT",
LEFTUP = "BOTTOMLEFT",
RIGHTDOWN = "TOPRIGHT",
RIGHTUP = "BOTTOMRIGHT"
}
function Display:New(group, spell)
local self = setmetatable({
group = group,
spell = spell,
settings = group.settings,
frame = CreateFrame("Frame", nil, UIParent),
icon = nil,
glowing = false,
bars = {},
count = 0,
active = false
}, Display)
self:BuildIcon()
return self
end
function Display:BuildIcon()
local icon = CreateFrame("BUTTON", nil, self.frame);
icon:SetFrameStrata("BACKGROUND")
icon:SetWidth(24)
icon:SetHeight(24)
local back = icon:CreateTexture(nil, "BACKGROUND")
back:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
back:SetAllPoints()
icon.back = back
local tex = icon:CreateTexture(nil, "MEDIUM")
tex:SetTexture(Cooldowns.spell_data[self.spell][2])
tex:SetTexCoord(0.08, 0.92, 0.08, 0.92)
icon.tex = tex
icon.cd = CreateFrame("Cooldown", nil, icon, "CooldownFrameTemplate")
icon:EnableMouse(false)
self.icon = icon
end
function Display:SetGlow(glow)
if glow and not self.glowing then
self.glowing = true
ActionButton_ShowOverlayGlow(self.icon);
elseif not glow and self.glowing then
self.glowing = false
ActionButton_HideOverlayGlow(self.icon);
end
end
function Display:SetCooldown(from, total)
self.icon.cd:SetCooldown(from, total)
end
function Display:SetDesaturated(desaturated)
if desaturated then
self.icon.tex:SetDesaturated(1)
self.icon.back:SetVertexColor(0.5, 0.5, 0.5, 1)
else
self.icon.tex:SetDesaturated()
local r, g, b = Cooldowns:GetClassColor(Cooldowns.spell_class[self.spell])
self.icon.back:SetVertexColor(r, g, b, 1)
end
end
function Display:Rebuild()
-- Settings
local settings = self.settings
local size = settings.size
local border = settings.border
local spacing = settings.spacing
local width = settings.width
local height = settings.height
local attach = settings.attach
-- Rebuild icon
local icon = self.icon
icon:SetSize(size, size)
icon:ClearAllPoints()
icon:SetPoint(ICON_ATTACH[attach], 0, 0)
icon.tex:SetPoint("TOPLEFT", icon, "TOPLEFT", border, -border)
icon.tex:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -border, border)
icon.cd:SetPoint("TOPLEFT", icon, "TOPLEFT", border, -border)
icon.cd:SetPoint("BOTTOMRIGHT", icon, "BOTTOMRIGHT", -border, border)
-- Rebuild bars
local bars = self.bars
for _, bar in ipairs(bars) do
bar:Hide()
end
local count = 0
local player_guid = UnitGUID("player")
local last_bar
for idx, cd in self:IterateCooldowns() do
count = idx
local bar = bars[idx]
if not bar then
bar = Cooldowns.Bar:New(self)
bars[idx] = bar
end
bar:Rebuild()
bar:Show()
local frame = bar.frame
frame:ClearAllPoints()
if not last_bar then
if attach == "RIGHTUP" then
frame:SetPoint("BOTTOMRIGHT", icon, "BOTTOMLEFT", -math.min(5, spacing), 0)
elseif attach == "RIGHTDOWN" then
frame:SetPoint("TOPRIGHT", icon, "TOPLEFT", -math.min(5, spacing), 0)
elseif attach == "LEFTUP" then
frame:SetPoint("BOTTOMLEFT", icon, "BOTTOMRIGHT", math.min(5, spacing), 0)
else
frame:SetPoint("TOPLEFT", icon, "TOPRIGHT", math.min(5, spacing), 0)
end
else
if attach == "LEFTUP" or attach == "RIGHTUP" then
frame:SetPoint("BOTTOMLEFT", last_bar.frame, "TOPLEFT", 0, 2)
else
frame:SetPoint("TOPLEFT", last_bar.frame, "BOTTOMLEFT", 0, -2)
end
end
last_bar = bar
end
self.count = count
self.active = count > 0
-- Resize frame
local bars_height = count * (height + 2) - 2
self.width = size + spacing + width
self.height = math.max(size, bars_height)
self.frame:SetSize(self.width, self.height)
if self.active then
self:Refresh(true)
else
self:SetDesaturated(true)
self:SetGlow(false)
self:SetCooldown(0, 0)
end
end
function Display:Refresh(didRebuild)
if not self.active then return end
local settings = self.settings
local player_guid = UnitGUID("player")
for idx, cd in self:IterateCooldowns() do
local bar = self.bars[idx]
if not bar and not didRebuild then
return self:Rebuild()
end
bar:SetCooldown(cd)
bar:Refresh()
end
local first = self.bars[1].cd
local active = first:IsActive()
local ready = active or first:IsReady()
self:SetDesaturated(not ready)
self:SetGlow(active)
local left, total, elapsed = first:Cooldown()
if not active and left > 0 then
self:SetCooldown(GetTime() - elapsed, total)
else
self:SetCooldown(0, 0)
end
end
function Display:IterateCooldowns()
if not Cooldowns:IndexHasSpell(self.spell) then
return function() end
end
local settings = self.settings
local player_guid = UnitGUID("player")
local cds = {}
for id, cd in Cooldowns:IterateIndex(self.spell) do
if not settings.exclude_self or (cd.unit.guid ~= player_guid) then
cds[#cds + 1] = cd
if settings.limit and #cds >= settings.limit_nb then
break
end
end
end
return ipairs(cds)
end
function Display:IsActive()
return self.active
end
function Display:Show()
self.frame:Show()
end
function Display:Hide()
self.frame:Hide()
end