-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAutoBarButton.lua
More file actions
2814 lines (2207 loc) · 95.5 KB
/
AutoBarButton.lua
File metadata and controls
2814 lines (2207 loc) · 95.5 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
--
-- AutoBarButton
-- Copyright 2007+ Toadkiller of Proudmoore.
--
-- Buttons for AutoBar
-- http://muffinmangames.com
--
local _, AB = ... -- Pulls back the Addon-Local Variables and store them locally.
local types = AB.types ---@class ABTypes
local code = AB.code ---@class ABCode
local AutoBar = AutoBar
local AutoBarSearch = AutoBarSearch --TODO: This shouldn't be a global at all
local ABGData = AutoBarGlobalDataObject
local spellIconList = ABGData.spell_icon_list
local Class = AutoBar.Class.new_class
local L = AutoBarGlobalDataObject.locale
AutoBarButton = Class(AutoBar.Class.Button)
AutoBarButton.dirtyButton = {}
function AutoBarButton:init(parentBar, buttonDB)
AutoBarButton.super.init(self, parentBar, buttonDB)
end
-- Handle dragging of items, macros, spells to the button
-- Handle rearranging of buttons when buttonLock is off
--TODO: Why is this in the Button class? It should be part of Category
local function AddItemToCategory(category, itemType, itemId, itemInfo)
local categoryInfo = AutoBarCategoryList[category]
local itemsListDB = categoryInfo.customCategoriesDB.items
local itemIndex = # itemsListDB + 1
--print("AutoBarButton:DropLink " .. tostring(categoryInfo.description) .. "itemType " .. tostring(itemType) .. " itemId " .. tostring(itemId) .. " itemInfo " .. tostring(itemInfo))
for index = # itemsListDB, 1, -1 do
if(itemsListDB[index].itemId == itemId) then
print("AutoBar: Item " .. itemInfo .. " already exists in Category " .. tostring(categoryInfo.description) .. " not adding it again");
return
end
end
local itemDB = {
itemType = itemType,
itemId = itemId,
itemInfo = itemInfo
}
itemsListDB[itemIndex] = itemDB
if (itemType == "spell") then
itemDB.spellName = AB.GetSpellInfo(itemId)
itemDB.spellClass = AutoBar.CLASS
else
itemDB.spellName = nil
itemDB.spellClass = nil
end
end
-- Handle dragging of items, macros, spells to the button
-- Handle rearranging of buttons when buttonLock is off
function AutoBarButton:DropLink(itemType, itemId, itemInfo)
if(itemType == "item" and AB.PlayerHasToy(itemId)) then
print("AutoBar: Item " .. itemInfo .. " looks like a Toy, so I'm not adding it. Toys are not currently supported in Drag and Drop.");
return;
end
if (itemType == "item" or itemType == "spell" or itemType == "macro") then
-- Select a Custom Category to use
local categoryInfo, categoryKey, dropped
for index = # self, 1, -1 do
categoryKey = self[index]
categoryInfo = AutoBarCategoryList[categoryKey]
if (categoryInfo and categoryInfo.customKey) then
AddItemToCategory(categoryKey, itemType, itemId, itemInfo)
AutoBar:BarButtonChanged()
dropped = true
break
end
end
-- Create a Custom Category to use
local buttonDB = self.buttonDB
if (not dropped and buttonDB.drop) then
local buttonCategoryIndex = # buttonDB + 1
local new_key = AutoBar:CategoryNew()
buttonDB[buttonCategoryIndex] = new_key
AddItemToCategory(new_key, itemType, itemId, itemInfo)
AutoBar:BarButtonChanged()
end
end
end
-- Handle dragging of items, macros, spells to the button
-- Handle rearranging of buttons when buttonLock is off
function AutoBarButton:DropObject()
local toObject = self
local fromObject = AutoBar:GetDraggingObject()
local refreshNeeded
--print("AutoBarButton:DropObject " .. tostring(fromObject and fromObject.buttonDB.buttonKey or "none") .. " --> " .. tostring(toObject.buttonDB.buttonKey))
if (fromObject and fromObject ~= toObject and AutoBar.moveButtonsMode) then
AutoBar:ButtonMove(fromObject.parentBar.barKey, fromObject.order, toObject.parentBar.barKey, toObject.order)
AutoBar:BarButtonChanged()
ClearCursor()
else
local buttonDB = toObject.buttonDB
if (buttonDB.hasCustomCategories and AutoBar.moveButtonsMode or buttonDB.drop) then
local itemType, itemId, itemInfo, spell_id, base_spell_id = GetCursorInfo()
if(itemType == "spell") then
itemId = spell_id
end
if (itemType == "item" or itemType == "spell" or itemType == "macro") then
--print("AutoBarButton:DropObject itemType " .. tostring(itemType) .. " itemId " .. tostring(itemId) .. " itemInfo " .. tostring(itemInfo))
toObject:DropLink(itemType, itemId, itemInfo)
refreshNeeded = true
ClearCursor()
AutoBar:CategoriesChanged()
end
end
end
if (refreshNeeded) then
if (fromObject) then
fromObject:UpdateButton()
end
end
AutoBar:SetDraggingObject(nil)
end
-- popupNazi makes sure we dont have multiple popups open. Google "Soup Nazi" for how this is done
-- There are two cases:
-- 1) Rapid movement or movement off the window breaks the Blizzard code. We use a sensible timer to fix this - popupNaziSnippet
local popupNaziSnippet = [[
local flag = self:IsUnderMouse(true)
if (flag) then
local queued = control:SetTimer(1, "hoverCheck")
else
local anchorButton = self:GetFrameRef("anchorButton")
x, y = anchorButton:GetMousePosition()
if (x and y) then
local queued = control:SetTimer(1, "hoverCheck")
else
self:Hide()
end
end
]]
-- 2) Track the popped open menu. If we open a new one we sensibly close the old one - popupNaziHandler
local popupNaziHandler = CreateFrame("Frame", "AutoBarPopupNaziHandler", nil, "SecureHandlerAttributeTemplate")
popupNaziHandler:SetAttribute("_onattributechanged", [[
local openHandler = self:GetAttribute("openhandler")
if (name == "openhandler") then
local openHandler = self:GetAttribute("openhandler")
local oldOpenHandler = self:GetAttribute("oldopenhandler")
if (oldOpenHandler and oldOpenHandler ~= openHandler) then
-- print("hiding old one", oldOpenHandler, openHandler)
oldOpenHandler:Hide()
end
self:SetAttribute("oldopenhandler", openHandler)
end
]])
-- The basic idea is to have an intervening handler frame that is Shown / Hidden if popupOnModifier is true / nil
local snippetPopupKey = [[
if (newstate == "1") then
self:Show()
else
self:Hide()
end
]]
local popupKeyStates = "[modifier:shift] 1; 0"
-- Clone the popup into the anchorButton
local snippetOnClick = [[
local popupHeader = self:GetFrameRef("popupHeader")
local anchorButton = popupHeader:GetFrameRef("anchorButton")
-- Move the attributes that make the button work
local itemType = self:GetAttribute("type")
local itemType1 = self:GetAttribute("type1")
local item_guid = self:GetAttribute("AutoBarGUID")
if(itemType1) then
anchorButton:SetAttribute("type1", self:GetAttribute("type1"))
anchorButton:SetAttribute("target-slot1", self:GetAttribute("target-slot1"))
anchorButton:SetAttribute("target-bag1", self:GetAttribute("target-bag1"))
anchorButton:SetAttribute("item1", self:GetAttribute("item1"))
anchorButton:SetAttribute("spell1", self:GetAttribute("spell1"))
end
anchorButton:SetAttribute("type", self:GetAttribute("type"))
anchorButton:SetAttribute("unit", self:GetAttribute("unit"))
anchorButton:SetAttribute("target-slot", self:GetAttribute("target-slot"))
anchorButton:SetAttribute("target-bag", self:GetAttribute("target-bag"))
anchorButton:SetAttribute("AutoBarGUID", self:GetAttribute("AutoBarGUID"))
if (itemType == "toy") then
anchorButton:SetAttribute("toy", self:GetAttribute("toy"))
elseif (itemType == "item") then
anchorButton:SetAttribute("item", self:GetAttribute("item"))
elseif (itemType == "spell") then
anchorButton:SetAttribute("spell", self:GetAttribute("spell"))
elseif (itemType == "macro") then
anchorButton:SetAttribute("macro", self:GetAttribute("macro"))
anchorButton:SetAttribute("macrotext", self:GetAttribute("macrotext"))
anchorButton:SetAttribute("macroName", self:GetAttribute("macroName"))
anchorButton:SetAttribute("macroBody", self:GetAttribute("macroBody"))
end
-- Move the right click attributes
itemType = self:GetAttribute("type2")
anchorButton:SetAttribute("type2", self:GetAttribute("type2"))
anchorButton:SetAttribute("target-slot2", self:GetAttribute("target-slot2"))
anchorButton:SetAttribute("target-bag2", self:GetAttribute("target-bag2"))
anchorButton:SetAttribute("unit2", self:GetAttribute("unit2"))
if (itemType == "item") then
anchorButton:SetAttribute("item2", self:GetAttribute("item2"))
elseif (itemType == "spell") then
anchorButton:SetAttribute("spell2", self:GetAttribute("spell2"))
elseif (itemType == "macro") then
anchorButton:SetAttribute("macro2", self:GetAttribute("macro2"))
anchorButton:SetAttribute("macrotext2", self:GetAttribute("macrotext2"))
end
-- Tooltip and Icon support
anchorButton:SetAttribute("category", self:GetAttribute("category"))
anchorButton:SetAttribute("itemId", self:GetAttribute("itemId"))
anchorButton:SetAttribute("icon", self:GetAttribute("icon"))
anchorButton:SetAttribute("itemLink", self:GetAttribute("itemLink"))
-- Arrange on Use source popup button
anchorButton:SetAttribute("sourceButton", self)
]]
-- Clicking on a popup changes the anchor button spell. This updates the icon texture to match
local function UpdateIcon(button, texture)
button.icon:SetTexture(texture)
end
-- Clicking on a popup changes the anchor button spell. This updates the icon texture to match
local function UpdateHandlers(frame)
local TooltipSet = frame:GetAttribute("TooltipSet")
--print("UpdateHandlers", sourceButton, TooltipSet, frame.TooltipSet)
frame.TooltipSet = TooltipSet
local itemId
local buttonKey = frame.class.buttonName
local itemType = frame:GetAttribute("type")
local item_guid = frame:GetAttribute("AutoBarGUID")
if(item_guid) then
itemId = item_guid
elseif (itemType) then
if (itemType == "item") then
itemId = frame:GetAttribute("itemId")
elseif (itemType == "spell") then
itemId = frame:GetAttribute("spell")
elseif (itemType == "macro") then
itemId = frame:GetAttribute("macroId")
else
print("AutoBar UpdateHandlers can't handle:", itemType);
end
end
local buttonData = AutoBar.char.buttonDataList[buttonKey]
if (not buttonData) then
buttonData = {}
AutoBar.char.buttonDataList[buttonKey] = buttonData
end
buttonData.arrangeOnUse = itemId
end
local MAX_POPUP_HEIGHT = 8
-- Lay out the popups
function AutoBarButton:SetupPopups(nItems)
local buttonKey = self.buttonDB.buttonKey
local frame = self.frame
local popupHeader = frame.popupHeader
local popupKeyHandler = frame.popupKeyHandler
local barKey = self.parentBar.barKey
local layoutDB = AutoBar.barLayoutDBList[barKey]
local debug = false --(buttonKey == "AutoBarButtonHearth")
local padding = layoutDB.padding
local hitRectPadding = -math.max(4, padding)
local popupDirection = layoutDB.popupDirection
local relativeSide, side, splitRelativeSide, splitSide
local paddingX, paddingY, splitPaddingX, splitPaddingY = 0, 0, 0, 0
if (popupDirection == "1") then -- Top
side = "BOTTOM"
relativeSide = "TOP"
paddingY = padding
splitSide = "LEFT"
splitRelativeSide = "RIGHT"
splitPaddingX = padding
elseif (popupDirection == "2") then -- Left
side = "RIGHT"
relativeSide = "LEFT"
paddingX = -padding
splitSide = "BOTTOM"
splitRelativeSide = "TOP"
splitPaddingY = padding
elseif (popupDirection == "3") then -- Bottom
side = "TOP"
relativeSide = "BOTTOM"
paddingY = -padding
splitSide = "RIGHT"
splitRelativeSide = "LEFT"
splitPaddingX = -padding
elseif (popupDirection == "4") then -- Right
side = "LEFT"
relativeSide = "RIGHT"
paddingX = padding
splitSide = "TOP"
splitRelativeSide = "BOTTOM"
splitPaddingY = -padding
end
local max_popup_height = self.buttonDB.max_popup_height or MAX_POPUP_HEIGHT
-- For gigantic popups, split it up into a block
local splitLength = max_popup_height
local splitRelativePoint
if(self.buttonDB.square_popups == true) then
local nSplits = math.ceil(nItems / max_popup_height)
if (nSplits > 1) then
splitLength = math.ceil(nItems / nSplits)
end
end
--if (self.buttonDB.max_popup_height) then
-- print("items:", nItems,"max height:", self.buttonDB.max_popup_height, "square:", self.buttonDB.square_popups, "split_len:", splitLength)
--end
-- Arrange on Use Buttons show the first Button because it needs to remain there for changes during combat.
local arrangeOnUse = self.buttonDB.arrangeOnUse
local popupIndexStart = 2
if (arrangeOnUse) then
popupIndexStart = 1
end
local buttonItems = AutoBarSearch.items:GetList(buttonKey)
if debug then code.log_warning("SetupPopups|n", code.Dump(buttonItems, 1)) end;
local relativePoint = popupHeader
for popupButtonIndex = popupIndexStart, nItems, 1 do
local popupButton = AutoBar.Class.PopupButton:GetPopupButton(self, popupButtonIndex, popupHeader, popupKeyHandler)
local popupButtonFrame = popupButton.frame
-- Wrap OnClick with the Arrange on use code
local wrapped = popupButtonFrame.snippetOnClick
if (wrapped and (not arrangeOnUse)) then
local _header, preBody, _post_body = popupHeader:UnwrapScript(popupButtonFrame, "OnClick")
assert(wrapped == preBody, "wrapped ~= preBody in UnwrapScript")
-- ToDo: Are we the only wrapping people? Maybe add some recursive unwrapping of our exact script.
elseif ((not wrapped) and arrangeOnUse) then
SecureHandlerWrapScript(popupButtonFrame, "OnClick", popupHeader, snippetOnClick)
popupButtonFrame.snippetOnClick = snippetOnClick
end
-- Attach to edge of previous popupButtonFrame or the popupHeader
popupButtonFrame:ClearAllPoints()
popupButtonFrame:SetHeight(ABGData.default_button_height)
popupButtonFrame:SetWidth(ABGData.default_button_width)
popupButtonFrame:Raise()
popupButtonFrame:SetScale(1)
if (relativePoint == popupHeader) then
popupButtonFrame:SetPoint(side, relativePoint, side, paddingX, paddingY)
splitRelativePoint = popupButtonFrame
else
if (math.fmod(popupButtonIndex - popupIndexStart, splitLength) == 0) then
--print(frame:GetName(), popupButtonIndex, "/", nItems, splitLength, nSplits)
popupButtonFrame:SetPoint(splitSide, splitRelativePoint, splitRelativeSide, splitPaddingX, splitPaddingY)
splitRelativePoint = popupButtonFrame
else
popupButtonFrame:SetPoint(side, relativePoint, relativeSide, paddingX, paddingY)
end
end
if (popupButtonIndex == 2) then
if (popupDirection == "1") then
popupButtonFrame:SetHitRectInsets(hitRectPadding, hitRectPadding, hitRectPadding, -padding)
elseif (popupDirection == "2") then
popupButtonFrame:SetHitRectInsets(hitRectPadding, -padding, hitRectPadding, hitRectPadding)
elseif (popupDirection == "3") then
popupButtonFrame:SetHitRectInsets(hitRectPadding, hitRectPadding, -padding, hitRectPadding)
elseif (popupDirection == "4") then
popupButtonFrame:SetHitRectInsets(-padding, hitRectPadding, hitRectPadding, hitRectPadding)
end
else
popupButtonFrame:SetHitRectInsets(hitRectPadding, hitRectPadding, hitRectPadding, hitRectPadding)
end
relativePoint = popupButtonFrame
-- Support selfcast
popupButtonFrame:SetAttribute("checkselfcast", true)
popupButtonFrame:SetAttribute("checkfocuscast", true)
local bag, slot, spell, itemId, macroId, type_id, info_data = AutoBarSearch.sorted:GetInfo(buttonKey, popupButtonIndex)
self:SetupAttributes(popupButton, bag, slot, spell, macroId, type_id, info_data, itemId, buttonItems[itemId])
popupButton:UpdateIcon()
end
popupHeader:ClearAllPoints()
--- ToDo: fix for orientation
-- popupHeader:SetWidth(ABGData.default_button_width + paddingX * 2)
-- popupHeader:SetHeight((ABGData.default_button_height + paddingY) * (nItems - 1) + paddingY)
popupHeader:SetWidth(2)
popupHeader:SetHeight(2)
popupHeader:SetScale(1)
popupHeader:SetPoint(side, frame, relativeSide)
RegisterAutoHide(popupHeader, 0.25)
-- Hide unwanted buttons
for popupButtonIndex, popupButton in pairs(popupHeader.popupButtonList) do
if (popupButtonIndex > nItems) then
popupButton.frame:Hide() -- Items have shrunk below instantiated list. Hide the excess.
elseif (popupButtonIndex < popupIndexStart) then
--print("hiding popupButtonIndex, popupIndexStart, nItems, arrangeOnUse", popupButton:getName(), popupButtonIndex, popupIndexStart, nItems, arrangeOnUse)
popupButton.frame:Hide() -- Hide 1st popup if it is not arrange on use as it is identical to the anchorButton
elseif (self.buttonDB.alwaysPopup) then
popupButton.frame:Show()
popupHeader:Show()
else
popupButton.frame:Show()
end
end
end
-- Set the state attributes of the button
function AutoBarButton:GetHierarchicalSetting(setting)
local db = self.buttonDB
if (db[setting] ~= nil) then
return db[setting]
end
db = self.parentBar.sharedLayoutDB
if (db[setting] ~= nil) then
return db[setting]
end
db = AutoBarDB2.account
if (db[setting] ~= nil) then
return db[setting]
end
end
-- Update the anchorButton after a click on a popup
local snippetOnAttributeChanged = [[
if (name == "icon") then
control:CallMethod("UpdateIcon", value)
elseif (name == "sourcebutton") then -- or name == "sourceButton" Some code is lowercasing this. How silly.
control:CallMethod("UpdateHandlers")
end
]]
-- Used to pop up the buttons based on popupHeader FrameRef on the button
local popupHandler = CreateFrame("Frame", "AutoBarPopupHandler", nil, "SecureHandlerEnterLeaveTemplate")
-- Set the state attributes of the button
function AutoBarButton:SetupButton()
local buttonKey = self.buttonDB.buttonKey
local frame = self.frame
local bag, slot, spell, itemId, macroId, type_id, info_data = AutoBarSearch.sorted:GetInfo(buttonKey, 1)
local popupHeader = frame.popupHeader
--if (buttonKey == "AutoBarButtonHearth") then print("AutoBarButton.proto:SetupButton buttonKey ", buttonKey, " bag ", bag, " slot ", slot, " spell ", spell, " macroId ", macroId, "type_id", type_id, "info_data", info_data) end;
if ((bag or slot or spell or macroId or type_id) and self.buttonDB.enabled) then
frame:Show()
local sortedItems = AutoBarSearch.sorted:GetList(buttonKey)
local noPopup = self.buttonDB.noPopup
local nItems = # sortedItems
if (nItems < 2) then
noPopup = true
end
local buttonItems = AutoBarSearch.items:GetList(buttonKey)
local itemData = buttonItems[itemId]
self:SetupAttributes(self, bag, slot, spell, macroId, type_id, info_data, itemId, itemData)
if (noPopup) then
if (popupHeader) then
for _, popupButton in pairs(popupHeader.popupButtonList) do
popupButton.frame:Hide()
end
end
else
local popupOnModifier = self:GetHierarchicalSetting("popupOnShift")
-- Create the Button's Popup Header
if (not popupHeader) then
local name = buttonKey .. "PopupHeader"
popupHeader = CreateFrame("Frame", name, frame, "SecureHandlerEnterLeaveTemplate")
popupHeader:SetAttribute("_onenter", [[self:Show()]])
popupHeader:SetAttribute("_onleave", [[self:Hide()]])
popupHeader:SetFrameStrata("DIALOG")
-- Create the popupKeyHandler if required
if (popupOnModifier) then
-- Note that it is made a child of popupHeader, and later becomes parent to the popup buttons
-- Hiding it will thus hide the popup buttons as well, even if popupHeader is shown
local popupKeyHandler = CreateFrame("Frame", buttonKey .. "HandlerPopupKey", popupHeader, "SecureHandlerStateTemplate")
popupKeyHandler:SetAttribute("_onstate-modifier", snippetPopupKey)
popupKeyHandler:SetAllPoints(popupHeader)
RegisterStateDriver(popupKeyHandler, "modifier", popupKeyStates)
popupKeyHandler:SetAttribute("_onenter", [[ self:GetParent():Show() ]])
popupKeyHandler:SetAttribute("_onleave", [[ self:GetParent():Hide() ]])
frame.popupKeyHandler = popupKeyHandler
end
frame.popupHeader = popupHeader
popupHeader.popupButtonList = {}
RegisterAutoHide(popupHeader, 0.5)
end
-- Add needed snippets (only execute once)
if (not frame.popupHandler) then
frame.popupHandler = popupHandler
frame:SetFrameRef("popupHeader", popupHeader)
frame:Execute([[
popupHeader = self:GetFrameRef("popupHeader")
popupHeader:ClearAllPoints()
popupHeader:SetPoint("BOTTOM", self, "TOP")
popupHeader:Raise()
popupHeader:Hide()
]])
SecureHandlerWrapScript(frame, "OnEnter", popupHandler, [[
popupHeader = self:GetFrameRef("popupHeader")
popupHeader:Show()
]])
popupHandler.TooltipHide = AutoBar.Class.BasicButton.TooltipHide
SecureHandlerWrapScript(frame, "OnLeave", popupHandler, [[
popupHeader = self:GetFrameRef("popupHeader")
popupHeader:Hide()
]])
popupHandler:SetAttribute("_adopt", frame)
-- Deal with rare irritating cases where Popups remain open incorrectly
popupHeader:SetFrameRef("popupNaziHandler", popupNaziHandler)
popupHeader:SetFrameRef("popupHeader", popupHeader)
popupHeader:SetFrameRef("anchorButton", frame)
popupHeader:SetAttribute("_ontimer", popupNaziSnippet)
end
local arrangeOnUse = self.buttonDB.arrangeOnUse
local wrapped = frame.UpdateIcon
-- Trigger Updating on the Anchor Button
if (wrapped and (not arrangeOnUse)) then
local _header, _preBody, _postBody = popupHeader:UnwrapScript(frame, "OnAttributeChanged") --ToDo: Remove this?
elseif ((not wrapped) and arrangeOnUse) then
frame.UpdateIcon = UpdateIcon -- Update Icon
frame.UpdateHandlers = UpdateHandlers -- Update Handlers: Tooltip
SecureHandlerWrapScript(frame, "OnAttributeChanged", frame, snippetOnAttributeChanged)
end
self:SetupPopups(nItems)
end
else
--if (buttonKey == "AutoBarButtonCharge") then print("Charge has no spell") end;
frame:SetAttribute("itemId", nil)
frame:Hide()
if (popupHeader) then
popupHeader:Hide()
end
--if (buttonKey == "AutoBarButtonCharge") then print("move_mode",AutoBar.moveButtonsMode, "showEmpty", AutoBarDB2.settings.show_empty_buttons, "Alwaysshow", self.buttonDB.alwaysShow, "enabled", self.buttonDB.enabled ) end;
if ((AutoBar.moveButtonsMode or AutoBarDB2.settings.show_empty_buttons or self.buttonDB.alwaysShow) and self.buttonDB.enabled) then
frame:Show()
--if (buttonKey == "AutoBarButtonCharge") then print("Showing Frame", "self[1]", self[1]); end;
if (self[1]) then
frame:SetAttribute("category", self[# self])
else
frame:SetAttribute("category", nil)
end
else
frame:SetAttribute("category", nil)
end
end
end
--[[
/dump (# AutoBarSearch.sorted:GetList("AutoBarButtonRecovery"))
/dump (AutoBar.buttonList["AutoBarButtonHearth"].frame.popupHeader.popupButtonList[2].frame:IsVisible())
/dump (AutoBar.buttonList["AutoBarButtonHearth"].frame.popupHeader.popupButtonList[2].frame:IsShown())
/script AutoBar.buttonList["AutoBarButtonHearth"].frame.popupHeader.popupButtonList[2].frame:SetPoint("RIGHT", -260,-80)
--]]
-- Clear the state attributes of the button
local function ClearButtonAttributes(frame)
frame:SetAttribute("target-slot1", nil)
frame:SetAttribute("target-slot2", nil)
frame:SetAttribute("target-bag1", nil)
frame:SetAttribute("target-bag2", nil)
frame:SetAttribute("unit2", nil)
frame:SetAttribute("type", nil)
frame:SetAttribute("type2", nil)
frame:SetAttribute("item", nil)
frame:SetAttribute("item2", nil)
frame:SetAttribute("spell", nil)
frame:SetAttribute("spell2", nil)
frame:SetAttribute("toy", nil)
frame:SetAttribute("macroId", nil)
frame:SetAttribute("macro", nil)
frame:SetAttribute("macrotext", nil)
frame:SetAttribute("macro_action", nil)
frame:SetAttribute("macro_icon", nil)
frame:SetAttribute("macroName", nil)
frame:SetAttribute("macroBody", nil)
frame:SetAttribute("macro2", nil)
frame:SetAttribute("macrotext2", nil)
frame:SetAttribute("itemLink", nil)
frame:SetAttribute("AutoBarGUID", nil)
frame:SetAttribute("icon", nil)
frame:SetAttribute("category", nil)
frame:SetAttribute("itemId", nil)
end
local SPELL_FEED_PET = code.get_spell_name_by_name("Feed Pet")
local SPELL_PICK_LOCK = code.get_spell_name_by_name("Pick Lock")
local SPELL_MILL_HERB
if(ABGData.is_mainline_wow) then
SPELL_MILL_HERB = code.get_spell_name_by_name("Milling")
end
local TRINKET1_SLOT = 13
local TRINKET2_SLOT = 14
-- Set the state attributes of the button
function AutoBarButton:SetupAttributes(button, bag, slot, spell, macroId, p_type_id, p_info_data, itemId, itemData)
local frame = button.frame
ClearButtonAttributes(frame)
local enabled = true
frame.needsTooltip = true
local category = itemData and itemData.category
local debug_me = false; --p_type_id ~= nil
if (debug_me) then print("ABButton.proto:SetupAttributes", bag, slot, spell, macroId, p_type_id, p_info_data, itemId, itemData.category) end;
frame:SetAttribute("category", category)
frame:SetAttribute("itemId", itemId)
local targeted, castSpell, itemsRightClick
local buttonDB = self.buttonDB -- Use base button info for popups as well
local selfCastRightClick = AutoBarDB2.settings.self_cast_right_click
-- Set up special conditions from Category attributes
local categoryInfo = AutoBarCategoryList[category]
if (categoryInfo) then
targeted = categoryInfo.targeted
-- Disable battleground only items outside BG
if (categoryInfo.battleground and not AutoBar.inBG) then
enabled = false
end
castSpell = categoryInfo.castSpell
itemsRightClick = categoryInfo.itemsRightClick
end
if (not targeted and buttonDB.targeted) then
targeted = buttonDB.targeted
end
if (targeted) then
if (targeted == "CHEST") then
frame:SetAttribute("target-slot", 5)
--frame:SetAttribute("target-slot2", 5)
elseif (targeted == "SHIELD") then
frame:SetAttribute("target-slot", 17)
--frame:SetAttribute("target-slot2", 17)
elseif (targeted == "WEAPON") then
frame:SetAttribute("target-slot1", 16)
frame:SetAttribute("target-slot2", 17)
elseif (targeted == TRINKET1_SLOT) then
frame:SetAttribute("target-slot1", TRINKET1_SLOT)
frame:SetAttribute("target-slot2", TRINKET2_SLOT)
elseif (targeted == TRINKET2_SLOT) then
frame:SetAttribute("target-slot1", TRINKET2_SLOT)
frame:SetAttribute("target-slot2", TRINKET1_SLOT)
elseif (AutoBar.CLASS == "ROGUE" and targeted == "Lockpicking") then
frame:SetAttribute("type2", "spell")
frame:SetAttribute("spell2", SPELL_PICK_LOCK)
frame:SetAttribute("target-bag2", bag)
frame:SetAttribute("target-slot2", slot)
elseif (targeted == "Milling") then
frame:SetAttribute("type1", "spell")
frame:SetAttribute("spell1", SPELL_MILL_HERB)
frame:SetAttribute("target-bag1", bag)
frame:SetAttribute("target-slot1", slot)
frame:SetAttribute("type2", "item")
frame:SetAttribute("item2", "Draenic Mortar")
frame:SetAttribute("target-bag2", bag)
frame:SetAttribute("target-slot2", slot)
elseif (AutoBar.CLASS == "HUNTER" and targeted == "PET") then
-- Right Click targets pet
if (category and strfind(category, "Consumable.Food")) then
frame:SetAttribute("type2", "spell")
frame:SetAttribute("spell2", SPELL_FEED_PET)
frame:SetAttribute("target-bag2", bag)
frame:SetAttribute("target-slot2", slot)
else
frame:SetAttribute("unit2", "pet")
end
else
-- Support selfcast-RightMouse
if (selfCastRightClick) then
frame:SetAttribute("unit2", "player")
else
frame:SetAttribute("unit2", nil)
end
end
end
if (enabled) then
if (buttonDB) then
-- Handle right click pet targeting for a slot
if (buttonDB.rightClickTargetsPet) then
if (category and strfind(category, "Consumable.Food")) then
frame:SetAttribute("type2", "spell")
frame:SetAttribute("spell2", SPELL_FEED_PET)
frame:SetAttribute("target-bag2", bag)
frame:SetAttribute("target-slot2", slot)
--print("AutoBarButton:SetupAttributes buttonKey " .. tostring(buttonKey) .. " bag ".. tostring(bag).. " slot " .. tostring(slot))
else
frame:SetAttribute("unit2", "pet")
end
elseif (selfCastRightClick) then
frame:SetAttribute("unit2", "player")
end
if (not castSpell) then
castSpell = buttonDB.castSpell
end
end
-- The matched spell to cast on RightClick
if (itemsRightClick and itemsRightClick[itemId]) then
castSpell = itemsRightClick[itemId]
selfCastRightClick = false
--print("AutoBarButton:SetupAttributes category " .. category .. " castSpell " .. tostring(castSpell))
end
-- Special spell to cast on RightClick
if (castSpell) then
frame:SetAttribute("type2", "spell")
frame:SetAttribute("spell2", castSpell)
end
-- selfCastRightClick targeting
local unit2 = frame:GetAttribute("unit2")
if (selfCastRightClick and not unit2) then
frame:SetAttribute("unit2", "player")
end
local type2 = frame:GetAttribute("type2")
if (not bag and slot) then
local itemLink = GetInventoryItemLink("player", slot)
frame:SetAttribute("type", "item")
frame:SetAttribute("item", itemLink)
-- Tooltip
frame:SetAttribute("itemLink", itemLink)
elseif (bag and slot) then
local itemLink = AB.GetContainerItemLink(bag, slot)
frame:SetAttribute("itemLink", itemLink)
--- if (buttonDB.shuffle) then
--- itemLink = bag .. " " .. slot
--- end
frame:SetAttribute("type", "item")
frame:SetAttribute("item", itemLink)
if (not type2) then
frame:SetAttribute("type2", "item")
frame:SetAttribute("item2", itemLink)
end
elseif (p_type_id == ABGData.TYPE_TOY) then
frame:SetAttribute("type", "toy")
frame:SetAttribute("toy", p_info_data.item_id)
frame:SetAttribute("AutoBarGUID", p_info_data.guid)
elseif (p_type_id == ABGData.TYPE_MACRO_TEXT) then
frame:SetAttribute("type", "macro")
frame:SetAttribute("macrotext", p_info_data.macro_text)
frame:SetAttribute("AutoBarGUID", p_info_data.guid)
frame:SetAttribute("itemLink", p_info_data.macro_tooltip)
button.macroActive = true
elseif (p_type_id == ABGData.TYPE_BATTLE_PET) then
frame:SetAttribute("type", "macro")
frame:SetAttribute("macrotext", p_info_data.macro_text)
frame:SetAttribute("AutoBarGUID", p_info_data.guid)
button.macroActive = true
elseif (macroId) then
local macroInfo = AutoBarSearch.registered_macros[macroId]
frame:SetAttribute("type", "macro")
frame:SetAttribute("macroId", macroId)
if (macroInfo.macroIndex) then
frame:SetAttribute("macro", macroInfo.macroIndex)
button.macroActive = true
else
frame:SetAttribute("macrotext", macroInfo.macroText)
button.macroActive = true
frame:SetAttribute("macroName", macroInfo.macroName)
frame:SetAttribute("macroBody", macroInfo.macroText)
frame:SetAttribute("macro_action", macroInfo.macro_action)
--frame:SetAttribute("macro_tooltip", macroInfo.macro_tooltip)
frame:SetAttribute("itemLink", macroInfo.macro_tooltip)
frame:SetAttribute("macro_icon", macroInfo.macro_icon)
end
elseif (spell) then
-- Default spell to cast
frame:SetAttribute("type", "spell")
frame:SetAttribute("spell", spell)
-- Tooltip
local spellInfo = AutoBarSearch.GetRegisteredSpellInfo(spell)
if (spellInfo and spellInfo.spell_link) then
frame:SetAttribute("itemLink", spellInfo.spell_link)
end
elseif (castSpell) then
-- Set castSpell as default if nothing else is available
--print("AutoBarButton:SetupAttributes-castspell buttonKey " .. buttonKey .. " castSpell " .. tostring(castSpell))
frame:SetAttribute("type", "spell")
frame:SetAttribute("spell", castSpell)
-- Tooltip
local spellInfo = AutoBarSearch.GetRegisteredSpellInfo(castSpell)
if (spellInfo and spellInfo.spell_link) then
frame:SetAttribute("itemLink", spellInfo.spell_link)
end
else
frame:SetAttribute("type", nil)
frame:SetAttribute("type2", nil)
end
end
if (frame.menu) then
frame:SetAttribute("type2", "menu")
end
end
--[[
/dump AutoBar.buttonList["AutoBarButtonFoodPet"][1]
/dump AutoBar.buttonList["AutoBarButtonFoodPet"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("type2")
/dump AutoBar.buttonList["AutoBarButtonFoodPet"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("spell2")
/dump AutoBar.buttonList["AutoBarButtonFoodPet"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("target-bag2")
/dump AutoBar.buttonList["AutoBarButtonFoodPet"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("target-slot2")
/dump AutoBar.buttonList["AutoBarButtonBuff"].frame.popupHeader.popupButtonList[2].frame:GetAttribute("target-slot1")
/dump AutoBar.buttonList["AutoBarButtonClassBuff"].frame:GetAttribute("spell")
/dump AutoBar.buttonList["AutoBarButtonBuff"].frame:GetAttribute("target-slot2")
/dump AutoBar.buttonList["AutoBarButtonCooldownStoneMana"].frame:GetAttribute("itemId")
/dump AutoBar.buttonList["AutoBarButtonHealth"].frame:GetAttribute("itemId")
/dump AutoBar.buttonList["AutoBarButtonMillHerbs"].frame.popupHeader.popupButtonList[10].frame:GetAttribute("type")
--]]
--
-- Button Update callback functions
--
--function AutoBarButton:SetTooltip(button)
--print("SetTooltip " .. tostring(self.needsTooltip) .. " button " .. tostring(button) .. " button " .. tostring(button) .. " showTooltip " .. tostring(AutoBarDB2.settings.show_tooltip) .. " self.needsTooltip " .. tostring(self.needsTooltip))
-- local isAutoBarButton = self.class and self.class.buttonDB
--
-- if (isAutoBarButton and self.GetHotkey) then
-- 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) or (button == "OnLeave")
-- if (noTooltip) then
-- self.updateTooltip = nil
-- GameTooltip:Hide()
-- return
-- end
--
-- if (GetCVar("UberTooltips") == "1") then
-- GameTooltip_SetDefaultAnchor(GameTooltip, self)
-- else
-- local x = self:GetRight();
-- if ( x >= ( GetScreenWidth() / 2 ) ) then
-- GameTooltip:SetOwner(self, "ANCHOR_LEFT");
-- else
-- GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
-- end
-- end
--
-- -- Add Button or Bar name
-- if (AutoBar.moveButtonsMode) then
-- if (self.class and self.class.sharedLayoutDB) then
-- GameTooltip:AddLine(self.class.barName)
-- elseif(isAutoBarButton) then
-- GameTooltip:AddLine(AB.GetButtonDisplayName(self.class.buttonDB))
-- end
-- else
-- local buttonType = self:GetAttribute("type")
--
-- if (not buttonType) then
-- if (isAutoBarButton) then
-- GameTooltip:AddLine(AB.GetButtonDisplayName(self.class.buttonDB))
-- else
-- self.updateTooltip = nil
-- end
-- elseif (buttonType == "item") then
-- local itemLink = self:GetAttribute("item")
-- if (itemLink) then
-- local itemId = self:GetAttribute("itemId")
-- local bag, slot = AutoBarSearch.found:GetItemData(itemId)
-- if (bag and slot) then
-- GameTooltip:SetBagItem(bag, slot)
-- elseif (slot) then
-- GameTooltip:SetInventoryItem("player", slot)
-- else
-- GameTooltip:SetHyperlink(itemLink)
-- end
-- end
-- self.updateTooltip = TOOLTIP_UPDATE_TIME
-- if (AAutoBarDB2.settings.showTooltipExtended) then
-- print("GameTooltip_ShowCompareItem")
-- GameTooltip_ShowCompareItem()
-- end
---- /script local bag, slot = strmatch("3,4", "^(%d+)%s+(%d+)$"); print("bag " .. tostring(bag).." slot " .. tostring(slot))
-- elseif (buttonType == "spell") then
-- local spellName = self:GetAttribute("spell")
--
-- if (spellName) then
-- local spellInfo = AutoBarSearch.GetRegisteredSpellInfo(spellName)
-- GameTooltip:SetSpellBookItem(spellInfo.spell_id, spellInfo.spellTab)
-- end
-- self.updateTooltip = TOOLTIP_UPDATE_TIME
-- end
--
-- local rightClickType = self:GetAttribute("type2")
-- if (rightClickType == "spell") then
-- local spellName = self:GetAttribute("spell2")
-- if (spellName) then
-- GameTooltip:AddLine(L["Right Click casts "] .. spellName, 1, 0.2, 1, 1)
-- end
-- end
-- end
--
-- GameTooltip:Show()
--end
-- Add your Button custom options to the optionlist
-- optionList[myCustomOptionKey]
-- Call specific SetOption<Type> methods to do the actual setting
function AutoBarButton.AddOptions(_self, _option_list, _pass_value)
end
local function set_button_option(p_info, p_value)
local button_key = p_info.arg.buttonKey
local button_db = AutoBar:GetButtonDB(button_key)
button_db[p_info[# p_info]] = p_value
button_db.is_dirty = true
AutoBarChanged()
AutoBar:ButtonsChanged();
end
-- Call specific option type methods to do the actual setting
function AutoBarButton:SetOptionBoolean(optionList, passValue, valueName, name, desc)
if (not optionList.headerCustomOptions) then
optionList.headerCustomOptions = {
type = "header",
order = 100,
name = "",
}
end
if (not optionList[valueName]) then
optionList[valueName] = {
type = "toggle",
order = 110,
name = name,
desc = desc,
arg = passValue,
disabled = InCombatLockdown,
set = set_button_option,