-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.lua
More file actions
6566 lines (6327 loc) · 314 KB
/
Copy pathUI.lua
File metadata and controls
6566 lines (6327 loc) · 314 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 _, private = ...
local BindCards = _G.BindCards or private or {}
_G.BindCards = BindCards
local UI = {}
BindCards.UI = UI
local Helpers = BindCards.UIHelpers or {}
UI.themeButtons, UI.themeFonts, UI.themeIcons = {}, {}, {}
local floor, max, min = math.floor, math.max, math.min
local tinsert, tsort = table.insert, table.sort
local unpack = unpack or table.unpack
local FlattenCards, EntryIcon
local MAX_HIERARCHY_SHEETS = 6
local C = {
window = { 0.035, 0.041, 0.052, 0.985 },
panel = { 0.055, 0.063, 0.078, 1 },
paper = { 0.073, 0.082, 0.098, 1 },
paperAlt = { 0.060, 0.069, 0.084, 1 },
raised = { 0.095, 0.108, 0.129, 1 },
border = { 0.20, 0.235, 0.28, 0.72 },
faint = { 0.18, 0.21, 0.25, 0.25 },
blue = { 0.27, 0.58, 0.82, 1 },
blueSoft = { 0.18, 0.36, 0.52, 1 },
teal = { 0.18, 0.76, 0.70, 1 },
drop = { 0.25, 0.90, 0.55, 1 },
amber = { 0.93, 0.66, 0.25, 1 },
amberMuted = { 0.58, 0.45, 0.25, 0.82 },
amberFaint = { 0.55, 0.40, 0.20, 0.34 },
red = { 0.88, 0.31, 0.34, 1 },
text = { 0.91, 0.93, 0.96, 1 },
muted = { 0.59, 0.64, 0.71, 1 },
shortcutInactive = { 0.70, 0.74, 0.81, 1 },
}
local EDGE = "Interface\\Buttons\\WHITE8X8"
local BG = "Interface\\Buttons\\WHITE8X8"
local WHITE_ICON = 134400
local function InCombat()
return InCombatLockdown and InCombatLockdown()
end
local function PlayerClassColor()
local classFile = UnitClass and select(2, UnitClass("player"))
if issecretvalue and issecretvalue(classFile) then classFile = nil end
local color = classFile and RAID_CLASS_COLORS and RAID_CLASS_COLORS[classFile]
if color then return color.r or 1, color.g or 1, color.b or 1 end
return C.text[1], C.text[2], C.text[3]
end
local function CursorInside(frame)
if not frame or not frame:IsShown() or not GetCursorPosition then return false end
local x, y = GetCursorPosition()
local left, right, bottom, top = frame:GetLeft(), frame:GetRight(), frame:GetBottom(), frame:GetTop()
if issecretvalue and (issecretvalue(x) or issecretvalue(y) or issecretvalue(left) or
issecretvalue(right) or issecretvalue(bottom) or issecretvalue(top)) then
return false
end
if not (x and y and left and right and bottom and top) then return false end
local scale = frame:GetEffectiveScale()
return x >= left * scale and x <= right * scale and y >= bottom * scale and y <= top * scale
end
local function CursorOverSurface(frame, capturedDragTarget)
if not frame or not frame:IsShown() then return false end
-- Card dragging retains mouse capture on its source in Retail. Binder
-- return surfaces cannot rely on GetMouseFoci at release time. The target
-- has already been constrained to the card's owning binder, so its full
-- page rectangle is intentionally valid even beneath the active stack.
if capturedDragTarget or frame.bindCardsBinderKey or frame.bindCardsBinderCoverKey then
return CursorInside(frame)
end
if GetMouseFoci then
for _, focus in ipairs(GetMouseFoci() or {}) do
local region = focus
while region do
if region == frame then return CursorInside(frame) end
region = region.GetParent and region:GetParent() or nil
end
end
return false
end
return CursorInside(frame)
end
local function EntryTileUnderCursor()
if not GetMouseFoci then return nil end
for _, focus in ipairs(GetMouseFoci() or {}) do
local region = focus
while region do
if region.bindCardsEntryTile then
if region:IsShown() and CursorInside(region) then return region, true end
break
end
if region.bindCardsCardSurface and region:IsShown() and CursorInside(region) then
return nil, true
end
region = region.GetParent and region:GetParent() or nil
end
end
return nil, false
end
local function CardTabUnderCursor()
-- Retail's hit-test result respects ScrollFrame clipping and occlusion.
-- Raw frame rectangles do not: a clipped docked tab can still report that
-- the cursor is inside it, causing its screen-level drop glow to appear as
-- an unexplained empty rectangle over the card grid.
if GetMouseFoci then
for _, focus in ipairs(GetMouseFoci() or {}) do
local region = focus
while region do
if region.bindCardsCard and region:IsShown() and CursorInside(region) then
return region
end
region = region.GetParent and region:GetParent() or nil
end
end
return nil
end
-- Compatibility fallback for clients/test harnesses without GetMouseFoci.
local strataRank = {
BACKGROUND = 1, LOW = 2, MEDIUM = 3, HIGH = 4, DIALOG = 5,
FULLSCREEN = 6, FULLSCREEN_DIALOG = 7, TOOLTIP = 8,
}
local best, bestRank, bestLevel
for _, view in pairs(UI.cardViews or {}) do
local tab = view.tab
if tab and tab:IsShown() and tab.bindCardsCard and CursorInside(tab) then
local rank = strataRank[tab:GetFrameStrata()] or 0
local level = tab:GetFrameLevel() or 0
if not best or rank > bestRank or (rank == bestRank and level > bestLevel) then
best, bestRank, bestLevel = tab, rank, level
end
end
end
-- Panel mode represents cards with navigator rows instead of physical
-- binder tabs. Treat those rows as equivalent drop targets so an icon
-- can be moved directly to another card without first opening it.
for _, row in ipairs(UI.navRows or {}) do
if row and row:IsShown() and row.bindCardsCard and CursorInside(row) then
local rank = strataRank[row:GetFrameStrata()] or 0
local level = row:GetFrameLevel() or 0
if not best or rank > bestRank or (rank == bestRank and level > bestLevel) then
best, bestRank, bestLevel = row, rank, level
end
end
end
return best
end
local function Call(method, ...)
local fn = BindCards[method]
if type(fn) ~= "function" then return nil end
local ok, a, b, c = pcall(fn, BindCards, ...)
if ok then
if a == nil and type(b) == "string" then UI.lastCallError = b; return false, b end
UI.lastCallError = nil
return a, b, c
end
UI.lastCallError = tostring(a)
if UI.SetStatus then UI:SetStatus("Could not complete that action.", "error") end
return false
end
local function Color(dst, c, alpha)
dst:SetVertexColor(c[1], c[2], c[3], alpha or c[4] or 1)
end
local function Skin(frame, color, border)
frame:SetBackdrop({ bgFile = BG, edgeFile = EDGE, edgeSize = 1 })
local b = border or C.border
frame:SetBackdropColor(unpack(color or C.panel))
frame:SetBackdropBorderColor(unpack(b))
end
function UI:StyleEditableText(edit)
if not edit then return end
-- Compound Blizzard editors do not always enable their inner EditBox.
if edit.EnableMouse then edit:EnableMouse(true) end
if edit.SetTextColor then edit:SetTextColor(1, 1, 1, 1) end
if edit.SetHighlightColor then edit:SetHighlightColor(0.10, 0.70, 0.76, 1) end
if edit.SetBlinkSpeed then edit:SetBlinkSpeed(0.32) end
if not edit.bindCardsTextInputHooks and edit.HookScript then
edit.bindCardsTextInputHooks = true
edit:HookScript("OnEditFocusGained", function(self)
UI:StyleEditableText(self)
-- Consume modified shortcuts so Ctrl+C/Ctrl+V do not reach gameplay bindings.
if self.SetPropagateKeyboardInput then self:SetPropagateKeyboardInput(false) end
end)
edit:HookScript("OnEditFocusLost", function(self)
if self.SetPropagateKeyboardInput then self:SetPropagateKeyboardInput(true) end
end)
end
end
local function Font(parent, size, color, flags)
local text = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
local font = text:GetFont()
text:SetFont(font, size or 12, flags or "")
text:SetTextColor(unpack(color or C.text))
text:SetJustifyH("LEFT")
UI.themeFonts[#UI.themeFonts + 1] = text
if UI.euiApplied and UI.euiSkin and UI.euiSkin.Font then pcall(UI.euiSkin.Font, text) end
return text
end
local function ShortcutLabel(parent, size)
local text = Font(parent, size, C.text, "OUTLINE")
text:SetShadowColor(0, 0, 0, 0.95)
text:SetShadowOffset(1, -1)
return text
end
local function Divider(parent, vertical)
local line = parent:CreateTexture(nil, "BORDER")
line:SetColorTexture(unpack(C.faint))
if vertical then line:SetWidth(1) else line:SetHeight(1) end
return line
end
local function Button(parent, label, width, height, kind)
local b = CreateFrame("Button", nil, parent, "BackdropTemplate")
b:SetSize(width or 88, height or 24)
Skin(b, kind == "primary" and C.blueSoft or C.raised, kind == "danger" and C.red or nil)
b.label = Font(b, 11, C.text, "")
b.label:SetPoint("CENTER", 0, 0)
b.label:SetText(label or "")
b:SetScript("OnEnter", function(self)
self:SetBackdropBorderColor(unpack(kind == "danger" and C.red or C.blue))
self:SetBackdropColor(0.12, 0.14, 0.17, 1)
end)
b:SetScript("OnLeave", function(self)
Skin(self, kind == "primary" and C.blueSoft or C.raised, kind == "danger" and C.red or nil)
end)
UI.themeButtons[#UI.themeButtons + 1] = b
if UI.euiApplied and UI.euiSkin and UI.euiSkin.Button then pcall(UI.euiSkin.Button, b) end
return b
end
local function SetButtonEnabled(button, enabled)
if not button then return end
enabled = enabled == true
if button.SetEnabled then button:SetEnabled(enabled) else button:EnableMouse(enabled) end
button:SetAlpha(enabled and 1 or 0.38)
end
local function UpdateSlimScroll(scroll)
local bar = scroll and scroll.bindCardsScrollBar
if not bar then return end
local range = max(0, scroll:GetVerticalScrollRange() or 0)
bar:SetMinMaxValues(0, range)
bar:SetValue(min(range, max(0, scroll:GetVerticalScroll() or 0)))
bar:SetShown(range > 0.5)
end
local function SkinScrollFrame(scroll)
if not scroll or scroll.bindCardsScrollBar then return end
local stock = scroll.ScrollBar or scroll.scrollBar
if not stock and scroll.GetName and scroll:GetName() then stock = _G[scroll:GetName() .. "ScrollBar"] end
if stock then
stock:SetAlpha(0)
stock:EnableMouse(false)
stock:Hide()
end
if scroll.SetClipsChildren then scroll:SetClipsChildren(true) end
scroll:EnableMouseWheel(true)
local bar = CreateFrame("Slider", nil, scroll:GetParent(), "BackdropTemplate")
bar:SetOrientation("VERTICAL")
bar:SetPoint("TOPLEFT", scroll, "TOPRIGHT", 4, 0)
bar:SetPoint("BOTTOMLEFT", scroll, "BOTTOMRIGHT", 4, 0)
bar:SetWidth(8)
bar:SetValueStep(1)
bar:SetObeyStepOnDrag(false)
Skin(bar, C.paperAlt, C.faint)
bar:SetThumbTexture(EDGE)
local thumb = bar:GetThumbTexture()
thumb:SetColorTexture(unpack(C.teal))
thumb:SetSize(6, 28)
bar:SetScript("OnValueChanged", function(_, value) scroll:SetVerticalScroll(value) end)
scroll:SetScript("OnMouseWheel", function(self, delta)
self:SetVerticalScroll(min(self:GetVerticalScrollRange(), max(0,
self:GetVerticalScroll() - delta * 42)))
UpdateSlimScroll(self)
end)
scroll.bindCardsScrollBar = bar
bar:Hide()
end
local function IconButton(parent, text, size)
local b = Button(parent, text, size or 24, size or 24)
b.label:SetFont(b.label:GetFont(), 14, "")
return b
end
local function CardID(card)
return card and (card.id or card.cardID or card.uid)
end
local function ParentID(card)
return card and (card.parentID or card.parentId or card.parent)
end
local function CardName(card)
return (card and (card.name or card.title)) or "Untitled card"
end
local function IsMainBinderRoot(card)
local templateKey = card and card.templateKey
return templateKey == "default:general" or
(type(templateKey) == "string" and templateKey:match("^default:class:") ~= nil)
end
local function IsStandardCard(card)
local templateKey = card and card.templateKey
return type(templateKey) == "string" and templateKey:match("^default:") ~= nil
end
local function ExperimentalColorPass()
return BindCardsDB and BindCardsDB.settings and
BindCardsDB.settings.experimentalColorPass == true
end
local function IsAmberNestedCard(card)
return ExperimentalColorPass() and
(ParentID(card) ~= nil or card and card.homeParentId ~= nil) and
not IsStandardCard(card)
end
local function ExperimentalCardSurface(base, card, amount)
if not ExperimentalColorPass() then return base end
local red, green, blue
if IsAmberNestedCard(card) then
red, green, blue = C.amber[1], C.amber[2], C.amber[3]
else
red, green, blue = PlayerClassColor()
end
amount = tonumber(amount) or 0.02
return {
base[1] + (red - base[1]) * amount,
base[2] + (green - base[2]) * amount,
base[3] + (blue - base[3]) * amount,
base[4] or 1,
}
end
local function CardSelectionBorder(card, selected)
if IsAmberNestedCard(card) then return C.amber end
return selected and C.blue or C.faint
end
local function IsMutuallyExclusiveSheet(card)
local templateKey = card and card.templateKey
return type(templateKey) == "string" and
(templateKey:match("^default:role:") ~= nil or
templateKey:match("^default:spec:") ~= nil)
end
local function CardPageHeight(card, pageWidth, iconSize, binderKey)
local columns = min(12, max(3, tonumber(card and card.columns) or 6))
local capacity = max(columns, tonumber(card and card.capacity) or columns * 2)
local rows = math.ceil(capacity / columns)
local cardIconSize = min(iconSize or 36, max(18,
floor((pageWidth - 16 - (columns - 1) * 6) / columns)))
local gridHeight = rows * (cardIconSize + 6) - 6
if card and card.collapsed then return 35 end
if binderKey == "general" and Helpers.GeneralPageFootprint then
local _, naturalHeight = Helpers.GeneralPageFootprint(columns, capacity, iconSize)
return naturalHeight
end
return 78 + gridHeight
end
local function CurrentClassBinder()
local className, classFile
if UnitClass then className, classFile = UnitClass("player") end
if issecretvalue then
if issecretvalue(className) then className = nil end
if issecretvalue(classFile) then classFile = nil end
end
classFile = type(classFile) == "string" and classFile ~= "" and classFile or nil
className = type(className) == "string" and className ~= "" and className:upper() or classFile
return classFile and ("class:" .. classFile) or nil, className or "CLASS"
end
local function BinderFamily(card)
local family = Call("GetBinderFamily", card)
if family == "class" then return "class" end
if family == "general" then return "general" end
local binderId = card and card.binderId
if type(binderId) == "string" and binderId:match("^class:") then return "class" end
local condition = card and card.condition or {}
local templateKey = card and card.templateKey
if (type(templateKey) == "string" and templateKey:match("^default:class:")) or condition.class then
return "class"
end
return "general"
end
local FRIENDLY = {
DAMAGER = "Damage", HEALER = "Healer", TANK = "Tank",
DEATHKNIGHT = "Death Knight", DEMONHUNTER = "Demon Hunter",
PVE = "PvE", PVP = "PvP", ANY = "Any",
}
local function Friendly(value, fallback)
if value == nil or value == "" then return fallback end
local text = tostring(value)
return FRIENDLY[text] or text:sub(1, 1) .. text:sub(2):lower()
end
local function Entries(card)
return (card and (card.tiles or card.entries or card.slots or card.abilities or card.actions)) or {}
end
local function EntryGridPosition(card, entry, fallback)
local oldColumns = min(12, max(3, tonumber(card and card.columns) or 6))
local oldSlot = max(1, math.floor(tonumber(entry.order) or fallback or 1))
local x = math.floor(tonumber(entry.gridX) or ((oldSlot - 1) % oldColumns + 1))
local y = math.floor(tonumber(entry.gridY) or (math.floor((oldSlot - 1) / oldColumns) + 1))
return x, y
end
local function EntriesBySlot(card, columns, rows)
local slots, croppedRight, croppedDown = {}, 0, 0
for fallback, entry in ipairs(Entries(card)) do
local x, y = EntryGridPosition(card, entry, fallback)
if x <= columns and y <= rows then
slots[(y - 1) * columns + x] = entry
else
if x > columns then croppedRight = croppedRight + 1 end
if y > rows then croppedDown = croppedDown + 1 end
end
end
return slots, croppedRight, croppedDown
end
local function GetCards()
local cards = Call("GetCards")
if type(cards) ~= "table" then
local profile = Call("GetActiveProfile") or BindCards.activeProfile
cards = profile and profile.cards or BindCards.cards or {}
end
return cards
end
local function IsCardActive(card)
if UI.activeSnapshotReady then
return UI.activeCardStates and UI.activeCardStates[CardID(card)] == true
end
local active, reason = Call("IsCardActive", CardID(card))
if active == nil and BindCards.GetActiveCards then
local profile = Call("GetSelectedProfile")
local activeCards = Call("GetActiveCards", profile)
if type(activeCards) == "table" then
active = false
for _, candidate in ipairs(activeCards) do
if CardID(candidate) == CardID(card) then active = true break end
end
end
end
if active == nil then active = card and card.active ~= false end
return active, reason
end
local function Mutate(label, fn)
if InCombat() then
UI:SetStatus("Editing is unavailable during combat.", "warning")
return false
end
local ok, result, message = pcall(fn)
if not ok or result == false then
local detail = not ok and result or message or UI.lastCallError
UI.lastCallError = nil
UI:SetStatus(type(detail) == "string" and detail or ("Could not " .. label:lower() .. "."), "error")
return false, detail
end
UI:SetStatus(label .. ".", "success")
UI:RequestRefresh()
return true
end
function UI:CaptureUndo(label, profileId)
local snapshot = Call("CreateUndoSnapshot", profileId)
if snapshot then
self.lastUndo = { label = label or "change", profileId = profileId, snapshot = snapshot }
end
end
function UI:UndoLastChange()
local undo = self.lastUndo
if not undo then self:SetStatus("Nothing to undo.", "info"); return false end
local restored, message = Call("RestoreUndoSnapshot", undo.snapshot)
if restored == false then self:SetStatus(message or "Undo failed.", "error"); return false end
self.lastUndo = nil
self:SetStatus("Undid " .. undo.label .. ".", "success")
self:RequestRefresh()
return true
end
function UI:CancelDrag(suppressClick)
local hadCardSession = self.dragSession ~= nil
if self.windowResizing and self.FinishWindowResize then
self:FinishWindowResize(true)
elseif self.frame and self.frame.StopMovingOrSizing then
self.frame:StopMovingOrSizing()
end
for _, view in pairs(self.cardViews or {}) do
if view.StopMovingOrSizing then view:StopMovingOrSizing() end
end
if self.dragSourceTile then
self.dragSourceTile.icon:SetAlpha(self.dragSourceTile.entry and 1 or 0.035)
end
self.dragCard, self.dragEntry, self.dragSession, self.pendingCardDrag = nil, nil, nil, nil
self.pendingEntryDrag, self.dragSourceTile = nil, nil
if self.cardDragWatcher then self.cardDragWatcher:Hide() end
if self.entryDragWatcher then self.entryDragWatcher:Hide() end
if self.dragGhost then self.dragGhost:Hide() end
if self.entryTabGlow then self.entryTabGlow:Hide() end
if self.entryDropCardView then
local view = self.entryDropCardView
local selected = view.card and self.selectedCardID == CardID(view.card)
view:SetBackdropBorderColor(unpack(CardSelectionBorder(view.card, selected)))
self.entryDropCardView = nil
end
if self.homeBinderGlow then self.homeBinderGlow:Hide() end
if self.homeBinderTabGlow then self.homeBinderTabGlow:Hide() end
self.peelingCardID = nil
if self.workspaceDrop then self.workspaceDrop:Hide() end
ResetCursor()
if suppressClick then
self.suppressClick = true
if C_Timer and C_Timer.After then C_Timer.After(0, function() UI.suppressClick = false end) end
else
self.suppressClick = false
end
if hadCardSession and self.workspaceContent then
self:RefreshBinderSelectors()
self:RefreshWorkspace()
end
end
function UI:UpdateEntryCardHighlight()
local target, targetRank, targetLevel
local strataRank = {
BACKGROUND = 1, LOW = 2, MEDIUM = 3, HIGH = 4, DIALOG = 5,
FULLSCREEN = 6, FULLSCREEN_DIALOG = 7, TOOLTIP = 8,
}
if self.dragEntry and not CardTabUnderCursor() then
for _, view in pairs(self.cardViews or {}) do
if view:IsShown() and CursorInside(view) then
local rank = strataRank[view:GetFrameStrata()] or 0
local level = view:GetFrameLevel()
if not target or rank > targetRank or (rank == targetRank and level > targetLevel) then
target, targetRank, targetLevel = view, rank, level
end
end
end
end
if self.entryDropCardView ~= target then
local previous = self.entryDropCardView
if previous then
local selected = previous.card and self.selectedCardID == CardID(previous.card)
previous:SetBackdropBorderColor(unpack(CardSelectionBorder(previous.card, selected)))
end
self.entryDropCardView = target
end
if target then target:SetBackdropBorderColor(unpack(C.drop)) end
end
function UI:ShowEntryDragGhost(entry, copying)
if not entry then return end
if not self.dragGhost then
local ghost = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
ghost:SetSize(40, 40); ghost:SetFrameStrata("FULLSCREEN_DIALOG"); ghost:SetFrameLevel(500)
ghost:EnableMouse(false); Skin(ghost, C.paper, C.blue)
ghost.icon = ghost:CreateTexture(nil, "ARTWORK")
ghost.icon:SetPoint("TOPLEFT", 3, -3); ghost.icon:SetPoint("BOTTOMRIGHT", -3, 3)
ghost.icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
ghost.copy = Font(ghost, 13, C.teal, "OUTLINE")
ghost.copy:SetPoint("BOTTOMRIGHT", -2, 1); ghost.copy:SetText("+")
ghost:SetScript("OnUpdate", function(self)
local x, y = GetCursorPosition()
if issecretvalue and (issecretvalue(x) or issecretvalue(y)) then return end
local scale = UIParent:GetEffectiveScale()
self:ClearAllPoints()
self:SetPoint("CENTER", UIParent, "BOTTOMLEFT", x / scale + 12, y / scale - 12)
end)
self.dragGhost = ghost
end
local size = min(44, max(32, tonumber(BindCardsDB and BindCardsDB.settings and BindCardsDB.settings.iconSize) or 36))
self.dragGhost:SetSize(size, size)
self.dragGhost.icon:SetTexture(EntryIcon(entry))
self.dragGhost.copy:SetShown(copying == true)
self.dragGhost:Show()
end
function UI:UpdateEntryTabHighlight()
local tab = self.dragEntry and CardTabUnderCursor()
if not tab then
if self.entryTabGlow then self.entryTabGlow:Hide() end
return
end
if not self.entryTabGlow then
local glow = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
glow:EnableMouse(false)
glow:SetFrameStrata("TOOLTIP")
self.entryTabGlow = glow
end
local glow = self.entryTabGlow
glow:ClearAllPoints(); glow:SetAllPoints(tab)
glow:SetFrameLevel(tab:GetFrameLevel() + 20)
Skin(glow, { 0.04, 0.16, 0.13, 0.20 }, C.drop)
glow:Show()
end
function UI:StartEntryDrag(tile)
if self.dragEntry or not tile or not tile.entry or InCombat() then return false end
self.pendingEntryDrag = nil
self.dragEntry = {
card = tile.card, entry = tile.entry,
copy = IsShiftKeyDown and IsShiftKeyDown(),
}
self.dragSourceTile = tile
tile.icon:SetAlpha(0.30)
self.suppressClick = true
SetCursor("CAST_CURSOR")
self:ShowEntryDragGhost(tile.entry, self.dragEntry.copy)
return true
end
function UI:ArmEntryDrag(tile)
if self.quickBind or InCombat() or not tile or not tile.entry then return end
local x, y = GetCursorPosition()
if issecretvalue and (issecretvalue(x) or issecretvalue(y)) then return end
self.pendingEntryDrag = { tile = tile, startX = x, startY = y }
if not self.entryDragWatcher then
local watcher = CreateFrame("Frame", nil, UIParent)
watcher:Hide()
watcher:SetScript("OnUpdate", function()
if UI.dragEntry then
UI:UpdateEntryTabHighlight()
UI:UpdateEntryCardHighlight()
if IsMouseButtonDown and not IsMouseButtonDown("LeftButton") then UI:FinishEntryDrag() end
return
end
local pending = UI.pendingEntryDrag
if not pending then watcher:Hide(); return end
if IsMouseButtonDown and not IsMouseButtonDown("LeftButton") then
UI.pendingEntryDrag = nil; watcher:Hide(); return
end
local cursorX, cursorY = GetCursorPosition()
if issecretvalue and (issecretvalue(cursorX) or issecretvalue(cursorY)) then return end
local dx, dy = cursorX - pending.startX, cursorY - pending.startY
if dx * dx + dy * dy >= 9 then UI:StartEntryDrag(pending.tile) end
end)
self.entryDragWatcher = watcher
end
self.entryDragWatcher:Show()
end
function UI:ReleaseEntryDrag()
local pending = self.pendingEntryDrag
if not self.dragEntry and pending then
local x, y = GetCursorPosition()
if not (issecretvalue and (issecretvalue(x) or issecretvalue(y))) then
local dx, dy = x - pending.startX, y - pending.startY
if dx * dx + dy * dy >= 9 then self:StartEntryDrag(pending.tile) end
end
end
if self.dragEntry then self:FinishEntryDrag() end
self.pendingEntryDrag = nil
if self.entryDragWatcher and not self.dragEntry then self.entryDragWatcher:Hide() end
end
function UI:ArmCardDrag(view, rootCard, sourceTab, peelFromBinder)
if BindCardsDB and BindCardsDB.settings and BindCardsDB.settings.workspaceMode == "panel" then return end
-- A card cannot own resize and move gestures at the same time.
local viewCardID = view and view.card and CardID(view.card)
if self.cardResize then self:FinishCardResize(false) end
if self.gridResize then self:FinishGridResize(false) end
if viewCardID and self.cardViews and self.cardViews[viewCardID] then
view = self.cardViews[viewCardID]
end
if InCombat() or not view or not rootCard or
(ParentID(rootCard) and not self:CanPeelCard(rootCard)) then return end
local x, y = GetCursorPosition()
if issecretvalue and (issecretvalue(x) or issecretvalue(y)) then return end
self.pendingCardDrag = {
view = view, root = rootCard, sourceTab = sourceTab,
peel = peelFromBinder, startX = x, startY = y,
}
if not self.cardDragWatcher then
local watcher = CreateFrame("Frame", nil, UIParent)
watcher:Hide()
watcher:SetScript("OnUpdate", function()
if UI.dragSession then
UI:UpdateCardDragPosition()
if IsMouseButtonDown and not IsMouseButtonDown("LeftButton") then UI:FinishCardDrag() end
return
end
local pending = UI.pendingCardDrag
if not pending then watcher:Hide(); return end
if IsMouseButtonDown and not IsMouseButtonDown("LeftButton") then
UI.pendingCardDrag = nil; watcher:Hide(); return
end
local cursorX, cursorY = GetCursorPosition()
if issecretvalue and (issecretvalue(cursorX) or issecretvalue(cursorY)) then return end
local dx, dy = cursorX - pending.startX, cursorY - pending.startY
if dx * dx + dy * dy >= 36 then
UI.pendingCardDrag = nil
UI:BeginCardDrag(pending.view, pending.peel, pending.root, pending.sourceTab)
end
end)
self.cardDragWatcher = watcher
end
self.cardDragWatcher:Show()
end
function UI:ReleaseCardDrag()
local pending = self.pendingCardDrag
if not self.dragSession and pending then
local x, y = GetCursorPosition()
if not (issecretvalue and (issecretvalue(x) or issecretvalue(y))) then
local dx, dy = x - pending.startX, y - pending.startY
if dx * dx + dy * dy >= 36 then
self.pendingCardDrag = nil
self:BeginCardDrag(pending.view, pending.peel, pending.root, pending.sourceTab)
end
end
end
if self.dragSession then self:FinishCardDrag() end
self.pendingCardDrag = nil
if self.cardDragWatcher and not self.dragSession then self.cardDragWatcher:Hide() end
end
function UI:IsEUITheme()
return true
end
function UI:UpdateEUIAccent()
local skin = self.euiSkin
if not skin or not skin.GetAccentColor then return end
local ok, r, g, b = pcall(skin.GetAccentColor)
if not ok or type(r) ~= "number" or type(g) ~= "number" or type(b) ~= "number" then return end
C.blue[1], C.blue[2], C.blue[3] = r, g, b
C.teal[1], C.teal[2], C.teal[3] = r, g, b
if self.frame then self:RefreshWorkspace() end
end
function UI:ApplyEUITheme(skin)
self.euiSkin = skin or self.euiSkin
skin = self.euiSkin
if not skin or not self:IsEUITheme() or not self.frame or self.euiApplied then return end
self.euiApplied = true
local binderMode = not (BindCardsDB and BindCardsDB.settings and BindCardsDB.settings.workspaceMode == "panel")
if skin.Shell and self.panelShell then pcall(skin.Shell, self.panelShell, { bottomBar = 24 }) end
if skin.Panel then
if self.header then pcall(skin.Panel, self.header) end
if self.centerBackdrop and not binderMode then pcall(skin.Panel, self.centerBackdrop, { inset = true }) end
if self.navPanel then pcall(skin.Panel, self.navPanel, { inset = true }) end
if self.rightPanel then pcall(skin.Panel, self.rightPanel, { inset = true }) end
if self.entryPanel then pcall(skin.Panel, self.entryPanel, { inset = true }) end
if self.displayPopover then pcall(skin.Panel, self.displayPopover, { inset = true }) end
if self.modal then pcall(skin.Panel, self.modal, { inset = true }) end
if self.capture then pcall(skin.Panel, self.capture, { inset = true }) end
end
for _, fontString in ipairs(self.themeFonts) do
if skin.Font then pcall(skin.Font, fontString) end
end
for _, button in ipairs(self.themeButtons) do
if skin.Button then pcall(skin.Button, button, button.Icon and { "Icon" } or nil) end
end
for _, iconInfo in ipairs(self.themeIcons) do
if skin.SquareIcon then pcall(skin.SquareIcon, iconInfo.texture, iconInfo.parent) end
end
if self.closeButton and skin.CloseButton then
-- EUI supplies its own close glyph; do not leave our text glyph under it.
if self.closeButton.label then self.closeButton.label:SetText("") end
pcall(skin.CloseButton, self.closeButton)
end
if skin.EditBox then
if self.modal and self.modal.edit then pcall(skin.EditBox, self.modal.edit) end
if self.modal and self.modal.multi then pcall(skin.EditBox, self.modal.multi) end
if self.profileTransfer and self.profileTransfer.edit then
pcall(skin.EditBox, self.profileTransfer.edit)
end
end
-- External skins may replace EditBox colours. Restore the accessibility
-- treatment after they have finished.
if self.modal then
self:StyleEditableText(self.modal.edit)
self:StyleEditableText(self.modal.multi)
end
if self.profileTransfer then self:StyleEditableText(self.profileTransfer.edit) end
self:UpdateEUIAccent()
if binderMode then
self.frame:SetBackdropColor(0, 0, 0, 0)
self.frame:SetBackdropBorderColor(0, 0, 0, 0)
if self.centerPanel.SetBackdrop then self.centerPanel:SetBackdrop(nil) end
if self.centerBackdrop then self.centerBackdrop:Hide() end
end
if skin.OnLooksChanged then pcall(skin.OnLooksChanged, function() UI:UpdateEUIAccent() end) end
end
function UI:ApplyFloatingGroupLayer(view, bringToFront)
if not view then return end
local root = view.groupRoot or view.card
local rootID = CardID(root)
if not rootID then return end
self.floatingZOrder = self.floatingZOrder or {}
self.floatingZSerial = tonumber(self.floatingZSerial) or 0
if bringToFront and self.floatingZSerial >= 240 then
local ordered, seen = {}, {}
for _, candidate in pairs(self.cardViews or {}) do
local candidateRoot = candidate.groupRoot or candidate.card
local candidateID = CardID(candidateRoot)
if candidate:IsShown() and candidateRoot and candidateRoot.layoutMode == "floating" and not seen[candidateID] then
seen[candidateID] = true
ordered[#ordered + 1] = { id = candidateID, rank = self.floatingZOrder[candidateID] or 0 }
end
end
tsort(ordered, function(a, b) return a.rank < b.rank end)
self.floatingZOrder, self.floatingZSerial = {}, 0
for _, item in ipairs(ordered) do
self.floatingZSerial = self.floatingZSerial + 1
self.floatingZOrder[item.id] = self.floatingZSerial
end
end
if bringToFront or not self.floatingZOrder[rootID] then
self.floatingZSerial = self.floatingZSerial + 1
self.floatingZOrder[rootID] = self.floatingZSerial
end
-- Give every floating stack a wide, private level band. Its paper sheets,
-- card, buttons, and cells cannot interleave with another floating stack.
local baseLevel = 60 + self.floatingZOrder[rootID] * 32
local function Layer(frame, depth)
if not frame then return end
frame:SetFrameStrata("DIALOG")
frame:SetFrameLevel(baseLevel + min(depth, 12))
frame.bindCardsFloatingOwner = view
if frame.IsObjectType and frame:IsObjectType("Button") and not frame.bindCardsFloatingClickRaiseHook then
frame.bindCardsFloatingClickRaiseHook = true
frame:HookScript("OnClick", function(self)
local owner = self.bindCardsFloatingOwner
local ownerRoot = owner and (owner.groupRoot or owner.card)
if owner and owner:IsShown() and ownerRoot and ownerRoot.layoutMode == "floating" then
UI:RaiseFloatingGroup(owner)
end
end)
end
for _, child in ipairs({ frame:GetChildren() }) do Layer(child, depth + 1) end
end
for index, sheet in ipairs((self.floatingSheets and self.floatingSheets[rootID]) or {}) do
if sheet:IsShown() then
sheet:SetFrameStrata("DIALOG")
sheet:SetFrameLevel(baseLevel + index)
sheet.bindCardsFloatingOwner = view
end
end
Layer(view, 8)
-- A stack reads correctly only when the selected page and its own tab are
-- one front layer. Keep every sibling tab immediately below the page so
-- it can protrude at the edge without painting over the selected sheet.
local selectedID = CardID(view.card)
local function LayerTab(frame, depth)
if not frame then return end
frame:SetFrameStrata("DIALOG")
frame:SetFrameLevel(baseLevel + depth)
frame.bindCardsFloatingOwner = view
-- Match embedded-tab layering: interactive children must sit above the
-- parent button. Flattening them onto the parent's level makes the tab
-- capture the click as a drag before the expand button can receive it.
for _, child in ipairs({ frame:GetChildren() }) do LayerTab(child, depth + 1) end
end
for _, candidate in pairs(self.cardViews or {}) do
local tab = candidate.tab
if tab and tab:IsShown() and tab.groupRoot == root then
LayerTab(tab, CardID(candidate.card) == selectedID and 24 or 7)
end
end
end
function UI:RaiseFloatingGroup(view)
if not view then return end
local root = view.groupRoot or view.card
if not root or root.layoutMode ~= "floating" then return end
self:ApplyFloatingGroupLayer(view, true)
end
function UI:ApplyEmbeddedLayer(frame, baseLevel)
if not frame then return end
local function Layer(childFrame, depth)
childFrame:SetFrameStrata("HIGH")
childFrame:SetFrameLevel(baseLevel + min(depth, 12))
childFrame.bindCardsFloatingOwner = nil
for _, child in ipairs({ childFrame:GetChildren() }) do Layer(child, depth + 1) end
end
Layer(frame, 0)
end
function UI:ApplyDockedEarLayer(frame, selected)
if not frame then return end
local strata, baseLevel = "DIALOG", (selected and 52 or 44)
if Helpers.HierarchyEarLayer then strata, baseLevel = Helpers.HierarchyEarLayer(selected) end
local function Layer(childFrame, depth)
childFrame:SetFrameStrata(strata)
childFrame:SetFrameLevel(baseLevel + min(depth, 6))
childFrame.bindCardsFloatingOwner = nil
for _, child in ipairs({ childFrame:GetChildren() }) do Layer(child, depth + 1) end
end
frame:EnableMouse(true)
Layer(frame, 0)
end
function UI:UpdateBinderStrings()
local enabled = BindCardsDB and BindCardsDB.settings and
BindCardsDB.settings.experimentalBinderStrings == true
for _, cord in ipairs(self.binderStrings or {}) do
cord.shadow:Hide(); cord.accent:Hide(); cord.startDot:Hide(); cord.endDot:Hide()
end
if not enabled or not self.frame or not self.frame:IsShown() then
if self.binderStringLayer then self.binderStringLayer:Hide() end
return
end
if not self.binderStringLayer then
local layer = CreateFrame("Frame", nil, UIParent)
layer:SetAllPoints(UIParent)
layer:SetFrameStrata("DIALOG")
layer:SetFrameLevel(18)
layer:EnableMouse(false)
self.binderStringLayer, self.binderStrings = layer, {}
end
self.binderStringLayer:Show()
local cardsByID = {}
for _, card in ipairs(GetCards()) do cardsByID[CardID(card)] = card end
local function VisibleGroupView(root)
local rootID = CardID(root)
for _, view in pairs(self.cardViews or {}) do
if view:IsShown() and CardID(view.groupRoot or view.card) == rootID then return view end
end
end
local function OwningRoot(card)
local owner, seen = cardsByID[card.homeParentId], {}
while owner and ParentID(owner) and not seen[CardID(owner)] do
seen[CardID(owner)] = true
owner = cardsByID[ParentID(owner)] or owner
if not cardsByID[ParentID(owner)] then break end
end
return owner
end
local function Cord(index)
local cord = self.binderStrings[index]
if cord then return cord end
local layer = self.binderStringLayer
cord = {
shadow = layer:CreateLine(nil, "BACKGROUND"),
accent = layer:CreateLine(nil, "ARTWORK"),
startDot = layer:CreateTexture(nil, "ARTWORK"),
endDot = layer:CreateTexture(nil, "ARTWORK"),
}
cord.shadow:SetThickness(4)
cord.shadow:SetColorTexture(0, 0, 0, 0.55)
cord.accent:SetThickness(1.6)
cord.accent:SetColorTexture(C.teal[1], C.teal[2], C.teal[3], 0.78)
for _, dot in ipairs({ cord.startDot, cord.endDot }) do
dot:SetSize(5, 5)
dot:SetColorTexture(C.teal[1], C.teal[2], C.teal[3], 0.88)
end
self.binderStrings[index] = cord
return cord
end
local connections = {}
for _, child in ipairs(GetCards()) do
if child.layoutMode == "floating" and child.homeParentId then
local owner = OwningRoot(child)
local ownerView = owner and owner.layoutMode == "floating" and VisibleGroupView(owner)
local childView = VisibleGroupView(child)
if ownerView and childView and ownerView ~= childView then
local ownerX, ownerY = ownerView:GetCenter()
local childX, childY = childView:GetCenter()
if ownerX and ownerY and childX and childY then
local startPoint, endPoint
if math.abs(childX - ownerX) >= math.abs(childY - ownerY) then
startPoint = childX >= ownerX and "RIGHT" or "LEFT"
endPoint = childX >= ownerX and "LEFT" or "RIGHT"
else
startPoint = childY >= ownerY and "TOP" or "BOTTOM"
endPoint = childY >= ownerY and "BOTTOM" or "TOP"