-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCooldownTracker.lua
More file actions
434 lines (387 loc) · 16.1 KB
/
Copy pathCooldownTracker.lua
File metadata and controls
434 lines (387 loc) · 16.1 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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
-- ============================================================
-- RT v2 — CooldownTracker.lua
-- Suivi des cooldowns importants de raid (inspiré ExRT)
-- Vanilla 1.12 : tracking manuel + class-based timers
-- Sync via Sync.lua (CD message)
-- ============================================================
RT_CD = RT_CD or {}
-- ── Définition des CDs par classe (vanilla 1.12) ───────────
-- { name, icon_hint, duration_sec, color }
local CD_DEFS = {
Druid = {
{ id="rebirth", label="Rebirth", dur=1800, color="FF7D0A" },
{ id="tranquility", label="Tranquility", dur=300, color="FF7D0A" },
{ id="barkskin", label="Barkskin", dur=60, color="FF7D0A" },
},
Paladin = {
{ id="divshield", label="Divine Shield", dur=300, color="F58CBA" },
{ id="divinv", label="Divine Intervention",dur=1800,color="F58CBA" },
{ id="layonh", label="Lay on Hands", dur=3600, color="F58CBA" },
{ id="blessp", label="Blessing of Prot", dur=300, color="F58CBA" },
},
Warrior = {
{ id="shieldwall", label="Shield Wall", dur=1800, color="C79C6E" },
{ id="laststand", label="Last Stand", dur=600, color="C79C6E" },
{ id="retaliation", label="Retaliation", dur=1800, color="C79C6E" },
{ id="recklessness",label="Recklessness", dur=1800, color="C79C6E" },
},
Priest = {
{ id="innervate", label="Inner Fire", dur=180, color="FFFFFF" },
{ id="fearlord", label="Fear Ward", dur=30, color="FFFFFF" },
},
Shaman = {
{ id="reincarnation",label="Reincarnation", dur=3600, color="0070DE" },
},
Mage = {
{ id="iceblock", label="Ice Block", dur=300, color="69CCF0" },
{ id="combustion", label="Combustion", dur=180, color="69CCF0" },
},
Warlock = {
{ id="soulstone", label="Soulstone", dur=1800, color="9482C9" },
{ id="gateway", label="Healthstone", dur=900, color="9482C9" },
},
}
-- ── État des CDs ────────────────────────────────────────────
-- RT_CD_STATE[playerName][cdId] = { usedAt, duration }
RT_CD_STATE = RT_CD_STATE or {}
-- ── Frame principale ────────────────────────────────────────
local CD_FRAME = nil
local CD_ROWS = {}
local CLASS_COLOR = {
Warrior="C79C6E", Paladin="F58CBA", Hunter="ABD473", Rogue="FFF569",
Priest="FFFFFF", Shaman="0070DE", Mage="69CCF0", Warlock="9482C9",
Druid="FF7D0A",
}
local function CD_MakeRow(parent, yOff)
local row = CreateFrame("Frame", nil, parent)
row:SetWidth(340)
row:SetHeight(18)
row:SetPoint("TOPLEFT", parent, "TOPLEFT", 4, yOff)
local nameText = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
nameText:SetPoint("LEFT", row, "LEFT", 2, 0)
nameText:SetWidth(90)
nameText:SetJustifyH("LEFT")
local cdText = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
cdText:SetPoint("LEFT", row, "LEFT", 96, 0)
cdText:SetWidth(240)
cdText:SetJustifyH("LEFT")
row.nameText = nameText
row.cdText = cdText
row:Hide()
return row
end
local function CD_CreateFrame()
if CD_FRAME then return end
local f = CreateFrame("Frame", "RT_CDFrame", UIParent)
f:SetWidth(360)
f:SetHeight(300)
f:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -10, -200)
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", function() f:StartMoving() end)
f:SetScript("OnDragStop", function() f:StopMovingOrSizing() end)
f:SetFrameStrata("MEDIUM")
f:SetClampedToScreen(true)
f:Hide()
f:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 16, edgeSize = 12,
insets = { left=3, right=3, top=3, bottom=3 },
})
f:SetBackdropColor(0.04, 0.02, 0.08, 0.92)
f:SetBackdropBorderColor(0.5, 0.2, 0.8, 1.0)
local title = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOP", f, "TOP", 0, -6)
title:SetText("|cffAA66FFCooldowns Raid|r")
local closeBtn = CreateFrame("Button", nil, f, "UIPanelCloseButton")
closeBtn:SetPoint("TOPRIGHT", f, "TOPRIGHT", 2, 2)
closeBtn:SetWidth(18)
closeBtn:SetHeight(18)
closeBtn:SetScript("OnClick", function() f:Hide() end)
-- Zone de contenu scrollable (max 15 rows visibles)
for i = 1, 30 do
CD_ROWS[i] = CD_MakeRow(f, -16 - (i-1)*18)
end
-- Timer de refresh (1.12 : GetTime au lieu de elapsed)
local _cdLast = GetTime()
f:SetScript("OnUpdate", function()
if (GetTime() - _cdLast) < 1 then return end
_cdLast = GetTime()
RT_CD.Refresh()
end)
CD_FRAME = f
end
-- ── Marquer un CD comme utilisé ─────────────────────────────
function RT_CD.Use(playerName, cdId, broadcast)
playerName = playerName or (UnitName and UnitName("player") or "")
if playerName == "" or not cdId then return end
RT_DB = RT_DB or {}
RT_DB.cdState = RT_DB.cdState or {}
RT_DB.cdState[playerName] = RT_DB.cdState[playerName] or {}
-- Trouve la durée du CD
local dur = 300
local class = (RT_DB.roster and RT_DB.roster[playerName] and RT_DB.roster[playerName].class) or ""
local classCDs = CD_DEFS[class] or {}
for i = 1, table.getn(classCDs) do
if classCDs[i].id == cdId then
dur = classCDs[i].dur
break
end
end
RT_DB.cdState[playerName][cdId] = {
usedAt = GetTime and GetTime() or 0,
duration = dur,
}
if broadcast ~= false and RT_Sync_Send then
RT_Sync_Send("CD", playerName, cdId, tostring(dur))
end
RT_CD.Refresh()
RT_Print("|cffAA66FF[CD]|r " .. playerName .. " a utilisé " .. cdId)
end
function RT_CD.Reset(playerName, cdId, broadcast)
if not playerName or not cdId then return end
RT_DB = RT_DB or {}
RT_DB.cdState = RT_DB.cdState or {}
if RT_DB.cdState[playerName] then
RT_DB.cdState[playerName][cdId] = nil
end
if broadcast ~= false and RT_Sync_Send then
RT_Sync_Send("CD", playerName, cdId, "0")
end
RT_CD.Refresh()
end
-- ── Sync reception ─────────────────────────────────────────
if RT_Sync_Register then
RT_Sync_Register("CD", function(sender, pname, cdId, durStr)
pname = pname or sender
cdId = cdId or ""
local dur = tonumber(durStr) or 0
RT_DB = RT_DB or {}
RT_DB.cdState = RT_DB.cdState or {}
RT_DB.cdState[pname] = RT_DB.cdState[pname] or {}
if dur <= 0 then
RT_DB.cdState[pname][cdId] = nil
else
RT_DB.cdState[pname][cdId] = {
usedAt = GetTime and GetTime() or 0,
duration = dur,
}
end
RT_CD.Refresh()
end)
end
-- ── Refresh display ────────────────────────────────────────
function RT_CD.Refresh()
if not CD_FRAME or not CD_FRAME:IsShown() then return end
local now = GetTime and GetTime() or 0
RT_DB = RT_DB or {}
local roster = RT_DB.roster or {}
local cdState = RT_DB.cdState or {}
local entries = {}
-- Collecte tous les CDs de tous les joueurs du roster
for name, data in pairs(roster) do
local class = data.class or ""
local classCDs = CD_DEFS[class]
if classCDs then
for _, cdDef in pairs(classCDs) do
local state = cdState[name] and cdState[name][cdDef.id]
local remaining = 0
local isOnCD = false
if state and state.usedAt then
remaining = math.max(0, state.duration - (now - state.usedAt))
isOnCD = remaining > 0
end
table.insert(entries, {
name = name,
class = class,
cdId = cdDef.id,
cdLabel = cdDef.label,
dur = cdDef.dur,
remaining = remaining,
isOnCD = isOnCD,
color = cdDef.color or "CCCCCC",
classColor= CLASS_COLOR[class] or "CCCCCC",
})
end
end
end
-- Trie : dispo (remaining=0) d'abord, puis par remaining croissant
table.sort(entries, function(a, b)
if a.isOnCD ~= b.isOnCD then return (a.isOnCD and 1 or 0) < (b.isOnCD and 1 or 0) end
return a.remaining < b.remaining
end)
-- Affiche dans les rows
local maxRows = math.min(table.getn(entries), 30)
for i = 1, 30 do
if i <= maxRows then
local e = entries[i]
CD_ROWS[i].nameText:SetText("|cff" .. e.classColor .. e.name .. "|r")
local cdStr
if e.isOnCD then
local m = math.floor(e.remaining / 60)
local s = math.mod(math.floor(e.remaining), 60)
if m > 0 then
cdStr = "|cffFF4444" .. e.cdLabel .. "|r |cff888888" .. m .. "m" .. s .. "s|r"
else
cdStr = "|cffFF8800" .. e.cdLabel .. "|r |cff888888" .. s .. "s|r"
end
else
cdStr = "|cff44FF44" .. e.cdLabel .. "|r |cff44FF44✓ dispo|r"
end
CD_ROWS[i].cdText:SetText(cdStr)
-- Bouton "Utilisé" sur clic de la row
if not CD_ROWS[i]._btn then
local btn = CreateFrame("Button", nil, CD_ROWS[i])
btn:SetAllPoints(CD_ROWS[i])
btn:SetScript("OnClick", function()
local entry = entries[i]
if entry then
if entry.isOnCD then
RT_CD.Reset(entry.name, entry.cdId, true)
else
RT_CD.Use(entry.name, entry.cdId, true)
end
end
end)
btn:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
CD_ROWS[i]._btn = btn
end
CD_ROWS[i]:Show()
else
CD_ROWS[i]:Hide()
end
end
-- Ajuste hauteur
local h = math.max(50, 22 + maxRows * 18 + 10)
CD_FRAME:SetHeight(h)
end
-- ── Afficher/masquer ────────────────────────────────────────
function RT_CD.Show()
if not CD_FRAME then CD_CreateFrame() end
CD_FRAME:Show()
RT_CD.Refresh()
end
function RT_CD.Hide()
if CD_FRAME then CD_FRAME:Hide() end
end
function RT_CD.Toggle()
if CD_FRAME and CD_FRAME:IsShown() then RT_CD.Hide()
else RT_CD.Show() end
end
-- ── Construire le panneau "CDs" dans l'UI principale ───────
-- Appelé depuis rt.lua lors de la création des panels
function RT_BuildUICooldowns(parent)
local p = RT_CreatePanel and RT_CreatePanel("RT_Panel_CDs") or parent
local titleLabel = p:CreateFontString(nil, "OVERLAY", "GameFontNormal")
titleLabel:SetPoint("TOPLEFT", p, "TOPLEFT", 6, -4)
titleLabel:SetText("|cffAA66FFCooldowns Raid|r — Clic sur un CD pour le marquer utilisé/dispo")
titleLabel:SetTextColor(0.7, 0.4, 1.0)
local openBtn = CreateFrame("Button", nil, p, "UIPanelButtonTemplate")
openBtn:SetPoint("TOPRIGHT", p, "TOPRIGHT", -6, -4)
openBtn:SetWidth(130)
openBtn:SetHeight(22)
openBtn:SetText("Fenêtre CDs")
openBtn:SetScript("OnClick", function() RT_CD.Toggle() end)
-- Mini-liste intégrée dans le panneau (non-interactive, refresh)
local cdInlineScroll = CreateFrame("ScrollFrame", "RT_CDInlineScroll", p, "UIPanelScrollFrameTemplate")
cdInlineScroll:SetPoint("TOPLEFT", p, "TOPLEFT", 6, -30)
cdInlineScroll:SetWidth(700)
cdInlineScroll:SetHeight(380)
local cdInlineContent = CreateFrame("Frame", nil, cdInlineScroll)
cdInlineContent:SetWidth(680)
cdInlineContent:SetHeight(1200)
cdInlineScroll:SetScrollChild(cdInlineContent)
local CD_INLINE_ROWS = {}
for i = 1, 40 do
local row = CreateFrame("Frame", nil, cdInlineContent)
row:SetWidth(680)
row:SetHeight(18)
row:SetPoint("TOPLEFT", cdInlineContent, "TOPLEFT", 2, -(i-1)*18)
local rName = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
rName:SetPoint("LEFT", row, "LEFT", 2, 0)
rName:SetWidth(100)
rName:SetJustifyH("LEFT")
local rCD = row:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
rCD:SetPoint("LEFT", row, "LEFT", 106, 0)
rCD:SetWidth(580)
rCD:SetJustifyH("LEFT")
-- Bouton "Utilisé"
local markBtn = CreateFrame("Button", nil, row, "UIPanelButtonTemplate")
markBtn:SetPoint("RIGHT", row, "RIGHT", 0, 0)
markBtn:SetWidth(60)
markBtn:SetHeight(16)
markBtn:SetText("Utilisé")
markBtn:Hide()
row.rName = rName
row.rCD = rCD
row.markBtn= markBtn
row:Hide()
CD_INLINE_ROWS[i] = row
end
-- Refresh toutes les secondes (1.12 : GetTime au lieu de elapsed)
local _panelLast = GetTime()
p:SetScript("OnUpdate", function()
if (GetTime() - _panelLast) < 1 then return end
_panelLast = GetTime()
-- Rebuilt entries
local now = GetTime and GetTime() or 0
RT_DB = RT_DB or {}
local roster = RT_DB.roster or {}
local cdState = RT_DB.cdState or {}
local entries = {}
for name, data in pairs(roster) do
local class = data.class or ""
local cds = CD_DEFS[class]
if cds then
for _, cdDef in pairs(cds) do
local state = cdState[name] and cdState[name][cdDef.id]
local rem = 0
local onCD = false
if state and state.usedAt then
rem = math.max(0, state.duration - (now - state.usedAt))
onCD = rem > 0
end
table.insert(entries, {
name=name, class=class, cdId=cdDef.id, cdLabel=cdDef.label,
dur=cdDef.dur, remaining=rem, isOnCD=onCD,
classColor=CLASS_COLOR[class] or "CCCCCC"
})
end
end
end
table.sort(entries, function(a,b)
if a.isOnCD ~= b.isOnCD then return (a.isOnCD and 1 or 0) < (b.isOnCD and 1 or 0) end
return a.remaining < b.remaining
end)
local maxR = math.min(table.getn(entries), 40)
for i = 1, 40 do
if i <= maxR then
local e = entries[i]
CD_INLINE_ROWS[i].rName:SetText("|cff" .. e.classColor .. e.name .. "|r")
local cdStr
if e.isOnCD then
local m = math.floor(e.remaining/60)
local s = math.mod(math.floor(e.remaining),60)
cdStr = "|cffFF4444" .. e.cdLabel .. "|r "
.. (m>0 and (m.."m") or "") .. s .. "s"
else
cdStr = "|cff44FF44" .. e.cdLabel .. " ✓|r"
end
CD_INLINE_ROWS[i].rCD:SetText(cdStr)
-- Configure le bouton
local entry = entries[i]
CD_INLINE_ROWS[i].markBtn:SetText(entry.isOnCD and "Reset" or "Utilisé")
CD_INLINE_ROWS[i].markBtn:SetScript("OnClick", function()
if entry.isOnCD then RT_CD.Reset(entry.name, entry.cdId, true)
else RT_CD.Use(entry.name, entry.cdId, true) end
end)
CD_INLINE_ROWS[i].markBtn:Show()
CD_INLINE_ROWS[i]:Show()
else
CD_INLINE_ROWS[i]:Hide()
end
end
end)
end