-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcore.lua
More file actions
executable file
·15978 lines (14643 loc) · 669 KB
/
core.lua
File metadata and controls
executable file
·15978 lines (14643 loc) · 669 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 IS_RETAIL = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
local IS_CLASSIC_ERA = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
local IS_CLASSIC = not IS_RETAIL and not IS_CLASSIC_ERA
local addonName = ... ---@type string @The name of the addon.
local ns = select(2, ...) ---@class ns @The addon namespace.
local L = ns.L
local arshift = bit.arshift
local band = bit.band
local bnot = bit.bnot
local bor = bit.bor
local bxor = bit.bxor
local lshift = bit.lshift
local mod = bit.mod
local rshift = bit.rshift
local ScrollBoxUtil do
ScrollBoxUtil = {}
---@class CallbackRegistryMixin
---@field public RegisterCallback fun(event: string|any, callback: fun())
---@class ScrollBoxBaseMixin : CallbackRegistryMixin, Frame
---@field public GetFrames fun(): Frame[]
---@field public Update fun()
---@field public buttons? Button[]
---@field public update? fun()
---@param scrollBox ScrollBoxBaseMixin
---@param callback fun(frames: Button[], scrollBox: ScrollBoxBaseMixin)
function ScrollBoxUtil:OnViewFramesChanged(scrollBox, callback)
if not scrollBox then
return
end
if scrollBox.buttons then -- TODO: legacy 9.X support
callback(scrollBox.buttons, scrollBox)
return 1
end
if scrollBox.RegisterCallback then
local frames = scrollBox:GetFrames()
if frames and frames[1] then
callback(frames, scrollBox)
end
scrollBox:RegisterCallback(ScrollBoxListMixin.Event.OnUpdate, function()
frames = scrollBox:GetFrames()
callback(frames, scrollBox)
end)
return true
end
return false
end
---@param scrollBox ScrollBoxBaseMixin
---@param callback fun(self: ScrollBoxBaseMixin)
function ScrollBoxUtil:OnViewScrollChanged(scrollBox, callback)
if not scrollBox then
return
end
local function wrappedCallback()
callback(scrollBox)
end
if scrollBox.update then -- TODO: legacy 9.X support
hooksecurefunc(scrollBox, "update", wrappedCallback)
return 1
end
if scrollBox.RegisterCallback then
scrollBox:RegisterCallback(ScrollBoxListMixin.Event.OnScroll, wrappedCallback)
return true
end
return false
end
end
local HookUtil do
---@alias ScriptAnyWidgetHandler
---|ScriptAnimation
---|ScriptAnimationGroup
---|ScriptBrowser
---|ScriptButton
---|ScriptCheckout
---|ScriptCinematicModel
---|ScriptColorSelect
---|ScriptCooldown
---|ScriptDressUpModel
---|ScriptEditBox
---|ScriptFogOfWarFrame
---|ScriptFrame
---|ScriptGameTooltip
---|ScriptModel
---|ScriptModelSceneActor
---|ScriptMovieFrame
---|ScriptScrollFrame
---|ScriptSlider
---|ScriptStatusBar
HookUtil = {}
local hooked = {}
---@param frame Frame
---@param callback fun(self: Frame, ...)
---@param ... ScriptAnyWidgetHandler
function HookUtil:On(frame, callback, ...)
local hook = hooked[frame]
if not hook then
hook = {}
hooked[frame] = hook
end
for _, key in ipairs({...}) do
local keyHook = hook[key]
if not keyHook then
keyHook = {}
hook[key] = keyHook
end
if not keyHook[callback] then
keyHook[callback] = true
frame:HookScript(key, callback)
end
end
end
---@param frames Frame[]
---@param callback fun(self: Frame, ...)
---@param ... ScriptAnyWidgetHandler
function HookUtil:OnAll(frames, callback, ...)
for _, frame in ipairs(frames) do
HookUtil:On(frame, callback, ...)
end
end
---@param object Frame[]|Frame
---@param map table<ScriptAnyWidgetHandler, fun()>
function HookUtil:MapOn(object, map)
if type(object) ~= "table" then
return
end
if type(object.GetObjectType) == "function" then
for key, callback in pairs(map) do
HookUtil:On(object, callback, key)
end
return 1
end
for key, callback in pairs(map) do
HookUtil:OnAll(object, callback, key)
end
return true
end
--- In Classic the ScrollFrame uses the legacy system where the buttons are created as the frame is loaded.
---
--- There is no race condition, so we can simply ensure that the ScrollFrame exists, and if the first row widget exists, then all of them exist and can be hooked.
---
--- The return value is `nil` if the ScrollFrame doesn't exist. `false` if first row widget doesn't exist. Otherwise `true` to indicate success.
---
---@param scrollFrame Frame
---@param namePattern string
---@param hookMap table<string, fun()>
---@param onScroll? fun()
---@param maxIndex? number
---@param minIndex? number
function HookUtil:ClassicScrollFrame(scrollFrame, namePattern, hookMap, onScroll, maxIndex, minIndex)
if type(scrollFrame) ~= "table" then
return
end
minIndex = minIndex or 1
maxIndex = maxIndex or 32
local name = format(namePattern, minIndex)
local button = _G[name] ---@type Button?
if type(button) ~= "table" then
return false
end
for i = minIndex, maxIndex do
name = format(namePattern, i)
button = _G[name] ---@type Button?
if button then
HookUtil:MapOn(button, hookMap)
end
end
if onScroll then
HookUtil:On(scrollFrame, onScroll, "OnVerticalScroll")
end
return true
end
end
local DropDownUtil do
---@class UIDropDownMenuTemplatePolyfill : Frame
---@class UIDropDownMenuInfoPolyfill
---@field public checked boolean
---@field public text string
---@field public hasArrow boolean
---@field public notCheckable boolean
---@field public tooltipTitle? string
---@field public tooltipText? string
---@field public tooltipOnButton? boolean
---@field public menuList any
---@field public func? fun(self: UIDropDownMenuInfoPolyfill)
---@field public arg1 any
---@field public arg2 any
---@alias WowStyle1DropdownTemplateGeneratorFunctionPolyfill fun(owner: WowStyle1DropdownTemplatePolyfill, rootDescription: WowStyle1DropdownTemplateRootDescriptionPolyfill)
---@alias WowStyle1DropdownTemplateTooltipHandlerPolyfill fun(tooltip: GameTooltip, elementDescription: WowStyle1DropdownTemplateElementDescriptionPolyfill)
---@alias WowStyle1DropdownTemplateButtonBindingPolyfill fun(data: any)
---@alias WowStyle1DropdownTemplateRadioIsSelectedPolyfill fun(index: number): boolean?
---@alias WowStyle1DropdownTemplateRadioSetSelectedPolyfill fun(index: number)
---@class WowStyle1DropdownTemplateMenuAnchorPolyfill
---@field public point FramePoint
---@field public relativeTo Region
---@field public relativePoint FramePoint
---@field public x number
---@field public y number
---@class WowStyle1DropdownTemplatePolyfill : Button
---@field public intrinsic "DropdownButton"
---@field public menu? Frame @The menu frame when the menu is being shown.
---@field public menuAnchor WowStyle1DropdownTemplateMenuAnchorPolyfill
---@field public menuDescription WowStyle1DropdownTemplateRootDescriptionPolyfill
---@field public menuRelativePoint FramePoint
---@field public menuPoint FramePoint
---@field public menuPointX number
---@field public menuPointY number
---@field public text string
---@field public Arrow Texture
---@field public Background Texture
---@field public Text FontString
---@field public SetDefaultText fun(self: WowStyle1DropdownTemplatePolyfill, text?: string)
---@field public GetDefaultText fun(self: WowStyle1DropdownTemplatePolyfill): string?
---@field public SetupMenu fun(self: WowStyle1DropdownTemplatePolyfill, generatorFunction?: WowStyle1DropdownTemplateGeneratorFunctionPolyfill)
---@field public GenerateMenu fun(self: WowStyle1DropdownTemplatePolyfill)
---@field public GetMenuDescription fun(self: WowStyle1DropdownTemplatePolyfill): WowStyle1DropdownTemplateRootDescriptionPolyfill
---@field public SetMenuAnchor fun(self: WowStyle1DropdownTemplatePolyfill, anchor: WowStyle1DropdownTemplateMenuAnchorPolyfill)
---@field public SetMouseWheelEnabled fun(self: WowStyle1DropdownTemplatePolyfill, enabled?: boolean)
---@field public SetMenuOpen fun(self: WowStyle1DropdownTemplatePolyfill, open?: boolean)
---@field public OpenMenu fun(self: WowStyle1DropdownTemplatePolyfill, ownerRegion: Region, menuDescription: WowStyle1DropdownTemplateRootDescriptionPolyfill, anchor: WowStyle1DropdownTemplateMenuAnchorPolyfill)
---@field public CloseMenu fun(self: WowStyle1DropdownTemplatePolyfill)
---@field public SetSelectionText fun(self: WowStyle1DropdownTemplatePolyfill) @TODO
---@field public SetSelectionTranslator fun(self: WowStyle1DropdownTemplatePolyfill) @TODO
---@field public GetSelectionData fun(self: WowStyle1DropdownTemplatePolyfill) @TODO
---@field public SetText fun(self: WowStyle1DropdownTemplatePolyfill, text?: string)
---@field public GetText fun(self: WowStyle1DropdownTemplatePolyfill): string?
---@field public GetUpdateText fun(self: WowStyle1DropdownTemplatePolyfill): string?
---@field public SetTooltip fun(self: WowStyle1DropdownTemplatePolyfill, tooltipFunction?: WowStyle1DropdownTemplateTooltipHandlerPolyfill)
---@class WowStyle1DropdownTemplateRootDescriptionPolyfill
---@field public AddInitializer fun(owner: WowStyle1DropdownTemplatePolyfill, elementDescription?: WowStyle1DropdownTemplateElementDescriptionPolyfill, menu?: any)
---@field public CreateButton fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill, text?: string, binding?: WowStyle1DropdownTemplateButtonBindingPolyfill): WowStyle1DropdownTemplateRootDescriptionCheckboxPolyfill
---@field public CreateCheckbox fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public CreateColorSwatch fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public CreateDivider fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public CreateFrame fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public CreateRadio fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill, text?: string, isSelected: WowStyle1DropdownTemplateRadioIsSelectedPolyfill, setSelected: WowStyle1DropdownTemplateRadioSetSelectedPolyfill, index: number): WowStyle1DropdownTemplateRootDescriptionRadioPolyfill
---@field public CreateSpacer fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public CreateTemplate fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public CreateTitle fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill, text?: string)
---@field public QueueDivider fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public QueueSpacer fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public QueueTitle fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@field public SetTooltip fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill, tooltipFunction?: WowStyle1DropdownTemplateTooltipHandlerPolyfill)
---@field public SetTitleAndTextTooltip fun(self: WowStyle1DropdownTemplateRootDescriptionPolyfill) TODO
---@class WowStyle1DropdownTemplateRootDescriptionCheckboxPolyfill : WowStyle1DropdownTemplateRootDescriptionPolyfill
---@field public defaultResponse number `2`
---@class WowStyle1DropdownTemplateRootDescriptionRadioPolyfill : WowStyle1DropdownTemplateRootDescriptionPolyfill
---@field public isRadio true
---@field public soundKit number
---@class WowStyle1DropdownTemplateElementDescriptionPolyfill : WowStyle1DropdownTemplateRootDescriptionPolyfill
---@field public text string
---@field public data number
DropDownUtil = {}
function DropDownUtil:IsMenuSupported()
return Menu and MenuUtil and AnchorUtil and true or false
end
function DropDownUtil:PlaySound()
PlaySound(SOUNDKIT.IG_CHAT_EMOTE_BUTTON)
end
---@generic T
---@param owner T
---@param generatorFunction fun(owner: T, rootDescription: WowStyle1DropdownTemplateRootDescriptionPolyfill)
function DropDownUtil:CreateMenu(owner, generatorFunction)
local menu = CreateFrame("DropdownButton", nil, owner, "WowStyle1DropdownTemplate") ---@class WowStyle1DropdownTemplatePolyfill
menu:SetupMenu(generatorFunction)
return menu
end
---@generic T, L
---@param owner T
---@param initialize fun(self: UIDropDownMenuTemplatePolyfill, level: number, menuList?: L)
---@param style? "MENU"
function DropDownUtil:CreateDropDown(owner, initialize, style)
local menu = CreateFrame("Frame", nil, owner, "UIDropDownMenuTemplate") ---@class UIDropDownMenuTemplatePolyfill
UIDropDownMenu_Initialize(menu, initialize, style or "MENU")
return menu
end
---@param menu WowStyle1DropdownTemplatePolyfill
---@param anchorPoint? FramePoint
---@param anchorRelativePoint? Region
---@param anchorRelativeTo? FramePoint
---@param anchorX? number
---@param anchorY? number
function DropDownUtil:OpenMenu(menu, anchorPoint, anchorRelativePoint, anchorRelativeTo, anchorX, anchorY)
if not menu.menuAnchor or menu.menuAnchor.relativeTo ~= anchorRelativePoint then
local anchor = AnchorUtil.CreateAnchor(anchorPoint or "TOPLEFT", anchorRelativePoint or menu:GetParent(), anchorRelativeTo or "BOTTOMLEFT", anchorX or 0, anchorY or 0)
menu:SetMenuAnchor(anchor)
end
menu:SetMenuOpen(true)
end
---@param menu WowStyle1DropdownTemplatePolyfill
function DropDownUtil:IsMenuOpen(menu)
return menu.menu ~= nil
end
---@param menu WowStyle1DropdownTemplatePolyfill
function DropDownUtil:CloseMenu(menu)
menu:SetMenuOpen(false)
end
---@param menu WowStyle1DropdownTemplatePolyfill
---@param anchorPoint? FramePoint
---@param anchorRelativePoint? Region
---@param anchorRelativeTo? FramePoint
---@param anchorX? number
---@param anchorY? number
function DropDownUtil:ToggleMenu(menu, anchorPoint, anchorRelativePoint, anchorRelativeTo, anchorX, anchorY)
self:PlaySound()
if self:IsMenuOpen(menu) then
self:CloseMenu(menu)
else
self:OpenMenu(menu, anchorPoint, anchorRelativePoint, anchorRelativeTo, anchorX, anchorY)
end
end
---@param dropDownMenu UIDropDownMenuTemplatePolyfill
---@param anchor? "cursor"|Region
---@param anchorX? number
---@param anchorY? number
function DropDownUtil:OpenDropDown(dropDownMenu, anchor, anchorX, anchorY)
ToggleDropDownMenu(1, nil, dropDownMenu, anchor, anchorX, anchorY)
end
---@param dropDownMenu UIDropDownMenuTemplatePolyfill
function DropDownUtil:IsDropDownOpen(dropDownMenu)
return DropDownList1:IsShown() and DropDownList1.dropdown == dropDownMenu
end
---@param dropDownMenu UIDropDownMenuTemplatePolyfill
function DropDownUtil:CloseDropDown(dropDownMenu)
if self:IsDropDownOpen(dropDownMenu) then
CloseDropDownMenus()
end
end
---@param dropDownMenu UIDropDownMenuTemplatePolyfill
---@param anchor? "cursor"|Region
---@param anchorX? number
---@param anchorY? number
function DropDownUtil:ToggleDropDown(dropDownMenu, anchor, anchorX, anchorY)
self:PlaySound()
if self:IsDropDownOpen(dropDownMenu) then
self:CloseDropDown(dropDownMenu)
else
self:OpenDropDown(dropDownMenu, anchor, anchorX, anchorY)
end
end
end
local StaticPopupUtil do
---@param widget? Region
local function isTextFontString(widget)
return widget and widget:GetObjectType() == "FontString"
end
---@param widget? Region
---@param reqShown? boolean
local function isEditBox(widget, reqShown)
return widget and widget:GetObjectType() == "EditBox" and (not reqShown or widget:IsShown())
end
---@param widget? Region
local function isButton(widget)
return widget and widget:GetObjectType() == "Button"
end
StaticPopupUtil = {}
---@param id string|InternalStaticPopupDialog
---@param ... any
---@return InternalStaticPopupFrame? popup, string? name
function StaticPopupUtil:IsVisible(id, ...)
local name ---@type string?
local t = type(id)
if t == "table" then
name = id.id
elseif t == "string" then
name = id
end
if not name or type(name) ~= "string" then
return
end
---@type string?, InternalStaticPopupFrame?
local frameName, frame = StaticPopup_Visible(name, ...)
return frame, frameName
end
---@param popup InternalStaticPopupDialog
---@param ... any
---@return InternalStaticPopupFrame
function StaticPopupUtil:Show(popup, ...)
local id = popup.id
if not StaticPopupDialogs[id] then
if type(popup.text) == "function" then
popup.text = popup.text()
end
if not popup.which then
popup.which = popup.id
end
StaticPopupDialogs[id] = popup
end
return StaticPopup_Show(id, ...)
end
---@param popup InternalStaticPopupFrame
---@param ... any
function StaticPopupUtil:Hide(popup, ...)
return StaticPopup_Hide(popup.which, ...)
end
---@param popup InternalStaticPopupFrame
function StaticPopupUtil:GetTextFontString(popup)
local text = popup.Text
if isTextFontString(text) then
return text
end
if popup.GetTextFontString then
text = popup:GetTextFontString()
end
if isTextFontString(text) then
return text
end
text = popup.text
if isTextFontString(text) then
return text
end
local name = popup:GetName()
text = _G[format("%sText", name)]
return text
end
---@param popup InternalStaticPopupFrame
function StaticPopupUtil:GetEditBox(popup)
local editBox = popup.EditBox
if isEditBox(editBox) then
return editBox
end
if popup.GetEditBox then
editBox = popup:GetEditBox()
end
if isEditBox(editBox) then
return editBox
end
local name = popup:GetName()
editBox = _G[format("%sWideEditBox", name)]
if isEditBox(editBox, true) then
return editBox
end
editBox = _G[format("%sEditBox", name)]
return editBox
end
---@param popup InternalStaticPopupFrame
function StaticPopupUtil:GetWideEditBox(popup)
local name = popup:GetName()
local editBox = _G[format("%sWideEditBox", name)]
if isEditBox(editBox, true) then
return editBox
end
return self:GetEditBox(popup)
end
---@param popup InternalStaticPopupFrame
---@param index number
function StaticPopupUtil:GetButton(popup, index)
local button ---@type Button?
if popup.GetButton then
button = popup:GetButton(index)
end
if isButton(button) then
return button
end
local func = popup[format("GetButton%d", index)] ---@type (fun(self: InternalStaticPopupFrame): Button?)?
if func then
button = func(popup)
end
if isButton(button) then
return button
end
button = popup[format("button%d", index)] ---@type Button?
if isButton(button) then
return button
end
local name = popup:GetName()
button = _G[format("%sButton%d", name, index)]
return button
end
end
-- clients have API naming variants and this helps bridge that gap (this will require revisions/deletion as the clients unify their API's)
local GetDetailedItemLevelInfo = GetDetailedItemLevelInfo or C_Item.GetDetailedItemLevelInfo ---@diagnostic disable-line: deprecated
local GetItemInfo = GetItemInfo or C_Item.GetItemInfo ---@diagnostic disable-line: deprecated
local GetItemInfoInstant = GetItemInfoInstant or C_Item.GetItemInfoInstant ---@diagnostic disable-line: deprecated
local GetItemQualityColor = GetItemQualityColor or C_Item.GetItemQualityColor ---@diagnostic disable-line: deprecated
local ReloadUI = ReloadUI or C_UI.Reload
local issecretvalue = issecretvalue or function(value) return false end ---@type fun(value: any): boolean
---@param tbl table
---@param ... string
local function issecretvaluekey(tbl, ...)
if issecretvalue(tbl) then
return true
end
for _, key in ipairs({...}) do
local value = tbl[key]
if issecretvalue(value) then
return true
end
end
return false
end
-- constants.lua (ns)
-- dependencies: none
do
---@class ns
---@field public DUNGEONS? Dungeon[]
---@field public dungeons? Dungeon[] @DEPRECATED
---@field public EXPANSION_DUNGEONS? Dungeon[]
---@field public expansionDungeons? Dungeon[] @DEPRECATED
---@field public RAIDS? DungeonRaid[]
---@field public raids? DungeonRaid[] @DEPRECATED
---@field public REALMS table<string, string>
---@field public realmSlugs table<string, string> @DEPRECATED
---@field public REGIONS table<number, number>
---@field public regionIDs table<number, number> @DEPRECATED
---@field public SCORE_STATS? table<number, number>
---@field public scoreLevelStats? table<number, number> @DEPRECATED
---@field public DUNGEON_SCORE_STATS? table<number, DungeonScoreStats>
---@field public dungeonScoreStats? table<number, DungeonScoreStats> @DEPRECATED
---@field public SCORE_TIERS? table<number, ScoreColor>
---@field public scoreTiers? table<number, ScoreColor> @DEPRECATED
---@field public SCORE_TIERS_SIMPLE? table<number, ScoreTierSimple>
---@field public scoreTiersSimple? table<number, ScoreTierSimple> @DEPRECATED
---@field public SCORE_TIERS_PREV? table<number, ScoreColor>
---@field public previousScoreTiers? table<number, ScoreColor> @DEPRECATED
---@field public SCORE_TIERS_SIMPLE_PREV table<number, ScoreTierSimple>
---@field public previousScoreTiersSimple table<number, ScoreTierSimple> @DEPRECATED
---@field public CUSTOM_TITLES table<number, RecruitmentTitle>
---@field public CLIENT_CHARACTERS table<string, CharacterCollection>
---@field public CLIENT_RECENT_CHARACTERS table<string, RecentCharacterCollection>
---@field public CLIENT_COLORS table<number, ScoreColor>
---@field public CLIENT_CONFIG ClientConfig
---@field public GUILD_BEST_DATA table<string, GuildCollection>
---@field public REPLAYS Replay[]
---@field public EXPANSION number @The currently accessible expansion to the playerbase
---@field public MAX_LEVEL number @The currently accessible expansion max level to the playerbase
---@field public PLAYER_REGION string @`us`, `kr`, `eu`, `tw`, `cn`
---@field public PLAYER_REGION_ID number @`1` (us), `2` (kr), `3` (eu), `4` (tw), `5` (cn)
---@field public PLAYER_FACTION number @`1` (alliance), `2` (horde), `3` (neutral)
---@field public PLAYER_FACTION_TEXT string @`Alliance`, `Horde`, `Neutral`
---@field public PLAYER_NAME string @The name of the player character
---@field public PLAYER_REALM string @The realm of the player character
---@field public PLAYER_REALM_SLUG string @The realm slug of the player character
ns.Print = function(text, r, g, b, ...)
r, g, b = r or 1, g or 1, b or 0
DEFAULT_CHAT_FRAME:AddMessage(tostring(text), r, g, b, ...)
end
ns.EXPANSION = max(GetServerExpansionLevel(), GetMinimumExpansionLevel(), GetExpansionLevel()) - 1
ns.MAX_LEVEL = GetMaxLevelForExpansionLevel(ns.EXPANSION)
ns.REGION_TO_LTD = { "us", "kr", "eu", "tw", "cn" }
ns.FACTION_TO_ID = { Alliance = 1, Horde = 2, Neutral = 3 }
ns.PLAYER_REGION = nil
ns.PLAYER_REGION_ID = nil
ns.PLAYER_FACTION = nil
ns.PLAYER_FACTION_TEXT = nil
ns.OUTDATED_CUTOFF = 86400 * 3 -- number of seconds before we start warning about stale data (warning the user should update their addon)
ns.OUTDATED_BLOCK_CUTOFF = 86400 * 7 -- number of seconds before we hide the data (block showing score as its most likely inaccurate)
ns.PROVIDER_DATA_TYPE = { MythicKeystone = 1, Raid = 2, Recruitment = 3, PvP = 4 }
ns.LOOKUP_MAX_SIZE = floor(2^18-1) -- the maximum index we can use in a table before we start to get errors
ns.CURRENT_SEASON = 0 -- the current mythic keystone season. dynamically assigned once keystone data is loaded. 0-index based.
ns.RAIDERIO_ADDON_DOWNLOAD_URL = "https://rio.gg/addon"
ns.RAIDERIO_DOMAIN = "raider.io"
if IS_CLASSIC_ERA then
ns.RAIDERIO_DOMAIN = "era.raider.io"
elseif IS_CLASSIC then
ns.RAIDERIO_DOMAIN = "classic.raider.io"
end
ns.EASTER_EGG = {
["eu"] = {
["TarrenMill"] = {
["Vladinator"] = "Raider.IO AddOn Author"
},
["Ysondre"] = {
["Isakem"] = "Raider.IO Developer"
},
["TwistingNether"] = {
["Piccoò"] = "Raider.IO Super Tato"
}
},
["us"] = {
["Skullcrusher"] = {
["Aspyrx"] = "Raider.IO Creator",
["Ulsoga"] = "Raider.IO Creator",
["Mccaffrey"] = "Killing Keys Since 1977!",
["Oscassey"] = "Master of dis guys",
["Rhoma"] = "Plays an MDI Champion on TV",
["Infoxicated"] = "Pogged out of her mind"
},
["Thrall"] = {
["Firstclass"] = "Author of mythicpl.us",
["Hulahoops"] = "Raider.IO Cool Kid"
},
["Tichondrius"] = {
["Johnsamdi"] = "Raider.IO Developer",
["Vitamiinp"] = "Content Manager of Raider.IO"
},
["Mal'Ganis"] = {
["Qbgosa"] = "Raider.IO Support Dragon"
},
["BurningBlade"] = {
["Pelinal"] = "Raider.IO Developer"
}
}
}
-- Special servers for keystones, PvP, etc. That we do not wish to consider a live server.
ns.IGNORED_REALMS = {
["EU Mythic Dungeons"] = true,
["EUMythicDungeons"] = true,
}
---@class HeadlineMode
ns.HEADLINE_MODE = {
CURRENT_SEASON = 0,
BEST_SEASON = 1,
BEST_RUN = 2
}
local PREVIOUS_SEASON_NUM_DUNGEONS = 8
local DUNGEONS = ns.DUNGEONS or ns.dungeons or {} -- DEPRECATED: ns.dungeons + FALLBACK
-- threshold for comparing current character's previous season score to current score
-- meaning: once current score exceeds this fraction of previous season, then show current season
ns.PREVIOUS_SEASON_SCORE_RELEVANCE_THRESHOLD = min((#DUNGEONS / PREVIOUS_SEASON_NUM_DUNGEONS) * 0.9, 0.9)
-- threshold for comparing the main character's previous season score to current. This establishes
-- when to prioritize showing the main's current score over their previous score. With Dragonflight
-- seasons have changed significantly (new dungeons each patch) so we do not think showing the main's
-- previous season score is relevant for that long into progression.
ns.PREVIOUS_SEASON_MAIN_SCORE_RELEVANCE_THRESHOLD = min((#DUNGEONS / PREVIOUS_SEASON_NUM_DUNGEONS) * 0.9, 0.9)
---Use `ns.CUSTOM_ICONS.FILENAME.KEY` to get the raw icon table.
---
---Use `ns.CUSTOM_ICONS.FILENAME.KEY("Texture")` to retrieve the `CustomIconTexture` for the icon.
---
---Use `ns.CUSTOM_ICONS.FILENAME.KEY("TextureMarkup")` to retrieve the texture markup `string` for the icon.
---@class CustomIcons
---@class CustomIconsCollection
ns.CUSTOM_ICONS = {
---@class CustomIcons_Affixes : CustomIcons
affixes = {
TYRANNICAL_OFF = { 32, 32, 0, 0, 16/32, 32/32, 16/32, 32/32, 0, 0 },
FORTIFIED_OFF = { 32, 32, 0, 0, 16/32, 32/32, 0/32, 16/32, 0, 0 },
TYRANNICAL_ON = { 32, 32, 0, 0, 0/32, 16/32, 16/32, 32/32, 0, 0 },
FORTIFIED_ON = { 32, 32, 0, 0, 0/32, 16/32, 0/32, 16/32, 0, 0 },
},
---@class CustomIcons_Icons : CustomIcons
icons = {
RAIDERIO_COLOR_CIRCLE = { 256, 256, 0, 0, 0/256, 64/256, 0/256, 64/256, 0, 0 },
RAIDERIO_WHITE_CIRCLE = { 256, 256, 0, 0, 64/256, 128/256, 0/256, 64/256, 0, 0 },
RAIDERIO_BLACK_CIRCLE = { 256, 256, 0, 0, 128/256, 192/256, 0/256, 64/256, 0, 0 },
RAIDERIO_COLOR = { 256, 256, 0, 0, 0/256, 64/256, 64/256, 128/256, 0, 0 },
RAIDERIO_WHITE = { 256, 256, 0, 0, 64/256, 128/256, 64/256, 128/256, 0, 0 },
RAIDERIO_BLACK = { 256, 256, 0, 0, 128/256, 192/256, 64/256, 128/256, 0, 0 },
WARBAND_WHITE = { 256, 256, 0, 0, 0/256, 64/256, 128/256, 192/256, -2, 2 },
WARBAND_BLACK = { 256, 256, 0, 0, 64/256, 128/256, 128/256, 192/256, -2, 2 },
},
---@class CustomIcons_Replay : CustomIcons
replay = {
TIMER = { 256, 256, 0, 0, 0/256, 64/256, 0/256, 64/256, 0, 0 },
BOSS = { 256, 256, 0, 0, 64/256, 128/256, 0/256, 64/256, 0, 0 },
TRASH = { 256, 256, 0, 0, 128/256, 192/256, 0/256, 64/256, 0, 0 },
DEATH = { 256, 256, 0, 0, 192/256, 256/256, 0/256, 64/256, 0, 0 },
COMBAT = { 256, 256, 0, 0, 0/256, 64/256, 64/256, 128/256, 0, 0 },
ROUTE = { 256, 256, 0, 0, 64/256, 128/256, 64/256, 128/256, 0, 0 },
},
---@class CustomIcons_Roles : CustomIcons
roles = {
dps_full = { 64, 64, 0, 0, 0/64, 18/64, 0/64, 18/64, 0, 0 },
dps_partial = { 64, 64, 0, 0, 0/64, 18/64, 18/64, 36/64, 0, 0 },
dps_thanos = { 64, 64, 0, 0, 0/64, 18/64, 36/64, 54/64, 0, 0 },
healer_full = { 64, 64, 0, 0, 18/64, 36/64, 0/64, 18/64, 0, 0 },
healer_partial = { 64, 64, 0, 0, 18/64, 36/64, 18/64, 36/64, 0, 0 },
healer_thanos = { 64, 64, 0, 0, 18/64, 36/64, 36/64, 54/64, 0, 0 },
tank_full = { 64, 64, 0, 0, 36/64, 54/64, 0/64, 18/64, 0, 0 },
tank_partial = { 64, 64, 0, 0, 36/64, 54/64, 18/64, 36/64, 0, 0 },
tank_thanos = { 64, 64, 0, 0, 36/64, 54/64, 36/64, 54/64, 0, 0 },
},
}
-- Finalize the `ns.CUSTOM_ICONS` table
do
---@class CustomIcon
---@field public filePath string
---@class CustomIconTexture
---@field public width number @The requested width that we should use for the texture.
---@field public height number @The requested height that we should use for the texture.
---@field public texture string @The texture filepath for use with `:SetTexture(...)`
---@field public texCoord table @The texture coordinates for use with `:SetTexCoord(unpack(...))`
---@field public textureWidth number @The real texture width.
---@field public textureHeight number @The real texture height.
local Handlers = {
---@param self CustomIcon
---@param left number
---@param right number
---@param top number
---@param bottom number
---@return CustomIconTexture
Texture = function(self, _, _, width, height, left, right, top, bottom)
return {
width = width,
height = height,
texture = self.filePath,
texCoord = { left, right, top, bottom },
textureWidth = self[3],
textureHeight = self[4],
}
end,
---@param self CustomIcon
TextureMarkup = function(self, ...)
return CreateTextureMarkup(self.filePath, ...)
end,
}
local Utils = {
GetSize = function(size, fallback)
if type(fallback) ~= "number" then
fallback = 0
end
if type(size) ~= "number" or size <= 0 then
return fallback
end
return size
end,
GetKey = function(key, size)
if size > 0 then
return format("%s_%d", key, size)
end
return key
end,
GetKeySize = function(self, key, size)
size = self.GetSize(size, 0)
return self.GetKey(key, size), size
end,
}
local Metatable = {
__metatable = false,
__call = function(self, key, ...)
local handler = Handlers[key]
if not handler then
return
end
local rawKey, size = Utils:GetKeySize(key, ...)
local rawVal = rawget(self, rawKey)
if rawVal ~= nil then
return rawVal
end
local fileWidth, fileHeight, width, height, left, right, top, bottom, xOffset, yOffset = unpack(self)
local realWidth = (right * fileWidth) - (left * fileWidth)
local realHeight = (bottom * fileHeight) - (top * fileHeight)
if realWidth >= size or realHeight >= size then
width, height = size, size
else
rawKey = key
end
rawVal = handler(self, fileWidth, fileHeight, width, height, left, right, top, bottom, xOffset, yOffset)
rawset(self, rawKey, rawVal)
return rawVal
end,
}
for fileName, fileIcons in pairs(ns.CUSTOM_ICONS) do
for _, iconInfo in pairs(fileIcons) do
iconInfo.filePath = format("Interface\\AddOns\\RaiderIO\\icons\\%s", fileName)
setmetatable(iconInfo, Metatable)
end
end
end
---@class MarkupIcons
---@field public markup? string
---@field public markupPadLeft? string
---@field public markupPadRight? string
---@class MarkupIconsCollection
ns.MARKUP_ICONS = {
---@class MarkupIcons
LeftButton = {
atlas = "newplayertutorial-icon-mouse-leftbutton",
atlasWidth = 12,
atlasHeight = 16,
},
---@class MarkupIcons
RightButton = {
atlas = "newplayertutorial-icon-mouse-rightbutton",
atlasWidth = 12,
atlasHeight = 16,
},
}
-- Finalize the `ns.MARKUP_ICONS` table
do
for _, info in pairs(ns.MARKUP_ICONS) do
info = info ---@type MarkupIcons
if info.atlas then
local atlasInfo = C_Texture.GetAtlasInfo(info.atlas)
if atlasInfo then
info.markup = format("|A:%s:%d:%d|a", info.atlas, info.atlasHeight or atlasInfo.height, info.atlasWidth or atlasInfo.width)
info.markupPadLeft = format(" %s", info.markup)
info.markupPadRight = format("%s ", info.markup)
end
end
end
end
ns.KEYSTONE_AFFIX_TEXTURE = { -- Maps each affix to a texture string Tyrannical (`9`/`-9`) and Fortified (`10`/`-10`).
[-9] = ns.CUSTOM_ICONS.affixes.TYRANNICAL_OFF("TextureMarkup"),
[-10] = ns.CUSTOM_ICONS.affixes.FORTIFIED_OFF("TextureMarkup"),
[9] = ns.CUSTOM_ICONS.affixes.TYRANNICAL_ON("TextureMarkup"),
[10] = ns.CUSTOM_ICONS.affixes.FORTIFIED_ON("TextureMarkup"),
}
ns.PROFILE_TOOLTIP_COLUMN_TEXTURE = { -- The regular character column and the warband icon used in the profile tooltip.
CHARACTER = "|T982414:1:1|t",
WARBAND = ns.CUSTOM_ICONS.icons.WARBAND_WHITE("TextureMarkup"),
}
---@class RoleIcon
---@field full string @The full icon in "|T|t" syntax
---@field partial string @The partial icon in "|T|t" syntax
---@class RoleIcons
---@field public dps RoleIcon
---@field public healer RoleIcon
---@field public tank RoleIcon
---@type RoleIcons
ns.ROLE_ICONS = { -- Collection of roles and their icons.
dps = {
full = "|TInterface\\AddOns\\RaiderIO\\icons\\roles:14:14:0:0:64:64:0:18:0:18|t",
partial = "|TInterface\\AddOns\\RaiderIO\\icons\\roles:14:14:0:0:64:64:0:18:36:54|t"
},
healer = {
full = "|TInterface\\AddOns\\RaiderIO\\icons\\roles:14:14:0:0:64:64:19:37:0:18|t",
partial = "|TInterface\\AddOns\\RaiderIO\\icons\\roles:14:14:0:0:64:64:19:37:36:54|t"
},
tank = {
full = "|TInterface\\AddOns\\RaiderIO\\icons\\roles:14:14:0:0:64:64:38:56:0:18|t",
partial = "|TInterface\\AddOns\\RaiderIO\\icons\\roles:14:14:0:0:64:64:38:56:36:54|t"
}
}
ns.KEYSTONE_LEVEL_PATTERN = { -- Table over patterns matching keystone levels in strings.
"(%d+)%+",
"%+%s*(%d+)",
"(%d+)%s*%+",
"(%d+)"
}
ns.KEYSTONE_LEVEL_TO_SCORE = { -- Table over keystone levels and the base score for that level.
[2] = 40,
[3] = 45,
[4] = 55,
[5] = 60,
[6] = 65,
[7] = 75,
[8] = 80,
[9] = 85,
[10] = 100,
[11] = 105,
[12] = 110,
[13] = 115,
[14] = 120,
[15] = 125,
[16] = 130,
[17] = 135,
[18] = 140,
[19] = 145,
[20] = 150,
[21] = 155,
[22] = 160,
[23] = 165,
[24] = 170,
[25] = 175,
[26] = 180,
[27] = 185,
[28] = 190,
[29] = 195,
[30] = 200
}
---@class RaidDifficultyColor
---@field public [1] number @red (0-1.0) - this table can be unpacked to get r, g, b
---@field public [2] number @green (0-1.0) - this table can be unpacked to get r, g, b
---@field public [3] number @blue (0-1.0) - this table can be unpacked to get r, g, b
---@field public hex string @hex (000000-ffffff) - this table can be unpacked to get r, g, b
---@class RaidDifficulty
---@field public suffix string
---@field public name string
---@field public color RaidDifficultyColor
if IS_RETAIL then
ns.RAID_DIFFICULTY = { -- Table of `1` (normal), `2` (heroic), `3` (mythic) difficulties and their names and colors.
---@type RaidDifficulty
[1] = {
suffix = L.RAID_DIFFICULTY_SUFFIX_NORMAL,
name = L.RAID_DIFFICULTY_NAME_NORMAL,
color = { 0.12, 1.00, 0.00, hex = "1eff00" }
},
---@type RaidDifficulty
[2] = {
suffix = L.RAID_DIFFICULTY_SUFFIX_HEROIC,
name = L.RAID_DIFFICULTY_NAME_HEROIC,
color = { 0.00, 0.44, 0.87, hex = "0070dd" }
},
---@type RaidDifficulty
[3] = {
suffix = L.RAID_DIFFICULTY_SUFFIX_MYTHIC,
name = L.RAID_DIFFICULTY_NAME_MYTHIC,
color = { 0.64, 0.21, 0.93, hex = "a335ee" }
}
}
elseif IS_CLASSIC then
ns.RAID_DIFFICULTY = { -- Table of `1` (normal10), `2` (normal25), `3` (heroic10), `4` (heroic25) difficulties and their names and colors.
---@type RaidDifficulty
[1] = {
suffix = L.RAID_DIFFICULTY_SUFFIX_NORMAL10,
name = L.RAID_DIFFICULTY_NAME_NORMAL10,
color = { 0.12, 1.00, 0.00, hex = "1eff00" }
},
---@type RaidDifficulty
[2] = {
suffix = L.RAID_DIFFICULTY_SUFFIX_NORMAL25,
name = L.RAID_DIFFICULTY_NAME_NORMAL25,
color = { 0.12, 1.00, 0.00, hex = "1eff00" }
},
---@type RaidDifficulty
[3] = {
suffix = L.RAID_DIFFICULTY_SUFFIX_HEROIC10,
name = L.RAID_DIFFICULTY_NAME_HEROIC10,
color = { 0.64, 0.21, 0.93, hex = "a335ee" }
},
---@type RaidDifficulty
[4] = {
suffix = L.RAID_DIFFICULTY_SUFFIX_HEROIC25,
name = L.RAID_DIFFICULTY_NAME_HEROIC25,
color = { 0.64, 0.21, 0.93, hex = "a335ee" }
}
}