Repository navigation
Expand file tree
/
Copy pathEUI_UnlockMode_Session.lua
More file actions
2648 lines (2413 loc) · 121 KB
/
Copy pathEUI_UnlockMode_Session.lua
File metadata and controls
2648 lines (2413 loc) · 121 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
if EUI_CLIENT_BLOCKED then return end -- pre-12.1 client failsafe (EllesmereUI_ClientGate.lua)
-------------------------------------------------------------------------------
-- EUI_UnlockMode_Session.lua
-- Unlock Mode session: top banner HUD, save / revert, spec overrides,
-- open / close with their animations, the one-time how-to-use tip.
-- Loaded after EUI_UnlockMode.lua; _unlockCoreInit runs it once with UM.
-------------------------------------------------------------------------------
local _, EUI_NS = ...
EUI_NS = EUI_NS.__euiCoreNS or EUI_NS -- standalone builds: the core's own table (EllesmereUI.lua)
EUI_NS.unlockParts = EUI_NS.unlockParts or {}
EUI_NS.unlockParts.Session = function(UM)
local ns, EAB, min, max = EUI_NS, UM.EAB, UM.min, UM.max
local sin, FONT_PATH, LOCK_INNER, LOCK_OUTER = UM.sin, UM.FONT_PATH, UM.LOCK_INNER, UM.LOCK_OUTER
local LOCK_TOP, MOVER_ALPHA, GEAR_ROTATION, ALL_BAR_ORDER = UM.LOCK_TOP, UM.MOVER_ALPHA, UM.GEAR_ROTATION, UM.ALL_BAR_ORDER
local registeredElements, registeredOrder, RebuildRegisteredOrder, movers = UM.registeredElements, UM.registeredOrder, UM.RebuildRegisteredOrder, UM.movers
local lockAnimFrame, pendingPositions, snapshotPositions, snapshotAnchors = UM.lockAnimFrame, UM.pendingPositions, UM.snapshotPositions, UM.snapshotAnchors
local snapshotSizes, snapshotWidthMatch, snapshotHeightMatch, snapshotGrowDirs = UM.snapshotSizes, UM.snapshotWidthMatch, UM.snapshotHeightMatch, UM.snapshotGrowDirs
local GridHudAlpha, GridLabelText, CycleGridMode, _blizzOwnedOverlays = UM.GridHudAlpha, UM.GridLabelText, UM.CycleGridMode, UM._blizzOwnedOverlays
local GetAnchorDB, MatchH, ValidateStoredLinks, FadeOverlayForSelectElement = UM.GetAnchorDB, UM.MatchH, UM.ValidateStoredLinks, UM.FadeOverlayForSelectElement
local CancelPickMode, ReapplyAllAnchors, ConvertToCenterPos, ClearBarPosition = UM.CancelPickMode, UM.ReapplyAllAnchors, UM.ConvertToCenterPos, UM.ClearBarPosition
local InstallAnchorGuard, GetAccent, CreateGrid, HideAllGuidesAndHighlight = UM.InstallAnchorGuard, UM.GetAccent, UM.CreateGrid, UM.HideAllGuidesAndHighlight
local SelectMover, DeselectMover, ApplyDarkOverlays, SetupArrowKeyFrame = UM.SelectMover, UM.DeselectMover, UM.ApplyDarkOverlays, UM.SetupArrowKeyFrame
local SortMoverFrameLevels, ShowBlizzOwnedOverlays, HideBlizzOwnedOverlays, CreateMover = UM.SortMoverFrameLevels, UM.ShowBlizzOwnedOverlays, UM.HideBlizzOwnedOverlays, UM.CreateMover
-------------------------------------------------------------------------------
-- Top Banner Bar: single pre-rendered banner image (1144x120), displayed
-- pixel-perfect at native resolution, flush with top of screen. Grid + magnet
-- toggle icons overlaid on top. Slides down during the SHACKLE animation phase.
-------------------------------------------------------------------------------
local GRID_ICON = "Interface\\AddOns\\EllesmereUI\\media\\icons\\grid.png"
local MAGNET_ICON = "Interface\\AddOns\\EllesmereUI\\media\\icons\\magnet.png"
local FLASHLIGHT_ICON = "Interface\\AddOns\\EllesmereUI\\media\\icons\\flashlight.png"
local HOVER_ICON = "Interface\\AddOns\\EllesmereUI\\media\\icons\\hover.png"
local DARK_OVERLAY_ICON = "Interface\\AddOns\\EllesmereUI\\media\\icons\\dark-overlay.png"
local COORD_ICON = "Interface\\AddOns\\EllesmereUI\\media\\icons\\coordinates.png"
local BANNER_TEX = "Interface\\AddOns\\EllesmereUI\\media\\eui-unlocked-banner-2.png"
local HUD_ON_ALPHA = 0.60
local HUD_OFF_ALPHA = 0.30
local HUD_ICON_SZ = 20
-- Banner native pixel dimensions
local BANNER_PX_W = 1144
local BANNER_PX_H = 120
UM.hudFrame = nil
-- Stable visible-height anchor for other addons that stack controls below the banner.
function EllesmereUI:GetUnlockModeTopBarAnchor()
return UM.hudFrame and UM.hudFrame._hoverZone
end
local hoverBarEnabled = false -- show-bar-on-hover toggle
local function CreateHUD(parent)
if UM.hudFrame then return UM.hudFrame end
local ar, ag, ab = GetAccent()
-- Load saved settings
if EllesmereUIDB then
if EllesmereUIDB.unlockGridMode == nil then EllesmereUIDB.unlockGridMode = "dimmed" end
if EllesmereUIDB.unlockSnapEnabled == nil then EllesmereUIDB.unlockSnapEnabled = true end
end
UM.gridMode = (EllesmereUIDB and EllesmereUIDB.unlockGridMode) or "dimmed"
UM.snapEnabled = (EllesmereUIDB and EllesmereUIDB.unlockSnapEnabled ~= false) or true
-- Pixel-perfect scale: 1 frame unit = 1 physical screen pixel
local physW = (GetPhysicalScreenSize())
local uiScale = GetScreenWidth() / physW
-- At very low UI scales the top bar gets too small to read; enlarge it 15%.
-- Bumping the base here propagates through every downstream scale use
-- (initial scale, user banner scale, slide-in offsets read GetScale()).
if UIParent:GetEffectiveScale() < 0.6 then uiScale = uiScale * 1.08 end
UM.hudFrame = CreateFrame("Frame", nil, parent)
UM.hudFrame:SetFrameStrata("TOOLTIP")
UM.hudFrame:SetFrameLevel(900)
UM.hudFrame:SetSize(BANNER_PX_W, BANNER_PX_H)
UM.hudFrame:SetScale(uiScale)
UM.hudFrame:EnableMouse(false) -- background only, clicks pass through
-- Start off-screen above
UM.hudFrame:SetPoint("TOP", UIParent, "TOP", 0, (BANNER_PX_H + 10) * uiScale)
-- Banner image at native resolution
local bannerTex = UM.hudFrame:CreateTexture(nil, "ARTWORK")
bannerTex:SetTexture(BANNER_TEX)
bannerTex:SetSize(BANNER_PX_W, BANNER_PX_H)
bannerTex:SetPoint("TOPLEFT", UM.hudFrame, "TOPLEFT", 0, 0)
if bannerTex.SetSnapToPixelGrid then bannerTex:SetSnapToPixelGrid(false); bannerTex:SetTexelSnappingBias(0) end
UM.hudFrame._bannerTex = bannerTex
-- Icons at native 28x28 resolution (banner frame is already pixel-perfect scaled)
-- Vertically centered within the 58px visible banner area, shifted up 1px
local iconSz = 28
local BANNER_VIS_H = 58
local iconCenterY = -(BANNER_VIS_H / 2) + 1 -- -28px from top (centered + 1px up)
-- Helper: shared hover/click behavior for icon+label wrapper buttons
local function SetupToggleBtn(wrapper, iconTex, labelFS, getState, setState)
wrapper:SetScript("OnClick", function() setState() end)
wrapper:SetScript("OnEnter", function()
iconTex:SetAlpha(0.9)
labelFS:SetTextColor(1, 1, 1, 0.9)
end)
wrapper:SetScript("OnLeave", function()
local a = getState() and HUD_ON_ALPHA or HUD_OFF_ALPHA
iconTex:SetAlpha(a)
labelFS:SetTextColor(1, 1, 1, a)
end)
end
---------------------------------------------------------------
-- Grid toggle (left of center): label LEFT of icon
---------------------------------------------------------------
local gridBtn = CreateFrame("Button", nil, UM.hudFrame)
-- Size will be set after label is created to encompass icon + gap + label
gridBtn:SetPoint("RIGHT", UM.hudFrame, "TOP", -80 + iconSz / 2, iconCenterY)
local gridTex = gridBtn:CreateTexture(nil, "OVERLAY")
gridTex:SetSize(iconSz, iconSz)
gridTex:SetPoint("RIGHT", gridBtn, "RIGHT", 0, 0)
gridTex:SetTexture(GRID_ICON)
gridTex:SetAlpha(GridHudAlpha())
gridBtn._tex = gridTex
local gridLabel = gridBtn:CreateFontString(nil, "OVERLAY")
gridLabel:SetFont(FONT_PATH, 10, "OUTLINE, SLUG")
gridLabel:SetJustifyH("RIGHT")
gridLabel:SetPoint("RIGHT", gridTex, "LEFT", -5, 0)
gridLabel:SetTextColor(1, 1, 1, GridHudAlpha())
gridLabel:SetText(EllesmereUI.L(GridLabelText()))
gridBtn._label = gridLabel
-- Size wrapper to fit label + gap + icon
local gridLabelW = gridLabel:GetStringWidth() or 80
gridBtn:SetSize(gridLabelW + 5 + iconSz, max(iconSz, 24))
-- Custom 3-state toggle (not using SetupToggleBtn)
gridBtn:SetScript("OnClick", function()
CycleGridMode()
if EllesmereUIDB then EllesmereUIDB.unlockGridMode = UM.gridMode end
local a = GridHudAlpha()
gridTex:SetAlpha(a)
gridLabel:SetTextColor(1, 1, 1, a)
gridLabel:SetText(EllesmereUI.L(GridLabelText()))
if UM.gridFrame then
if UM.gridMode ~= "disabled" then
UM.gridFrame:Rebuild()
UM.gridFrame:Show()
else
UM.gridFrame:Hide()
end
end
end)
gridBtn:SetScript("OnEnter", function()
gridTex:SetAlpha(0.9)
gridLabel:SetTextColor(1, 1, 1, 0.9)
end)
gridBtn:SetScript("OnLeave", function()
local a = GridHudAlpha()
gridTex:SetAlpha(a)
gridLabel:SetTextColor(1, 1, 1, a)
end)
UM.hudFrame._gridBtn = gridBtn
---------------------------------------------------------------
-- Dark Overlays toggle (left of grid): label LEFT of icon
---------------------------------------------------------------
local darkOverlayBtn = CreateFrame("Button", nil, UM.hudFrame)
darkOverlayBtn:SetPoint("RIGHT", gridBtn, "LEFT", -20, 0)
local darkOverlayTex = darkOverlayBtn:CreateTexture(nil, "OVERLAY")
darkOverlayTex:SetSize(iconSz, iconSz)
darkOverlayTex:SetPoint("RIGHT", darkOverlayBtn, "RIGHT", 0, 0)
darkOverlayTex:SetTexture(DARK_OVERLAY_ICON)
darkOverlayTex:SetAlpha(UM.darkOverlaysEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
darkOverlayBtn._tex = darkOverlayTex
local darkOverlayLabel = darkOverlayBtn:CreateFontString(nil, "OVERLAY")
darkOverlayLabel:SetFont(FONT_PATH, 10, "OUTLINE, SLUG")
darkOverlayLabel:SetJustifyH("RIGHT")
darkOverlayLabel:SetPoint("RIGHT", darkOverlayTex, "LEFT", -5, 0)
darkOverlayLabel:SetTextColor(1, 1, 1, UM.darkOverlaysEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
darkOverlayLabel:SetText(UM.darkOverlaysEnabled and EllesmereUI.L("Dark Overlays\nEnabled") or EllesmereUI.L("Dark Overlays\nDisabled"))
darkOverlayBtn._label = darkOverlayLabel
local darkOverlayLabelW = darkOverlayLabel:GetStringWidth() or 80
darkOverlayBtn:SetSize(darkOverlayLabelW + 5 + iconSz, max(iconSz, 24))
SetupToggleBtn(darkOverlayBtn, darkOverlayTex, darkOverlayLabel,
function() return UM.darkOverlaysEnabled end,
function()
UM.darkOverlaysEnabled = not UM.darkOverlaysEnabled
darkOverlayTex:SetAlpha(UM.darkOverlaysEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
darkOverlayLabel:SetTextColor(1, 1, 1, UM.darkOverlaysEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
darkOverlayLabel:SetText(UM.darkOverlaysEnabled and EllesmereUI.L("Dark Overlays\nEnabled") or EllesmereUI.L("Dark Overlays\nDisabled"))
ApplyDarkOverlays()
end)
UM.hudFrame._darkOverlayBtn = darkOverlayBtn
---------------------------------------------------------------
-- Flashlight toggle (left of grid): label LEFT of icon
---------------------------------------------------------------
local flashBtn = CreateFrame("Button", nil, UM.hudFrame)
flashBtn:SetPoint("RIGHT", darkOverlayBtn, "LEFT", -20, 0)
local flashTex = flashBtn:CreateTexture(nil, "OVERLAY")
flashTex:SetSize(iconSz, iconSz)
flashTex:SetPoint("RIGHT", flashBtn, "RIGHT", 0, 0)
flashTex:SetTexture(FLASHLIGHT_ICON)
flashTex:SetAlpha(UM.flashlightEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
flashBtn._tex = flashTex
local flashLabel = flashBtn:CreateFontString(nil, "OVERLAY")
flashLabel:SetFont(FONT_PATH, 10, "OUTLINE, SLUG")
flashLabel:SetJustifyH("RIGHT")
flashLabel:SetPoint("RIGHT", flashTex, "LEFT", -5, 0)
flashLabel:SetTextColor(1, 1, 1, UM.flashlightEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
flashLabel:SetText(UM.flashlightEnabled and EllesmereUI.L("Cursor Light\nEnabled") or EllesmereUI.L("Cursor Light\nDisabled"))
flashBtn._label = flashLabel
local flashLabelW = flashLabel:GetStringWidth() or 80
flashBtn:SetSize(flashLabelW + 5 + iconSz, max(iconSz, 24))
SetupToggleBtn(flashBtn, flashTex, flashLabel,
function() return UM.flashlightEnabled end,
function()
UM.flashlightEnabled = not UM.flashlightEnabled
flashTex:SetAlpha(UM.flashlightEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
flashLabel:SetTextColor(1, 1, 1, UM.flashlightEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
flashLabel:SetText(UM.flashlightEnabled and EllesmereUI.L("Cursor Light\nEnabled") or EllesmereUI.L("Cursor Light\nDisabled"))
end)
UM.hudFrame._flashBtn = flashBtn
---------------------------------------------------------------
-- Magnet/Snap toggle (right of center): label RIGHT of icon
---------------------------------------------------------------
local magnetBtn = CreateFrame("Button", nil, UM.hudFrame)
magnetBtn:SetPoint("LEFT", UM.hudFrame, "TOP", 76 - iconSz / 2, iconCenterY)
local magnetTex = magnetBtn:CreateTexture(nil, "OVERLAY")
magnetTex:SetSize(iconSz, iconSz)
magnetTex:SetPoint("LEFT", magnetBtn, "LEFT", 0, 0)
magnetTex:SetTexture(MAGNET_ICON)
magnetTex:SetAlpha(UM.snapEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
magnetBtn._tex = magnetTex
local magnetLabel = magnetBtn:CreateFontString(nil, "OVERLAY")
magnetLabel:SetFont(FONT_PATH, 10, "OUTLINE, SLUG")
magnetLabel:SetJustifyH("LEFT")
magnetLabel:SetPoint("LEFT", magnetTex, "RIGHT", 5, 0)
magnetLabel:SetTextColor(1, 1, 1, UM.snapEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
magnetLabel:SetText(UM.snapEnabled and EllesmereUI.L("Snap Elements\nEnabled") or EllesmereUI.L("Snap Elements\nDisabled"))
magnetBtn._label = magnetLabel
local magnetLabelW = magnetLabel:GetStringWidth() or 100
magnetBtn:SetSize(iconSz + 5 + magnetLabelW, max(iconSz, 24))
SetupToggleBtn(magnetBtn, magnetTex, magnetLabel,
function() return UM.snapEnabled end,
function()
UM.snapEnabled = not UM.snapEnabled
if EllesmereUIDB then EllesmereUIDB.unlockSnapEnabled = UM.snapEnabled end
magnetTex:SetAlpha(UM.snapEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
magnetLabel:SetTextColor(1, 1, 1, UM.snapEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
magnetLabel:SetText(UM.snapEnabled and EllesmereUI.L("Snap Elements\nEnabled") or EllesmereUI.L("Snap Elements\nDisabled"))
-- Refresh all movers' snap dropdown visual state
for _, m in pairs(movers) do
if m._refreshSnapDD then m._refreshSnapDD() end
end
end)
UM.hudFrame._magnetBtn = magnetBtn
---------------------------------------------------------------
-- Coordinates toggle (right of snap): label RIGHT of icon
---------------------------------------------------------------
local coordBtn = CreateFrame("Button", nil, UM.hudFrame)
coordBtn:SetPoint("LEFT", magnetBtn, "RIGHT", 7, 0)
local coordTex = coordBtn:CreateTexture(nil, "OVERLAY")
coordTex:SetSize(iconSz, iconSz)
coordTex:SetPoint("LEFT", coordBtn, "LEFT", 0, 0)
coordTex:SetTexture(COORD_ICON)
coordTex:SetAlpha(UM.coordsEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
coordBtn._tex = coordTex
local coordLabel = coordBtn:CreateFontString(nil, "OVERLAY")
coordLabel:SetFont(FONT_PATH, 10, "OUTLINE, SLUG")
coordLabel:SetJustifyH("LEFT")
coordLabel:SetPoint("LEFT", coordTex, "RIGHT", 1, 0)
coordLabel:SetTextColor(1, 1, 1, UM.coordsEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
coordLabel:SetText(UM.coordsEnabled and EllesmereUI.L("Coordinates\nEnabled") or EllesmereUI.L("Coordinates\nDisabled"))
coordBtn._label = coordLabel
local coordLabelW = coordLabel:GetStringWidth() or 110
coordBtn:SetSize(iconSz + 5 + coordLabelW, max(iconSz, 24))
SetupToggleBtn(coordBtn, coordTex, coordLabel,
function() return UM.coordsEnabled end,
function()
UM.coordsEnabled = not UM.coordsEnabled
coordTex:SetAlpha(UM.coordsEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
coordLabel:SetTextColor(1, 1, 1, UM.coordsEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
coordLabel:SetText(UM.coordsEnabled and EllesmereUI.L("Coordinates\nEnabled") or EllesmereUI.L("Coordinates\nDisabled"))
-- Show or hide coords for all movers based on new state
for _, m in pairs(movers) do
if m._coordFS then
if UM.coordsEnabled then
if m.UpdateCoordText then m:UpdateCoordText() end
else
-- Only keep visible on the currently selected mover
if not m._selected then
m._coordFS:Hide()
end
end
end
end
end)
UM.hudFrame._coordBtn = coordBtn
---------------------------------------------------------------
-- Hover toggle (right of coords): label RIGHT of icon
---------------------------------------------------------------
local hoverBtn = CreateFrame("Button", nil, UM.hudFrame)
hoverBtn:SetPoint("LEFT", coordBtn, "RIGHT", 2, 0)
local hoverTex = hoverBtn:CreateTexture(nil, "OVERLAY")
hoverTex:SetSize(iconSz, iconSz)
hoverTex:SetPoint("LEFT", hoverBtn, "LEFT", 0, 0)
hoverTex:SetTexture(HOVER_ICON)
hoverTex:SetAlpha(hoverBarEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
hoverBtn._tex = hoverTex
local hoverLabel = hoverBtn:CreateFontString(nil, "OVERLAY")
hoverLabel:SetFont(FONT_PATH, 10, "OUTLINE, SLUG")
hoverLabel:SetJustifyH("LEFT")
hoverLabel:SetPoint("LEFT", hoverTex, "RIGHT", 5, 0)
hoverLabel:SetTextColor(1, 1, 1, hoverBarEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
hoverLabel:SetText(hoverBarEnabled and EllesmereUI.L("Hover Top Bar\nEnabled") or EllesmereUI.L("Hover Top Bar\nDisabled"))
hoverBtn._label = hoverLabel
local hoverLabelW = hoverLabel:GetStringWidth() or 110
hoverBtn:SetSize(iconSz + 5 + hoverLabelW, max(iconSz, 24))
SetupToggleBtn(hoverBtn, hoverTex, hoverLabel,
function() return hoverBarEnabled end,
function()
hoverBarEnabled = not hoverBarEnabled
hoverTex:SetAlpha(hoverBarEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
hoverLabel:SetTextColor(1, 1, 1, hoverBarEnabled and HUD_ON_ALPHA or HUD_OFF_ALPHA)
hoverLabel:SetText(hoverBarEnabled and EllesmereUI.L("Hover Top Bar\nEnabled") or EllesmereUI.L("Hover Top Bar\nDisabled"))
end)
UM.hudFrame._hoverBtn = hoverBtn
---------------------------------------------------------------
-- Exit (left) and Save & Exit (right) buttons
-- Vertically centered in the 58px visible banner area.
-- Positioned ~50px from left/right edges of the banner, but pulled in
-- further when localized toggle labels run wide enough to reach them
-- (German especially runs longer than English and used to overlap them).
---------------------------------------------------------------
local BTN_H = 26
local BTN_FONT = 10
local btnCenterY = iconCenterY -- same vertical center as icons
local CHAIN_GAP = 15 -- minimum clearance from the icon-toggle chain
-- Outer edges of the left (grid/darkOverlay/flash) and right
-- (magnet/coord/hover) toggle chains, center-relative -- re-derives the
-- same offsets used to anchor them above, so keep these in sync with
-- those SetPoint calls if the chain spacing ever changes.
local flashLeftEdge = (-80 + iconSz / 2) - gridBtn:GetWidth() - 20 - darkOverlayBtn:GetWidth() - 20 - flashBtn:GetWidth()
local hoverRightEdge = (76 - iconSz / 2) + magnetBtn:GetWidth() + 7 + coordBtn:GetWidth() + 2 + hoverBtn:GetWidth()
-- Exit button (left side, 85px from left edge by default)
local exitBtn = CreateFrame("Button", nil, UM.hudFrame)
local EXIT_BTN_W = 60
exitBtn:SetSize(EXIT_BTN_W, BTN_H)
local exitLeftEdge = min(-BANNER_PX_W / 2 + 85, flashLeftEdge - CHAIN_GAP - EXIT_BTN_W)
exitBtn:SetPoint("LEFT", UM.hudFrame, "TOPLEFT", exitLeftEdge + BANNER_PX_W / 2, btnCenterY)
EllesmereUI.MakeStyledButton(exitBtn, "Exit", BTN_FONT,
EllesmereUI.RB_COLOURS, function() ns.RequestClose(false) end)
UM.hudFrame._exitBtn = exitBtn
-- Save & Exit button (right side, 50px from right edge, green "Done" style)
do
local btn = CreateFrame("Button", nil, UM.hudFrame)
local SAVE_BTN_W = 90
btn:SetSize(SAVE_BTN_W, BTN_H)
local saveRightEdge = max(BANNER_PX_W / 2 - 85, hoverRightEdge + CHAIN_GAP + SAVE_BTN_W)
btn:SetPoint("RIGHT", UM.hudFrame, "TOPRIGHT", saveRightEdge - BANNER_PX_W / 2, btnCenterY)
btn:SetFrameLevel(UM.hudFrame:GetFrameLevel() + 2)
local eg = EllesmereUI.ELLESMERE_GREEN or { r = 12/255, g = 210/255, b = 157/255 }
EllesmereUI.MakeBorder(btn, eg.r, eg.g, eg.b, 0.7)
local bg = btn:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetColorTexture(0.06, 0.08, 0.10, 0.92)
local lbl = btn:CreateFontString(nil, "OVERLAY")
lbl:SetFont(FONT_PATH, BTN_FONT, "OUTLINE, SLUG")
lbl:SetPoint("CENTER")
lbl:SetText(EllesmereUI.L("Save & Exit"))
lbl:SetTextColor(eg.r, eg.g, eg.b, 0.7)
local FADE_DUR = 0.1
local progress, target = 0, 0
local lerp = EllesmereUI.lerp
local function Apply(t)
local c = EllesmereUI.ELLESMERE_GREEN or eg
lbl:SetTextColor(c.r, c.g, c.b, lerp(0.7, 1, t))
end
local function OnUpdate(self, elapsed)
local dir = (target == 1) and 1 or -1
progress = progress + dir * (elapsed / FADE_DUR)
if (dir == 1 and progress >= 1) or (dir == -1 and progress <= 0) then
progress = target; self:SetScript("OnUpdate", nil)
end
Apply(progress)
end
btn:SetScript("OnEnter", function(self) target = 1; self:SetScript("OnUpdate", OnUpdate) end)
btn:SetScript("OnLeave", function(self) target = 0; self:SetScript("OnUpdate", OnUpdate) end)
btn:SetScript("OnClick", function() ns.RequestClose(true) end)
UM.hudFrame._saveBtn = btn
end
---------------------------------------------------------------
-- Banner Scale +/- Buttons: far left (-) and far right (+) of the banner.
-- Scale range 100%-150% in 10% steps. Saved to EllesmereUIDB.unlockBannerScale.
---------------------------------------------------------------
do
local SCALE_MIN = 1.0
local SCALE_MAX = 1.5
local SCALE_STEP = 0.1
local DISABLED_R, DISABLED_G, DISABLED_B = 0.35, 0.35, 0.35
local NORMAL_R, NORMAL_G, NORMAL_B = 1, 1, 1
local HOVER_R, HOVER_G, HOVER_B = 1, 1, 1
local NORMAL_A = 0.50
local HOVER_A = 0.90
local FONT_SZ = 26
-- Load saved banner scale
local bannerUserScale = 1.0
if EllesmereUIDB and EllesmereUIDB.unlockBannerScale then
bannerUserScale = EllesmereUIDB.unlockBannerScale
if bannerUserScale < SCALE_MIN then bannerUserScale = SCALE_MIN end
if bannerUserScale > SCALE_MAX then bannerUserScale = SCALE_MAX end
end
-- Apply initial scale (uiScale * userScale)
UM.hudFrame:SetScale(uiScale * bannerUserScale)
local minusBtn, plusBtn -- forward refs for cross-refresh
local function RefreshScaleBtns()
local atMin = bannerUserScale <= SCALE_MIN + 0.001
local atMax = bannerUserScale >= SCALE_MAX - 0.001
if atMin then
minusBtn._shadow:SetTextColor(DISABLED_R, DISABLED_G, DISABLED_B, NORMAL_A * 0.6)
minusBtn._label:SetTextColor(DISABLED_R, DISABLED_G, DISABLED_B, NORMAL_A)
minusBtn:EnableMouse(true) -- still catch hover for tooltip
minusBtn._isDisabled = true
else
minusBtn._shadow:SetTextColor(0, 0, 0, NORMAL_A)
minusBtn._label:SetTextColor(NORMAL_R, NORMAL_G, NORMAL_B, NORMAL_A)
minusBtn._isDisabled = false
end
if atMax then
plusBtn._shadow:SetTextColor(DISABLED_R, DISABLED_G, DISABLED_B, NORMAL_A * 0.6)
plusBtn._label:SetTextColor(DISABLED_R, DISABLED_G, DISABLED_B, NORMAL_A)
plusBtn:EnableMouse(true)
plusBtn._isDisabled = true
else
plusBtn._shadow:SetTextColor(0, 0, 0, NORMAL_A)
plusBtn._label:SetTextColor(NORMAL_R, NORMAL_G, NORMAL_B, NORMAL_A)
plusBtn._isDisabled = false
end
end
local function ApplyBannerScale(newScale)
newScale = max(SCALE_MIN, min(SCALE_MAX, newScale))
bannerUserScale = newScale
if EllesmereUIDB then EllesmereUIDB.unlockBannerScale = newScale end
UM.hudFrame:SetScale(uiScale * newScale)
-- Keep flush with top of screen
UM.hudFrame:ClearAllPoints()
UM.hudFrame:SetPoint("TOP", UIParent, "TOP", 0, 0)
-- Resize hover zone to match new scale
if UM.hudFrame._hoverZone then
UM.hudFrame._hoverZone:SetHeight(60 * uiScale * newScale)
end
RefreshScaleBtns()
end
-- Helper: create a text button with drop shadow
local function MakeScaleBtn(text, anchorPoint, anchorTo, anchorRel, xOff, yOff)
local btn = CreateFrame("Button", nil, UM.hudFrame)
btn:SetSize(30, 30)
btn:SetPoint(anchorPoint, anchorTo, anchorRel, xOff, yOff)
btn:SetFrameLevel(UM.hudFrame:GetFrameLevel() + 3)
-- Drop shadow (offset 1px down-right)
local shadow = btn:CreateFontString(nil, "ARTWORK")
shadow:SetFont(FONT_PATH, FONT_SZ, "")
shadow:SetPoint("CENTER", btn, "CENTER", 1, -1)
shadow:SetText(EllesmereUI.L(text))
shadow:SetTextColor(0, 0, 0, NORMAL_A)
btn._shadow = shadow
-- Main text
local label = btn:CreateFontString(nil, "OVERLAY")
label:SetFont(FONT_PATH, FONT_SZ, "")
label:SetPoint("CENTER", btn, "CENTER", 0, 0)
label:SetText(EllesmereUI.L(text))
label:SetTextColor(NORMAL_R, NORMAL_G, NORMAL_B, NORMAL_A)
btn._label = label
btn._isDisabled = false
btn:SetScript("OnEnter", function(self)
if self._isDisabled then return end
self._shadow:SetTextColor(0, 0, 0, HOVER_A)
self._label:SetTextColor(HOVER_R, HOVER_G, HOVER_B, HOVER_A)
end)
btn:SetScript("OnLeave", function(self)
if self._isDisabled then return end
self._shadow:SetTextColor(0, 0, 0, NORMAL_A)
self._label:SetTextColor(NORMAL_R, NORMAL_G, NORMAL_B, NORMAL_A)
end)
return btn
end
-- Minus button (10px left of the Exit button, outer side)
minusBtn = MakeScaleBtn("\226\128\147", "RIGHT", exitBtn, "LEFT", -10, 0)
minusBtn:SetScript("OnClick", function(self)
if self._isDisabled then return end
ApplyBannerScale(bannerUserScale - SCALE_STEP)
end)
-- Plus button (10px right of the Save & Exit button, outer side)
plusBtn = MakeScaleBtn("+", "LEFT", UM.hudFrame._saveBtn, "RIGHT", 10, 0)
plusBtn:SetScript("OnClick", function(self)
if self._isDisabled then return end
ApplyBannerScale(bannerUserScale + SCALE_STEP)
end)
UM.hudFrame._minusBtn = minusBtn
UM.hudFrame._plusBtn = plusBtn
UM.hudFrame._applyBannerScale = ApplyBannerScale
RefreshScaleBtns()
end
---------------------------------------------------------------
-- Hover-bar logic: when hoverBarEnabled, the banner + all children fade out
-- unless the cursor is in a 1144x60 zone at the top of the screen. Fade = 0.5s.
-- Holding Shift fades the bar out in ANY mode so elements beneath it can
-- be seen and clicked; releasing Shift brings it straight back.
---------------------------------------------------------------
local HOVER_ZONE_H = 60
local HOVER_FADE = 0.5
local SHIFT_FADE = 0.15
local hoverAlpha = 1 -- current fade alpha (1 = fully visible)
-- Invisible hover detection zone (parented to UIParent, not hudFrame,
-- so it's always accessible even when hudFrame alpha is 0)
local hoverZone = CreateFrame("Frame", nil, parent)
hoverZone:SetFrameStrata("FULLSCREEN_DIALOG")
hoverZone:SetFrameLevel(parent:GetFrameLevel() + 56)
hoverZone:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, 0)
hoverZone:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0)
hoverZone:SetHeight(HOVER_ZONE_H * (UM.hudFrame:GetScale() or uiScale))
hoverZone:EnableMouse(false) -- doesn't block clicks
hoverZone:Hide()
UM.hudFrame._hoverZone = hoverZone
-- Every mouse-interactive banner child. Mouse is cut while Shift-hidden so
-- the invisible buttons can't eat clicks meant for elements under the bar.
local hudMouseKids = {
UM.hudFrame._gridBtn, UM.hudFrame._darkOverlayBtn, UM.hudFrame._flashBtn,
UM.hudFrame._magnetBtn, UM.hudFrame._coordBtn, UM.hudFrame._hoverBtn,
UM.hudFrame._exitBtn, UM.hudFrame._saveBtn, UM.hudFrame._minusBtn, UM.hudFrame._plusBtn,
}
local shiftMouseCut = false
UM.hudFrame:SetScript("OnUpdate", function(self, dt)
-- Hold Shift: temporarily hide the top bar (works in both modes)
local shiftHeld = IsShiftKeyDown()
if shiftHeld ~= shiftMouseCut then
shiftMouseCut = shiftHeld
for i = 1, #hudMouseKids do
local kid = hudMouseKids[i]
if shiftHeld then
-- EnableMouse(false) does not fire OnLeave on a frame the
-- cursor is already over; reset hover visuals explicitly
-- so no button sticks in its highlighted state.
local leave = kid:GetScript("OnLeave")
if leave then leave(kid) end
end
kid:EnableMouse(not shiftHeld)
end
end
if shiftHeld then
-- Push-through, no change guard: unlock entry force-sets frame
-- alpha to 1 while hoverAlpha can still be 0 from a close that
-- happened with Shift held; a guarded write would strand the
-- banner visible with its buttons mouse-dead.
hoverAlpha = max(0, hoverAlpha - dt / SHIFT_FADE)
self:SetAlpha(hoverAlpha)
if not hoverBarEnabled then hoverZone:Hide() end
return
end
if not hoverBarEnabled then
-- Not in hover mode -- ensure full alpha
if hoverAlpha < 1 then
hoverAlpha = 1
self:SetAlpha(1)
end
hoverZone:Hide()
return
end
hoverZone:Show()
-- Check if cursor is within the hover zone (top of screen)
local scale = UIParent:GetEffectiveScale()
local _, cy = GetCursorPosition()
cy = cy / scale
local screenH = UIParent:GetHeight()
local zoneBot = screenH - (HOVER_ZONE_H * (UM.hudFrame:GetScale() or uiScale))
local inZone = (cy >= zoneBot)
if inZone then
hoverAlpha = min(1, hoverAlpha + dt / HOVER_FADE)
else
hoverAlpha = max(0, hoverAlpha - dt / HOVER_FADE)
end
self:SetAlpha(hoverAlpha)
end)
UM.hudFrame:Hide()
return UM.hudFrame
end
-------------------------------------------------------------------------------
-- Save / Revert / Close helpers
-------------------------------------------------------------------------------
-- Snapshot current bar positions when entering unlock mode
local function SnapshotPositions()
wipe(snapshotPositions)
-- Action bars: capture from barPositions DB
local db = UM.GetPositionDB()
if db then
for barKey, pos in pairs(db) do
snapshotPositions[barKey] = { point = pos.point, relPoint = pos.relPoint, x = pos.x, y = pos.y }
end
end
-- Action bars: for any bar that has NO saved position, capture its live position
for _, barKey in ipairs(ALL_BAR_ORDER) do
if not snapshotPositions[barKey] then
local bar = UM.GetBarFrame(barKey)
if bar then
local nPts = bar:GetNumPoints()
if nPts and nPts > 0 then
local point, _, relPoint, x, y = bar:GetPoint(1)
if point then
snapshotPositions[barKey] = { point = point, relPoint = relPoint, x = x, y = y }
end
end
end
end
end
-- Registered elements: snapshot via loadPosition or live frame position
RebuildRegisteredOrder()
for _, key in ipairs(registeredOrder) do
if not snapshotPositions[key] then
local elem = registeredElements[key]
if elem then
local pos = elem.loadPosition and elem.loadPosition(key)
if pos then
snapshotPositions[key] = { point = pos.point, relPoint = pos.relPoint or pos.point, x = pos.x, y = pos.y }
else
local fr = elem.getFrame and elem.getFrame(key)
if fr then
local nPts = fr:GetNumPoints()
if nPts and nPts > 0 then
local point, _, relPoint, x, y = fr:GetPoint(1)
if point then
-- relPoint may be a frame object here (not a string) if anchored to
-- a parent frame rather than UIParent; mark this snapshot so RevertPositions skips writing it to SavedVariables.
snapshotPositions[key] = { point = point, relPoint = relPoint, x = x, y = y, _fromLiveFrame = true }
end
end
end
end
end
end
end
-- Snapshot anchor data so we can revert on discard (includes the
-- growth-edge pin fields; losing them on cancel would force a lazy
-- recapture from whatever position the session left the bar at)
wipe(snapshotAnchors)
local anchorDB = GetAnchorDB()
if anchorDB then
for childKey, info in pairs(anchorDB) do
snapshotAnchors[childKey] = {
target = info.target, side = info.side,
offsetX = info.offsetX, offsetY = info.offsetY,
refX = info.refX, refY = info.refY,
edgeOffX = info.edgeOffX, edgeOffY = info.edgeOffY,
refFor = info.refFor,
-- COPY, not a reference: _NudgeSelectedFallbackGhost mutates
-- fb.offsetX/offsetY in place, so a shared table would drag the
-- snapshot along with the edit and make the revert a no-op. The
-- cross-axis edge is nudged in place too, so it copies as well.
fallback = info.fallback and CopyTable(info.fallback) or nil,
edge = info.edge and CopyTable(info.edge) or nil,
}
end
end
-- Snapshot element sizes so we can revert width/height changes on discard
wipe(snapshotSizes)
for _, key in ipairs(registeredOrder) do
local elem = registeredElements[key]
if elem and elem.getSize then
local w, h = elem.getSize(key)
if w and h then
snapshotSizes[key] = { w = w, h = h }
end
end
end
-- Snapshot width/height match DBs so we can revert on discard
wipe(snapshotWidthMatch)
wipe(snapshotHeightMatch)
local wmDB = MatchH.GetWidthMatchDB()
if wmDB then
for k, v in pairs(wmDB) do snapshotWidthMatch[k] = v end
end
local hmDB = MatchH.GetHeightMatchDB()
if hmDB then
for k, v in pairs(hmDB) do snapshotHeightMatch[k] = v end
end
-- ...and each match's Extra Width / Height, reverted with its link.
local sx = MatchH.snapExtra
wipe(sx.w)
wipe(sx.h)
local wxDB = EllesmereUIDB and EllesmereUIDB.unlockWidthMatchExtra
if wxDB then
for k, v in pairs(wxDB) do sx.w[k] = v end
end
local hxDB = EllesmereUIDB and EllesmereUIDB.unlockHeightMatchExtra
if hxDB then
for k, v in pairs(hxDB) do sx.h[k] = v end
end
-- Snapshot growth directions so we can revert on discard
wipe(snapshotGrowDirs)
local cdm = EllesmereUI.Lite.GetAddon("EllesmereUICooldownManager", true)
local cdmBars = cdm and cdm.db and cdm.db.profile and cdm.db.profile.cdmBars
if cdmBars and cdmBars.bars then
for _, bar in ipairs(cdmBars.bars) do
-- bar.key guard: ghost bars (keyless skeletons from stale
-- override writes) have nothing to snapshot.
if bar.key then
snapshotGrowDirs["CDM_" .. bar.key] = bar.growDirection or false
end
end
end
local eab = EllesmereUI.Lite.GetAddon("EllesmereUIActionBars", true)
local abBars = eab and eab.db and eab.db.profile and eab.db.profile.bars
if abBars then
local abGrowKeys = { MainBar=1, Bar2=1, Bar3=1, Bar4=1, Bar5=1, Bar6=1, Bar7=1, Bar8=1 }
for bk, cfg in pairs(abBars) do
if abGrowKeys[bk] then
snapshotGrowDirs[bk] = cfg.growDirection or false
end
end
end
-- Raw pre-session position entries for CDM/AB bars: verbatim saved edges
-- including the tgt* follow baselines. The snapshotPositions entries above are
-- center-converted and LOSSY for edge-preserving grow bars (a restored
-- CENTER-format saved edge can't pin, so the bar stays wherever it currently
-- sits). Spec-override baseline capture prefers these raw copies. Namespace
-- table: this body is inside the deferred-init closure, at the 200-local cap.
local rawSnap = {}
EllesmereUI._unlockSnapRawPos = rawSnap
local cdmPos = cdm and cdm.db and cdm.db.profile and cdm.db.profile.cdmBarPositions
if cdmPos and cdmBars and cdmBars.bars then
for _, bar in ipairs(cdmBars.bars) do
local e = cdmPos[bar.key]
if e then rawSnap["CDM_" .. bar.key] = CopyTable(e) end
end
end
local abPos = UM.GetPositionDB()
if abPos and EllesmereUI._abBarKeys then
for bk in pairs(EllesmereUI._abBarKeys) do
local e = abPos[bk]
if e then rawSnap[bk] = CopyTable(e) end
end
end
end
-------------------------------------------------------------------------------
-- Unlock spec-overrides: session visuals + Save & Exit routing. Gold border =
-- this element carries an unlock override for the active edit context (the
-- special group's entry, or the current spec's owning group in a normal
-- session). Red lock = element can't be edited in the special session (owned by a spec-sharing group, or a blocked subsystem).
-------------------------------------------------------------------------------
do
local specOvBanner
local function UpdateSpecOvBanner()
local g = EllesmereUI._specialUnlockGroup
if not g or not UM.unlockFrame then
if specOvBanner then specOvBanner:Hide() end
return
end
if not specOvBanner then
specOvBanner = CreateFrame("Frame", nil, UM.unlockFrame)
specOvBanner:SetFrameLevel(UM.unlockFrame:GetFrameLevel() + 60)
specOvBanner:SetHeight(28)
specOvBanner:SetPoint("TOP", UM.unlockFrame, "TOP", 0, -64)
local bg = specOvBanner:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetColorTexture(0.16, 0.12, 0.04, 0.92)
EllesmereUI.MakeBorder(specOvBanner, 199/255, 166/255, 90/255, 0.7)
local fs = specOvBanner:CreateFontString(nil, "OVERLAY")
fs:SetFont(FONT_PATH, 12, "OUTLINE, SLUG")
fs:SetPoint("CENTER")
fs:SetTextColor(1, 0.88, 0.55, 1)
specOvBanner._text = fs
end
specOvBanner._text:SetText(string.format(
EllesmereUI.L("Customizing Unlock Mode: %s (changes apply only to this group's specs)"),
g.name or "?"))
specOvBanner:SetWidth((specOvBanner._text:GetStringWidth() or 200) + 28)
specOvBanner:Show()
end
-- Layer model: a custom unlock mode is a whole-layout fork, so there are no
-- per-element gold marks or conflict locks anymore -- the gold frame variant
-- and this banner carry the state; this refresh keeps the banner current and hides stale per-element markers on pooled movers.
EllesmereUI._unlockRefreshSpecOvMarks = function()
UpdateSpecOvBanner()
for _, m in pairs(movers) do
if m._specOvBrd then m._specOvBrd:Hide() end
if m._specOvLock then m._specOvLock:Hide() end
end
end
end
-- Commit pending positions to SavedVariables
local function CommitPositions()
-- Suppress per-save rebuilds (e.g. CDM's BuildAllCDMBars) so that
-- all positions are written first, then a single rebuild runs at the end.
EllesmereUI._propagatingSave = true
for barKey, pos in pairs(pendingPositions) do
if pos == "RESET" then
ClearBarPosition(barKey)
else
local elem = registeredElements[barKey]
local pt, rpt, px, py = pos.point, pos.relPoint, pos.x, pos.y
-- Anchor-cascade marker: ApplyAnchorPosition repositioned this bar during
-- the session (e.g. its anchor target was dragged) but the entry carries no
-- coords. The open-time snapshot below is STALE for it: saving that would
-- pair a pre-move growth edge with the post-move target baselines savePos
-- captures, and the bar snaps to the stale edge on save. Resolve from the
-- bar's LIVE bounds instead -- ConvertToCenterPos prefers them and returns
-- the exact CENTER/CENTER convention SaveBarPosition expects. Bars a cascade
-- reapplied without actually moving resolve to the same snapshot position.
if elem and not pt and pos._anchored then
local liveBar = UM.GetBarFrame(barKey)
if liveBar and liveBar:GetLeft() and liveBar:GetRight()
and liveBar:GetTop() and liveBar:GetBottom() then
pt, rpt, px, py = ConvertToCenterPos(barKey, "TOPLEFT", "TOPLEFT", 0, 0)
end
end
-- If position wasn't dragged, fill from snapshot
if elem and not pt then
local snap = snapshotPositions[barKey]
if snap then
pt, rpt, px, py = snap.point, snap.relPoint or snap.point, snap.x, snap.y
else
-- Fallback: read from loadPosition
local lp = elem.loadPosition and elem.loadPosition(barKey)
if lp then
pt, rpt, px, py = lp.point, lp.relPoint or lp.point, lp.x, lp.y
end
end
end
UM.SaveBarPosition(barKey, pt, rpt, px, py)
-- Install anchor guard for action bar positions
if not elem then
local bar = UM.GetBarFrame(barKey)
if bar then InstallAnchorGuard(bar, barKey) end
end
end
end
EllesmereUI._propagatingSave = false
-- Force edge-preservation across the save rebuild + reapply below. These run
-- while isUnlocked is still true (DoClose clears it only AFTER CommitPositions
-- returns), so without this flag ApplyAnchorPosition skips its absolute
-- saved-edge branch and places anchored custom-growth CDM bars from the anchor
-- offset + live width instead -- if the rebuild changed a bar's width, the
-- growth edge lands off the freshly-saved edge and the bar visibly snaps back
-- until /reload. Setting the flag makes both passes read cdmBarPositions
-- exactly like the login/reload apply. Mirrors OpenUnlockMode's entry reapply; pcall-wrapped and reset in all cases so it can never leak.
EllesmereUI._reapplyForceEdgePreserve = true
-- Single rebuild now that all positions are committed.
-- CDM savePos normally calls BuildAllCDMBars per save, but we
-- suppressed that above to avoid partial-state rebuilds.
for barKey in pairs(pendingPositions) do
if type(barKey) == "string" and barKey:sub(1, 4) == "CDM_" then
local elem = registeredElements[barKey]
if elem and elem.applyPosition then
pcall(elem.applyPosition, barKey)
end
break -- one rebuild is enough, it rebuilds all bars
end
end
-- Reapply anchor positions for all anchored bars so they move from the stale CENTER
-- coords (saved by CommitPositions) to their correct anchor-relative position
-- immediately. Without this, anchored bars sit at stale coords until a deferred
-- ScheduleAnchorBatch corrects them, causing a visible jump on the next resize.
if EllesmereUI.ReapplyAllUnlockAnchorsForced then
pcall(EllesmereUI.ReapplyAllUnlockAnchorsForced)
end
EllesmereUI._reapplyForceEdgePreserve = false
-- Persist unlock layout into the active profile so it survives reloads
-- without requiring a manual profile switch.
if EllesmereUIDB and EllesmereUI.GetProfilesDB then
local pdb = EllesmereUI.GetProfilesDB()
local activeName = pdb.activeProfile or "Default"
local profileData = pdb.profiles and pdb.profiles[activeName]
if profileData then
local snap = {
anchors = CopyTable(EllesmereUIDB.unlockAnchors or {}),
widthMatch = CopyTable(EllesmereUIDB.unlockWidthMatch or {}),
heightMatch = CopyTable(EllesmereUIDB.unlockHeightMatch or {}),
widthMatchExtra = CopyTable(EllesmereUIDB.unlockWidthMatchExtra or {}),
heightMatchExtra = CopyTable(EllesmereUIDB.unlockHeightMatchExtra or {}),
phantomBounds = CopyTable(EllesmereUIDB.phantomBounds or {}),
}
-- While a spec-override unlock LAYER is live, the profile
-- snapshot must carry the shared BASELINE links, not the live
-- (group-valued) globals; the stored baseline layout provides
-- them. When the baseline itself is live, live is the source.
if EllesmereUI.SpecOverrides_UnlockBaselineLinks then
local ba, bw, bh = EllesmereUI.SpecOverrides_UnlockBaselineLinks()
if ba then
snap.anchors = CopyTable(ba)
snap.widthMatch = CopyTable(bw)
snap.heightMatch = CopyTable(bh)
-- The baseline's match extras ride with its links (4th and
-- 5th returns); a baseline without extras carries none.
local _, _, _, bwx, bhx = EllesmereUI.SpecOverrides_UnlockBaselineLinks()
snap.widthMatchExtra = CopyTable(bwx or {})
snap.heightMatchExtra = CopyTable(bhx or {})
end
end
profileData.unlockLayout = snap
end
end
-- The active spec's tracked buff bar links and extras into their spec bucket,
-- so a profile restore before the next bar build cannot swap older ones in.
if EllesmereUI._TBBBankUnlockLinks then EllesmereUI._TBBBankUnlockLinks() end
-- Bank CAPTURED settings the session edited (cog size inputs) into
-- values.default -- a normal unlock session edits the shared baseline, exactly
-- like the panel's Default Editing Mode. Without this the next value apply
-- reverts the user's unlock-mode resize (the sticky harvest deliberately never adopts foreign live diffs).
if EllesmereUI.SpecOverrides_UnlockValueSnapCommit then
pcall(EllesmereUI.SpecOverrides_UnlockValueSnapCommit)
end
-- Bank the freshly-saved live layout into its owning spec-override layer (the
-- active group layer, else the stored baseline). Wholesale harvest -- no
-- per-aspect routing exists. true = user commit: banks even inside the post-import suppression window (and closes it).
if EllesmereUI.SpecOverrides_HarvestUnlockLayout then
local okH, errH = pcall(EllesmereUI.SpecOverrides_HarvestUnlockLayout, true)
if not okH then
print("|cffff6060[EllesmereUI]|r Unlock layer harvest failed: "
.. tostring(errH))
end
end
end
-- Revert bars to their snapshot positions (discard all pending changes)
local function RevertPositions()