Repository navigation
Expand file tree
/
Copy pathUI.lua
More file actions
1197 lines (1065 loc) · 41.7 KB
/
Copy pathUI.lua
File metadata and controls
1197 lines (1065 loc) · 41.7 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
-- Wick's Ledger
-- UI.lua: slim bar + independent itemized panel + options
local ADDON, ns = ...
if not WickCore then return end -- said once in Core.lua
local WL = WicksLedger
WL.UI = WL.UI or {}
local UI = WL.UI
-- ============================================================
-- CONSTANTS
-- ============================================================
local BAR_W = 280
local BAR_H = 26
local PANEL_W_DEF = 360
local PANEL_H_MAX = 600
local PANEL_H_MIN = 120
local ROW_H = 24
local ICON_SIZE = 18
local HEADER_H = 24
local TAB_H = 20
local FOOTER_H = 30
local PAD = 8
-- Palette: tokens are references into Chrome.Colors, never copies, so a
-- look or theme change repaints every panel at once. The dim label colour
-- is the addon's own.
local Chrome = WickCore.Chrome
local C_BG = Chrome.Colors.voidBG
local C_HEADER = Chrome.Colors.shadow
local C_BORDER = Chrome.Colors.border
local C_GREEN = Chrome.Colors.fel
local C_TEXT = Chrome.Colors.text
local C_DIM = { 0.42, 0.35, 0.54, 1 }
-- ============================================================
-- CHROME HELPERS
-- Rule: BACKGROUND textures go on a bg child frame.
-- FontStrings go on the parent (no bg texture on parent).
-- BORDER/ARTWORK textures on parent are fine -- only BACKGROUND blocks text.
-- A colour set on a region after it was made is remembered by Chrome, so
-- a theme change finds it; a colour that is not a token is left alone.
-- ============================================================
local function Ink(fs, c, a)
fs:SetTextColor(c[1], c[2], c[3], a or c[4] or 1)
Chrome:Register(fs, c, "text", a)
end
local function Paint(tex, c, a)
tex:SetColorTexture(c[1], c[2], c[3], a or c[4] or 1)
Chrome:Register(tex, c, "texture", a)
end
local function Tint(tex, c, a)
tex:SetVertexColor(c[1], c[2], c[3], a or c[4] or 1)
Chrome:Register(tex, c, "vertex", a)
end
local function MakeBgChild(parent, c, a)
local f = CreateFrame("Frame", nil, parent)
f:SetAllPoints(parent)
local lvl = parent:GetFrameLevel()
f:SetFrameLevel(lvl > 0 and lvl - 1 or 0)
local t = f:CreateTexture(nil, "BACKGROUND")
t:SetAllPoints()
Paint(t, c, a)
return f
end
-- The border and the corner marks are the look's: a 1px line and fel
-- brackets in the flat styles, a ring in the textured ones.
local function AddBorder(f) Chrome:AddBorder(f) end
local function AddCornerAccents(f) Chrome:AddBrackets(f) end
-- One corner mark drawn on `host` at a corner of `rel`: the header and
-- footer carry the panel's marks so they draw above their own backgrounds.
-- Drawn only where the look draws marks at all.
local function Bracket(host, anchor, rel)
if Chrome:Modern() or Chrome:Corners() == "none" then return end
local B = Chrome.BRACKET
local h = Chrome:Texture(host, "OVERLAY", C_GREEN); h:SetPoint(anchor, rel, anchor); h:SetSize(B, 2)
local v = Chrome:Texture(host, "OVERLAY", C_GREEN); v:SetPoint(anchor, rel, anchor); v:SetSize(2, B)
end
-- ============================================================
-- POSITION / SIZE PERSISTENCE
-- ============================================================
local function SavePos(key, frame)
if not WL.db then return end
local pt, _, rpt, x, y = frame:GetPoint()
WL.db[key] = { pt = pt, rpt = rpt, x = x, y = y }
end
local function SaveSize(key, frame)
if not WL.db then return end
WL.db[key] = { w = frame:GetWidth(), h = frame:GetHeight() }
end
local function LoadPos(key, frame, defPt, defX, defY)
local p = WL.db and WL.db[key]
if p and p.pt then
frame:SetPoint(p.pt, UIParent, p.rpt, p.x, p.y)
else
frame:SetPoint(defPt, UIParent, defPt, defX, defY)
end
end
local function LoadSize(key, frame, defW, defH)
local s = WL.db and WL.db[key]
if s and s.w then
frame:SetSize(math.max(s.w, 200), math.max(s.h, PANEL_H_MIN))
else
frame:SetSize(defW, defH)
end
end
-- ============================================================
-- ELAPSED FORMATTER
-- ============================================================
local function FormatElapsed(secs)
local h = math.floor(secs / 3600)
local m = math.floor((secs % 3600) / 60)
local s = secs % 60
if h > 0 then return string.format("%d:%02d:%02d", h, m, s) end
return string.format("%d:%02d", m, s)
end
local function FormatXP(xp)
xp = math.floor(xp or 0)
if xp >= 1000 then return string.format("%.1fk", xp / 1000) end
return tostring(xp)
end
-- ============================================================
-- ROW POOL
-- Every row: bg child frame holds the separator BACKGROUND texture.
-- FontStrings live on the row frame itself (no BACKGROUND on it).
-- ============================================================
local rowPool = {}
local activeRows = {}
local function AcquireRow(parent, panelW)
local row = table.remove(rowPool)
if not row then
row = CreateFrame("Button", nil, parent)
row:SetHeight(ROW_H)
row:EnableMouse(true)
row:RegisterForClicks("LeftButtonUp", "RightButtonUp")
-- separator on bg child
local bgChild = MakeBgChild(row, C_BORDER, 0)
local sep = bgChild:CreateTexture(nil, "BACKGROUND")
Paint(sep, C_BORDER, 0.3)
sep:SetHeight(1)
sep:SetPoint("BOTTOMLEFT", row, "BOTTOMLEFT")
sep:SetPoint("BOTTOMRIGHT", row, "BOTTOMRIGHT")
row.icon = row:CreateTexture(nil, "ARTWORK")
row.icon:SetSize(ICON_SIZE, ICON_SIZE)
row.icon:SetPoint("LEFT", row, "LEFT", PAD, 0)
row.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
row.name = row:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(row.name, 10, "")
Ink(row.name, C_TEXT)
row.name:SetPoint("LEFT", row.icon, "RIGHT", 4, 0)
row.name:SetJustifyH("LEFT")
row.name:SetWordWrap(false)
row.value = row:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(row.value, 10, "")
Ink(row.value, C_TEXT)
row.value:SetPoint("RIGHT", row, "RIGHT", -PAD, 0)
row.value:SetJustifyH("RIGHT")
end
row:SetParent(parent)
row:ClearAllPoints()
-- name width: fills between icon+gap and value column
local w = panelW or PANEL_W_DEF
row.name:SetWidth(w - PAD - ICON_SIZE - 4 - 110)
row:Show()
return row
end
local function ReleaseRow(row)
row:Hide()
row:SetParent(nil)
row:SetScript("OnEnter", nil)
row:SetScript("OnLeave", nil)
row:SetScript("OnMouseUp", nil)
table.insert(rowPool, row)
end
-- ============================================================
-- SLIM BAR
-- ============================================================
local bar, expandBtn, statusText, panelOpen
local function BuildBar()
bar = CreateFrame("Frame", "WicksLedgerBar", UIParent)
bar:SetSize(BAR_W, BAR_H)
bar:SetMovable(true)
bar:EnableMouse(true)
bar:RegisterForDrag("LeftButton")
bar:SetScript("OnDragStart", function(self)
WicksSnap.Detach("ledger_bar")
self:StartMoving()
end)
bar:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
WicksSnap.TrySnap("ledger_bar")
SavePos("barPos", self)
end)
bar:SetFrameStrata("MEDIUM")
bar:SetClampedToScreen(true)
LoadPos("barPos", bar, "CENTER", 0, -300)
-- bg on child so BACKGROUND doesn't block bar FontStrings
MakeBgChild(bar, C_BG)
AddBorder(bar)
AddCornerAccents(bar)
local dot = bar:CreateTexture(nil, "OVERLAY")
dot:SetSize(6, 6)
Paint(dot, C_GREEN)
dot:SetPoint("LEFT", bar, "LEFT", PAD, 0)
bar.dot = dot
dot:Hide()
-- Expand button
expandBtn = CreateFrame("Button", nil, bar)
expandBtn:SetSize(20, BAR_H)
expandBtn:SetPoint("RIGHT", bar, "RIGHT", 0, 0)
local expandTex = expandBtn:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(expandTex, 14, "")
Ink(expandTex, C_GREEN)
expandTex:SetAllPoints()
expandTex:SetJustifyH("CENTER"); expandTex:SetJustifyV("MIDDLE")
expandTex:SetText("+")
expandBtn.label = expandTex
expandBtn:SetScript("OnClick", function()
if panelOpen then UI:ClosePanel() else UI:OpenPanel() end
end)
expandBtn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(Chrome:TitleMarkup("Wick's Ledger"))
GameTooltip:AddLine("Open itemized breakdown", 1, 1, 1)
GameTooltip:Show()
end)
expandBtn:SetScript("OnLeave", function() GameTooltip:Hide() end)
-- Start/stop icon button
local ssBtn = CreateFrame("Button", nil, bar)
ssBtn:SetSize(18, 18)
ssBtn:SetPoint("RIGHT", expandBtn, "LEFT", -4, 0)
local ssIcon = ssBtn:CreateTexture(nil, "ARTWORK")
ssIcon:SetAllPoints()
ssBtn.icon = ssIcon
bar.ssBtn = ssBtn
local ICO_PLAY = "Interface\\Buttons\\UI-SpellbookIcon-NextPage-Up"
local ICO_STOP = "Interface\\Buttons\\UI-StopButton"
local function UpdateSSBtn()
local S = WL.Session
if S and S.active then
ssIcon:SetTexture(ICO_STOP)
ssIcon:SetTexCoord(0, 1, 0, 1)
ssIcon:SetVertexColor(1, 0.4, 0.4, 1)
else
ssIcon:SetTexture(ICO_PLAY)
ssIcon:SetTexCoord(0, 1, 0, 1)
Tint(ssIcon, C_GREEN)
end
end
bar.UpdateSSBtn = UpdateSSBtn
UpdateSSBtn()
ssBtn:SetScript("OnClick", function()
local S = WL.Session
if S and S.active then S:Stop() else S:Start() end
UpdateSSBtn()
end)
ssBtn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
local S = WL.Session
GameTooltip:AddLine(S and S.active and "Stop session" or "Start session", 1, 1, 1)
GameTooltip:Show()
end)
ssBtn:SetScript("OnLeave", function() GameTooltip:Hide() end)
statusText = bar:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(statusText, 12, "")
Ink(statusText, C_TEXT)
statusText:SetPoint("LEFT", bar, "TOPLEFT", PAD + 10, -BAR_H / 2)
statusText:SetPoint("RIGHT", ssBtn, "LEFT", -4, 0)
statusText:SetJustifyH("LEFT")
statusText:SetText("idle")
bar.statusText = statusText
local tickAcc = 0
bar:SetScript("OnUpdate", function(self, elapsed)
tickAcc = tickAcc + elapsed
if tickAcc < 0.5 then return end
tickAcc = 0
local S = WL.Session
if S and S.active then
bar.dot:Show()
local P = WL.Prices
local elapsed = S:Elapsed()
local hrFac = elapsed > 60 and (3600 / elapsed) or 0
local val = P and P:FormatCopper(S.totalCopper) or "0c"
if hrFac > 0 and P then
val = val .. " |cff888888(" .. P:FormatGold(S.totalCopper * hrFac) .. "/hr)|r"
end
statusText:SetText(val .. " " .. FormatElapsed(elapsed))
else
bar.dot:Hide()
statusText:SetText("idle")
end
end)
WicksSnap.Register("ledger_bar", bar)
bar:Hide()
end
-- ============================================================
-- ITEMIZED PANEL
-- ============================================================
local panel
local PopulatePanel, PopulateHistory
local function BuildPanel()
panel = CreateFrame("Frame", "WicksLedgerPanel", UIParent)
panel:SetFrameStrata("MEDIUM")
panel:SetClampedToScreen(true)
panel:SetMovable(true)
panel:SetResizable(true)
panel:EnableMouse(true)
panel:RegisterForDrag("LeftButton")
panel:SetScript("OnDragStart", function(self)
WicksSnap.Detach("ledger_panel")
self:StartMoving()
end)
panel:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
WicksSnap.TrySnap("ledger_panel")
SavePos("panelPos", self)
end)
LoadSize("panelSize", panel, PANEL_W_DEF, 300)
LoadPos("panelPos", panel, "CENTER", 0, -100)
MakeBgChild(panel, C_BG)
AddBorder(panel)
-- Header
local header = CreateFrame("Frame", nil, panel)
header:SetHeight(HEADER_H)
header:SetPoint("TOPLEFT"); header:SetPoint("TOPRIGHT")
MakeBgChild(header, C_HEADER)
local hsep = header:CreateTexture(nil, "BORDER")
Paint(hsep, C_BORDER)
hsep:SetHeight(1); hsep:SetPoint("BOTTOMLEFT"); hsep:SetPoint("BOTTOMRIGHT")
Bracket(header, "TOPLEFT", panel); Bracket(header, "TOPRIGHT", panel)
local title = header:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(title, 11, "")
Ink(title, C_GREEN)
title:SetPoint("LEFT", header, "TOPLEFT", PAD, -HEADER_H / 2)
title:SetText("Wick's Ledger")
local closeBtn = CreateFrame("Button", nil, header)
closeBtn:SetSize(HEADER_H, HEADER_H)
closeBtn:SetPoint("RIGHT", header, "TOPRIGHT", 0, -HEADER_H / 2)
local closeTex = closeBtn:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(closeTex, 14, "")
Ink(closeTex, C_DIM)
closeTex:SetAllPoints(); closeTex:SetJustifyH("CENTER"); closeTex:SetJustifyV("MIDDLE")
closeTex:SetText("x")
closeBtn:SetScript("OnClick", function() UI:ClosePanel() end)
local gearBtn = CreateFrame("Button", nil, header)
gearBtn:SetSize(16, 16)
gearBtn:SetPoint("RIGHT", closeBtn, "LEFT", -4, 0)
local gearIcon = gearBtn:CreateTexture(nil, "ARTWORK")
gearIcon:SetAllPoints()
gearIcon:SetTexture("Interface\\Buttons\\UI-OptionsButton")
Tint(gearIcon, C_DIM)
gearBtn:SetScript("OnClick", function() UI:ToggleOptions() end)
gearBtn:SetScript("OnEnter", function(self)
Tint(gearIcon, C_GREEN)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Options", 1, 1, 1)
GameTooltip:Show()
end)
gearBtn:SetScript("OnLeave", function()
Tint(gearIcon, C_DIM)
GameTooltip:Hide()
end)
-- Tab strip (Session | History) below the header
local tabStrip = CreateFrame("Frame", nil, panel)
tabStrip:SetHeight(TAB_H)
tabStrip:SetPoint("TOPLEFT", panel, "TOPLEFT", 1, -HEADER_H)
tabStrip:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -1, -HEADER_H)
MakeBgChild(tabStrip, C_HEADER, 0.7)
local tabsep = tabStrip:CreateTexture(nil, "BORDER")
Paint(tabsep, C_BORDER)
tabsep:SetHeight(1); tabsep:SetPoint("BOTTOMLEFT"); tabsep:SetPoint("BOTTOMRIGHT")
local activeTab = "session"
local function makeTab(label, xOff, key)
local btn = CreateFrame("Button", nil, tabStrip)
btn:SetSize(70, TAB_H)
btn:SetPoint("LEFT", tabStrip, "LEFT", xOff, 0)
local fs = btn:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(fs, 9, "")
fs:SetAllPoints(); fs:SetJustifyH("CENTER"); fs:SetJustifyV("MIDDLE")
fs.key = key
btn._label = fs
return btn, fs
end
local sessionTab, sessionFS = makeTab("Session", PAD, "session")
local historyTab, historyFS = makeTab("History", PAD + 72, "history")
local function RefreshTabs()
if activeTab == "session" then
Ink(sessionFS, C_GREEN)
Ink(historyFS, C_DIM)
else
Ink(sessionFS, C_DIM)
Ink(historyFS, C_GREEN)
end
sessionFS:SetText("Session")
historyFS:SetText("History")
end
RefreshTabs()
panel.RefreshTabs = RefreshTabs
panel.getActiveTab = function() return activeTab end
panel.switchTab = function(key)
if activeTab == key then return end
activeTab = key
RefreshTabs()
end
sessionTab:SetScript("OnClick", function()
if activeTab == "session" then return end
activeTab = "session"
RefreshTabs()
PopulatePanel()
end)
historyTab:SetScript("OnClick", function()
if activeTab == "history" then return end
activeTab = "history"
RefreshTabs()
PopulateHistory()
end)
-- Scroll area (sits below tab strip)
local SCROLL_TOP = HEADER_H + TAB_H + 1
local scroll = CreateFrame("ScrollFrame", "WicksLedgerScroll", panel)
scroll:SetPoint("TOPLEFT", panel, "TOPLEFT", 1, -SCROLL_TOP)
scroll:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", -1, FOOTER_H + 1)
local content = CreateFrame("Frame", nil, scroll)
content:SetSize(PANEL_W_DEF - 2, 1)
scroll:SetScrollChild(content)
panel.scroll = scroll
panel.content = content
-- Footer
local footer = CreateFrame("Frame", nil, panel)
footer:SetHeight(FOOTER_H)
footer:SetPoint("BOTTOMLEFT"); footer:SetPoint("BOTTOMRIGHT")
MakeBgChild(footer, C_HEADER)
local ftop = footer:CreateTexture(nil, "BORDER")
Paint(ftop, C_BORDER)
ftop:SetHeight(1); ftop:SetPoint("TOPLEFT"); ftop:SetPoint("TOPRIGHT")
panel.footer = footer
local totalLabel = footer:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(totalLabel, 10, "")
Ink(totalLabel, C_DIM)
totalLabel:SetPoint("LEFT", footer, "TOPLEFT", PAD, -FOOTER_H / 2)
totalLabel:SetText("Total")
panel.totalLabel = totalLabel
local totalValue = footer:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(totalValue, 11, "")
Ink(totalValue, C_TEXT)
totalValue:SetPoint("RIGHT", footer, "TOPRIGHT", -PAD, -FOOTER_H / 2)
totalValue:SetJustifyH("RIGHT")
panel.totalValue = totalValue
Bracket(footer, "BOTTOMLEFT", panel)
-- Resize grip
local grip = CreateFrame("Frame", nil, panel)
grip:SetSize(12, 12)
grip:SetPoint("BOTTOMRIGHT", panel, "BOTTOMRIGHT", 0, 0)
grip:EnableMouse(true)
Bracket(grip, "BOTTOMRIGHT", grip)
grip:SetScript("OnMouseDown", function(self, btn)
if btn ~= "LeftButton" then return end
-- Pin TOPLEFT so the frame doesn't jump when sizing starts
local x, y = panel:GetLeft(), panel:GetTop()
panel:ClearAllPoints()
panel:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y)
panel:StartSizing("BOTTOMRIGHT")
end)
grip:SetScript("OnMouseUp", function()
panel:StopMovingOrSizing()
local w = panel:GetWidth()
local h = math.max(math.min(panel:GetHeight(), PANEL_H_MAX), PANEL_H_MIN)
panel:SetHeight(h)
SaveSize("panelSize", panel)
panel.content:SetWidth(w - 2)
end)
grip:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Drag to resize", 1, 1, 1)
GameTooltip:Show()
end)
grip:SetScript("OnLeave", function() GameTooltip:Hide() end)
WicksSnap.Register("ledger_panel", panel)
panel:Hide()
end
-- ============================================================
-- OPTIONS PANEL
-- ============================================================
local optPanel
local function BuildOptions()
local OPT_W = 290
local OPT_H = 256
local ROW_Y = 20
optPanel = CreateFrame("Frame", "WicksLedgerOptions", UIParent)
optPanel:SetSize(OPT_W, OPT_H)
optPanel:SetFrameStrata("HIGH")
optPanel:SetClampedToScreen(true)
optPanel:SetMovable(true)
optPanel:EnableMouse(true)
optPanel:RegisterForDrag("LeftButton")
optPanel:SetScript("OnDragStart", function(self)
WicksSnap.Detach("ledger_opt")
self:StartMoving()
end)
optPanel:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
WicksSnap.TrySnap("ledger_opt")
SavePos("optPos", self)
end)
LoadPos("optPos", optPanel, "CENTER", 100, 0)
-- bg child so FontStrings on optPanel are visible
MakeBgChild(optPanel, C_BG, 0.98)
AddBorder(optPanel)
-- Header: bg child on a header sub-frame
local header = CreateFrame("Frame", nil, optPanel)
header:SetHeight(HEADER_H)
header:SetPoint("TOPLEFT"); header:SetPoint("TOPRIGHT")
MakeBgChild(header, C_HEADER)
local hsep = header:CreateTexture(nil, "BORDER")
Paint(hsep, C_BORDER)
hsep:SetHeight(1); hsep:SetPoint("BOTTOMLEFT"); hsep:SetPoint("BOTTOMRIGHT")
-- All 4 brackets on the header anchored to optPanel corners
for _, corner in ipairs({ "TOPLEFT", "TOPRIGHT", "BOTTOMLEFT", "BOTTOMRIGHT" }) do Bracket(header, corner, optPanel) end
local title = header:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(title, 11, "")
Ink(title, C_GREEN)
title:SetPoint("LEFT", header, "TOPLEFT", PAD, -HEADER_H / 2)
title:SetText("Options")
local closeBtn = CreateFrame("Button", nil, header)
closeBtn:SetSize(HEADER_H, HEADER_H)
closeBtn:SetPoint("RIGHT", header, "TOPRIGHT", 0, -HEADER_H / 2)
local closeTex = closeBtn:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(closeTex, 14, "")
Ink(closeTex, C_DIM)
closeTex:SetAllPoints(); closeTex:SetJustifyH("CENTER"); closeTex:SetJustifyV("MIDDLE")
closeTex:SetText("x")
closeBtn:SetScript("OnClick", function() optPanel:Hide() end)
-- ---- Price source section ----
local srcLabel = optPanel:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(srcLabel, 9, "")
Ink(srcLabel, C_DIM)
srcLabel:SetPoint("TOPLEFT", optPanel, "TOPLEFT", PAD, -(HEADER_H + 10))
srcLabel:SetText("PRICE SOURCE")
local SOURCES = { "auto", "TSM", "Auctionator", "Auctioneer", "vendor" }
local SOURCE_LABELS = {
auto = "Auto (TSM > Auctionator > Auctioneer > Vendor)",
TSM = "TSM (TradeSkillMaster)",
Auctionator = "Auctionator",
Auctioneer = "Auctioneer",
vendor = "Vendor only",
}
local radioFrames = {}
local function RefreshRadios()
local cur = WL.db and WL.db.priceSource or "auto"
for _, rf in ipairs(radioFrames) do
local sel = (rf.src == cur)
Tint(rf.dot, sel and C_GREEN or C_DIM)
Ink(rf.lbl, sel and C_TEXT or C_DIM)
end
end
for i, src in ipairs(SOURCES) do
local rf = CreateFrame("Button", nil, optPanel)
rf:SetHeight(ROW_Y)
local yOff = -(HEADER_H + 22 + (i - 1) * ROW_Y)
rf:SetPoint("TOPLEFT", optPanel, "TOPLEFT", PAD, yOff)
rf:SetPoint("TOPRIGHT", optPanel, "TOPRIGHT", -PAD, yOff)
rf.src = src
local dot = rf:CreateTexture(nil, "ARTWORK")
dot:SetSize(7, 7)
Paint(dot, C_DIM)
dot:SetPoint("LEFT", rf, "LEFT", 0, 0)
rf.dot = dot
local lbl = rf:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(lbl, 10, "")
Ink(lbl, C_DIM)
lbl:SetPoint("LEFT", dot, "RIGHT", 6, 0)
lbl:SetText(SOURCE_LABELS[src])
rf.lbl = lbl
rf:SetScript("OnClick", function()
if WL.db then WL.db.priceSource = src end
RefreshRadios()
end)
table.insert(radioFrames, rf)
end
-- Divider
local divY = HEADER_H + 22 + #SOURCES * ROW_Y + 6
local div = optPanel:CreateTexture(nil, "BORDER")
Paint(div, C_BORDER, 0.5)
div:SetHeight(1)
div:SetPoint("TOPLEFT", optPanel, "TOPLEFT", PAD, -divY)
div:SetPoint("TOPRIGHT", optPanel, "TOPRIGHT", -PAD, -divY)
-- Auto mode toggle
local autoY = divY + 10
local autoBtn = CreateFrame("Button", nil, optPanel)
autoBtn:SetHeight(ROW_Y)
autoBtn:SetPoint("TOPLEFT", optPanel, "TOPLEFT", PAD, -autoY)
autoBtn:SetPoint("TOPRIGHT", optPanel, "TOPRIGHT", -PAD, -autoY)
local autoDot = autoBtn:CreateTexture(nil, "ARTWORK")
autoDot:SetSize(7, 7)
autoDot:SetPoint("LEFT", autoBtn, "LEFT", 0, 0)
autoBtn.dot = autoDot
local autoLbl = autoBtn:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(autoLbl, 10, "")
autoLbl:SetPoint("LEFT", autoDot, "RIGHT", 6, 0)
autoLbl:SetText("Auto-start on instance entry")
autoBtn.lbl = autoLbl
local function RefreshAutoBtn()
local on = WL.db and WL.db.autoMode
Tint(autoDot, on and C_GREEN or C_DIM)
Ink(autoLbl, on and C_TEXT or C_DIM)
end
autoBtn:SetScript("OnClick", function()
if WL.db then WL.db.autoMode = not WL.db.autoMode end
RefreshAutoBtn()
end)
-- Hard lock toggle
local hardY = autoY + ROW_Y
local hardBtn = CreateFrame("Button", nil, optPanel)
hardBtn:SetHeight(ROW_Y)
hardBtn:SetPoint("TOPLEFT", optPanel, "TOPLEFT", PAD, -hardY)
hardBtn:SetPoint("TOPRIGHT", optPanel, "TOPRIGHT", -PAD, -hardY)
local hardDot = hardBtn:CreateTexture(nil, "ARTWORK")
hardDot:SetSize(7, 7)
hardDot:SetPoint("LEFT", hardBtn, "LEFT", 0, 0)
hardBtn.dot = hardDot
local hardLbl = hardBtn:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(hardLbl, 10, "")
hardLbl:SetPoint("LEFT", hardDot, "RIGHT", 6, 0)
hardLbl:SetText("Hard lock (persist across resets)")
hardBtn.lbl = hardLbl
local function RefreshHardBtn()
local on = WL.db and WL.db.hardLock
Tint(hardDot, on and C_GREEN or C_DIM)
Ink(hardLbl, on and C_TEXT or C_DIM)
end
hardBtn:SetScript("OnClick", function()
if WL.db then WL.db.hardLock = not WL.db.hardLock end
RefreshHardBtn()
end)
hardBtn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Hard lock", 1, 1, 1)
GameTooltip:AddLine("Session pauses on instance exit instead of stopping.", 0.8, 0.8, 0.8, true)
GameTooltip:AddLine("Re-enter the instance to resume where you left off.", 0.8, 0.8, 0.8, true)
GameTooltip:Show()
end)
hardBtn:SetScript("OnLeave", function() GameTooltip:Hide() end)
-- Divider 2
local div2Y = hardY + ROW_Y + 6
local div2 = optPanel:CreateTexture(nil, "BORDER")
Paint(div2, C_BORDER, 0.5)
div2:SetHeight(1)
div2:SetPoint("TOPLEFT", optPanel, "TOPLEFT", PAD, -div2Y)
div2:SetPoint("TOPRIGHT", optPanel, "TOPRIGHT", -PAD, -div2Y)
-- Reset session button
local resetY = div2Y + 10
local resetBtn = CreateFrame("Button", nil, optPanel)
resetBtn:SetHeight(ROW_Y)
resetBtn:SetPoint("TOPLEFT", optPanel, "TOPLEFT", PAD, -resetY)
resetBtn:SetPoint("TOPRIGHT", optPanel, "TOPRIGHT", -PAD, -resetY)
local resetTex = resetBtn:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(resetTex, 10, "")
resetTex:SetTextColor(1, 0.4, 0.4, 1)
resetTex:SetPoint("LEFT", resetBtn, "LEFT", 0, 0)
resetTex:SetText("Reset session")
resetBtn:SetScript("OnClick", function()
if WL.Session and WL.Session.Reset then WL.Session:Reset() end
end)
resetBtn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine("Clear all session data", 1, 0.4, 0.4)
GameTooltip:Show()
end)
resetBtn:SetScript("OnLeave", function() GameTooltip:Hide() end)
optPanel:SetScript("OnShow", function()
RefreshRadios()
RefreshAutoBtn()
RefreshHardBtn()
end)
WicksSnap.Register("ledger_opt", optPanel)
optPanel:Hide()
end
function UI:ToggleOptions()
if not optPanel then BuildOptions() end
if optPanel:IsShown() then
optPanel:Hide()
if WL.db then WL.db.optShown = false end
else
optPanel:Show()
if WL.db then WL.db.optShown = true end
end
end
-- ============================================================
-- CONTEXT MENU
-- A minimal right-click menu. One item at a time; hides on any click outside.
-- ============================================================
local ctxMenu
local function BuildContextMenu()
ctxMenu = CreateFrame("Frame", "WicksLedgerCtxMenu", UIParent)
ctxMenu:SetFrameStrata("TOOLTIP")
ctxMenu:SetClampedToScreen(true)
ctxMenu:EnableMouse(true)
MakeBgChild(ctxMenu, C_BG, 0.98)
AddBorder(ctxMenu)
ctxMenu:Hide()
ctxMenu:SetScript("OnLeave", function() ctxMenu:Hide() end)
ctxMenu._items = {}
end
local function ShowContextMenu(x, y, items)
if not ctxMenu then BuildContextMenu() end
-- Release old item buttons
for _, btn in ipairs(ctxMenu._items) do btn:Hide() end
ctxMenu._items = {}
local ITEM_H = 22
local menuW = 180
local yOff = -4
for _, item in ipairs(items) do
local btn = CreateFrame("Button", nil, ctxMenu)
btn:SetSize(menuW - 8, ITEM_H)
btn:SetPoint("TOPLEFT", ctxMenu, "TOPLEFT", 4, yOff)
local lbl = btn:CreateFontString(nil, "OVERLAY")
Chrome:SetFont(lbl, 10, "")
Ink(lbl, C_TEXT)
lbl:SetAllPoints(); lbl:SetJustifyH("LEFT"); lbl:SetJustifyV("MIDDLE")
lbl:SetText(item.label)
btn:SetScript("OnEnter", function() Ink(lbl, C_GREEN) end)
btn:SetScript("OnLeave", function() Ink(lbl, C_TEXT) end)
btn:SetScript("OnClick", function()
ctxMenu:Hide()
if item.onClick then item.onClick() end
end)
yOff = yOff - ITEM_H
table.insert(ctxMenu._items, btn)
end
ctxMenu:SetSize(menuW, -yOff + 4)
ctxMenu:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", x, y)
ctxMenu:Show()
end
-- ============================================================
-- PANEL POPULATION
-- ============================================================
PopulateHistory = function()
local content = panel.content
for _, row in ipairs(activeRows) do ReleaseRow(row) end
activeRows = {}
if panel.footer then panel.footer:Hide() end
local P = WL.Prices
local history = WL.charDB and WL.charDB.history or {}
local panW = panel:GetWidth()
local y = 0
if #history == 0 then
local row = AcquireRow(content, panW)
table.insert(activeRows, row)
row:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
row:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
row.icon:SetTexture(nil)
Chrome:SetFont(row.name, 10, "")
Ink(row.name, C_DIM)
row.name:SetText("No past sessions yet")
row.value:SetText("")
y = y + ROW_H
else
for i, entry in ipairs(history) do
-- Section header: date + zone
local dateStr = entry.startTime and date("%Y-%m-%d %H:%M", entry.startTime) or "?"
local zone = entry.zoneName or "?"
local hdr = AcquireRow(content, panW)
table.insert(activeRows, hdr)
hdr:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
hdr:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
hdr.icon:SetTexture(nil)
Chrome:SetFont(hdr.name, 9, "")
Ink(hdr.name, C_DIM)
hdr.name:SetText(string.format("#%d %s %s", i, dateStr, zone))
-- elapsed + total on right
local elapsed = entry.elapsed or 0
local h = math.floor(elapsed / 3600)
local m = math.floor((elapsed % 3600) / 60)
local timeStr = h > 0 and string.format("%dh%dm", h, m) or string.format("%dm", m)
Chrome:SetFont(hdr.value, 9, "")
Ink(hdr.value, C_DIM)
hdr.value:SetText(timeStr)
y = y + ROW_H
-- Total earned row
local totalRow = AcquireRow(content, panW)
table.insert(activeRows, totalRow)
totalRow:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
totalRow:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
totalRow.icon:SetTexture("Interface\\MoneyFrame\\UI-GoldIcon")
totalRow.icon:SetTexCoord(0, 1, 0, 1)
Chrome:SetFont(totalRow.name, 10, "")
Ink(totalRow.name, C_TEXT)
totalRow.name:SetText("Total earned")
local hrFactor = (elapsed > 60) and (3600 / elapsed) or 0
local totalStr = P and P:FormatCopper(entry.totalCopper or 0) or "?"
if hrFactor > 0 and P then
totalStr = totalStr .. " |cff888888(" .. P:FormatGold((entry.totalCopper or 0) * hrFactor) .. "/hr)|r"
end
Chrome:SetFont(totalRow.value, 10, "")
Ink(totalRow.value, C_TEXT)
totalRow.value:SetText(totalStr)
y = y + ROW_H
-- Divider between sessions
if i < #history then
local divRow = AcquireRow(content, panW)
table.insert(activeRows, divRow)
divRow:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
divRow:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
divRow:SetHeight(6)
divRow.icon:SetTexture(nil)
divRow.name:SetText("")
divRow.value:SetText("")
y = y + 6
end
end
end
content:SetWidth(panW - 2)
content:SetHeight(math.max(y, 1))
end
PopulatePanel = function()
local content = panel.content
for _, row in ipairs(activeRows) do ReleaseRow(row) end
activeRows = {}
if panel.footer then panel.footer:Show() end
if panel.totalLabel then panel.totalLabel:SetText("Total") end
local S = WL.Session
if not S then return end
local P = WL.Prices
local elapsed = S:Elapsed()
local hrFactor = elapsed > 60 and (3600 / elapsed) or 0
local panW = panel:GetWidth()
local y = 0
local function SectionLabel(txt)
local row = AcquireRow(content, panW)
table.insert(activeRows, row)
row:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
row:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
row.icon:SetTexture(nil)
Chrome:SetFont(row.name, 9, "")
Ink(row.name, C_DIM)
row.name:SetText(txt)
row.value:SetText("")
y = y + ROW_H
end
-- ---- Gold ----
SectionLabel("Gold")
local goldRow = AcquireRow(content, panW)
table.insert(activeRows, goldRow)
goldRow:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
goldRow:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
goldRow.icon:SetTexture("Interface\\MoneyFrame\\UI-GoldIcon")
goldRow.icon:SetTexCoord(0, 1, 0, 1)
Chrome:SetFont(goldRow.name, 10, "")
Ink(goldRow.name, C_TEXT)
goldRow.name:SetText("Raw gold")
goldRow.value:SetText(P:FormatCopper(S.goldDelta))
y = y + ROW_H
-- ---- Items ----
local items = {}
for _, entry in pairs(S.loot) do
if not entry.isJunk then table.insert(items, entry) end
end
table.sort(items, function(a, b)
return (a.copper or 0) * (a.count or 1) > (b.copper or 0) * (b.count or 1)
end)
local junk = S.loot["junk"]
if #items > 0 or junk then
SectionLabel("Items")
for _, entry in ipairs(items) do
local row = AcquireRow(content, panW)
table.insert(activeRows, row)
row:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -y)
row:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -y)
Chrome:SetFont(row.name, 10, "")
Ink(row.name, C_TEXT)
if entry.icon then
row.icon:SetTexture(entry.icon)
row.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
else
row.icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
end
local nameStr = entry.link or ("item:" .. entry.itemID)
if entry.count > 1 then
nameStr = nameStr .. " |cff888888x" .. entry.count .. "|r"
end
row.name:SetText(nameStr)
local lineVal = (entry.copper or 0) * (entry.count or 1)
local valStr = P:FormatCopper(lineVal)
if entry.source == "vendor" then
valStr = valStr .. " |cff888888v|r"
elseif entry.source == "unknown" then
valStr = "|cff888888?|r"
end
row.value:SetText(valStr)