Repository navigation
Expand file tree
/
Copy pathUI.lua
More file actions
1329 lines (1138 loc) · 42.3 KB
/
Copy pathUI.lua
File metadata and controls
1329 lines (1138 loc) · 42.3 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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Raid Locks - the panel.
--
-- Ledger layout: one row per lockout, sorted by what expires first. The row
-- reads in this order - instance name, time left, then difficulty, size and
-- boss pips underneath, with a hairline bar showing how much of the lock has
-- already burned off. Clicking a row opens its boss list, clicking a boss in
-- that list toggles it, for anything neither the server nor the combat log saw.
local ADDON, RaidLocks = ...
--------------------------------------------------------------------
-- Committed layout numbers
--------------------------------------------------------------------
local PANEL_W = 360
local PANEL_PAD = 10
local HEADER_H = 52 -- title line plus the view tabs under it
local FOOTER_H = 20
local ROW_H = 40
local ROW_GAP = 3
local BOSS_LINE_H = 15
local MAX_LIST_H = 9 * (ROW_H + ROW_GAP)
local PIP_SIZE = 6
local PIP_GAP = 3
-- Middle dot, written as UTF-8 bytes so it survives whatever the file is saved as.
local SEP = "\194\183"
local FONT = "Fonts\\FRIZQT__.TTF"
local FONT_NUM = "Fonts\\ARIALN.TTF"
local SOLID = "Interface\\Buttons\\WHITE8X8"
--------------------------------------------------------------------
-- Palette - one dark ground, one accent per difficulty, amber for urgency
--------------------------------------------------------------------
local C = {
ground = { 0.04, 0.05, 0.06, 0.94 },
hairline = { 0.28, 0.32, 0.38, 0.70 },
rowBg = { 0.085, 0.095, 0.115, 0.90 },
rowHover = { 0.135, 0.155, 0.185, 0.95 },
track = { 0.16, 0.17, 0.20, 0.90 },
primary = { 0.93, 0.94, 0.96 },
secondary = { 0.52, 0.56, 0.63 },
dead = { 0.34, 0.36, 0.40 },
urgent = { 0.98, 0.70, 0.25 },
pipEmpty = { 0.20, 0.22, 0.26 },
}
-- Ascension renames the raid difficulties, so match on the words rather than on
-- the difficulty index, and fall back to steel for anything unrecognised.
local DIFFICULTY_COLORS = {
{ match = "mythic", color = { 0.93, 0.51, 0.19 } },
{ match = "ascended", color = { 0.36, 0.82, 0.74 } },
{ match = "heroic", color = { 0.65, 0.45, 0.90 } },
{ match = "normal", color = { 0.42, 0.57, 0.75 } },
}
local DIFFICULTY_FALLBACK = { 0.42, 0.57, 0.75 }
-- The second channel: what kind of content the lockout is. Kept desaturated
-- next to the difficulty colours so difficulty still wins the glance.
local KIND_COLORS = {
raid = { 0.58, 0.62, 0.70 },
worldboss = { 0.86, 0.71, 0.33 },
dungeon = { 0.44, 0.64, 0.50 },
openRaid = { 0.45, 0.72, 0.56 },
openBoss = { 0.45, 0.72, 0.56 },
-- One accent per expansion, so the open list reads as four short blocks
-- instead of one long column. Kept in the same muted register as the rest.
openVanilla = { 0.72, 0.62, 0.42 },
openTbc = { 0.48, 0.72, 0.44 },
openWotlk = { 0.46, 0.68, 0.82 },
openCustom = { 0.62, 0.55, 0.80 },
}
-- Expansion key -> the header kind that paints it.
local OPEN_EXPANSION_KIND = {
vanilla = "openVanilla",
tbc = "openTbc",
wotlk = "openWotlk",
custom = "openCustom",
}
local KIND_LABELS = {
raid = "raid",
worldboss = "world boss",
dungeon = "dungeon",
}
-- Kind is carried by the section headers the list is grouped under, which reads
-- far better than a slice of a 3px spine did. The spine is difficulty alone.
local KIND_ORDER = { "raid", "worldboss", "dungeon" }
local KIND_HEADINGS = {
raid = "RAID INSTANCES",
worldboss = "WORLD BOSSES",
dungeon = "DUNGEONS",
openRaid = "STILL OPEN",
openBoss = "WORLD BOSSES STILL OPEN",
openVanilla = "STILL OPEN " .. SEP .. " CLASSIC",
openTbc = "STILL OPEN " .. SEP .. " BURNING CRUSADE",
openWotlk = "STILL OPEN " .. SEP .. " WRATH OF THE LICH KING",
openCustom = "STILL OPEN " .. SEP .. " ASCENSION",
}
-- A world boss sitting in an expansion's open list still needs to read as a
-- world boss, so the name carries the kind the header no longer does.
local OPEN_NAME_COLORS = {
raid = { 0.62, 0.68, 0.62 },
worldboss = { 0.86, 0.71, 0.33 },
}
-- The open lists are names only, two to a line, in a quieter colour than any
-- lockout: they are what is left, not what is spent.
local OPEN_LINE_H = 13
local OPEN_COLUMNS = 2
local HEADER_ROW_H = 22
local SPINE_W = 4
local function ColorHex(color)
return string.format("ff%02x%02x%02x",
math.floor(color[1] * 255), math.floor(color[2] * 255), math.floor(color[3] * 255))
end
local URGENT_BELOW = 12 * 3600
local function DifficultyColor(lock)
local name = lock.difficultyName
if name then
local lower = string.lower(name)
for _, entry in ipairs(DIFFICULTY_COLORS) do
if string.find(lower, entry.match, 1, true) then return entry.color end
end
end
return DIFFICULTY_FALLBACK
end
--------------------------------------------------------------------
-- Small builders
--------------------------------------------------------------------
local function Fill(parent, layer, color, blend)
local tex = parent:CreateTexture(nil, layer or "BACKGROUND")
tex:SetTexture(SOLID)
if color then tex:SetVertexColor(color[1], color[2], color[3], color[4] or 1) end
if blend then tex:SetBlendMode(blend) end
return tex
end
local function Label(parent, font, size, flags, color)
local text = parent:CreateFontString(nil, "OVERLAY")
text:SetFont(font, size, flags)
if color then text:SetTextColor(color[1], color[2], color[3]) end
return text
end
--------------------------------------------------------------------
-- Panel
--------------------------------------------------------------------
local panel, content, scroll, rows, headers, openBlocks, historyRows, viewTabs, headerRight, footer
rows = {}
headers = {}
openBlocks = {}
historyRows = {}
local function SavePosition()
local point, _, _, x, y = panel:GetPoint()
local db = RaidLocks.db
db.point, db.x, db.y = point, x, y
end
local function BuildPanel()
panel = CreateFrame("Frame", "RaidLocksPanel", UIParent)
panel:SetWidth(PANEL_W)
panel:SetHeight(200)
panel:SetFrameStrata("MEDIUM")
panel:SetMovable(true)
panel:EnableMouse(true)
panel:SetClampedToScreen(true)
panel:Hide()
local bg = Fill(panel, "BACKGROUND", C.ground)
bg:SetAllPoints(panel)
-- A 1px lit edge along the top does the work a bevel would, for nothing.
local edge = Fill(panel, "BORDER", C.hairline)
edge:SetPoint("TOPLEFT", panel, "TOPLEFT", 0, 0)
edge:SetPoint("TOPRIGHT", panel, "TOPRIGHT", 0, 0)
edge:SetHeight(1)
local title = Label(panel, FONT, 14, nil, C.primary)
title:SetPoint("TOPLEFT", panel, "TOPLEFT", PANEL_PAD, -11)
title:SetText("Raid Locks")
headerRight = Label(panel, FONT, 11, nil, C.secondary)
headerRight:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -26, -13)
-- Two views over the same panel: what is locked now, and what has already
-- reset. A lockout that expires takes its record with it otherwise.
local function ViewTab(text, view, anchor)
local tab = CreateFrame("Button", nil, panel)
tab:SetHeight(14)
local label = Label(tab, FONT, 10, nil, C.secondary)
label:SetPoint("LEFT", tab, "LEFT", 0, 0)
label:SetText(text)
tab.label = label
local underline = Fill(tab, "ARTWORK", C.hairline)
underline:SetPoint("TOPLEFT", label, "BOTTOMLEFT", 0, -2)
underline:SetPoint("TOPRIGHT", label, "BOTTOMRIGHT", 0, -2)
underline:SetHeight(1)
tab.underline = underline
-- The string width is only known once the font is laid out; before that
-- it can be nil or 0, and a tab with no width is unclickable.
local textWidth = label:GetStringWidth() or 0
tab:SetWidth(textWidth > 0 and textWidth or 60)
tab:SetPoint("TOPLEFT", anchor or panel, anchor and "TOPRIGHT" or "TOPLEFT",
anchor and 14 or PANEL_PAD, anchor and 0 or -(HEADER_H - 22))
tab:SetScript("OnClick", function()
RaidLocks.db.view = view
RaidLocks:Redraw()
end)
tab.view = view
return tab
end
viewTabs = {}
viewTabs[1] = ViewTab("LOCKOUTS", "locks", nil)
viewTabs[2] = ViewTab("HISTORY", "history", viewTabs[1])
local close = CreateFrame("Button", nil, panel)
close:SetWidth(18)
close:SetHeight(18)
close:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -6, -9)
local closeText = Label(close, FONT, 14, nil, C.secondary)
closeText:SetPoint("CENTER")
closeText:SetText("x")
close:SetScript("OnEnter", function() closeText:SetTextColor(unpack(C.primary)) end)
close:SetScript("OnLeave", function() closeText:SetTextColor(unpack(C.secondary)) end)
close:SetScript("OnClick", function() RaidLocks:Toggle() end)
local headerRule = Fill(panel, "BORDER", { C.hairline[1], C.hairline[2], C.hairline[3], 0.35 })
headerRule:SetPoint("TOPLEFT", panel, "TOPLEFT", PANEL_PAD, -(HEADER_H - 6))
headerRule:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -PANEL_PAD, -(HEADER_H - 6))
headerRule:SetHeight(1)
scroll = CreateFrame("ScrollFrame", "RaidLocksScroll", panel)
scroll:SetPoint("TOPLEFT", panel, "TOPLEFT", PANEL_PAD, -HEADER_H)
scroll:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -PANEL_PAD, -HEADER_H)
scroll:SetHeight(MAX_LIST_H)
scroll:EnableMouseWheel(true)
scroll:SetScript("OnMouseWheel", function(self, delta)
local range = self.scrollRange or 0
if range <= 0 then return end
local target = self:GetVerticalScroll() - (delta * 40)
if target < 0 then target = 0 end
if target > range then target = range end
self:SetVerticalScroll(target)
end)
content = CreateFrame("Frame", "RaidLocksContent", scroll)
content:SetWidth(PANEL_W - PANEL_PAD * 2)
content:SetHeight(1)
scroll:SetScrollChild(content)
footer = Label(panel, FONT, 10, nil, C.dead)
footer:SetPoint("BOTTOMLEFT", panel, "BOTTOMLEFT", PANEL_PAD, 7)
-- Drag anywhere on the panel body.
panel:RegisterForDrag("LeftButton")
panel:SetScript("OnDragStart", function(self) self:StartMoving() end)
panel:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
SavePosition()
end)
-- Only the clock needs redrawing between data changes, and only while the
-- panel is on screen.
panel.elapsed = 0
panel:SetScript("OnUpdate", function(self, elapsed)
self.elapsed = self.elapsed + elapsed
if self.elapsed < 1 then return end
self.elapsed = 0
RaidLocks:UpdateClocks()
end)
end
--------------------------------------------------------------------
-- Rows
--------------------------------------------------------------------
-- Section heading: the kind's colour, its name, how many are locked, and a rule
-- running out to the right edge so the eye can find the break while scrolling.
local function BuildHeader(index)
local header = CreateFrame("Frame", nil, content)
header:SetWidth(PANEL_W - PANEL_PAD * 2)
header:SetHeight(HEADER_ROW_H)
header.chip = Fill(header, "ARTWORK")
header.chip:SetWidth(SPINE_W)
header.chip:SetHeight(11)
header.chip:SetPoint("BOTTOMLEFT", header, "BOTTOMLEFT", 0, 5)
header.label = Label(header, FONT, 10, nil, C.secondary)
header.label:SetPoint("BOTTOMLEFT", header.chip, "BOTTOMRIGHT", 6, -1)
header.count = Label(header, FONT, 10, nil, C.dead)
header.count:SetPoint("BOTTOMRIGHT", header, "BOTTOMRIGHT", 0, -1)
header.rule = Fill(header, "BACKGROUND")
header.rule:SetHeight(1)
header.rule:SetPoint("BOTTOMLEFT", header.label, "BOTTOMRIGHT", 8, 4)
header.rule:SetPoint("BOTTOMRIGHT", header.count, "BOTTOMLEFT", -8, 4)
headers[index] = header
RaidLocks.headers = headers
return header
end
local function PaintHeader(header, kind, group, countText)
local color = KIND_COLORS[kind] or KIND_COLORS.raid
header.chip:SetVertexColor(color[1], color[2], color[3], 1)
header.label:SetText(KIND_HEADINGS[kind] or "OTHER")
header.label:SetTextColor(color[1], color[2], color[3])
header.rule:SetVertexColor(color[1], color[2], color[3], 0.22)
if countText then
header.count:SetText(countText)
return
end
local locked = 0
for _, lock in ipairs(group) do
if lock.locked then locked = locked + 1 end
end
header.count:SetText(locked > 0 and (locked .. " locked") or "all clear")
end
-- A block of instance names, two to a line. Cheaper than a row each, and the
-- point of this list is scanning it, not reading a clock off it.
local function BuildOpenBlock(index)
local block = CreateFrame("Frame", nil, content)
block:SetWidth(PANEL_W - PANEL_PAD * 2)
block:SetHeight(OPEN_LINE_H)
block.labels = {}
openBlocks[index] = block
RaidLocks.openBlocks = openBlocks
return block
end
local function PaintOpenBlock(block, entries)
local perColumn = math.ceil(#entries / OPEN_COLUMNS)
local columnWidth = (PANEL_W - PANEL_PAD * 2) / OPEN_COLUMNS
for i, entry in ipairs(entries) do
local label = block.labels[i]
if not label then
label = Label(block, FONT, 9, nil, C.secondary)
label:SetJustifyH("LEFT")
block.labels[i] = label
end
local column = math.floor((i - 1) / perColumn)
local slot = (i - 1) % perColumn
label:ClearAllPoints()
label:SetPoint("TOPLEFT", block, "TOPLEFT", 6 + column * columnWidth, -(slot * OPEN_LINE_H))
label:SetWidth(columnWidth - 10)
-- "Coilfang: Serpentshrine Cavern" is the cavern, and the prefix is what
-- pushes the name past the column. " (PvE)" is a map-name artefact.
local name = string.gsub(entry.name, "^[^:]+:%s*", "")
name = string.gsub(name, "%s*%(PvE%)$", "")
label:SetText(name)
local color = OPEN_NAME_COLORS[entry.kind] or OPEN_NAME_COLORS.raid
label:SetTextColor(color[1] * 0.85, color[2] * 0.85, color[3] * 0.85)
label:Show()
end
for i = #entries + 1, #block.labels do
block.labels[i]:Hide()
end
local height = math.max(perColumn * OPEN_LINE_H, OPEN_LINE_H)
block:SetHeight(height)
return height
end
-- History row: what was cleared, at what difficulty, how far it got, and how
-- long ago it reset. No clock and no pips - none of it is live any more.
local HISTORY_ROW_H = 26
local function BuildHistoryRow(index)
local row = CreateFrame("Frame", nil, content)
row:SetWidth(PANEL_W - PANEL_PAD * 2)
row:SetHeight(HISTORY_ROW_H)
row.bg = Fill(row, "BACKGROUND", { C.rowBg[1], C.rowBg[2], C.rowBg[3], 0.65 })
row.bg:SetAllPoints(row)
row.spine = Fill(row, "BORDER")
row.spine:SetWidth(SPINE_W)
row.spine:SetPoint("TOPLEFT", row, "TOPLEFT", 0, 0)
row.spine:SetPoint("BOTTOMLEFT", row, "BOTTOMLEFT", 0, 0)
row.name = Label(row, FONT, 11, nil, C.secondary)
row.name:SetPoint("TOPLEFT", row, "TOPLEFT", 10, -4)
row.meta = Label(row, FONT, 9, nil, C.dead)
row.meta:SetPoint("TOPLEFT", row, "TOPLEFT", 10, -15)
row.count = Label(row, FONT_NUM, 12, nil, C.secondary)
row.count:SetPoint("TOPRIGHT", row, "TOPRIGHT", -2, -4)
row.when = Label(row, FONT, 9, nil, C.dead)
row.when:SetPoint("TOPRIGHT", row, "TOPRIGHT", -2, -15)
historyRows[index] = row
RaidLocks.historyRows = historyRows
return row
end
local function PaintHistoryRow(row, entry)
local color = DifficultyColor(entry)
row.spine:SetVertexColor(color[1], color[2], color[3], 0.55)
row.name:SetText(entry.name)
local difficulty = entry.difficultyName and string.gsub(entry.difficultyName, "%s*%b()", "") or ""
if entry.full then
-- A full clear is the thing worth spotting in a list of half-runs.
row.meta:SetText(string.format("|c%s%s|r %s |cff5cd18acleared|r",
ColorHex(color), difficulty, SEP))
else
row.meta:SetText(string.format("|c%s%s|r", ColorHex(color), difficulty))
end
if entry.total and entry.total > 0 then
row.count:SetText(entry.killed .. "/" .. entry.total)
else
row.count:SetText(tostring(entry.killed))
end
row.count:SetTextColor(color[1], color[2], color[3])
row.when:SetText(RaidLocks:FormatAgo(entry.clearedAt))
end
local function BuildPips(row)
row.pips = {}
for i = 1, 24 do
local pip = Fill(row, "ARTWORK", C.pipEmpty)
pip:SetWidth(PIP_SIZE)
pip:SetHeight(PIP_SIZE)
pip:SetPoint("TOPRIGHT", row, "TOPRIGHT", -((i - 1) * (PIP_SIZE + PIP_GAP)), -24)
pip:Hide()
row.pips[i] = pip
end
-- One flash, moved to whichever pip just changed - bosses die one at a time.
-- It is a frame because on this client only frames carry animation groups,
-- and its texture blends additively so a kill reads as light arriving
-- rather than as a colour swap.
local flash = CreateFrame("Frame", nil, row)
flash:SetWidth(PIP_SIZE + 6)
flash:SetHeight(PIP_SIZE + 6)
flash:SetPoint("CENTER", row, "TOPRIGHT", 0, 0)
flash:SetAlpha(0)
flash.tex = Fill(flash, "OVERLAY", { 1, 1, 1, 1 }, "ADD")
flash.tex:SetAllPoints(flash)
local group = flash:CreateAnimationGroup()
local up = group:CreateAnimation("Alpha")
up:SetChange(1)
up:SetDuration(0.08)
up:SetOrder(1)
local down = group:CreateAnimation("Alpha")
down:SetChange(-1)
down:SetDuration(0.32)
down:SetOrder(2)
down:SetSmoothing("OUT")
group:SetScript("OnFinished", function() flash:SetAlpha(0) end)
row.flash = flash
row.flashAnim = group
end
local function BossLine(row, index)
local line = row.bossLines[index]
if line then return line end
line = CreateFrame("Button", nil, row.expand)
line:SetHeight(BOSS_LINE_H)
line:SetWidth((PANEL_W - PANEL_PAD * 2) / 2 - 8)
line.mark = Fill(line, "ARTWORK", C.pipEmpty)
line.mark:SetWidth(5)
line.mark:SetHeight(5)
line.mark:SetPoint("LEFT", line, "LEFT", 2, 0)
line.right = Label(line, FONT_NUM, 11, nil, C.dead)
line.right:SetPoint("RIGHT", line, "RIGHT", -4, 0)
line.right:SetJustifyH("RIGHT")
line.text = Label(line, FONT, 10, nil, C.secondary)
line.text:SetPoint("LEFT", line.mark, "RIGHT", 5, 0)
line.text:SetPoint("RIGHT", line.right, "LEFT", -4, 0)
line.text:SetJustifyH("LEFT")
-- The list is a readout, not a form: progress arrives from the server on
-- zone-in and from the combat log during the run. Shift-click is left as a
-- quiet override for the rare lockout neither source ever saw.
line:SetScript("OnClick", function(self)
local lock = row.lock
if not lock or not self.boss or not IsShiftKeyDown() then return end
RaidLocks:SetBossKilled(lock, self.boss, not lock.saved.bosses[self.boss])
end)
line:SetScript("OnEnter", function(self)
if IsShiftKeyDown() then self.text:SetTextColor(unpack(C.primary)) end
end)
line:SetScript("OnLeave", function(self) RaidLocks:PaintBossLine(row, self) end)
row.bossLines[index] = line
return line
end
local function BuildRow(index)
local row = CreateFrame("Button", "RaidLocksRow" .. index, content)
row:SetWidth(PANEL_W - PANEL_PAD * 2)
row:SetHeight(ROW_H)
row.bg = Fill(row, "BACKGROUND", C.rowBg)
row.bg:SetAllPoints(row)
-- Difficulty as a spine down the left edge: colour instead of a legend.
row.spine = Fill(row, "BORDER")
row.spine:SetWidth(SPINE_W)
row.spine:SetPoint("TOPLEFT", row, "TOPLEFT", 0, 0)
row.spine:SetPoint("BOTTOMLEFT", row, "BOTTOMLEFT", 0, 0)
-- and a wash of the same colour across the row, so difficulty is legible
-- from the block of the row itself, not only from a 4px stripe.
row.tint = Fill(row, "BORDER")
row.tint:SetPoint("TOPLEFT", row.spine, "TOPRIGHT", 0, 0)
row.tint:SetWidth(90)
row.tint:SetPoint("BOTTOMLEFT", row.spine, "BOTTOMRIGHT", 0, 0)
row.tint:SetTexture("Interface\\Buttons\\WHITE8X8")
row.tint:SetBlendMode("ADD")
row.name = Label(row, FONT, 13, nil, C.primary)
row.name:SetPoint("TOPLEFT", row, "TOPLEFT", 10, -6)
row.name:SetJustifyH("LEFT")
row.time = Label(row, FONT_NUM, 16, "OUTLINE", C.primary)
row.time:SetPoint("TOPRIGHT", row, "TOPRIGHT", -2, -5)
row.time:SetJustifyH("RIGHT")
row.meta = Label(row, FONT, 10, nil, C.secondary)
row.meta:SetPoint("TOPLEFT", row, "TOPLEFT", 10, -22)
row.meta:SetJustifyH("LEFT")
row.progress = Label(row, FONT, 10, nil, C.secondary)
row.progress:SetPoint("TOPRIGHT", row, "TOPRIGHT", -2, -22)
row.progress:SetJustifyH("RIGHT")
row.track = Fill(row, "ARTWORK", C.track)
row.track:SetPoint("BOTTOMLEFT", row, "BOTTOMLEFT", 3, 3)
row.track:SetPoint("BOTTOMRIGHT", row, "BOTTOMRIGHT", 0, 3)
row.track:SetHeight(2)
row.fill = Fill(row, "OVERLAY")
row.fill:SetPoint("BOTTOMLEFT", row.track, "BOTTOMLEFT", 0, 0)
row.fill:SetHeight(2)
BuildPips(row)
row.expand = CreateFrame("Frame", nil, row)
row.expand:SetPoint("TOPLEFT", row, "BOTTOMLEFT", 10, -2)
row.expand:SetPoint("TOPRIGHT", row, "BOTTOMRIGHT", 0, -2)
row.expand:SetHeight(1)
row.expand:Hide()
row.bossLines = {}
-- Where this row's boss state came from, so a wrong-looking list is
-- explainable rather than mysterious.
row.note = Label(row.expand, FONT, 9, nil, C.dead)
row.note:SetPoint("BOTTOMLEFT", row.expand, "BOTTOMLEFT", 2, 1)
row:SetScript("OnEnter", function(self)
self.bg:SetVertexColor(unpack(C.rowHover))
end)
row:SetScript("OnLeave", function(self)
self.bg:SetVertexColor(unpack(C.rowBg))
end)
row:RegisterForClicks("LeftButtonUp", "RightButtonUp")
row:SetScript("OnClick", function(self, button)
if not self.lock then return end
if button == "RightButton" then
RaidLocks:ShowRowMenu(self)
return
end
local db = RaidLocks.db
db.expanded = (db.expanded ~= self.lock.key) and self.lock.key or nil
RaidLocks:Redraw()
end)
rows[index] = row
return row
end
--------------------------------------------------------------------
-- Painting
--------------------------------------------------------------------
-- One line saying where this lockout's boss state came from.
function RaidLocks:SourceNote(lock, killed)
if lock.source == "lockouts" then
if lock.lootOnly then
return "boss locks only - no instance save, so each boss clears on its own"
end
return "live from the server's loot lockouts"
elseif lock.saved.source == "server" and lock.saved.capturedAt then
return "read from the server on zone-in, " .. date("%d %b %H:%M", lock.saved.capturedAt)
elseif lock.saved.source == "manual" then
return "set by hand"
elseif killed and killed > 0 then
return "recorded from the combat log during the run"
end
return "no boss data yet - it fills in the moment you zone into the raid"
end
function RaidLocks:PaintBossLine(row, line)
local lock = row.lock
if not lock or not line.boss then return end
local killed = self:IsBossKilled(lock, line.boss)
local color = killed and DifficultyColor(lock) or C.pipEmpty
line.mark:SetVertexColor(color[1], color[2], color[3], 1)
if killed then
line.text:SetTextColor(unpack(C.dead))
else
line.text:SetTextColor(unpack(C.secondary))
end
-- When bosses carry their own lock, say when this one comes back, but only
-- where it differs from the row's own clock by more than a few minutes.
local remaining = self:BossRemaining(lock, line.boss)
if remaining and remaining > 0 and math.abs(remaining - (lock.reset or 0)) > 300 then
line.right:SetText(self:FormatDuration(remaining))
line.right:SetTextColor(color[1], color[2], color[3])
else
line.right:SetText("")
end
end
-- Returns the width the pip block occupies, so the count text can sit clear of it.
local function PaintPips(row, lock)
local roster = RaidLocks:RosterFor(lock)
local color = DifficultyColor(lock)
local count = roster and #roster or 0
local fits = count > 0 and count <= #row.pips
row.pipState = row.pipState or {}
for i, pip in ipairs(row.pips) do
if fits and i <= count then
-- Pips run right to left, so the row keeps a flush right edge and
-- the first boss of the raid sits leftmost.
local boss = roster[count - i + 1]
local killed = RaidLocks:IsBossKilled(lock, boss)
if killed then
pip:SetVertexColor(color[1], color[2], color[3], 1)
else
pip:SetVertexColor(C.pipEmpty[1], C.pipEmpty[2], C.pipEmpty[3], 1)
end
pip:Show()
-- Flash only a pip that just turned over, never on a plain redraw.
local was = row.pipState[i]
if was == false and killed and row.flash then
row.flashAnim:Stop()
row.flash:ClearAllPoints()
row.flash:SetPoint("CENTER", pip, "CENTER")
row.flash.tex:SetVertexColor(color[1], color[2], color[3], 1)
row.flashAnim:Play()
end
row.pipState[i] = killed
else
pip:Hide()
row.pipState[i] = nil
end
end
return fits and (count * (PIP_SIZE + PIP_GAP)) or 0
end
local function PaintRow(row, lock, expanded)
row.lock = lock
local color = DifficultyColor(lock)
local urgent = lock.locked and lock.reset > 0 and lock.reset < URGENT_BELOW
local dim = not lock.locked
row.spine:SetVertexColor(color[1], color[2], color[3], dim and 0.35 or 1)
local kind = RaidLocks:KindOf(lock)
-- The wash carries the difficulty colour into the row and fades out, so the
-- difficulty is readable from the row as a whole.
row.tint:SetGradientAlpha("HORIZONTAL",
color[1], color[2], color[3], dim and 0.05 or 0.16,
color[1], color[2], color[3], 0)
row.name:SetText(lock.name)
row.name:SetTextColor(C.primary[1], C.primary[2], C.primary[3])
if dim then
row.time:SetText("expired")
row.time:SetTextColor(unpack(C.dead))
else
row.time:SetText(RaidLocks:FormatDuration(lock.reset))
if urgent then
row.time:SetTextColor(unpack(C.urgent))
else
row.time:SetTextColor(unpack(C.primary))
end
end
-- Meta line, coloured by what each part is: the difficulty in its own
-- colour, size and reset clock in the quiet grey, an extended lock in the
-- alarm colour because it is the one thing here that is unusual.
local bits = {}
if lock.difficultyName then
-- "Mythic (10-25 Player)" is mostly the size, which the next field
-- already carries, and the full string crowds the pips.
local short = string.gsub(lock.difficultyName, "%s*%b()", "")
bits[#bits + 1] = "|c" .. ColorHex(color) .. short .. "|r"
end
if lock.maxPlayers and lock.maxPlayers > 0 then
bits[#bits + 1] = "|c" .. ColorHex(C.secondary) .. lock.maxPlayers .. " players|r"
end
if lock.locked and lock.reset > 0 then
bits[#bits + 1] = "|c" .. ColorHex(C.dead) .. RaidLocks:FormatResetClock(lock.reset) .. "|r"
end
if lock.extended then
bits[#bits + 1] = "|c" .. ColorHex(C.urgent) .. "extended|r"
end
row.meta:SetText(table.concat(bits, "|c" .. ColorHex(C.dead) .. " " .. SEP .. " |r"))
local killed, total = RaidLocks:KillCount(lock)
local roster = RaidLocks:RosterFor(lock)
local pipWidth = PaintPips(row, lock)
if total then
row.progress:SetText(killed .. "/" .. total)
else
row.progress:SetText(killed > 0 and (killed .. " down") or "")
end
row.progress:ClearAllPoints()
row.progress:SetPoint("TOPRIGHT", row, "TOPRIGHT", -(pipWidth > 0 and (pipWidth + 4) or 2), -22)
if killed > 0 then
row.progress:SetTextColor(color[1], color[2], color[3])
else
row.progress:SetTextColor(unpack(C.secondary))
end
-- The bar burns down over the whole lock, so a glance says how much of the
-- week is gone without reading the number.
local total_time = lock.saved.total or 0
local fraction = 0
if total_time > 0 and lock.locked then
fraction = lock.reset / total_time
if fraction > 1 then fraction = 1 elseif fraction < 0 then fraction = 0 end
end
local width = (PANEL_W - PANEL_PAD * 2 - 3) * fraction
if width < 1 then width = 1 end
row.fill:SetWidth(width)
if urgent then
row.fill:SetVertexColor(C.urgent[1], C.urgent[2], C.urgent[3], 0.95)
else
row.fill:SetVertexColor(color[1], color[2], color[3], dim and 0.25 or 0.75)
end
row:SetAlpha(dim and 0.55 or 1)
-- Boss list
if expanded and roster then
local columns = 2
local perColumn = math.ceil(#roster / columns)
for i, boss in ipairs(roster) do
local line = BossLine(row, i)
local column = math.floor((i - 1) / perColumn)
local slot = (i - 1) % perColumn
line:ClearAllPoints()
line:SetPoint("TOPLEFT", row.expand, "TOPLEFT",
column * ((PANEL_W - PANEL_PAD * 2) / 2), -(slot * BOSS_LINE_H))
line.boss = boss
line.text:SetText(boss)
RaidLocks:PaintBossLine(row, line)
line:Show()
end
for i = #roster + 1, #row.bossLines do
row.bossLines[i]:Hide()
end
row.note:SetText((KIND_LABELS[kind] or "raid") .. " " .. SEP .. " " .. RaidLocks:SourceNote(lock, killed))
row.expand:SetHeight(perColumn * BOSS_LINE_H + 16)
row.expand:Show()
return ROW_H + perColumn * BOSS_LINE_H + 18
end
if expanded and not roster then
local line = BossLine(row, 1)
line:ClearAllPoints()
line:SetPoint("TOPLEFT", row.expand, "TOPLEFT", 0, 0)
line.boss = nil
line.right:SetText("")
line.text:SetText("No boss list for this instance yet.")
line.text:SetTextColor(unpack(C.dead))
line.mark:SetVertexColor(C.pipEmpty[1], C.pipEmpty[2], C.pipEmpty[3], 1)
line:Show()
for i = 2, #row.bossLines do row.bossLines[i]:Hide() end
row.note:SetText("")
row.expand:SetHeight(BOSS_LINE_H + 4)
row.expand:Show()
return ROW_H + BOSS_LINE_H + 6
end
for _, line in ipairs(row.bossLines) do line:Hide() end
row.expand:Hide()
return ROW_H
end
--------------------------------------------------------------------
-- Layout
--------------------------------------------------------------------
local function PaintViewTabs()
if not viewTabs then return end
local active = RaidLocks.db.view or "locks"
for _, tab in ipairs(viewTabs) do
if tab.view == active then
tab.label:SetTextColor(unpack(C.primary))
tab.underline:SetVertexColor(C.primary[1], C.primary[2], C.primary[3], 0.75)
else
tab.label:SetTextColor(unpack(C.dead))
tab.underline:SetVertexColor(C.hairline[1], C.hairline[2], C.hairline[3], 0.15)
end
end
end
-- Everything already reset, newest first. This is the only place a cleared
-- lockout still exists: the server forgets it the moment it resets.
local function DrawHistory()
local entries = RaidLocks:GetHistory()
local offset = 0
for index, entry in ipairs(entries) do
local row = historyRows[index] or BuildHistoryRow(index)
row:ClearAllPoints()
row:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -offset)
PaintHistoryRow(row, entry)
row:Show()
offset = offset + HISTORY_ROW_H + ROW_GAP
end
for index = #entries + 1, #historyRows do
historyRows[index]:Hide()
end
for index = 1, #rows do
rows[index]:Hide()
rows[index].lock = nil
end
for index = 1, #headers do headers[index]:Hide() end
for index = 1, #openBlocks do openBlocks[index]:Hide() end
if #entries == 0 then
footer:SetText("Nothing has reset yet - cleared lockouts land here when their week rolls over")
else
footer:SetText(#entries .. " past lockout" .. (#entries == 1 and "" or "s")
.. " " .. SEP .. " right-click the minimap button to clear")
end
headerRight:SetText("what already reset")
return offset
end
function RaidLocks:Redraw()
if not panel then return end
PaintViewTabs()
if self.db.view == "history" then
local used = DrawHistory()
local listHeight = math.min(math.max(used, HISTORY_ROW_H), MAX_LIST_H)
content:SetHeight(math.max(used, 1))
scroll:SetHeight(listHeight)
scroll.scrollRange = math.max(used - listHeight, 0)
if scroll:GetVerticalScroll() > scroll.scrollRange then
scroll:SetVerticalScroll(scroll.scrollRange)
end
panel:SetHeight(HEADER_H + listHeight + FOOTER_H)
return
end
for index = 1, #historyRows do historyRows[index]:Hide() end
local locks = self:VisibleLocks()
local expandedKey = self.db.expanded
local offset = 0
-- Group the list under headings rather than mixing a world boss between two
-- raids: scrolling should land you in a section, not in a soup.
local grouped = {}
for _, lock in ipairs(locks) do
local kind = self:KindOf(lock)
grouped[kind] = grouped[kind] or {}
table.insert(grouped[kind], lock)
end
local rowIndex, headerIndex = 0, 0
for _, kind in ipairs(KIND_ORDER) do
local group = grouped[kind]
if group and #group > 0 then
headerIndex = headerIndex + 1
local header = headers[headerIndex] or BuildHeader(headerIndex)
header:ClearAllPoints()
header:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -offset)
PaintHeader(header, kind, group)
header:Show()
offset = offset + HEADER_ROW_H
for _, lock in ipairs(group) do
rowIndex = rowIndex + 1
local row = rows[rowIndex] or BuildRow(rowIndex)
row:ClearAllPoints()
row:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -offset)
row:Show()
local used = PaintRow(row, lock, expandedKey == lock.key)
offset = offset + used + ROW_GAP
end
offset = offset + 6
end
end
-- What is still open, at the bottom: everything with no lock on it at all.
local blockIndex = 0
if self.db.showOpen then
for _, group in ipairs(self:OpenByExpansion()) do
local kind = OPEN_EXPANSION_KIND[group.key] or "openCustom"
local entries = group.entries
headerIndex = headerIndex + 1
local header = headers[headerIndex] or BuildHeader(headerIndex)
header:ClearAllPoints()
header:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -offset)
PaintHeader(header, kind, nil, #entries .. " open")
header:Show()
offset = offset + HEADER_ROW_H
blockIndex = blockIndex + 1
local block = openBlocks[blockIndex] or BuildOpenBlock(blockIndex)
block:ClearAllPoints()
block:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -offset)
block:Show()
offset = offset + PaintOpenBlock(block, entries) + 8
end
end
for index = rowIndex + 1, #rows do
rows[index]:Hide()
rows[index].lock = nil
end
for index = headerIndex + 1, #headers do
headers[index]:Hide()
end
for index = blockIndex + 1, #openBlocks do
openBlocks[index]:Hide()
end
content:SetHeight(math.max(offset, 1))
local listHeight = math.min(offset, MAX_LIST_H)
if listHeight < ROW_H then listHeight = ROW_H end
scroll:SetHeight(listHeight)
scroll.scrollRange = math.max(offset - listHeight, 0)
if scroll:GetVerticalScroll() > scroll.scrollRange then
scroll:SetVerticalScroll(scroll.scrollRange)
end
panel:SetHeight(HEADER_H + listHeight + FOOTER_H)
-- Header: who this is, and what falls off next.
local soonest
for _, lock in ipairs(locks) do