-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAutoBarClassButton.lua
More file actions
1088 lines (945 loc) · 32.4 KB
/
AutoBarClassButton.lua
File metadata and controls
1088 lines (945 loc) · 32.4 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
--
-- AutoBarClassButton
-- Copyright 2007+ Toadkiller of Proudmoore.
-- A lot of code borrowed from Bartender3
--
-- Layout Buttons for AutoBar
-- Buttons are contained by AutoBar.Class.Bar
-- http://muffinmangames.com
--
local _, AB = ...
local types = AB.types ---@class ABTypes
local code = AB.code ---@class ABCode
local AutoBar = AutoBar
local ABGData = AutoBarGlobalDataObject
local Class = AutoBar.Class.new_class
local L = AutoBarGlobalDataObject.locale
local Masque = LibStub("Masque", true)
local _
local _G = _G
local print, select, assert, ipairs, pairs, tonumber, strmatch = print, select, assert, ipairs, pairs, tonumber, strmatch
-- Basic Button with textures, highlighting, keybindText, tooltips etc.
AutoBar.Class.Button = Class(AutoBar.Class.BasicButton)
local function onAttributeChangedFunc(button)
local self = button.class
self:UpdateButton()
end
local function onDragStartFunc(button)
local fromObject = button.class
if (AutoBar.moveButtonsMode) then
ClearCursor()
SetCursor("BUY_CURSOR")
AutoBar:SetDraggingObject(fromObject)
fromObject:SetDragCursor()
else
local buttonDB = AutoBar:GetButtonDB(fromObject.buttonDB.buttonKey)
--print("onDragStartFunc", fromObject.buttonName, "arg1", arg1, "arg2", arg2, "buttonDB.drag", buttonDB.drag)
if (buttonDB.drag) then
ClearCursor()
AutoBar:SetDraggingObject(nil)
fromObject:SetDragCursor()
end
end
end
local function onReceiveDragFunc(button)
local toObject = button.class
--print("onReceiveDragFunc " .. tostring(toObject.buttonName) .. " arg1 " .. tostring(arg1) .. " arg2 " .. tostring(arg2))
toObject:DropObject()
SetCursor(nil)
end
local function OnUpdateFunc(button, elapsed)
local self = button.class
self.elapsed = self.elapsed + elapsed
if (self.elapsed > 0.2) then
self:OnUpdate(self.elapsed)
self.elapsed = 0
end
end
function AutoBar.Class.Button:init(parentBar, buttonDB)
AutoBar.Class.Button.super.init(self)
self.showgrid = 0
self.flashing = 0
self.flashtime = 0
self.outOfRange = nil
self.elapsed = 0
self.action = 0
self.parentBar = parentBar
self.buttonDB = buttonDB
if (self.buttonDB.square_popups == nil) then
self.buttonDB.square_popups = true
end
self.buttonName = buttonDB.buttonKey
self.buttonDBIndex = buttonDB.order
self:CreateButtonFrame()
self:Refresh(parentBar, buttonDB)
end
-- Refresh the category list
function AutoBar.Class.Button:Refresh(parentBar, buttonDB)
local debug = false --(buttonDB.buttonKey == "AutoBarButtonQuest")
if(debug) then code.log_warning("AB.C.Button.proto.Refresh", self.buttonName, self.buttonDB.hasCustomCategories, #self.buttonDB) end
self.parentBar = parentBar
if (buttonDB ~= self.buttonDB) then
self.buttonDB = buttonDB
assert(self.buttonName == buttonDB.buttonKey, "AutoBar.Class.Button:Refresh Button Name changed")
self.buttonDBIndex = buttonDB.order
end
self.buttonName = buttonDB.buttonKey
if (self.buttonDB.hasCustomCategories) then
for categoryIndex, categoryKey in ipairs(self.buttonDB) do
self[categoryIndex] = categoryKey
end
-- Clear out excess if any
for i = # self.buttonDB + 1, # self, 1 do
self[i] = nil
end
end
end
-- Disable the Button
function AutoBar.Class.Button:Disable()
-- self.frame:SetAttribute("category", nil)
-- self.frame:SetAttribute("itemId", nil)
-- self.frame:Hide()
--print("AutoBar.Class.Button:Disable " .. tostring(self.buttonName))
end
-- Return the name of the global frame of the button. Keybinds are made to it.
function AutoBar.Class.Button:GetButtonFrameName()
return self.buttonDB.buttonKey .. "Frame"
end
function AutoBar.Class.Button:GetButtonBinding()
return self.buttonDB.buttonKey .. "_X"
end
--
-- LibKeyBound Handlers
--
function AutoBar.Class.Button:GetHotkey()
local frame = self
local key1 = GetBindingKey(frame.class.buttonName .. "_X")
local key = AB.LibKeyBound:ToShortKey(key1)
--print("AutoBar.Class.Button:GetHotkey key1 " .. tostring(key1) .. " -> " .. tostring(key))-- .. " buttonName " .. tostring(frame.class.buttonName))
return key
end
function AutoBar.Class.Button:GetActionName()
local frame = self
local buttonKey = frame.class.buttonDB.buttonKey
return (L[buttonKey] or "???") .. " (" .. frame.class:GetButtonFrameName() .. ")"
end
function AutoBar.Class.Button:SetKey(key)
local button = self.class
local buttonKey = button.buttonDB.buttonKey
local buttonFrameName = button:GetButtonFrameName()
if (key) then
-- SetOverrideBindingClick(AutoBar.frame, false, key, buttonFrameName)
local buttonBinding = button:GetButtonBinding()
if (buttonBinding) then
--print("AutoBar.Class.Button:SetKey buttonBinding " .. tostring(buttonBinding) .. " -> " .. tostring(key))-- .. " buttonName " .. tostring(frame.class.buttonName))
SetBinding(key, buttonBinding)
--print("AutoBar.Class.Button:SetKey buttonBinding " .. tostring(buttonBinding) .. " <- " .. tostring(GetBindingKey(buttonBinding)))-- .. " buttonName " .. tostring(frame.class.buttonName))
end
button:BindingsUpdate()
end
end
function AutoBar.Class.Button:ClearBindings()
local button = self.class
local buttonFrameName = button:GetButtonFrameName()
local buttonBinding = button:GetButtonBinding()
while GetBindingKey(buttonBinding) do
SetBinding(GetBindingKey(buttonBinding), nil)
end
button:BindingsUpdate()
end
function AutoBar.Class.Button:GetBindings()
local button = self.class
local buttonBinding = button:GetButtonBinding()
local keys
if (buttonBinding) then
for i = 1, select('#', GetBindingKey(buttonBinding)) do
local hotKey = select(i, GetBindingKey(buttonBinding))
if keys then
keys = keys .. ', ' .. GetBindingText(hotKey, 'KEY_')
else
keys = GetBindingText(hotKey, 'KEY_')
end
end
end
return keys
end
--/dump _G["AutoBarButtonTrinket2_X"]
function AutoBar.Class.Button:BindingsUpdate()
local buttonFrameName = self:GetButtonFrameName()
local buttonBinding = self:GetButtonBinding()
for i = 1, select('#', GetBindingKey(buttonBinding)) do
local hotKey = select(i, GetBindingKey(buttonBinding))
--print("AutoBar.Class.Button:BindingsUpdate hotKey " .. tostring(hotKey) .. " buttonFrameName " .. tostring(buttonFrameName))
SetOverrideBindingClick(AutoBar.frame, false, hotKey, buttonFrameName)
end
--print("AutoBar.Class.Button:BindingsUpdate -> buttonFrameName " .. tostring(buttonFrameName))
self:UpdateHotkeys()
end
-- Update the keybinds for the Button.
-- Copied from Bartender3
-- Create Override Bindings from the Blizzard bindings to our dummy binds in Bindings.xml.
-- These do not clash with the real frames to bind to, so all is happy.
function AutoBar.Class.Button:UpdateBindings(buttonName, buttonFrameName)
local key1, key2 = GetBindingKey(buttonName .. "_X")
if (key1) then
--print("AutoBar.Class.Button:UpdateBindings key1 " .. tostring(key1) .. " key2 " .. tostring(key2) .. " buttonName " .. tostring(buttonName))
SetOverrideBindingClick(AutoBar.frame, false, key1, buttonFrameName)
end
if (key2) then
SetOverrideBindingClick(AutoBar.frame, false, key2, buttonFrameName)
end
end
--[[
/script SetOverrideBindingClick(AutoBarButtonTrinket1Frame, false, "U", "AutoBarButtonTrinket1Frame")
/script ClearOverrideBindings(AutoBarButtonTrinket1Frame)
/script AutoBarButtonTrinket2Frame.class:UpdateHotkeys()
/dump AutoBarButtonTrinket2Frame:GetScript("OnUpdate")
--]]
local function funcOnEnter(self)
if (self.GetHotkey and AutoBar.keyBoundMode) then
AB.LibKeyBound:Set(self)
end
local noTooltip = not (AutoBarDB2.settings.show_tooltip and self.needsTooltip or AutoBar.moveButtonsMode)
noTooltip = noTooltip or (InCombatLockdown() and not AutoBarDB2.settings.show_tooltip_in_combat)
if (noTooltip) then
self.UpdateTooltip = nil
GameTooltip:Hide()
else
AutoBar.Class.BasicButton.TooltipShow(self)
end
end
local function funcOnLeave(self)
GameTooltip:Hide()
end
function AutoBar.Class.Button:CreateButtonFrame()
local name = self:GetButtonFrameName()
local frame = CreateFrame("Button", name, self.parentBar.frame, "ActionButtonTemplate, SecureActionButtonTemplate, SecureHandlerBaseTemplate")
self.frame = frame
frame:ClearAllPoints()
frame:SetWidth(ABGData.default_button_width)
frame:SetHeight(ABGData.default_button_height)
-- Support selfcast and focuscast
frame:SetAttribute("checkselfcast", true)
frame:SetAttribute("checkfocuscast", true)
frame.class = self
frame:SetMouseClickEnabled()
if (AutoBarGlobalDataObject.is_mainline_wow or ABGData.is_bcc_wow) then
frame:RegisterForClicks("AnyUp", "AnyDown")
else
frame:RegisterForClicks("AnyUp")
end frame:RegisterForDrag("LeftButton", "RightButton")
frame:SetScript("OnUpdate", OnUpdateFunc)
frame:SetScript("OnEnter", funcOnEnter)
frame:SetScript("OnLeave", funcOnLeave)
RegisterStateDriver(frame, "visibility", AutoBar.visibility_driver_string)
--- frame:SetScript("OnAttributeChanged", onAttributeChangedFunc)
frame:SetScript("OnDragStart", onDragStartFunc)
frame:SetScript("OnReceiveDrag", onReceiveDragFunc)
--- frame:SetScript("PostClick", self.PostClick)
frame.icon = _G[("%sIcon"):format(name)]
frame.border = _G[("%sBorder"):format(name)]
frame.cooldown = _G[("%sCooldown"):format(name)]
frame.macroName = _G[("%sName"):format(name)]
frame.hotKey = _G[("%sHotKey"):format(name)]
frame.count = _G[("%sCount"):format(name)]
frame.flash = _G[("%sFlash"):format(name)]
if (Masque) then
local group = self.parentBar.frame.MasqueGroup
frame.MasqueButtonData = {
Border = frame.border,
Cooldown = frame.cooldown,
Count = frame.count,
Flash = frame.flash,
HotKey = frame.hotKey,
Icon = frame.icon,
Name = frame.macroName,
}
group:AddButton(frame, frame.MasqueButtonData)
end
frame.normalTexture = frame:GetNormalTexture()
local frameStrata = AutoBar.barLayoutDBList[self.parentBar.barKey].frameStrata
frame:SetFrameStrata(frameStrata)
frame.GetHotkey = AutoBar.Class.Button.GetHotkey
frame.GetActionName = AutoBar.Class.Button.GetActionName
frame.SetKey = AutoBar.Class.Button.SetKey
frame.ClearBindings = AutoBar.Class.Button.ClearBindings
frame.GetBindings = AutoBar.Class.Button.GetBindings
if frame.Arrow then
frame.Arrow:Hide()
end
self:UpdateButton()
self:EventsEnable()
end
-- Handle a click on a popped up button
function AutoBar.Class.Button.OnClick(object, button, down)
local self = object.class
--print("OnClick " .. self.buttonName .. " " .. tostring(object) .. " object.class " .. tostring(object.class) .. " button " .. tostring(button) .. " down " .. tostring(down))
if (down) then
object:SetChecked(1)
return true
else
object:SetChecked(0)
end
end
-- For a given itemId, find and shuffle stacks of it to targetBag, targetSlot
-- Return true if successful
-- Return nil if not
function AutoBar.Class.Button:ShuffleItem(itemId, targetBag, targetSlot, isNewItem)
local _, itemCount, _locked = GetContainerItemInfo(targetBag, targetSlot)
local totalCount = code.GetItemCount(itemId)
if (not itemCount and totalCount > 0) then
AutoBarSearch:ScanBagsInCombat()
end
-- if (isNewItem) then
--print("ShuffleItem isNewItem " .. " itemId " .. tostring(itemId) .. " itemCount " .. tostring(itemCount) .. " locked " .. tostring(locked))
-- end
if ((itemCount == 1 and totalCount > 1) or (not itemCount and totalCount > 0) or (isNewItem and totalCount > 0)) then
-- Shuffle in another stack
local index = AutoBarSearch.found:GetTotalSlots(itemId)
--print("ShuffleItem start index " .. tostring(self.class.buttonName) .. " itemId " .. tostring(itemId) .. " index " .. tostring(index))
if (index and index > 0) then
repeat
local bag, slot, spell = AutoBarSearch.found:GetItemData(itemId, index)
--print("ShuffleItem checking index " .. tostring(index) .. " bag " .. tostring(bag) .. " slot " .. tostring(slot) .. " spell " .. tostring(spell))
if (bag and slot) then
local _, itemCount, locked = GetContainerItemInfo(bag, slot)
if (itemCount and itemCount > 0) then
ClearCursor()
PickupContainerItem(bag, slot)
PickupContainerItem(targetBag, targetSlot)
AutoBarSearch.found:ClearItemData(itemId, index)
--print("ShuffleItem actually swapped index " .. tostring(index) .. " bag " .. tostring(bag) .. " slot " .. tostring(slot) .. " locked " .. tostring(locked) .. " targetBag " .. tostring(targetBag) .. " targetSlot " .. tostring(targetSlot))
return true
end
end
index = index - 1
--print("ShuffleItem done with index " .. tostring(index) .. " bag " .. tostring(bag) .. " slot " .. tostring(slot) .. " spell " .. tostring(spell))
until index <= 0
else
-- Redo scan for item only then call ShuffleItem again
end
return true
elseif (totalCount == 1) then
-- Redo scan for item only then call ShuffleItem again
end
-- Nothing left to shuffle in
return nil
end
-- For a given itemId, find and shuffle stacks of it to targetBag, targetSlot
-- Return true if successful
-- Return nil if not
--TODO: Is this ever called???
function AutoBar.Class.Button:SwitchItem(buttonItemId, targetBag, targetSlot)
local popupHeader = self.frame.popupHeader
if (popupHeader) then
for _, popupButton in pairs(popupHeader.popupButtonList) do
local frame = popupButton.frame
local itemType = self.frame:GetAttribute("type")
if (itemType == "item") then
local itemId = frame:GetAttribute("itemId")
local isUsable = code.IsUsableItem(itemId)
if (isUsable) then
-- It is usable so we have some in inventory so switch
local didShuffle = AutoBar.Class.Button:ShuffleItem(itemId, targetBag, targetSlot, true)
if (didShuffle) then
local texture
texture = code.GetIconForItemID(tonumber(itemId))
self.frame.icon:SetTexture(texture)
texture = code.GetIconForItemID(tonumber(buttonItemId))
frame.icon:SetTexture(texture)
return true
-- self:UpdateButton()
-- popupButton:UpdateButton()
end
end
end
end
end
return false
end
-- Handle shuffle buttons
function AutoBar.Class.Button:PostClick(mouseButton, down)
local self = self.class
if (self.buttonDB.shuffle and InCombatLockdown()) then
local itemType = self.frame:GetAttribute("type")
if (itemType == "item") then
local itemId = self.frame:GetAttribute("itemId")
local itemLink = self.frame:GetAttribute("item")
local targetBag, targetSlot = strmatch(itemLink, "^(%d+)%s+(%d+)$")
if (IsConsumableItem(itemId) and targetBag and targetSlot) then
local didShuffle = AutoBar.Class.Button:ShuffleItem(itemId, targetBag, targetSlot)
if (not didShuffle) then
--print("\nAutoBar.Class.PopupButton.prototype:PostClick did not shuffle, switchItem itemId " .. tostring(itemId) .. " targetBag " .. tostring(targetBag) .. " targetSlot " .. tostring(targetSlot))
-- Switch to next item
--[[local didSwitch = ]] self:SwitchItem(itemId, targetBag, targetSlot)
--print("\nAutoBar.Class.PopupButton.prototype:PostClick didSwitch " .. tostring(didSwitch) .. " targetBag " .. tostring(targetBag) .. " targetSlot " .. tostring(targetSlot))
end
end
end
end
end
-- /dump AutoBarSearch.found:GetTotalSlots(2723)
-- /dump AutoBarSearch.found:GetList()[2723]
-- /dump IsUsableItem(2723) Pinot Noir
-- /dump IsUsableItem(32902) Bottled Nethergon
-- /dump IsUsableItem("1 6")
local borderMoveActive = {r = 0, g = 1.0, b = 0, a = 1.0}
local borderMoveDisabled = {r = 1.0, g = 0, b = 0, a = 1.0}
local borderMoveEmpty = {r = 0, g = 0, b = 1.0, a = 1.0}
-- Returns Icon texture, borderColor
-- Nil borderColor hides border
function AutoBar.Class.Button:GetIconTexture()
local frame = self.frame
local texture, borderColor = AutoBar.Class.Button.super.GetIconTexture(self, frame)
local category = frame:GetAttribute("category")
if (AutoBar.moveButtonsMode) then
if (texture) then
borderColor = borderMoveActive
else
if (category and AutoBarCategoryList[category]) then
texture = AutoBarCategoryList[category].texture
borderColor = borderMoveEmpty
else
texture = "Interface\\Icons\\INV_Misc_Gift_01"
borderColor = borderMoveDisabled
end
end
elseif ((AutoBarDB2.settings.show_empty_buttons or self.buttonDB.alwaysShow) and not texture) then
if (category and AutoBarCategoryList[category]) then
texture = AutoBarCategoryList[category].texture
end
end
return texture, borderColor
end
--/script AutoBar.buttonList["AutoBarButtonTrinket1"].frame.icon:SetTexture("Interface\\Buttons\\UI-Quickslot2")
--/script AutoBar.buttonList["AutoBarButtonTrinket1"].frame.icon:SetTexture("Interface\\Icons\\INV_Misc_QirajiCrystal_05")
--/dump AutoBar.buttonList["AutoBarButtonTrinket1"].frame.icon:GetTexture()
--/script AutoBar.buttonList["AutoBarButtonTrinket1"]:UpdateIcon()
function AutoBar.Class.Button:UpdateIcon()
local frame = self.frame
local texture, borderColor = self:GetIconTexture()
if (texture) then
frame.icon:SetTexture(texture)
frame.icon:Show()
frame.tex = texture
else
-- frame:Hide()
end
if (borderColor) then
frame.border:SetVertexColor(borderColor.r, borderColor.g, borderColor.b, borderColor.a)
frame.border:Show()
else
frame.border:Hide()
end
end
function AutoBar.Class.Button:UpdateButton()
local frame = self.frame
self:UpdateIcon()
self:UpdateCount()
self:UpdateHotkeys()
local itemType = frame:GetAttribute("type")
if (AutoBar.moveButtonsMode) then
self:ShowButton()
elseif (itemType) then
self:UpdateUsable()
self:UpdateCooldown()
self:ShowButton()
frame:SetScript("OnUpdate", OnUpdateFunc)
else
frame:SetScript("OnUpdate", nil)
frame.cooldown:Hide()
self:HideButton()
end
if (AutoBar.moveButtonsMode) then
frame.macroName:SetText(AB.GetButtonDisplayName(self.buttonDB))
-- elseif self.parentBar.sharedLayoutDB.showMacrotext then
-- frame.macroName:SetText(GetActionText(self.action))
else
frame.macroName:SetText("")
end
local buttonDB = self.buttonDB
if (buttonDB.drop) then
frame:RegisterEvent("ACTIONBAR_SHOWGRID")
frame:RegisterEvent("ACTIONBAR_HIDEGRID")
else
frame:UnregisterEvent("ACTIONBAR_SHOWGRID")
frame:UnregisterEvent("ACTIONBAR_HIDEGRID")
end
end
function AutoBar.Class.Button:UpdateHotkeys()
if (AutoBarDB2.settings.show_hotkey) then
self.frame.hotKey:Show()
else
self.frame.hotKey:Hide()
end
local frame = self.frame
local buttonBinding = self:GetButtonBinding()
local key
if (buttonBinding) then
key = GetBindingKey(buttonBinding)
else
key = AB.LibKeyBound.Binder:GetBindings(frame)
end
if (key) then
frame.hotKey:SetText(AB.LibKeyBound:ToShortKey(GetBindingText(key, "KEY_", 1)))
else
frame.hotKey:SetText("")
end
end
-- Set cooldown for the button and popups if any
function AutoBar.Class.Button:UpdateCooldown()
AutoBar.Class.Button.super.UpdateCooldown(self)
local popupHeader = self.frame.popupHeader
if (popupHeader) then
for _, popupButton in pairs(popupHeader.popupButtonList) do
popupButton:UpdateCooldown()
end
end
end
--/script local start, duration, enabled = AB.GetSpellCooldown("Summon Water Elemental", BOOKTYPE_SPELL); print("start " .. tostring(start) .. " duration " .. tostring(duration) .. " enabled " .. tostring(enabled))
-- Set count for the button and popups if any
function AutoBar.Class.Button:UpdateCount()
AutoBar.Class.Button.super.UpdateCount(self)
if (AutoBarDB2.settings.show_count) then
local popupHeader = self.frame.popupHeader
if (popupHeader) then
for _, popupButton in pairs(popupHeader.popupButtonList) do
popupButton:UpdateCount()
end
end
end
end
function AutoBar.Class.Button:UpdateUsable()
local itemType = self.frame:GetAttribute("type")
local category = self.frame:GetAttribute("category")
if (itemType) then
AutoBar.Class.Button.super.UpdateUsable(self)
local popupHeader = self.frame.popupHeader
if (popupHeader) then
for _, popupButton in pairs(popupHeader.popupButtonList) do
popupButton:UpdateUsable()
end
end
elseif (category and (AutoBar.moveButtonsMode or AutoBarDB2.settings.show_empty_buttons or self.buttonDB.alwaysShow)) then
self.frame.icon:SetVertexColor(0.4, 0.4, 0.4, 1)
end
end
--[[
/script AutoBar.buttonList["AutoBarButtonQuest"].frame.icon:SetVertexColor(1.0, 1.0, 1.0)
/dump AutoBar.buttonList["AutoBarButtonTrinket1"].frame.hotKey:SetVertexColor(1.0, 1.0, 1.0)
--]]
--/dump AutoBar.buttonList["AutoBarButtonCat"]:IsActive()
function AutoBar.Class.Button:IsActive()
local debug_me = false; --("AutoBarButtonPets" == self.buttonName)
if (debug_me) then print("AutoBar.Class.Button:IsActive", self.buttonName); end;
if (not self.buttonDB.enabled) then
return false
end
if (AutoBarDB2.settings.show_empty_buttons or AutoBar.moveButtonsMode or self.buttonDB.alwaysShow or AutoBar.keyBoundMode) then
return true
end
local itemType = self.frame:GetAttribute("type")
if (itemType) then
if (debug_me) then print("AutoBar.Class.Button:IsActive itemId ", self.frame:GetAttribute("itemId"), "itemtype:", itemType); end;
local category = self.frame:GetAttribute("category")
local categoryInfo = AutoBarCategoryList[category]
if (categoryInfo and categoryInfo.battleground and not AutoBar.inBG) then
return false
end
local count = 0
if (itemType == "item") then
local itemId = self.frame:GetAttribute("itemId") or 1
count = code.GetItemCount(tonumber(itemId)) or 0
if (count == 0) then
local sortedItems = AutoBarSearch.sorted:GetList(self.buttonName)
if (sortedItems) then
local noPopup = self.buttonDB.noPopup
local nItems = # sortedItems
if (nItems > 1 and not noPopup) then
count = 1
--print("AutoBar.Class.Button:IsActive nItems " .. tostring(nItems))
end
end
if (self.frame:GetAttribute("type2") == "spell") then
count = 1
end
end
elseif (itemType == "spell") then
local sortedItems = AutoBarSearch.sorted:GetList(self.buttonName)
if(sortedItems) then
count = #sortedItems
end
elseif (itemType == "toy") then
local sortedItems = AutoBarSearch.sorted:GetList(self.buttonName)
if(sortedItems) then
count = #sortedItems
end
elseif (itemType == "macro") then
if (self.macroActive) then
count = 1
end
end
return count > 0
elseif (self.macroTexture) then
return true
else
return false
end
end
local function FindSpell(spellName, bookType)
local s
local found = false;
for i = 1, MAX_SKILLLINE_TABS do
local name, _, offset, numSpells = GetSpellTabInfo(i)
if (not name) then
break
end
for s = offset + 1, offset + numSpells do
local spell = GetSpellBookItemName(s, bookType)
if (spell == spellName) then
found = true
end
if (found and spell ~=spellName) then
return s-1
end
end
end
if (found) then
return s
end
return nil
end
-- Set Cursor based on the type settings
function AutoBar.Class.Button:SetDragCursor()
local itemType = self.frame:GetAttribute("type")
if (itemType) then
if (itemType == "item") then
local itemLink = self.frame:GetAttribute("item")
PickupItem(itemLink)
elseif (itemType == "action") then
local action = self.frame:GetAttribute("action1")
PickupAction(action)
elseif (itemType == "macro") then
local macroIndex = self.frame:GetAttribute("macro")
PickupMacro(macroIndex)
elseif (itemType == "spell") then
local spellName = self.frame:GetAttribute("spell")
PickupSpellBookItem(spellName)
end
end
end
local ATTACK_BUTTON_FLASH_TIME = ATTACK_BUTTON_FLASH_TIME
function AutoBar.Class.Button:OnUpdate(elapsed)
if (not self.frame.tex) then
self:UpdateIcon()
end
if ( self.flashing == 1 ) then
self.flashtime = self.flashtime - elapsed;
if ( self.flashtime <= 0 ) then
local overtime = -self.flashtime;
if ( overtime >= ATTACK_BUTTON_FLASH_TIME ) then
overtime = 0;
end
self.flashtime = ATTACK_BUTTON_FLASH_TIME - overtime;
local flashTexture = self.frame.flash
if ( flashTexture:IsVisible() ) then
flashTexture:Hide()
else
flashTexture:Show()
end
end
end
local frame = self.frame
local itemType = frame:GetAttribute("type")
local inRange = 1
if (itemType == "item") then
local itemId = frame:GetAttribute("itemId")
if (ItemHasRange(itemId)) then
inRange = IsItemInRange(itemId, "target")
end
elseif (itemType == "spell") then
local spellName = frame:GetAttribute("spell")
if (SpellHasRange(spellName)) then
inRange = IsSpellInRange(spellName, "target")
end
end
if (frame.outOfRange ~= (inRange == 0)) then
frame.outOfRange = not frame.outOfRange
print(frame:GetName(), frame.outOfRange)
self:UpdateUsable()
end
if (not self.updateTooltip) then
return
end
self.updateTooltip = self.updateTooltip - elapsed
if (self.updateTooltip > 0) then
return
end
end
function AutoBar.Class.Button:StartFlash()
self.flashing = 1
self.flashtime = 0
end
function AutoBar.Class.Button:StopFlash()
self.flashing = 0
self.frame.flash:Hide()
end
function AutoBar.Class.Button:ShowButton()
if (Masque) then
local frame = self.frame
local backdrop, gloss = Masque:GetBackdrop(frame), Masque:GetGloss(frame)
if (backdrop) then
backdrop:Show()
end
if (gloss) then
gloss:Show()
end
local popupHeader = frame.popupHeader
if (popupHeader) then
for _, popupButton in pairs(popupHeader.popupButtonList) do
frame = popupButton.frame
if (backdrop) then
backdrop:Show()
end
if (gloss) then
gloss:Show()
end
end
end
end
end
function AutoBar.Class.Button:HideButton()
local frame = self.frame
if (Masque) then
local backdrop, gloss = Masque:GetBackdrop(self), Masque:GetGloss(self)
if (backdrop) then
backdrop:Hide()
end
if (gloss) then
gloss:Hide()
end
local popupHeader = frame.popupHeader
if (popupHeader) then
for _, popupButton in pairs(popupHeader.popupButtonList) do
frame = popupButton.frame
local backdrop, gloss = Masque:GetBackdrop(frame), Masque:GetGloss(frame)
if (backdrop) then
backdrop:Hide()
end
if (gloss) then
gloss:Hide()
end
end
end
end
end
function AutoBar.Class.Button:ShowGrid(override)
-- local frame = self.frame
-- if not override then
-- self.showgrid = self.showgrid + 1
-- end
-- frame.icon:Hide()
-- frame.normalTexture:Show()
end
function AutoBar.Class.Button:HideGrid(override)
-- local frame = self.frame
-- if (not override) then
-- self.showgrid = self.showgrid - 1
-- end
-- local itemType = self.frame:GetAttribute("type")
-- if (self.showgrid == 0 and not itemType) then
-- if (not self.parentBar.sharedLayoutDB.showGrid) then
-- frame.normalTexture:Hide()
-- end
-- end
-- frame.icon:Show()
end
function AutoBar.Class.Button:MoveButtonsModeOn()
local frame = self.frame
frame:SetScript("OnDragStart", onDragStartFunc)
frame:SetScript("OnReceiveDrag", onReceiveDragFunc)
frame.macroName:SetText(AB.GetButtonDisplayName(self.buttonDB))
frame:Show()
end
function AutoBar.Class.Button:MoveButtonsModeOff()
local frame = self.frame
frame:SetScript("OnDragStart", nil)
frame:SetScript("OnReceiveDrag", nil)
frame.macroName:SetText("")
frame.menu = nil
if (self.buttonDB.hide or self.parentBar.sharedLayoutDB.hide) then
frame:Hide()
elseif (self:IsActive()) then
--print("AutoBar.Class.Button:MoveButtonsModeOff self:IsActive() " .. tostring(self:IsActive()) .. " self.buttonName " .. tostring(self.buttonName))
frame:Show()
else
frame:Hide()
end
end
-- Show grid feedback for droppable buttons
function AutoBar.Class.Button:ACTIONBAR_SHOWGRID()
--print(self.frame:GetName(), "ShowGrid")
local frame = self.frame
frame.icon:Hide()
frame.normalTexture:Show()
end
-- Hide grid feedback for droppable buttons
function AutoBar.Class.Button:ACTIONBAR_HIDEGRID()
--print(self.frame:GetName(), "HideGrid")
local frame = self.frame
frame.icon:Show()
frame.normalTexture:Hide()
end
-- Return a unique key to use
function AutoBar.Class.Button:GetCustomKey(customButtonName)
local barKey = "AutoBarCustomButton" .. customButtonName
return barKey
end
function AutoBar.Class.Button:NameExists(newName)
local newKey = AutoBar.Class.Button:GetCustomKey(newName)
if (AutoBarDB2.account.buttonList[newKey]) then
return true
end
for _, classDB in pairs (AutoBarDB2.classes) do
if (classDB.buttonList[newKey]) then
return true
end
end
for _, charDB in pairs (AutoBarDB2.chars) do
if (charDB.buttonList[newKey]) then
return true
end
end
return nil
end
-- Return a unique name and buttonKey to use
function AutoBar.Class.Button:GetNewName(baseName)
local newName, newKey
local key_seed = 0
while true do
newName = baseName .. key_seed
newKey = AutoBar.Class.Button:GetCustomKey(newName)
key_seed = key_seed + 1
if (not AutoBar.Class.Button:NameExists(newName)) then
break
end
end
return newName, newKey
end
function AutoBar.Class.Button:Delete(buttonKey)
AutoBarDB2.account.buttonList[buttonKey] = nil
for _, classDB in pairs (AutoBarDB2.classes) do
classDB.buttonList[buttonKey] = nil
end
for _, charDB in pairs (AutoBarDB2.chars) do
charDB.buttonList[buttonKey] = nil
end
-- Delete ButtonKeys on Bars
AB.bar:DeleteButtonKey(AutoBarDB2.account.barList, buttonKey)
for _, classDB in pairs (AutoBarDB2.classes) do
AB.bar:DeleteButtonKey(classDB.barList, buttonKey)
end
for _, charDB in pairs (AutoBarDB2.chars) do
AB.bar:DeleteButtonKey(charDB.barList, buttonKey)
end
-- Delete Instantiated Buttons
AutoBar.buttonList[buttonKey] = nil
AutoBar.buttonListDisabled[buttonKey] = nil
end
function AutoBar.Class.Button:RenameCategoryKey(dbList, oldKey, newKey)
for _, buttonDB in pairs(dbList) do
for index, categoryKey in ipairs(buttonDB) do
if (categoryKey == oldKey) then
buttonDB[index] = newKey
end
end
end
end
function AutoBar.Class.Button:RenameCategory(oldKey, newKey)
-- Change all db instances
AutoBar.Class.Button:RenameCategoryKey(AutoBarDB2.account.buttonList, oldKey, newKey)
for _, classDB in pairs (AutoBarDB2.classes) do
AutoBar.Class.Button:RenameCategoryKey(classDB.buttonList, oldKey, newKey)
end
for _, charDB in pairs (AutoBarDB2.chars) do
AutoBar.Class.Button:RenameCategoryKey(charDB.buttonList, oldKey, newKey)
end
end
function AutoBar.Class.Button:RenameKey(dbList, oldKey, newKey, newName)
local buttonDB = dbList[oldKey]
if (buttonDB) then