-
Notifications
You must be signed in to change notification settings - Fork 0
/
cooldown_bar.lua
276 lines (230 loc) · 7.25 KB
/
cooldown_bar.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
ZAF = Zed_ArenaFrames
local MAX_ICONS = 10
local PVP_TRINKET_TEXTURE = "Interface\\Icons\\INV_Jewelry_TrinketPVP_02"
-- Some of cooldowns are already in cooldown tracker
-- you can add , cooldown = time parameter just incase or overwrite existing cd
local BAR_SETUP = {
["Warrior"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE, cooldown = 120, },
{ name = "Pummel", icon = select(3,GetSpellInfo(6552)), cooldown = 10,},
{ name = "Spell Reflection", icon = select(3,GetSpellInfo(23920)) },
-- { ID = 6552, cooldown=10 }, This works as well, name + texture or spell id
},
["Death Knight"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Mind Freeze", icon = select(3,GetSpellInfo(47528)) },
{ name = "Death Grip", icon = select(3,GetSpellInfo(49576)) },
},
["Rogue"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Kick", icon = select(3,GetSpellInfo(1766)) },
{ name = "Shadowstep", icon = select(3,GetSpellInfo(36554)) },
{ ID = 51713, cooldown = 60, }, -- Shadowdance
},
["Hunter"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Scatter Shot", icon = select(3,GetSpellInfo(19503)) },
},
["Shaman"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Wind Shear", icon = select(3,GetSpellInfo(57994)) },
{ name = "Grounding Totem", icon = select(3,GetSpellInfo(8177)) },
},
["Druid"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Barkskin", icon = select(3,GetSpellInfo(22812)), cooldown=60 },
},
["Paladin"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Holy Shock", icon = select(3,GetSpellInfo(48825)) },
{ name = "Hammer of Justice", icon = select(3,GetSpellInfo(10308)) },
{ name = "Hand of Freedom", icon = select(3,GetSpellInfo(1044)) },
},
["Warlock"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Spell Lock", icon = select(3,GetSpellInfo(19647)) },
{ name = "Shadowfury", icon = select(3,GetSpellInfo(30283)), },
},
["Priest"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Psychic Scream", icon = select(3,GetSpellInfo(10890)) },
{ name = "Penance", icon = select(3,GetSpellInfo(53007)) },
},
["Mage"] = {
{ name = "PvP Trinket", icon = PVP_TRINKET_TEXTURE },
{ name = "Counterspell", icon = select(3,GetSpellInfo(2139)) },
{ name = "Deep Freeze", icon = select(3,GetSpellInfo(44572)) },
{ name = "Blink", icon = select(3,GetSpellInfo(1953)) },
},
}
-- validate bar settings
for class, bars in pairs(BAR_SETUP) do
for i, bar in pairs(bars) do
local spellName = bar.name or GetSpellInfo(bar.ID)
local cd = bar.cooldown
if cd then
ZAF.spell_cooldown[spellName] = cd
end
if not ZAF.spell_cooldown[spellName] then
print("Zed_ArenaFrames: Missing cooldown parameter for ", spellName," in BAR_SETUP")
end
if bar.ID then
bar.icon = select(3, GetSpellInfo(bar.ID))
end
end
end
local ZAF = Zed_ArenaFrames
ZAF.CD = {}
Zed_ArenaFrames.CooldownBars = {}
function Zed_ArenaFrames.CD:SetBarPoint(POINT)
for BAR, val in pairs(Zed_ArenaFrames.CooldownBars) do
end
end
function Zed_ArenaFrames.CD:SetPerRow(rows)
Zed_ArenaFramesDB.CD.PER_ROW = rows
local ICON_SIZE = Zed_ArenaFramesDB.CD.SIZE
for BAR, val in pairs(Zed_ArenaFrames.CooldownBars) do
for i=1,MAX_ICONS do
icon = BAR[i]
icon:ClearAllPoints()
if i>1 then
icon:SetPoint("RIGHT", BAR[i-1], "RIGHT", ICON_SIZE,0)
else
icon:SetPoint("CENTER", BAR)
end
if i > 1 and (i-1)%rows == 0 then
icon:ClearAllPoints()
icon:SetPoint("BOTTOM", BAR[i-rows], "BOTTOM", 0, -ICON_SIZE)
end
end
end
end
function Zed_ArenaFrames.CD:SetIconSize(size)
Zed_ArenaFramesDB.CD.SIZE = size
for BAR, val in pairs(Zed_ArenaFrames.CooldownBars) do
for i=1,MAX_ICONS do
icon = BAR[i]
icon:SetSize(size,size)
end
end
Zed_ArenaFrames.CD:SetPerRow(Zed_ArenaFramesDB.CD.PER_ROW )
end
local PVPTRINKETS = {
["Every Man for Himself"] = true,
["PvP Trinket"] = true,
}
local function Create_CooldownBar(parent)
local PER_ROW = Zed_ArenaFramesDB.CD.PER_ROW
local ICON_SIZE = Zed_ArenaFramesDB.CD.SIZE
local BAR = CreateFrame("Frame",nil, parent)
BAR:SetSize(25,25)
BAR.spells = {}
BAR.unit = parent.unit
ZAF.Cooldowns:Register(BAR,true)
for i=1,MAX_ICONS do
-- ICON
local icon = CreateFrame("Frame", nil,BAR)
BAR[i] = icon
if i>1 then
icon:SetPoint("RIGHT", BAR[i-1], "RIGHT", ICON_SIZE,0)
else
icon:SetPoint("CENTER", BAR)
end
if i > 1 and (i-1)%PER_ROW == 0 then
icon:ClearAllPoints()
icon:SetPoint("BOTTOM", BAR[i-PER_ROW], "BOTTOM", 0, -ICON_SIZE)
end
icon:SetSize(ICON_SIZE,ICON_SIZE)
-- TEXTURE
icon.texture = icon:CreateTexture("ARTWORK")
icon.texture:SetAllPoints(icon)
icon.texture:SetTexture( select(3,GetSpellInfo(57994)))
icon.texture:SetTexCoord(0.07,0.9,0.07,0.90) -- remove borders
icon.texture:SetDrawLayer("BACKGROUND")
-- COOLDOWN
icon.cd = CreateFrame("Cooldown")
icon.cd:ClearAllPoints()
icon.cd:SetAllPoints(icon)
icon.cd:SetFrameStrata("HIGH")
icon.cd:SetAlpha(1)
-- TEXT
icon.text = icon:CreateFontString(nil,"ARTWORK")
icon.text:SetFont(STANDARD_TEXT_FONT,16,"OUTLINE")
icon.text:SetPoint("CENTER", frame,0, 0)
icon.text:SetText("")
icon.text:SetTextColor(0.8 ,0,0,1)
--icon.cd:SetReverse(true)
-- BORDER
icon.border = CreateFrame("Frame", nil, icon)
icon.border:SetPoint("CENTER", icon)
icon.border:SetBackdrop({
bgFile=nil,
edgeFile="Interface\\ChatFrame\\ChatFrameBackground",
tile=true,
tileSize=5,
edgeSize= 1,
})
icon.border:SetBackdropColor(0,0,0)
icon.border:SetBackdropBorderColor(0,0,0)
icon.border:SetAlpha(1)
icon.border:SetAllPoints(icon)
icon.border:Show()
icon:Hide()
BAR[i] = icon
end
local function UpdateBar(self)
local class = UnitClass(self.unit)
if not class then return end
for i=1, MAX_ICONS do
local IconConfig = BAR_SETUP[class][i]
local icon = self[i]
if IconConfig then
local spell,_,iconbyID = IconConfig.name or GetSpellInfo(IconConfig.ID)
if not spell then print("Zed_ArenaFrames: Invalid CD bar config in cooldown_bar.lua")return end
self.spells[spell] = icon
icon:Show()
icon.texture:SetTexture(IconConfig.icon or iconbyID)
icon.cd:SetCooldown(0,0)
else
icon:Hide()
end
end
end
--[[
BAR.HideOnExpiration = {}
function BAR:HideIconAfterCD(icon, finish)
BAR.HideOnExpiration[icon] = finish
end
BAR:SetScript("OnUpdate", function(self, elapsed)
for icon, endTime in pairs(self.HideOnExpiration) do
if GetTime() > endTime then
icon:Hide()
end
end
end)
]]--
function BAR:Callback(sourceguid, spell, start, finish, icon)
if self.spells[spell] and not PVPTRINKETS[spell] and UnitGUID(self.unit) == sourceguid then
local icon = self.spells[spell]
local duration = finish - start
icon.cd:SetCooldown(start, duration)
elseif PVPTRINKETS[spell] and UnitGUID(self.unit) == sourceguid then
local icon = self[1]
local duration = finish - start
icon.cd:SetCooldown(start, duration)
end
end
BAR:SetScript("OnShow", UpdateBar)
BAR:SetScript("OnEvent", UpdateBar)
BAR:RegisterEvent("PLAYER_ENTERING_WORLD")
return BAR
end
function Zed_ArenaFrames.CD.CreateBars()
for i=1,3 do
local arenaFrame = _G["ArenaEnemyFrame"..i]
local cooldown_bar = Create_CooldownBar(arenaFrame)
cooldown_bar:SetPoint("LEFT", arenaFrame, "RIGHT", 150)
cooldown_bar:Show()
Zed_ArenaFrames.CooldownBars[cooldown_bar] = true
end
end