Repository navigation
Expand file tree
/
Copy pathUI.lua
More file actions
3020 lines (2875 loc) · 162 KB
/
Copy pathUI.lua
File metadata and controls
3020 lines (2875 loc) · 162 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
-- LifeTimeStats - main window, pages, minimap button and backup dialog
-- Copyright (C) 2026 Malikor. Licensed under GPL-3.0-or-later (see LICENSE).
local ADDON, ns = ...
local T, W = ns.THEME, ns.W
local C = W.C
local Int, Time, Money = ns.FormatInt, ns.FormatTime, ns.FormatMoney
-- The window is 1140 x 740 ("Normal"), or as large as the screen allows ("Fill screen").
-- The sizes below are recomputed by ComputeLayout() just before the window is built, so every
-- page is laid out for the size in use.
local BASE_W, BASE_H = 1140, 740
local WIN_W, WIN_H = BASE_W, BASE_H
local HEADER_H, SIDEBAR_W, FOOTER_H, PAD = 44, 176, 24, 10
local KPI_H, GAP = 72, 10
local NAV_STEP = 29 -- 18 pages still leave room for the 7-row Today box
local BODY_Y = KPI_H + GAP -- y where panels start (82)
local CW, CH, KPI_W, BODY_H
local function Derive()
CW = WIN_W - SIDEBAR_W - PAD * 2 -- content width (944 at Normal)
CH = WIN_H - HEADER_H - FOOTER_H - PAD * 2 -- content height (652 at Normal)
KPI_W = (CW - GAP * 3) / 4
BODY_H = CH - BODY_Y -- 570 at Normal
end
Derive()
-- Room the window needs beyond its own edges: the notebook's parchment overhangs 46 px on each
-- side and 30 px top and bottom, and the section tabs stick out on the right.
local TAB_ROOM = 118 + 34 + 12
function ns.WindowSizeFor(mode, uiW, uiH, scale, book)
if mode ~= "fill" or type(uiW) ~= "number" or type(uiH) ~= "number" then return BASE_W, BASE_H end
scale = (type(scale) == "number" and scale > 0) and scale or 1
local w = uiW / scale - (book and 46 or 0) - TAB_ROOM - 16
local h = uiH / scale - (book and 60 or 0) - 24
w = math.max(BASE_W, math.min(2600, math.floor(w)))
h = math.max(BASE_H, math.min(1600, math.floor(h)))
return w, h
end
local function ComputeLayout()
local s = ns.settings and ns.settings.window or {}
-- the framed skins put their title on a plaque over the top rail, so the header row sits lower
HEADER_H = (ns.Framed and ns.Framed()) and 62 or ((ns.Styled and ns.Styled()) and 48 or 44)
local book = (ns.Notebook and ns.Notebook()) or (ns.Framed and ns.Framed()) or (ns.Styled and ns.Styled())
WIN_W, WIN_H = ns.WindowSizeFor(s.size, UIParent:GetWidth(), UIParent:GetHeight(), s.scale or 1, book)
Derive()
end
function ns.WindowSize() return WIN_W, WIN_H end
local win
local pages = {}
local current
local pinLayer
local noteLayer
-- ------------------------------------------------------------ helpers
local function c(v, k) return (v and v.c and v.c[k]) or 0 end
local function PlusAlways(n, fmt) return "+" .. (fmt or Int)(n or 0) end
local function Plus(n, fmt)
if not n or n == 0 then return "" end
return "+" .. (fmt or Int)(n)
end
local function DayLabel(d)
local y, m, dd = d:match("^(%d%d%d%d)(%d%d)(%d%d)$")
if not y then return d end
return date("%b %d", time({ year = tonumber(y), month = tonumber(m), day = tonumber(dd), hour = 12 }))
end
local function DateLabel(t) return t and date("%b %d %H:%M", t) or "" end
local function Settings() return ns.settings end
local function RangeName()
local r = Settings().range
return ({ today = "TODAY", session = "SESSION", week = "LAST 7 DAYS", month = "Last 30 days" })[r] or "LIFETIME"
end
local function Views()
local s = Settings()
local base = ns.GetView(s.scope, "lifetime")
local view = ns.GetView(s.scope, s.range)
return view, base, ns.session
end
local function Series(base, key, n)
local out, labels = {}, {}
for i, e in ipairs(ns.DaySeries(base, key, n)) do
out[i] = { e.v }
labels[i] = DayLabel(e.d)
end
return out, labels
end
local function KpiRow(page, defs, allowFormatted)
page.kpis = {}
for i, d in ipairs(defs) do
local tile = W.Odometer(page, (i - 1) * (KPI_W + GAP), 0, KPI_W, KPI_H, d.label, d.icon, d.tip, allowFormatted)
page.kpis[i] = tile
-- a tile backed by a statistic opens its card when clicked
tile.stat = ns.FindStat and (ns.FindStat(d.id) or ns.FindStat(d.label))
if tile.HookScript then
tile:EnableMouse(true)
tile:HookScript("OnMouseUp", function(self, button)
local st = rawget(self, "stat")
if st and button ~= "RightButton" then ns.ShowStatDetail(st) end
end)
end
end
page.kpiDefs = defs
end
local function UpdateKpi(tile, def, view, base, sess)
tile:SetValue(def.value(view), def.sub and def.sub(view, base, sess) or "", def.exact and def.exact(view) or nil)
end
local function UpdateKpis(page, view, base, sess)
for i, d in ipairs(page.kpiDefs) do
UpdateKpi(page.kpis[i], d, view, base, sess)
end
end
-- Account scope: each character's part of a counter (Accountwide Stats style).
local function PerChar(key)
local list = {}
for _, rec in pairs(ns.db.chars or {}) do
local v = type(rec) == "table" and rec.c and rec.c[key]
if v and v > 0 and rec.meta then list[#list + 1] = { rec.meta.name or "?", v, rec.meta.class } end
end
if #list < 2 then return nil end
table.sort(list, function(a, b) return a[2] > b[2] end)
local out = {}
for i = 1, math.min(#list, 8) do
local e = list[i]
local cc = e[3] and RAID_CLASS_COLORS and RAID_CLASS_COLORS[e[3]]
local nm = cc and cc.colorStr and ("|c" .. cc.colorStr .. e[1] .. "|r") or e[1]
out[#out + 1] = nm .. ": " .. Int(e[2])
end
return table.concat(out, "\n")
end
-- Rows for a stat page, grouped into its sections: a heading row starts each section.
-- Returns the rows and { { name, index } } for the section tabs. `focus` (a stat label) is
-- inked in the accent colour, for search results that open the page.
local function StatRows(cat, view, sess, focus)
local rows, sections = {}, {}
local perChar = Settings().scope == "account" and Settings().range == "lifetime"
local range = Settings().range
local other = range == "session" and ns.GetView(Settings().scope, "today") or sess
local groups = ns.SectionedStats and ns.SectionedStats(cat) or { { stats = ns.STATS[cat] or {} } }
for _, group in ipairs(groups) do
if group.name and #groups > 1 then
rows[#rows + 1] = { group.name, "", "", header = true }
sections[#sections + 1] = { name = group.name, index = #rows }
end
for _, st in ipairs(group.stats) do
local v, what = ns.StatValue(st, view)
local ov = ns.StatValue(st, other)
local empty = view.today and st.rec
local na, naTip = ns.IsNA(st, v)
rows[#rows + 1] = {
(st.label2 and what) and (st.label .. ": " .. what) or st.label,
na and "n/a" or (empty and "—" or ns.FormatStat(st, v)),
(Settings().showSession and type(ov) == "number" and ov > 0 and not st.get) and ("+" .. ns.FormatStat(st, ov)) or "",
tip = na and naTip or st.tip, what = what, stat = st.label, def = st,
color = (focus and st.label == focus) and T.amber or nil,
}
if perChar and st.key and not na then
local pc = PerChar(st.key)
if pc then rows[#rows].tip = ((st.tip and (st.tip .. "\n\n")) or "") .. pc end
end
end
end
return rows, sections
end
-- Section tabs for a page whose table has heading rows: one tab per section, the active one
-- being the section at the top of the visible rows. Clicking scrolls the table there.
local function TableSectionTabs(tbl, sections)
local out = {}
local top = (tbl.offset or 0) + 1
local active = 1
for i, s in ipairs(sections or {}) do if s.index <= top + 1 then active = i end end
for i, s in ipairs(sections or {}) do
out[i] = { name = s.name, active = i == active, click = function() tbl:ScrollTo(s.index) end }
end
return out
end
ns.TableSectionTabs = TableSectionTabs
-- Find the row for a stat on a page and bring it into view (used by search results).
local function FocusRow(p, tbl, label)
p.focus = label
for i, d in ipairs(tbl.data or {}) do
if d.stat == label or d[1] == label then tbl:Reveal(i); return true end
end
end
-- A built page by id (used by the offline tests and other modules).
function ns.Page(id) return pages[id] end
-- ------------------------------------------------------------ page factory
local function NewPage(id)
local p = CreateFrame("Frame", nil, win.content)
p:SetAllPoints()
p:Hide()
p.id = id
pages[id] = p
return p
end
local function Panel(page, title, icon, x, y, w, h, tip)
return W.Card(page, title, icon, x, y, w, h, tip)
end
-- ============================================================ DASHBOARD
local function UpdateDashboardKpis(page, view, base, sess)
local _, byID = ns.DashboardPinCatalog()
local used, nextSlot = {}, 1
local showCharacterParts = Settings().scope == "account" and Settings().range == "lifetime"
for _, id in ipairs(ns.DashboardPins()) do
local pin = byID[id]
local stat = pin.stat
local value = ns.StatValue(stat, view)
local unavailable, why = ns.IsNA(stat, value)
local tip = unavailable and why or stat.tip
if showCharacterParts and stat.key and not unavailable then
local parts = PerChar(stat.key)
if parts then tip = tip and (tip .. "\n\n" .. parts) or parts end
end
local tile = page.kpis[nextSlot]
tile:Configure(stat.label, pin.icon, tip)
tile.stat = stat
local sub = "Pinned · " .. pin.category
local goal = ns.GoalFor and ns.GoalFor(id)
if goal and type(value) == "number" then
sub = goal.done and ("Goal reached · " .. ns.FormatStat(stat, goal.target)) or string.format("Goal %.0f%% of %s", math.min(99.9, value * 100 / goal.target), ns.FormatStat(stat, goal.target))
end
tile:SetFormatted(unavailable and "n/a" or ns.FormatStat(stat, value), sub)
-- notebook: a pinned statistic whose goal is reached gets a wax seal
if ns.Notebook() and ns.MakeSeal then
local seal = rawget(tile, "goalSeal")
if not seal then
seal = ns.MakeSeal(tile, 30)
seal.text:SetText("")
seal:SetPoint("CENTER", tile, "TOPRIGHT", -8, -6)
rawset(tile, "goalSeal", seal)
end
seal:SetShown(goal and goal.done and true or false)
end
used[id], nextSlot = true, nextSlot + 1
end
for _, def in ipairs(page.kpiDefs) do
if nextSlot > #page.kpis then break end
if not used[def.id] then
local tile = page.kpis[nextSlot]
local seal = rawget(tile, "goalSeal")
if seal then seal:Hide() end
tile:Configure(def.label, def.icon, def.tip)
tile.stat = ns.FindStat(def.id) or ns.FindStat(def.label)
UpdateKpi(tile, def, view, base, sess)
nextSlot = nextSlot + 1
end
end
end
local function CreateDashboardPinPicker()
local layer = CreateFrame("Frame", nil, win)
layer:SetAllPoints()
layer:SetFrameLevel((win:GetFrameLevel() or 0) + 10)
layer:EnableMouse(true)
layer:Hide()
local dim = W.Fill(layer, { 0.06, 0.04, 0.02, 0.66 })
dim:SetPoint("TOPLEFT", 1, -HEADER_H); dim:SetPoint("BOTTOMRIGHT", -1, FOOTER_H)
local width, height = 630, 390
local dlg = W.Window(layer)
dlg:SetSize(width, height)
dlg:SetPoint("CENTER")
dlg:EnableMouse(true)
local ink = ns.JournalSkin() and W.JOURNAL or nil
local banner = W.Fill(dlg, T.tile)
banner:SetPoint("TOPLEFT", 1, -1); banner:SetPoint("TOPRIGHT", -1, -1); banner:SetHeight(37)
if ink then W.Shade(banner, ink.base, ink.top) end
local rule = W.Line(dlg, ink and ink.trim or nil)
rule:SetPoint("TOPLEFT", 1, -38); rule:SetPoint("TOPRIGHT", -1, -38); rule:SetHeight(1)
local title = W.Text(dlg, 16, ink and ink.gold or T.amber)
title:SetPoint("TOPLEFT", 13, -11)
title:SetText("Manage Dashboard pins")
local close
if ink then
local ok, native = pcall(CreateFrame, "Button", nil, dlg, "UIPanelCloseButtonNoScripts")
if ok then close = native end
end
if not close then close = W.FlatButton(dlg, "×", 24, 24) end
close:SetSize(24, 24); close:SetPoint("TOPRIGHT", -9, -7)
close:SetScript("OnClick", function() layer:Hide() end)
W.Tip(close, "Close", "Close the pin picker.")
local label = W.Text(dlg, 12, T.text)
label:SetPoint("TOPLEFT", 13, -56); label:SetText("Find a statistic")
local box = W.Panel(dlg, T.bg)
box:SetPoint("LEFT", label, "RIGHT", 9, 0); box:SetSize(236, 24)
local edit = CreateFrame("EditBox", nil, box)
edit:SetPoint("TOPLEFT", 7, 0); edit:SetPoint("BOTTOMRIGHT", -7, 0)
edit:SetFont(W.FONT, 12, "")
edit:SetTextColor(T.text[1], T.text[2], T.text[3])
edit:SetAutoFocus(false)
local placeholder = W.Text(box, 11, T.dim, nil, "LEFT")
placeholder:SetPoint("LEFT", 7, 0); placeholder:SetText("Search by name or category")
local count = W.Text(dlg, 12, ink and ink.gold or T.amber, nil, "RIGHT")
count:SetPoint("TOPRIGHT", -13, -56)
local done = W.FlatButton(dlg, "Done", 76, 20)
done:SetPoint("BOTTOMRIGHT", -13, 10)
done:SetScript("OnClick", function() layer:Hide() end)
local status = W.Text(dlg, 11, T.dim, nil, "LEFT")
status:SetPoint("BOTTOMLEFT", 13, 14); status:SetPoint("RIGHT", done, "LEFT", -8, 0)
local listParent = CreateFrame("Frame", nil, dlg)
listParent:SetPoint("TOPLEFT", 12, -82); listParent:SetSize(width - 24, height - 124)
local list
local function Refresh(keepOffset, message)
local catalog, byID = ns.DashboardPinCatalog()
local pins = ns.DashboardPins()
local limit = ns.DASHBOARD_PIN_LIMIT
local full = #pins >= limit
local query = (edit:GetText() or ""):match("^%s*(.-)%s*$"):lower()
local rows, pinned = {}, {}
local function Add(pin, selected)
if query ~= "" and not (pin.stat.label:lower():find(query, 1, true)
or pin.category:lower():find(query, 1, true)) then return end
rows[#rows + 1] = { pin.stat.label, pin.category, selected and "Unpin" or (full and "Slots full" or "Pin"),
id = pin.id, tip = pin.stat.tip }
end
for _, id in ipairs(pins) do
pinned[id] = true
Add(byID[id], true)
end
for _, pin in ipairs(catalog) do
if not pinned[pin.id] then Add(pin, false) end
end
list:SetData(rows, keepOffset)
count:SetText(string.format("%d of %d pins", #pins, limit))
status:SetText(message or (full and "Unpin a statistic to free a slot." or "Click a row to pin or unpin it. Scroll for more."))
end
list = W.Table(listParent, width - 24, height - 124, {
{ "STATISTIC", 306, kind = "text" }, { "CATEGORY", 195, kind = "text" }, { "PINS", 0, kind = "text" },
}, function(row)
local ok, why = ns.ToggleDashboardPin(row.id)
GameTooltip:Hide()
Refresh(true, not ok and why or nil)
if ok then ns.RefreshWindow() end
end, "No statistics match this search.")
edit:SetScript("OnTextChanged", function(self)
placeholder:SetShown((self:GetText() or "") == "" and not self:HasFocus())
Refresh(false)
end)
edit:SetScript("OnEditFocusGained", function() placeholder:Hide() end)
edit:SetScript("OnEditFocusLost", function(self) placeholder:SetShown((self:GetText() or "") == "") end)
edit:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
edit:SetScript("OnEscapePressed", function() layer:Hide() end)
layer:SetScript("OnShow", function()
Refresh(false)
edit:SetFocus()
end)
layer:SetScript("OnHide", function()
edit:ClearFocus()
GameTooltip:Hide()
end)
return layer
end
-- ------------------------------------------------------------ one statistic, in detail
-- Clicking a row of a stat page opens this card over the window: the statistic's last 30
-- days, its totals and best day, and the same statistic on every character (or, for a record,
-- every time it was beaten).
local detailLayer
local function DetailDay(d)
if type(d) ~= "string" or #d ~= 8 then return tostring(d or "") end
local t = time({ year = tonumber(d:sub(1, 4)), month = tonumber(d:sub(5, 6)), day = tonumber(d:sub(7, 8)), hour = 12 })
return date("%b %d, %Y", t)
end
local function CreateStatDetail()
local layer = CreateFrame("Frame", nil, win)
layer:SetAllPoints()
layer:SetFrameLevel((win:GetFrameLevel() or 0) + 12)
layer:EnableMouse(true)
layer:Hide()
local dim = W.Fill(layer, { 0.06, 0.04, 0.02, 0.66 })
dim:SetPoint("TOPLEFT", 1, -HEADER_H); dim:SetPoint("BOTTOMRIGHT", -1, FOOTER_H)
-- a click outside the card closes it
layer:SetScript("OnMouseDown", function() layer:Hide() end)
local width = math.min(760, CW)
local height = math.min(CH, 560)
local dlg = W.Window(layer)
dlg:SetSize(width, height)
dlg:SetPoint("CENTER", win.content or layer, "CENTER")
dlg:EnableMouse(true)
dlg:SetScript("OnMouseDown", function() end)
local ink = ns.JournalSkin() and W.JOURNAL or nil
local banner = W.Fill(dlg, T.tile)
banner:SetPoint("TOPLEFT", 1, -1); banner:SetPoint("TOPRIGHT", -1, -1); banner:SetHeight(52)
if ink then W.Shade(banner, ink.base, ink.top) end
if ns.Paper() then banner:SetAlpha(0.35) end
local rule = W.Line(dlg, ink and ink.trim or nil)
rule:SetPoint("TOPLEFT", 1, -53); rule:SetPoint("TOPRIGHT", -1, -53); rule:SetHeight(1)
layer.title = W.Text(dlg, 16, ink and ink.gold or T.amber)
layer.title:SetPoint("TOPLEFT", 14, -10); layer.title:SetPoint("RIGHT", -44, 0); layer.title:SetJustifyH("LEFT")
if ns.Paper() then W.Bold(layer.title, T.amber) end
layer.home = W.Text(dlg, 11, T.dim)
layer.home:SetPoint("TOPLEFT", 14, -32); layer.home:SetPoint("RIGHT", -44, 0); layer.home:SetJustifyH("LEFT")
local close
if ink then
local ok, native = pcall(CreateFrame, "Button", nil, dlg, "UIPanelCloseButtonNoScripts")
if ok then close = native end
end
if not close then close = W.FlatButton(dlg, "×", 24, 24) end
close:SetSize(24, 24); close:SetPoint("TOPRIGHT", -9, -12)
close:SetScript("OnClick", function() layer:Hide() end)
W.Tip(close, "Close", "Close this statistic.")
layer.tip = W.Text(dlg, 12, T.text)
layer.tip:SetPoint("TOPLEFT", 14, -64); layer.tip:SetPoint("RIGHT", -14, 0)
layer.tip:SetJustifyH("LEFT"); layer.tip:SetWordWrap(true)
-- eight facts in two rows
layer.facts = {}
local fw = (width - 28) / 4
for i = 1, 8 do
local col, row = (i - 1) % 4, math.floor((i - 1) / 4)
local lab = W.Text(dlg, 10, T.dim)
lab:SetPoint("TOPLEFT", 14 + col * fw, -112 - row * 44); lab:SetWidth(fw - 10); lab:SetJustifyH("LEFT")
local val = W.Text(dlg, 15, T.amber, W.NUM)
val:SetPoint("TOPLEFT", lab, "BOTTOMLEFT", 0, -3); val:SetWidth(fw - 10); val:SetJustifyH("LEFT"); val:SetWordWrap(false)
if ns.Paper() then W.Bold(val, T.amber) end
layer.facts[i] = { lab = lab, val = val }
end
local chartY, chartH = 206, 112
layer.chartTitle = W.Text(dlg, 10, T.dim)
layer.chartTitle:SetPoint("TOPLEFT", 14, -chartY)
-- the pace line: when the next round number comes at the last 30 days' rate
layer.pace = W.Text(dlg, 11, T.amber, nil, "RIGHT")
layer.pace:SetPoint("TOPRIGHT", -14, -chartY + 1); layer.pace:SetWidth(width - 160); layer.pace:SetWordWrap(false)
local chartHost = CreateFrame("Frame", nil, dlg)
chartHost:SetPoint("TOPLEFT", 14, -chartY - 16); chartHost:SetSize(width - 28, chartH)
layer.chart = W.Columns(chartHost, width - 28, chartH, 30, "single")
layer.chartHost = chartHost
local tableY = chartY + 16 + chartH + 12
layer.tableHost = CreateFrame("Frame", nil, dlg)
layer.tableHost:SetPoint("TOPLEFT", 14, -tableY); layer.tableHost:SetSize(width - 28, height - tableY - 12)
layer.charTable = W.Table(layer.tableHost, width - 28, height - tableY - 12,
{ { "CHARACTER", 260, kind = "text" }, { "VALUE", 180, kind = "num" }, { "", 0, kind = "dim" } }, nil, "No characters yet")
layer.recTable = W.Table(layer.tableHost, width - 28, height - tableY - 12,
{ { "WHEN", 190, kind = "dim" }, { "NEW BEST", 170, kind = "num" }, { "WHERE", 0, kind = "text" } }, nil, "Not beaten yet")
return layer
end
function ns.ShowStatDetail(st)
if not win or not st then return end
if not detailLayer then detailLayer = CreateStatDetail() end
local L = detailLayer
local h = ns.StatHistory(st, ns.char)
L.stat = st
L.data = h
local F = function(v) return ns.FormatStat(st, v) end
L.title:SetText(st.label)
L.home:SetText(h.home or "")
L.tip:SetText(st.tip or (st.rec and "A personal record: the best value ever reached." or ""))
local facts
if h.kind == "record" then
local first, last = h.history[#h.history], h.history[1]
facts = {
{ "Best", F(h.value) }, { "Set at", h.what or "—" }, { "Times beaten", Int(#h.history) },
{ "Characters with it", Int((function() local n = 0 for _, c in ipairs(h.chars) do if c.v > 0 then n = n + 1 end end return n end)()) },
{ "First set", first and date("%b %d, %Y", first.at) or "—" }, { "Last beaten", last and date("%b %d, %Y", last.at) or "—" },
{ "Best on the account", h.chars[1] and h.chars[1].v > 0 and (F(h.chars[1].v) .. " · " .. tostring(h.chars[1].name)) or "—" }, { "", "" },
}
else
facts = {
{ "Lifetime", F(h.value) }, { "This session", F(h.session or 0) },
{ "Today", h.series and F(h.today) or "—" }, { "Last 7 days", h.series and F(h.last7) or "—" },
{ "Last 30 days", h.series and F(h.last30) or "—" },
{ "Best day", h.bestEver and (F(h.bestEver.v) .. " · " .. DetailDay(h.bestEver.d)) or "—" },
{ "Days with any", h.series and (Int(h.daysOnFile or 0) .. " of the last 40") or "—" },
{ "All characters", (function() local t = 0 for _, c in ipairs(h.chars) do t = t + c.v end return F(t) end)() },
}
end
for i, f in ipairs(L.facts) do
local d = facts[i] or { "", "" }
f.lab:SetText(ns.Paper() and W.SmallCaps(d[1]) or d[1]:upper())
f.val:SetText(d[2])
end
-- the 30-day chart (counters only)
if h.series then
L.chartTitle:SetText(ns.Paper() and W.SmallCaps("Last 30 days") or "LAST 30 DAYS")
local vals, labels = {}, {}
for i, e in ipairs(h.series) do vals[i] = { e.v or 0 }; labels[i] = DayLabel(e.d) end
L.chart:Set(vals, { C.amber }, labels, { labels[1], labels[15], "Today" }, F, { st.label }, true)
L.chartHost:Show(); L.chartTitle:Show()
local pace = ns.StatPace(st, h)
local text = ""
if pace and pace.rate == 0 then
text = "Not done in the last 30 days."
elseif pace and pace.target then
local rate = pace.rate >= 10 and Int(pace.rate) or string.format("%.1f", pace.rate)
if st.fmt and st.fmt ~= "int" then rate = F(pace.rate) end
text = string.format("At %s a day: %s %s", rate, F(pace.target),
pace.days <= 1 and "by tomorrow" or ("around " .. date("%b %d, %Y", pace.at) .. " (in " .. Int(pace.days) .. " days)"))
end
L.pace:SetText(text); L.pace:Show()
else
L.chartHost:Hide(); L.chartTitle:Hide(); L.pace:Hide()
end
if h.kind == "record" then
local rows = {}
for _, e in ipairs(h.history) do
rows[#rows + 1] = { date("%b %d, %Y %H:%M", e.at), F(e.v), e.w or "", tip = e.character }
end
L.recTable:SetData(rows); L.recTable:Show(); L.charTable:Hide()
else
local rows = {}
for _, c in ipairs(h.chars) do
local col = c.class and ns.ClassRGB and ns.ClassRGB(c.class) or nil
rows[#rows + 1] = { tostring(c.name) .. (c.me and " (this character)" or ""), F(c.v), "", color = col }
end
L.charTable:SetData(rows); L.charTable:Show(); L.recTable:Hide()
end
L:Show()
end
function ns.HideStatDetail() if detailLayer then detailLayer:Hide() end end
local function OpenDashboardPinPicker()
if not pinLayer then pinLayer = CreateDashboardPinPicker() end
pinLayer:Show()
end
local function BuildDashboard()
-- the framed skins draw their own overview (Overview.lua)
if ns.Framed() and ns.BuildFramedOverview then
return ns.BuildFramedOverview({
NewPage = NewPage, Panel = Panel, CW = CW, CH = CH, GAP = GAP, DayLabel = DayLabel,
OpenPins = OpenDashboardPinPicker,
RangeName = function()
return ({ today = "Today", session = "This session", week = "Last 7 days", month = "Last 30 days" })[Settings().range] or "Lifetime"
end,
})
end
local p = NewPage("dashboard")
KpiRow(p, {
{ id = "computed:steps", label = "Steps taken", icon = "steps", value = ns.Steps, tip = "Distance on foot divided by a 0.75 m stride.",
sub = function(v, b, s) return ns.GOLD .. PlusAlways(ns.Steps(s)) .. "|r this session" end },
{ id = "counter:jumps", label = "Times jumped", icon = "jump", value = function(v) return c(v, "jumps") end, tip = "Jumps that actually left the ground.",
sub = function(v, b, s) return ns.GOLD .. PlusAlways(c(s, "jumps")) .. "|r this session" end },
{ id = "computed:kills", label = "Enemies killed", icon = "sword", value = ns.Kills, tip = "Creatures and hostile players that died after you damaged them.",
sub = function(v, b, s) return ns.GOLD .. PlusAlways(ns.Kills(s)) .. "|r this session · " .. Int(c(v, "kills_pvp")) .. " players" end },
{ id = "counter:deaths", label = "Deaths", icon = "skull", value = function(v) return c(v, "deaths") end, tip = "Times you died.",
sub = function(v) return "K/D " .. ns.GOLD .. string.format("%.1f", ns.Div(ns.Kills(v), c(v, "deaths"))) .. "|r · first: " .. (v.first and v.first.death or "—") end },
}, true)
local hw = (CW - GAP) / 2
local zc = Panel(p, "Kills vs deaths by zone", "combat", 0, BODY_Y, hw, 180, "Your five deadliest zones: kills on the left, deaths on the right.")
p.mirror = W.Mirror(zc.body, zc.bw, zc.bh - 16, 5, C.amber, C.rust)
local lg = W.Legend(zc.body, { { "Kills", C.amber }, { "Deaths", C.rust } }); lg:SetPoint("BOTTOMLEFT", 0, 0)
local gc = Panel(p, "Gold, last 30 days", "coin", hw + GAP, BODY_Y, hw, 180, "Net gold per day: earned minus spent. Red days spent more than they earned.")
p.goldBig = W.Text(gc.body, 28, T.amber, W.NUM); p.goldBig:SetPoint("TOPLEFT", 0, -8)
p.goldInfo = W.Text(gc.body, 11, T.dim); p.goldInfo:SetPoint("TOPLEFT", 0, -48); p.goldInfo:SetWordWrap(true); p.goldInfo:SetWidth(132); p.goldInfo:SetJustifyH("LEFT")
local gb = CreateFrame("Frame", nil, gc.body); gb:SetPoint("TOPLEFT", 142, 0); gb:SetSize(gc.bw - 142, gc.bh)
p.goldCols = W.Columns(gb, gc.bw - 142, gc.bh, 30, "signed")
local qw = KPI_W
local y2 = BODY_Y + 190
local dc = Panel(p, "Deaths by cause", "skull", 0, y2, qw, 200)
p.deathRing = W.RingWithLegend(dc.body, dc.bw, dc.bh)
local bc = Panel(p, "By level band", "adventure", qw + GAP, y2, qw, 200, "Quests, kills (÷10) and deaths for each 10-level band.")
p.bands = W.Columns(bc.body, bc.bw, bc.bh - 16, 6, "group", 3)
local bl = W.Legend(bc.body, { { "Quests", C.cream2 }, { "Kills ÷10", C.amber }, { "Deaths", C.rust } }); bl:SetPoint("BOTTOMLEFT", 0, 0)
local sc = Panel(p, "Gold sources", "coin", (qw + GAP) * 2, y2, qw, 200, "Where all the gold you ever earned came from.")
p.srcRing = W.RingWithLegend(sc.body, sc.bw, sc.bh)
local jc = Panel(p, "Jumps by hour", "jump", (qw + GAP) * 3, y2, qw, 200, "When you jump the most, in 2-hour blocks of your local time.")
p.jumpDots = W.Dots(jc.body, jc.bw, jc.bh, 12, 9)
local y3 = y2 + 210
local h3 = CH - y3
local w1, w2 = math.floor(CW * 0.38), math.floor(CW * 0.32)
local w3 = CW - w1 - w2 - GAP * 2
local stc = Panel(p, "Steps per day", "steps", 0, y3, w1, h3)
p.stepCols = W.Columns(stc.body, stc.bw, stc.bh, 30, "single")
local rc = Panel(p, "Rates", "timeline", w1 + GAP, y3, w2, h3)
p.gauges = {}
local gs = math.min(rc.bh - 30, 92)
for i = 1, 3 do
local g = W.TickRing(rc.body, gs, 48, 7, 3)
g:SetPoint("TOP", rc.body, "TOPLEFT", rc.bw / 6 * (2 * i - 1), 0)
local lab = W.Text(rc.body, 11, T.text); lab:SetPoint("TOP", g, "BOTTOM", 0, -3)
local sub = W.Text(rc.body, 10, T.dim); sub:SetPoint("TOP", lab, "BOTTOM", 0, -1)
p.gauges[i] = { ring = g, lab = lab, sub = sub }
end
local fc = Panel(p, "Your legend", "crown", w1 + w2 + GAP * 2, y3, w3, h3, "What defines this character: favourite spell, nemesis, most hunted creature, best fight and homeland.")
p.legend = {}
local LH = math.max(16, math.floor(fc.bh / 5))
for i = 1, 5 do
local l = W.Text(fc.body, 10, T.dim); l:SetPoint("TOPLEFT", 0, -(i - 1) * LH)
local v = W.Text(fc.body, 12, T.amber, nil, "RIGHT"); v:SetPoint("TOPRIGHT", 0, -(i - 1) * LH)
v:SetPoint("LEFT", fc.body, "LEFT", 92, 0)
p.legend[i] = { l = l, v = v }
end
function p:Update(view, base, sess)
UpdateDashboardKpis(self, view, base, sess)
-- zones
local zk = ns.TopList(base, "zonekills", 5)
local zd = base.t.zonedeaths or {}
local list = {}
for i, e in ipairs(zk) do list[i] = { e[1], e[2], zd[e[1]] or 0 } end
self.mirror:Set(list)
-- gold
local vals, labels = {}, {}
local net, inn, out, best = 0, 0, 0, 0
for i, e in ipairs(ns.DaySeries(base, function(d) return (d.money_in or 0) - (d.money_out or 0) end, 30)) do
vals[i] = { e.v }; labels[i] = DayLabel(e.d)
net = net + e.v; best = math.max(best, e.v)
end
for _, e in ipairs(ns.DaySeries(base, "money_in", 30)) do inn = inn + e.v end
for _, e in ipairs(ns.DaySeries(base, "money_out", 30)) do out = out + e.v end
self.goldBig:SetText(Money(net))
self.goldInfo:SetText("Net, last 30 days\nEarned " .. Money(inn) .. "\nSpent " .. Money(out) .. "\nBest day " .. Money(best))
self.goldCols:Set(vals, { C.amber }, labels, { labels[1], labels[15], "Today" }, Money, { "Net gold" })
-- deaths
local o = c(base, "deaths_fatigue") + c(base, "deaths_slime")
self.deathRing:Set({
{ "Creatures", c(base, "deaths_npc"), C.amber }, { "Players", c(base, "deaths_pvp"), C.rust },
{ "Falling", c(base, "deaths_fall"), C.cream2 }, { "Drowning", c(base, "deaths_drown"), C.teal },
{ "Fire / lava", c(base, "deaths_lava"), C.amber2 or C.rust }, { "Other", o, C.dim },
}, Int(c(base, "deaths")), "deaths")
-- bands
local bv, bLabels = {}, {}
local bq, bk, bd = base.t.bandquests or {}, base.t.bandkills or {}, base.t.banddeaths or {}
for i = 1, 6 do
local lo = (i - 1) * 10
local key = (lo == 0 and 1 or lo) .. "-" .. (lo + 9)
bv[i] = { bq[key] or 0, (bk[key] or 0) / 10, bd[key] or 0 }
bLabels[i] = "Levels " .. key
end
self.bands:Set(bv, { C.cream2, C.amber, C.rust }, bLabels, { "1-9", "20-29", "50-59" }, ns.FMT.num1, { "Quests", "Kills ÷10", "Deaths" })
-- gold sources
local loot, quest, vend, ah, mail = c(base, "money_loot"), c(base, "money_quest"), c(base, "money_vendor_in"), c(base, "money_ah_in"), c(base, "money_mail_in")
local other = math.max(0, c(base, "money_in") - loot - quest - vend - ah - mail)
self.srcRing:Set({
{ "Looted", loot, C.amber }, { "Quests", quest, C.cream2 }, { "Vendors", vend, C.amber2 },
{ "Auctions", ah, C.teal }, { "Mail", mail, C.rust }, { "Other", other, C.dim },
}, Money(c(base, "money_in")), "earned", Money)
-- jumps by hour
local jh = base.t.jumphour or {}
local dots = {}
for b = 1, 12 do dots[b] = (jh[tostring((b - 1) * 2)] or 0) + (jh[tostring((b - 1) * 2 + 1)] or 0) end
self.jumpDots:Set(dots, { "00", "12", "23" })
-- steps per day
local sv, sl = Series(base, function(d) return (d.dist_foot or 0) * ns.YARDS_TO_STEPS end, 30)
self.stepCols:Set(sv, { C.cream2 }, sl, { sl[1], sl[15], "Today" }, Int, { "Steps" }, true)
-- rates
local r1 = ns.Div(c(base, "crits") * 100, c(base, "hits"))
local r2 = ns.Div(c(base, "quests_done") * 100, c(base, "quests_accepted"))
local r3 = ns.Div(c(base, "runs_party_boss") * 100, c(base, "runs_party"))
local R = {
{ r1, C.amber, "Crit rate", Int(c(base, "crits")) .. " crits" },
{ r2, C.cream2, "Quests finished", Int(c(base, "quests_done")) .. " / " .. Int(c(base, "quests_accepted")) },
{ r3, C.rust, "Runs with boss", Int(c(base, "runs_party_boss")) .. " / " .. Int(c(base, "runs_party")) },
}
for i, g in ipairs(self.gauges) do
g.ring:SetPercent(R[i][1], R[i][2], string.format("%d%%", R[i][1] + 0.5))
g.lab:SetText(R[i][3]); g.sub:SetText(R[i][4])
end
-- legend
local function Top(id) local t = ns.TopList(base, id, 1)[1] return t and tostring(t[1]) or "—", t and t[2] or 0 end
local spell, sv = Top("spelldamage")
local nem = Top("hurtby")
local hunted, hk = Top("creatures")
local home = Top("zonetime")
local dps = base.r and base.r.max_fight_dps
local rows = {
{ "Signature spell", spell ~= "—" and (spell .. " " .. ns.GREY .. Int(sv) .. "|r") or "—" },
{ "Nemesis", nem },
{ "Most hunted", hunted ~= "—" and (hunted .. " " .. ns.GREY .. Int(hk) .. "|r") or "—" },
{ "Best fight", dps and (ns.FMT.num1(dps) .. " dps") or "—" },
{ "Homeland", home },
}
for i, e in ipairs(self.legend) do e.l:SetText(rows[i][1]:upper()); e.v:SetText(rows[i][2]) end
end
end
-- ============================================================ CATEGORY PAGES
local function CategoryPage(id, kpis, panels, cols)
local p = NewPage(id)
KpiRow(p, kpis)
local tw = math.max(470, math.floor(CW * 0.5))
if cols and cols.cols and not cols.scaled then cols.cols[1][2] = cols.cols[1][2] + (tw - 470); cols.scaled = true end
local tc = Panel(p, (cols and cols.title) or "All statistics", "lists", 0, BODY_Y, tw, BODY_H, "Hover a row to see how it is measured. Click it for its last 30 days, best day and every character.")
p.table = W.Table(tc.body, tc.bw, tc.bh, cols and cols.cols or {
{ "STATISTIC", 230 + (tw - 470), kind = "text" }, { "LIFETIME", 120, kind = "num" }, { "SESSION", 0, kind = "dim" },
}, function(d) if d.def then ns.ShowStatDetail(d.def) end end)
local rx, rw = tw + GAP, CW - tw - GAP
local y = BODY_Y
p.panels = {}
for i, def in ipairs(panels) do
local h = def.h or (BODY_H - (y - BODY_Y))
local card = Panel(p, def.title, def.icon, rx, y, rw, h, def.tip)
p.panels[i] = { def = def, obj = def.build(card.body, card.bw, card.bh) }
y = y + h + GAP
end
function p:Update(view, base, sess)
UpdateKpis(self, view, base, sess)
local rows, sections
if cols and cols.rows then
rows, sections = cols.rows(view, base, sess, self.focus)
else
self.table:SetHeader(2, RangeName())
self.table:SetHeader(3, Settings().range == "session" and "TODAY" or "SESSION")
rows, sections = StatRows(id, view, sess, self.focus)
end
self.sections = sections
self.table:SetData(rows, true)
for _, pn in ipairs(self.panels) do pn.def.update(pn.obj, view, base, sess) end
end
function p:SectionTabs() return TableSectionTabs(self.table, self.sections) end
function p:FocusStat(label)
self.focus = label
ns.RefreshWindow()
FocusRow(self, self.table, label)
end
p.table.onScroll = function() if ns.UpdateSectionTabs then ns.UpdateSectionTabs() end end
return p
end
local function RingPanel(title, icon, h, partsFn, center, tip)
return { title = title, icon = icon, h = h, tip = tip,
build = function(b, bw, bh) return W.RingWithLegend(b, bw, bh) end,
update = function(o, v, base, s) local parts, big, small, fmt = partsFn(base, v, s); o:Set(parts, big, small, fmt) end }
end
local function ListPanel(title, icon, h, tally, fmt, n, tip)
return { title = title, icon = icon, h = h, tip = tip,
build = function(b, bw, bh) return W.BarList(b, bw, bh, n or 6) end,
update = function(o, v, base) o:Set(ns.TopList(base, tally, n or 6), fmt) end }
end
local function DayPanel(title, icon, h, mode, series, fn, colors, names, fmt, tip)
return { title = title, icon = icon, h = h, tip = tip,
build = function(b, bw, bh)
local o = { cols = W.Columns(b, bw, bh - (series > 1 and 16 or 0), 30, mode, series) }
if series > 1 then
local items = {}
for i, n in ipairs(names) do items[i] = { n, colors[i] } end
local lg = W.Legend(b, items); lg:SetPoint("BOTTOMLEFT", 0, 0)
end
return o
end,
update = function(o, v, base)
local vals, labels = {}, {}
for i, e in ipairs(ns.DaySeries(base, function(d) return d end, 30)) do
vals[i] = fn(e.v or {}); labels[i] = DayLabel(e.d)
end
o.cols:Set(vals, colors, labels, { labels[1], labels[15], "Today" }, fmt, names, series == 1)
end }
end
local function BuildCategories()
CategoryPage("travel", {
{ label = "Total distance (yd)", icon = "travel", value = function(v) return c(v, "dist_total") end,
sub = function(v, b, s) return string.format("%.0f mi · %s mi session", c(v, "dist_total") / 1760, ns.GOLD .. string.format("+%.1f", c(s, "dist_total") / 1760) .. "|r") end },
{ label = "On foot (yd)", icon = "steps", value = function(v) return c(v, "dist_foot") end, sub = function(v) return Int(ns.Steps(v)) .. " steps" end },
{ label = "Mounted (yd)", icon = "horseshoe", value = function(v) return c(v, "dist_mount") end, sub = function(v) return Int(c(v, "mount_ups")) .. " mount-ups" end },
{ label = "Flight paths (yd)", icon = "wing", value = function(v) return c(v, "dist_taxi") end, sub = function(v) return Int(c(v, "flights")) .. " flights · " .. Money(c(v, "money_taxi")) end },
}, {
RingPanel("How you travel", "travel", 180, function(b)
return { { "On foot", c(b, "dist_foot"), C.cream2 }, { "Mounted", c(b, "dist_mount"), C.amber }, { "Flight", c(b, "dist_taxi"), C.amber2 },
{ "Ghost", c(b, "dist_ghost"), C.dim }, { "Swim", c(b, "dist_swim"), C.teal } },
c(b, "dist_total") >= 1760 and string.format("%.1f", c(b, "dist_total") / 1760) or Int(c(b, "dist_total")),
c(b, "dist_total") >= 1760 and "miles" or "yards", function(n) return string.format("%.0f%%", ns.Div(n * 100, c(b, "dist_total"))) end
end),
ListPanel("Zones by distance", "travel", 170, "zonedist", function(n) return n >= 10000 and string.format("%.0fk yd", n / 1000) or (Int(n) .. " yd") end, 6),
DayPanel("Distance per day", "timeline", nil, "stack", 2, function(d) return { d.dist_foot or 0, d.dist_mount or 0 } end,
{ C.cream2, C.amber }, { "On foot", "Mounted" }, function(n) return Int(n) .. " yd" end),
})
CategoryPage("combat", {
{ label = "Hits landed", icon = "sword", value = function(v) return c(v, "hits") end, sub = function(v)
if c(v, "dmg_done") > 0 then return Int(c(v, "dmg_done")) .. " damage · " .. string.format("%.1f DPS", ns.Div(c(v, "dmg_done"), c(v, "time_combat"))) end
return Int(c(v, "fights_won")) .. " fights won"
end },
{ label = "Critical hits", icon = "star", value = function(v) return c(v, "crits") end, sub = function(v) return string.format("%.1f%% crit rate", ns.Div(c(v, "crits") * 100, c(v, "hits"))) end },
{ label = "Dodges + parries", icon = "shield", value = function(v) return c(v, "in_dodge") + c(v, "in_parry") end, sub = function(v) return Int(c(v, "in_dodge")) .. " dodged · " .. Int(c(v, "in_parry")) .. " parried" end },
{ label = "Enemy players killed", icon = "crown", value = function(v) return c(v, "kills_pvp") end, sub = function(v) return Int(c(v, "hk_server")) .. " honorable kills" end },
}, {
RingPanel("Your attacks", "sword", 180, function(b)
return { { "Hits", math.max(0, c(b, "hits") - c(b, "crits")), C.cream2 }, { "Crits", c(b, "crits"), C.amber },
{ "Missed", c(b, "out_miss"), C.dim }, { "Dodged", c(b, "out_dodge"), C.rust }, { "Parried", c(b, "out_parry"), C.amber2 },
{ "Blocked", c(b, "out_block"), C.teal }, { "Resisted", c(b, "out_resist"), C.edge or C.dim } },
Int(c(b, "hits") + c(b, "misses_out")), "attacks"
end),
RingPanel("Attacks on you", "shield", 180, function(b)
return { { "Hits", math.max(0, c(b, "hits_taken") - c(b, "crits_taken")), C.cream2 }, { "Crits", c(b, "crits_taken"), C.rust },
{ "Dodged", c(b, "in_dodge"), C.amber }, { "Parried", c(b, "in_parry"), C.amber2 }, { "Blocked", c(b, "in_block"), C.teal },
{ "Missed", c(b, "in_miss"), C.dim }, { "Resisted", c(b, "in_resist"), T.tileHi } },
Int(c(b, "hits_taken") + c(b, "avoided_in")), "incoming"
end),
DayPanel("Kills per day", "sword", nil, "single", 1, function(d) return { (d.kills_npc or 0) + (d.kills_pvp or 0) } end, { C.amber }, { "Kills" }, Int),
})
CategoryPage("deaths", {
{ label = "Deaths", icon = "skull", value = function(v) return c(v, "deaths") end, sub = function(v) return string.format("%.1f kills per death", ns.Div(ns.Kills(v), c(v, "deaths"))) end },
{ label = "Corpse runs", icon = "travel", value = function(v) return c(v, "corpse_runs") end, sub = function(v) return "longest " .. Time(v.r.max_corpse_time or 0) end },
{ label = "Falls survived", icon = "fall", value = function(v) return c(v, "falls_survived") end, sub = function(v) return "biggest " .. Int(v.r.max_fall_survived or 0) .. " dmg" end },
{ label = "Seconds dead", icon = "clock", value = function(v) return c(v, "time_dead") end, sub = function(v) return Time(c(v, "time_dead")) .. " total" end },
}, {
RingPanel("Deaths by cause", "skull", 180, function(b)
return { { "Creatures", c(b, "deaths_npc"), C.amber }, { "Players", c(b, "deaths_pvp"), C.rust }, { "Falling", c(b, "deaths_fall"), C.cream2 },
{ "Drowning", c(b, "deaths_drown"), C.teal }, { "Fatigue", c(b, "deaths_fatigue"), C.dim }, { "Lava / fire", c(b, "deaths_lava"), C.amber2 } },
Int(c(b, "deaths")), "deaths"
end),
ListPanel("Killed most often by", "skull", 170, "killers", Int, 6),
ListPanel("Zones by deaths", "travel", nil, "zonedeaths", Int, 7),
})
CategoryPage("adventure", {
{ label = "Quests completed", icon = "scroll", value = function(v) return c(v, "quests_done") end, sub = function(v) return string.format("%.0f%% of accepted", ns.Div(c(v, "quests_done") * 100, c(v, "quests_accepted"))) end },
{ label = "Dungeon runs", icon = "tower", value = function(v) return c(v, "runs_party") end, sub = function(v) return Int(c(v, "runs_party_boss")) .. " with a boss kill" end },
{ label = "Dungeon bosses", icon = "tower", value = function(v) return c(v, "boss_kills_party") end, sub = function(v) return Int((v.un and v.un.bosses_party) or 0) .. " different" end },
{ label = "Raid bosses", icon = "crown", value = function(v) return c(v, "boss_kills_raid") end, sub = function(v) return Int(c(v, "raid_clears")) .. " full clears" end },
}, {
{ title = "By level band", icon = "adventure", h = 180, tip = "Quests, kills (÷10) and deaths for each 10-level band.",
build = function(b, bw, bh)
local o = W.Columns(b, bw, bh - 16, 6, "group", 3)
local lg = W.Legend(b, { { "Quests", C.cream2 }, { "Kills ÷10", C.amber }, { "Deaths", C.rust } }); lg:SetPoint("BOTTOMLEFT", 0, 0)
return o
end,
update = function(o, v, base)
local bv, bl = {}, {}
local bq, bk, bd = base.t.bandquests or {}, base.t.bandkills or {}, base.t.banddeaths or {}
for i = 1, 6 do
local lo = (i - 1) * 10
local key = (lo == 0 and 1 or lo) .. "-" .. (lo + 9)
bv[i] = { bq[key] or 0, (bk[key] or 0) / 10, bd[key] or 0 }; bl[i] = "Levels " .. key
end
o:Set(bv, { C.cream2, C.amber, C.rust }, bl, { "1-9", "20-29", "50-59" }, ns.FMT.num1, { "Quests", "Kills ÷10", "Deaths" })
end },
ListPanel("Instance runs", "tower", 170, "instances", Int, 6),
DayPanel("XP per day", "adventure", nil, "single", 1, function(d) return { d.xp or 0 } end, { C.amber }, { "XP" }, Int),
})
CategoryPage("wealth", {
{ label = "Gold earned", icon = "coin", value = function(v) return math.floor(c(v, "money_in") / 10000) end, exact = function(v) return Money(c(v, "money_in")) end, sub = function(v) return Money(c(v, "money_in")) end },
{ label = "Gold spent", icon = "coin", value = function(v) return math.floor(c(v, "money_out") / 10000) end, exact = function(v) return Money(c(v, "money_out")) end, sub = function(v) return Money(c(v, "money_out")) end },
{ label = "Items looted", icon = "chest", value = function(v) return c(v, "items_looted") end, sub = function(v) return Int(c(v, "loot_q4")) .. " epics · " .. Int(c(v, "loot_q3")) .. " blues" end },
{ label = "Repairs", icon = "shield", value = function(v) return c(v, "repairs") end, sub = function(v) return Money(c(v, "money_repair")) .. " spent" end },
}, {
RingPanel("Gold sources", "coin", 180, function(b)
local loot, quest, vend, ah, mail = c(b, "money_loot"), c(b, "money_quest"), c(b, "money_vendor_in"), c(b, "money_ah_in"), c(b, "money_mail_in")
return { { "Looted", loot, C.amber }, { "Quests", quest, C.cream2 }, { "Vendors", vend, C.amber2 }, { "Auctions", ah, C.teal },
{ "Mail", mail, C.rust }, { "Other", math.max(0, c(b, "money_in") - loot - quest - vend - ah - mail), C.dim } },
Money(c(b, "money_in")), "earned", Money
end),
RingPanel("Loot by quality", "chest", 180, function(b)
return { { "Poor", c(b, "loot_q0"), C.dim }, { "Common", c(b, "loot_q1"), C.cream }, { "Uncommon", c(b, "loot_q2"), C.teal },
{ "Rare", c(b, "loot_q3"), C.cream2 }, { "Epic", c(b, "loot_q4"), C.amber }, { "Legendary", c(b, "loot_q5"), C.rust } },
Int(c(b, "items_looted")), "items"
end),
DayPanel("Net gold per day", "coin", nil, "signed", 1, function(d) return { (d.money_in or 0) - (d.money_out or 0) } end, { C.amber }, { "Net gold" }, Money),
})
CategoryPage("social", {
{ label = "Chat messages", icon = "social", value = function(v) return c(v, "chat_sent") end, sub = function(v) return Int(c(v, "whispers_sent")) .. " whispers sent" end },
{ label = "Emotes", icon = "social", value = function(v) return c(v, "emotes") end, sub = function(v) return Int(c(v, "emote_DANCE")) .. " dances · " .. Int(c(v, "emote_CHICKEN")) .. " chickens" end },
{ label = "Critters loved", icon = "heart", value = function(v) return c(v, "critters_loved") end, sub = function(v) return Int(c(v, "critters_love_kill")) .. " then killed · " .. Int(c(v, "ui_errors")) .. " red errors" end },
{ label = "Stats checked", icon = "dashboard", value = function(v) return c(v, "lts_opens") end, sub = function() return "Yes, this counts too." end },
}, {
ListPanel("Favourite emotes", "social", 180, "emotes", Int, 6),
ListPanel("Red error messages", "skull", 180, "uierrors", Int, 6),
DayPanel("Chat messages per day", "social", nil, "single", 1, function(d) return { d.chat_sent or 0 } end, { C.cream2 }, { "Messages" }, Int),
})
CategoryPage("life", {
{ label = "Times drunk", icon = "social", value = function(v) return c(v, "times_drunk") end, sub = function(v) return Int(c(v, "drunk_smashed")) .. " completely smashed" end },
{ label = "Campfires lit", icon = "star", value = function(v) return c(v, "campfires") end, sub = function(v) return Int(c(v, "nights_camped")) .. " nights camped out" end },
{ label = "Hearth locations", icon = "star", value = function(v) return (v.un and v.un.bindspots) or 0 end, sub = function(v) return Int((v.un and v.un.hearthstones) or 0) .. " unique hearthstones · " .. Int(c(v, "hearths")) .. " used" end },
{ label = "Books read", icon = "scroll", value = function(v) return c(v, "books_read") end, sub = function(v) return Int(c(v, "potions")) .. " potions drunk" end },
}, {
RingPanel("Where you rest at night", "clock", 180, function(b)
return { { "Camped out", c(b, "nights_camped"), C.amber }, { "Inn or city", c(b, "nights_inn"), C.cream2 } },
Int(c(b, "nights_camped") + c(b, "nights_inn")), "logouts"
end),
ListPanel("Where you camped", "travel", 170, "campzones", Int, 6),
DayPanel("Time in the wild per day", "timeline", nil, "single", 1, function(d) return { d.time_wild or 0 } end, { C.amber }, { "Wild" }, Time),
})
CategoryPage("records", {
{ label = "Biggest hit", icon = "sword", value = function(v) return v.r.max_hit or 0 end, sub = function(v) return v.r.max_hit_what or "" end },
{ label = "Biggest crit", icon = "star", value = function(v) return v.r.max_crit or 0 end, sub = function(v) return v.r.max_crit_what or "" end },
{ label = "Longest kill streak", icon = "skull", value = function(v) return v.r.max_streak or 0 end, sub = function() return "kills without dying" end },
{ label = "Biggest heal", icon = "heart", value = function(v) return v.r.max_heal or 0 end, sub = function(v) return v.r.max_heal_what or "" end },
}, {
{ title = "Time per level", icon = "clock", h = 280, tip = "Online time spent on each level. The level you are on now is shown as it grows; the level you installed on is marked (since install).",
build = function(b, bw, bh) return W.BarList(b, bw, bh, 11) end,
update = function(o, v, base)
local list = ns.TopList(base, "leveltime", 10)
local m = ns.char and ns.char.meta
if base == ns.char and m and m.levelMark and m.levelMarkLevel == UnitLevel("player") then
table.insert(list, 1, { "Level " .. m.levelMarkLevel .. (m.levelMarkPartial and " (since install)" or " (now)"), (ns.char.c.time_online or 0) - m.levelMark })
end
o:Set(list, Time)
end },
ListPanel("Most cast spells", "star", nil, "spells", Int, 10),
}, {
title = "Records",
cols = { { "RECORD", 250, kind = "text" }, { "BEST", 100, kind = "num" }, { "SOURCE", 0, kind = "dim" } },
rows = function(view, base, sess, focus)
local rows, sections = {}, {}
for _, group in ipairs(ns.SectionedStats("records")) do
rows[#rows + 1] = { group.name, "", "", header = true }
sections[#sections + 1] = { name = group.name, index = #rows }
for _, st in ipairs(group.stats) do
local v, what = ns.StatValue(st, view)
local na, naTip = ns.IsNA(st, v)
rows[#rows + 1] = { st.label, na and "n/a" or ((view.today) and "—" or ns.FormatStat(st, v)), what or "", tip = na and naTip or st.tip, what = what,
stat = st.label, def = st, color = (focus and st.label == focus) and T.amber or nil }
end
end
return rows, sections
end,
})
end
-- ============================================================ FASTEST & UNIQUES
local function BuildFastest()
local p = NewPage("fastest")
KpiRow(p, {
{ label = "Unique NPCs met", icon = "person", value = function(v) return (v.un and v.un.npcs) or 0 end, sub = function() return "talked, traded, trained" end },
{ label = "Unique creatures killed", icon = "sword", value = function(v) return (v.un and v.un.creatures) or 0 end, sub = function(v) return "of " .. Int(c(v, "kills_npc")) .. " kills" end },
{ label = "Dungeon bosses", icon = "tower", value = function(v) return c(v, "boss_kills_party") end, sub = function(v) return Int((v.un and v.un.bosses_party) or 0) .. " unique · " .. Int(c(v, "runs_party")) .. " runs" end },
{ label = "Raid bosses", icon = "crown", value = function(v) return c(v, "boss_kills_raid") end, sub = function(v) return Int((v.un and v.un.bosses_raid) or 0) .. " unique · " .. Int(c(v, "raid_clears")) .. " full clears" end },
})
local w1, w2 = 380, 260
local w3 = CW - w1 - w2 - GAP * 2
local fc = Panel(p, "Fastest times", "fastest", 0, BODY_Y, w1, BODY_H, "Lower is better. Instance clears count from entering to the last boss; a run only qualifies if it killed as many bosses as your best run there.")
p.fastT = W.Table(fc.body, fc.bw, fc.bh, { { "FASTEST", 170, kind = "text" }, { "BEST", 72, kind = "num" }, { "WHERE / WHEN", 0, kind = "dim" } })
local uc = Panel(p, "Uniques", "star", w1 + GAP, BODY_Y, w2, BODY_H, "How many different things you have met, killed, visited or used.")
p.uniqT = W.Table(uc.body, uc.bw, uc.bh, { { "DIFFERENT", 150, kind = "text" }, { "TOTAL", 46, kind = "num" }, { "NEW", 0, kind = "dim" } })
local ff = Panel(p, "Firsts", "clock", w1 + w2 + GAP * 2, BODY_Y, w3, BODY_H, "The first time something happened after LifeTimeStats was installed.")
p.firstT = W.Table(ff.body, ff.bw, ff.bh, { { "FIRST", 86, kind = "text" }, { "WHAT", 104, kind = "num" }, { "WHEN", 0, kind = "dim" } })
function p:Update(view, base, sess)
UpdateKpis(self, base, base, sess)
local rows = {}
local f, fw, fd = base.f or {}, base.fw or {}, base.fd or {}
for _, e in ipairs(ns.FASTEST) do
rows[#rows + 1] = { e.label, f[e.key] and Time(f[e.key]) or "—", f[e.key] and ((fw[e.key] or "") .. " " .. (fd[e.key] and date("%b %d", fd[e.key]) or "")) or "not yet" }
end
local dyn = {}
for k, v in pairs(f) do
local kind, name = k:match("^(%a+):(.+)$")
if kind then
dyn[#dyn + 1] = { (kind == "run" and "" or "Full clear: ") .. name, Time(v), (fw[k] or "") .. " " .. (fd[k] and date("%b %d", fd[k]) or ""),
tip = kind == "run" and "Fastest run, entering to last boss." or "Fastest full raid clear." }
end
end
table.sort(dyn, function(a, b) return a[1] < b[1] end)
for _, r in ipairs(dyn) do rows[#rows + 1] = r end
self.fastT:SetData(rows, true)
local ur = {}
local un, sun = base.un or {}, sess.un or {}
for _, e in ipairs(ns.UNIQUES) do
ur[#ur + 1] = { e.label, Int(un[e.set] or 0), Plus(sun[e.set]) }
end
self.uniqT:SetData(ur, true)
local fr = {}
local first, firstd = base.first or {}, base.firstd or {}
for _, e in ipairs(ns.FIRSTS) do
local short = e.label:gsub("^First ", "")
short = short:sub(1, 1):upper() .. short:sub(2)
fr[#fr + 1] = { short, first[e.key] or "not yet", firstd[e.key] and DateLabel(firstd[e.key]) or "", tipTitle = e.label, tip = first[e.key] }
end
self.firstT:SetData(fr, true)
end
end
-- ============================================================ TOP LISTS
local function BuildLists()
local p = NewPage("lists")
local lw = math.max(250, math.floor(CW * 0.27))
local lc = Panel(p, "Lists", "lists", 0, 0, lw, CH)
p.selected = ns.LISTS[1].id
p.nameT = W.Table(lc.body, lc.bw, lc.bh, { { "LIST", 180, kind = "text" }, { "#", 0, kind = "dim" } }, function(d)
p.selected = d.id
ns.RefreshWindow()