-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathAutoBarClassBar.lua
More file actions
935 lines (811 loc) · 30.2 KB
/
AutoBarClassBar.lua
File metadata and controls
935 lines (811 loc) · 30.2 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
--
-- AutoBarClassBar
-- Copyright 2007+ Toadkiller of Proudmoore.
-- A lot of code borrowed from Bartender3
--
-- Layout Bars for AutoBar
-- Layout Bars logically organize similar buttons and provide for layout options for the Bar and its Buttons
-- Sticky dragging is provided as well
-- http://muffinmangames.com
--
--GLOBALS: UIParent, CreateFrame, GameFontNormal, RegisterStateDriver, UnregisterStateDriver, InCombatLockdown, IsShiftKeyDown, IsControlKeyDown, IsAltKeyDown
local _
local AB = select(2, ...)
local types = AB.types ---@class ABTypes
local code = AB.code ---@class ABCode
local AutoBar = AutoBar
local ABGData = AutoBarGlobalDataObject
local _G = _G
local L = AutoBarGlobalDataObject.locale
local Masque = LibStub("Masque", true)
local assert, ipairs, print, pairs, math = assert, ipairs, print, pairs, math
if (not AutoBar.Class) then
AutoBar.Class = {}
end
--local function onReceiveDragFunc(bar)
-- local toObject = bar.class
----print("onReceiveDragFunc " .. tostring(toObject.barKey) .. " arg1 " .. tostring(arg1) .. " arg2 " .. tostring(arg2))
-- toObject:DropObject()
--end
local FADEOUT_UPDATE_TIME = 0.1
local function onUpdateFunc(button, elapsed)
local self = button.class
--print("onUpdateFunc " .. tostring(self.barName) .. " elapsed " .. tostring(elapsed) .. " self.elapsed " .. tostring(self.elapsed))
self.elapsed = self.elapsed + elapsed
if (self.fadeOutDelay) then
if (self.elapsed < self.fadeOutDelay) then
return
else
self.elapsed = self.elapsed - self.fadeOutDelay
self.fadeOutDelay = nil
end
end
if (self.elapsed > FADEOUT_UPDATE_TIME) then
self:UpdateFadeOut(self.elapsed)
self.elapsed = 0
end
end
-- Basic Bar that can do the classic AutoBar layout grid
-- Provides snapto when dragging bars
AB.bar = {}
local Bar = AB.bar ---@class Bar
-- Handle dragging of items, macros, spells to the button
-- Handle rearranging of buttons when buttonLock is off
function Bar:DropObject()
local fromObject = AutoBar:GetDraggingObject()
--print("Bar:DropObject " .. tostring(fromObject and fromObject.buttonDB.buttonKey or "none") .. " --> " .. tostring(toObject.buttonDB.buttonKey))
if (fromObject and AutoBar.moveButtonsMode) then
local targetButton = # self.buttonList + 1
AutoBar:ButtonMove(fromObject.parentBar.barKey, fromObject.order, self.barKey, targetButton)
AutoBar:BarButtonChanged()
fromObject:UpdateButton()
end
AutoBar:SetDraggingObject(nil)
end
---@param p_bar_key string
---@return Bar
function Bar:new(p_bar_key)
local obj = CreateFromMixins(self)
obj:init(p_bar_key)
return obj
end
function Bar:init(p_bar_key)
self.barKey = p_bar_key
self:UpdateShared()
if (not L[p_bar_key]) then
L[p_bar_key] = self.sharedLayoutDB.name
end
self.barName = L[p_bar_key]
-- if self.statebar and self.id == 1 then self.mainbar = true end
self:CreateBarFrame()
self:CreateDragFrame()
self.buttonList = {} -- Button by index
self.activeButtonList = {} -- Button by index, non-empty & enabled ones only
self:UpdateObjects()
end
--/script print(tostring(AutoBar.barList["AutoBarClassBarExtras"].frame:GetAttribute("state")))
--/script print(tostring(AutoBar.buttonList["AutoBarButtonFishing"].frame:GetAttribute("state")))
function Bar:SkinChanged(SkinID, Gloss, Backdrop, barKey, buttonKey, Colors)
if (buttonKey) then
local buttonDB = AutoBar.buttonDBList[buttonKey]
buttonDB.SkinID = SkinID
buttonDB.Gloss = Gloss
buttonDB.Backdrop = Backdrop
buttonDB.Colors = Colors
elseif (barKey) then
local barLayoutDB = AutoBar.barLayoutDBList[barKey]
barLayoutDB.SkinID = SkinID
barLayoutDB.Gloss = Gloss
barLayoutDB.Backdrop = Backdrop
barLayoutDB.Colors = Colors
else
--print("Bar:SkinChanged SkinID " .. tostring(SkinID) .. " barKey " .. tostring(barKey) .. " buttonKey " .. tostring(buttonKey))
AutoBarDB2.skin.SkinID = SkinID
AutoBarDB2.skin.Gloss = Gloss
AutoBarDB2.skin.Backdrop = Backdrop
AutoBarDB2.skin.Colors = Colors
end
end
function Bar:CreateBarFrame()
local name = self.barKey .. "Driver"
local driver_template = "SecureHandlerStateTemplate"
if (BackdropTemplateMixin) then
driver_template = "SecureHandlerStateTemplate, BackdropTemplate"
end
---@type Button
local driver = CreateFrame("Button", name, UIParent, driver_template) ---@diagnostic disable-line: assign-type-mismatch
driver.class = self
driver:SetClampedToScreen(AutoBarDB2.settings.clamp_bars_to_screen)
driver:EnableMouse(false)
driver:SetMovable(true)
driver:RegisterForDrag("LeftButton")
driver:RegisterForClicks("RightButtonDown", "LeftButtonUp")
driver:SetBackdrop({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = 0, right = 0, top = 0, bottom = 0},})
driver:SetBackdropColor(0, 1, 1, 0)
driver:ClearAllPoints()
driver:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
driver.text = driver:CreateFontString(nil, "ARTWORK")
driver.text:SetFontObject(GameFontNormal)
driver.text:SetText()
driver.text:Show()
driver.text:ClearAllPoints()
driver.text:SetPoint("CENTER", driver, "CENTER", 0, 0)
if (self.sharedLayoutDB.hide) then
driver:Hide()
else
driver:Show()
end
self.frame = driver
AB.LibMMStickyFrames:RegisterFrame(self.frame)
self.elapsed = 0
if (self.sharedLayoutDB.fadeOut) then
self:CreateFadeFrame()
self.fadeFrame:SetScript("OnUpdate", onUpdateFunc)
end
if (Masque) then
local group = Masque:Group("AutoBar", self.barKey) ---@class MasqueGroup
driver.MasqueGroup = group
group.SkinID = self.sharedLayoutDB.SkinID or "Blizzard"
group.Backdrop = self.sharedLayoutDB.Backdrop
group.Gloss = self.sharedLayoutDB.Gloss
group.Colors = self.sharedLayoutDB.Colors or {}
end
end
-- /dump LibStub("Masque",true):ListSkins()
-- /dump LibStub("Masque",true):ListAddons()
-- /dump LibStub("Masque",true):ListGroups("AutoBar")
-- /dump LibStub("Masque",true):ListButtons("AutoBar", "AutoBarClassBarBasic")
-- Refresh the Bar
-- New buttons are added, unused ones removed
function Bar:UpdateShared()
self.sharedLayoutDB = AutoBar.barLayoutDBList[self.barKey]
self.sharedButtonDB = AutoBar.barButtonsDBList[self.barKey]
self.sharedPositionDB = AutoBar.barPositionDBList[self.barKey]
assert(self.sharedLayoutDB, "nil sharedLayoutDB " .. self.barKey)
assert(self.sharedButtonDB, "nil sharedButtonDB " .. self.barKey)
assert(self.sharedPositionDB, "nil sharedPositionDB " .. self.barKey)
end
-- Apply the new skin
function Bar:UpdateSkin(SkinID)
if (Masque) then
local group = self.frame.MasqueGroup
group.SkinID = SkinID
group:Skin(group.SkinID, group.Backdrop, group.Gloss, group.Colors)
--print("Bar:UpdateSkin SkinID " .. tostring(group.SkinID))
end
end
-- Refresh the Bar
-- New buttons are added, unused ones removed
function Bar:UpdateObjects()
local buttonList = self.buttonList
local buttonKeyList = self.sharedButtonDB.buttonKeys
local buttonDB
assert(buttonList)
assert(buttonKeyList)
-- Create or Refresh the Bar's Buttons
for buttonKeyIndex, buttonKey in ipairs(buttonKeyList) do
local debug = false --(buttonKey == "AutoBarButtonQuest")
buttonDB = AutoBar.buttonDBList[buttonKey]
if (not buttonDB) then
buttonKeyList[buttonKeyIndex] = nil
elseif (buttonDB.enabled) then
-- Recover from disabled cache
assert(buttonDB.buttonKey == buttonKey, "Bar:UpdateObjects mismatched keys")
if(AutoBar.Class[buttonDB.buttonClass] == nil) then print("AutoBar ", buttonDB.buttonClass, "is nil"); end;
if (AutoBar.buttonListDisabled[buttonKey]) then
AutoBar.buttonList[buttonKey] = AutoBar.buttonListDisabled[buttonKey]
AutoBar.buttonListDisabled[buttonKey] = nil
if(debug) then code.log_warning("Bar:UpdateObjects Thaw " .. tostring(buttonKey) .. " <-- buttonListDisabled") end
end
if (AutoBar.buttonList[buttonKey]) then
buttonList[buttonKeyIndex] = AutoBar.buttonList[buttonKey]
buttonList[buttonKeyIndex]:Refresh(self, buttonDB)
if(debug) then code.log_warning("Bar:UpdateObjects existing buttonKeyIndex " .. tostring(buttonKeyIndex) .. " buttonKey " .. tostring(buttonKey)) end
else
assert(buttonKeyIndex)
assert(buttonDB)
assert(buttonDB.buttonClass)
assert(AutoBar.Class[buttonDB.buttonClass], "AutoBar.Class[buttonDB.buttonClass]" .. " fails for " .. buttonDB.buttonClass)
buttonList[buttonKeyIndex] = AutoBar.Class[buttonDB.buttonClass]:new(self, buttonDB)
AutoBar.buttonList[buttonKey] = buttonList[buttonKeyIndex]
if(debug) then code.log_warning("Bar:UpdateObjects new buttonKeyIndex " .. tostring(buttonKeyIndex) .. " buttonKey " .. tostring(buttonKey)) end
end
buttonList[buttonKeyIndex].order = buttonKeyIndex
else
if(debug) then code.log_warning("Bar:UpdateObjects Disabled " .. tostring(buttonKey) .. " --> buttonListDisabled ?") end
-- Move to disabled cache
if (AutoBar.buttonList[buttonKey]) then
buttonList[buttonKeyIndex] = AutoBar.buttonList[buttonKey]
buttonList[buttonKeyIndex]:Refresh(self, buttonDB)
AutoBar.buttonListDisabled[buttonKey] = AutoBar.buttonList[buttonKey]
AutoBar.buttonList[buttonKey] = nil
if(debug) then code.log_warning("Bar:UpdateObjects Freeze " .. tostring(buttonKey) .. " --> buttonListDisabled") end
elseif (AutoBar.buttonListDisabled[buttonKey]) then
buttonList[buttonKeyIndex] = AutoBar.buttonListDisabled[buttonKey]
buttonList[buttonKeyIndex]:Refresh(self, buttonDB)
else
assert(AutoBar.Class[buttonDB.buttonClass] ~= nil, buttonDB.buttonClass .. " is nil")
buttonList[buttonKeyIndex] = AutoBar.Class[buttonDB.buttonClass]:new(self, buttonDB)
AutoBar.buttonListDisabled[buttonKey] = buttonList[buttonKeyIndex]
end
end
end
-- Trim Excess
for buttonIndex = # buttonList, # buttonKeyList + 1, -1 do
buttonList[buttonIndex] = nil
end
end
--/dump AutoBar.buttonList["AutoBarCustomButtonCustoXyXz"]
--/dump AutoBar.buttonList["AutoBarButtonBandages"]
--/dump AutoBar.buttonList["CustomButton28"]:IsActive()
--/dump AutoBar.buttonListDisabled["CustomButton30"]:IsActive()
--/script AutoBar.buttonListDisabled["CustomButton30"].frame:Show()
--/dump AutoBar.barList["AutoBarClassBarExtras"].buttonList[2].buttonDB.buttonKey
--/dump AutoBar.barList["AutoBarClassBarExtras"].buttonList[2]:IsActive()
--/dump # AutoBar.barList["AutoBarClassBarExtras"].activeButtonList
--/dump AutoBar.barList["AutoBarClassBarDruid"].buttonList
--/script AutoBar.barList["AutoBarClassBarBasic"]:UpdateActive()
--/dump (# AutoBar.barList["AutoBarClassBarBasic"].activeButtonList)
--/dump (# AutoBar.barList["AutoBarClassBarBasic"].buttonList)
--/dump (# AutoBar.buttonList)
--/dump (# AutoBar.buttonListDisabled)
-- Based on the current Scan results, update the Button and Popup Attributes
-- Create Popup Buttons as needed
function Bar:UpdateAttributes()
local buttonList = self.buttonList
-- Create or Refresh the Bar's Buttons
for _, button in ipairs(buttonList) do
button:SetupButton()
end
end
-- The activeButtonList contains only active buttons. Make it so.
function Bar:UpdateActive()
local activeButtonList = self.activeButtonList
local maxButtons = # self.buttonList
local activeIndex = 1
local maxActiveButtons = self.sharedLayoutDB.rows * self.sharedLayoutDB.columns
--print("Bar:UpdateActive maxButtons " .. tostring(maxButtons))
for index = 1, maxButtons, 1 do
local button = self.buttonList[index]
if (button and button:IsActive()) then
--if (button.buttonName == "AutoBarButtonCharge") then print("AB.Class.Bar.proto:UpdateActive Active ", activeIndex, button.buttonName, button:IsActive()) end;
activeButtonList[activeIndex] = button
activeIndex = activeIndex + 1
if (button.SecureStateDriverRegistered == false) then
RegisterStateDriver(button.frame, "visibility", AutoBar.visibility_driver_string)
button.SecureStateDriverRegistered = true
end
button.frame:Show()
elseif (button) then
--if (button.buttonName == "AutoBarButtonCharge") then print("Bar:UpdateActive Inactive " .. tostring(index) .. " " .. tostring(button.buttonName)) end
if (button.SecureStateDriverRegistered ~= false) then
UnregisterStateDriver(button.frame, "visibility")
button.SecureStateDriverRegistered = false
end
button.frame:Hide()
end
end
-- Ditch buttons in excess of rows * columns
if ((activeIndex - 1) > maxActiveButtons and not AutoBar.moveButtonsMode) then
--print("Bar:UpdateActive activeIndex " .. tostring(activeIndex - 1) .. " maxActiveButtons " .. tostring(maxActiveButtons) .. " = rows " .. tostring(self.sharedLayoutDB.rows) .. " columns " .. tostring(self.sharedLayoutDB.columns))
activeIndex = maxActiveButtons + 1
end
-- Trim Excess
for i = activeIndex, # activeButtonList, 1 do
local button = activeButtonList[i]
button:Disable()
activeButtonList[i] = nil
end
end
-- /dump AutoBar.buttonListDisabled
-- /dump (# AutoBar.buttonList)
-- /dump (# AutoBar.barList["AutoBarClassBarBasic"].buttonList)
-- /dump AutoBar.barList["AutoBarClassBarBasic"].buttonList[6]
-- /dump AutoBar.barList["AutoBarClassBarBasic"].activeButtonList[2].frame.popupHeader:GetAttribute("state")
-- /script AutoBar.barList["AutoBarClassBarBasic"].activeButtonList[4].frame:SetChecked(1)
function Bar:UpdateFadeOut()
--print("Bar:OnUpdate self.sharedLayoutDB.fadeOut " .. tostring(self.sharedLayoutDB.fadeOut))
if (self.sharedLayoutDB.fadeOut) then
local cancelFade = InCombatLockdown() and self.sharedLayoutDB.fadeOutCancelInCombat or self.frame:IsMouseOver() or IsShiftKeyDown() and self.sharedLayoutDB.fadeOutCancelOnShift or IsControlKeyDown() and self.sharedLayoutDB.fadeOutCancelOnCtrl or IsAltKeyDown() and self.sharedLayoutDB.fadeOutCancelOnAlt
for _, button in pairs(self.activeButtonList) do
--- ToDo: Verify
if (button.frame.popupHeader and button.frame.popupHeader:IsVisible()) then
cancelFade = true
end
end
if (cancelFade) then
self.frame:SetAlpha(self.sharedLayoutDB.alpha)
self.faded = nil
self.fadeOutDelay = self.sharedLayoutDB.fadeOutDelay
elseif (not self.faded) then
local startAlpha = self.sharedLayoutDB.alpha
local fadeOutAlpha = self.sharedLayoutDB.fadeOutAlpha or 0
local fadeOutChunks = (self.sharedLayoutDB.fadeOutTime or 10) / FADEOUT_UPDATE_TIME
local decrement = (startAlpha - fadeOutAlpha) / fadeOutChunks
local alpha = self.frame:GetAlpha() - decrement
if (alpha < fadeOutAlpha) then
alpha = fadeOutAlpha
end
if (AutoBar.stickyMode or AutoBar.moveButtonsMode) then
self.frame:SetAlpha(startAlpha)
self.faded = nil
elseif (alpha > fadeOutAlpha) then
self.frame:SetAlpha(alpha)
else
self.frame:SetAlpha(fadeOutAlpha)
self.faded = true
end
end
end
end
function Bar:SetFadeOut(fadeOut)
self.sharedLayoutDB.fadeOut = fadeOut
self.faded = nil
if (fadeOut) then
self:CreateFadeFrame()
self.fadeFrame:SetScript("OnUpdate", onUpdateFunc)
else
self.frame:SetAlpha(self.sharedLayoutDB.alpha)
self.fadeFrame:SetScript("OnUpdate", nil)
end
end
function Bar:StickTo(frame, point, stickToFrame, stickToPoint, stickToX, stickToY)
AB.LibMMStickyFrames:SetFramePoints(frame, point, stickToFrame, stickToPoint, stickToX, stickToY)
self.sharedLayoutDB.stickPoint = point
self.sharedLayoutDB.stickToFrameName = stickToFrame and stickToFrame:GetName() or nil
self.sharedLayoutDB.stickToPoint = stickToPoint
self.sharedLayoutDB.stickToX = stickToX
self.sharedLayoutDB.stickToY = stickToY
end
local colorMoveButtons = {r = 1, b = 1, g = 0, a = 0.5}
function Bar:ColorBars()
local frame = self.frame
if (AutoBar.keyBoundMode or AutoBar.moveButtonsMode) then
-- Adjust Frame Strata
frame:SetFrameStrata("DIALOG")
self:SetButtonFrameStrata("LOW")
-- Cancel Fade
if self.sharedLayoutDB.fadeOut then
frame:SetAlpha(self.sharedLayoutDB.alpha)
self.faded = nil
end
-- Set Color
if (AutoBar.keyBoundMode) then
frame:SetBackdropColor(AB.LibKeyBound:GetColorKeyBoundMode())
elseif (AutoBar.moveButtonsMode) then
if (self.sharedLayoutDB.hide) then
frame:SetBackdropColor(AB.LibMMStickyFrames:GetColorHidden())
else
frame:SetBackdropColor(colorMoveButtons.r, colorMoveButtons.g, colorMoveButtons.b, colorMoveButtons.a)
end
end
frame.text:SetText(self.barName)
frame:Show()
elseif (AutoBar.stickyMode) then
frame:SetFrameStrata(self.sharedLayoutDB.frameStrata)
self:SetButtonFrameStrata(self.sharedLayoutDB.frameStrata)
frame.text:SetText(self.barName)
else
if (self.sharedLayoutDB.hide) then
self.frame:Hide()
else
self.frame:Show()
end
frame:SetFrameStrata(self.sharedLayoutDB.frameStrata)
self:SetButtonFrameStrata(self.sharedLayoutDB.frameStrata)
frame.text:SetText("")
frame:SetBackdropColor(0, 0, 0, 0)
frame:SetBackdropBorderColor(0, 0, 0, 0)
end
end
function Bar:SetButtonFrameStrata(frameStrata)
for _, button in pairs(self.buttonList) do
button.frame:SetFrameStrata(frameStrata)
if (button.frame.popupHeader) then
button.frame.popupHeader:SetFrameStrata("DIALOG")
end
end
end
--local oldOnReceiveDragFunc
function Bar:MoveButtonsModeOn()
local frame = self.frame
frame:EnableMouse(# self.buttonList == 0)
--oldOnReceiveDragFunc = frame:GetScript("OnReceiveDrag")
--- frame:SetScript("OnReceiveDrag", onReceiveDragFunc)
self:ColorBars()
for _, button in pairs(self.buttonList) do
button:MoveButtonsModeOn()
end
self.dragFrame:Show()
end
function Bar:MoveButtonsModeOff()
local frame = self.frame
frame:EnableMouse(AutoBar.stickyMode)
--- frame:SetScript("OnReceiveDrag", oldOnReceiveDragFunc)
frame:SetFrameStrata(self.sharedLayoutDB.frameStrata)
self:SetButtonFrameStrata(self.sharedLayoutDB.frameStrata)
self:ColorBars()
for _, button in pairs(self.buttonList) do
button:MoveButtonsModeOff()
end
self.dragFrame:Hide()
end
function Bar:CreateDragFrame()
if (not self.dragFrame) then
local name = self.barKey .. "DragFrame"
local frame = CreateFrame("Button", name, self.frame, "ActionButtonTemplate SecureActionButtonTemplate SecureHandlerDragTemplate")
frame:GetNormalTexture():Hide()
code.ClearNormalTexture(frame)
self.dragFrame = frame
--print(tostring(self.parentBar.frame) .. " -> " .. tostring(frame) .. " button " .. tostring(name))
frame.class = self
frame:EnableMouse(true)
if (ABGData.is_mainline_wow or ABGData.is_bcc_wow) then
frame:RegisterForClicks("AnyUp", "AnyDown")
else
frame:RegisterForClicks("AnyUp")
end
frame:RegisterForDrag("LeftButton", "RightButton")
--- frame:SetScript("OnReceiveDrag", onReceiveDragFunc)
end
end
function Bar:CreateFadeFrame()
if (not self.fadeFrame) then
local name = self.barKey .. "FadeFrame"
local frame = CreateFrame("CheckButton", name, self.frame, "ActionButtonTemplate, SecureActionButtonTemplate")
code.ClearNormalTexture(frame)
frame.class = self
self.fadeFrame = frame
self.fadeFrame:SetScript("OnUpdate", onUpdateFunc)
end
end
function Bar:ToggleVisibilty()
-- Disable during combat or Move Buttons
if (InCombatLockdown() or AutoBar.moveButtonsMode) then
return
end
if (self.sharedLayoutDB.hide) then
self.sharedLayoutDB.hide = nil
else
self.sharedLayoutDB.hide = true
end
AutoBar:BarsChanged()
if (not AutoBar.stickyMode) then
if (self.sharedLayoutDB.hide) then
-- self.frame:Hide()
else
-- self.frame:Show()
end
end
end
function Bar:RefreshLayout()
-- Disable during combat
if (InCombatLockdown()) then
return
end
self:RefreshScale()
self:RefreshButtonLayout()
self:RefreshAlpha()
--If it's in stickyMode or movebuttonsMode, show it regardless of whether it's hidden or not
if ((AutoBar.stickyMode or AutoBar.moveButtonsMode)) then
self.frame:Show()
elseif (self.sharedLayoutDB.hide or not self.sharedLayoutDB.enabled) then
self.frame:Hide()
else
self.frame:Show()
end
end
function Bar:PositionLoad()
local sharedPositionDB = self.sharedPositionDB
local sharedLayoutDB = self.sharedLayoutDB
local debug = false --self.barKey == "AutoBarClassBarBasic"
if(debug) then code.log_warning("PositionLoad", self.barKey); end
if(debug) then code.log_warning(code.Dump(sharedPositionDB, 1)); end
if (sharedPositionDB.stickToFrameName and _G[sharedPositionDB.stickToFrameName]) then
local stickToFrame = _G[sharedPositionDB.stickToFrameName]
AB.LibMMStickyFrames:SetFramePoints(self.frame, sharedPositionDB.stickPoint, stickToFrame, sharedPositionDB.stickToPoint, sharedPositionDB.stickToX, sharedPositionDB.stickToY)
--print("Bar:PositionLoad " .. tostring(barDB.stickToFrameName))
else
if (not sharedLayoutDB.alignButtons) then
sharedLayoutDB.alignButtons = "3"
end
if (not sharedPositionDB.posX) then
sharedPositionDB.posX = 300
sharedPositionDB.posY = 360
end
-- local alignPoint = Bar:GetAlignPoints(sharedLayoutDB.alignButtons)
local x, y, s = sharedPositionDB.posX, sharedPositionDB.posY, self.frame:GetEffectiveScale()
x, y = x/s, y/s
self.frame:ClearAllPoints()
self.frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", x, y)
end
end
function Bar:PositionSave()
local debug = false --self.barKey == "AutoBarClassBarBasic"
local frame = self.frame
local x, y = frame:GetLeft(), frame:GetBottom()
local s = frame:GetEffectiveScale()
x, y = x * s, y * s
self.sharedPositionDB.posX = x
self.sharedPositionDB.posY = y
if(debug) then code.log_warning("|nPositionSave", self.barKey); end
if(debug) then code.log_warning(code.Dump(self.sharedPositionDB, 1)); end
end
-- Translate the alignButtons setting
function Bar:GetAlignPoints(alignButtons)
local alignPoint, columnRelativePoint, rowRelativePoint, signX, signY
if (alignButtons == "3") then
alignPoint = "BOTTOMLEFT"
rowRelativePoint = "BOTTOMRIGHT"
columnRelativePoint = "TOPLEFT"
signX, signY = 1, 1
elseif (alignButtons == "6") then
alignPoint = "BOTTOMLEFT"
rowRelativePoint = "BOTTOMRIGHT"
columnRelativePoint = "TOPLEFT"
signX, signY = 1, 1
elseif (alignButtons == "9") then
alignPoint = "BOTTOMRIGHT"
rowRelativePoint = "BOTTOMLEFT"
columnRelativePoint = "TOPRIGHT"
signX, signY = -1, 1
elseif (alignButtons == "8") then
alignPoint = "BOTTOMRIGHT"
rowRelativePoint = "BOTTOMLEFT"
columnRelativePoint = "TOPRIGHT"
signX, signY = -1, 1
elseif (alignButtons == "5") then
alignPoint = "BOTTOMLEFT"
rowRelativePoint = "BOTTOMRIGHT"
columnRelativePoint = "TOPLEFT"
signX, signY = 1, 1
elseif (alignButtons == "2") then
alignPoint = "BOTTOMLEFT"
rowRelativePoint = "BOTTOMRIGHT"
columnRelativePoint = "TOPLEFT"
signX, signY = 1, 1
elseif (alignButtons == "7") then
alignPoint = "TOPRIGHT"
rowRelativePoint = "TOPLEFT"
columnRelativePoint = "BOTTOMRIGHT"
signX, signY = -1, -1
elseif (alignButtons == "4") then
alignPoint = "TOPLEFT"
rowRelativePoint = "TOPRIGHT"
columnRelativePoint = "BOTTOMLEFT"
signX, signY = 1, -1
elseif (alignButtons == "1") then
alignPoint = "TOPLEFT"
rowRelativePoint = "TOPRIGHT"
columnRelativePoint = "BOTTOMLEFT"
signX, signY = 1, -1
end
return alignPoint, rowRelativePoint, columnRelativePoint, signX, signY
end
-- ["1"] = L["TOPLEFT"],
-- ["2"] = L["LEFT"],
-- ["3"] = L["BOTTOMLEFT"],
-- ["4"] = L["TOP"],
-- ["5"] = L["CENTER"],
-- ["6"] = L["BOTTOM"],
-- ["7"] = L["TOPRIGHT"],
-- ["8"] = L["RIGHT"],
-- ["9"] = L["BOTTOMRIGHT"],
-- Get offsets for any of the centered options of alignButtons
local function getCenterShift(alignButtons, signX, signY, rows, columns, displayedRows, displayedColumns, padding)
local centerShiftX = 0
local centerShiftY = 0
local padded_width = ABGData.default_button_width + padding
local padded_height = ABGData.default_button_height + padding
if (alignButtons == "6") then
centerShiftX = signX * (columns - displayedColumns) * (padded_width) / 2
elseif (alignButtons == "8") then
centerShiftY = signY * (rows - displayedRows) * (padded_height) / 2
elseif (alignButtons == "5") then
centerShiftX = signX * (columns - displayedColumns) * (padded_width) / 2
centerShiftY = signY * (rows - displayedRows) * (padded_height) / 2
elseif (alignButtons == "2") then
centerShiftY = signY * (rows - displayedRows) * (padded_height) / 2
elseif (alignButtons == "4") then
centerShiftX = signX * (columns - displayedColumns) * (padded_width) / 2
end
return centerShiftX, centerShiftY
end
-- Lay out the buttons in the rows, columns grid specified
-- Collapse holes if collapseButtons is true
-- Obey the alignment options in alignButtons
function Bar:RefreshButtonLayout()
local rows = self.sharedLayoutDB.rows or 1
local columns = self.sharedLayoutDB.columns or 24
local padding = self.sharedLayoutDB.padding
local alignButtons = self.sharedLayoutDB.alignButtons or "3"
local alignPoint, _, _, signX, signY = Bar:GetAlignPoints(alignButtons)
local framePadding = math.max(0, padding)
self.frame:SetWidth(ABGData.default_button_width * columns + ((columns + 1) * framePadding))
self.frame:SetHeight(ABGData.default_button_height * rows + ((rows + 1) * framePadding))
local anchorFrame = self.frame
local activeButtonList = self.activeButtonList
local displayedRows = math.floor((# activeButtonList - 1) / columns) + 1
local displayedColumns = math.min(# activeButtonList, columns)
local centerShiftX, centerShiftY = getCenterShift(alignButtons, signX, signY, rows, columns, displayedRows, displayedColumns, padding)
local pad_btn_width = ABGData.default_button_width + padding
local pad_btn_height = ABGData.default_button_height + padding
--TODO: Clean up those SetPoint calls. Poor perf, and they're ugly
local nButtons = # activeButtonList
local frame
for i = 1, nButtons do
frame = activeButtonList[i].frame
frame:ClearAllPoints()
frame:SetHeight(ABGData.default_button_height)
frame:SetWidth(ABGData.default_button_width)
frame:SetScale(1)
frame:SetPoint(alignPoint, anchorFrame, alignPoint, ((i - 1) % columns) * signX * pad_btn_width + signX * padding + centerShiftX, (math.floor((i - 1) / columns)) * signY * (ABGData.default_button_height + padding) + signY * padding + centerShiftY)
end
-- Dummy drag button for empty bar and end of bar drags
if (AutoBar.moveButtonsMode) then
local i = nButtons + 1
frame = self.dragFrame
frame:ClearAllPoints()
local emptyColumns = columns - ((i - 1) % columns)
--print("Bar:RefreshButtonLayout columns " .. tostring(columns) .. " i " .. tostring(i) .. " emptyColumns " .. tostring(emptyColumns))
frame:SetWidth(pad_btn_width * emptyColumns)
frame:SetPoint(alignPoint, anchorFrame, alignPoint,
((i - 1) % columns) * signX * pad_btn_width + signX * padding + centerShiftX,
(math.floor((i - 1) / columns)) * signY * pad_btn_height + signY * padding + centerShiftY)
end
end
function Bar:RefreshScale()
self.frame:SetScale(self.sharedLayoutDB.scale or 1)
self:PositionLoad()
end
function Bar:RefreshAlpha()
for _, button in pairs(self.buttonList) do
button.frame:SetAlpha(self.sharedLayoutDB.alpha or 1)
end
end
-- Remove a button from the Bar
function Bar:ButtonRemove(buttonDB)
for i, button in pairs(self.buttonList) do
if (button.buttonDB == buttonDB) then
button.frame:SetAttribute("category", nil)
button.frame:SetAttribute("itemId", nil)
button.frame:Hide()
if (AutoBar.buttonListDisabled[buttonDB.buttonKey]) then
AutoBar.buttonListDisabled[buttonDB.buttonKey] = nil
end
if (AutoBar.buttonList[buttonDB.buttonKey]) then
AutoBar.buttonList[buttonDB.buttonKey] = nil
end
for j = i, # self.buttonList, 1 do
if (self.buttonList[j + 1]) then
self.buttonList[j] = self.buttonList[j + 1]
self.buttonList[j + 1] = nil
end
end
break
end
end
end
-- Return a unique key to use
function Bar:GetCustomKey(customBarName)
local barKey = "AutoBarCustomBar" .. customBarName
return barKey
end
-- Change name if possible. return current name
function Bar:ChangeName(newName)
L[self.barKey] = newName
self.barName = newName
self.barKey = Bar:GetCustomKey(newName)
end
function Bar:NameExists(newName)
local newKey = Bar:GetCustomKey(newName)
if (AutoBarDB2.account.barList[newKey]) then
return true
end
for _, classDB in pairs (AutoBarDB2.classes) do
if (classDB.barList[newKey]) then
return true
end
end
for _, charDB in pairs (AutoBarDB2.chars) do
if (charDB.barList[newKey]) then
return true
end
end
return nil
end
-- Return a unique barName and barKey to use
function Bar:GetNewName(baseName)
local newName, newKey
local key_seed = 0
while true do
newName = baseName .. key_seed
newKey = Bar:GetCustomKey(newName)
key_seed = key_seed + 1
if (not Bar:NameExists(newName)) then
break
end
end
return newName, newKey
end
function Bar:DeleteButtonKey(barDBList, oldKey)
for _, barDB in pairs(barDBList) do
local buttonKeys = barDB.buttonKeys
for _, buttonKey in ipairs(buttonKeys) do
if (buttonKey == oldKey) then
for index = buttonKey, # buttonKeys - 1, 1 do
buttonKeys[index] = buttonKeys[index + 1]
end
end
end
end
end
function Bar:RenameButtonKey(barDBList, oldKey, newKey)
for _, barDB in pairs(barDBList) do
local buttonKeys = barDB.buttonKeys
for buttonIndex, buttonKey in pairs(buttonKeys) do
if (buttonKey == oldKey) then
buttonKeys[buttonIndex] = newKey
end
end
end
end
function Bar:RenameKey(barDBList, oldKey, newKey, newName)
local barDB = barDBList[oldKey]
if (barDB) then
barDBList[newKey] = barDB
barDBList[oldKey] = nil
barDB.barKey = newKey
if (barDB.name) then
barDB.name = newName
end
end
end
function Bar:Rename(oldKey, newName)
local newKey = Bar:GetCustomKey(newName)
-- Rename Bar for all classes and characters
Bar:RenameKey(AutoBarDB2.account.barList, oldKey, newKey, newName)
for _, classDB in pairs (AutoBarDB2.classes) do
Bar:RenameKey(classDB.barList, oldKey, newKey, newName)
end
for _, charDB in pairs (AutoBarDB2.chars) do
Bar:RenameKey(charDB.barList, oldKey, newKey, newName)
end
-- Rename instantiated Bar
local bar = AutoBar.barList[oldKey]
if (bar) then
AutoBar.barList[newKey] = bar
AutoBar.barList[oldKey] = nil
end
end
function Bar:OptionsInitialize()
if (not AutoBarDB2.account.barList) then
AutoBarDB2.account.barList = {}
end
if (not AutoBar.class.barList) then
AutoBar.class.barList = {}
end
if (not AutoBar.char.barList) then
AutoBar.char.barList = {}
end
if Masque then
Masque:Group("AutoBar");
end
end
function Bar:OptionsReset()
AutoBarDB2.account.barList = {}
end
function Bar:OptionsUpgrade()
--print("Bar:OptionsUpgrade start")
-- if (not AutoBarDB2.account.barListVersion) then
-- AutoBarDB2.account.barListVersion = barListVersion
-- elseif (AutoBarDB2.account.barListVersion < barListVersion) then
--print("Bar:OptionsUpgrade AutoBarDB2.account.barListVersion " .. tostring(AutoBarDB2.account.barListVersion))
-- AutoBarDB2.account.barListVersion = barListVersion
-- end
end
--[[
/dump AutoBar.barList
/script AutoBarClassBarBasicFrame:Show()
/dump AutoBar.barList["AutoBarClassBar"]
--]]