forked from MuffinManKen/AutoBar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
1297 lines (965 loc) · 34.8 KB
/
Core.lua
File metadata and controls
1297 lines (965 loc) · 34.8 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
--[[
Name: AutoBar
Author: Toadkiller of Proudmoore
Credits: Saien the original author. Sayclub (Korean), PDI175 (Chinese traditional and simplified), Teodred (German), Cinedelle (French), shiftos (Spanish)
Website: http://www.wowace.com/
Description: Dynamic 24 button bar automatically adds potions, water, food and other items you specify into a button for use. Does not use action slots so you can save those for spells and abilities.
--]]
--
-- Copyright 2004 - 2006 original author.
-- New Stuff Copyright 2006-2009 Toadkiller of Proudmoore.
-- New Stuff Copyright 2009- MuffinManKen
-- Maintained by MuffinManKen. Original author Saien of Hyjal
local ADDON_NAME = select(1, ...) ---@type string
local AB = select(2, ...)
local types = AB.types ---@class ABTypes
local code = AB.code ---@class ABCode
local _G = _G
local Masque = LibStub("Masque", true)
local AceCfgDlg = LibStub("AceConfigDialog-3.0")
local _
local L = AutoBarGlobalDataObject.locale
local AutoBar = AutoBar ---@type AutoBar
local ABGData = AutoBarGlobalDataObject
local tick = ABGData.TickScheduler
local ABSchedulerTickLength = 0.04
AB.events = {}
AutoBar.dockingFramesValidateList = {
["NONE"] = L["None"],
["BT3Bar1"] = L["AUTOBAR_CONFIG_BT3BAR"]..1,
["BT3Bar2"] = L["AUTOBAR_CONFIG_BT3BAR"]..2,
["BT3Bar3"] = L["AUTOBAR_CONFIG_BT3BAR"]..3,
["BT3Bar4"] = L["AUTOBAR_CONFIG_BT3BAR"]..4,
["BT3Bar6"] = L["AUTOBAR_CONFIG_BT3BAR"]..6,
["BT3Bar10"] = L["AUTOBAR_CONFIG_BT3BAR"]..10,
["MainMenuBarArtFrame"] = L["AUTOBAR_CONFIG_DOCKTOMAIN"],
["ChatFrame1"] = L["AUTOBAR_CONFIG_DOCKTOCHATFRAME"],
["ChatFrameMenuButton"] = L["AUTOBAR_CONFIG_DOCKTOCHATFRAMEMENU"],
["MainMenuBar"] = L["AUTOBAR_CONFIG_DOCKTOACTIONBAR"],
["CharacterMicroButton"] = L["AUTOBAR_CONFIG_DOCKTOMENUBUTTONS"],
}
AutoBar.dockingFrames = {
["NONE"] = {
text = L["None"],
offset = { x = 0, y = 0, point = "CENTER", relative = "TOPLEFT" },
},
["BT3Bar1"] = {
text = L["AUTOBAR_CONFIG_BT3BAR"]..1,
offset = { x = 0, y = 0, point = "CENTER", relative = "TOPLEFT" },
},
["BT3Bar2"] = {
text = L["AUTOBAR_CONFIG_BT3BAR"]..2,
offset = { x = 0, y = 0, point = "CENTER", relative = "TOPLEFT" },
},
["BT3Bar3"] = {
text = L["AUTOBAR_CONFIG_BT3BAR"]..3,
offset = { x = 0, y = 0, point = "CENTER", relative = "TOPLEFT" },
},
["BT3Bar4"] = {
text = L["AUTOBAR_CONFIG_BT3BAR"]..4,
offset = { x = 0, y = 0, point = "CENTER", relative = "BOTTOMLEFT" },
},
["BT3Bar6"] = {
text = L["AUTOBAR_CONFIG_BT3BAR"]..6,
offset = { x = 0, y = 0, point = "CENTER", relative = "TOPLEFT" },
},
["BT3Bar10"] = {
text = L["AUTOBAR_CONFIG_BT3BAR"]..10,
offset = { x = 0, y = 0, point = "CENTER", relative = "TOPLEFT" },
},
["MainMenuBarArtFrame"] = {
text = L["AUTOBAR_CONFIG_DOCKTOMAIN"],
offset = { x = 0, y = 0, point = "CENTER", relative = "TOPRIGHT" },
},
["ChatFrame1"] = {
text = L["AUTOBAR_CONFIG_DOCKTOCHATFRAME"],
offset = { x = 0, y = 25, point = "CENTER", relative = "TOPLEFT" },
},
["ChatFrameMenuButton"] = {
text = L["AUTOBAR_CONFIG_DOCKTOCHATFRAMEMENU"],
offset = { x = 0, y = 25, point = "CENTER", relative = "TOPLEFT" },
},
["MainMenuBar"] = {
text = L["AUTOBAR_CONFIG_DOCKTOACTIONBAR"],
offset = { x = 7, y = 40, point = "CENTER", relative = "TOPLEFT" },
},
["CharacterMicroButton"] = {
text = L["AUTOBAR_CONFIG_DOCKTOMENUBUTTONS"],
offset = { x = 0, y = 0, point = "CENTER", relative = "BOTTOMLEFT" },
},
}
-- Single parent for key binding overides, and event handling
AutoBar.frame = CreateFrame("Frame", "AutoBarEventFrame", UIParent)
AutoBar.frame:SetScript("OnEvent",
function(_self, event, ...)
-- The BAG_UPDATE event is now trivial in its execution; it just sets a boolean so don't throttle it
-- PLAYER_ENTERING_WORLD runs before the throttling stuff is set up and doesn't need it anyway
if(event == "BAG_UPDATE" or event == "PLAYER_ENTERING_WORLD") then
AB.events[event]( ...)
return
end
--If it's a GET_ITEM_INFO_RECEIVED and there aren't any items we don't know, ignore it
if(event == "GET_ITEM_INFO_RECEIVED" and not AutoBar.missing_items) then
return
end
if(AutoBarDB2.settings.throttle_event_limit > 0) then
local timer_name = event .. "_last_tick"
local now = GetTime()
AutoBar[timer_name] = AutoBar[timer_name] or 0
if ((now - AutoBar[timer_name]) < AutoBarDB2.settings.throttle_event_limit) then
if (AutoBarDB2.settings.log_throttled_events) then print (" AutoBar Skipping " .. event .. "(" .. AutoBar[timer_name] .. ", " .. now .. ")", ...) end
return
end
AutoBar[timer_name] = now
end
AB.events[event]( ...)
end)
AutoBar.frame:RegisterEvent("PLAYER_ENTERING_WORLD")
-- Process a macro to determine what its "action" is:
-- a spell
-- an item
function AB.GetActionForMacroBody(p_macro_body)
--local debug = false
local action
local tooltip
local icon
--if debug then print("Finding icon for", p_macro_body); end;
--print(debugstack())
local show_action = string.match(p_macro_body, "#show%s+([^\n]+)")
if(show_action) then
action = show_action
--if debug then print("show_action:", show_action); end;
else
local show_tt_action = string.match(p_macro_body, "#showtooltip%s+([^\n]+)")
if(show_tt_action) then
--if debug then print("show_tt_action:", show_tt_action); end;
action = show_tt_action
tooltip = select(2, GetItemInfo(action)) or AB.GetSpellLink(action)
--if debug then print(" ", show_tt_action,tooltip); end;
end
end
if(not action) then
local cast_action = string.match(p_macro_body, "/cast%s+([^\n]+)")
local use_action = string.match(p_macro_body, "/use%s+([^\n]+)")
if(cast_action or use_action) then
action = SecureCmdOptionParse(cast_action or use_action)
--if there are qualifiers on the action (like [mounted]) and they all parse away, it returns null
if(action) then
tooltip = select(2, GetItemInfo(action)) or AB.GetSpellLink(action)
end
end
end
if(action) then
icon = select(3, GetSpellInfo(action)) or code.GetIconForItemID(action)
end
return action, icon, tooltip
end
function AutoBar:IsInLockDown()
return self.inCombat or InCombatLockdown() or (C_PetBattles and C_PetBattles.IsInBattle()) or (UnitInVehicle and UnitInVehicle("player"))
end
-- This function needs to be globally accessible for Bindings.xml
function AutoBar.ConfigToggle()
if (not InCombatLockdown()) then
AutoBar:OpenOptions()
end
end
function AutoBar:InitializeZero()
AutoBar.player_faction_name = UnitFactionGroup("player")
AutoBar.currentPlayer = UnitName("player") .. " - " .. GetRealmName();
_, AutoBar.CLASS = UnitClass("player")
AutoBar.NiceClass = string.sub(AutoBar.CLASS, 1, 1) .. string.lower(string.sub(AutoBar.CLASS, 2))
AutoBar.version = AB.GetAddOnMetadata(ADDON_NAME, "Version")
AutoBar.InitializeDB()
AutoBar:InitializeOptions()
AutoBar.Initialize()
AB.UpdateCategories()
AB.RegisterOverrideBindings()
AutoBar.frame:RegisterEvent("UPDATE_BINDINGS")
AutoBar.frame:RegisterEvent("BAG_UPDATE")
AutoBar.frame:RegisterEvent("BAG_UPDATE_DELAYED")
AutoBar.frame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
AutoBar.frame:RegisterEvent("LEARNED_SPELL_IN_TAB")
AutoBar.frame:RegisterUnitEvent("UNIT_SPELLCAST_SUCCEEDED", "player")
if(AutoBarDB2.settings.handle_spell_changed) then
AutoBar.frame:RegisterEvent("SPELLS_CHANGED")
end
AutoBar.frame:RegisterEvent("ACTIONBAR_UPDATE_USABLE")
AutoBar.frame:RegisterEvent("QUEST_ACCEPTED")
if (ABGData.is_mainline_wow) then
AutoBar.frame:RegisterEvent("COMPANION_LEARNED")
AutoBar.frame:RegisterEvent("QUEST_LOG_UPDATE")
AutoBar.frame:RegisterEvent("TOYS_UPDATED")
end
-- For item use restrictions
AutoBar.frame:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
AutoBar.frame:RegisterEvent("PLAYER_ALIVE")
AutoBar.frame:RegisterUnitEvent("UNIT_AURA", "player")
AutoBar.frame:RegisterEvent("PLAYER_CONTROL_GAINED")
AutoBar.frame:RegisterEvent("PLAYER_REGEN_ENABLED")
AutoBar.frame:RegisterEvent("PLAYER_REGEN_DISABLED")
AutoBar.frame:RegisterEvent("PLAYER_UNGHOST")
AutoBar.frame:RegisterEvent("BAG_UPDATE_COOLDOWN")
AutoBar.frame:RegisterEvent("SPELL_UPDATE_COOLDOWN")
AutoBar.frame:RegisterEvent("UPDATE_BATTLEFIELD_STATUS")
AutoBar.frame:RegisterEvent("GET_ITEM_INFO_RECEIVED")
AB.LibKeyBound.RegisterCallback(self, "LIBKEYBOUND_ENABLED")
AB.LibKeyBound.RegisterCallback(self, "LIBKEYBOUND_DISABLED")
AB.LibKeyBound.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED")
AB.LibStickyFrames.RegisterCallback(self, "OnSetGroup")
AB.LibStickyFrames.RegisterCallback(self, "OnClick")
-- AB.LibStickyFrames.RegisterCallback(self, "OnStartFrameMoving")
AB.LibStickyFrames.RegisterCallback(self, "OnStopFrameMoving")
AB.LibStickyFrames.RegisterCallback(self, "OnStickToFrame")
end
-- Will not update if set during combat
function AB.RegisterOverrideBindings()
AB.LogEventStart("RegisterOverrideBindings")
ClearOverrideBindings(AutoBar.frame)
for buttonKey, _buttonDB in pairs(AutoBar.buttonDBList) do
AutoBar.Class.Button:UpdateBindings(buttonKey, buttonKey .. "Frame")
end
AB.LogEventEnd("RegisterOverrideBindings")
end
function AB.events.GET_ITEM_INFO_RECEIVED(p_item_id)
AB.LogEventStart("GET_ITEM_INFO_RECEIVED")
--print("GET_ITEM_INFO_RECEIVED", p_item_id, GetItemInfo(p_item_id))
AB.ClearMissingItemFlag();
AB.ABScheduleUpdate(tick.UpdateItemsID)
AB.LogEventEnd("GET_ITEM_INFO_RECEIVED", p_item_id)
end
-- Given an item link, this adds the item to the given category
-- NOTE: No effort is made to avoid adding an item that as already been added. As long as the list is small, this isn't worth worrying about.
local function add_item_to_dynamic_category(p_item_link, p_category_name)
local debug_me = false
local category = AutoBarCategoryList[p_category_name]
if(debug_me) then code.log_warning("Adding", p_item_link, " to ", p_category_name, code.Dump(category.items, 1)); end;
local item_name, item_id = AutoBar.ItemLinkDecode(p_item_link)
category.items[#category.items + 1] = item_id
if(debug_me) then code.log_warning(item_name, item_id, "Num Items:", #category.items); end;
end
function AB.events.QUEST_ACCEPTED(p_arg1, p_arg2)
AB.LogEventStart("QUEST_ACCEPTED", p_arg1, p_arg2)
-- At some point, the event payload was changed from (Index, ID) to (ID, null)
local quest_idx
if (p_arg2) then
quest_idx = p_arg1
else
quest_idx = code.GetLogIndexForQuestID(p_arg1)
end
code.log_warning("QUEST_ACCEPTED"," Idx:", quest_idx)
if(quest_idx) then
local link = GetQuestLogSpecialItemInfo(quest_idx)
code.log_warning(" ", link)
if(link) then
add_item_to_dynamic_category(link, "Dynamic.Quest")
AB.ABScheduleUpdate(tick.UpdateItemsID)
end
end
AB.LogEventEnd("QUEST_ACCEPTED", p_arg1, p_arg2)
end
if (ABGData.is_mainline_wow) then
function AB.events.QUEST_LOG_UPDATE(p_arg1)
AB.LogEventStart("QUEST_LOG_UPDATE")
code.log_warning("QUEST_LOG_UPDATE"," Idx:", p_arg1)
--Make sure we're in the world. Should always be the case, but stuff loads in odd orders
if(AutoBar.inWorld and AutoBarCategoryList["Dynamic.Quest"]) then
local num_entries, _num_quests = AB.GetNumQuestLogEntries() --TODO: Remove this after Shadowlands and Classic no longer need the shim
for i = 1, num_entries do
local link = GetQuestLogSpecialItemInfo(i)
if(link) then
code.log_warning(" ", link)
add_item_to_dynamic_category(link, "Dynamic.Quest")
AB.ABScheduleUpdate(tick.UpdateItemsID)
end
end
end
AB.LogEventEnd("QUEST_LOG_UPDATE", p_arg1)
end
function AB.events.COMPANION_LEARNED()
local need_update = false;
AB.LogEventStart("COMPANION_LEARNED")
local button = AutoBar.buttonList["AutoBarButtonMount"]
if (button) then
button:Refresh(button.parentBar, button.buttonDB, true)
end
if(need_update) then
AB.ABScheduleUpdate(tick.UpdateCategoriesID);
end
AB.LogEventEnd("COMPANION_LEARNED")
end
function AB.events.TOYS_UPDATED(p_item_id, p_new)
AB.LogEventStart("TOYS_UPDATED")
if(false) then code.log_warning("|nTOYS_UPDATED", p_item_id, p_new); end
if(p_item_id == nil or p_new == true) then
AB.ABScheduleUpdate(tick.UpdateItemsID)
end
AB.LogEventEnd("TOYS_UPDATED", p_item_id, p_new)
end
end
function AB.events.PLAYER_ENTERING_WORLD()
code.log_warning("* PLAYER_ENTERING_WORLD")
--UIParentLoadAddOn("Blizzard_DebugTools")
--UIParentLoadAddOn("Blizzard_EventTrace")
if (not AutoBar.initialized) then
AutoBar:InitializeZero();
AutoBar.initialized = true;
end
if (not AutoBar.inWorld) then
AutoBar.inWorld = true;
AutoBarDB2.whatsnew_version = MUFFIN_WHATS_NEW_QUEUE.AddConditionalEntry({
addon_name = ADDON_NAME,
text = AB.WHATSNEW_TEXT,
version = AutoBarDB2.whatsnew_version,
force_show = false,
})
MUFFIN_WHATS_NEW_QUEUE.Show()
end
if(AutoBarDB2.settings.hack_PetActionBarFrame and PetActionBarFrame) then
PetActionBarFrame:EnableMouse(false);
end
AutoBar.frame:UnregisterEvent("PLAYER_ENTERING_WORLD")
AB.ABScheduleUpdate(tick.UpdateCategoriesID);
C_Timer.After(ABSchedulerTickLength, AutoBar.ABSchedulerTick)
end
function AB.events.PLAYER_LEAVING_WORLD()
AutoBar.inWorld = false;
end
function AB.events.BAG_UPDATE(p_bag_idx)
AB.LogEventStart("BAG_UPDATE")
if (AutoBar.inWorld and p_bag_idx <= NUM_BAG_SLOTS) then
AutoBarSearch:MarkBagDirty(p_bag_idx)
end
AB.LogEventEnd("BAG_UPDATE", p_bag_idx)
end
function AB.events.BAG_UPDATE_DELAYED()
AB.LogEventStart("BAG_UPDATE_DELAYED")
if (InCombatLockdown()) then
for _button_name, button in pairs(AutoBar.buttonList) do
button:UpdateCount()
end
else
AB.ABScheduleUpdate(tick.UpdateItemsID)
end
AB.LogEventEnd("BAG_UPDATE_DELAYED")
end
function AB.events.PLAYER_EQUIPMENT_CHANGED()
AB.LogEventStart("PLAYER_EQUIPMENT_CHANGED")
AutoBarSearch:MarkInventoryDirty()
AB.ABScheduleUpdate(tick.UpdateItemsID)
AB.LogEventEnd("PLAYER_EQUIPMENT_CHANGED")
end
function AB.events.BAG_UPDATE_COOLDOWN(p_arg1)
AB.LogEventStart("BAG_UPDATE_COOLDOWN")
for _button_name, button in pairs(AutoBar.buttonList) do
button:UpdateCooldown()
end
AB.LogEventEnd("BAG_UPDATE_COOLDOWN", p_arg1)
end
function AB.events.SPELL_UPDATE_COOLDOWN(arg1)
AB.LogEventStart("SPELL_UPDATE_COOLDOWN")
for _button_name, button in pairs(AutoBar.buttonList) do
button:UpdateCooldown()
end
AB.LogEventEnd("SPELL_UPDATE_COOLDOWN", arg1)
end
function AB.events.ACTIONBAR_UPDATE_USABLE(p_arg1)
AB.LogEventStart("ACTIONBAR_UPDATE_USABLE")
if (InCombatLockdown()) then
for _button_name, button in pairs(AutoBar.buttonList) do
button:UpdateUsable()
end
else
AB.ABScheduleUpdate(tick.UpdateObjectsID)
end
AB.LogEventEnd("ACTIONBAR_UPDATE_USABLE", p_arg1)
end
function AB.events.UPDATE_SHAPESHIFT_FORMS(p_arg1)
AB.LogEventStart("UPDATE_SHAPESHIFT_FORMS")
if (InCombatLockdown()) then
for _button_name, button in pairs(AutoBar.buttonList) do
button:UpdateUsable()
end
end
AB.ABScheduleUpdate(tick.UpdateSpellsID)
AB.LogEventEnd("UPDATE_SHAPESHIFT_FORMS", p_arg1)
end
function AB.events.UPDATE_BINDINGS()
AB.LogEventStart("UPDATE_BINDINGS")
AB.RegisterOverrideBindings()
AB.ABScheduleUpdate(tick.UpdateButtonsID)
AB.LogEventEnd("UPDATE_BINDINGS")
end
function AB.events.LEARNED_SPELL_IN_TAB(p_arg1)
AB.LogEventStart("LEARNED_SPELL_IN_TAB")
AB.ABScheduleUpdate(tick.UpdateSpellsID)
AB.LogEventEnd("LEARNED_SPELL_IN_TAB", p_arg1)
end
function AB.events.UNIT_SPELLCAST_SUCCEEDED(p_unit, p_guid, p_spell_id)
AB.LogEventStart("UNIT_SPELLCAST_SUCCEEDED")
assert(p_unit == "player")
AB.ABScheduleUpdate(tick.UpdateSpellsID)
AB.LogEventEnd("UNIT_SPELLCAST_SUCCEEDED", p_unit, p_guid, p_spell_id)
end
function AB.events.SPELLS_CHANGED(p_arg1)
AB.LogEventStart("SPELLS_CHANGED")
if(AutoBarDB2.settings.handle_spell_changed) then
AB.ABScheduleUpdate(tick.UpdateSpellsID)
end
AB.LogEventEnd("SPELLS_CHANGED", p_arg1)
end
function AB.events.PLAYER_CONTROL_GAINED(p_arg1)
AB.LogEventStart("PLAYER_CONTROL_GAINED")
AB.ABScheduleUpdate(tick.UpdateButtonsID)
AB.LogEventEnd("PLAYER_CONTROL_GAINED", p_arg1)
end
function AB.events.PLAYER_REGEN_ENABLED(p_arg1)
AB.LogEventStart("PLAYER_REGEN_ENABLED")
AutoBar.inCombat = nil
AB.LogEventEnd("PLAYER_REGEN_ENABLED", p_arg1)
end
function AB.events.PLAYER_REGEN_DISABLED(p_arg1)
AB.LogEventStart("PLAYER_REGEN_DISABLED")
AutoBar.inCombat = true
if (InCombatLockdown()) then
print("AutoBar PLAYER_REGEN_DISABLED called while InCombatLockdown")
end
if (AutoBar.moveButtonsMode) then
AutoBar:MoveButtonsModeOff()
AB.LibKeyBound:Deactivate()
end
if (AutoBar.keyBoundMode) then
AB.LibKeyBound:Deactivate()
end
AB.UpdateActive()
AceCfgDlg:Close("AutoBar")
AB.LogEventEnd("PLAYER_REGEN_DISABLED", p_arg1)
end
function AB.events.PLAYER_ALIVE(p_arg1)
AB.LogEventStart("PLAYER_ALIVE")
AB.ABScheduleUpdate(tick.UpdateButtonsID)
AB.LogEventEnd("PLAYER_ALIVE", p_arg1)
end
function AB.events.UNIT_AURA(p_arg1)
AB.LogEventStart("UNIT_AURA")
if (AutoBar:IsInLockDown()) then
for _button_name, button in pairs(AutoBar.buttonList) do
button:UpdateUsable()
end
else
AB.ABScheduleUpdate(tick.UpdateButtonsID)
end
AB.LogEventEnd("UNIT_AURA", p_arg1)
end
function AB.events.PLAYER_UNGHOST(p_arg1)
AB.LogEventStart("PLAYER_UNGHOST")
AB.ABScheduleUpdate(tick.UpdateButtonsID)
AB.LogEventEnd("PLAYER_UNGHOST", p_arg1)
end
function AB.events.UPDATE_BATTLEFIELD_STATUS()
AB.LogEventStart("UPDATE_BATTLEFIELD_STATUS")
if (AutoBar.inWorld) then
local bgStatus = false
local max_battlefield_id = GetMaxBattlefieldID()
for i = 1, max_battlefield_id do
local _status, _map_name, instance_id = GetBattlefieldStatus(i);
if (instance_id ~= 0) then
bgStatus = true
break
end
end
if (AutoBar.inBG ~= bgStatus) then
AutoBar.inBG = bgStatus
AB.ABScheduleUpdate(tick.UpdateActiveID)
end
end
AB.LogEventEnd("UPDATE_BATTLEFIELD_STATUS")
end
-- When dragging, contains { frameName, index }, otherwise nil
AutoBar.dragging = nil;
local draggingData = {};
function AutoBar.GetDraggingIndex(frameName)
if (AutoBar.dragging and AutoBar.dragging.frameName == frameName) then
return AutoBar.dragging.index;
end
return nil;
end
function AutoBar.SetDraggingIndex(frameName, index)
draggingData.frameName = frameName;
draggingData.index = index;
AutoBar.dragging = draggingData;
end
function AutoBar.ItemLinkDecode(link)
if (link) then
local id, name = string.match(link,"item:(%d+):.+%[(.*)%]")
if (id and name) then
return name, tonumber(id)
end
end
end
-- Initialize
-- All Initialization
-- UpdateCategories
-- Based on the current db, add or remove Custom Categories
-- UpdateCustomBars
-- Based on the current db, add or remove Custom Bars
-- UpdateCustomButtons
-- Based on the current db, add or remove Custom Buttons
-- UpdateSpells
-- Rescan all registered spells
-- This is on a less frequent cycle than UpdateScan. Called on leveling or spellbook changes.
-- ToDo: Also trigger on spec changes
-- UpdateObjects
-- Based on the current db, instantiate or refresh Bars, Buttons
-- Move disabled Bars, Buttons to cold storage, & thaw out re-enabled ones
-- This is done on Initialize and on Configuration changes
-- Could be triggered by events (Boss specific categories for instance)
-- UpdateRescan
-- Rescan all bags and inventory from scratch based on current Buttons and their Categories
-- UpdateScan
-- Scan all bags and inventory based on current Buttons and their Categories
-- Triggered by bag & inventory changes, combat end
-- UpdateAttributes
-- Based on the current Scan results, update the Button and Popup Attributes
-- Create Popup Buttons as needed
-- UpdateActive
-- Based on the current Scan results, Bars and their Buttons, determine the active Buttons
-- UpdateButtons
-- Based on the active Bars and their Buttons display them
-- Triggered by events
-- ToDo: Mmm Styles callback should be pulled out of the hierarchy
function AutoBar.Initialize()
AB.LogEventStart("AutoBar:Initialize")
-- Set AutoBar Skin
if (Masque and not AutoBar.MasqueGroup) then
local group = Masque:Group("AutoBar")
AutoBar.MasqueGroup = group
group.SkinID = AutoBarDB2.skin.SkinID or "Blizzard"
group.Gloss = AutoBarDB2.skin.Gloss
group.Backdrop = AutoBarDB2.skin.Backdrop
group.Colors = AutoBarDB2.skin.Colors or {}
end
AB.InitializeAllCategories()
AB.UpdateCustomCategories()
AutoBarSearch:Initialize()
AB.LogEventEnd("AutoBar:Initialize")
end
--
-- Bar & Button drag locking / unlocking and key binding modes
--
function AutoBar:ColorAutoBar()
for _i, bar in pairs(self.barList) do
if (bar.sharedLayoutDB.enabled) then
bar:ColorBars()
end
end
end
function AutoBar:LIBKEYBOUND_ENABLED()
self:MoveBarModeOff()
self:MoveButtonsModeOff()
self.keyBoundMode = true
self:ColorAutoBar()
end
function AutoBar:LIBKEYBOUND_DISABLED()
self.keyBoundMode = nil
self:ColorAutoBar()
end
function AutoBar:LIBKEYBOUND_MODE_COLOR_CHANGED()
self:ColorAutoBar()
end
function AutoBar:MoveBarModeToggle()
--print("AutoBar:MoveBarModeToggle")
if (AB.LibStickyFrames:GetGroup()) then
AutoBar:MoveBarModeOff()
else
AutoBar:MoveBarModeOn()
end
end
function AutoBar:MoveBarModeOff()
AB.LibStickyFrames:SetGroup(nil)
AutoBar.stickyMode = false
end
function AutoBar:MoveBarModeOn()
AB.LibKeyBound:Deactivate()
AutoBar:MoveButtonsModeOff()
AB.LibStickyFrames:SetGroup(true)
AutoBar.stickyMode = true
end
function AutoBar.OnSetGroup(group)
--print("AutoBar.SetStickyMode stickyMode " .. tostring(stickyMode))
AutoBar.stickyMode = false
if (group == true) then
AutoBar.stickyMode = true
elseif (type(group) == "table") then
for _, bar in pairs(AutoBar.barList) do
if (bar.sharedLayoutDB.enabled and AB.LibStickyFrames:InFrameGroup(bar.frame, group)) then
AutoBar.stickyMode = true
break
end
end
end
end
function AutoBar.OnClick(_self, _event, frame, button)
--print("AutoBar.Class.Bar.OnClick frame " .. tostring(frame) .. " button " .. tostring(button) .. " lolwut " .. tostring(lolwut))
local bar = frame.class
if (bar and bar.sharedLayoutDB) then
if (button == "LeftButton") then
--print("AutoBar.Class.Bar.OnClick ToggleVisibilty frame " .. tostring(frame) .. " button " .. tostring(button))
bar:ToggleVisibilty()
--elseif (button == "RightButton") then
--print("AutoBar.Class.Bar.OnClick ShowBarOptions frame " .. tostring(frame) .. " button " .. tostring(button))
--bar:ShowBarOptions()
end
end
end
--[[
function AutoBar:OnStartFrameMoving()
--print("AutoBar.OnStartFrameMoving")
end
--]]
function AutoBar.OnStopFrameMoving(_self, _event, frame, point, stickToFrame, stickToPoint, stickToX, stickToY)
local bar = frame.class
if (bar and bar.sharedPositionDB) then
--print("AutoBar:OnStopFrameMoving " .. tostring(bar.barName) .. " frame " .. tostring(frame) .. " point " .. tostring(point) .. " stickToFrame " .. tostring(stickToFrame) .. " stickToPoint " .. tostring(stickToPoint))
bar:StickTo(frame, point, stickToFrame, stickToPoint, stickToX, stickToY)
bar:PositionSave()
end
end
function AutoBar.OnStickToFrame(_self, _event, frame, point, stickToFrame, stickToPoint, stickToX, stickToY)
local bar = frame.class
--print("AutoBar:OnStickToFrame " .. tostring(bar.barName) .. " frame " .. tostring(frame) .. " point " .. tostring(point) .. " stickToFrame " .. tostring(stickToFrame) .. " stickToPoint " .. tostring(stickToPoint))
if (bar and bar.sharedPositionDB) then
bar:StickTo(frame, point, stickToFrame, stickToPoint, stickToX, stickToY)
bar:PositionSave()
end
end
function AutoBar:MoveButtonsModeToggle()
if AutoBar.moveButtonsMode then
AutoBar:MoveButtonsModeOff()
else
AutoBar:MoveButtonsModeOn()
end
end
function AutoBar:MoveButtonsModeOn()
AutoBar:MoveBarModeOff()
AB.LibKeyBound:Deactivate()
AutoBar.moveButtonsMode = true
for _, bar in pairs(self.barList) do
if (bar.sharedLayoutDB.enabled) then
bar:MoveButtonsModeOn()
end
end
AB.UpdateActive()
end
function AutoBar:MoveButtonsModeOff()
AutoBar.moveButtonsMode = nil
for _, bar in pairs(self.barList) do
if bar.sharedLayoutDB.enabled then
bar:MoveButtonsModeOff()
end
end
AB.UpdateActive()
end
--
-- ConfigMode support
--
-- Create the global table if it does not exist yet
CONFIGMODE_CALLBACKS = CONFIGMODE_CALLBACKS or {}
-- Declare our handler
CONFIGMODE_CALLBACKS["AutoBar"] = function(action)
if (action == "ON") then
AutoBar:MoveBarModeOn()
elseif (action == "OFF") then
AutoBar:MoveBarModeOff()
end
end
--
-- Drag and Drop support
--
-- Retrieve last object dragged from
function AutoBar:GetDraggingObject()
return self.fromObject
end
-- Record last object dragged from
function AutoBar:SetDraggingObject(fromObject)
self.fromObject = fromObject
end
--/dump AutoBarDB2.account.barList["AutoBarClassBarBasic"].buttonKeys[16]
--/dump AutoBar.moveButtonsMode
--/script AutoBarDB2.settings.log_events = true
--/script AutoBarDB2.settings.log_events = false
--/script LibStub("LibKeyBound-1.0"):SetColorKeyBoundMode(0.75, 1, 0, 0.5)
--/script DEFAULT_CHAT_FRAME:AddMessage("" .. tostring())
--/print GetMouseFocus():GetName()
function AutoBar.Print(_self, ...)
print(...)
end
local StupidLogEnabled = false
function AutoBar:StupidLogEnable(p_toggle)
StupidLogEnabled = p_toggle
end
function AutoBar:StupidLog(p_text)
if (StupidLogEnabled) then
AutoBarDB2.stupidlog = AutoBarDB2.stupidlog .. p_text
end
end
function AutoBar:DumpWarningLog()
if next(AutoBar.warning_log) == nil then --Empty log
return
end
AutoBar:Print("Warnings/Errors occured in AutoBar:")
for _i, v in ipairs(AutoBar.warning_log) do
AutoBar:Print(v)
end
end
function AutoBar:LoggedGetSpellInfo(p_spell_id, p_spell_name)
local ret_val = {GetSpellInfo(p_spell_id)} --table-ify
if next(ret_val) == nil then
code.log_warning("Invalid Spell ID:" .. p_spell_id .. " : " .. (p_spell_name or "Unknown"));
end
return unpack(ret_val)
end
function AutoBar:DebugItemCategory(p_category_name)
print("Category name:", p_category_name)
local pt_set = LibStub("LibPeriodicTable-3.1"):GetSetTable(p_category_name)
local set_size = AutoBar:tcount(pt_set) - 1 --PTSets have a "set" member which is the set name
print("Size of PT Set:", set_size)
local items = AutoBarCategoryList[p_category_name].items
local item_size = AutoBar:tcount(items)
print("# Category Items:", item_size)
if(item_size) then
local diff_set = AutoBar:SetDifference(pt_set, items)
print("In PT, but not in items:", table.concat(diff_set, ","))
diff_set = AutoBar:SetDifference(items, pt_set)
print("In items, but not in PT:", table.concat(diff_set, ","))
end
end
--/dump LibStub("LibPeriodicTable-3.1"):GetSetTable("Muffin.Flask")
--/dump AutoBarCategoryList["Muffin.Flask"].castList
--/dump AutoBarCategoryList["Muffin.Flask"].items
--/dump /run AutoBar:DebugItemCategory("Muffin.Flask")
-- tcount: count table members even if they're not indexed by numbers
function AutoBar:tcount(p_table)
if(p_table == nil) then return nil; end
local n = #p_table
if (n == 0) then
for _k in pairs(p_table) do
n = n + 1;
end
end