-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathUI.lua
More file actions
4772 lines (4244 loc) · 181 KB
/
UI.lua
File metadata and controls
4772 lines (4244 loc) · 181 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
local _, ns = ...
local MR = ns.MR
local L = LibStub("AceLocale-3.0"):GetLocale("MidnightRoutine")
local PANEL_MIN_WIDTH = 200
local PANEL_MAX_WIDTH = 500
local PANEL_MIN_HEIGHT = 100
local PANEL_MAX_HEIGHT = 800
local FONT_ROWS = ns.FONT_ROWS
local FONT_HEADERS = ns.FONT_HEADERS
local MakeBackdrop = ns.MakeBackdrop
local StyledFrame = ns.StyledFrame
local LeftAccent = ns.LeftAccent
local TitleBar = ns.TitleBar
local CloseButton = ns.CloseButton
local RestoreFramePos = ns.RestoreFramePos
local RestoreManagedFramePos = ns.RestoreManagedFramePos
local CaptureManagedFrameAnchor = ns.CaptureManagedFrameAnchor
local ApplyManagedFrameAnchor = ns.ApplyManagedFrameAnchor
local AnimateManagedFrameHeight = ns.AnimateManagedFrameHeight
local WrapColor = ns.WrapColor
local SetDotColor = ns.SetDotColor
local OptionsGap = ns.OptionsGap
local OptionsDivider = ns.OptionsDivider
local OptionsSectionLabel = ns.OptionsSectionLabel
local OptionsCheckbox = ns.OptionsCheckbox
local OptionsBtn = ns.OptionsBtn
local OptionsSlider = ns.OptionsSlider
local OptionsColorSwatch = ns.OptionsColorSwatch
local ApplyBackgroundTexture = ns.ApplyBackgroundTexture
local FONT_SIZE_MIN = 7
local FONT_SIZE_MAX = 20
local DAY_SECONDS = 24 * 60 * 60
local ROW_HEIGHT = 18
local HEADER_HEIGHT = 18
local PADDING = 6
local SECTION_GAP = 6
local BuildModuleStatsCache
local GetModuleStats
local IsMainTextOnlyMode
local GetWindowLayoutValue
local SetWindowLayoutValue
local countColor
local WC = WrapColor
countColor = ns.CountColor
local function GetFontSize()
if type(ns.GetFontSize) == "function" then
return ns.GetFontSize()
end
if MR and MR.db and MR.db.profile and MR.db.profile.fontSize then
return MR.db.profile.fontSize
end
return 11
end
local function GetFontFlags()
if type(ns.GetFontFlags) == "function" then
local flags = ns.GetFontFlags()
if flags ~= nil then
return flags
end
end
return "OUTLINE"
end
local function GetLocaleFont()
if type(STANDARD_TEXT_FONT) == "string" and STANDARD_TEXT_FONT ~= "" then
return STANDARD_TEXT_FONT
end
if GameFontNormal and GameFontNormal.GetFont then
local f = GameFontNormal:GetFont()
if type(f) == "string" and f ~= "" then return f end
end
if ns.GetDefaultFontTexture then
local f = ns.GetDefaultFontTexture()
if type(f) == "string" and f ~= "" then return f end
end
return "Fonts\\FRIZQT__.TTF"
end
local function RefreshFonts()
if ns.EnsureFonts then
FONT_HEADERS, FONT_ROWS = ns.EnsureFonts()
end
local loc = GetLocaleFont()
if not FONT_ROWS or FONT_ROWS == "" then FONT_ROWS = loc end
if not FONT_HEADERS or FONT_HEADERS == "" then FONT_HEADERS = loc end
end
local function SetFontForText(fontString, text, size, flags)
if not fontString then return end
local fontPath = FONT_ROWS
if ns.ResolveFontForText then
fontPath = ns.ResolveFontForText(text, FONT_ROWS)
elseif ns.ScriptFontForText then
fontPath = ns.ScriptFontForText(text) or FONT_ROWS
end
fontString:SetFont(fontPath, size, flags)
end
local function GetMainHeaderHeight()
return math.max(24, GetFontSize() + 11)
end
local function GetMainCharacterBarHeight()
if not (MR and MR.db and MR.db.profile and MR.db.profile.showMainCharacterBar ~= false) then
return 0
end
return math.max(22, GetFontSize() + 10)
end
local function GetMainHeaderMetrics()
local fontSize = GetFontSize()
local headerHeight = GetMainHeaderHeight()
return {
fontSize = fontSize,
headerHeight = headerHeight,
iconSize = math.max(14, fontSize),
buttonSize = math.max(16, fontSize + 1),
buttonPad = 3,
buttonMargin = 6,
warbandWidth = math.max(34, fontSize * 3),
}
end
local PEEK_ALPHA_IDLE = 0.0
local PEEK_ALPHA_HOVER = 1.0
local PEEK_FADE_IN = 6.0
local PEEK_FADE_OUT = 2.5
local function PeekFrameList()
local list = {}
if MR.frame then list[#list+1] = MR.frame end
if MR.raresFrame then list[#list+1] = MR.raresFrame end
if MR.renownFrame then list[#list+1] = MR.renownFrame end
if MR.gatheringLocationsFrame then list[#list+1] = MR.gatheringLocationsFrame end
if MR.detachedFrames then
for _, f in pairs(MR.detachedFrames) do
list[#list+1] = f
end
end
return list
end
local function AnyFrameHovered()
for _, f in ipairs(PeekFrameList()) do
if f:IsShown() and f:IsMouseOver() then return true end
end
return false
end
local function GetMovableHostFrame(frame)
local current = frame
while current do
if current.IsMovable and current:IsMovable() then
return current
end
current = current.GetParent and current:GetParent() or nil
end
return nil
end
local peekUpdater = CreateFrame("Frame")
peekUpdater:Hide()
function MR:ApplyPeekOnHover(enable)
self.db.profile.peekOnHover = enable
if not enable then
peekUpdater:SetScript("OnUpdate", nil)
peekUpdater:Hide()
for _, f in ipairs(PeekFrameList()) do
if f:IsShown() then f:SetAlpha(1.0) end
end
return
end
peekUpdater:Show()
peekUpdater:SetScript("OnUpdate", function(_, dt)
local target = AnyFrameHovered() and PEEK_ALPHA_HOVER or PEEK_ALPHA_IDLE
local rate = (target > PEEK_ALPHA_IDLE) and PEEK_FADE_IN or PEEK_FADE_OUT
for _, f in ipairs(PeekFrameList()) do
if f:IsShown() then
local cur = f:GetAlpha()
if math.abs(cur - target) < 0.005 then
f:SetAlpha(target)
else
local step = rate * dt
if cur < target then
f:SetAlpha(math.min(cur + step, target))
else
f:SetAlpha(math.max(cur - step, target))
end
end
end
end
end)
end
local function RecalcLayout()
local fs = GetFontSize()
ROW_HEIGHT = math.max(18, fs + 10)
HEADER_HEIGHT = math.max(18, fs + 10)
PADDING = math.max(4, math.floor(fs * 0.55))
end
local hex = ns.Hex
local COL = ns.COLORS
local function ApplyTheme()
if not MR.frame then return end
local t = IsMainTextOnlyMode()
local v = MR.db.profile.frameAlpha or 1.0
local f = MR.frame
f:SetBackdrop(MakeBackdrop())
if MR._titleBar then
MR._titleBar:SetBackdrop(MakeBackdrop())
end
if MR._characterBar then
MR._characterBar:SetBackdrop(MakeBackdrop())
end
if t then
f:SetBackdropColor(0, 0, 0, 0)
f:SetBackdropBorderColor(0, 0, 0, 0)
if MR._titleBar then MR._titleBar:SetBackdropColor(0, 0, 0, 0) end
if MR._titleBar then MR._titleBar:SetBackdropBorderColor(0, 0, 0, 0) end
if MR._characterBar then MR._characterBar:SetBackdropColor(0, 0, 0, 0) end
if MR._characterBar then MR._characterBar:SetBackdropBorderColor(0, 0, 0, 0) end
if MR._scrollBg then ApplyBackgroundTexture(MR._scrollBg, 0, 0, 0, 0) end
if MR._titleAccent then MR._titleAccent:SetAlpha(0) end
else
f:SetBackdropColor(COL.bg[1], COL.bg[2], COL.bg[3], COL.bg[4] * v)
f:SetBackdropBorderColor(0.15, 0.15, 0.2, v)
if MR._titleBar then MR._titleBar:SetBackdropColor(0.03, 0.06, 0.12, 0.98 * v) end
if MR._titleBar then MR._titleBar:SetBackdropBorderColor(0.17, 0.24, 0.32, v) end
if MR._characterBar then MR._characterBar:SetBackdropColor(0.020, 0.040, 0.060, 0.96 * v) end
if MR._characterBar then MR._characterBar:SetBackdropBorderColor(0.08, 0.16, 0.22, 0.45 * v) end
if MR._scrollBg then ApplyBackgroundTexture(MR._scrollBg, COL.bg[1], COL.bg[2], COL.bg[3], 0.96 * v) end
if MR._titleAccent then MR._titleAccent:SetAlpha(0) end
end
end
MR.ApplyTheme = ApplyTheme
local function CleanLabelText(text)
if type(text) ~= "string" then
return tostring(text or "")
end
return text:gsub("|c%x%x%x%x%x%x%x%x(.-)%|r", "%1"):gsub("|[cCrR]%x*", "")
end
local function ExtractInlineLabelColor(text)
if type(text) ~= "string" then
return nil
end
local hexColor = text:match("|cff(%x%x%x%x%x%x)")
if not hexColor then
return nil
end
return "#" .. hexColor
end
local function HideTooltipIfOwned(frame)
if GameTooltip and GameTooltip:IsOwned(frame) then
GameTooltip:Hide()
end
end
local function MainSectionHeaderOnMouseDown(selfFrame, button)
if selfFrame._mrDetachedHost and button == "LeftButton" then
selfFrame._pressed = true
selfFrame._dragged = false
return
end
if button == "LeftButton" then
selfFrame._pressed = true
end
end
local function MainSectionHeaderOnDragStart(selfFrame)
local host = selfFrame._mrDetachedHost
if not host or MR.db.profile.locked then
return
end
selfFrame._dragged = true
host:StartMoving()
end
local function MainSectionHeaderOnDragStop(selfFrame)
local host = selfFrame._mrDetachedHost
local mod = selfFrame._mrMod
if not host or not mod then
return
end
host:StopMovingOrSizing()
local pt, _, rp, x, y = host:GetPoint()
MR:SetDetachedModulePosition(mod.key, pt, rp, x, y)
end
local function MainSectionHeaderOnMouseUp(selfFrame, button)
local mod = selfFrame._mrMod
if not mod then
selfFrame._pressed = false
return
end
if selfFrame._mrDetachedHost and button == "LeftButton" and selfFrame._dragged then
selfFrame._pressed = false
selfFrame._dragged = false
return
end
if mod.key == "custom_tasks" and button == "RightButton" and IsShiftKeyDown() then
if MR.ShowCustomTasksTitleDialog then
MR:ShowCustomTasksTitleDialog()
end
selfFrame._pressed = false
return
end
if button == "LeftButton" then
if not selfFrame._mrDetachedHost and MR.FastToggleMainSection and MR:FastToggleMainSection(mod.key) then
elseif not selfFrame._mrDetachedHost and MR.RefreshMainPanelSectionsOnly then
MR:SetModuleOpen(mod.key, not MR:IsModuleOpen(mod.key))
MR:RefreshMainPanelSectionsOnly()
elseif MR.RequestUIRefresh then
MR:SetModuleOpen(mod.key, not MR:IsModuleOpen(mod.key))
MR:RequestUIRefresh(0.04)
else
MR:SetModuleOpen(mod.key, not MR:IsModuleOpen(mod.key))
MR:RefreshUI()
end
elseif button == "RightButton" then
MR:SetModuleDetached(mod.key, not selfFrame._mrDetachedHost)
if MR.RequestUIRefresh then
MR:RequestUIRefresh(0.04)
else
MR:RefreshUI()
end
end
selfFrame._pressed = false
end
local function MainSectionHeaderOnEnter(selfFrame)
local mod = selfFrame._mrMod
if not mod then
return
end
local alpha = selfFrame._mrHoverAlpha or 0
if selfFrame._hdrHover then
selfFrame._hdrHover:SetColorTexture(1, 1, 1, alpha)
end
GameTooltip:SetOwner(selfFrame, "ANCHOR_RIGHT")
GameTooltip:SetText(mod.label, 1, 1, 1)
GameTooltip:AddLine(L["Tooltip_ExpandCollapse"], 0.5, 0.5, 0.5)
GameTooltip:AddLine(selfFrame._mrDetachedHost and "Right-click to dock back" or "Right-click to detach", 0.5, 0.8, 1)
if mod.key == "custom_tasks" then
GameTooltip:AddLine("Shift-right-click to rename this header.", 0.85, 0.82, 0.45, true)
end
GameTooltip:Show()
end
local function MainSectionHeaderOnLeave(selfFrame)
if selfFrame._hdrHover then
selfFrame._hdrHover:SetColorTexture(1, 1, 1, 0)
end
HideTooltipIfOwned(selfFrame)
end
local function CurrencyBrowserButtonOnClick()
if MR.ToggleCurrencyBrowserFrame then
MR:ToggleCurrencyBrowserFrame()
end
end
local function CurrencyBrowserButtonOnEnter(selfBtn)
selfBtn:SetBackdropColor(0.07, 0.18, 0.24, 1)
selfBtn:SetBackdropBorderColor(0.30, 0.80, 0.78, 1)
if selfBtn._label then
selfBtn._label:SetTextColor(0.65, 1.00, 0.92, 1)
end
GameTooltip:SetOwner(selfBtn, "ANCHOR_RIGHT")
GameTooltip:SetText("Show all Blizzard currencies", 1, 1, 1)
GameTooltip:AddLine("Opens a side window populated from the currency API.", 0.55, 0.82, 1, true)
GameTooltip:Show()
end
local function CurrencyBrowserButtonOnLeave(selfBtn)
local alpha = selfBtn._mrTransparent and 0 or (0.90 * (selfBtn._mrFrameAlpha or 1))
local borderAlpha = selfBtn._mrTransparent and 0 or (0.70 * (selfBtn._mrFrameAlpha or 1))
selfBtn:SetBackdropColor(0.04, 0.09, 0.14, alpha)
selfBtn:SetBackdropBorderColor(0.14, 0.34, 0.42, borderAlpha)
if selfBtn._label then
selfBtn._label:SetTextColor(0.42, 0.82, 0.82, selfBtn._mrTransparent and 0.75 or 1)
end
HideTooltipIfOwned(selfBtn)
end
local function StyleSectionCollapseIndicator(indicator, isOpen)
if not indicator then return end
indicator:ClearAllPoints()
indicator:SetSize(12, HEADER_HEIGHT)
indicator:SetPoint("RIGHT", indicator:GetParent(), "RIGHT", -5, 0)
indicator:SetFont(FONT_ROWS, math.max(9, GetFontSize() - 1), GetFontFlags())
indicator:SetJustifyH("CENTER")
indicator:SetText(isOpen and "-" or "+")
indicator:SetTextColor(0.50, 0.95, 0.80)
end
local function StyleCurrencyBrowserButton(button, transparent, frameAlpha)
if not button then return end
button._mrTransparent = transparent
button._mrFrameAlpha = frameAlpha
button:SetSize(24, 14)
button:SetBackdropColor(0.04, 0.09, 0.14, transparent and 0 or (0.90 * frameAlpha))
button:SetBackdropBorderColor(0.14, 0.34, 0.42, transparent and 0 or (0.70 * frameAlpha))
if button._label then
button._label:SetFont(FONT_ROWS, math.max(7, GetFontSize() - 3), GetFontFlags())
button._label:SetText(L["CurrencyBrowser_All"] or "ALL")
button._label:SetTextColor(0.42, 0.82, 0.82, transparent and 0.75 or 1)
end
end
local function MainHeaderActionOnClick(selfBtn)
if MR.IsMainAltViewActive and MR:IsMainAltViewActive() then
return
end
local owner = selfBtn._mrOwner
local data = owner and owner._mrData
if data and data.row and data.row.onHeaderActionClick then
data.row.onHeaderActionClick(data.row, data.mod, owner)
end
end
local function MainHeaderActionOnEnter(selfBtn)
local owner = selfBtn._mrOwner
local data = owner and owner._mrData
if data and data.row and data.row.headerActionTooltip and data.row.headerActionTooltip ~= "" then
GameTooltip:SetOwner(selfBtn, "ANCHOR_RIGHT")
GameTooltip:SetText(data.row.headerActionTooltip, 1, 1, 1, 1, true)
GameTooltip:Show()
end
end
local function MainHeaderActionOnLeave(selfBtn)
HideTooltipIfOwned(selfBtn)
end
local function MainRowOnEnter(selfRow)
local data = selfRow._mrData
if not data then
return
end
if data.mode == "sectionHeader" then
if data.row.note then
GameTooltip:SetOwner(selfRow, "ANCHOR_RIGHT")
GameTooltip:SetText(data.row.label, 1, 1, 1)
GameTooltip:AddLine(data.row.note, 0.70, 0.70, 0.76, true)
GameTooltip:Show()
end
return
end
if data.mode == "collapsed" then
GameTooltip:SetOwner(selfRow, "ANCHOR_RIGHT")
GameTooltip:SetText(L["Tooltip_DonePrefix"] .. data.row.label, 0.4, 0.85, 0.4, 1, true)
GameTooltip:AddLine(L["Tooltip_CompletedWeek"], 0.3, 0.6, 0.3)
GameTooltip:Show()
return
end
if selfRow._hover then
selfRow._hover:SetColorTexture(1, 1, 1, data.transparent and 0 or (0.04 * data.frameAlpha))
end
local row = data.row
GameTooltip:SetOwner(selfRow, "ANCHOR_RIGHT")
if row.currencyId and not row.noBlizzardTooltip then
GameTooltip:SetCurrencyByID(row.currencyId)
GameTooltip:AddLine(L["Tooltip_AutoBlizzard"], 0.4, 0.8, 1)
if row.tooltipFunc then
row.tooltipFunc(GameTooltip)
end
elseif row.itemId and not row.noBlizzardTooltip then
if GameTooltip.SetItemByID then
GameTooltip:SetItemByID(row.itemId)
else
GameTooltip:SetHyperlink("item:" .. row.itemId)
end
GameTooltip:AddLine(L["Tooltip_AutoItem"], 0.9, 0.6, 1)
else
GameTooltip:SetText(row.label, 1, 1, 1, 1, true)
if row.note then
GameTooltip:AddLine(row.note, 0.7, 0.7, 0.7, true)
end
if data.hasWaypoint then
GameTooltip:AddLine(" ")
GameTooltip:AddLine(string.format(L["Gathering_Coords"], row.x, row.y), 0.7, 1, 0.9)
GameTooltip:AddLine(L["Gathering_ClickWaypoint"], 0.45, 0.85, 1)
end
if row.tooltipFunc then
row.tooltipFunc(GameTooltip)
end
if row.noDefaultTooltipHint then
elseif row.liveKey or row.autoTracked or (row.currencyId and row.noBlizzardTooltip) then
GameTooltip:AddLine(L["Tooltip_AutoBlizzard"], 0.4, 0.8, 1)
elseif row.questIds then
GameTooltip:AddLine(L["Tooltip_AutoQuest"], 0.4, 1, 0.6)
elseif row.spellId or row.itemId then
GameTooltip:AddLine(L["Tooltip_AutoItem"], 0.9, 0.6, 1)
elseif not data.hasWaypoint then
GameTooltip:AddLine(L["Tooltip_ManualClick"], 0.5, 0.5, 0.5)
end
end
GameTooltip:Show()
end
local function MainRowOnLeave(selfRow)
if selfRow._hover then
selfRow._hover:SetColorTexture(1, 1, 1, 0)
end
HideTooltipIfOwned(selfRow)
end
local function MainRowOnMouseDown(selfRow, button)
local data = selfRow._mrData
if not data or data.mode ~= "normal" then
return
end
if MR.IsMainAltViewActive and MR:IsMainAltViewActive() then
return
end
local row = data.row
local mod = data.mod
local done = data.done
if button == "LeftButton" and row.onLeftClick then
local handled = row.onLeftClick(row, mod, done, selfRow)
if handled ~= false then
return
end
elseif button == "RightButton" and row.onRightClick then
local handled = row.onRightClick(row, mod, done, selfRow)
if handled ~= false then
return
end
end
if button == "LeftButton" and data.hasWaypoint then
local ok, source = MR:SetWaypoint(row)
if ok then
print(string.format(L["Waypoint_Set"], source, row.waypointTitle or row.label, row.x, row.y))
else
print(L["Waypoint_Unavailable"])
end
elseif not data.isAutoTracked and not row.encounterIds and button == "LeftButton" then
MR:BumpProgress(mod.key, row.key, 1, row.max)
elseif not data.isAutoTracked and not row.encounterIds and button == "RightButton" then
MR:BumpProgress(mod.key, row.key, -1, row.max)
end
end
local function MainStatusButtonOnClick(selfBtn)
local owner = selfBtn._mrOwner
local data = owner and owner._mrData
if not data or data.mode ~= "normal" then
return
end
if MR.IsMainAltViewActive and MR:IsMainAltViewActive() then
return
end
local row = data.row
local mod = data.mod
if row.toggleStatus and MR.ToggleCustomTask and mod.key == "custom_tasks" then
local rowKey = row.key or ""
local scope = row.taskScope or (rowKey:match("^shared_task_") and "shared" or "character")
local taskId = tonumber(rowKey:match("^shared_task_(%d+)") or rowKey:match("^task_(%d+)"))
MR:ToggleCustomTask(taskId, scope)
return
end
if row.encounterIds then return end
local cur = MR:GetManualOverride(mod.key, row.key)
MR:SetManualOverride(mod.key, row.key, cur >= row.max and 0 or row.max, row.max)
end
local function MainStatusButtonOnEnter(selfBtn)
local owner = selfBtn._mrOwner
local data = owner and owner._mrData
if not data or data.mode ~= "normal" then
return
end
if owner._hover then
owner._hover:SetColorTexture(1, 1, 1, data.transparent and 0 or (0.04 * data.frameAlpha))
end
local row = data.row
local mo = row.toggleStatus and MR:GetProgress(data.mod.key, row.key) or MR:GetManualOverride(data.mod.key, row.key)
GameTooltip:SetOwner(selfBtn, "ANCHOR_RIGHT")
GameTooltip:SetText(row.label, 1, 1, 1, 1, true)
if row.note then
GameTooltip:AddLine(row.note, 0.7, 0.7, 0.7, true)
end
GameTooltip:AddLine(" ")
if mo >= row.max then
GameTooltip:AddLine(L["Tooltip_ManualDot_Active"], 1, 0.85, 0.1, true)
else
GameTooltip:AddLine(L["Tooltip_ManualDot_Hint"], 0.7, 0.7, 0.7, true)
end
GameTooltip:Show()
end
local function MainStatusButtonOnLeave(selfBtn)
local owner = selfBtn._mrOwner
if owner and owner._hover then
owner._hover:SetColorTexture(1, 1, 1, 0)
end
HideTooltipIfOwned(selfBtn)
end
local function HideMainRowWidget(rowFrame)
if not rowFrame then
return
end
HideTooltipIfOwned(rowFrame)
if rowFrame._headerActionButton then
HideTooltipIfOwned(rowFrame._headerActionButton)
end
if rowFrame._statusBtn then
HideTooltipIfOwned(rowFrame._statusBtn)
end
rowFrame._mrData = nil
rowFrame._timerUpdate = nil
rowFrame:Hide()
end
local function HideMainSectionWidget(section)
if not section then
return
end
if section._hdrFrame then
HideTooltipIfOwned(section._hdrFrame)
end
if section._rows then
for _, rowFrame in pairs(section._rows) do
HideMainRowWidget(rowFrame)
end
end
section:Hide()
end
local GetTextOnlyHeaderAlpha
local ShouldShowIcons
local ShouldShowSectionHeaders
local NormalizeIconInfo
local GetRowIconInfo
local GetModuleIconInfo
local ShouldShowModuleHeaderIcon
local GetModuleFallbackIconInfo
local ApplyIconToTexture
local EnsureMainRowWidget
local UpdateMainRowWidget
local function EnsureMainSeparator(self, index)
self._mainColumnSeparators = self._mainColumnSeparators or {}
local sep = self._mainColumnSeparators[index]
if sep then
sep:SetParent(self.content)
sep:Show()
return sep
end
sep = CreateFrame("Frame", nil, self.content)
sep._tex = sep:CreateTexture(nil, "ARTWORK")
sep._tex:SetAllPoints()
sep._tex:SetColorTexture(1, 1, 1, 0.08)
self._mainColumnSeparators[index] = sep
return sep
end
local function EnsureMainSectionWidget(self, modKey)
self._mainSectionFrames = self._mainSectionFrames or {}
local card = self._mainSectionFrames[modKey]
if card then
card:SetParent(self.content)
card:Show()
return card
end
card = CreateFrame("Frame", nil, self.content, "BackdropTemplate")
card._glow = card:CreateTexture(nil, "BACKGROUND")
card._glow:SetPoint("TOPLEFT", card, "TOPLEFT", 1, -1)
card._glow:SetPoint("BOTTOMRIGHT", card, "BOTTOMRIGHT", -1, 1)
card._glow:SetTexture("Interface\\Buttons\\WHITE8X8")
card._hdrFrame = CreateFrame("Frame", nil, card)
card._hdrFrame:SetPoint("TOPLEFT", card, "TOPLEFT", 0, 0)
card._hdrFrame:SetPoint("TOPRIGHT", card, "TOPRIGHT", 0, 0)
card._hdrFrame:EnableMouse(true)
card._hdrFrame._hdrHover = card._hdrFrame:CreateTexture(nil, "BORDER")
card._hdrFrame._hdrHover:SetAllPoints()
card._hdrFrame._hdrBg = card._hdrFrame:CreateTexture(nil, "BACKGROUND")
card._hdrFrame._hdrBg:SetAllPoints()
card._hdrFrame._iconPlate = CreateFrame("Frame", nil, card._hdrFrame, "BackdropTemplate")
card._hdrFrame._icon = card._hdrFrame:CreateTexture(nil, "ARTWORK")
card._hdrFrame._label = card._hdrFrame:CreateFontString(nil, "OVERLAY")
card._hdrFrame._count = card._hdrFrame:CreateFontString(nil, "OVERLAY")
card._hdrFrame._currencyBrowserButton = CreateFrame("Button", nil, card._hdrFrame, "BackdropTemplate")
card._hdrFrame._currencyBrowserButton:SetSize(18, 18)
card._hdrFrame._currencyBrowserButton:SetBackdrop(MakeBackdrop())
card._hdrFrame._currencyBrowserButton:SetScript("OnClick", CurrencyBrowserButtonOnClick)
card._hdrFrame._currencyBrowserButton:SetScript("OnEnter", CurrencyBrowserButtonOnEnter)
card._hdrFrame._currencyBrowserButton:SetScript("OnLeave", CurrencyBrowserButtonOnLeave)
card._hdrFrame._currencyBrowserText = card._hdrFrame._currencyBrowserButton:CreateFontString(nil, "OVERLAY")
card._hdrFrame._currencyBrowserButton._label = card._hdrFrame._currencyBrowserText
card._hdrFrame._currencyBrowserText:SetFont(FONT_ROWS, 12, GetFontFlags())
card._hdrFrame._currencyBrowserText:SetPoint("CENTER", card._hdrFrame._currencyBrowserButton, "CENTER", 0, 0)
card._hdrFrame._currencyBrowserText:SetText(L["CurrencyBrowser_All"] or "ALL")
card._hdrFrame._arrow = card._hdrFrame:CreateFontString(nil, "OVERLAY")
card._hdrFrame:SetScript("OnMouseDown", MainSectionHeaderOnMouseDown)
card._hdrFrame:SetScript("OnMouseUp", MainSectionHeaderOnMouseUp)
card._hdrFrame:SetScript("OnDragStart", MainSectionHeaderOnDragStart)
card._hdrFrame:SetScript("OnDragStop", MainSectionHeaderOnDragStop)
card._hdrFrame:SetScript("OnEnter", MainSectionHeaderOnEnter)
card._hdrFrame:SetScript("OnLeave", MainSectionHeaderOnLeave)
card._divider = CreateFrame("Frame", nil, card, "BackdropTemplate")
card._divider:SetBackdrop(MakeBackdrop(false))
card._rows = {}
self._mainSectionFrames[modKey] = card
return card
end
local function EnsureDetachedSectionWidget(frame, modKey)
frame._sectionFrames = frame._sectionFrames or {}
local card = frame._sectionFrames[modKey]
if card then
card:SetParent(frame.content)
card:Show()
return card
end
card = CreateFrame("Frame", nil, frame.content, "BackdropTemplate")
card._glow = card:CreateTexture(nil, "BACKGROUND")
card._glow:SetPoint("TOPLEFT", card, "TOPLEFT", 1, -1)
card._glow:SetPoint("BOTTOMRIGHT", card, "BOTTOMRIGHT", -1, 1)
card._glow:SetTexture("Interface\\Buttons\\WHITE8X8")
card._hdrFrame = CreateFrame("Frame", nil, card)
card._hdrFrame:SetPoint("TOPLEFT", card, "TOPLEFT", 0, 0)
card._hdrFrame:SetPoint("TOPRIGHT", card, "TOPRIGHT", 0, 0)
card._hdrFrame:EnableMouse(true)
card._hdrFrame:RegisterForDrag("LeftButton")
card._hdrFrame._hdrHover = card._hdrFrame:CreateTexture(nil, "BORDER")
card._hdrFrame._hdrHover:SetAllPoints()
card._hdrFrame._hdrBg = card._hdrFrame:CreateTexture(nil, "BACKGROUND")
card._hdrFrame._hdrBg:SetAllPoints()
card._hdrFrame._iconPlate = CreateFrame("Frame", nil, card._hdrFrame, "BackdropTemplate")
card._hdrFrame._icon = card._hdrFrame:CreateTexture(nil, "ARTWORK")
card._hdrFrame._label = card._hdrFrame:CreateFontString(nil, "OVERLAY")
card._hdrFrame._count = card._hdrFrame:CreateFontString(nil, "OVERLAY")
card._hdrFrame._currencyBrowserButton = CreateFrame("Button", nil, card._hdrFrame, "BackdropTemplate")
card._hdrFrame._currencyBrowserButton:SetSize(18, 18)
card._hdrFrame._currencyBrowserButton:SetBackdrop(MakeBackdrop())
card._hdrFrame._currencyBrowserButton:SetScript("OnClick", CurrencyBrowserButtonOnClick)
card._hdrFrame._currencyBrowserButton:SetScript("OnEnter", CurrencyBrowserButtonOnEnter)
card._hdrFrame._currencyBrowserButton:SetScript("OnLeave", CurrencyBrowserButtonOnLeave)
card._hdrFrame._currencyBrowserText = card._hdrFrame._currencyBrowserButton:CreateFontString(nil, "OVERLAY")
card._hdrFrame._currencyBrowserButton._label = card._hdrFrame._currencyBrowserText
card._hdrFrame._currencyBrowserText:SetFont(FONT_ROWS, 12, GetFontFlags())
card._hdrFrame._currencyBrowserText:SetPoint("CENTER", card._hdrFrame._currencyBrowserButton, "CENTER", 0, 0)
card._hdrFrame._currencyBrowserText:SetText(L["CurrencyBrowser_All"] or "ALL")
card._hdrFrame._arrow = card._hdrFrame:CreateFontString(nil, "OVERLAY")
card._hdrFrame:SetScript("OnMouseDown", MainSectionHeaderOnMouseDown)
card._hdrFrame:SetScript("OnMouseUp", MainSectionHeaderOnMouseUp)
card._hdrFrame:SetScript("OnDragStart", MainSectionHeaderOnDragStart)
card._hdrFrame:SetScript("OnDragStop", MainSectionHeaderOnDragStop)
card._hdrFrame:SetScript("OnEnter", MainSectionHeaderOnEnter)
card._hdrFrame:SetScript("OnLeave", MainSectionHeaderOnLeave)
card._divider = CreateFrame("Frame", nil, card, "BackdropTemplate")
card._divider:SetBackdrop(MakeBackdrop(false))
card._rows = {}
frame._sectionFrames[modKey] = card
return card
end
local function UpdateDetachedSectionWidget(self, hostFrame, mod, contentWidth)
local transparent = IsMainTextOnlyMode()
local frameAlpha = MR.db.profile.frameAlpha or 1.0
local showSectionHeaders = ShouldShowSectionHeaders()
local textOnlyHeaderAlpha = showSectionHeaders and GetTextOnlyHeaderAlpha() or 0
local headerAlpha = transparent and textOnlyHeaderAlpha or ((showSectionHeaders and 0.90 or 0) * frameAlpha)
local dividerAlpha = transparent and (0.50 * textOnlyHeaderAlpha) or ((showSectionHeaders and 0.09 or 0) * frameAlpha)
local showSoftHeaders = transparent and textOnlyHeaderAlpha > 0
local showIcons = ShouldShowIcons()
local stats = GetModuleStats(self, mod)
local isOpen = stats and stats.isOpen
local secTotal = stats and stats.totalRows or 0
local secDone = stats and stats.doneRows or 0
local shownRows = stats and stats.shownRows or 0
if shownRows == 0 then
return nil
end
local allDone = (secTotal > 0) and (secDone == secTotal)
local card = EnsureDetachedSectionWidget(hostFrame, mod.key)
local sectionHeight = math.max((stats and stats.height or 0) - SECTION_GAP, HEADER_HEIGHT + 1)
card:ClearAllPoints()
card:SetPoint("TOPLEFT", hostFrame.content, "TOPLEFT", 0, 0)
card:SetSize(math.max(contentWidth, 1), sectionHeight)
card:SetBackdrop(MakeBackdrop())
if ns.HookBackdropFrame then ns.HookBackdropFrame(card) end
card._hdrFrame._mrDetachedHost = nil
if transparent then
card:SetBackdropColor(0, 0, 0, 0)
card:SetBackdropBorderColor(0, 0, 0, 0)
else
card:SetBackdropColor(0.02, 0.03, 0.05, 0.94 * frameAlpha)
card:SetBackdropBorderColor(0.18, 0.22, 0.28, 0.95 * frameAlpha)
end
card._glow:SetColorTexture(0.12, 0.14, 0.18, transparent and 0 or (0.10 * frameAlpha))
card._hdrFrame:SetHeight(HEADER_HEIGHT)
card._hdrFrame._mrMod = mod
card._hdrFrame._mrDetachedHost = hostFrame
card._hdrFrame._mrHoverAlpha = transparent and (0.10 * textOnlyHeaderAlpha) or ((showSectionHeaders and 0.05 or 0) * frameAlpha)
local customHeaderBg = MR.GetHeaderBackgroundColor and MR:GetHeaderBackgroundColor(mod.key) or nil
local hdrR, hdrG, hdrB = 0.08, 0.09, 0.12
if customHeaderBg then
hdrR, hdrG, hdrB = hex(customHeaderBg)
end
card._hdrFrame._hdrBg:SetColorTexture(hdrR, hdrG, hdrB, headerAlpha)
local explicitColor = MR.db.profile.headerColors and MR.db.profile.headerColors[mod.key]
local customColor = MR:GetHeaderColor(mod.key)
local headerColor = customColor or mod.labelColor or "#ffffff"
local lr, lg, lb = hex(headerColor)
local accentA = transparent and textOnlyHeaderAlpha or ((showSectionHeaders and 1 or 0) * frameAlpha)
local accentR, accentG, accentB = lr, lg, lb
if allDone then
accentR, accentG, accentB = COL.complete[1], COL.complete[2], COL.complete[3]
end
card._hdrFrame._iconPlate:ClearAllPoints()
card._hdrFrame._iconPlate:SetSize(math.max(HEADER_HEIGHT - 6, 12), math.max(HEADER_HEIGHT - 6, 12))
card._hdrFrame._iconPlate:SetPoint("LEFT", card._hdrFrame, "LEFT", 4, 0)
card._hdrFrame._iconPlate:SetBackdrop(MakeBackdrop())
local iconPlateBgAlpha = transparent and (showSoftHeaders and (0.16 * accentA) or 0) or ((showSectionHeaders and 0.16 or 0) * frameAlpha)
local iconPlateBorderAlpha = transparent and (showSoftHeaders and (0.50 * accentA) or 0) or ((showSectionHeaders and 0.50 or 0) * frameAlpha)
card._hdrFrame._iconPlate:SetBackdropColor(accentR, accentG, accentB, iconPlateBgAlpha)
card._hdrFrame._iconPlate:SetBackdropBorderColor(accentR, accentG, accentB, iconPlateBorderAlpha)
local iconInfo = showIcons and ShouldShowModuleHeaderIcon(mod.key) and GetModuleIconInfo(mod) or nil
card._hdrFrame._icon:ClearAllPoints()
card._hdrFrame._icon:SetSize(math.max(HEADER_HEIGHT - 12, 9), math.max(HEADER_HEIGHT - 12, 9))
card._hdrFrame._icon:SetPoint("CENTER", card._hdrFrame._iconPlate, "CENTER", 0, 0)
local hasHeaderIcon = ApplyIconToTexture(card._hdrFrame._icon, iconInfo, { 0.14, 0.86, 0.14, 0.86 })
card._hdrFrame._iconPlate:SetShown(hasHeaderIcon and (showIcons or showSectionHeaders))
card._hdrFrame._label:SetFont(FONT_HEADERS, math.max(9, GetFontSize()), GetFontFlags())
card._hdrFrame._label:ClearAllPoints()
if hasHeaderIcon then
card._hdrFrame._label:SetPoint("LEFT", card._hdrFrame._iconPlate, "RIGHT", 6, 0)
else
card._hdrFrame._label:SetPoint("LEFT", card._hdrFrame, "LEFT", 9, 0)
end
card._hdrFrame._label:SetJustifyH("LEFT")
if card._hdrFrame._label.SetWordWrap then
card._hdrFrame._label:SetWordWrap(false)
end
card._hdrFrame._label:SetText((allDone and not explicitColor) and WC("00ff96", mod.label) or WC(headerColor:gsub("#", ""), mod.label))
card._hdrFrame._count:SetFont(FONT_ROWS, math.max(7, GetFontSize() - 2), GetFontFlags())
card._hdrFrame._count:ClearAllPoints()
local currencyBrowserButton = card._hdrFrame._currencyBrowserButton
local showCurrencyBrowserButton = mod.key == "currencies" and MR.ToggleCurrencyBrowserFrame
if showCurrencyBrowserButton then
currencyBrowserButton:ClearAllPoints()
currencyBrowserButton:SetPoint("RIGHT", card._hdrFrame, "RIGHT", -23, 0)
StyleCurrencyBrowserButton(currencyBrowserButton, transparent, frameAlpha)
currencyBrowserButton:Show()
card._hdrFrame._count:SetPoint("RIGHT", currencyBrowserButton, "LEFT", -8, 0)
else
currencyBrowserButton:Hide()
card._hdrFrame._count:SetPoint("RIGHT", card._hdrFrame, "RIGHT", -18, 0)
end
card._hdrFrame._count:SetText(showCurrencyBrowserButton
and string.format("%d / %d", secDone, secTotal)
or string.format(L["%d / %d complete"], secDone, secTotal))
card._hdrFrame._count:SetTextColor(countColor(secDone, secTotal))
card._hdrFrame._count:SetJustifyH("RIGHT")
card._hdrFrame._label:SetPoint("RIGHT", card._hdrFrame._count, "LEFT", -8, 0)
StyleSectionCollapseIndicator(card._hdrFrame._arrow, isOpen)
local localY = HEADER_HEIGHT
card._divider:ClearAllPoints()
card._divider:SetPoint("TOPLEFT", card, "TOPLEFT", 0, -localY)
card._divider:SetPoint("TOPRIGHT", card, "TOPRIGHT", 0, -localY)
card._divider:SetHeight(1)
card._divider:SetBackdropColor(1, 1, 1, dividerAlpha)
local usedRows = {}
if isOpen then
localY = localY + 1
local hideComplete = stats and stats.hideComplete
for _, row in ipairs(mod.rows) do
local rowVisible = not row.isVisible or row.isVisible()
if rowVisible and MR:IsRowEnabled(mod.key, row.key) then
local done = MR:GetProgress(mod.key, row.key)
local rowComplete = self:IsRowComplete(mod, row, done)
if row.control or not (hideComplete and rowComplete) then
local _, nextY, rowId = UpdateMainRowWidget(self, card, mod, row, done, localY, card:GetWidth())
localY = nextY
usedRows[rowId] = true
end
end
end
end
for key, rowFrame in pairs(card._rows or {}) do
if not usedRows[key] then
HideMainRowWidget(rowFrame)
end
end
return card
end
EnsureMainRowWidget = function(section, rowKey)
section._rows = section._rows or {}
local rowFrame = section._rows[rowKey]
if rowFrame then
rowFrame:SetParent(section)
rowFrame:Show()
return rowFrame
end
rowFrame = CreateFrame("Frame", nil, section)
rowFrame:EnableMouse(true)
rowFrame:SetScript("OnEnter", MainRowOnEnter)
rowFrame:SetScript("OnLeave", MainRowOnLeave)
rowFrame:SetScript("OnMouseDown", MainRowOnMouseDown)
rowFrame._headerBg = rowFrame:CreateTexture(nil, "BACKGROUND")
rowFrame._headerBg:SetAllPoints()
rowFrame._headerText = rowFrame:CreateFontString(nil, "OVERLAY")
rowFrame._headerActionButton = CreateFrame("Button", nil, rowFrame, "BackdropTemplate")
rowFrame._headerActionButton._mrOwner = rowFrame
rowFrame._headerActionButton:SetScript("OnClick", MainHeaderActionOnClick)
rowFrame._headerActionButton:SetScript("OnEnter", MainHeaderActionOnEnter)
rowFrame._headerActionButton:SetScript("OnLeave", MainHeaderActionOnLeave)
rowFrame._headerActionText = rowFrame._headerActionButton:CreateFontString(nil, "OVERLAY")
rowFrame._headerActionText:SetFont(FONT_ROWS, 9, GetFontFlags())
rowFrame._headerCount = rowFrame:CreateFontString(nil, "OVERLAY")
rowFrame._headerCount:SetFont(FONT_ROWS, math.max(8, GetFontSize() - 2), GetFontFlags())
rowFrame._collapsedLine = rowFrame:CreateTexture(nil, "ARTWORK")
rowFrame._collapsedDot = rowFrame:CreateTexture(nil, "ARTWORK")
rowFrame._hover = rowFrame:CreateTexture(nil, "BACKGROUND")
rowFrame._hover:SetAllPoints()
rowFrame._rowShade = rowFrame:CreateTexture(nil, "BORDER")
rowFrame._separator = rowFrame:CreateTexture(nil, "ARTWORK")
rowFrame._statusBtn = CreateFrame("Button", nil, rowFrame, "BackdropTemplate")
rowFrame._statusBtn._mrOwner = rowFrame
rowFrame._statusBtn:SetScript("OnClick", MainStatusButtonOnClick)