-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathBindingEditor.lua
More file actions
executable file
·4946 lines (4315 loc) · 192 KB
/
Copy pathBindingEditor.lua
File metadata and controls
executable file
·4946 lines (4315 loc) · 192 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, DF = ...
-- Get module namespace
local CC = DF.ClickCast
local L = DF.L
local format = string.format
-- Local aliases for shared constants (defined in Constants.lua)
local DEFAULT_BINDING_SCOPE = CC.DEFAULT_BINDING_SCOPE
local DEFAULT_BINDING_COMBAT = CC.DEFAULT_BINDING_COMBAT
local DEFAULT_TARGET_TYPE = CC.DEFAULT_TARGET_TYPE
local TARGET_INFO = CC.TARGET_INFO
local FRAME_INFO = CC.FRAME_INFO
local FALLBACK_INFO = CC.FALLBACK_INFO
local COMBAT_INFO = CC.COMBAT_INFO
-- Local alias for shared UI tables (defined in UI/Main.lua)
-- spellCells is now accessed via CC.spellCells
-- Local alias for UI constants (defined in UI/Main.lua)
local BINDING_ROW_HEIGHT = CC.BINDING_ROW_HEIGHT or 48
-- Local alias for helper functions (defined in Bindings.lua)
local function GetSpellDisplayInfo(a, b)
if CC.GetSpellDisplayInfo then
return CC.GetSpellDisplayInfo(a, b)
else
-- Fallback if function not available
local name = b or (a and C_Spell.GetSpellName and C_Spell.GetSpellName(a)) or "Unknown"
local icon = a and C_Spell.GetSpellTexture and C_Spell.GetSpellTexture(a) or 134400
return name, icon, a
end
end
-- Local alias for helper functions (defined in UI/Main.lua)
local function GetFallbackDisplayText(f) return CC.GetFallbackDisplayText and CC.GetFallbackDisplayText(f) or nil end
-- Local alias for helper functions (defined in UI/ProfilesPanel.lua)
local function ShowPopupOnTop(name) return CC.ShowPopupOnTop and CC.ShowPopupOnTop(name) or StaticPopup_Show(name) end
-- ADD/EDIT BINDING DIALOG
-- ============================================================
local addBindingDialog = nil
function CC:ShowAddBindingDialog(onComplete, existingBinding, existingIndex)
if addBindingDialog then
addBindingDialog:Hide()
end
-- Theme colors (matching GUI/GUI.lua)
local themeColor = DF.GUI and DF.GUI.GetThemeColor and DF.GUI.GetThemeColor() or {r = 0.45, g = 0.45, b = 0.95}
local C_BACKGROUND = {r = 0.08, g = 0.08, b = 0.08}
local C_PANEL = {r = 0.12, g = 0.12, b = 0.12}
local C_ELEMENT = {r = 0.18, g = 0.18, b = 0.18}
local C_BORDER = {r = 0.25, g = 0.25, b = 0.25}
local C_TEXT = {r = 0.9, g = 0.9, b = 0.9}
local C_TEXT_DIM = {r = 0.6, g = 0.6, b = 0.6}
-- Create dialog
addBindingDialog = CreateFrame("Frame", "DFClickCastAddDialog", UIParent, "BackdropTemplate")
addBindingDialog:SetSize(420, 430) -- Start at collapsed height
addBindingDialog:SetPoint("CENTER", 0, 50)
addBindingDialog:SetFrameStrata("FULLSCREEN_DIALOG")
addBindingDialog:SetFrameLevel(100)
addBindingDialog:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
addBindingDialog:SetBackdropColor(C_BACKGROUND.r, C_BACKGROUND.g, C_BACKGROUND.b, 0.98)
addBindingDialog:SetBackdropBorderColor(0, 0, 0, 1)
addBindingDialog:EnableMouse(true)
addBindingDialog:SetMovable(true)
addBindingDialog:RegisterForDrag("LeftButton")
addBindingDialog:SetScript("OnDragStart", addBindingDialog.StartMoving)
addBindingDialog:SetScript("OnDragStop", addBindingDialog.StopMovingOrSizing)
-- Title
local title = addBindingDialog:CreateFontString(nil, "OVERLAY", "DFFontNormal")
title:SetPoint("TOPLEFT", 12, -12)
title:SetText(existingBinding and L["Edit Binding"] or L["Add New Binding"])
title:SetTextColor(C_TEXT.r, C_TEXT.g, C_TEXT.b)
-- Close button
local closeBtn = CreateFrame("Button", nil, addBindingDialog, "BackdropTemplate")
closeBtn:SetPoint("TOPRIGHT", -6, -6)
closeBtn:SetSize(20, 20)
closeBtn:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
closeBtn:SetBackdropColor(C_ELEMENT.r, C_ELEMENT.g, C_ELEMENT.b, 1)
closeBtn:SetBackdropBorderColor(C_BORDER.r, C_BORDER.g, C_BORDER.b, 0.5)
local closeIcon = closeBtn:CreateTexture(nil, "OVERLAY")
closeIcon:SetPoint("CENTER", 0, 0)
closeIcon:SetSize(12, 12)
closeIcon:SetTexture("Interface\\AddOns\\DandersFrames\\Media\\Icons\\close")
closeIcon:SetVertexColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
closeBtn:SetScript("OnClick", function() addBindingDialog:Hide() end)
closeBtn:SetScript("OnEnter", function()
closeBtn:SetBackdropBorderColor(1, 0.4, 0.4, 1)
closeIcon:SetVertexColor(1, 0.4, 0.4)
end)
closeBtn:SetScript("OnLeave", function()
closeBtn:SetBackdropBorderColor(C_BORDER.r, C_BORDER.g, C_BORDER.b, 0.5)
closeIcon:SetVertexColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
end)
-- Working binding data
local bindingData = existingBinding and CopyTable(existingBinding) or {
enabled = true,
button = "LeftButton",
modifiers = "",
actionType = "spell",
spellId = nil,
spellName = nil,
macroText = nil,
loadSpec = nil,
loadCombat = nil,
priority = 5, -- Default priority (1=highest, 10=lowest)
}
local yOffset = -45
-- STEP 1: Key Combination
local step1Label = addBindingDialog:CreateFontString(nil, "OVERLAY", "DFFontNormal")
step1Label:SetPoint("TOPLEFT", 15, yOffset)
step1Label:SetText(L["Step 1: Click here with desired key combo"])
step1Label:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
yOffset = yOffset - 20
local keyCaptureBtn = CreateFrame("Button", nil, addBindingDialog, "BackdropTemplate")
keyCaptureBtn:SetPoint("TOPLEFT", 15, yOffset)
keyCaptureBtn:SetSize(390, 32)
keyCaptureBtn:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
keyCaptureBtn:SetBackdropColor(C_ELEMENT.r, C_ELEMENT.g, C_ELEMENT.b, 1)
keyCaptureBtn:SetBackdropBorderColor(C_BORDER.r, C_BORDER.g, C_BORDER.b, 0.5)
keyCaptureBtn:RegisterForClicks("AnyDown", "AnyUp")
local keyText = keyCaptureBtn:CreateFontString(nil, "OVERLAY", "DFFontNormal")
keyText:SetPoint("CENTER")
local function UpdateKeyText()
keyText:SetText(CC:GetBindingDisplayString(bindingData))
keyText:SetTextColor(themeColor.r, themeColor.g, themeColor.b)
end
UpdateKeyText()
keyCaptureBtn:SetScript("OnClick", function(self, button)
local mods = ""
if IsShiftKeyDown() then mods = mods .. "shift-" end
if IsControlKeyDown() then mods = mods .. "ctrl-" end
if IsAltKeyDown() then mods = mods .. "alt-" end
if IsMetaKeyDown() then mods = mods .. "meta-" end
bindingData.button = button
bindingData.modifiers = mods
UpdateKeyText()
-- Warn Mac users about Command+Left Click limitation (right click works fine)
if mods:find("meta") and button == "LeftButton" then
CC:ShowMacMetaClickWarning()
end
end)
-- Mac warning label (only shown on Mac)
if IsMacClient and IsMacClient() then
local macWarning = addBindingDialog:CreateFontString(nil, "OVERLAY", "DFFontHighlightSmall")
macWarning:SetPoint("TOPLEFT", keyCaptureBtn, "BOTTOMLEFT", 0, -2)
macWarning:SetWidth(390)
macWarning:SetJustifyH("LEFT")
macWarning:SetText("|cffff9900" .. L["Note: Cmd + Left Click unavailable on Mac"])
macWarning:SetTextColor(0.9, 0.6, 0.2)
yOffset = yOffset - 12 -- Extra space for the warning
end
yOffset = yOffset - 45
-- STEP 2: Action Selection (spell list with Target/Menu at top)
local step2Label = addBindingDialog:CreateFontString(nil, "OVERLAY", "DFFontNormal")
step2Label:SetPoint("TOPLEFT", 15, yOffset)
step2Label:SetText(L["Step 2: Select Action"])
step2Label:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
yOffset = yOffset - 20
-- Search box for filtering spells
local spellBox = CreateFrame("EditBox", nil, addBindingDialog, "BackdropTemplate")
spellBox:SetPoint("TOPLEFT", 15, yOffset)
spellBox:SetSize(390, 26)
spellBox:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
spellBox:SetBackdropColor(C_ELEMENT.r, C_ELEMENT.g, C_ELEMENT.b, 1)
spellBox:SetBackdropBorderColor(C_BORDER.r, C_BORDER.g, C_BORDER.b, 0.5)
DF.GUI:SetSettingsFont(spellBox, 11, "")
spellBox:SetTextColor(C_TEXT.r, C_TEXT.g, C_TEXT.b)
spellBox:SetTextInsets(24, 8, 0, 0)
spellBox:SetAutoFocus(false)
spellBox:SetText("")
-- Search icon
local spellSearchIcon = spellBox:CreateTexture(nil, "OVERLAY")
spellSearchIcon:SetPoint("LEFT", 6, 0)
spellSearchIcon:SetSize(12, 12)
spellSearchIcon:SetTexture("Interface\\AddOns\\DandersFrames\\Media\\Icons\\search")
spellSearchIcon:SetVertexColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
-- Placeholder text
local placeholder = spellBox:CreateFontString(nil, "OVERLAY", "DFFontHighlightSmall")
placeholder:SetPoint("LEFT", 24, 0)
placeholder:SetText(L["Search spells..."])
placeholder:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
spellBox:SetScript("OnEditFocusGained", function() placeholder:Hide() end)
spellBox:SetScript("OnEditFocusLost", function()
if spellBox:GetText() == "" then placeholder:Show() end
end)
yOffset = yOffset - 32
-- Selection display
local selectionFrame = CreateFrame("Frame", nil, addBindingDialog, "BackdropTemplate")
selectionFrame:SetPoint("TOPLEFT", 15, yOffset)
selectionFrame:SetSize(390, 28)
selectionFrame:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
selectionFrame:SetBackdropColor(C_PANEL.r, C_PANEL.g, C_PANEL.b, 1)
selectionFrame:SetBackdropBorderColor(C_BORDER.r, C_BORDER.g, C_BORDER.b, 0.5)
local selectionIcon = selectionFrame:CreateTexture(nil, "ARTWORK")
selectionIcon:SetPoint("LEFT", 6, 0)
selectionIcon:SetSize(20, 20)
selectionIcon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark") -- Default question mark
selectionIcon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
local selectionText = selectionFrame:CreateFontString(nil, "OVERLAY", "DFFontNormal")
selectionText:SetPoint("LEFT", selectionIcon, "RIGHT", 8, 0)
selectionText:SetText(L["No action selected"])
selectionText:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
-- Track if valid selection was made
local validSelection = false
local function UpdateSelection(actionType, spellName, icon)
bindingData.actionType = actionType
bindingData.spellName = spellName
validSelection = true
if actionType == "target" then
selectionIcon:SetTexture(132212) -- Target icon
selectionText:SetText(L["Target Unit"])
elseif actionType == "menu" then
selectionIcon:SetTexture(134331) -- Menu icon
selectionText:SetText(L["Open Unit Menu"])
else
selectionIcon:SetTexture(icon or "Interface\\Icons\\INV_Misc_QuestionMark")
selectionText:SetText(spellName or "Unknown Spell")
end
selectionText:SetTextColor(C_TEXT.r, C_TEXT.g, C_TEXT.b)
selectionFrame:SetBackdropBorderColor(themeColor.r, themeColor.g, themeColor.b, 1)
end
-- Pre-populate if editing existing binding
if existingBinding then
if existingBinding.actionType == "target" then
UpdateSelection("target", nil, nil)
elseif existingBinding.actionType == "menu" then
UpdateSelection("menu", nil, nil)
elseif existingBinding.spellName then
local icon = CC:GetSpellIcon(existingBinding.spellName)
UpdateSelection("spell", existingBinding.spellName, icon)
end
end
yOffset = yOffset - 35
-- Action list (Target/Menu + Spells)
local spellScrollFrame = CreateFrame("ScrollFrame", nil, addBindingDialog, "ScrollFrameTemplate")
spellScrollFrame:SetPoint("TOPLEFT", 15, yOffset)
spellScrollFrame:SetSize(375, 130)
DF.GUI.StyleScrollBar(spellScrollFrame)
local spellListContent = CreateFrame("Frame", nil, spellScrollFrame)
spellListContent:SetSize(360, 1)
spellScrollFrame:SetScrollChild(spellListContent)
local spellButtons = {}
local function CreateActionButton(parent, yPos, icon, text, onClick)
local btn = CreateFrame("Button", nil, parent)
btn:SetPoint("TOPLEFT", 0, -yPos)
btn:SetSize(360, 22)
local iconTex = btn:CreateTexture(nil, "ARTWORK")
iconTex:SetPoint("LEFT", 4, 0)
iconTex:SetSize(18, 18)
iconTex:SetTexture(icon)
iconTex:SetTexCoord(0.08, 0.92, 0.08, 0.92)
local nameText = btn:CreateFontString(nil, "OVERLAY", "DFFontHighlightSmall")
nameText:SetPoint("LEFT", iconTex, "RIGHT", 8, 0)
nameText:SetText(text)
local highlight = btn:CreateTexture(nil, "HIGHLIGHT")
highlight:SetAllPoints()
highlight:SetColorTexture(themeColor.r, themeColor.g, themeColor.b, 0.3)
btn:SetScript("OnClick", onClick)
return btn
end
local function PopulateSpellList(searchText)
for _, btn in ipairs(spellButtons) do
btn:Hide()
btn:SetParent(nil)
end
wipe(spellButtons)
local yPos = 0
searchText = searchText or ""
local searchLower = searchText:lower()
-- Add Target Unit at top (if matches search or no search)
if searchText == "" or ("target unit"):find(searchLower, 1, true) then
local btn = CreateActionButton(spellListContent, yPos, 132212, "|cff88ff88Target Unit|r", function()
UpdateSelection("target", nil, nil)
end)
table.insert(spellButtons, btn)
yPos = yPos + 24
end
-- Add Open Menu at top (if matches search or no search)
if searchText == "" or ("open menu"):find(searchLower, 1, true) or ("unit menu"):find(searchLower, 1, true) then
local btn = CreateActionButton(spellListContent, yPos, 134331, "|cff88ff88Open Unit Menu|r", function()
UpdateSelection("menu", nil, nil)
end)
table.insert(spellButtons, btn)
yPos = yPos + 24
end
-- Add separator if we have special items and spells
if yPos > 0 and searchText == "" then
local sep = spellListContent:CreateTexture(nil, "ARTWORK")
sep:SetPoint("TOPLEFT", 0, -yPos)
sep:SetSize(360, 1)
sep:SetColorTexture(0.3, 0.3, 0.3, 0.5)
yPos = yPos + 6
end
-- Add spells from spellbook
local spells = CC:SearchSpellbook(searchText)
for i, spell in ipairs(spells) do
if i > 30 then break end
-- Use displayName from search results (already has override applied)
local displayName = spell.displayName or spell.name
local displayIcon = spell.icon
-- Show override name/icon, but pass BASE spell name for binding
local btn = CreateActionButton(spellListContent, yPos, displayIcon, displayName, function()
UpdateSelection("spell", spell.name, displayIcon) -- spell.name is the base name
end)
table.insert(spellButtons, btn)
yPos = yPos + 24
end
spellListContent:SetHeight(math.max(1, yPos))
end
spellBox:SetScript("OnTextChanged", function(self)
local text = self:GetText()
if text == "" then
placeholder:Show()
else
placeholder:Hide()
end
PopulateSpellList(text)
end)
PopulateSpellList("")
yOffset = yOffset - 145
-- STEP 3: Combat Condition
local step3Label = addBindingDialog:CreateFontString(nil, "OVERLAY", "DFFontNormal")
step3Label:SetPoint("TOPLEFT", 15, yOffset)
step3Label:SetText(L["Step 3: Combat Condition (optional)"])
step3Label:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
yOffset = yOffset - 20
local combatOptions = {
{value = nil, label = L["Always"]},
{value = "combat", label = L["In Combat Only"]},
{value = "nocombat", label = L["Out of Combat Only"]},
}
local combatButtons = {}
xPos = 15
local function UpdateCombatButtons()
for key, b in pairs(combatButtons) do
local isSelected = (key == "always" and not bindingData.loadCombat) or (key == bindingData.loadCombat)
if isSelected then
b:SetBackdropColor(themeColor.r * 0.3, themeColor.g * 0.3, themeColor.b * 0.3, 1)
b:SetBackdropBorderColor(themeColor.r, themeColor.g, themeColor.b, 1)
b.label:SetTextColor(C_TEXT.r, C_TEXT.g, C_TEXT.b)
else
b:SetBackdropColor(C_ELEMENT.r, C_ELEMENT.g, C_ELEMENT.b, 1)
b:SetBackdropBorderColor(C_BORDER.r, C_BORDER.g, C_BORDER.b, 0.5)
b.label:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
end
end
end
for _, opt in ipairs(combatOptions) do
local btn = CreateFrame("Button", nil, addBindingDialog, "BackdropTemplate")
btn:SetPoint("TOPLEFT", xPos, yOffset)
btn:SetSize(125, 26)
btn:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
local label = btn:CreateFontString(nil, "OVERLAY", "DFFontHighlightSmall")
label:SetPoint("CENTER")
label:SetText(opt.label)
btn.label = label
combatButtons[opt.value or "always"] = btn
btn:SetScript("OnClick", function()
bindingData.loadCombat = opt.value
UpdateCombatButtons()
end)
xPos = xPos + 130
end
UpdateCombatButtons()
yOffset = yOffset - 50
-- SAVE / CANCEL BUTTONS
local saveBtn = CreateFrame("Button", nil, addBindingDialog, "BackdropTemplate")
saveBtn:SetPoint("BOTTOMRIGHT", -95, 12)
saveBtn:SetSize(80, 26)
saveBtn:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
saveBtn:SetBackdropColor(themeColor.r * 0.3, themeColor.g * 0.3, themeColor.b * 0.3, 1)
saveBtn:SetBackdropBorderColor(themeColor.r, themeColor.g, themeColor.b, 1)
local saveIcon = saveBtn:CreateTexture(nil, "OVERLAY")
saveIcon:SetPoint("LEFT", 12, 0)
saveIcon:SetSize(14, 14)
saveIcon:SetTexture("Interface\\AddOns\\DandersFrames\\Media\\Icons\\save")
saveIcon:SetVertexColor(C_TEXT.r, C_TEXT.g, C_TEXT.b)
local saveLabel = saveBtn:CreateFontString(nil, "OVERLAY", "DFFontNormal")
saveLabel:SetPoint("LEFT", saveIcon, "RIGHT", 4, 0)
saveLabel:SetText(L["Save"])
saveLabel:SetTextColor(C_TEXT.r, C_TEXT.g, C_TEXT.b)
saveBtn:SetScript("OnEnter", function()
saveBtn:SetBackdropColor(themeColor.r * 0.5, themeColor.g * 0.5, themeColor.b * 0.5, 1)
end)
saveBtn:SetScript("OnLeave", function()
saveBtn:SetBackdropColor(themeColor.r * 0.3, themeColor.g * 0.3, themeColor.b * 0.3, 1)
end)
local function DoSave()
local success = true
if existingIndex then
success = CC:UpdateBinding(existingIndex, bindingData)
else
success = CC:AddBinding(bindingData) ~= nil
end
if not success then
-- Duplicate found, don't close dialog
return
end
addBindingDialog:Hide()
if onComplete then
onComplete()
end
end
saveBtn:SetScript("OnClick", function()
-- Validate that an action was selected
if not validSelection then
-- Flash the selection frame red
selectionFrame:SetBackdropBorderColor(1, 0.3, 0.3, 1)
selectionText:SetText(L["Please select an action!"])
selectionText:SetTextColor(1, 0.4, 0.4)
C_Timer.After(2, function()
if not validSelection then
selectionFrame:SetBackdropBorderColor(C_BORDER.r, C_BORDER.g, C_BORDER.b, 0.5)
selectionText:SetText(L["No action selected"])
selectionText:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
end
end)
return
end
-- Save the binding (multiple bindings on same key allowed for fallback functionality)
DoSave()
end)
local cancelBtn = CreateFrame("Button", nil, addBindingDialog, "BackdropTemplate")
cancelBtn:SetPoint("BOTTOMRIGHT", -10, 12)
cancelBtn:SetSize(80, 26)
cancelBtn:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
cancelBtn:SetBackdropColor(C_ELEMENT.r, C_ELEMENT.g, C_ELEMENT.b, 1)
cancelBtn:SetBackdropBorderColor(C_BORDER.r, C_BORDER.g, C_BORDER.b, 0.5)
local cancelLabel = cancelBtn:CreateFontString(nil, "OVERLAY", "DFFontNormal")
cancelLabel:SetPoint("CENTER")
cancelLabel:SetText(L["Cancel"])
cancelLabel:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
cancelBtn:SetScript("OnEnter", function()
cancelBtn:SetBackdropColor(0.25, 0.25, 0.25, 1)
cancelLabel:SetTextColor(C_TEXT.r, C_TEXT.g, C_TEXT.b)
end)
cancelBtn:SetScript("OnLeave", function()
cancelBtn:SetBackdropColor(C_ELEMENT.r, C_ELEMENT.g, C_ELEMENT.b, 1)
cancelLabel:SetTextColor(C_TEXT_DIM.r, C_TEXT_DIM.g, C_TEXT_DIM.b)
end)
cancelBtn:SetScript("OnClick", function()
addBindingDialog:Hide()
end)
addBindingDialog:Show()
end
-- ============================================================
-- ============================================================
-- BINDING ROW DRAG-TO-REORDER
-- Handle + floating ghost + insert indicator for drag reordering
-- ============================================================
local reorderState = nil -- active drag state
local reorderGhost = nil -- floating cursor-follower frame
local reorderIndicator = nil -- insert-position line
local reorderUpdater = nil -- OnUpdate driver
-- Build the ordered list of currently-visible (enabled) bindings.
local function BuildVisibleSequence()
local seq = {}
local bindings = CC.db and CC.db.bindings or {}
for _, b in ipairs(bindings) do
if b.enabled ~= false then
table.insert(seq, b)
end
end
return seq
end
-- Compute drop zone index (0 .. N) from cursor Y against bindingsContent.
-- Zone 0 = insert before first row, Zone N = insert after last row.
local function ComputeDropZone(visibleCount)
local content = CC.bindingsContent
if not content or visibleCount <= 0 then return 0 end
local scale = content:GetEffectiveScale()
local _, cy = GetCursorPosition()
cy = cy / scale
local top = content:GetTop()
if not top then return 0 end
local relY = top - cy -- distance from content top, in pixels
local rowH = BINDING_ROW_HEIGHT
local zone = math.floor(relY / rowH + 0.5)
if zone < 0 then zone = 0 end
if zone > visibleCount then zone = visibleCount end
return zone
end
local function EnsureGhost()
if reorderGhost then return reorderGhost end
local C = CC.UI_COLORS
local theme = C and C.theme or { r = 1, g = 1, b = 1 }
local g = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
g:SetFrameStrata("TOOLTIP")
g:SetSize(220, 34)
g:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
g:SetBackdropColor(0, 0, 0, 0.88)
g:SetBackdropBorderColor(theme.r, theme.g, theme.b, 1)
local gi = g:CreateTexture(nil, "ARTWORK")
gi:SetSize(24, 24)
gi:SetPoint("LEFT", 4, 0)
gi:SetTexCoord(0.08, 0.92, 0.08, 0.92)
g.icon = gi
local gt = g:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
gt:SetPoint("LEFT", gi, "RIGHT", 6, 0)
gt:SetPoint("RIGHT", -6, 0)
gt:SetJustifyH("LEFT")
gt:SetWordWrap(false)
g.text = gt
g:Hide()
reorderGhost = g
return g
end
local function EnsureIndicator()
if reorderIndicator then return reorderIndicator end
local content = CC.bindingsContent
if not content then return nil end
local C = CC.UI_COLORS
local theme = C and C.theme or { r = 1, g = 1, b = 1 }
local ind = content:CreateTexture(nil, "OVERLAY")
ind:SetHeight(2)
ind:SetColorTexture(theme.r, theme.g, theme.b, 1)
ind:Hide()
reorderIndicator = ind
return ind
end
local function UpdateReorderVisuals()
if not reorderState then return end
local ghost = reorderGhost
if ghost then
local scale = UIParent:GetEffectiveScale()
local cx, cy = GetCursorPosition()
ghost:ClearAllPoints()
ghost:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", cx / scale + 14, cy / scale - 4)
end
local content = CC.bindingsContent
local ind = reorderIndicator
if content and ind then
local zone = ComputeDropZone(reorderState.visibleCount)
reorderState.dropZone = zone
ind:ClearAllPoints()
ind:SetPoint("TOPLEFT", content, "TOPLEFT", 0, -zone * BINDING_ROW_HEIGHT + 1)
ind:SetPoint("TOPRIGHT", content, "TOPRIGHT", 0, -zone * BINDING_ROW_HEIGHT + 1)
ind:Show()
end
end
local function BeginBindingReorder(row, binding)
if InCombatLockdown() then return end -- be defensive, though this is non-secure UI
if not CC.db or not CC.db.bindings then return end
local seq = BuildVisibleSequence()
local sourceVisibleIdx
for i, b in ipairs(seq) do
if b == binding then sourceVisibleIdx = i; break end
end
if not sourceVisibleIdx then return end
reorderState = {
sourceBinding = binding,
sourceRow = row,
sourceVisibleIdx = sourceVisibleIdx,
visibleCount = #seq,
dropZone = sourceVisibleIdx - 1,
}
row:SetAlpha(0.4)
local ghost = EnsureGhost()
if ghost then
if row.icon and row.icon.GetTexture then
ghost.icon:SetTexture(row.icon:GetTexture())
ghost.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
end
if row.name and row.name.GetText then
ghost.text:SetText(row.name:GetText() or "")
end
ghost:Show()
end
EnsureIndicator()
if not reorderUpdater then
reorderUpdater = CreateFrame("Frame")
reorderUpdater:SetScript("OnUpdate", UpdateReorderVisuals)
end
reorderUpdater:Show()
UpdateReorderVisuals()
end
local function CancelBindingReorder()
if reorderState and reorderState.sourceRow then
reorderState.sourceRow:SetAlpha(1)
end
reorderState = nil
if reorderGhost then reorderGhost:Hide() end
if reorderIndicator then reorderIndicator:Hide() end
if reorderUpdater then reorderUpdater:Hide() end
end
local function EndBindingReorder()
if not reorderState then return end
local state = reorderState
local sourceBinding = state.sourceBinding
local sourceVisibleIdx = state.sourceVisibleIdx
local targetZone = state.dropZone or (sourceVisibleIdx - 1)
-- Clean up visuals first (avoid flash during Refresh)
if reorderGhost then reorderGhost:Hide() end
if reorderIndicator then reorderIndicator:Hide() end
if reorderUpdater then reorderUpdater:Hide() end
if state.sourceRow then state.sourceRow:SetAlpha(1) end
reorderState = nil
-- No-op if dropped in its current slot (zones sourceIdx-1 or sourceIdx both mean "stay put")
if targetZone == sourceVisibleIdx - 1 or targetZone == sourceVisibleIdx then
return
end
local seq = BuildVisibleSequence()
-- Re-resolve source index in case array changed underneath
local curSource
for i, b in ipairs(seq) do
if b == sourceBinding then curSource = i; break end
end
if not curSource then return end
table.remove(seq, curSource)
local insertAt = targetZone
if curSource < targetZone then insertAt = insertAt - 1 end
insertAt = math.max(0, math.min(#seq, insertAt))
table.insert(seq, insertAt + 1, sourceBinding)
-- Rebuild CC.db.bindings, preserving disabled entries in their original slots
local oldDb = CC.db.bindings
local newDb = {}
local seqIdx = 1
for _, b in ipairs(oldDb) do
if b.enabled ~= false then
newDb[#newDb + 1] = seq[seqIdx]
seqIdx = seqIdx + 1
else
newDb[#newDb + 1] = b
end
end
CC.db.bindings = newDb
if CC.ApplyBindings then CC:ApplyBindings() end
if CC.RefreshActiveBindings then CC:RefreshActiveBindings() end
if CC.RefreshSpellGrid then CC:RefreshSpellGrid(true) end
end
-- =========================================================================
-- ACTIVE BINDINGS ROW CREATION
-- =========================================================================
function CC:CreateBindingRow(parent, binding, index)
local C = self.UI_COLORS
local themeColor = C.theme
local row = CreateFrame("Button", nil, parent, "BackdropTemplate")
row:SetHeight(BINDING_ROW_HEIGHT - 2)
row:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1,
})
row:SetBackdropColor(C.element.r, C.element.g, C.element.b, 0.8)
row:SetBackdropBorderColor(C.border.r, C.border.g, C.border.b, 0.5)
-- Icon (larger to fill height better)
local icon = row:CreateTexture(nil, "ARTWORK")
icon:SetSize(32, 32)
icon:SetPoint("LEFT", 14, 0) -- Shifted right to make room for drag handle
-- Set icon based on action type
if binding.actionType == "target" then
icon:SetTexture("Interface\\CURSOR\\Crosshairs")
elseif binding.actionType == "menu" then
icon:SetTexture("Interface\\Buttons\\UI-GuildButton-OfficerNote-Up")
elseif binding.actionType == "focus" then
icon:SetTexture("Interface\\Icons\\Ability_Hunter_MasterMarksman")
elseif binding.actionType == "assist" then
icon:SetTexture("Interface\\Icons\\Ability_Hunter_SniperShot")
elseif binding.actionType == CC.ACTION_TYPES.ITEM then
-- Item binding
if binding.itemType == "slot" and binding.itemSlot then
local itemInfo = CC:GetSlotItemInfo(binding.itemSlot)
if itemInfo and itemInfo.icon then
icon:SetTexture(itemInfo.icon)
else
-- Use slot default icon
for _, slotData in ipairs(CC.EQUIPMENT_SLOTS) do
if slotData.slot == binding.itemSlot then
icon:SetTexture(slotData.icon)
break
end
end
end
elseif binding.itemId then
local itemInfo = CC:GetItemInfoById(binding.itemId)
if itemInfo and itemInfo.icon then
icon:SetTexture(itemInfo.icon)
else
icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
end
else
icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
end
elseif binding.actionType == "macro" and binding.macroId then
local macro = CC:GetMacroById(binding.macroId)
if macro then
-- Try to auto-detect icon from macro body first
local autoIcon = CC:GetIconFromMacroBody(macro.body)
if autoIcon then
icon:SetTexture(autoIcon)
elseif macro.icon and type(macro.icon) == "number" and macro.icon > 0 then
icon:SetTexture(macro.icon)
else
icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
end
else
icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
end
elseif binding.spellId or binding.spellName then
-- Get current display icon (accounts for talent overrides like Divine Toll -> Holy Armaments)
local _, displayIcon = GetSpellDisplayInfo(binding.spellId, binding.spellName)
icon:SetTexture(displayIcon or "Interface\\Icons\\INV_Misc_QuestionMark")
else
icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark")
end
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
row.icon = icon
-- Drag handle (far left, thin strip for reordering)
local dragHandle = CreateFrame("Button", nil, row)
dragHandle:SetPoint("TOPLEFT", 0, 0)
dragHandle:SetPoint("BOTTOMLEFT", 0, 0)
dragHandle:SetWidth(10)
dragHandle:RegisterForDrag("LeftButton")
dragHandle:EnableMouse(true)
local handleIcon = dragHandle:CreateTexture(nil, "OVERLAY")
handleIcon:SetSize(8, 14)
handleIcon:SetPoint("CENTER")
handleIcon:SetTexture("Interface\\AddOns\\DandersFrames\\Media\\Icons\\reorder")
handleIcon:SetVertexColor(C.textDim.r, C.textDim.g, C.textDim.b)
dragHandle:SetScript("OnEnter", function(self)
handleIcon:SetVertexColor(themeColor.r, themeColor.g, themeColor.b)
SetCursor("Interface\\CURSOR\\UI-Cursor-Move")
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:AddLine(L["Drag to reorder"], 1, 1, 1)
GameTooltip:Show()
end)
dragHandle:SetScript("OnLeave", function()
handleIcon:SetVertexColor(C.textDim.r, C.textDim.g, C.textDim.b)
SetCursor(nil)
GameTooltip:Hide()
end)
dragHandle:SetScript("OnDragStart", function()
BeginBindingReorder(row, binding)
end)
dragHandle:SetScript("OnDragStop", function()
EndBindingReorder()
end)
row.dragHandle = dragHandle
-- Delete button (far right)
local deleteBtn = CreateFrame("Button", nil, row)
deleteBtn:SetSize(20, 20)
deleteBtn:SetPoint("RIGHT", -4, 0)
local deleteIcon = deleteBtn:CreateTexture(nil, "OVERLAY")
deleteIcon:SetPoint("CENTER")
deleteIcon:SetSize(10, 10)
deleteIcon:SetTexture("Interface\\AddOns\\DandersFrames\\Media\\Icons\\close")
deleteIcon:SetVertexColor(C.textDim.r, C.textDim.g, C.textDim.b)
deleteBtn:SetScript("OnEnter", function()
deleteIcon:SetVertexColor(1, 0.3, 0.3)
end)
deleteBtn:SetScript("OnLeave", function()
deleteIcon:SetVertexColor(C.textDim.r, C.textDim.g, C.textDim.b)
end)
deleteBtn:SetScript("OnClick", function()
for i, b in ipairs(CC.db.bindings) do
if b == binding then
table.remove(CC.db.bindings, i)
break
end
end
CC:ApplyBindings()
CC:RefreshActiveBindings()
CC:RefreshSpellGrid(true) -- Skip scroll reset to maintain position
end)
row.deleteBtn = deleteBtn
-- Format keybind display
local bindText = ""
if binding.bindType == "mouse" then
local modDisplay = ""
if binding.modifiers and binding.modifiers ~= "" then
local mods = binding.modifiers:lower()
if mods:find("shift") then modDisplay = modDisplay .. "Shift+" end
if mods:find("ctrl") then modDisplay = modDisplay .. "Ctrl+" end
if mods:find("alt") then modDisplay = modDisplay .. "Alt+" end
if mods:find("meta") then modDisplay = modDisplay .. "Cmd+" end
end
local buttonName = CC.BUTTON_DISPLAY_NAMES[binding.button] or binding.button
bindText = modDisplay .. buttonName
elseif binding.bindType == "key" then
local modDisplay = ""
if binding.modifiers and binding.modifiers ~= "" then
local mods = binding.modifiers:lower()
if mods:find("shift") then modDisplay = modDisplay .. "Shift+" end
if mods:find("ctrl") then modDisplay = modDisplay .. "Ctrl+" end
if mods:find("alt") then modDisplay = modDisplay .. "Alt+" end
if mods:find("meta") then modDisplay = modDisplay .. "Cmd+" end
end
local keyName = CC.KEY_DISPLAY_NAMES[binding.key] or binding.key
bindText = modDisplay .. keyName
elseif binding.bindType == "scroll" then
local modDisplay = ""
if binding.modifiers and binding.modifiers ~= "" then
local mods = binding.modifiers:lower()
if mods:find("shift") then modDisplay = modDisplay .. "Shift+" end
if mods:find("ctrl") then modDisplay = modDisplay .. "Ctrl+" end
if mods:find("alt") then modDisplay = modDisplay .. "Alt+" end
if mods:find("meta") then modDisplay = modDisplay .. "Cmd+" end
end
local scrollName = CC.SCROLL_DISPLAY_NAMES[binding.key] or binding.key
bindText = modDisplay .. scrollName
end
-- Keybind text (aligned with spell name on top line)
local keybind = row:CreateFontString(nil, "OVERLAY", "DFFontHighlightSmall")
keybind:SetPoint("TOPRIGHT", row, "TOPRIGHT", -28, -6)
keybind:SetJustifyH("RIGHT")
keybind:SetTextColor(themeColor.r, themeColor.g, themeColor.b)
keybind:SetText(bindText)
row.keybind = keybind
row.keybindText = bindText -- Store for collapsed mode
-- Content area - two lines: spell name on top, targeting info below
local displayName = CC:GetActionDisplayString(binding)
-- Spell name (top line, aligned with keybind)
local name = row:CreateFontString(nil, "OVERLAY", "DFFontHighlight")
name:SetPoint("TOPLEFT", icon, "TOPRIGHT", 6, -4)
name:SetPoint("RIGHT", keybind, "LEFT", -8, 0)
name:SetJustifyH("LEFT")
name:SetText(displayName)
name:SetTextColor(C.text.r, C.text.g, C.text.b)
name:SetWordWrap(false)
row.name = name
-- Targeting info (bottom line, below spell name) - human readable format
-- Hide fallback info for macros since they handle their own targeting
local actionType = binding.actionType or ""
local isMacro = (actionType == "macro") or (binding.macroId ~= nil)
local fallback = binding.fallback or {}
local fallbackText = isMacro and nil or GetFallbackDisplayText(fallback)
local combatSetting = binding.combat or "always"
local targetingInfo = row:CreateFontString(nil, "OVERLAY", "DFFontHighlightSmall")
targetingInfo:SetPoint("TOPLEFT", name, "BOTTOMLEFT", 0, -2)
targetingInfo:SetPoint("BOTTOMRIGHT", row, "BOTTOMRIGHT", -28, 4)
targetingInfo:SetJustifyH("LEFT")
targetingInfo:SetJustifyV("TOP")
targetingInfo:SetTextColor(C.textDim.r, C.textDim.g, C.textDim.b)
targetingInfo:SetWordWrap(true)
-- Build targeting description
local targetParts = {}
if fallbackText then
table.insert(targetParts, fallbackText)
end
-- Add combat state if not "always"
if combatSetting == "incombat" then
table.insert(targetParts, L["Combat Only"])
elseif combatSetting == "outofcombat" then
table.insert(targetParts, L["Out of combat"])