-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalRaidCD.lua
287 lines (265 loc) · 7.14 KB
/
alRaidCD.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
-- Config start
local anchor = "TOPLEFT"
local x, y = 12, -300
local width, height = 130, 14
local spacing = 5
local icon_size = 14
local font = GameFontHighlight:GetFont()
local font_size = 11
local font_style = nil
local backdrop_color = {0, 0, 0, 0.4}
local border_color = {0, 0, 0, 1}
local show_icon = true
local texture = "Interface\\TargetingFrame\\UI-StatusBar"
local show = {
raid = true,
party = true,
arena = true,
}
-- Config end
local spells = {
[20484] = 600, -- Rebirth
[6203] = 900, -- Soulstone
[95750] = 900,
[20707] = 900, -- Soulstone res
[6346] = 180, -- Fear Ward
[29166] = 180, -- Innervate
[32182] = 300, -- Heroism
[2825] = 300, -- Bloodlust
[80353] = 300, -- Time Warp
[90355] = 300, -- Ancient Hysteria
[61999] = 600, -- Raise Ally
}
local cfg = {}
if IsAddOnLoaded("alInterface") then
local config = {
general = {
width = {
order = 1,
value = width,
type = "range",
min = 10,
max = 300,
},
height = {
order = 2,
value = height,
type = "range",
min = 5,
max = 30,
},
spacing = {
order = 3,
value = spacing,
type = "range",
min = 0,
max = 30,
},
iconsize = {
order = 4,
value = icon_size,
type = "range",
min = 5,
max = 70,
},
showicon = {
order = 5,
value = true,
},
},
showin = {
raid = {
order = 1,
value = true,
},
party = {
order = 2,
value = true,
},
arena = {
order = 3,
value = true,
},
},
}
UIConfigGUI.raidcd = config
UIConfig.raidcd = cfg
local frame = CreateFrame("Frame")
frame:RegisterEvent("VARIABLES_LOADED")
frame:SetScript("OnEvent", function(self, event)
width = cfg.general.width
height = cfg.general.height
spacing = cfg.general.spacing
icon_size = cfg.general.iconsize
show_icon = cfg.general.showicon
show = {
raid = cfg.showin.raid,
party = cfg.showin.party,
arena = cfg.showin.arena,
}
end)
end
local filter = COMBATLOG_OBJECT_AFFILIATION_RAID + COMBATLOG_OBJECT_AFFILIATION_PARTY + COMBATLOG_OBJECT_AFFILIATION_MINE
local band = bit.band
local sformat = string.format
local floor = math.floor
local timer = 0
local backdrop = {
bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=],
edgeFile = [=[Interface\ChatFrame\ChatFrameBackground]=], edgeSize = 1,
insets = {top = 0, left = 0, bottom = 0, right = 0},
}
local bars = {}
local anchorframe = CreateFrame("Frame", "RaidCD", UIParent)
anchorframe:SetSize(width, height)
anchorframe:SetPoint(anchor, x, y)
if UIMovableFrames then tinsert(UIMovableFrames, anchorframe) end
local FormatTime = function(time)
if time >= 60 then
return sformat('%.2d:%.2d', floor(time / 60), time % 60)
else
return sformat('%.2d', time)
end
end
local CreateFS = CreateFS or function(frame)
local fstring = frame:CreateFontString(nil, 'OVERLAY', 'GameFontHighlight')
fstring:SetFont(font, font_size, font_style)
fstring:SetShadowColor(0, 0, 0, 1)
fstring:SetShadowOffset(0.5, -0.5)
return fstring
end
local CreateBG = CreateBG or function(parent)
local bg = CreateFrame("Frame", nil, parent)
bg:SetPoint("TOPLEFT", parent, "TOPLEFT", -1, 1)
bg:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", 1, -1)
bg:SetFrameStrata("LOW")
bg:SetBackdrop(backdrop)
bg:SetBackdropColor(unpack(backdrop_color))
bg:SetBackdropBorderColor(unpack(border_color))
return bg
end
local UpdatePositions = function()
for i = 1, #bars do
bars[i]:ClearAllPoints()
if i == 1 then
bars[i]:SetPoint("TOPLEFT", anchorframe, 0, 0)
else
bars[i]:SetPoint("TOPLEFT", bars[i-1], "BOTTOMLEFT", 0, -spacing)
end
bars[i].id = i
end
end
local StopTimer = function(bar)
bar:SetScript("OnUpdate", nil)
bar:Hide()
tremove(bars, bar.id)
UpdatePositions()
end
local BarUpdate = function(self, elapsed)
local curTime = GetTime()
if self.endTime < curTime then
StopTimer(self)
return
end
self.status:SetValue(100 - (curTime - self.startTime) / (self.endTime - self.startTime) * 100)
self.right:SetText(FormatTime(self.endTime - curTime))
end
local OnEnter = function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(self.spell)
GameTooltip:SetClampedToScreen(true)
GameTooltip:Show()
end
local OnLeave = function(self)
GameTooltip:Hide()
end
local OnMouseDown = function(self, button)
if button == "LeftButton" then
SendChatMessage(sformat("Cooldown %s %s: %s", self.left:GetText(), self.spell, self.right:GetText()), "RAID")
elseif button == "RightButton" then
StopTimer(self)
end
end
local CreateBar = function()
local bar = CreateFrame("Frame", nil, UIParent)
bar:SetSize(width, height)
bar.status = CreateFrame("Statusbar", nil, bar)
if show_icon then
bar.icon = CreateFrame("button", nil, bar)
bar.icon:SetSize(icon_size, icon_size)
bar.icon:SetPoint("BOTTOMLEFT", 0, 0)
bar.status:SetPoint("BOTTOMLEFT", bar.icon, "BOTTOMRIGHT", 5, 0)
else
bar.status:SetPoint("BOTTOMLEFT", 0, 0)
end
bar.status:SetPoint("BOTTOMRIGHT", 0, 0)
bar.status:SetHeight(height)
bar.status:SetStatusBarTexture(texture)
bar.status:SetMinMaxValues(0, 100)
bar.status:SetFrameLevel(bar:GetFrameLevel()-1)
bar.left = CreateFS(bar)
bar.left:SetPoint('LEFT', bar.status, 2, 1)
bar.left:SetJustifyH('LEFT')
bar.right = CreateFS(bar)
bar.right:SetPoint('RIGHT', bar.status, -2, 1)
bar.right:SetJustifyH('RIGHT')
CreateBG(bar.icon)
CreateBG(bar.status)
return bar
end
local StartTimer = function(name, spellId)
local spell, rank, icon = GetSpellInfo(spellId)
for _, v in pairs(bars) do
if v.name == name and v.spell == spell then
return
end
end
local bar = CreateBar()
bar.endTime = GetTime() + spells[spellId]
bar.startTime = GetTime()
bar.left:SetText(name)
bar.name = name
bar.right:SetText(FormatTime(spells[spellId]))
if icon and bar.icon then
bar.icon:SetNormalTexture(icon)
bar.icon:GetNormalTexture():SetTexCoord(0.07, 0.93, 0.07, 0.93)
end
bar.spell = spell
bar:Show()
local color = RAID_CLASS_COLORS[select(2, UnitClass(name))]
bar.status:SetStatusBarColor(color.r, color.g, color.b)
bar:SetScript("OnUpdate", BarUpdate)
bar:EnableMouse(true)
bar:SetScript("OnEnter", OnEnter)
bar:SetScript("OnLeave", OnLeave)
bar:SetScript("OnMouseDown", OnMouseDown)
tinsert(bars, bar)
UpdatePositions()
end
local OnEvent = function(self, event, ...)
if event == "COMBAT_LOG_EVENT_UNFILTERED" then
local timestamp, eventType, _, sourceGUID, sourceName, sourceFlags = ...
if band(sourceFlags, filter) == 0 then return end
if eventType == "SPELL_RESURRECT" or eventType == "SPELL_CAST_SUCCESS" or eventType == "SPELL_AURA_APPLIED" then
local spellId = select(12, ...)
sourceName = sourceName:gsub("-%w+", "")
if spells[spellId] and show[select(2, IsInInstance())] then
StartTimer(sourceName, spellId)
end
end
elseif event == "ZONE_CHANGED_NEW_AREA" and select(2, IsInInstance()) == "arena" then
for k, v in pairs(bars) do
StopTimer(v)
end
end
end
local addon = CreateFrame("frame")
addon:SetScript('OnEvent', OnEvent)
addon:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
addon:RegisterEvent("ZONE_CHANGED_NEW_AREA")
SlashCmdList["RaidCD"] = function(msg)
StartTimer(UnitName('player'), 20484)
StartTimer(UnitName('player'), 6203)
StartTimer(UnitName('player'), 6346)
end
SLASH_RaidCD1 = "/raidcd"