This repository was archived by the owner on Apr 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsUI.lua
More file actions
1365 lines (1214 loc) · 60.8 KB
/
SettingsUI.lua
File metadata and controls
1365 lines (1214 loc) · 60.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName = "GCast"
local _G = _G
local GCast = _G[addonName] or {}
_G[addonName] = GCast
GCast.SettingsUI = GCast.SettingsUI or {}
function GCast.SettingsUI:CreateControl(parent, frameType, template, size, point, extras)
if not frameType or frameType == "" or type(frameType) ~= "string" then
error("Invalid frame type: " .. tostring(frameType))
end
if template and type(template) ~= "string" then
error("Invalid template: " .. tostring(template))
end
if parent and type(parent) ~= "table" then
error("Invalid parent: " .. tostring(parent))
end
if extras and type(extras) ~= "function" then
error("Invalid extras: " .. tostring(extras))
end
local frame = CreateFrame(frameType, nil, parent, template)
if not frame then
error("Failed to create frame: type=" .. tostring(frameType) .. ", template=" .. tostring(template) .. ", parent=" .. tostring(parent))
end
if size then frame:SetSize(unpack(size)) end
if point then frame:SetPoint(unpack(point)) end
if extras then extras(frame) end
return frame
end
function GCast.SettingsUI:InitDottedFrame()
if GCast.dottedFrame then return end
GCast.dottedFrame = CreateFrame("Frame", "GCastDottedFrame", UIParent, "BackdropTemplate")
GCast.dottedFrame:SetSize(GCast.db.global.visual.size or 50, GCast.db.global.visual.size or 50)
GCast.dottedFrame:SetPoint("CENTER", UIParent, "CENTER", GCast.db.player.visual.startPoint.x or 0, GCast.db.player.visual.startPoint.y or 0)
GCast.dottedFrame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 32, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
})
GCast.dottedFrame:Hide()
GCast.dottedFrame:EnableMouse(true)
GCast.dottedFrame:SetMovable(true)
GCast.dottedFrame:RegisterForDrag("LeftButton")
GCast.dottedFrame:SetScript("OnDragStart", function(frame)
if GCast.db.player.visual.editMode then
frame:StartMoving()
GCast.Utils:Log("Started dragging dotted frame", true)
end
end)
GCast.dottedFrame:SetScript("OnMouseUp", function(frame, button)
if GCast.db.player.visual.editMode and button == "LeftButton" then
frame:StopMovingOrSizing()
local x, y = frame:GetCenter()
local parentX, parentY = UIParent:GetCenter()
local newX = x and parentX and tonumber(string.format("%.1f", x - parentX)) or 0
local newY = y and parentY and tonumber(string.format("%.1f", y - parentY)) or 0
GCast.SettingsUI:UpdateStartPoint(newX, newY)
GCast.Utils:Log("Updated coordinates: x=" .. newX .. ", y=" .. newY, true)
end
end)
GCast.dottedFrame:SetScript("OnDragStop", function(frame)
if GCast.db.player.visual.editMode then
frame:StopMovingOrSizing()
local x, y = frame:GetCenter()
local parentX, parentY = UIParent:GetCenter()
local newX = x and parentX and tonumber(string.format("%.1f", x - parentX)) or 0
local newY = y and parentY and tonumber(string.format("%.1f", y - parentY)) or 0
GCast.SettingsUI:UpdateStartPoint(newX, newY)
GCast.Utils:Log("Updated coordinates: x=" .. newX .. ", y=" .. newY, true)
end
end)
GCast.dottedFrame:SetScript("OnUpdate", function(frame, elapsed)
if GCast.db.player.visual.editMode and IsMouseButtonDown("LeftButton") then
local lastUpdate = frame.lastUpdate or 0
if GetTime() - lastUpdate > 0.1 then
local x, y = frame:GetCenter()
local parentX, parentY = UIParent:GetCenter()
local newX = x and parentX and tonumber(string.format("%.1f", x - parentX)) or 0
local newY = y and parentY and tonumber(string.format("%.1f", y - parentY)) or 0
GCast.SettingsUI:UpdateStartPoint(newX, newY)
frame.lastUpdate = GetTime()
GCast.Utils:Log("Real-time coordinate update: x=" .. newX .. ", y=" .. newY, true)
end
end
end)
GCast.dottedFrame:SetScript("OnKeyDown", function(self, key)
if key == "ESCAPE" and GCast.db.player.visual.editMode then
GCast.db.player.visual.editMode = false
GCast.dottedFrame:Hide()
local coordPanel = _G["GCastCoordPanel"]
if coordPanel then
coordPanel:Hide()
GCast.Utils:Log("Hid coord panel on ESC", true)
end
if _G["GCastSettings"] and _G["GCastSettings"]:IsShown() then
local editButton = _G["GCastSettings"]:GetChildren()
if editButton and editButton.SetText then
editButton:SetText(GCast.L["Toggle Edit Mode"] or "Toggle Edit Mode")
end
end
GCast.Utils:Log("Exited edit mode via ESC", true)
end
end)
GCast.dottedFrame:EnableKeyboard(true)
end
function GCast.SettingsUI:UpdateStartPoint(x, y)
GCast.DB:EnsureInitialized()
if type(x) ~= "number" or type(y) ~= "number" then
GCast.Utils:Log("Invalid coordinates x=" .. tostring(x) .. ", y=" .. tostring(y))
return
end
GCast.db.player.visual.startPoint = GCast.db.player.visual.startPoint or {}
GCast.db.player.visual.startPoint.x = x
GCast.db.player.visual.startPoint.y = y
if GCast.dottedFrame then
GCast.dottedFrame:ClearAllPoints()
GCast.dottedFrame:SetPoint("CENTER", UIParent, "CENTER", x, y)
end
local coordPanel = _G["GCastCoordPanel"]
if coordPanel then
local xEdit = coordPanel.xEdit
local yEdit = coordPanel.yEdit
if xEdit then xEdit:SetText(string.format("%.1f", x)) end
if yEdit then yEdit:SetText(string.format("%.1f", y)) end
GCast.Utils:Log("Updated coord panel: x=" .. x .. ", y=" .. y, true)
end
end
function GCast.SettingsUI:ToggleSettingsUI()
if not GCast.settingsPanel then
GCast.settingsPanel = GCast.SettingsUI:CreateSettingsPanel()
if not GCast.settingsPanel then
GCast.Utils:Log("Failed to create settings panel")
return
end
end
if GCast.settingsPanel:IsShown() then
GCast.settingsPanel:Hide()
GCast.Utils:Log("Hid settings panel", true)
else
GCast.settingsPanel:Show()
if not GCast.db.player.visual.editMode then
tinsert(UISpecialFrames, "GCastSettings")
end
local currentTab = 1
for i = 1, 2 do
local tab = _G["GCastTab"..i]
if tab and not tab:IsEnabled() then
currentTab = i
break
end
end
local content = _G["GCastTabContent"..currentTab]
if content and content.Update then
content:Update()
end
GCast:UpdateKeybindOverlays()
if GCast.currentClassCooldownManager and GCast.currentClassCooldownManager.syncGlobalSettings then
GCast.currentClassCooldownManager:syncGlobalSettings()
end
GCast.Utils:Log("Showed settings panel, active tab=" .. currentTab, true)
end
end
local function UpdateSpellList(scrollChild, spellList, settings, isKeybindMode, categoryIndex)
for _, child in ipairs({scrollChild:GetChildren()}) do
child:Hide()
child:ClearAllPoints()
end
local scrollFrame = scrollChild:GetParent()
if not scrollFrame then
GCast.Utils:Log("ScrollFrame not found")
return
end
scrollFrame:Show()
scrollChild:Show()
if #spellList == 0 then
local noSpellLabel = scrollChild.noSpellLabel
if not noSpellLabel then
noSpellLabel = scrollChild:CreateFontString(nil, "OVERLAY", "GameFontNormal")
noSpellLabel:SetPoint("CENTER", scrollChild, "CENTER", 0, 0)
noSpellLabel:SetText(GCast.L["No Spells"])
noSpellLabel:SetTextColor(0.7, 0.7, 0.7)
scrollChild.noSpellLabel = noSpellLabel
end
noSpellLabel:Show()
scrollChild:SetSize(270, 300)
scrollFrame:SetHeight(290)
if scrollFrame:GetParent() then
scrollFrame:GetParent():SetHeight(300)
end
scrollFrame:UpdateScrollChildRect()
return
end
if scrollChild.noSpellLabel then
scrollChild.noSpellLabel:Hide()
end
if isKeybindMode then
local withKeybinds = {}
local withoutKeybinds = {}
for _, spell in ipairs(spellList) do
local keybindValue = settings.customKeybinds[tostring(spell.id)]
if keybindValue and keybindValue ~= "" then
table.insert(withKeybinds, spell)
else
table.insert(withoutKeybinds, spell)
end
end
table.sort(withKeybinds, function(a, b) return a.name < b.name end)
table.sort(withoutKeybinds, function(a, b) return a.name < b.name end)
spellList = {}
for _, spell in ipairs(withKeybinds) do
table.insert(spellList, spell)
end
for _, spell in ipairs(withoutKeybinds) do
table.insert(spellList, spell)
end
end
local itemHeight = 28
local totalHeight = math.max(300, #spellList * itemHeight + 20)
scrollChild:SetSize(270, totalHeight)
local containerHeight = math.min(300, totalHeight)
scrollFrame:SetHeight(containerHeight)
if scrollFrame:GetParent() then
scrollFrame:GetParent():SetHeight(containerHeight + 10)
end
local rowWidth = 270
for i, spell in ipairs(spellList) do
local row = CreateFrame("Frame", nil, scrollChild)
row:SetSize(rowWidth, itemHeight)
row:SetPoint("TOPLEFT", scrollChild, "TOPLEFT", 0, -((i-1) * itemHeight + 10))
row:SetFrameLevel(scrollChild:GetFrameLevel() + 1)
row:Show()
if i % 2 == 0 then
local bg = row:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints(row)
bg:SetColorTexture(0.2, 0.2, 0.2, 0.3)
bg:Show()
end
local spellText = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
spellText:SetPoint("LEFT", isKeybindMode and 30 or 50, 0)
spellText:SetWidth(isKeybindMode and 200 or 170)
spellText:SetJustifyH("LEFT")
spellText:SetText(spell.name)
if isKeybindMode then
local keybindValue = settings.customKeybinds[tostring(spell.id)]
if not keybindValue or keybindValue == "" then
spellText:SetTextColor(0.5, 0.5, 0.5)
else
spellText:SetTextColor(1, 1, 1)
end
local keybindEdit = GCast.Utils:CreateEditBox(row, {50, 20}, {"LEFT", spellText, "RIGHT", -10, 0}, false, 20, function(edit)
edit:SetFontObject("GameFontHighlight")
edit:SetTextInsets(8, 8, 0, 0)
edit:SetJustifyH("RIGHT")
edit:SetTextColor(1, 1, 0)
edit:Show()
end)
keybindEdit:SetText(keybindValue or "")
keybindEdit:SetScript("OnEnterPressed", function(self)
local bindText = self:GetText()
local idStr = tostring(spell.id)
if bindText and bindText ~= "" then
GCast.Keybinds:SetSpellBinding(spell.id, bindText, categoryIndex)
spellText:SetTextColor(1, 1, 1)
else
GCast.Keybinds:ClearSpellBinding(spell.id, categoryIndex)
spellText:SetTextColor(0.5, 0.5, 0.5)
end
self:ClearFocus()
GCast.Keybinds:UpdateOverlays(categoryIndex)
pcall(GCast.DB.SaveSettings)
local currentSpells = {}
for _, s in ipairs(spellList) do
table.insert(currentSpells, s)
end
local withKeybinds = {}
local withoutKeybinds = {}
for _, s in ipairs(currentSpells) do
local keybindValue = settings.customKeybinds[tostring(s.id)]
if keybindValue and keybindValue ~= "" then
table.insert(withKeybinds, s)
else
table.insert(withoutKeybinds, s)
end
end
table.sort(withKeybinds, function(a, b) return a.name < b.name end)
table.sort(withoutKeybinds, function(a, b) return a.name < b.name end)
currentSpells = {}
for _, s in ipairs(withKeybinds) do
table.insert(currentSpells, s)
end
for _, s in ipairs(withoutKeybinds) do
table.insert(currentSpells, s)
end
UpdateSpellList(scrollChild, currentSpells, settings, isKeybindMode, categoryIndex)
end)
keybindEdit:SetScript("OnEscapePressed", function(self)
self:ClearFocus()
end)
else
local removeButton = GCast.Utils:CreateButton(row, "-", {30, 20}, function()
local spellID = tostring(spell.id)
GCast.db.player.visual.enabledSpells[spellID] = nil
GCast.Utils:Log("Removed spell ID " .. spellID .. " (" .. spell.name .. ")", true)
pcall(GCast.DB.SaveSettings)
local visualContent = _G["GCastTabContent1"]
if visualContent and visualContent.Update then
visualContent:Update()
GCast.Utils:Log("Visual spell list updated", true)
else
GCast.Utils:Log("Failed to update visual spell list")
end
local spellsStr = ""
for k, v in pairs(GCast.db.player.visual.enabledSpells) do
spellsStr = spellsStr .. k .. "=" .. v .. ", "
end
GCast.Utils:Log("enabledSpells=" .. (spellsStr == "" and "empty" or spellsStr), true)
end)
removeButton:SetPoint("LEFT", 10, 0)
removeButton:Show()
end
end
scrollFrame:UpdateScrollChildRect()
scrollFrame:SetVerticalScroll(0)
scrollFrame:Show()
scrollChild:Show()
if scrollFrame:GetParent() then
scrollFrame:GetParent():Show()
end
GCast.Utils:Log("Rendered spell list with " .. #spellList .. " spells", true)
end
function GCast.SettingsUI:CreateSettingsPanel()
GCast.DB:EnsureInitialized()
local panel = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
if not panel then
GCast.Utils:Log("Failed to create settings panel")
return nil
end
panel:SetSize(800, 600)
panel:SetPoint("CENTER")
panel:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 32,
insets = { left = 11, right = 12, top = 12, bottom = 11 }
})
panel:Hide()
panel:SetMovable(true)
panel:EnableMouse(true)
panel:RegisterForDrag("LeftButton")
panel:SetScript("OnDragStart", panel.StartMoving)
panel:SetScript("OnDragStop", panel.StopMovingOrSizing)
panel:SetFrameStrata("DIALOG")
GCast.settingsPanel = panel
local title = panel:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOP", 0, -20)
title:SetText(GCast.L["GCast Settings"])
local closeButton = GCast.SettingsUI:CreateControl(panel, "Button", "UIPanelCloseButton", nil, {"TOPRIGHT", -5, -5})
local tabContainer = CreateFrame("Frame", nil, panel)
tabContainer:SetPoint("TOPLEFT", 40, -50)
tabContainer:SetSize(400, 32)
local visualEffectSpellListFrame
local function CreateTabButton(id, text)
local button = GCast.Utils:CreateButton(tabContainer, text, {200, 32}, function(self)
for i = 1, 2 do
local content = _G["GCastTabContent"..i]
local tab = _G["GCastTab"..i]
if content then content:Hide() end
if tab then tab:Enable() end
end
local content = _G["GCastTabContent"..id]
if content then
content:Show()
if content.Update then
content:Update()
if id == 1 and visualEffectSpellListFrame and visualEffectSpellListFrame.scrollFrame then
visualEffectSpellListFrame.scrollFrame:UpdateScrollChildRect()
GCast.Utils:Log("Visual effect tab scroll frame updated", true)
end
end
end
self:Disable()
end)
button:SetID(id)
button:SetPoint("TOPLEFT", (id - 1) * 220, 0)
_G["GCastTab"..id] = button
return button
end
local function CreateTabContent(id)
local content = CreateFrame("Frame", "GCastTabContent"..id, panel)
content:SetPoint("TOPLEFT", 50, -70)
content:SetPoint("BOTTOMRIGHT", -50, 25)
content:Hide()
content:SetFrameStrata("DIALOG")
return content
end
local visualTab = CreateTabButton(1, GCast.L["Visual Effects"])
local keybindTab = CreateTabButton(2, GCast.L["Cooldown Manager Keybinds"])
local visualContent = CreateTabContent(1)
local keybindContent = CreateTabContent(2)
local function CreateVisualSliders(content)
local sliders = {
{ label = GCast.L["Size"], key = "size", x = 10, y = -70, width = 60, default = 50 },
{ label = GCast.L["Opacity"], key = "opacity", x = 180, y = -70, width = 60, default = 100 },
{ label = GCast.L["Flight Duration"], key = "flightDuration", x = 10, y = -110, width = 60, default = 20 },
{ label = GCast.L["Fade-Out Duration"], key = "fadeOutDuration", x = 180, y = -110, width = 60, default = 25 }
}
local slidersLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
slidersLabel:SetPoint("TOPLEFT", 10, -30)
slidersLabel:SetText(GCast.L["Visual Settings"])
for _, s in ipairs(sliders) do
local label = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("TOPLEFT", s.x, s.y)
label:SetText(s.label .. ":")
GCast.editBoxes[s.key] = GCast.Utils:CreateEditBox(content, {s.width, 20}, {"LEFT", label, "RIGHT", 10, 0}, true, nil, function(edit)
edit:SetNumeric(true)
edit:SetAutoFocus(false)
end)
local value = GCast.db.global.visual[s.key] or s.default
if GCast.editBoxes[s.key] then
GCast.editBoxes[s.key]:SetText(tostring(value))
GCast.editBoxes[s.key]:SetScript("OnEnterPressed", function(self)
local newValue = tonumber(self:GetText()) or s.default
GCast:UpdateConfig(s.key, newValue)
self:SetText(tostring(newValue))
self:ClearFocus()
end)
end
end
return slidersLabel
end
local function CreateEditButton(content, slidersLabel)
local editButton = GCast.Utils:CreateButton(content, GCast.L["Toggle Edit Mode"], {150, 28}, function(self)
local enteringEditMode = not GCast.db.player.visual.editMode
if enteringEditMode then
local coordPanel = _G["GCastCoordPanel"] or GCast.SettingsUI:CreateCoordPanel()
if coordPanel then
coordPanel:Show()
GCast.Utils:Log("Showing coord panel", true)
else
GCast.Utils:Log("Failed to create coord panel")
end
GCast.db.player.visual.editMode = true
if GCast.dottedFrame then GCast.dottedFrame:Show() end
for i, frameName in ipairs(UISpecialFrames) do
if frameName == "GCastSettings" then
tremove(UISpecialFrames, i)
break
end
end
GCast.Utils:Log("Entered edit mode, editMode=" .. tostring(GCast.db.player.visual.editMode), true)
else
GCast.db.player.visual.editMode = false
if GCast.dottedFrame then GCast.dottedFrame:Hide() end
local coordPanel = _G["GCastCoordPanel"]
if coordPanel then
coordPanel:Hide()
GCast.Utils:Log("Hid coord panel", true)
end
if _G["GCastSettings"] and _G["GCastSettings"]:IsShown() then
tinsert(UISpecialFrames, "GCastSettings")
end
GCast.Utils:Log("Exited edit mode, editMode=" .. tostring(GCast.db.player.visual.editMode), true)
end
self:SetText(GCast.db.player.visual.editMode and GCast.L["Exit Edit Mode"] or GCast.L["Toggle Edit Mode"])
end)
editButton:SetPoint("LEFT", slidersLabel, "RIGHT", 20, 0)
end
local function CreateDirectionControls(content)
local directions = {
{ label = GCast.L["Up"], key = "UP", group = "verticalDirections", x = 360, y = -90, dir = "UP" },
{ label = GCast.L["Left"], key = "LEFT", group = "horizontalDirections", x = 460, y = -90, dir = "LEFT" },
{ label = GCast.L["Left Up"], key = "LEFT_UP", group = "diagonalDirections", x = 560, y = -90, dir = "LEFT_UP" },
{ label = GCast.L["Down"], key = "DOWN", group = "verticalDirections", x = 360, y = -130, dir = "DOWN" },
{ label = GCast.L["Right"], key = "RIGHT", group = "horizontalDirections", x = 460, y = -130, dir = "RIGHT" },
{ label = GCast.L["Left Down"], key = "LEFT_DOWN", group = "diagonalDirections", x = 560, y = -130, dir = "LEFT_DOWN" },
{ label = GCast.L["Right Up"], key = "RIGHT_UP", group = "diagonalDirections", x = 560, y = -170, dir = "RIGHT_UP" },
{ label = GCast.L["Right Down"], key = "RIGHT_DOWN", group = "diagonalDirections", x = 560, y = -210, dir = "RIGHT_DOWN" }
}
local rightHeader = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
rightHeader:SetPoint("TOPLEFT", 360, -30)
rightHeader:SetText(GCast.L["Flight Directions"])
local dirCheckButtons = {}
local orderEditBoxes = {}
local function UpdateDirectionOrder()
GCast.db.global.visual.directionOrder = GCast.db.global.visual.directionOrder or {}
local enabledDirections = {}
for _, d in ipairs(directions) do
if GCast.db.global.visual[d.group] and GCast.db.global.visual[d.group][d.key] then
local order = GCast.db.global.visual.directionOrder[d.dir] or #enabledDirections + 1
table.insert(enabledDirections, { dir = d.dir, order = order })
end
end
table.sort(enabledDirections, function(a, b) return a.order < b.order end)
local newOrder = {}
for i, entry in ipairs(enabledDirections) do
newOrder[entry.dir] = i
end
for dir in pairs(GCast.db.global.visual.directionOrder) do
if not newOrder[dir] then
GCast.db.global.visual.directionOrder[dir] = nil
end
end
for dir, order in pairs(newOrder) do
GCast.db.global.visual.directionOrder[dir] = order
end
for i, btn in ipairs(dirCheckButtons) do
if btn and orderEditBoxes[i] then
local d = directions[i]
if GCast.db.global.visual[d.group] then
local checked = GCast.db.global.visual[d.group][d.key]
btn:SetChecked(checked)
if checked then
orderEditBoxes[i]:Enable()
orderEditBoxes[i]:SetText(tostring(GCast.db.global.visual.directionOrder[d.dir] or ""))
else
orderEditBoxes[i]:Disable()
orderEditBoxes[i]:SetText("")
end
end
end
end
GCast:UpdateDirectionsCache()
end
for i, d in ipairs(directions) do
if d.label == GCast.L["Up"] then
local groupLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
groupLabel:SetPoint("TOPLEFT", 360, -70)
groupLabel:SetText(GCast.L["Vertical"])
elseif d.label == GCast.L["Left"] then
local groupLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
groupLabel:SetPoint("TOPLEFT", 460, -70)
groupLabel:SetText(GCast.L["Horizontal"])
elseif d.label == GCast.L["Left Up"] then
local groupLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
groupLabel:SetPoint("TOPLEFT", 560, -70)
groupLabel:SetText(GCast.L["Diagonal"])
end
local btn = GCast.SettingsUI:CreateControl(content, "CheckButton", "UICheckButtonTemplate", {26, 26}, {"TOPLEFT", d.x, d.y}, function(check)
check.text = check:CreateFontString(nil, "OVERLAY", "GameFontNormal")
check.text:SetPoint("LEFT", check, "RIGHT", 5, 0)
check.text:SetText(d.label)
if GCast.db.global.visual[d.group] then
check:SetChecked(GCast.db.global.visual[d.group][d.key])
else
check:SetChecked(false)
end
check:SetScript("OnClick", function(self)
if not GCast.db.global.visual[d.group] then return end
GCast.db.global.visual[d.group][d.key] = self:GetChecked()
if self:GetChecked() then
local maxOrder = 0
for _, order in pairs(GCast.db.global.visual.directionOrder) do
maxOrder = math.max(maxOrder, order)
end
GCast.db.global.visual.directionOrder[d.dir] = maxOrder + 1
else
GCast.db.global.visual.directionOrder[d.dir] = nil
end
UpdateDirectionOrder()
end)
end)
table.insert(dirCheckButtons, btn)
local orderBox = GCast.Utils:CreateEditBox(content, {30, 20}, {"LEFT", btn.text, "RIGHT", 5, 0}, true, 2, function(edit)
edit:SetNumeric(true)
edit:SetAutoFocus(false)
edit:SetScript("OnEnterPressed", function(self)
if not GCast.db.global.visual.directionOrder then return end
local val = tonumber(self:GetText()) or 1
GCast.db.global.visual.directionOrder[d.dir] = val
UpdateDirectionOrder()
self:ClearFocus()
end)
if GCast.db.global.visual[d.group] and GCast.db.global.visual[d.group][d.key] and GCast.db.global.visual.directionOrder then
edit:SetText(tostring(GCast.db.global.visual.directionOrder[d.dir] or ""))
edit:Enable()
else
edit:SetText("")
edit:Disable()
end
end)
table.insert(orderEditBoxes, orderBox)
end
return UpdateDirectionOrder
end
local function CreateFlightEffectControls(content)
local flightEffectsLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
flightEffectsLabel:SetPoint("TOPLEFT", 360, -250)
flightEffectsLabel:SetText(GCast.L["Flight Effect"])
GCast.db.global.visual.flightEffectType = GCast.db.global.visual.flightEffectType or "straight"
local flightTypes = {
{ key = "straight", label = GCast.L["Straight Line"], y = -290 },
{ key = "wave", label = GCast.L["Wave"], y = -330 },
{ key = "zigzag", label = GCast.L["Zigzag"], y = -370 }
}
local checkButtons = {}
local function updateFlightTypeUI()
if not GCast.db.global.visual then return end
local flightType = GCast.db.global.visual.flightEffectType
local isWave = flightType == "wave"
local isZigzag = flightType == "zigzag"
waveAmplitudeLabel:SetAlpha(isWave and 1 or 0.5)
GCast.editBoxes.waveAmplitude:SetEnabled(isWave)
GCast.editBoxes.waveAmplitude:SetAlpha(isWave and 1 or 0.5)
waveAmplitudeLabel:SetShown(isWave)
GCast.editBoxes.waveAmplitude:SetShown(isWave)
zigzagAngleLabel:SetAlpha(isZigzag and 1 or 0.5)
GCast.editBoxes.zigzagAngle:SetEnabled(isZigzag)
GCast.editBoxes.zigzagAngle:SetAlpha(isZigzag and 1 or 0.5)
zigzagAngleLabel:SetShown(isZigzag)
GCast.editBoxes.zigzagAngle:SetShown(isZigzag)
for i, check in ipairs(checkButtons) do
check:SetChecked(GCast.db.global.visual.flightEffectType == check.ft.key)
end
end
for i, ft in ipairs(flightTypes) do
local check = GCast.SettingsUI:CreateControl(content, "CheckButton", "UICheckButtonTemplate", {26, 26}, {"TOPLEFT", 370, ft.y}, function(check)
check.ft = ft
check.text = check:CreateFontString(nil, "OVERLAY", "GameFontNormal")
check.text:SetPoint("LEFT", check, "RIGHT", 5, 0)
check.text:SetText(ft.label)
check:SetChecked(GCast.db.global.visual.flightEffectType == ft.key)
check:SetScript("OnClick", function(self)
if self:GetChecked() then
for j = 1, #flightTypes do
if j ~= i then
checkButtons[j]:SetChecked(false)
end
end
GCast.db.global.visual.flightEffectType = ft.key
else
self:SetChecked(true)
end
updateFlightTypeUI()
end)
_G["GCastFlightType"..i] = check
end)
table.insert(checkButtons, check)
end
local waveAmplitudeLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
waveAmplitudeLabel:SetPoint("TOPLEFT", 450, -330)
waveAmplitudeLabel:SetText(GCast.L["Wave Amplitude"] .. ":")
GCast.editBoxes.waveAmplitude = GCast.Utils:CreateEditBox(content, {50, 20}, {"LEFT", waveAmplitudeLabel, "RIGHT", 10, 0}, true, nil, function(edit)
edit:SetNumeric(true)
edit:SetAutoFocus(false)
end)
GCast.db.global.visual.waveAmplitude = GCast.db.global.visual.waveAmplitude or 20
if GCast.editBoxes.waveAmplitude then
GCast.editBoxes.waveAmplitude:SetText(tostring(GCast.db.global.visual.waveAmplitude))
GCast.editBoxes.waveAmplitude:SetScript("OnEnterPressed", function(self)
local value = tonumber(self:GetText()) or 20
GCast:UpdateConfig("waveAmplitude", value)
self:SetText(tostring(value))
self:ClearFocus()
end)
end
local zigzagAngleLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
zigzagAngleLabel:SetPoint("TOPLEFT", 450, -370)
zigzagAngleLabel:SetText(GCast.L["Zigzag Angle"] .. ":")
GCast.editBoxes.zigzagAngle = GCast.Utils:CreateEditBox(content, {50, 20}, {"LEFT", zigzagAngleLabel, "RIGHT", 10, 0}, true, nil, function(edit)
edit:SetNumeric(true)
edit:SetAutoFocus(false)
end)
GCast.db.global.visual.zigzagAngle = GCast.db.global.visual.zigzagAngle or 30
if GCast.editBoxes.zigzagAngle then
GCast.editBoxes.zigzagAngle:SetText(tostring(GCast.db.global.visual.zigzagAngle))
GCast.editBoxes.zigzagAngle:SetScript("OnEnterPressed", function(self)
local value = tonumber(self:GetText()) or 30
GCast:UpdateConfig("zigzagAngle", value)
self:SetText(tostring(value))
self:ClearFocus()
end)
end
return updateFlightTypeUI
end
local function CreateVisualSpellList(content)
local visualEffectSpellListLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
visualEffectSpellListLabel:SetPoint("TOPLEFT", 10, -180)
visualEffectSpellListLabel:SetText(GCast.L["Spell List"])
visualEffectSpellListFrame = GCast.SettingsUI:CreateControl(content, "Frame", "BackdropTemplate", {300, 300}, {"TOPLEFT", 8, -210}, function(f)
f:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
f:SetFrameLevel(content:GetFrameLevel() + 1)
f:Show()
end)
local scrollFrame = GCast.SettingsUI:CreateControl(visualEffectSpellListFrame, "ScrollFrame", "UIPanelScrollFrameTemplate", {270, 290}, {"TOPLEFT", 5, -5, "BOTTOMRIGHT", -20, 5}, function(f)
f:SetFrameLevel(visualEffectSpellListFrame:GetFrameLevel() + 1)
f:Show()
end)
local scrollChild = CreateFrame("Frame", nil, scrollFrame)
scrollChild:SetSize(270, 300)
scrollFrame:SetScrollChild(scrollChild)
scrollChild:Show()
visualEffectSpellListFrame.scrollFrame = scrollFrame
GCast.editBoxes.spellID = GCast.Utils:CreateEditBox(content, {80, 20}, {"LEFT", visualEffectSpellListLabel, "RIGHT", 10, 0}, true, 10, function(edit)
edit:SetNumeric(true)
edit:SetAutoFocus(false)
end)
local visualEffectAddButton = GCast.Utils:CreateButton(content, GCast.L["Add Spell"], {80, 22}, function()
local spellID = tonumber(GCast.editBoxes.spellID:GetText())
if not spellID or spellID <= 0 then
GCast.Utils:Log("Invalid spell ID: " .. tostring(GCast.editBoxes.spellID:GetText()))
return
end
local spellInfo = C_Spell.GetSpellInfo(spellID)
if spellInfo and spellInfo.name then
GCast.db.player.visual.enabledSpells[tostring(spellID)] = spellInfo.name
GCast.Utils:Log("Added spell ID " .. tostring(spellID) .. " (" .. spellInfo.name .. ")")
pcall(GCast.DB.SaveSettings)
content:Update()
GCast.editBoxes.spellID:SetText("")
local spellsStr = ""
for k, v in pairs(GCast.db.player.visual.enabledSpells) do
spellsStr = spellsStr .. k .. "=" .. v .. ", "
end
GCast.Utils:Log("enabledSpells=" .. (spellsStr == "" and "empty" or spellsStr))
else
GCast.Utils:Log("No spell info for ID: " .. tostring(spellID))
end
end)
visualEffectAddButton:SetPoint("LEFT", GCast.editBoxes.spellID, "RIGHT", 10, 0)
GCast.editBoxes.spellID:SetScript("OnEnterPressed", function(self)
visualEffectAddButton:Click()
end)
local function UpdateVisualSpellList()
local spellsToShow = {}
GCast.db.player.visual.enabledSpells = GCast.db.player.visual.enabledSpells or {}
if type(GCast.db.player.visual.enabledSpells) ~= "table" then
GCast.db.player.visual.enabledSpells = {}
GCast.Utils:Log("Reset enabledSpells to empty table")
end
for spellID, spellName in pairs(GCast.db.player.visual.enabledSpells) do
local numSpellID = tonumber(spellID)
if numSpellID and numSpellID > 0 and type(spellName) == "string" then
local spellInfo = C_Spell.GetSpellInfo(numSpellID)
if spellInfo and spellInfo.name then
table.insert(spellsToShow, { id = numSpellID, name = spellName })
else
GCast.Utils:Log("Skipping spell ID " .. tostring(spellID) .. " (invalid spell info)")
end
else
GCast.Utils:Log("Skipping invalid spell ID " .. tostring(spellID) .. ", name=" .. tostring(spellName))
end
end
table.sort(spellsToShow, function(a, b) return a.name < b.name end)
GCast.Utils:Log("Updating visual spell list with " .. #spellsToShow .. " spells")
if not scrollFrame or not scrollChild then
GCast.Utils:Log("ScrollFrame or ScrollChild not found")
return
end
UpdateSpellList(scrollChild, spellsToShow, GCast.db.player.visual, false, nil)
end
return UpdateVisualSpellList
end
local function SetupVisualTabContent(content)
GCast.editBoxes = GCast.editBoxes or {}
local slidersLabel = CreateVisualSliders(content)
CreateEditButton(content, slidersLabel)
local UpdateDirectionOrder = CreateDirectionControls(content)
local UpdateFlightTypeUI = CreateFlightEffectControls(content)
local UpdateVisualSpellList = CreateVisualSpellList(content)
content.Update = function()
GCast.DB:EnsureInitialized()
GCast.db.global = GCast.db.global or {}
GCast.db.player = GCast.db.player or { visual = {} }
local sliders = {
{ key = "size", default = 50 },
{ key = "opacity", default = 100 },
{ key = "flightDuration", default = 20 },
{ key = "fadeOutDuration", default = 25 }
}
for _, s in ipairs(sliders) do
local value = tonumber(GCast.db.global.visual[s.key]) or s.default
if GCast.editBoxes[s.key] then
GCast.editBoxes[s.key]:SetText(tostring(value))
end
end
if GCast.editBoxes.waveAmplitude then
local waveAmplitude = tonumber(GCast.db.global.visual.waveAmplitude) or 20
GCast.editBoxes.waveAmplitude:SetText(tostring(waveAmplitude))
end
if GCast.editBoxes.zigzagAngle then
local zigzagAngle = tonumber(GCast.db.global.visual.zigzagAngle) or 30
GCast.editBoxes.zigzagAngle:SetText(tostring(zigzagAngle))
end
UpdateFlightTypeUI()
UpdateVisualSpellList()
UpdateDirectionOrder()
end
end
local function CreateKeybindControls(content, settings, categoryIndex)
local showKeybindsCheck = GCast.SettingsUI:CreateControl(content, "CheckButton", "UICheckButtonTemplate", {26, 26}, {"TOPLEFT", categoryIndex == 0 and 10 or 380, -70}, function(check)
check.text = check:CreateFontString(nil, "OVERLAY", "GameFontNormal")
check.text:SetPoint("LEFT", check, "RIGHT", 5, 0)
check.text:SetText(GCast.L["Show Keybinds"])
check:SetChecked(settings.showKeybinds)
check:SetScript("OnClick", function(self)
settings.showKeybinds = self:GetChecked()
GCast.db.global.keybinds[categoryIndex == 0 and "essential" or "utility"].show = self:GetChecked()
pcall(GCast.DB.SaveSettings)
GCast.Keybinds:UpdateOverlays(categoryIndex)
end)
end)
local textSizeLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
textSizeLabel:SetPoint("TOPLEFT", categoryIndex == 0 and 10 or 380, -110)
textSizeLabel:SetText(GCast.L["Keybind Text Size"] .. ":")
local keybindTextSizeEdit = GCast.Utils:CreateEditBox(content, {30, 20}, {"LEFT", textSizeLabel, "RIGHT", 5, 0}, true, nil, function(edit)
edit:SetNumeric(true)
edit:SetAutoFocus(false)
edit:SetText(tostring(settings.keybindTextSize or GCast.Config.keybindSettings.textSize.default))
edit:SetScript("OnEnterPressed", function(self)
local value = tonumber(self:GetText()) or GCast.Config.keybindSettings.textSize.default
GCast:UpdateConfig("textSize", value)
settings.keybindTextSize = value
GCast.db.global.keybinds[categoryIndex == 0 and "essential" or "utility"].textSize = value
pcall(GCast.DB.SaveSettings)
self:SetText(tostring(value))
self:ClearFocus()
GCast.Keybinds:UpdateOverlays(categoryIndex)
end)
end)
local xMarginLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
xMarginLabel:SetPoint("TOPLEFT", categoryIndex == 0 and 10 or 380, -150)
xMarginLabel:SetText(GCast.L["X Margin"] .. ":")
local xMarginEdit = GCast.Utils:CreateEditBox(content, {45, 20}, {"LEFT", xMarginLabel, "RIGHT", 5, 0}, true, nil, function(edit)
edit:SetAutoFocus(false)
edit:SetText(tostring(settings.xMargin or GCast.Config.keybindSettings.xMargin.default))
edit:SetScript("OnEnterPressed", function(self)
local value = tonumber(self:GetText()) or GCast.Config.keybindSettings.xMargin.default
GCast:UpdateConfig("xMargin", value)
settings.xMargin = value
GCast.db.global.keybinds[categoryIndex == 0 and "essential" or "utility"].xMargin = value
pcall(GCast.DB.SaveSettings)
self:SetText(tostring(value))
self:ClearFocus()
GCast.Keybinds:RefreshAll()
end)
end)
local yMarginLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
yMarginLabel:SetPoint("TOPLEFT", categoryIndex == 0 and 130 or 500, -150)
yMarginLabel:SetText(GCast.L["Y Margin"] .. ":")
local yMarginEdit = GCast.Utils:CreateEditBox(content, {45, 20}, {"LEFT", yMarginLabel, "RIGHT", 5, 0}, true, nil, function(edit)
edit:SetAutoFocus(false)
edit:SetText(tostring(settings.yMargin or GCast.Config.keybindSettings.yMargin.default))
edit:SetScript("OnEnterPressed", function(self)
local value = tonumber(self:GetText()) or GCast.Config.keybindSettings.yMargin.default
GCast:UpdateConfig("yMargin", value)
settings.yMargin = value
GCast.db.global.keybinds[categoryIndex == 0 and "essential" or "utility"].yMargin = value
pcall(GCast.DB.SaveSettings)
self:SetText(tostring(value))
self:ClearFocus()
GCast.Keybinds:RefreshAll()
end)
end)
end
local function CreateKeybindListFrame(parentFrame, settings, categoryIndex, anchorXOffset)
local backgroundFrame = GCast.SettingsUI:CreateControl(parentFrame, "Frame", "BackdropTemplate", {300, 300}, {"TOPLEFT", anchorXOffset, -180}, function(f)
f:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
f:SetFrameLevel(parentFrame:GetFrameLevel() + 1)
f:Show()
end)
local scrollFrame = GCast.SettingsUI:CreateControl(backgroundFrame, "ScrollFrame", "UIPanelScrollFrameTemplate", {270, 290}, {"TOPLEFT", 5, -5, "BOTTOMRIGHT", -20, 5}, function(f)
f:SetFrameLevel(backgroundFrame:GetFrameLevel() + 1)
f:Show()
end)
local scrollChild = CreateFrame("Frame", nil, scrollFrame)
scrollChild:SetSize(270, 300)
scrollFrame:SetScrollChild(scrollChild)
scrollChild.category = categoryIndex == 0 and "essential" or "utility"
scrollChild.categoryIndex = categoryIndex
scrollChild.settings = settings
scrollChild.scrollFrame = scrollFrame
scrollFrame:UpdateScrollChildRect()
scrollFrame:SetVerticalScroll(0)
return scrollChild
end
local function SetupKeybindTabContent(content)
local leftTitle = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
leftTitle:SetPoint("TOPLEFT", 10, -30)