-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCombatAssistIcon.lua
More file actions
1014 lines (846 loc) · 40.3 KB
/
CombatAssistIcon.lua
File metadata and controls
1014 lines (846 loc) · 40.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, addon = ...
local addonTitle = C_AddOns.GetAddOnMetadata(addonName, "Title")
local _G = _G
local GetTime = GetTime
local GetActionInfo = GetActionInfo
local GetBindingKey = GetBindingKey
local GetBindingText = GetBindingText
local InCombatLockdown = InCombatLockdown
local UnitCanAttack = UnitCanAttack
local UnitIsDead = UnitIsDead
local UnitIsUnit = UnitIsUnit
local UnitInVehicle = UnitInVehicle
local UnitGroupRolesAssigned = UnitGroupRolesAssigned
local C_CVar = C_CVar
local C_Spell = C_Spell
local C_SpellBook = C_SpellBook
local C_ActionBar = C_ActionBar
local C_AssistedCombat = C_AssistedCombat
local C_NamePlate = C_NamePlate
local C_StringUtil = C_StringUtil
local C_Timer = C_Timer
local LSM = LibStub("LibSharedMedia-3.0")
local LKB = LibStub("LibKeyBound-CUSTOM")
local ACR = LibStub("AceConfigRegistry-3.0")
local ACD = LibStub("AceConfigDialog-3.0")
local LAB = LibStub("LibActionButton-1.0", true)
local Masque = LibStub("Masque",true)
local HasBartender = false
local HasDominos = false
local HasElvUI = false
local OverrideBindingByButton
local BindingByButton = {}
local SpellIDByButton = {}
local ButtonsBySlot = {}
local SlotByButton = {}
local rotationalSpells = {}
local playerClass = select(2,UnitClass("player"))
local Colors = {
UNLOCKED = CreateColor(0, 1, 0, 1.0),
USABLE = CreateColor(1.0, 1.0, 1.0, 1.0),
NOT_USABLE = CreateColor(0.4, 0.4, 0.4, 1.0),
NOT_ENOUGH_MANA = CreateColor(0.5, 0.5, 1.0, 1.0),
NOT_IN_RANGE = CreateColor(0.64, 0.15, 0.15, 1.0)
}
local frameStrata = {
"BACKGROUND",
"LOW",
"MEDIUM",
"HIGH",
"DIALOG",
"TOOLTIP",
}
local function IsValidSpellID(spellID)
return type(spellID) == "number"
and spellID > 0
and C_Spell.DoesSpellExist(spellID)
end
local function IsRotationalSpell(spellID)
return rotationalSpells[spellID] or false
end
local function SafeSetShown(frame, shown)
local success = pcall(frame.SetShown, frame, addon.db.profile.fadeOutHide or shown)
local minAlpha = addon.db.profile.fadeOutHide and addon.db.profile.fadeOutAlpha or 0
local maxAlpha = addon.db.profile.alpha or 1
frame:SetAlpha(shown and maxAlpha or minAlpha)
return success
end
local function IsMountedLocal()
if playerClass == "DRUID" then
return GetShapeshiftForm() == 3 or IsMounted()
else
return IsMounted()
end
end
local function GetSpellIDFromActionID(action)
if not action then return end
local actionType, id, subType = GetActionInfo(action)
if (actionType == "macro" and subType == "spell")
or (actionType == "spell" and subType ~= "assistedcombat")
then
return id
end
return nil
end
local function GetBindingForAction(action)
if not action then return end
local key = GetBindingKey(action)
if not key then return end
local text = LKB:ToShortKey(key)
if text then return text end
end
local function GetButtonsForSpellID(spellID)
if not IsValidSpellID(spellID) then return end
local baseSpellID = C_SpellBook.FindBaseSpellByID(spellID)
local buttons = {}
for buttonName, buttonSpellID in pairs(SpellIDByButton) do
local frame = _G[buttonName]
if frame and buttonSpellID == baseSpellID then
table.insert(buttons, buttonName)
end
end
return buttons
end
local function GetSpellIDFromButton(buttonName)
local actionButton = _G[buttonName]
if not actionButton then return end
local spellID
if actionButton.spellID then
spellID = actionButton.spellID
elseif actionButton.action then
spellID = GetSpellIDFromActionID(actionButton.action)
else
local num = buttonName:find("Stance", 1, true) and tonumber(buttonName:match("(%d+)$"))
if num then
local _, _, _, formID = GetShapeshiftFormInfo(num)
spellID = formID
end
end
return spellID
end
local function UpdateButtonSpellID(buttonName)
if not buttonName then return end
local spellID = GetSpellIDFromButton(buttonName)
local baseSpellID = spellID and C_SpellBook.FindBaseSpellByID(spellID)
local isRotationSpell = IsRotationalSpell(spellID) or IsRotationalSpell(baseSpellID)
SpellIDByButton[buttonName] = isRotationSpell and baseSpellID or nil
end
local function UpdateAllButtonsSpellID()
for buttonName, buttonSpellID in pairs(SpellIDByButton) do
UpdateButtonSpellID(buttonName)
end
end
local function GetKeyBindForSpellID(spellID)
if not IsValidSpellID(spellID) then return end
local override = addon.db.profile.Keybind.overrides[spellID]
if override then return override end
if ConsolePort and addon.db.profile.Keybind.ConsolePort then
slots = C_ActionBar.FindSpellActionButtons(spellID)
if slots then
for _, slot in ipairs(slots) do
local bindingID = ConsolePort:GetActionBinding(slot)
local binding = ConsolePort:GetFormattedBindingOwner(bindingID)
if binding and binding ~= "" then return binding end
end
end
end
local buttons = GetButtonsForSpellID(spellID)
if not buttons then return end
for _,buttonName in ipairs(buttons) do
local buttonAction = BindingByButton[buttonName]
local text = GetBindingForAction(buttonAction)
if not text and OverrideBindingByButton then
buttonAction = OverrideBindingByButton[buttonName]
text = GetBindingForAction(buttonAction)
end
if text then return text end
end
end
local function AddButtonToSlot(buttonName, slot)
local oldSlot = SlotByButton[buttonName]
if not slot or oldSlot == slot then return end
if oldSlot then
local oldButtons = ButtonsBySlot[oldSlot]
if oldButtons then
oldButtons[buttonName] = nil
if not next(oldButtons) then
ButtonsBySlot[oldSlot] = nil
end
end
end
SlotByButton[buttonName] = slot
ButtonsBySlot[slot] = ButtonsBySlot[slot] or {}
ButtonsBySlot[slot][buttonName] = true
end
local function OnActionSlotChanged(slot)
if not slot then return end
local buttons = ButtonsBySlot[slot]
if not buttons then return end
for buttonName in pairs(buttons) do
UpdateButtonSpellID(buttonName)
end
end
local function OnActionChanged(self, button, action, ...)
if not button then return end
local buttonName = button:GetName()
if not buttonName then return end
C_Timer.After(0, function()
AddButtonToSlot(buttonName, button.action)
UpdateButtonSpellID(buttonName)
end)
end
local function OnSpellsChanged()
local spells = C_AssistedCombat.GetRotationSpells()
for _, spellID in ipairs(spells) do
if C_SpellBook.IsSpellInSpellBook(spellID) then
rotationalSpells[spellID] = true
end
end
UpdateAllButtonsSpellID()
end
local function HideLikelyMasqueRegions(frame)
if not Masque then return end
for _, region in ipairs({ frame:GetRegions() }) do
if not frame.__baselineRegions[region] then
region:Hide()
end
end
end
local function LoadRotationalSpells()
wipe(rotationalSpells)
OnSpellsChanged()
end
local function LoadActionSlotMap()
if C_AddOns.IsAddOnLoaded("ElvUI") then
local E = unpack(ElvUI)
HasElvUI = E and E.private and E.private.actionbar and E.private.actionbar.enable or false
end
if C_AddOns.IsAddOnLoaded("Bartender4") then HasBartender = true end
if C_AddOns.IsAddOnLoaded("Dominos") then HasDominos = true end
if ( (HasElvUI and HasBartender) or (HasElvUI and HasDominos) or (HasBartender and HasDominos) ) and addon.db.profile.Keybind.show then
DEFAULT_CHAT_FRAME:AddMessage("|cff4cc9f0SACI|r: |cffffa000 Warning! More than 1 Action Bar addon is loaded! Keybinds will be inconsistent!|r")
end
local NUM_SHAPESHIFT = GetNumShapeshiftForms()
if HasDominos then
local DominosActionSlotMap = {
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="DominosActionButton", start = 1, last = 12}, --Bar 1
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="DominosActionButton", start = 13, last = 24}, --Bar 2
{ actionPrefix = "MULTIACTIONBAR3BUTTON", buttonPrefix ="MultiBarRightButton", start = 25, last = 36}, --Bar 3
{ actionPrefix = "MULTIACTIONBAR4BUTTON", buttonPrefix ="MultiBarLeftButton", start = 37, last = 48}, --Bar 4
{ actionPrefix = "MULTIACTIONBAR2BUTTON", buttonPrefix ="MultiBarBottomRightButton",start = 49, last = 60}, --Bar 5
{ actionPrefix = "MULTIACTIONBAR1BUTTON", buttonPrefix ="MultiBarBottomLeftButton", start = 61, last = 72}, --Bar 6
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="DominosActionButton", start = 73, last = 84}, --Bar 7
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="DominosActionButton", start = 85, last = 96}, --Bar 8
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="DominosActionButton", start = 97, last = 108},--Bar 9
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="DominosActionButton", start = 109,last = 120},--Bar 10
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="DominosActionButton", start = 121,last = 132},--Bar 11
{ actionPrefix = "MULTIACTIONBAR5BUTTON", buttonPrefix ="MultiBar5Button", start = 145,last = 156},--Bar 12
{ actionPrefix = "MULTIACTIONBAR6BUTTON", buttonPrefix ="MultiBar6Button", start = 157,last = 168},--Bar 13
{ actionPrefix = "MULTIACTIONBAR7BUTTON", buttonPrefix ="MultiBar7Button", start = 169,last = 180},--Bar 14
{ actionPrefix = "SHAPESHIFTBUTTON", buttonPrefix ="DominosStanceButton", start = 901,last = NUM_SHAPESHIFT+900},--Stance Bar. Dummy slots
}
local DominosOverrideActionPattern = "CLICK %s%s:HOTKEY"
local DominosOverrideButtonPrefix = "DominosActionButton"
local DominosOverrideSlotMap = {
{ start = 13, last = 24}, --Bar 2
{ start = 73, last = 84}, --Bar 7
{ start = 85, last = 96}, --Bar 8
{ start = 97, last = 108},--Bar 9
{ start = 109,last = 120},--Bar 10
{ start = 121,last = 132},--Bar 11
}
for _, info in ipairs(DominosActionSlotMap) do
for slot = info.start, info.last do
local index = slot - info.start + 1
local buttonName = info.buttonPrefix .. index
BindingByButton[buttonName] = info.actionPrefix .. index
UpdateButtonSpellID(buttonName)
local button = _G[buttonName]
if button and button.action then
AddButtonToSlot(buttonName, button.action)
end
end
end
OverrideBindingByButton = {}
for _, info in ipairs(DominosOverrideSlotMap) do
for slot = info.start, info.last do
local index = slot - info.start + 1
local buttonName = DominosOverrideButtonPrefix .. slot
OverrideBindingByButton[buttonName] = DominosOverrideActionPattern:format(DominosOverrideButtonPrefix,slot)
UpdateButtonSpellID(buttonName)
local button = _G[buttonName]
if button and button.action then
AddButtonToSlot(buttonName, button.action)
end
end
end
hooksecurefunc(Dominos.ActionButtons, "OnActionChanged", function(self, name, value, prevValue) OnActionChanged(self,_G[name], value) end)
elseif HasBartender then
local Bartender4ActionSlotMap = {
{ actionPrefix = "ACTIONBUTTON",id= true, buttonPrefix ="BT4Button", start = 1, last = 12}, --Bar 1
{ actionPrefix = "ACTIONBUTTON",id= true, buttonPrefix ="BT4Button", start = 13, last = 24}, --Bar 2
{ actionPrefix = "MULTIACTIONBAR3BUTTON", buttonPrefix ="BT4Button", start = 25, last = 36}, --Bar 3
{ actionPrefix = "MULTIACTIONBAR4BUTTON", buttonPrefix ="BT4Button", start = 37, last = 48}, --Bar 4
{ actionPrefix = "MULTIACTIONBAR2BUTTON", buttonPrefix ="BT4Button", start = 49, last = 60}, --Bar 5
{ actionPrefix = "MULTIACTIONBAR1BUTTON", buttonPrefix ="BT4Button", start = 61, last = 72}, --Bar 6
{ actionPrefix = "ACTIONBUTTON",id= true, buttonPrefix ="BT4Button", start = 73, last = 84}, --Bar 7
{ actionPrefix = "ACTIONBUTTON",id= true, buttonPrefix ="BT4Button", start = 85, last = 96}, --Bar 8
{ actionPrefix = "ACTIONBUTTON",id= true, buttonPrefix ="BT4Button", start = 97, last = 108},--Bar 9
{ actionPrefix = "ACTIONBUTTON",id= true, buttonPrefix ="BT4Button", start = 109,last = 120},--Bar 10
{ actionPrefix = "ACTIONBUTTON",id= true, buttonPrefix ="BT4Button", start = 121,last = 132},--Bar 11
{ actionPrefix = "MULTIACTIONBAR5BUTTON", buttonPrefix ="BT4Button", start = 145,last = 156},--Bar 13
{ actionPrefix = "MULTIACTIONBAR6BUTTON", buttonPrefix ="BT4Button", start = 157,last = 168},--Bar 14
{ actionPrefix = "MULTIACTIONBAR7BUTTON", buttonPrefix ="BT4Button", start = 169,last = 180},--Bar 15
{ actionPrefix = "SHAPESHIFTBUTTON", id=true, buttonPrefix ="BT4StanceButton", start = 901,last = NUM_SHAPESHIFT+900},--Stance Bar. Dummy slots
}
local Bartender4OverrideSlotMap = {
{ actionPattern = "CLICK %s%s:Keybind", buttonPrefix ="BT4Button", start = 1, last = 180}, --Action Bars
{ actionPattern = "CLICK %s%s:LeftButton", buttonPrefix ="BT4StanceButton", start = 901,last = NUM_SHAPESHIFT+900}, --Stance Bar. Dummy slots
}
for _, info in ipairs(Bartender4ActionSlotMap) do
for slot = info.start, info.last do
local id = slot - info.start + 1
local index = info.id and id or slot
local buttonName = info.buttonPrefix .. index
BindingByButton[buttonName] = info.actionPrefix .. id
UpdateButtonSpellID(buttonName)
local button = _G[buttonName]
if button and button.action then
AddButtonToSlot(buttonName, button.action)
end
end
end
OverrideBindingByButton = {}
for _, info in ipairs(Bartender4OverrideSlotMap) do
for slot = info.start, info.last do
local id = slot - info.start + 1
local index = slot < 900 and id or slot
local buttonName = info.buttonPrefix..index
OverrideBindingByButton[buttonName] = info.actionPattern:format(info.buttonPrefix, index)
UpdateButtonSpellID(buttonName)
local button = _G[buttonName]
if button and button.action then
AddButtonToSlot(buttonName, button.action)
end
end
end
LAB = LibStub("LibActionButton-1.0")
LAB.RegisterCallback(addon, "OnButtonUpdate", OnActionChanged)
elseif HasElvUI then
local ElvUIActionSlotMap = {
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ElvUI_Bar1Button", start = 1, last = 12}, --Bar 1
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ElvUI_Bar1Button", start = 13, last = 24}, --Bar 2
{ actionPrefix = "MULTIACTIONBAR3BUTTON", buttonPrefix ="ElvUI_Bar3Button", start = 25, last = 36}, --Bar 3
{ actionPrefix = "MULTIACTIONBAR4BUTTON", buttonPrefix ="ElvUI_Bar4Button", start = 37, last = 48}, --Bar 4
{ actionPrefix = "MULTIACTIONBAR2BUTTON", buttonPrefix ="ElvUI_Bar5Button", start = 49, last = 60}, --Bar 5
{ actionPrefix = "MULTIACTIONBAR1BUTTON", buttonPrefix ="ElvUI_Bar6Button", start = 61, last = 72}, --Bar 6
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ElvUI_Bar1Button", start = 73, last = 84}, --Bar 7
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ElvUI_Bar1Button", start = 85, last = 96}, --Bar 8
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ElvUI_Bar1Button", start = 97, last = 108},--Bar 9
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ElvUI_Bar1Button", start = 109,last = 120},--Bar 10
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ElvUI_Bar1Button", start = 121,last = 132},--Bar 11
{ actionPrefix = "MULTIACTIONBAR5BUTTON", buttonPrefix ="ElvUI_Bar13Button", start = 145,last = 156},--Bar 13
{ actionPrefix = "MULTIACTIONBAR6BUTTON", buttonPrefix ="ElvUI_Bar14Button", start = 157,last = 168},--Bar 14
{ actionPrefix = "MULTIACTIONBAR7BUTTON", buttonPrefix ="ElvUI_Bar15Button", start = 169,last = 180},--Bar 15
{ actionPrefix = "SHAPESHIFTBUTTON", buttonPrefix ="ElvUI_StanceBarButton", start = 901,last = NUM_SHAPESHIFT+900},--Stance Bar. Dummy slots
}
local ElvUIOverrideSlotMap = {
{ actionPrefix = "ELVUIBAR2BUTTON", buttonPrefix ="ElvUI_Bar2Button", start = 13, last = 24}, --Bar 2
{ actionPrefix = "ELVUIBAR7BUTTON", buttonPrefix ="ElvUI_Bar7Button", start = 73, last = 84}, --Bar 7
{ actionPrefix = "ELVUIBAR8BUTTON", buttonPrefix ="ElvUI_Bar8Button", start = 85, last = 96}, --Bar 8
{ actionPrefix = "ELVUIBAR9BUTTON", buttonPrefix ="ElvUI_Bar9Button", start = 97, last = 108},--Bar 9
{ actionPrefix = "ELVUIBAR10BUTTON", buttonPrefix ="ElvUI_Bar10Button", start = 109,last = 120},--Bar 10
}
for _, info in ipairs(ElvUIActionSlotMap) do
for slot = info.start, info.last do
local id = slot - info.start + 1
local buttonName = info.buttonPrefix .. id
BindingByButton[buttonName] = info.actionPrefix .. id
UpdateButtonSpellID(buttonName)
local button = _G[buttonName]
if button and button.action then
AddButtonToSlot(buttonName, button.action)
end
end
end
OverrideBindingByButton = {}
for _, info in ipairs(ElvUIOverrideSlotMap) do
for slot = info.start, info.last do
local id = slot - info.start + 1
local buttonName = info.buttonPrefix..id
OverrideBindingByButton[buttonName] = info.actionPrefix..id
UpdateButtonSpellID(buttonName)
local button = _G[buttonName]
if button and button.action then
AddButtonToSlot(buttonName, button.action)
end
end
end
LAB = LibStub("LibActionButton-1.0-ElvUI")
LAB.RegisterCallback(addon, "OnButtonUpdate", OnActionChanged)
else
local DefaultActionSlotMap = {
--Default UI Slot mapping https://warcraft.wiki.gg/wiki/Action_slot
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ActionButton", start = 1, last = 12}, --Action Bar 1 (Main Bar)
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ActionButton", start = 13, last = 24}, --Action Bar 1 (Page 2)
{ actionPrefix = "MULTIACTIONBAR3BUTTON", buttonPrefix ="MultiBarRightButton", start = 25, last = 36}, --Action Bar 4 (Right)
{ actionPrefix = "MULTIACTIONBAR4BUTTON", buttonPrefix ="MultiBarLeftButton", start = 37, last = 48}, --Action Bar 5 (Left)
{ actionPrefix = "MULTIACTIONBAR2BUTTON", buttonPrefix ="MultiBarBottomRightButton",start = 49, last = 60}, --Action Bar 3 (Bottom Right)
{ actionPrefix = "MULTIACTIONBAR1BUTTON", buttonPrefix ="MultiBarBottomLeftButton", start = 61, last = 72}, --Action Bar 2 (Bottom Left)
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ActionButton", start = 73, last = 84}, --Class Bar 1
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ActionButton", start = 85, last = 96}, --Class Bar 2
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ActionButton", start = 97, last = 108},--Class Bar 3
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ActionButton", start = 109,last = 120},--Class Bar 4
{ actionPrefix = "ACTIONBUTTON", buttonPrefix ="ActionButton", start = 121,last = 132},--Action Bar 1 (Skyriding)
{ actionPrefix = "MULTIACTIONBAR5BUTTON", buttonPrefix ="MultiBar5Button", start = 145,last = 156},--Action Bar 6
{ actionPrefix = "MULTIACTIONBAR6BUTTON", buttonPrefix ="MultiBar6Button", start = 157,last = 168},--Action Bar 7
{ actionPrefix = "MULTIACTIONBAR7BUTTON", buttonPrefix ="MultiBar7Button", start = 169,last = 180},--Action Bar 8
{ actionPrefix = "SHAPESHIFTBUTTON", buttonPrefix ="StanceButton", start = 901,last = NUM_SHAPESHIFT+900},--Stance Bar. Dummy slots
}
for _, info in ipairs(DefaultActionSlotMap) do
for slot = info.start, info.last do
local index = slot - info.start + 1
local buttonName = info.buttonPrefix .. index
BindingByButton[buttonName] = info.actionPrefix .. index
AddButtonToSlot(buttonName, slot)
UpdateButtonSpellID(buttonName)
end
end
EventRegistry:RegisterCallback("ActionButton.OnActionChanged", OnActionChanged)
end
return not HasBartender and not HasDominos and not HasElvUI
end
AssistedCombatIconMixin = {}
function AssistedCombatIconMixin:OnLoad()
self:RegisterEvent("PLAYER_LOGIN")
self:RegisterEvent("SPELLS_CHANGED")
self:RegisterEvent("SPELL_RANGE_CHECK_UPDATE")
self:RegisterEvent("SPELL_UPDATE_COOLDOWN")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
self:RegisterEvent("CVAR_UPDATE")
self:RegisterEvent("ROLE_CHANGED_INFORM")
self:RegisterEvent("GROUP_ROSTER_UPDATE")
self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
self:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
self:RegisterEvent("UNIT_ENTERED_VEHICLE")
self:RegisterEvent("UNIT_EXITED_VEHICLE")
self:RegisterEvent("NAME_PLATE_UNIT_ADDED")
self:RegisterEvent("NAME_PLATE_UNIT_REMOVED")
self:RegisterEvent("MODIFIER_STATE_CHANGED")
self:RegisterForDrag("LeftButton")
self.spellID = 61304
self.updateInterval = tonumber(C_CVar.GetCVar("assistedCombatIconUpdateRate")) or 0.25
self.isDefaultUI = true
self.lastTickTime = GetTime()
self.Keybind:SetParent(self.Overlay)
self.Count:SetParent(self.Overlay)
self.lockBtn:SetNormalTexture("Interface\\buttons\\lockbutton-unlocked-up")
self.lockBtn:SetPushedTexture("Interface\\buttons\\lockbutton-unlocked-down")
self.lockBtn:SetIgnoreParentAlpha(true)
self.lockBtn:SetScript("OnClick", function()
self:Lock(not self.db.locked)
if ACD.OpenFrames[addonName] then
ACR:NotifyChange(addonName)
end
DEFAULT_CHAT_FRAME:AddMessage(("|cff4cc9f0SACI|r: %s!"):format(self.db.locked and "Locked" or "Unlocked"))
end)
if Masque then
self:SetBackdrop({
edgeSize = 0,
})
local set = {}
for _, r in ipairs({ self:GetRegions() }) do
set[r] = true
end
self.__baselineRegions = set
self.MSQGroup = Masque:Group(addonTitle)
Masque:AddType("SACI", {"Icon", "Cooldown","HotKey"})
self.MSQGroup:AddButton(self,{
Icon = self.Icon,
Cooldown = self.Cooldown,
--HotKey = self.Keybind, --This doesn't work as a Frame. Looking into changing to a Button to make it work..
}, "SACI")
self.MSQGroup:RegisterCallback(function(Group, Option, Value)
if Option == "Disabled" and Value == true then
HideLikelyMasqueRegions(self)
end
self:ApplyOptions()
end)
end
end
function AssistedCombatIconMixin:OnAddonLoaded()
self.db = addon.db.profile
end
function AssistedCombatIconMixin:OnEvent(event, ...)
if event == "SPELL_UPDATE_COOLDOWN" then
self:UpdateCooldown()
elseif event == "SPELL_RANGE_CHECK_UPDATE" then
local spellID, inRange, checksRange = ...
if spellID ~= self.spellID then return end
self.spellOutOfRange = checksRange == true and inRange == false
elseif event == "MODIFIER_STATE_CHANGED" then
local key, down = ...
local success, isMouseOver = pcall(function() return self:IsMouseOver() end)
if not success then return end
if key == "LCTRL" or key == "RCTRL" then
if down == 1 and isMouseOver then
self.lockBtn:SetShown(true)
elseif down == 0 and self.lockBtn:IsShown() then
self.lockBtn:SetShown(false)
end
end
elseif event == "ACTIONBAR_SLOT_CHANGED" then
OnActionSlotChanged(...)
elseif event == "PLAYER_REGEN_ENABLED" and self.db.display.IN_COMBAT then
self:UpdateVisibility()
self:Update()
elseif event == "PLAYER_REGEN_DISABLED" and self.db.display.IN_COMBAT then
self:UpdateVisibility()
self:Update()
elseif event == "PLAYER_TARGET_CHANGED" then
if self.db.position.parentFrame == "__nameplate" then
self:UpdateAnchorPoint()
self:UpdateVisibility()
self:Update()
elseif self.db.display.HOSTILE_TARGET then
self:UpdateVisibility()
self:Update()
end
elseif event == "NAME_PLATE_UNIT_ADDED" or event == "NAME_PLATE_UNIT_REMOVED" then
if self.db.position.parentFrame == "__nameplate" and UnitIsUnit(..., "target") then
self:UpdateAnchorPoint()
self:UpdateVisibility()
self:Update()
end
elseif (event == "GROUP_ROSTER_UPDATE" or event == "PLAYER_SPECIALIZATION_CHANGED" or event == "ROLE_CHANGED_INFORM") and self.db.display.HideAsHealer then
self:UpdateVisibility()
self:Update()
elseif (event == "UNIT_ENTERED_VEHICLE" or event == "UNIT_EXITED_VEHICLE") and self.db.display.HideInVehicle then
if ... == "player" then
self:UpdateVisibility()
self:Update()
end
elseif event == "PLAYER_SPECIALIZATION_CHANGED" then
LoadRotationalSpells()
elseif event == "SPELLS_CHANGED" then
OnSpellsChanged()
elseif event == "PLAYER_LOGIN" then
LoadRotationalSpells()
self.isDefaultUI = LoadActionSlotMap()
self:ApplyOptions()
if self.db.enabled then
self:Start()
else
self:Stop()
end
elseif event == "CVAR_UPDATE" then
local arg1, arg2 = ...
if arg1 =="assistedCombatIconUpdateRate" then
self.updateInterval = tonumber(arg2) or self.updateInterval
end
end
end
function AssistedCombatIconMixin:Start()
addon:UpdateBroker()
if self.ticker or not self.db.enabled then return end
self.ticker = C_Timer.NewTicker(self.updateInterval,function()
self:Tick()
end)
end
function AssistedCombatIconMixin:Stop()
SafeSetShown(self,false)
addon:UpdateBroker()
if not self.ticker then return end
self.ticker:Cancel()
self.ticker = nil
end
function AssistedCombatIconMixin:IsTickerStalled()
return self.lastTickTime and (GetTime() - self.lastTickTime) > (self.updateInterval * 2)
end
function AssistedCombatIconMixin:Tick()
if not self.ticker then return end
self:UpdateVisibility()
if self:IsShown() then
local nextSpell = C_AssistedCombat.GetNextCastSpell(self.db.checkForVisibleButton and self.isDefaultUI)
if IsValidSpellID(nextSpell) and nextSpell ~= self.spellID then
C_Spell.EnableSpellRangeCheck(self.spellID, false)
self.spellID = nextSpell
self:UpdateCooldown()
end
end
self:Update()
self.lastTickTime = GetTime()
end
function AssistedCombatIconMixin:OnUpdate()
if self.db.position.parentFrame == "__cursor" then
self:UpdateAnchorPoint()
end
end
function AssistedCombatIconMixin:SetVisible(visibility)
SafeSetShown(self, visibility)
end
function AssistedCombatIconMixin:UpdateVisibility()
local db = self.db
local display = db.display
if not db.enabled then
SafeSetShown(self, false)
return
end
local parentFrame = db.position.parentFrame
if parentFrame == "__nameplate" then
local nameplate = C_NamePlate.GetNamePlateForUnit("target")
if not UnitCanAttack("player","target") or not nameplate then
SafeSetShown(self, false)
return
end
elseif parentFrame ~= "UIParent" and parentFrame ~= "__cursor" and db.position.InheritFrameVisibility then
local parent = _G[db.position.parent]
if parent and parent.IsVisible and parent.GetAlpha
and not (parent:IsVisible() and parent:GetAlpha() > 0) then
SafeSetShown(self, false)
return
end
end
if display.ALWAYS then
self:SetVisible(true)
return
end
if display.ONLY_ALL_CONDITIONS then
if (display.HOSTILE_TARGET and not UnitCanAttack("player", "anyenemy"))
or (display.HOSTILE_TARGET and UnitIsDead("target"))
or (display.IN_COMBAT and not InCombatLockdown())
or (display.HideInVehicle and C_PetBattles.IsInBattle())
or (display.HideInVehicle and UnitInVehicle("player"))
or (display.HideAsHealer and UnitGroupRolesAssigned("player") == "HEALER")
or (display.HideOnMount and IsMountedLocal())
then
self:SetVisible(false)
else
self:SetVisible(db.position.parentFrame ~= "__nameplate" or nameplate)
end
else
local show = (display.HOSTILE_TARGET and UnitCanAttack("player", "anyenemy") and not UnitIsDead("target"))
or (display.IN_COMBAT and InCombatLockdown())
or (not display.IN_COMBAT and not display.HOSTILE_TARGET)
local hide = (display.HideInVehicle and UnitInVehicle("player"))
or (display.HideInVehicle and C_PetBattles.IsInBattle())
or (display.HideAsHealer and UnitGroupRolesAssigned("player") == "HEALER")
or (display.HideOnMount and IsMountedLocal())
self:SetVisible(show and not hide
and (db.position.parentFrame ~= "__nameplate" or nameplate))
end
end
function AssistedCombatIconMixin:Update()
if not IsValidSpellID(self.spellID) or not self:IsShown() then return end
local db = self.db
local spellID = self.spellID
if db.locked then self:EnableMouse(false) end
local text = db.Keybind.show and GetKeyBindForSpellID(spellID) or ""
self.Keybind:SetText(text)
self.Icon:SetTexture(C_Spell.GetSpellTexture(spellID))
local isUsable, notEnoughMana = C_Spell.IsSpellUsable(spellID);
local needsRangeCheck = self.spellID and C_Spell.SpellHasRange(spellID);
if needsRangeCheck then
C_Spell.EnableSpellRangeCheck(spellID, true)
self.spellOutOfRange = C_Spell.IsSpellInRange(spellID) == false
else
self.spellOutOfRange = false
end
if self.spellOutOfRange then
self.Icon:SetVertexColor(Colors.NOT_IN_RANGE:GetRGBA());
elseif isUsable then
self.Icon:SetVertexColor(Colors.USABLE:GetRGBA());
elseif notEnoughMana then
self.Icon:SetVertexColor(Colors.NOT_ENOUGH_MANA:GetRGBA());
else
self.Icon:SetVertexColor(Colors.NOT_USABLE:GetRGBA());
end
end
function AssistedCombatIconMixin:ApplyOptions()
local db = self.db
self:Lock(db.locked)
self:SetSize(db.iconSize, db.iconSize)
self:SetAlpha(db.alpha)
self:UpdateAnchorPoint()
self:SetFrameStrata(frameStrata[db.position.strata])
self:Raise()
local kb = db.Keybind
self.Keybind:ClearAllPoints()
self.Keybind:SetPoint(kb.point, self, kb.point, kb.X, kb.Y)
self.Keybind:SetTextColor(kb.fontColor.r, kb.fontColor.g, kb.fontColor.b, kb.fontColor.a)
self.Keybind:SetFont(LSM:Fetch(LSM.MediaType.FONT, kb.font), kb.fontSize, kb.fontOutline and "OUTLINE" or "")
self.Cooldown:SetDrawEdge(self.db.cooldown.edge)
self.Cooldown:SetDrawBling(self.db.cooldown.bling)
self.Cooldown:SetHideCountdownNumbers(self.db.cooldown.HideNumbers)
self.Cooldown:SetEdgeTexture("Interface\\Cooldown\\UI-HUD-ActionBar-SecondaryCooldown")
self.Cooldown:SetSwipeColor(0, 0, 0)
local cc = db.cooldown.chargeCooldown.text
self.Count:ClearAllPoints()
self.Count:SetPoint(cc.point, self, cc.point, cc.X, cc.Y)
self.Count:SetTextColor(cc.fontColor.r, cc.fontColor.g, cc.fontColor.b, cc.fontColor.a)
self.Count:SetFont(LSM:Fetch(LSM.MediaType.FONT, cc.font), cc.fontSize, cc.fontOutline and "OUTLINE" or "")
self.chargeCooldown:SetDrawBling(false)
self.chargeCooldown:SetDrawEdge(self.db.cooldown.chargeCooldown.edge)
self.chargeCooldown:SetEdgeTexture("Interface\\Cooldown\\edge")
self.chargeCooldown:SetSwipeTexture("Interface\\Cooldown\\swipe")
if (not Masque) or (self.MSQGroup and self.MSQGroup.db.Disabled) then
local border = db.border
self.Icon:SetPoint("TOPLEFT", border.thickness, -border.thickness)
self.Icon:SetPoint("BOTTOMRIGHT", -border.thickness, border.thickness)
self.Icon:SetTexCoord(0.06,0.94,0.06,0.94)
self.Cooldown:SetPoint("TOPLEFT", border.thickness, -border.thickness)
self.Cooldown:SetPoint("BOTTOMRIGHT", -border.thickness, border.thickness)
self.chargeCooldown:SetPoint("TOPLEFT", border.thickness, -border.thickness)
self.chargeCooldown:SetPoint("BOTTOMRIGHT", -border.thickness, border.thickness)
self:SetBackdrop({
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = border.thickness,
})
self:SetBackdropBorderColor(border.color.r, border.color.g, border.color.b, border.show and 1 or 0)
else
self:ClearBackdrop()
self.Icon:ClearAllPoints()
self.Icon:SetAllPoints()
self.MSQGroup:ReSkin()
end
self:UpdateVisibility()
self:Update()
end
function AssistedCombatIconMixin:UpdateAnchorPoint()
local db = self.db
local uiScale = UIParent:GetEffectiveScale()
local point = db.position.point
local relativeTo = _G[db.position.parent] or UIParent
local relativePoint = db.position.relativePoint
local X = db.position.X / db.icon.scale
local Y = db.position.Y / db.icon.scale
if db.position.parentFrame == "__nameplate" then
local nameplate = C_NamePlate.GetNamePlateForUnit("target")
if nameplate and not nameplate:IsForbidden() and UnitCanAttack("player", "target") then
relativeTo = nameplate
end
elseif db.position.parentFrame == "__cursor" then
local cursorX, cursorY = GetCursorPosition()
X = ((cursorX / uiScale) / db.icon.scale) + db.position.X
Y = ((cursorY / uiScale) / db.icon.scale) + db.position.Y
relativeTo = UIParent
relativePoint = "BOTTOMLEFT"
self:EnableMouse(false)
end
self:ClearAllPoints()
self:SetScale(db.icon.scale)
self:SetPoint(point, relativeTo, relativePoint, X, Y)
end
function AssistedCombatIconMixin:UpdateCooldown()
if not IsValidSpellID(self.spellID) or not self:IsShown() then return end
local spellID = self.spellID
local cdInfo = self.db.cooldown.showSwipe and C_Spell.GetSpellCooldown(spellID)
local chargeInfo = self.db.cooldown.chargeCooldown.showSwipe and C_Spell.GetSpellCharges(spellID)
local chargeCount = self.db.cooldown.chargeCooldown.showCount and C_Spell.GetSpellCharges(spellID)
if cdInfo and cdInfo.isActive then
local cdDuration = C_Spell.GetSpellCooldownDuration(spellID)
self.Cooldown.currentCooldownType = COOLDOWN_TYPE_NORMAL
self.Cooldown:SetCooldownFromDurationObject(cdDuration)
else
self.Cooldown:Clear()
end
if chargeInfo and chargeInfo.isActive then
local chargeDuration = C_Spell.GetSpellChargeDuration(spellID)
self.chargeCooldown:SetCooldownFromDurationObject(chargeDuration)
else
self.chargeCooldown:Clear()
end
if chargeCount and chargeCount.maxCharges > 1 then
local charges = chargeCount.currentCharges or 0
self.Count:SetText(C_StringUtil.TruncateWhenZero(charges))
else
self.Count:SetText(nil)
end
end
function AssistedCombatIconMixin:Reload()
self:Stop()
self.db = addon.db.profile
self:ApplyOptions()
self:Start()
end
function AssistedCombatIconMixin:Lock(lock)
if self.db.position.parentFrame ~= "UIParent" then
self:SetMovable(false)
self.db.locked = true
return
end
self.db.locked = lock
self.lockBtn:SetNormalTexture(lock and "Interface\\buttons\\lockbutton-locked-up" or "Interface\\buttons\\lockbutton-unlocked-up")
self:SetMovable(not lock)
self:EnableMouse(not lock)
end
function AssistedCombatIconMixin:OnDragStart()
if self.db.locked or self.db.position.parentFrame ~= "UIParent" then return end
self:StartMoving()
end
function AssistedCombatIconMixin:OnDragStop()
self:StopMovingOrSizing()
local position = self.db.position
local point, relativeTo, relativePoint, xOfs, yOfs = self:GetPoint()
position.point = point
position.parent = "UIParent"
position.parentFrame = "UIParent"
position.relativePoint = relativePoint
position.X = math.floor(xOfs+0.5)
position.Y = math.floor(yOfs+0.5)
if ACD.OpenFrames[addonName] then
ACR:NotifyChange(addonName)
end
end
function AssistedCombatIconMixin:Debug()
for spellID in pairs(rotationalSpells) do
local spellInfo = C_Spell.GetSpellInfo(spellID)
local baseSpellID = C_SpellBook.FindBaseSpellByID(spellID)
local actions = {}
local slots = {}
local names = {}
local keybinds = {}
local icon = ""
if spellInfo and spellInfo.iconID then
icon = ("|T%d:16:16:0:0|t "):format(spellInfo.iconID)
end
local spellName = icon ..spellInfo.name
for buttonName, buttonSpellID in pairs(SpellIDByButton) do
if buttonSpellID == baseSpellID then
local binding = BindingByButton[buttonName] or OverrideBindingByButton[buttonName]
local button = _G[buttonName]
if button and button.action then
slots[#slots + 1] = tostring(button.action)
end
actions[#actions + 1] = tostring(binding)
keybinds[#keybinds + 1] = GetBindingForAction(binding)
names[#names + 1] = buttonName
end
end
local slot = table.concat(slots, ", ")
local action = table.concat(actions, ", ")
local name = table.concat(names, ", ")
local text = table.concat(keybinds,", ")
print(spellName, spellID, baseSpellID, "\n|cff4cc9f0 | Keybind:|r ", text, "\n|cff4cc9f0 | Action Slot:|r ", slot,"\n|cff4cc9f0 | Binding Action:|r ", action, "\n|cff4cc9f0 | Button Name:|r ", name)
end
if DevTool then
DevTool:ClearAllData()
DevTool:AddData(rotationalSpells,"SACI-rotationalSpells")
DevTool:AddData(SpellIDByButton,"SACI-SpellIDByButton")
DevTool:AddData(BindingByButton,"SACI-BindingByButton")
DevTool:AddData(OverrideBindingByButton,"SACI-OverrideBindingByButton")
DevTool:AddData(ButtonsBySlot,"SACI-ButtonsBySlot")