-
Notifications
You must be signed in to change notification settings - Fork 9
/
gui.lua
9953 lines (8503 loc) · 497 KB
/
gui.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
local LSM = LibStub("LibSharedMedia-3.0")
local LibDD = LibStub:GetLibrary("LibUIDropDownMenu-4.0")
BetterBlizzPlates = nil
local anchorPoints = {"CENTER", "TOPLEFT", "TOP", "TOPRIGHT", "LEFT", "RIGHT", "BOTTOMLEFT", "BOTTOM", "BOTTOMRIGHT"}
local targetIndicatorAnchorPoints = {"TOPLEFT", "TOP", "TOPRIGHT", "LEFT", "RIGHT", "BOTTOMLEFT", "BOTTOM", "BOTTOMRIGHT"}
local pixelsBetweenBoxes = 5
local pixelsBetweenBoxedWSlider = -4
local pixelsOnFirstBox = -1
local npcEditFrame = nil
local LibDeflate = LibStub("LibDeflate")
local LibSerialize = LibStub("LibSerialize")
local LibAceSerializer = LibStub("AceSerializer-3.0")
local titleText = "|A:gmchat-icon-blizz:16:16|a Better|cff00c0ffBlizz|rPlates: \n\n"
local checkBoxList = {}
local sliderList = {}
local function ExportProfile(profileTable, dataType)
-- Include a dataType in the table being serialized
local exportTable = {
dataType = dataType,
data = profileTable
}
local serialized = LibSerialize:Serialize(exportTable)
local compressed = LibDeflate:CompressDeflate(serialized)
local encoded = LibDeflate:EncodeForPrint(compressed)
return "!BBP" .. encoded .. "!BBP"
end
local function ImportOtherProfile(encodedString, expectedDataType)
-- Decode the data
local compressed = LibDeflate:DecodeForPrint(encodedString)
if not compressed then
return nil, "Error decoding the data."
end
-- Decompress the data
local serialized, decompressMsg = LibDeflate:DecompressDeflate(compressed)
if not serialized then
return nil, "Error decompressing: " .. tostring(decompressMsg)
end
-- Deserialize the data using LibAceSerializer
local success, importTable = LibAceSerializer:Deserialize(serialized)
if not success then
return nil, "Error deserializing the data."
end
-- Store the imported data in the DB
if expectedDataType == "colorNpcList" then
BBP.MergeNpcColorToBBP(importTable)
elseif expectedDataType == "castEmphasisList" then
BBP.MergeCastColorToBBP(importTable)
end
return true, nil
end
function BBP.ImportProfile(encodedString, expectedDataType)
-- Check if the string starts and ends with !BBP
if encodedString:sub(1, 4) == "!BBP" and encodedString:sub(-4) == "!BBP" then
encodedString = encodedString:sub(5, -5) -- Remove both prefix and suffix
-- Proceed with the usual import process for your native format
local compressed = LibDeflate:DecodeForPrint(encodedString)
local serialized, decompressMsg = LibDeflate:DecompressDeflate(compressed)
if not serialized then
return nil, "Error decompressing: " .. tostring(decompressMsg)
end
local success, importTable = LibSerialize:Deserialize(serialized)
if not success then
return nil, "Error deserializing the data."
end
-- If it's a full profile, extract the relevant portion based on expectedDataType
if importTable.dataType == "fullProfile" then
if importTable.data[expectedDataType] then
-- Extract the relevant part and return it
return importTable.data[expectedDataType], nil
else
return importTable.data, nil
end
elseif importTable.dataType ~= expectedDataType then
return nil, "Data type mismatch"
end
return importTable.data, nil
elseif encodedString:sub(1, 4) == "!BBF" and encodedString:sub(-4) == "!BBF" then
return nil, "This is a BetterBlizz|cffff4040Frames|r profile string, not a BetterBlizz|cff40ff40Plates|r one. Two different addons."
else
-- If no !BBP, assume it's an other import and try to process it
local success, importTable = ImportOtherProfile(encodedString, expectedDataType)
-- Check if the import was successful and the expected data type is 'colorNpcList'
if success and (expectedDataType == "colorNpcList" or expectedDataType == "castEmphasisList") then
return nil, nil, true
else
return nil, "Invalid format or the imported data does not match the expected type."
end
end
end
local function deepMergeTables(destination, source)
for k, v in pairs(source) do
if type(v) == "table" then
if not destination[k] then
destination[k] = {}
end
deepMergeTables(destination[k], v) -- Recursive merge for nested tables
else
destination[k] = v
end
end
end
local tooltips = {
["5: Replace name with spec + ID on same row"] = "Shows as for example \"Frost 2\"",
["Off"] = "Turn the functionaly off and just use normal names",
}
local modes = {
["1: Replace name with Arena ID"] = "arenaIndicatorModeOne",
["2: Arena ID on top of name"] = "arenaIndicatorModeTwo",
["3: Replace name with spec"] = "arenaIndicatorModeThree",
["4: Replace name with spec + ID on top"] = "arenaIndicatorModeFour",
["5: Replace name with spec + ID on same row"] = "arenaIndicatorModeFive",
["Off"] = "arenaIndicatorModeOff",
}
local tooltipsParty = {
["5: Replace name with spec + ID on same row"] = "Shows as for example \"Frost 2\"",
["Off"] = "Turn the functionaly off and just use normal names",
}
local modesParty = {
["1: Replace name with Arena ID"] = "partyIndicatorModeOne",
["2: Arena ID on top of name"] = "partyIndicatorModeTwo",
["3: Replace name with spec"] = "partyIndicatorModeThree",
["4: Replace name with spec + ID on top"] = "partyIndicatorModeFour",
["5: Replace name with spec + ID on same row"] = "partyIndicatorModeFive",
["Off"] = "partyIndicatorModeOff",
}
StaticPopupDialogs["BBP_CONFIRM_RELOAD"] = {
text = "|A:gmchat-icon-blizz:16:16|a Better|cff00c0ffBlizz|rPlates: \n\nThis requires a reload. Reload now?",
button1 = "Yes",
button2 = "No",
OnAccept = function()
BetterBlizzPlatesDB.reopenOptions = true
ReloadUI()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["BBP_CONFIRM_WIPE_NPCCOLOR"] = {
text = titleText.."This will delete the entire npc color list and reload.\n\nAre you sure?",
button1 = "Yes",
button2 = "No",
OnAccept = function()
BetterBlizzPlatesDB.colorNpcList = {}
BetterBlizzPlatesDB.reopenOptions = true
ReloadUI()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["BBP_CONFIRM_WIPE_CASTEMPHASIS"] = {
text = titleText.."This will delete the entire cast list and reload.\n\nAre you sure?",
button1 = "Yes",
button2 = "No",
OnAccept = function()
BetterBlizzPlatesDB.castEmphasisList = {}
ReloadUI()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["BBP_CONFIRM_PROFILE"] = {
text = "",
button1 = "Yes",
button2 = "No",
OnAccept = function(self)
if self.data and self.data.func then
self.data.func()
end
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["BBP_TOTEMLIST_RESET"] = {
text = titleText.."This will delete the entire totem list and reset it back to its default state.\nA reload will be neccesary.\n\nAre you sure you want to continue?",
button1 = "Yes",
button2 = "No",
OnAccept = function()
BBP.ResetTotemList()
BetterBlizzPlatesDB.reopenOptions = true
ReloadUI()
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
------------------------------------------------------------
-- GUI Creation Functions
------------------------------------------------------------
local function CheckAndToggleCheckboxes(frame)
for i = 1, frame:GetNumChildren() do
local child = select(i, frame:GetChildren())
if child and (child:GetObjectType() == "CheckButton" or child:GetObjectType() == "Slider" or child:GetObjectType() == "Button") then
if frame:GetChecked() then
child:Enable()
child:SetAlpha(1)
else
child:Disable()
child:SetAlpha(0.5)
end
end
-- Check if the child has children and if it's a CheckButton or Slider
for j = 1, child:GetNumChildren() do
local childOfChild = select(j, child:GetChildren())
if childOfChild and (childOfChild:GetObjectType() == "CheckButton" or childOfChild:GetObjectType() == "Slider" or childOfChild:GetObjectType() == "Button") then
if child.GetChecked and child:GetChecked() and frame.GetChecked and frame:GetChecked() then
childOfChild:Enable()
childOfChild:SetAlpha(1)
else
childOfChild:Disable()
childOfChild:SetAlpha(0.5)
end
end
end
end
end
local function DisableElement(element)
element:Disable()
element:SetAlpha(0.5)
end
local function EnableElement(element)
element:Enable()
element:SetAlpha(1)
end
local function UpdateColorSquare(icon, r, g, b, a)
if r and g and b then
icon:SetColorTexture(r, g, b, a)
end
end
local function OpenColorPicker(colorType, icon)
-- Initialize color with default RGBA if not present
BetterBlizzPlatesDB[colorType] = BetterBlizzPlatesDB[colorType] or {1, 1, 1, 1}
local r, g, b, a = unpack(BetterBlizzPlatesDB[colorType])
BBP.needsUpdate = true
local function updateColors()
BetterBlizzPlatesDB[colorType] = {r, g, b, a}
if icon then
UpdateColorSquare(icon, r, g, b, a)
end
BBP.UpdateAuraTypeColors()
BBP.RefreshAllNameplates()
ColorPickerFrame.Content.ColorSwatchCurrent:SetAlpha(a)
end
local function swatchFunc()
r, g, b = ColorPickerFrame:GetColorRGB()
a = ColorPickerFrame:GetColorAlpha()
updateColors()
end
local function opacityFunc()
a = ColorPickerFrame:GetColorAlpha()
updateColors()
end
local function cancelFunc(previousValues)
if previousValues then
r, g, b, a = previousValues.r, previousValues.g, previousValues.b, previousValues.a
updateColors()
end
end
-- Setup and show the color picker
ColorPickerFrame.previousValues = {r, g, b, a}
ColorPickerFrame:SetupColorPickerAndShow({
r = r, g = g, b = b, opacity = a,
hasOpacity = true,
swatchFunc = swatchFunc,
opacityFunc = opacityFunc,
cancelFunc = cancelFunc,
previousValues = {r, g, b, a},
})
end
local function CreateColorBox(parent, colorVar, labelText)
local frame = CreateFrame("Frame", nil, parent)
frame:SetSize(55, 20) -- Adjust size as needed
frame:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, 0)
-- Border Frame (slightly larger to act as a border)
local borderFrame = CreateFrame("Frame", nil, frame)
borderFrame:SetSize(18, 18) -- Slightly larger than the color texture
borderFrame:SetPoint("LEFT", frame, "LEFT", 4, 0) -- Adjust to center the border around the color texture
local border = borderFrame:CreateTexture(nil, "OVERLAY", nil, 5)
border:SetAtlas("talents-node-square-gray")
border:SetAllPoints()
-- Create the color texture within the border frame
local colorTexture = borderFrame:CreateTexture(nil, "OVERLAY")
colorTexture:SetSize(15, 15) -- Adjust size as needed
colorTexture:SetPoint("CENTER", borderFrame, "CENTER", 0, 0)
colorTexture:SetColorTexture(unpack(BetterBlizzPlatesDB[colorVar] or {1, 1, 1}))
-- Label text for the color box
local text = frame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
text:SetText(labelText)
text:SetPoint("LEFT", borderFrame, "RIGHT", 5, 0) -- Adjust position as needed
-- Make the frame clickable and open a color picker on click
frame:SetScript("OnMouseDown", function()
if frame:GetAlpha() == 1 then
BBP.needsUpdate = true
OpenColorPicker(colorVar, colorTexture)
end
end)
local grandparent = parent:GetParent()
if parent:GetObjectType() == "CheckButton" and (parent:GetChecked() == false or (grandparent:GetObjectType() == "CheckButton" and grandparent:GetChecked() == false)) then
frame:SetAlpha(0.5)
else
frame:SetAlpha(1)
end
return frame
end
local function CreateBorderBox(anchor)
local contentFrame = anchor:GetParent()
local texture = contentFrame:CreateTexture(nil, "BACKGROUND")
texture:SetAtlas("UI-Frame-Neutral-PortraitWiderDisable")
texture:SetDesaturated(true)
texture:SetRotation(math.rad(90))
texture:SetSize(315, 163)
texture:SetPoint("CENTER", anchor, "CENTER", 0, -106)
return texture
end
local function CreateResetButton(relativeTo, settingKey, parent)
local resetButton = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
resetButton:SetText("Default")
resetButton:SetWidth(60)
resetButton:SetPoint("LEFT", relativeTo, "RIGHT", 10, 0)
resetButton:SetScript("OnClick", function()
BBP.ResetToDefaultValue(relativeTo, settingKey)
BBP.needsUpdate = true
end)
return resetButton
end
local function CreateModeDropdown(name, parent, defaultText, settingKey, toggleFunc, point, modes, tooltips, textLabel, textColor)
-- Create the dropdown frame using the library's creation function
local dropdown = LibDD:Create_UIDropDownMenu(name, parent)
LibDD:UIDropDownMenu_SetWidth(dropdown, 135)
LibDD:UIDropDownMenu_SetText(dropdown, BetterBlizzPlatesDB[settingKey] or defaultText)
-- Initialize the dropdown using the library's initialize function
LibDD:UIDropDownMenu_Initialize(dropdown, function(self, level, menuList)
local info = LibDD:UIDropDownMenu_CreateInfo()
local orderedKeys = {}
for displayText, _ in pairs(modes) do
table.insert(orderedKeys, displayText)
end
local dropdownTextFontString = _G[dropdown:GetName() .. "Text"]
if dropdownTextFontString then
-- Set text color (example: yellow)
dropdownTextFontString:SetTextColor(1, 1, 0) -- RGB for yellow
end
table.sort(orderedKeys)
for _, displayText in ipairs(orderedKeys) do
local dbKey = modes[displayText]
info.text = displayText
info.arg1 = dbKey
info.func = function(self, arg1, arg2, checked)
-- Set the selected mode to true and all others to false
for _, dbKeyIter in pairs(modes) do
BetterBlizzPlatesDB[dbKeyIter] = (dbKeyIter == arg1)
end
-- Store the selected mode's display text
BetterBlizzPlatesDB[settingKey] = displayText
LibDD:UIDropDownMenu_SetText(dropdown, displayText)
BBP.needsUpdate = true
toggleFunc(displayText)
end
info.checked = (BetterBlizzPlatesDB[settingKey] == displayText)
-- Color dropdown text
info.colorCode = "|cFFFFFF00"
-- Setting tooltip for specific menu items
if tooltips[displayText] then
info.tooltipTitle = displayText
info.tooltipText = tooltips[displayText]
info.tooltipOnButton = true
else
info.tooltipTitle = nil
info.tooltipText = nil
info.tooltipOnButton = nil
end
LibDD:UIDropDownMenu_AddButton(info)
end
end)
-- Position the dropdown
dropdown:SetPoint("TOPLEFT", point.anchorFrame, "TOPLEFT", point.x, point.y)
-- Create and set up the label
local dropdownText = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
local name, _, style = dropdownText:GetFont()
dropdownText:SetPoint("BOTTOM", dropdown, "TOP", 0, 3)
dropdownText:SetText(textLabel)
dropdownText:SetTextColor(unpack(textColor))
dropdownText:SetFont(name, 10, style)
return dropdown
end
local function CreateFontDropdown(name, parentFrame, defaultText, settingKey, toggleFunc, point, dropdownWidth, maxVisibleItems)
maxVisibleItems = maxVisibleItems or 25 -- Default to 25 visible items if not provided
-- Create container for label and dropdown
local container = CreateFrame("Frame", nil, parentFrame)
container:SetSize(dropdownWidth or 155, 50)
-- Create the dropdown button with the new dropdown template
local dropdown = CreateFrame("DropdownButton", nil, parentFrame, "WowStyle1DropdownTemplate")
dropdown:SetPoint("BOTTOMLEFT", container, "BOTTOMLEFT", 0, 0)
dropdown:SetWidth(dropdownWidth or 155)
dropdown:SetDefaultText(BetterBlizzPlatesDB[settingKey])
dropdown.Background:SetVertexColor(0.9,0.9,0.9)
dropdown.Arrow:SetVertexColor(0.9,0.9,0.9)
-- Custom font display for the selected font
-- dropdown.customFontText = dropdown:CreateFontString(nil, "OVERLAY", "GameFontNormal")
-- dropdown.customFontText:SetPoint("LEFT", dropdown, "LEFT", 8, 0)
-- dropdown.customFontText:SetText(BetterBlizzPlatesDB[settingKey] or defaultText)
-- dropdown.customFontText:SetTextColor(1,1,1)
-- local initialFont = LSM:Fetch(LSM.MediaType.FONT, BetterBlizzPlatesDB[settingKey] or "")
-- if initialFont then
-- dropdown.customFontText:SetFont(initialFont, 12)
-- end
-- Initialize a unique font pool for this dropdown
dropdown.fontPool = {}
-- Fetch and sort fonts
C_Timer.After(1, function()
local fonts = LSM:HashTable(LSM.MediaType.FONT)
local sortedFonts = {}
for fontName in pairs(fonts) do
table.insert(sortedFonts, fontName)
end
table.sort(sortedFonts)
-- Define the generator function for the dropdown menu
local function GeneratorFunction(owner, rootDescription)
local itemHeight = 20 -- Each item's height
local maxScrollExtent = maxVisibleItems * itemHeight
rootDescription:SetScrollMode(maxScrollExtent)
for index, fontName in ipairs(sortedFonts) do
local fontPath = fonts[fontName]
-- Create each item as a button with the custom font
local button = rootDescription:CreateButton(" ", function()
BetterBlizzPlatesDB[settingKey] = fontName
-- dropdown.customFontText:SetText(fontName)
-- dropdown.customFontText:SetFont(fontPath, 12)
dropdown:SetDefaultText(BetterBlizzPlatesDB[settingKey])
BBP.needsUpdate = true
toggleFunc(fontPath)
end)
-- Use the pooled font string for each button
button:AddInitializer(function(button)
local fontDisplay = dropdown.fontPool[index]
if not fontDisplay then
fontDisplay = dropdown:CreateFontString(nil, "BACKGROUND")
dropdown.fontPool[index] = fontDisplay
end
-- Attach the font display to the button and set the font
fontDisplay:SetParent(button)
fontDisplay:SetPoint("LEFT", button, "LEFT", 5, 0)
fontDisplay:SetFont(fontPath, 12)
fontDisplay:SetText(fontName)
fontDisplay:Show()
end)
end
end
-- Hide any unused font strings when the menu is closed
hooksecurefunc(dropdown, "OnMenuClosed", function()
for _, fontDisplay in pairs(dropdown.fontPool) do
fontDisplay:Hide()
end
end)
-- Set up the dropdown menu with the generator function
dropdown:SetupMenu(GeneratorFunction)
end)
-- Position the container on the specified anchor point
container:SetPoint("TOPLEFT", point.anchorFrame, "TOPLEFT", point.x, point.y)
return dropdown, container
end
local function CreateTextureDropdown(name, parentFrame, labelText, settingKey, toggleFunc, point, dropdownWidth, maxVisibleItems)
maxVisibleItems = maxVisibleItems or 25 -- Default to 25 visible items if not provided
-- Create container for label and dropdown
local container = CreateFrame("Frame", nil, parentFrame)
container:SetSize(dropdownWidth or 155, 50)
-- -- Create and position label
-- local label = container:CreateFontString(nil, "OVERLAY", "GameFontNormal")
-- label:SetPoint("BOTTOMLEFT", container, "TOPLEFT", 0, 2)
-- label:SetText(labelText)
-- Create the dropdown button with the new dropdown template
local dropdown = CreateFrame("DropdownButton", nil, parentFrame, "WowStyle1DropdownTemplate")
dropdown:SetPoint("BOTTOMLEFT", container, "BOTTOMLEFT", 0, 0)
dropdown:SetWidth(dropdownWidth or 155)
dropdown:SetDefaultText(BetterBlizzPlatesDB[settingKey] or "Select texture")
dropdown.Background:SetVertexColor(0.9,0.9,0.9)
dropdown.Arrow:SetVertexColor(0.9,0.9,0.9)
-- Initialize a unique texture pool for this dropdown
dropdown.texturePool = {}
-- Fetch and sort textures
C_Timer.After(1, function()
local textures = LSM:HashTable(LSM.MediaType.STATUSBAR)
local sortedTextures = {}
for textureName in pairs(textures) do
table.insert(sortedTextures, textureName)
end
table.sort(sortedTextures)
-- Get class colors table
local classColors = RAID_CLASS_COLORS
local classKeys = {}
for class in pairs(classColors) do
table.insert(classKeys, class)
end
-- Define the generator function for the dropdown menu
local function GeneratorFunction(owner, rootDescription)
local itemHeight = 20 -- Each item's height
local maxScrollExtent = maxVisibleItems * itemHeight
rootDescription:SetScrollMode(maxScrollExtent)
for index, textureName in ipairs(sortedTextures) do
local texturePath = textures[textureName]
-- Create each item as a button with the background texture
local button = rootDescription:CreateButton(textureName, function()
BetterBlizzPlatesDB[settingKey] = textureName
dropdown:SetDefaultText(textureName)
BBP.needsUpdate = true
toggleFunc(texturePath)
end)
-- Use the pooled texture for the background on each button
button:AddInitializer(function(button)
local textureBackground = dropdown.texturePool[index]
if not textureBackground then
textureBackground = dropdown:CreateTexture(nil, "BACKGROUND")
dropdown.texturePool[index] = textureBackground
end
-- Attach the background to the button and set the texture
textureBackground:SetParent(button)
textureBackground:SetAllPoints(button)
textureBackground:SetTexture(texturePath)
-- Pick a random class color and apply it
local randomClass = classKeys[math.random(#classKeys)]
local color = classColors[randomClass]
textureBackground:SetVertexColor(color.r, color.g, color.b)
textureBackground:Show()
end)
end
end
hooksecurefunc(dropdown, "OnMenuClosed", function()
for _, texture in pairs(dropdown.texturePool) do
texture:Hide()
end
end)
dropdown:SetupMenu(GeneratorFunction)
end)
container:SetPoint("TOPLEFT", point.anchorFrame, "TOPLEFT", point.x, point.y)
return dropdown, container
end
local function CreateAnchorDropdown(name, parent, defaultText, settingKey, toggleFunc, point, width, textColor)
-- Create the dropdown frame using the library's creation function
local dropdown = LibDD:Create_UIDropDownMenu(name, parent)
LibDD:UIDropDownMenu_SetWidth(dropdown, width or 125)
LibDD:UIDropDownMenu_SetText(dropdown, BetterBlizzPlatesDB[settingKey] or defaultText)
local anchorPointsToUse = anchorPoints
if name == "targetIndicatorDropdown" then
anchorPointsToUse = targetIndicatorAnchorPoints
end
-- Initialize the dropdown using the library's initialize function
LibDD:UIDropDownMenu_Initialize(dropdown, function(self, level, menuList)
local info = LibDD:UIDropDownMenu_CreateInfo()
for _, anchor in ipairs(anchorPointsToUse) do
info.text = anchor
info.arg1 = anchor
info.func = function(self, arg1)
if BetterBlizzPlatesDB[settingKey] ~= arg1 then
BetterBlizzPlatesDB[settingKey] = arg1
LibDD:UIDropDownMenu_SetText(dropdown, arg1)
BBP.needsUpdate = true
toggleFunc(arg1)
BBP.RefreshAllNameplates()
end
end
info.checked = (BetterBlizzPlatesDB[settingKey] == anchor)
LibDD:UIDropDownMenu_AddButton(info)
end
end)
-- Position the dropdown
dropdown:SetPoint("TOPLEFT", point.anchorFrame, "TOPLEFT", point.x, point.y)
-- Create and set up the label
local dropdownText = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
dropdownText:SetPoint("BOTTOM", dropdown, "TOP", 0, 3)
dropdownText:SetText(point.label)
if textColor then
dropdownText:SetTextColor(unpack(textColor))
end
-- Enable or disable the dropdown based on the parent's check state
if parent:GetObjectType() == "CheckButton" and parent:GetChecked() == false then
LibDD:UIDropDownMenu_DisableDropDown(dropdown)
else
LibDD:UIDropDownMenu_EnableDropDown(dropdown)
end
return dropdown
end
local function CreateSlider(parent, label, minValue, maxValue, stepValue, element, axis, width)
local slider = CreateFrame("Slider", name, parent, "OptionsSliderTemplate")
slider:SetOrientation('HORIZONTAL')
slider:SetMinMaxValues(minValue, maxValue)
slider:SetValueStep(stepValue)
slider:SetObeyStepOnDrag(true)
slider.Text:SetFontObject(GameFontHighlightSmall)
slider.Text:SetTextColor(1, 0.81, 0, 1)
slider.Low:SetText(" ")
slider.High:SetText(" ")
table.insert(sliderList, {
slider = slider,
label = label,
element = element
})
if width then
slider:SetWidth(width)
end
local function UpdateSliderRange(newValue, minValue, maxValue)
newValue = tonumber(newValue) -- Convert newValue to a number
if (axis == "X" or axis == "Y") and (newValue < minValue or newValue > maxValue) then
-- For X or Y axis: extend the range by ±30
local newMinValue = math.min(newValue - 30, minValue)
local newMaxValue = math.max(newValue + 30, maxValue)
slider:SetMinMaxValues(newMinValue, newMaxValue)
elseif newValue < minValue or newValue > maxValue then
-- For other sliders: adjust the range, ensuring it never goes below a specified minimum (e.g., 0)
local nonAxisRangeExtension = 2
local newMinValue = math.max(newValue - nonAxisRangeExtension, 0.1) -- Prevent going below 0.1
local newMaxValue = math.max(newValue + nonAxisRangeExtension, maxValue)
slider:SetMinMaxValues(newMinValue, newMaxValue)
end
end
local function SetSliderValue()
if BBP.variablesLoaded and BBP.CVarsAreSaved() then
local initialValue = tonumber(BetterBlizzPlatesDB[element]) -- Convert to number
if initialValue then
local currentMin, currentMax = slider:GetMinMaxValues() -- Fetch the latest min and max values
-- Check if the initial value is outside the current range and update range if necessary
UpdateSliderRange(initialValue, currentMin, currentMax)
slider:SetValue(initialValue) -- Set the initial value
local textValue = initialValue % 1 == 0 and tostring(math.floor(initialValue)) or string.format("%.2f", initialValue)
slider.Text:SetText(label .. ": " .. textValue)
end
else
C_Timer.After(0.1, SetSliderValue)
end
end
SetSliderValue()
local function SetSliderState()
if not BBP.variablesLoaded then
C_Timer.After(0.5, function()
SetSliderState()
end)
else
if parent:GetObjectType() == "CheckButton" and parent:GetChecked() == false then
slider:Disable()
slider:SetAlpha(0.5)
else
if parent:GetObjectType() == "CheckButton" and parent:IsEnabled() then
slider:Enable()
slider:SetAlpha(1)
elseif parent:GetObjectType() ~= "CheckButton" then
slider:Enable()
slider:SetAlpha(1)
end
end
end
end
SetSliderState()
-- Create Input Box on Right Click
local editBox = CreateFrame("EditBox", nil, slider, "InputBoxTemplate")
editBox:SetAutoFocus(false)
editBox:SetWidth(50) -- Set the width of the EditBox
editBox:SetHeight(20) -- Set the height of the EditBox
editBox:SetMultiLine(false)
editBox:SetPoint("CENTER", slider, "CENTER", 0, 0) -- Position it to the right of the slider
editBox:SetFrameStrata("DIALOG") -- Ensure it appears above other UI elements
editBox:Hide()
editBox:SetFontObject(GameFontHighlightSmall)
local function SliderOnValueChanged(self, value)
if not BetterBlizzPlatesDB.wasOnLoadingScreen then
BBP.needsUpdate = true
local textValue = value % 1 == 0 and tostring(math.floor(value)) or string.format("%.2f", value)
self.Text:SetText(label .. ": " .. textValue)
value = tonumber(textValue)
--if not BBP.checkCombatAndWarn() then
-- Update the X or Y position based on the axis
if axis == "X" then
BetterBlizzPlatesDB[element .. "XPos"] = value
elseif axis == "Y" then
BetterBlizzPlatesDB[element .. "YPos"] = value
elseif axis == "Alpha" then
BetterBlizzPlatesDB[element .. "Alpha"] = value
elseif axis == "Height" then
BetterBlizzPlatesDB[element .. "Height"] = value
end
if not axis then
BetterBlizzPlatesDB[element .. "Scale"] = value
end
local xPos = BetterBlizzPlatesDB[element .. "XPos"] or 0
local yPos = BetterBlizzPlatesDB[element .. "YPos"] or 0
local anchorPoint = BetterBlizzPlatesDB[element .. "Anchor"] or "CENTER"
--If no nameplates are present still adjust values
if element == "NamePlateVerticalScale" then
BetterBlizzPlatesDB.NamePlateVerticalScale = value
if not BBP.checkCombatAndWarn() then
BBP.ApplyNameplateWidth()
BBP.RefreshAllNameplates()
end
elseif element == "partyPointerScale" then
BetterBlizzPlatesDB.partyPointerScale = value
elseif element == "partyPointerHealerScale" then
BetterBlizzPlatesDB.partyPointerHealerScale = value
elseif element == "partyPointerXPos" then
BetterBlizzPlatesDB.partyPointerXPos = value
elseif element == "partyPointerYPos" then
BetterBlizzPlatesDB.partyPointerYPos = value
elseif element == "partyPointerWidth" then
BetterBlizzPlatesDB.partyPointerWidth = value
elseif element == "hpHeightEnemy" then
BetterBlizzPlatesDB.hpHeightEnemy = value
elseif element == "hpHeightFriendly" then
BetterBlizzPlatesDB.hpHeightFriendly = value
elseif element == "healthNumbersScale" then
BetterBlizzPlatesDB.healthNumbersScale = value
elseif element == "healthNumbersXPos" then
BetterBlizzPlatesDB.healthNumbersXPos = value
elseif element == "healthNumbersYPos" then
BetterBlizzPlatesDB.healthNumbersYPos = value
elseif element == "fakeNameXPos" then
BetterBlizzPlatesDB.fakeNameXPos = value
elseif element == "fakeNameYPos" then
BetterBlizzPlatesDB.fakeNameYPos = value
elseif element == "fakeNameFriendlyXPos" then
BetterBlizzPlatesDB.fakeNameFriendlyXPos = value
elseif element == "fakeNameFriendlyYPos" then
BetterBlizzPlatesDB.fakeNameFriendlyYPos = value
elseif element == "hideNpcMurlocScale" then
BetterBlizzPlatesDB.hideNpcMurlocScale = value
elseif element == "hideNpcMurlocYPos" then
BetterBlizzPlatesDB.hideNpcMurlocYPos = value
elseif element == "nameplateAuraEnlargedScale" then
BetterBlizzPlatesDB.nameplateAuraEnlargedScale = value
elseif element == "nameplateAuraCompactedScale" then
BetterBlizzPlatesDB.nameplateAuraCompactedScale = value
elseif element == "nameplateAuraBuffScale" then
BetterBlizzPlatesDB.nameplateAuraBuffScale = value
elseif element == "nameplateAuraDebuffScale" then
BetterBlizzPlatesDB.nameplateAuraDebuffScale = value
-- Absorb Indicator Pos and Scale
elseif element == "absorbIndicatorXPos" then
BetterBlizzPlatesDB.absorbIndicatorXPos = value
elseif element == "absorbIndicatorYPos" then
BetterBlizzPlatesDB.absorbIndicatorYPos = value
elseif element == "absorbIndicatorScale" then
BetterBlizzPlatesDB.absorbIndicatorScale = value
-- Combat Indicator Pos and Scale
elseif element == "combatIndicatorXPos" then
BetterBlizzPlatesDB.combatIndicatorXPos = value
elseif element == "combatIndicatorYPos" then
BetterBlizzPlatesDB.combatIndicatorYPos = value
elseif element == "combatIndicatorScale" then
BetterBlizzPlatesDB.combatIndicatorScale = value
-- Healer Indicator Pos and Scale
elseif element == "healerIndicatorXPos" then
BetterBlizzPlatesDB.healerIndicatorXPos = value
elseif element == "healerIndicatorYPos" then
BetterBlizzPlatesDB.healerIndicatorYPos = value
elseif element == "healerIndicatorScale" then
BetterBlizzPlatesDB.healerIndicatorScale = value
elseif element == "healerIndicatorEnemyXPos" then
BetterBlizzPlatesDB.healerIndicatorEnemyXPos = value
elseif element == "healerIndicatorEnemyYPos" then
BetterBlizzPlatesDB.healerIndicatorEnemyYPos = value
elseif element == "healerIndicatorEnemyScale" then
BetterBlizzPlatesDB.healerIndicatorEnemyScale = value
-- Pet Indicator Pos and Scale
elseif element == "petIndicatorXPos" then
BetterBlizzPlatesDB.petIndicatorXPos = value
elseif element == "petIndicatorYPos" then
BetterBlizzPlatesDB.petIndicatorYPos = value
elseif element == "petIndicatorScale" then
BetterBlizzPlatesDB.petIndicatorScale = value
-- Quest Indicator Pos and Scale
elseif element == "questIndicatorXPos" then
BetterBlizzPlatesDB.questIndicatorXPos = value
elseif element == "questIndicatorYPos" then
BetterBlizzPlatesDB.questIndicatorYPos = value
elseif element == "questIndicatorScale" then
BetterBlizzPlatesDB.questIndicatorScale = value
-- Execute Indicator Pos and Scale
elseif element == "executeIndicatorXPos" then
BetterBlizzPlatesDB.executeIndicatorXPos = value
elseif element == "executeIndicatorYPos" then
BetterBlizzPlatesDB.executeIndicatorYPos = value
elseif element == "executeIndicatorScale" then
BetterBlizzPlatesDB.executeIndicatorScale = value
-- Target Indicator Pos and Scale
elseif element == "targetIndicatorXPos" then
BetterBlizzPlatesDB.targetIndicatorXPos = value
elseif element == "targetIndicatorYPos" then
BetterBlizzPlatesDB.targetIndicatorYPos = value
elseif element == "targetIndicatorScale" then
BetterBlizzPlatesDB.targetIndicatorScale = value
-- Focus Target Indicator Pos and Scale
elseif element == "focusTargetIndicatorXPos" then
BetterBlizzPlatesDB.focusTargetIndicatorXPos = value
elseif element == "focusTargetIndicatorYPos" then
BetterBlizzPlatesDB.focusTargetIndicatorYPos = value
elseif element == "focusTargetIndicatorScale" then
BetterBlizzPlatesDB.focusTargetIndicatorScale = value
-- Raidmarker Indicator Pos and Scale
elseif element == "raidmarkIndicatorXPos" then
BetterBlizzPlatesDB.raidmarkIndicatorXPos = value
elseif element == "raidmarkIndicatorYPos" then
BetterBlizzPlatesDB.raidmarkIndicatorYPos = value
elseif element == "raidmarkIndicatorScale" then
BetterBlizzPlatesDB.raidmarkIndicatorScale = value
-- Bg Blitz
elseif element == "bgIndicatorXPos" then
BetterBlizzPlatesDB.bgIndicatorXPos = value
elseif element == "bgIndicatorYPos" then
BetterBlizzPlatesDB.bgIndicatorYPos = value
elseif element == "bgIndicatorScale" then
BetterBlizzPlatesDB.bgIndicatorScale = value
-- Totem Indicator Pos and Scale
elseif element == "totemIndicatorXPos" then
BetterBlizzPlatesDB.totemIndicatorXPos = value
elseif element == "totemIndicatorYPos" then
BetterBlizzPlatesDB.totemIndicatorYPos = value
elseif element == "totemIndicatorScale" then
BetterBlizzPlatesDB.totemIndicatorScale = value
elseif element == "executeIndicatorThreshold" then
BetterBlizzPlatesDB.executeIndicatorThreshold = value
elseif element == "castBarHeight" then
BetterBlizzPlatesDB.castBarHeight = value
elseif element == "castBarTextScale" then
BetterBlizzPlatesDB.castBarTextScale = value
elseif element == "castBarIconScale" then
BetterBlizzPlatesDB.castBarIconScale = value
elseif element == "castBarIconXPos" then
BetterBlizzPlatesDB.castBarIconXPos = value
elseif element == "castBarIconYPos" then
BetterBlizzPlatesDB.castBarIconYPos = value
elseif element == "castBarEmphasisSparkHeight" then
BetterBlizzPlatesDB.castBarEmphasisSparkHeight = value
elseif element == "castBarEmphasisIconScale" then
BetterBlizzPlatesDB.castBarEmphasisIconScale = value
elseif element == "classIndicatorXPos" then
BetterBlizzPlatesDB.classIndicatorXPos = value
elseif element == "classIndicatorYPos" then
BetterBlizzPlatesDB.classIndicatorYPos = value
elseif element == "classIndicatorScale" then
BetterBlizzPlatesDB.classIndicatorScale = value
elseif element == "classIndicatorFriendlyXPos" then
BetterBlizzPlatesDB.classIndicatorFriendlyXPos = value
elseif element == "classIndicatorFriendlyYPos" then
BetterBlizzPlatesDB.classIndicatorFriendlyYPos = value
elseif element == "classIndicatorFriendlyScale" then
BetterBlizzPlatesDB.classIndicatorFriendlyScale = value
-- Nameplate Widths
elseif element == "nameplateFriendlyWidth" then
if not BBP.checkCombatAndWarn() then
BetterBlizzPlatesDB.nameplateFriendlyWidth = value
local heightValue
if BetterBlizzPlatesDB.friendlyNameplateClickthrough then
heightValue = 1
else
heightValue = BBP.isLargeNameplatesEnabled() and 64.125 or 40
end
C_NamePlate.SetNamePlateFriendlySize(value, heightValue)
end
elseif element == "personalBarPosition" then
if not BBP.checkCombatAndWarn() then
BBP.SetPersonalResourceBarPosition(value)
BetterBlizzPlatesDB.personalBarPosition = value
end
elseif element == "nameplateEnemyWidth" then
if not BBP.checkCombatAndWarn() then
BetterBlizzPlatesDB.nameplateEnemyWidth = value
local heightValue
heightValue = BBP.isLargeNameplatesEnabled() and 64.125 or 40
C_NamePlate.SetNamePlateEnemySize(value, heightValue)
end
elseif element == "nameplateSelfWidth" then
if not BBP.checkCombatAndWarn() then
BetterBlizzPlatesDB.nameplateSelfWidth = value
local heightValue
heightValue = 45 --BBP.isLargeNameplatesEnabled() and 64.125 or 40
C_NamePlate.SetNamePlateSelfSize(value, heightValue)
end
-- Cast bar emphasis height
elseif element == "castBarEmphasisHeightValue" then