-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtonBin.lua
2371 lines (2215 loc) · 71.1 KB
/
ButtonBin.lua
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
--[[
**********************************************************************
ButtonBin - A displayer for LibDataBroker compatible addons
**********************************************************************
Some code from Fortress was used in this addon with permission from the
author Borlox.
**********************************************************************
]]
ButtonBin = LibStub("AceAddon-3.0"):NewAddon("ButtonBin", "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0", "LibMagicUtil-1.0")
local LibStub = LibStub
local LDB = LibStub:GetLibrary("LibDataBroker-1.1")
local R = LibStub("AceConfigRegistry-3.0")
local BB_DEBUG = false
local LJ = LibStub("LibJostle-3.0")
-- Silently fail embedding if it doesn't exist
local Logger = LibStub("LibLogger-1.0", true)
local C = LibStub("AceConfigDialog-3.0")
local DBOpt = LibStub("AceDBOptions-3.0")
local media = LibStub("LibSharedMedia-3.0")
local mod = ButtonBin
local CreateFrame = CreateFrame
local GetAddOnInfo = GetAddOnInfo
local GetCursorPosition = GetCursorPosition
local GetScreenHeight = GetScreenHeight
local GetScreenWidth = GetScreenWidth
local IsAltKeyDown = IsAltKeyDown
local UIParent = UIParent
local fmt = string.format
local ipairs = ipairs
local lower = string.lower
local pairs = pairs
local select = select
local setmetatable = setmetatable
local tconcat = table.concat
local tinsert = table.insert
local tostring = tostring
local tremove = table.remove
local tsort = table.sort
local type = type
local unpack = unpack
local bins = {}
local binTimers = {}
local ldbObjects = {}
local buttonFrames = {}
local options
local db
local unlockButtons = false
local unlockFrames = false
local playerInCombat = false
function mod.clear(tbl)
if type(tbl) == "table" then
for id,data in pairs(tbl) do
if type(data) == "table" then mod.del(data) end
tbl[id] = nil
end
end
end
if Logger then
Logger:Embed(mod)
else
-- Enable info messages
mod.info = function(self, ...) mod:Print(fmt(...)) end
mod.error = mod.info
mod.warn = mod.info
-- But disable debugging
if BB_DEBUG then
mod.debug = mod.info
else
mod.debug = function(self, ...) end
end
mod.trace = mod.debug
mod.spam = mod.debug
end
local defaults = {
profile = {
enabledDataObjects = {
['*'] = {
enabled = true,
tooltipScale = 1.0,
},
},
size = 24,
scale = 1.0,
tooltipScale = 1.0,
width = 20,
hpadding = 0.5,
vpadding = 0.5,
bins = {
['*'] = {
colors = {
backgroundColor = { 0, 0, 0, 0.5},
borderColor = { 0.88, 0.88, 0.88, 0.8 },
labelColor = { 1, 1, 1 },
textColor = { 1, 1, 1 },
unitColor = { 1, 1, 1 },
valueColor = { 0.9, 0.9, 0 },
},
background = "Solid",
binLabel = true,
border = "None",
clampToScreen = true,
collapsed = false,
edgeSize = 10,
flipx = false,
flipy = false,
font = "Friz Quadrata TT",
moveFrames = false,
fontsize = 12,
hidden = true,
hideAllText = false,
hideEmpty = true,
hideLabel = true,
hideTimeout = 2,
hpadding = 0.5,
labelOnMouse = false,
pixelwidth = 0,
scale = 1.0,
size = 24,
sortedButtons = {},
tooltipScale = 1.0,
useGlobal = true,
visibility = "always",
vpadding = 0.5,
width = 10,
binTexture = "Interface\\AddOns\\ButtonBin\\bin.tga",
center = false,
}
}
}
}
local function ColorToHex(c)
return ("%02x%02x%02x"):format(c[1]*255, c[2]*255, c[3]*255)
end
local GameTooltip = GameTooltip
local function GT_OnLeave(self)
self:SetScript("OnLeave", self.oldOnLeave)
self.oldOnLeave = nil
if self.oldScale then
self:SetScale(self.oldScale)
self.oldScale = nil
end
self:Hide()
GameTooltip:EnableMouse(false)
end
local function getAnchors(frame)
local x, y = frame:GetCenter()
local leftRight
if x < GetScreenWidth() / 2 then
leftRight = "LEFT"
else
leftRight = "RIGHT"
end
if y < GetScreenHeight() / 2 then
return "BOTTOM", "TOP"
else
return "TOP", "BOTTOM"
end
end
local function SetTooltipScale(tooltip, frame)
local bdb,sdb = mod:GetBinSettings(frame:GetParent())
local tooltipScale =
mod:DataBlockConfig(frame.name, "tooltipScale",
sdb.tooltipScale)
tooltip.oldScale = tooltip:GetScale()
tooltip:SetScale(tooltipScale or tooltip.oldScale)
end
local function PrepareTooltip(frame, anchorFrame, isGameTooltip)
if frame == GameTooltip then
frame.oldOnLeave = frame:GetScript("OnLeave")
frame:EnableMouse(true)
frame:SetScript("OnLeave", GT_OnLeave)
end
frame:SetOwner(anchorFrame, "ANCHOR_NONE")
frame:ClearAllPoints()
local a1, a2 = getAnchors(anchorFrame)
frame:SetPoint(a1, anchorFrame, a2)
SetTooltipScale(frame, anchorFrame)
end
local tablet
local function LDB_OnEnter(self)
local obj = self.obj
local bin = self:GetParent()
local bdb = mod:GetBinSettings(bin)
local hideTooltip = mod:DataBlockConfig(self.name, "hideTooltip", bdb.hideTooltips)
if not hideTooltip then
if obj.tooltip then
PrepareTooltip(obj.tooltip, self)
obj.tooltip:Show()
if obj.tooltiptext then
obj.tooltip:SetText(obj.tooltiptext)
end
elseif obj.OnTooltipShow then
PrepareTooltip(GameTooltip, self, true)
obj.OnTooltipShow(GameTooltip)
GameTooltip:Show()
elseif obj.tooltiptext then
PrepareTooltip(GameTooltip, self, true)
GameTooltip:SetText(obj.tooltiptext)
GameTooltip:Show()
elseif self.buttonBinText and not obj.OnEnter then
PrepareTooltip(GameTooltip, self, true)
GameTooltip:SetText(self.buttonBinText)
GameTooltip:Show()
self.hideTooltipOnLeave = true
end
if obj.OnEnter then
obj.OnEnter(self)
end
end
self._isMouseOver = true
self:resizeWindow()
bin._isMouseOver = true
bin:ShowOrHide()
end
local function LDB_OnLeave(self)
local obj = self.obj
local bin = self:GetParent()
self._isMouseOver = nil
bin._isMouseOver = nil
bin:ShowOrHide(true)
self:resizeWindow()
if not obj then return end
if mod:MouseIsOver(GameTooltip) and (obj.tooltiptext or obj.OnTooltipShow)
then
return
end
if self.hideTooltipOnLeave or obj.tooltiptext or obj.OnTooltipShow then
GT_OnLeave(GameTooltip)
self.hideTooltipOnLeave = nil
end
if obj.OnLeave then
obj.OnLeave(self)
end
end
local function LDB_OnReceiveDrag(self, button)
if self._ondrag then
self._ondrag(self, button)
end
end
local function LDB_OnClick(self, button)
if self._onclick then
LDB_OnLeave(self)
self._onclick(self, button)
end
end
local function BB_OnClick(self, button)
LDB_OnLeave(self)
if button == "LeftButton" then
if IsAltKeyDown() then
mod:ToggleButtonLock()
else
mod:ToggleCollapsed(self)
end
elseif button == "MiddleButton" then
mod:ToggleLocked()
elseif button == "RightButton" then
mod:ToggleConfigDialog(self)
end
end
function mod:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("ButtonBinDB", defaults, "Default")
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
db = self.db.profile
if self.SetLogLevel and BB_DEBUG then
mod:SetLogLevel(self.logLevels.TRACE)
end
if BB_DEBUG then
-- Just for easy access while debugging
bbdb = db
bns = bins
bf = buttonFrames
end
end
function mod:AddNewBin()
db.bins[#db.bins+1].hidden = false
mod:LoadPosition(mod:CreateBinFrame(#db.bins, db.bins[#db.bins]))
self:SetupBinOptions(true)
end
do
local tooltip = "Button Bin %d\n"..
"|cffffff00Left click|r to collapse/uncollapse all other icons.\n"..
"|cffffff00Alt-Left click|r to toggle the button lock.\n"..
"|cffffff00Middle click|r to toggle the Button Bin window lock.\n"..
"|cffffff00Right click|r to open the Button Bin configuration.\n"
function mod:CreateBinFrame(id, bdb)
local f = mod:GetBinFrame()
local sdb
if bdb.useGlobal then sdb = db else sdb = bdb end
bins[id] = f
f.binId = id
f:SetClampedToScreen(bdb.clampToScreen)
f.mover:SetClampedToScreen(bdb.clampToScreen)
f:SetScale(sdb.scale)
f:FixBackdrop()
f.button.db = { tooltiptext = tooltip:format(id) }
f.button.obj = f.button.db
f.button.name = "ButtonBin"
mod:SetBinIconAndLabel(f, bdb)
-- f._isMouseOver = true
mod:SortFrames(f)
return f
end
end
function mod:SetBinIconAndLabel(frame, bdb)
if bdb.binLabel then
frame.button.buttonBinText = bdb.binName or "Bin #"..frame.binId
else
frame.button.buttonBinText = nil
end
frame.button.icon:SetTexture(bdb.binTexture)
end
function mod:LibDataBroker_DataObjectCreated(event, name, obj)
ldbObjects[name] = obj
if db.enabledDataObjects[name].enabled then
mod:EnableDataObject(name, obj)
local binid = buttonFrames[name].db.bin
local bdb = db.bins[binid]
for _,bname in ipairs(bdb.sortedButtons) do
if name == bname then
return
end
end
bdb.sortedButtons[#bdb.sortedButtons+1] = name
mod:SortFrames(bins[binid])
end
end
local function TextUpdater(frame, value, name, obj, delay)
local bdb,sdb = mod:GetBinSettings(frame:GetParent())
if mod:DataBlockConfig(name, "hideLabel", bdb.hideAllText) and
mod:DataBlockConfig(name, "hideText", bdb.hideAllText) and
mod:DataBlockConfig(name, "hideValue", bdb.hideAllText) then
frame.buttonBinText = nil
else
local showLabel = not mod:DataBlockConfig(name, "hideLabel", bdb)
local showText = not mod:DataBlockConfig(name, "hideText", bdb)
local showValue = not mod:DataBlockConfig(name, "hideValue", bdb)
local labelColor = ColorToHex(bdb.colors.labelColor)
local textColor = ColorToHex(bdb.colors.textColor)
local unitColor = ColorToHex(bdb.colors.unitColor)
local valueColor = ColorToHex(bdb.colors.valueColor)
local text
if showLabel and obj.label then -- try to show the label
if showValue and obj.value then
text = fmt("|cff%s%s:|r |cff%s%s|r|cff%s%s|r", labelColor, obj.label,
valueColor, obj.value, unitColor, obj.suffix or "")
elseif showText and obj.text and obj.text ~= obj.label then
text = fmt("|cff%s%s:|r |cff%s%s|r",
labelColor, obj.label, textColor, obj.text)
else
text = fmt("|cff%s%s|r", labelColor, obj.label)
end
elseif showLabel and type == "launcher" then
-- show the addonname for launchers if no label is set
local addonName, addonTitle = GetAddOnInfo(obj.tocname or name)
text = fmt("|cff%s%s|r", labelColor, addonTitle or addonName or name)
elseif showText and obj.text then
if showValue and obj.value then
text = fmt("|cff%s%s|cff%s%s|r", valueColor,
obj.value, unitColor, obj.suffix or "")
else
text = fmt("|cff%s%s|r", textColor, obj.text)
end
end
frame.buttonBinText = text
end
if not delay then
local w = frame:GetWidth()
frame:resizeWindow(true)
w = w - frame:GetWidth()
if w > 0 or w < -10 then
mod:SortFrames(frame:GetParent())
end
end
end
local function SetTexCoord(frame, value, name, object)
object.texcoord = value
if object.texcoord then
frame.icon:SetTexCoord(unpack(object.texcoord))
end
end
local function SetIconColor(frame, object)
frame.icon:SetVertexColor(object.iconR or 1,
object.iconG or 1,
object.iconB or 1)
end
local updaters = {
text = TextUpdater, value = TextUpdater,
suffix = TextUpdater, label = TextUpdater,
textcoord = SetTexCoord,
iconCoords = SetTexCoord,
iconR = function(frame, value, name, object)
object.iconR = value
SetIconColor(frame, object)
end,
iconG = function(frame, value, name, object)
object.iconG = value
SetIconColor(frame, object)
end,
iconB = function(frame, value, name, object)
object.iconB = value
SetIconColor(frame, object)
end,
icon = function(frame, value, name, object, delay)
frame.icon:SetTexture(value)
local has_texture = not not value
if has_texture ~= frame._has_texture then
frame._has_texture = has_texture
if not delay then
if has_texture then
mod:SortFrames(frame:GetParent()) -- we grew
else
frame:resizeWindow(true)
end
end
end
end,
OnClick = function(frame, value)
frame._onclick = value
if value then
frame:SetScript("OnClick", LDB_OnClick)
else
frame:SetScript("OnClick", nil)
end
end,
OnReceiveDrag = function(frame, value)
frame._ondrag = value
if value then
frame:SetScript("OnReceiveDrag", LDB_OnReceiveDrag)
else
frame:SetScript("OnReceiveDrag", nil)
end
end,
tooltiptext = function(frame, value, name, object)
local tt = object.tooltip or GameTooltip
if tt:GetOwner() == frame then
tt:SetText(object.tooltiptext)
end
end,
}
function mod:AttributeChanged(event, name, key, value)
if not db.enabledDataObjects[name].enabled then return end
local f = buttonFrames[name]
local obj = ldbObjects[name]
obj[key] = value
if f and obj then
if updaters[key] then
updaters[key](f, value, name, obj)
end
end
end
function mod:EnableDataObject(name, obj)
db.enabledDataObjects[name].enabled = true
-- create frame for object
local frame = buttonFrames[name] or mod:GetFrame()
buttonFrames[name] = frame
frame.db = db.enabledDataObjects[name]
frame.name = name
frame.obj = obj
if not frame.db.bin then
frame.db.bin = 1
end
frame:SetParent(bins[frame.db.bin])
frame:SetScript("OnEnter", LDB_OnEnter)
frame:SetScript("OnLeave", LDB_OnLeave)
mod:UpdateBlock(name, frame, true)
LDB.RegisterCallback(self, "LibDataBroker_AttributeChanged_"..name, "AttributeChanged")
mod:SortFrames(frame:GetParent())
mod:SetupDataBlockOptions(true)
end
function mod:DisableDataObject(name, obj)
db.enabledDataObjects[name].enabled = false
LDB.UnregisterCallback(self, "LibDataBroker_AttributeChanged_"..name)
if buttonFrames[name] then
self:ReleaseFrame(buttonFrames[name])
end
mod:SetupDataBlockOptions(true)
end
function mod:OnEnable()
-- Make sure we have the default set of bins
if not db.bins or #db.bins == 0 then
mod:LoadDefaultBins()
else
for id,bdb in pairs(db.bins) do
mod:CreateBinFrame(id, bdb)
end
end
mod:SetupOptions()
self:ApplyProfile()
if self.SetLogLevel then
self:SetLogLevel(self.logLevels.TRACE)
end
LDB.RegisterCallback(self, "LibDataBroker_DataObjectCreated")
for _,bin in ipairs(bins) do
self:SortFrames(bin)
end
-- Seems to fire when resizing the window or switching from fullscreen to
-- windowed mode but not at other times
self:RegisterEvent("UPDATE_FLOATING_CHAT_WINDOWS","RecalculateSizes")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
end
function mod:OnDisable()
self:UnregisterEvent("UPDATE_FLOATING_CHAT_WINDOWS")
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
LDB.UnregisterAllCallbacks(self)
for id,bin in ipairs(bins) do
bin:Hide()
if binTimers[id] then
self:CancelTimer(binTimers[id], true)
binTimers[id] = nil
end
end
end
function mod:PLAYER_REGEN_ENABLED()
playerInCombat = false
for id,bin in ipairs(bins) do
bin:ShowOrHide(db.bins[id].visibility == "inCombat")
end
end
function mod:PLAYER_REGEN_DISABLED()
playerInCombat = true
for id,bin in ipairs(bins) do
bin:ShowOrHide(db.bins[id].visibility == "noCombat")
end
end
do
local timer
local function Low_RecalculateSizes()
for _,bin in ipairs(bins) do
mod:SortFrames(bin)
end
end
function mod:RecalculateSizes()
if timer then mod:CancelTimer(timer, true) timer = nil end
timer = mod:ScheduleTimer(Low_RecalculateSizes, 1)
end
end
-- Migrate settings
do
local migrated = {
shortLabels = "hideLabel"
}
local migratedobj = {
}
function mod:ConvertBinOptions(bin)
if bin.showLabels ~= nil then
bin.hideAllText = not bin.showLabels
bin.showLabels = nil
end
for from,to in pairs(migrated) do
if bin[from] ~= nil then
bin[to] = bin[from]
bin[from] = nil
end
end
end
function mod:ConvertBlockOptions(obj)
for from,to in pairs(migratedobj) do
if obj[from] ~= nil then
obj[to] = obj[from]
obj[from] = nil
end
end
end
end
function mod:ApplyProfile()
-- clean stuff up
for id,bin in ipairs(db.bins) do
local seen = {}
local newButtons = {}
for bid, name in pairs(bin.sortedButtons) do
if not seen[name] then
seen[name] = true
if db.enabledDataObjects[name].bin == id then
newButtons[#newButtons+1] = name
end
end
end
mod:ConvertBinOptions(bin)
bin.sortedButtons = newButtons
end
for id, obj in pairs(db.enabledDataObjects) do
mod:ConvertBlockOptions(obj)
end
for _,frame in pairs(buttonFrames) do
mod:ReleaseFrame(frame)
end
for name, obj in LDB:DataObjectIterator() do
self:LibDataBroker_DataObjectCreated(nil, name, obj)
end
for id,bin in ipairs(bins) do
bin:ClearAllPoints()
mod:LoadPosition(bin)
if bin.mover:IsVisible() then
mod:ToggleLocked()
else
self:SortFrames(bin) -- will handle any size changes etc
end
end
end
function mod:SavePosition(bin)
local s = bin:GetEffectiveScale()
local bdb = db.bins[bin.binId]
local top = bin:GetTop()
if not top then return end -- the bin is empty, and bin icon hidden
if bdb.flipy then
bdb.posy = bin:GetBottom() * s
bdb.anchor = "BOTTOM"
else
bdb.posy = top * s - UIParent:GetHeight()*UIParent:GetEffectiveScale()
bdb.anchor = "TOP"
end
if bdb.flipx then
bdb.anchor = bdb.anchor .. "RIGHT"
bdb.posx = bin:GetRight() * s - UIParent:GetWidth()*UIParent:GetEffectiveScale()
else
bdb.anchor = bdb.anchor .. "LEFT"
bdb.posx = bin:GetLeft() * s
end
end
function mod:LoadPosition(bin)
local bdb = db.bins[bin.binId]
local posx = bdb.posx
local posy = bdb.posy
local anchor = bdb.anchor
bin:ClearAllPoints()
if not anchor then anchor = "TOPLEFT" end
local s = bin:GetEffectiveScale()
if posx and posy then
bin:SetPoint(anchor, posx/s, posy/s)
if bdb.moveFrames and bin:IsVisible() and bin:GetAlpha() > 0 then
local height = UIParent:GetHeight()
local diff = height + posy/s
if diff < height/15 then
LJ:RegisterBottom(bin)
elseif (height - diff) < height/15 then
LJ:RegisterTop(bin)
else
LJ:Unregister(bin)
end
else
LJ:Unregister(bin)
end
LJ:Refresh()
else
bin:SetPoint(anchor, UIParent, "CENTER")
end
end
function mod:OnProfileChanged(event, newdb, src)
db = self.db.profile
for id,frame in ipairs(bins) do
mod:ReleaseBinFrame(frame)
end
if event == "OnProfileReset" or #db.bins == 0 then
for id,frame in ipairs(bins) do
db.bins[id] = nil
end
db.bins[1].hidden = false
end
for id,bdb in pairs(db.bins) do
mod:CreateBinFrame(id, bdb)
end
self:ApplyProfile()
self:SetupBinOptions(true)
end
function mod:LoadDefaultBins()
local defaults = {
posy = 0.5,
posx = 0,
hidden = false,
binLabel = false,
hideBinIcon = true,
edgeSize = 0,
moveFrames = true,
anchor = "TOPLEFT",
pixelwidth = UIParent:GetWidth(),
width = 100,
clampToScreen = false
}
for id in ipairs(db.bins) do
if bins[id] then
mod:ReleaseBinFrame(bins[id])
end
db.bins[id] = nil
end
for id = 1, 3 do
local bdb = db.bins[id]
for key, val in pairs(defaults) do
bdb[key] = val
end
end
-- left
db.bins[1].binName = "Left"
db.bins[1].hideBinIcon = false
-- right
db.bins[2].binName = "Right"
db.bins[2].flipx = true
db.bins[2].anchor = "TOPRIGHT"
-- center
db.bins[3].binName = "Center"
db.bins[3].center = true
for id, data in pairs(db.enabledDataObjects) do
data.bin = 1
end
for id,bdb in pairs(db.bins) do
mod:CreateBinFrame(id, bdb)
end
self:ApplyProfile()
self:SetupBinOptions(true)
end
function mod:ToggleLocked()
unlockFrames = not unlockFrames
for id,bin in ipairs(bins) do
if not unlockFrames then
local s = bin:GetEffectiveScale()
bin.mover:RegisterForDrag()
bin.mover:Hide()
bin.mover.text:Hide()
mod:LoadPosition(bin)
else
bin.mover:ClearAllPoints()
bin.mover:SetWidth(bin:GetWidth())
bin.mover:SetHeight(bin:GetHeight())
bin.mover:SetScale(bin:GetScale())
bin.mover:SetPoint(bin:GetPoint())
bin.mover:RegisterForDrag("LeftButton")
bin:ClearAllPoints()
bin:SetPoint("TOPLEFT", bin.mover)
bin.mover:Show()
bin.mover.text:Show()
end
bin:ShowOrHide()
mod:SortFrames(bin)
end
end
function mod:ToggleButtonLock()
unlockButtons = not unlockButtons
local dragButton
if unlockButtons then dragButton = "LeftButton" end
if unlockButtons then
mod:Print("Button positions are now unlocked.")
else
mod:Print("Locking button positions.")
end
for name,frame in pairs(buttonFrames) do
frame:RegisterForDrag(dragButton)
frame:SetMovable(unlockButtons)
if unlockButtons then
frame._onenter = frame:GetScript("OnEnter")
frame._onleave = frame:GetScript("OnLeave")
frame:SetScript("OnEnter", nil)
frame:SetScript("OnLeave", nil)
else
if name ~= "ButtonBin" or not db.hideBinTooltip then
frame:SetScript("OnEnter", frame._onenter or LDB_OnEnter)
frame:SetScript("OnLeave", frame._onleave or LDB_OnLeave)
end
frame._onenter = nil frame._onleave = nil
end
end
for _,bin in ipairs(bins) do
bin:ShowOrHide()
end
end
function mod:ReloadFrame(bin)
local wasUnlocked = unlockFrames
if wasUnlocked then mod:ToggleLocked() end
if not db.hideBinTooltip then
bin.button:SetScript("OnEnter", LDB_OnEnter)
bin.button:SetScript("OnLeave", LDB_OnLeave)
else
bin.button:SetScript("OnEnter", nil)
bin.button:SetScript("OnLeave", nil)
end
mod:UpdateAllBlocks(bin)
mod:SavePosition(bin)
mod:LoadPosition(bin)
mod:SortFrames(bin)
if wasUnlocked then mod:ToggleLocked() end
end
options = {
global = {
type = "group",
name = "Global Settings",
order = 4,
childGroups = "tab",
handler = mod,
get = "GetOption",
set = "SetOption",
args = {
toggle ={
type = "toggle",
name = "Lock the button bin frame",
width = "full",
get = function() return not unlockFrames end,
set = function() mod:ToggleLocked() end,
},
tooltipScale = {
type = "range",
name = "Tooltip Scale",
desc = "The scale of the tooltip for this datablock",
width="full",
min = 0.1, max = 5, step = 0.05,
},
toggleButton = {
type = "toggle",
name = "Lock data broker button positions",
desc = "When unlocked, you can move buttons into a new position on the bar.",
width = "full",
get = function() return not unlockButtons end,
set = function() mod:ToggleButtonLock() end
},
hideBinTooltip = {
type = "toggle",
width = "full",
name = "Hide Button Bin tooltips",
desc = "Decide whether or not to show the helper tooltip when mousing over the Button Bin icons.",
},
globalScale = {
type = "group",
name = "Scale and size",
args = {
hpadding = {
type = "range",
name = "Horizontal button padding",
width = "full",
min = 0, max = 50, step = 0.1,
order = 130,
},
vpadding = {
type = "range",
name = "Vertical button padding",
width = "full",
min = 0, max = 50, step = 0.1,
order = 140,
},
size = {
type = "range",
name = "Button size",
width = "full",
min = 5, max = 50, step = 1,
order = 160,
},
scale = {
type = "range",
name = "Bin scale",
width = "full",
min = 0.01, max = 5, step = 0.01,
order = 170,
},
}
}
}
},
dataBlock = {
type = "group",
handler = mod,
set = "SetDataBlockOption",
get = "GetDataBlockOption",
args = {
help = {
type = "description",
name = "You can override the bar level configuration in this section. Note that when enabled, these settings will always override the settings of the individual bins.",
order = 0,
hidden = function() return bins[1] == nil end,
},
enabled = {
type="toggle",
name = "Enabled",
desc = "Toggle to enable display of this datablock.",
order = 1,
disabled = function() return bins[1] == nil end,
},
blockOverride = {
type = "toggle",
name = "Override bin config",
desc = "If override is enabled, the settings here are used over the bin level configuration. Otherwise the block will be displayed as per the bin settings.",
order = 2,
hidden = "HideOverrideConfig",
},
hideTooltip = {
type = "toggle",
name = "Hide tooltip",
desc = "Don't show the mouseover tooltip for this block.",
order = 10,
},
hideIcon = {
type = "toggle",
name = "Hide icon",
desc = "Hide the icon for this datablock.",
hidden = "HideDataBlockOptions"
},
hideLabel = {
type = "toggle",
name = "Hide label",
desc = "Hide the label for this datablock",
hidden = "HideDataBlockOptions"
},
hideText = {
type = "toggle",
name = "Hide text",
desc = "Hide the text for this data block.",
hidden = "HideDataBlockOptions",
},
hideValue = {
type = "toggle",
name = "Hide values",
desc = "Hide the value for this data block.",
hidden = "HideDataBlockOptions",
},
tooltipScale = {
type = "range",
name = "Tooltip Scale",
desc = "The scale of the tooltip for this datablock",
width="full",
min = 0.1, max = 5, step = 0.05,
hidden = "HideDataBlockOptions"
},
bin = {
type = "select",
name = "Bin",