forked from EllesmereGaming/EllesmereUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEUI_UnlockMode.lua
More file actions
8700 lines (8045 loc) · 366 KB
/
EUI_UnlockMode.lua
File metadata and controls
8700 lines (8045 loc) · 366 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
-------------------------------------------------------------------------------
-- EUI_UnlockMode.lua
-- Full-featured Unlock Mode for EllesmereUI
-- Animated transition, grid overlay, draggable bar movers, snap guides,
-- position memory, and a polished return-to-options flow.
-- Supports elements from any addon via EllesmereUI:RegisterUnlockElements().
-------------------------------------------------------------------------------
local ADDON_NAME, ns = ...
local EAB = ns.EAB -- may be nil if loaded by a non-ActionBars addon
-------------------------------------------------------------------------------
-- Registration API – lives on the EllesmereUI global so ALL addons share
-- the same table regardless of which copy of this file runs.
-------------------------------------------------------------------------------
if not EllesmereUI._unlockRegisteredElements then
EllesmereUI._unlockRegisteredElements = {}
EllesmereUI._unlockRegisteredOrder = {}
EllesmereUI._unlockRegistrationDirty = true
end
if not EllesmereUI.RegisterUnlockElements then
-- Normalize short field names (savePos, loadPos, etc.) to the long
-- names used throughout unlock mode (savePosition, loadPosition, etc.)
local FIELD_ALIASES = {
savePos = "savePosition",
loadPos = "loadPosition",
clearPos = "clearPosition",
applyPos = "applyPosition",
}
function EllesmereUI:RegisterUnlockElements(elements)
for _, elem in ipairs(elements) do
for short, long in pairs(FIELD_ALIASES) do
if elem[short] and not elem[long] then
elem[long] = elem[short]
end
end
self._unlockRegisteredElements[elem.key] = elem
end
self._unlockRegistrationDirty = true
end
end
if not EllesmereUI.UnregisterUnlockElement then
function EllesmereUI:UnregisterUnlockElement(key)
self._unlockRegisteredElements[key] = nil
self._unlockRegistrationDirty = true
end
end
-- If this file was already fully loaded by another addon, bail out.
-- The registration API above is safe to re-run (idempotent), but the
-- rest of the file (state, frames, animations) must only exist once.
if EllesmereUI._unlockModeLoaded then return end
EllesmereUI._unlockModeLoaded = true
-------------------------------------------------------------------------------
-- Lightweight anchor reapply stub (pre-EnsureLoaded)
-- Allows child addons (CDM, etc.) to reposition anchored elements on login
-- before the full unlock mode body has been loaded. The deferred block
-- replaces this with the full implementation.
-------------------------------------------------------------------------------
if not EllesmereUI.ReapplyOwnAnchor then
EllesmereUI.ReapplyOwnAnchor = function(key)
if not EllesmereUIDB or not EllesmereUIDB.unlockAnchors then return end
local info = EllesmereUIDB.unlockAnchors[key]
if not info or not info.target then return end
-- Resolve child and target frames via registered elements
local elems = EllesmereUI._unlockRegisteredElements
local childElem = elems and elems[key]
local targetElem = elems and elems[info.target]
local childBar = childElem and childElem.getFrame and childElem.getFrame(key)
local targetBar = targetElem and targetElem.getFrame and targetElem.getFrame(info.target)
if not childBar or not targetBar then return end
if not targetBar:GetLeft() then return end
local side = info.side
local uiS = UIParent:GetEffectiveScale()
local tS = targetBar:GetEffectiveScale()
local cS = childBar:GetEffectiveScale()
local tL = (targetBar:GetLeft() or 0) * tS / uiS
local tR = (targetBar:GetRight() or 0) * tS / uiS
local tT = (targetBar:GetTop() or 0) * tS / uiS
local tB = (targetBar:GetBottom() or 0) * tS / uiS
local tCX = (tL + tR) / 2
local tCY = (tT + tB) / 2
local cW = (childBar:GetWidth() or 50) * cS / uiS
local cH = (childBar:GetHeight() or 50) * cS / uiS
local cx, cy
if info.offsetX and info.offsetY then
if side == "LEFT" then
cx = tL + info.offsetX - cW / 2
cy = tCY + info.offsetY
elseif side == "RIGHT" then
cx = tR + info.offsetX + cW / 2
cy = tCY + info.offsetY
elseif side == "TOP" then
cx = tCX + info.offsetX
cy = tT + info.offsetY + cH / 2
elseif side == "BOTTOM" then
cx = tCX + info.offsetX
cy = tB + info.offsetY - cH / 2
else
cx = tCX + info.offsetX
cy = tCY + info.offsetY
end
else
if side == "LEFT" then
cx = tL - cW / 2; cy = tCY
elseif side == "RIGHT" then
cx = tR + cW / 2; cy = tCY
elseif side == "TOP" then
cx = tCX; cy = tT + cH / 2
elseif side == "BOTTOM" then
cx = tCX; cy = tB - cH / 2
else
cx = tCX; cy = tCY
end
end
local uiW, uiH = UIParent:GetSize()
local centerX = cx - uiW / 2
local centerY = cy - uiH / 2
-- Snap CENTER offset to a grid that keeps the child's edges on
-- whole pixels. SnapCenterForDim picks the integer or integer+0.5
-- grid based on the child's pixel-dimension parity. Plain SnapForES
-- would round 540.5 to 541 and force half-pixel edges (1px drift).
local PPa = EllesmereUI.PP
if PPa then
if PPa.SnapCenterForDim then
centerX = PPa.SnapCenterForDim(centerX, cW, cS)
centerY = PPa.SnapCenterForDim(centerY, cH, cS)
elseif PPa.SnapForES then
centerX = PPa.SnapForES(centerX, cS)
centerY = PPa.SnapForES(centerY, cS)
end
end
pcall(function()
childBar:ClearAllPoints()
childBar:SetPoint("CENTER", UIParent, "CENTER", centerX, centerY)
end)
end
end
-------------------------------------------------------------------------------
-- Early stub: NotifyElementResized
-- Handles grow-direction-aware repositioning before unlock mode fully loads.
-- The deferred block overwrites this with the full implementation.
-------------------------------------------------------------------------------
if not EllesmereUI.NotifyElementResized then
EllesmereUI.NotifyElementResized = function(key)
if not EllesmereUIDB then return end
-- Skip if anchored (early ReapplyOwnAnchor handles those)
local anchors = EllesmereUIDB.unlockAnchors
if anchors and anchors[key] and anchors[key].target then return end
-- Read grow direction from the bar's per-profile settings
local growDir
if key == "EQT_Tracker" then growDir = "DOWN"
elseif key:sub(1, 4) == "CDM_" then
local rawKey = key:sub(5)
local cdm = EllesmereUI.Lite and EllesmereUI.Lite.GetAddon and 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
if bar.key == rawKey then
local g = bar.growDirection
if g then growDir = g end
break
end
end
end
else
local eab = EllesmereUI.Lite and EllesmereUI.Lite.GetAddon and EllesmereUI.Lite.GetAddon("EllesmereUIActionBars", true)
local s = eab and eab.db and eab.db.profile and eab.db.profile.bars and eab.db.profile.bars[key]
if s then
local g = (s.growDirection or "up"):upper()
if g ~= "UP" then growDir = g end
end
end
if not growDir or growDir == "CENTER" then return end
-- Find the frame via registered elements
local elems = EllesmereUI._unlockRegisteredElements
local elem = elems and elems[key]
local frame = elem and elem.getFrame and elem.getFrame(key)
if not frame or not frame:GetCenter() then return end
-- Load saved position
local pos
if elem and elem.loadPosition then
pos = elem.loadPosition(key)
else
local eab = EllesmereUI.Lite and EllesmereUI.Lite.GetAddon and EllesmereUI.Lite.GetAddon("EllesmereUIActionBars", true)
local db = eab and eab.db and eab.db.profile and eab.db.profile.barPositions
pos = db and db[key]
end
if not pos or pos.point ~= "CENTER" or pos.relPoint ~= "CENTER" then return end
local cx, cy = pos.x or 0, pos.y or 0
local fw = frame:GetWidth() or 0
local fh = frame:GetHeight() or 0
-- Use raw fw/2 and fh/2 (not floor) so odd-pixel-height/width frames
-- with integer + 0.5 center coords reverse exactly to integer pixel
-- edges. floor() loses the .5 and causes a 1px drift on save & exit.
local anchor, adjX, adjY
if growDir == "RIGHT" then
anchor = "LEFT"; adjX = cx - fw / 2; adjY = cy
elseif growDir == "LEFT" then
anchor = "RIGHT"; adjX = cx + fw / 2; adjY = cy
elseif growDir == "DOWN" then
anchor = "TOP"; adjX = cx; adjY = cy + fh / 2
elseif growDir == "UP" then
anchor = "BOTTOM"; adjX = cx; adjY = cy - fh / 2
else
return
end
-- Snap to physical pixel grid. Edge anchor case (LEFT/RIGHT/TOP/BOTTOM
-- with raw fw/2 or fh/2): adjX/Y represents an EDGE offset that lands
-- on a whole pixel, so SnapForES (round-to-nearest) is correct.
local PPa = EllesmereUI.PP
if PPa and PPa.SnapForES then
local es = frame:GetEffectiveScale()
adjX = PPa.SnapForES(adjX, es)
adjY = PPa.SnapForES(adjY, es)
end
pcall(function()
frame:ClearAllPoints()
frame:SetPoint(anchor, UIParent, "CENTER", adjX, adjY)
end)
end
end
-- Early stub: IsUnlockAnchored
-- Returns true if the given unlock key has an anchor target in the DB.
-- The deferred block overwrites this with the full implementation.
if not EllesmereUI.IsUnlockAnchored then
EllesmereUI.IsUnlockAnchored = function(unlockKey)
if not EllesmereUIDB or not EllesmereUIDB.unlockAnchors then return false end
local ai = EllesmereUIDB.unlockAnchors[unlockKey]
return ai and ai.target and true or false
end
end
-- Early anchor reapply on login: the full ApplySavedPositions lives in the
-- deferred block and only runs when EnsureLoaded() fires (options open, CDM
-- init, etc.). Without this, anchored action bars never resolve their chain
-- if the user doesn't open options and CDM is disabled.
do
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self)
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
C_Timer.After(1.5, function()
-- If the deferred block already ran, it handles everything
if EllesmereUI._applySavedPositions then return end
-- Otherwise, use the lightweight stub to reapply all anchors
local adb = EllesmereUIDB and EllesmereUIDB.unlockAnchors
if not adb then return end
for childKey, info in pairs(adb) do
if info.target and EllesmereUI.ReapplyOwnAnchor then
EllesmereUI.ReapplyOwnAnchor(childKey)
end
end
end)
end)
end
-- DEFERRED: heavy body (4900+ lines) runs on first EnsureLoaded() call.
EllesmereUI._deferredInits[#EllesmereUI._deferredInits + 1] = function()
local floor = math.floor
local abs = math.abs
local min = math.min
local max = math.max
local sqrt = math.sqrt
local sin = math.sin
-- IEEE 754 branchless round-to-nearest-even (avoids -0 from half-pixel centers)
local function round(num)
return num + (2^52 + 2^51) - (2^52 + 2^51)
end
-- Pixel-perfect snap: round a value to the nearest physical pixel boundary.
local PP = EllesmereUI and EllesmereUI.PP
local function pxSnap(x)
if not PP then return round(x) end
local m = PP.mult or 1
if m == 1 then return round(x) end
return round(x / m) * m
end
-- WaitForSize(frame, callback)
-- Defers callback to the next frame so the layout engine has flushed.
local function WaitForSize(frame, callback)
C_Timer.After(0, callback)
end
-- DeferMoverSync(moverFrame, syncFn, barFrame)
-- Syncs the mover immediately (no blink), then again next frame
-- to catch any position changes from the layout engine flush.
-- Hides the actual bar frame during the transition to prevent visual jump.
local function DeferMoverSync(m, syncFn, barFrame)
if not m then return end
if barFrame then barFrame:SetAlpha(0) end
syncFn(m)
C_Timer.After(0, function()
if m then syncFn(m) end
if barFrame then barFrame:SetAlpha(1) end
end)
end
-- RepositionBarToMover(barKey)
-- During unlock mode, after a setWidth/setHeight triggers an addon rebuild
-- that snaps the bar frame back to its stored position, this function
-- re-positions the bar frame to match the mover's current screen position.
-- Without this, resizing in unlock mode causes the bar to jump.
-- Stored on EllesmereUI to avoid adding an upvalue to CreateMover (Lua 5.1 limit: 60).
function EllesmereUI.RepositionBarToMover(barKey)
if not isUnlocked then return end
local m = movers[barKey]
if not m then return end
local bar = GetBarFrame(barKey)
if not bar then return end
local mL, mT = m:GetLeft(), m:GetTop()
if not mL or not mT then return end
-- GetLeft/GetTop return in UIParent coordinate space.
-- SetPoint TOPLEFT relative to UIParent TOPLEFT uses the same space.
-- Y offset from UIParent TOPLEFT is negative (top of screen = 0).
pcall(function()
bar:ClearAllPoints()
bar:SetPoint("TOPLEFT", UIParent, "TOPLEFT", mL, mT - UIParent:GetHeight())
end)
end
-- RecenterBarAnchor is defined after its dependencies (isUnlocked, movers,
-- registeredElements, GetBarFrame, GetBarGrowDirActual) are declared below.
-------------------------------------------------------------------------------
-- Constants
-------------------------------------------------------------------------------
local FONT_PATH = (EllesmereUI and EllesmereUI.GetFontPath and EllesmereUI.GetFontPath("extras"))
or "Interface\\AddOns\\EllesmereUI\\media\\fonts\\Expressway.TTF"
local LOCK_INNER = "Interface\\AddOns\\EllesmereUI\\media\\eui-unlocked-inner-2.png"
local LOCK_OUTER = "Interface\\AddOns\\EllesmereUI\\media\\eui-unlocked-outer-2.png"
local LOCK_TOP = "Interface\\AddOns\\EllesmereUI\\media\\eui-unlocked-top-2.png"
local GRID_SPACING = 32 -- pixels between grid lines
local SNAP_THRESH = 6 -- px distance to trigger snap-to-element
local MOVER_ALPHA = 0.55 -- resting alpha for mover overlays
local MOVER_HOVER = 0.85 -- hover alpha
local MOVER_DRAG = 0.95 -- dragging alpha
local TRANSITION_DUR = 0.35 -- seconds for the open/close fade-in
local GEAR_ROTATION = math.pi / 4 -- 45° rotation for gear effect
-- Bar keys that can be moved (action bars + stance + micro + bag)
-- These are populated by EAB if it's loaded; otherwise empty.
local BAR_LOOKUP = ns.BAR_LOOKUP or {}
local ALL_BAR_ORDER = ns.BAR_DROPDOWN_ORDER or {}
local VISIBILITY_ONLY = ns.VISIBILITY_ONLY or {}
local function GetVisibilityOnly()
-- Read lazily so child addons have time to populate ns.VISIBILITY_ONLY
return ns.VISIBILITY_ONLY or VISIBILITY_ONLY
end
-- Local aliases for the shared registration tables
local registeredElements = EllesmereUI._unlockRegisteredElements
local registeredOrder = EllesmereUI._unlockRegisteredOrder
local function RebuildRegisteredOrder()
if not EllesmereUI._unlockRegistrationDirty then return end
wipe(registeredOrder)
for key, _ in pairs(registeredElements) do
registeredOrder[#registeredOrder + 1] = key
end
-- Sort by order field (lower first), then alphabetically
table.sort(registeredOrder, function(a, b)
local oa = registeredElements[a].order or 1000
local ob = registeredElements[b].order or 1000
if oa ~= ob then return oa < ob end
return a < b
end)
EllesmereUI._unlockRegistrationDirty = false
end
-------------------------------------------------------------------------------
-- State
-------------------------------------------------------------------------------
local unlockFrame -- the full-screen overlay
local gridFrame -- grid line container
local guidePool = {} -- reusable alignment guide lines
local movers = {} -- { [barKey] = moverFrame }
local isUnlocked = false
function EllesmereUI.IsUnlockModeActive() return isUnlocked end
local gridMode = "dimmed" -- "disabled", "dimmed", "bright"
local snapEnabled = true -- magnet/snap state (runtime) — must be before SnapPosition
local lockAnimFrame -- lock assembly animation (close)
local openAnimFrame -- lock animation frame (open)
local logoFadeFrame -- the 2s logo+title fade-out timer frame
local pendingPositions = {} -- { [barKey] = {point,relPoint,x,y} } -- unsaved changes
local snapshotPositions = {} -- original positions captured when unlock mode opens
local snapshotAnchors = {} -- original anchor data captured when unlock mode opens
local snapshotSizes = {} -- original sizes captured when unlock mode opens
local snapshotWidthMatch = {} -- original width match DB captured when unlock mode opens
local snapshotHeightMatch = {} -- original height match DB captured when unlock mode opens
local hasChanges = false -- true if user dragged anything this session
local snapHighlightKey = nil -- barKey of mover currently showing snap highlight border
local snapHighlightAnim = nil -- OnUpdate frame for the pulsing border
local combatSuspended = false -- true if unlock mode was auto-closed by combat
local objTrackerWasVisible = false -- track objective tracker state for restore
-- Grid mode helpers
local GRID_ALPHA_DIMMED = 0.15
local GRID_ALPHA_BRIGHT = 0.30
local GRID_CENTER_DIMMED = 0.25
local GRID_CENTER_BRIGHT = 0.50
local GRID_HUD_BRIGHT = 0.60 -- matches HUD_ON_ALPHA
local GRID_HUD_DIMMED = 0.45
local GRID_HUD_OFF = 0.30 -- matches HUD_OFF_ALPHA
local function GridBaseAlpha()
return gridMode == "bright" and GRID_ALPHA_BRIGHT or GRID_ALPHA_DIMMED
end
local function GridCenterAlpha()
return gridMode == "bright" and GRID_CENTER_BRIGHT or GRID_CENTER_DIMMED
end
local function GridHudAlpha()
if gridMode == "bright" then return GRID_HUD_BRIGHT end
if gridMode == "dimmed" then return GRID_HUD_DIMMED end
return GRID_HUD_OFF
end
local function GridLabelText()
if gridMode == "bright" then return "Grid Lines\nBright" end
if gridMode == "dimmed" then return "Grid Lines\nDimmed" end
return "Grid Lines\nDisabled"
end
local function CycleGridMode()
if gridMode == "dimmed" then gridMode = "bright"
elseif gridMode == "bright" then gridMode = "disabled"
else gridMode = "dimmed" end
end
local flashlightEnabled = false -- cursor flashlight toggle
local hoverBarEnabled = false -- show-bar-on-hover toggle
local darkOverlaysEnabled = true -- dark overlay backgrounds on movers
local coordsEnabled = false -- show coordinates for all elements at all times
local unlockTipFrame -- one-time "how to use" tip frame
local pendingAfterClose -- callback to run after DoClose completes
local selectedMover -- currently selected mover frame (for arrow key nudging)
local arrowKeyFrame -- invisible frame that captures arrow key input
local selectElementPicker -- mover currently in "Select Element" pick mode (nil = off)
local _overlayFadeFrame -- tiny OnUpdate driver for select-element dimmer fade
local SELECT_ELEMENT_ALPHA = 0.50 -- overlay alpha during select-element pick mode
local SELECT_ELEMENT_FADE = 0.50 -- seconds for the fade transition
-- Maps barKey → settings location for "Element Options" navigation.
-- module = folder name used by RegisterModule
-- page = page tab name (PAGE_* constant value)
-- sectionName = exact string passed to SectionHeader()
-- preSelectFn = optional function to set the dropdown before page build
-- Stored on EllesmereUI to avoid adding an upvalue to CreateMover (Lua 5.1 limit: 60).
local function SelectActionBar(key)
return function()
local EAB = EllesmereUI.Lite.GetAddon("EllesmereUIActionBars", true)
if EAB and EAB.db then
EAB.db.profile.selectedBar = key
end
end
end
local function SelectUnitFrame(unit)
return function()
-- Direct setter (if init already ran) + pending flag (consumed at page build)
if EllesmereUI._setUnitFrameUnit then EllesmereUI._setUnitFrameUnit(unit) end
EllesmereUI._pendingUnitSelect = unit
end
end
EllesmereUI._ELEMENT_SETTINGS_MAP = {
-- Unit Frames (all share "Frame Display" page; dropdown pre-selected to correct unit)
["player"] = { module = "EllesmereUIUnitFrames", page = "Frame Display", sectionName = "HEALTH BAR", preSelectFn = SelectUnitFrame("player"), highlightText = "Bar Height" },
["target"] = { module = "EllesmereUIUnitFrames", page = "Frame Display", sectionName = "HEALTH BAR", preSelectFn = SelectUnitFrame("target"), highlightText = "Bar Height" },
["focus"] = { module = "EllesmereUIUnitFrames", page = "Frame Display", sectionName = "HEALTH BAR", preSelectFn = SelectUnitFrame("focus"), highlightText = "Bar Height" },
["pet"] = { module = "EllesmereUIUnitFrames", page = "Frame Display", sectionName = "HEALTH BAR", preSelectFn = SelectUnitFrame("pet"), highlightText = "Bar Height" },
["targettarget"] = { module = "EllesmereUIUnitFrames", page = "Frame Display", sectionName = "HEALTH BAR", preSelectFn = SelectUnitFrame("targettarget"), highlightText = "Bar Height" },
["focustarget"] = { module = "EllesmereUIUnitFrames", page = "Frame Display", sectionName = "HEALTH BAR", preSelectFn = SelectUnitFrame("focustarget"), highlightText = "Bar Height" },
["boss"] = { module = "EllesmereUIUnitFrames", page = "Frame Display", sectionName = "HEALTH BAR", preSelectFn = SelectUnitFrame("boss"), highlightText = "Bar Height" },
["classPower"] = { module = "EllesmereUIUnitFrames", page = "Frame Display", sectionName = "CLASS RESOURCE", preSelectFn = SelectUnitFrame("player"), highlightText = "Enable Class Resource" },
-- Resource Bars (no dropdown — each bar has its own section)
["ERB_Health"] = { module = "EllesmereUIResourceBars", page = "Class, Power and Health Bars", sectionName = "HEALTH BAR", highlightText = "Bar Height" },
["ERB_Power"] = { module = "EllesmereUIResourceBars", page = "Class, Power and Health Bars", sectionName = "POWER BAR", highlightText = "Bar Height" },
["ERB_ClassResource"] = { module = "EllesmereUIResourceBars", page = "Class, Power and Health Bars", sectionName = "CLASS RESOURCE BAR", highlightText = "Bar Height" },
["ERB_CastBar"] = { module = "EllesmereUIResourceBars", page = "Cast Bar", sectionName = "BAR DISPLAY", highlightText = "Bar Height" },
-- Action Bars (all share "Bar Display" page; dropdown pre-selected to correct bar)
["MainBar"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("MainBar"), highlightText = "Icon Size" },
["Bar2"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("Bar2"), highlightText = "Icon Size" },
["Bar3"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("Bar3"), highlightText = "Icon Size" },
["Bar4"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("Bar4"), highlightText = "Icon Size" },
["Bar5"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("Bar5"), highlightText = "Icon Size" },
["Bar6"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("Bar6"), highlightText = "Icon Size" },
["Bar7"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("Bar7"), highlightText = "Icon Size" },
["Bar8"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("Bar8"), highlightText = "Icon Size" },
["StanceBar"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("StanceBar"), highlightText = "Icon Size" },
["PetBar"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("PetBar"), highlightText = "Icon Size" },
["XPBar"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("XPBar"), highlightText = "Icon Size" },
["RepBar"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "LAYOUT", preSelectFn = SelectActionBar("RepBar"), highlightText = "Icon Size" },
-- Action Bars — visibility-only (dropdown pre-selected, scroll to top)
["MicroBar"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "GENERAL", preSelectFn = SelectActionBar("MicroBagBars") },
["BagBar"] = { module = "EllesmereUIActionBars", page = "Bar Display", sectionName = "GENERAL", preSelectFn = SelectActionBar("MicroBagBars") },
-- Aura Buff Reminders
["EABR_Reminders"] = { module = "EllesmereUIAuraBuffReminders", page = "Auras, Buffs & Consumables", sectionName = "DISPLAY" },
-- General
["EUI_FPS"] = { module = "_EUIGlobal", page = "General", sectionName = "EXTRAS", highlightText = "Show FPS Counter" },
["EUI_SecondaryStats"] = { module = "_EUIGlobal", page = "General", sectionName = "EXTRAS", highlightText = "Secondary Stat Display" },
}
-- Width Match / Height Match / Anchor To pick modes
-- Only one pick mode can be active at a time. The active picker mover is stored here.
local pickMode = nil -- nil, "widthMatch", "heightMatch", "anchorTo"
local pickModeMover = nil -- the mover that initiated the pick mode
local hoveredMover = nil -- the currently expanded mover (only one at a time)
local cogHoveredMover = nil -- the mover whose cog button is currently hovered
local anchorDropdownFrame = nil -- lazy-created dropdown for anchor direction selection
local anchorDropdownCatcher = nil -- click-catcher behind anchor dropdown
local growDropdownFrame = nil -- lazy-created dropdown for grow direction selection
local growDropdownCatcher = nil -- click-catcher behind grow dropdown
local _mouseHeld = false -- true while left mouse button is held down anywhere
-- Cursor speed tracking for hover intent detection (stored on EllesmereUI to avoid upvalue pressure)
EllesmereUI._unlockCursorX = 0
EllesmereUI._unlockCursorY = 0
EllesmereUI._unlockCursorSpeed = 0 -- pixels/sec at UIParent scale
EllesmereUI._unlockHoverSpeedThresh = 80 * 80 -- squared px/sec threshold (avoids sqrt each frame)
EllesmereUI._unlockHoverIntentDelay = 0.12 -- seconds to wait after settling before expanding
-------------------------------------------------------------------------------
-- Anchor / Match DB helpers
-- Stored in EllesmereUIDB.unlockAnchors = { [childKey] = { target=key, side="LEFT"|"RIGHT"|"TOP"|"BOTTOM" } }
-- Width/height matches are applied immediately and saved to the element's
-- own settings — no persistent "match" relationship is stored.
-------------------------------------------------------------------------------
-- Forward declarations for functions defined later but referenced by anchor helpers
local GetBarFrame
local GetBarLabel
local PropagateAnchorChain
local SaveBarPosition
local ApplyAnchorPosition
local ApplyCenterPosition
local GetPositionDB
-------------------------------------------------------------------------------
-- Actual grow direction -- always returns the real direction (never nil).
-- Used for position calculations where we need the true anchor edge.
-------------------------------------------------------------------------------
local function GetBarGrowDirActual(barKey)
if barKey == "EQT_Tracker" then return "DOWN" end
if barKey:sub(1, 4) == "CDM_" then
local rawKey = barKey:sub(5)
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
if bar.key == rawKey then
return bar.growDirection or "CENTER"
end
end
end
return "CENTER"
else
local eab = EllesmereUI.Lite.GetAddon("EllesmereUIActionBars", true)
local s = eab and eab.db and eab.db.profile and eab.db.profile.bars
and eab.db.profile.bars[barKey]
if s then
return (s.growDirection or "up"):upper()
end
return "CENTER"
end
end
-------------------------------------------------------------------------------
-- Grow direction helper -- reads from the bar's per-profile settings
-- Returns the uppercase grow direction string, or nil if default/unset.
-- Action bar default is "UP", CDM default is nil (centered).
-------------------------------------------------------------------------------
local function GetBarGrowDir(barKey)
if barKey == "EQT_Tracker" then return "DOWN" end
if barKey:sub(1, 4) == "CDM_" then
local rawKey = barKey:sub(5)
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
if bar.key == rawKey then
local g = bar.growDirection
if g then return g end
return nil
end
end
end
return nil
else
local eab = EllesmereUI.Lite.GetAddon("EllesmereUIActionBars", true)
local s = eab and eab.db and eab.db.profile and eab.db.profile.bars
and eab.db.profile.bars[barKey]
if s then
local g = (s.growDirection or "up"):upper()
if g ~= "UP" then return g end
end
return nil
end
end
local function GetAnchorDB()
if not EllesmereUIDB then return nil end
if not EllesmereUIDB.unlockAnchors then
EllesmereUIDB.unlockAnchors = {}
end
return EllesmereUIDB.unlockAnchors
end
local function GetAnchorInfo(barKey)
local db = GetAnchorDB()
if not db then return nil end
return db[barKey]
end
-- RecenterBarAnchor(barKey)
-- Re-applies the grow-direction-aware anchor to the bar frame after a resize
-- so the fixed edge stays put. Must be synchronous (no C_Timer.After) to
-- avoid a visible flicker frame.
-- Defined here (after isUnlocked, movers, registeredElements, GetBarFrame,
-- GetBarGrowDirActual are all in scope) so the closure captures the correct
-- local upvalues.
function EllesmereUI.RecenterBarAnchor(barKey)
if not isUnlocked then return end
local elem = registeredElements[barKey]
if elem and elem.isAnchored and elem.isAnchored() then return end
local b = GetBarFrame(barKey)
if not b then return end
local s = b:GetEffectiveScale()
local uiS = UIParent:GetEffectiveScale()
local elemScale = s / uiS
local bL = b:GetLeft()
local bT = b:GetTop()
if not bL or not bT then return end
local w = (b:GetWidth() or 0) * elemScale
local h = (b:GetHeight() or 0) * elemScale
if w < 1 or h < 1 then return end
-- Center in UIParent-BOTTOMLEFT space
local uiCX = bL * elemScale + w * 0.5
local uiCY = bT * elemScale - h * 0.5
-- Pick anchor based on grow direction so the fixed edge stays put
local growDir = GetBarGrowDirActual(barKey)
local anchor, aX, aY
if growDir == "RIGHT" then
anchor = "LEFT"
aX = bL * elemScale
aY = uiCY
elseif growDir == "LEFT" then
anchor = "RIGHT"
aX = (bL * elemScale) + w
aY = uiCY
elseif growDir == "DOWN" then
anchor = "TOP"
aX = uiCX
aY = bT * elemScale
elseif growDir == "UP" then
anchor = "BOTTOM"
aX = uiCX
aY = bT * elemScale - h
else
anchor = "CENTER"
aX = uiCX
aY = uiCY
end
pcall(function()
b:ClearAllPoints()
b:SetPoint(anchor, UIParent, "BOTTOMLEFT", aX, aY)
end)
-- Keep mover's stored center in sync so drag/snap logic stays consistent
local m = movers[barKey]
if m and m._setCenterXY then
m._setCenterXY(uiCX, uiCY - UIParent:GetHeight())
end
end
local function SetAnchorInfo(childKey, targetKey, side, offsetX, offsetY)
local db = GetAnchorDB()
if not db then return end
db[childKey] = { target = targetKey, side = side, offsetX = offsetX, offsetY = offsetY }
end
local function ClearAnchorInfo(childKey)
local db = GetAnchorDB()
if not db then return end
db[childKey] = nil
end
local function IsAnchored(barKey)
local info = GetAnchorInfo(barKey)
if info ~= nil then return true end
local elem = registeredElements[barKey]
return elem and elem.isAnchored and elem.isAnchored() or false
end
-- Width/Height match persistent links
local MatchH = {}
function MatchH.GetWidthMatchDB()
if not EllesmereUIDB then return nil end
if not EllesmereUIDB.unlockWidthMatch then
EllesmereUIDB.unlockWidthMatch = {}
end
return EllesmereUIDB.unlockWidthMatch
end
function MatchH.GetHeightMatchDB()
if not EllesmereUIDB then return nil end
if not EllesmereUIDB.unlockHeightMatch then
EllesmereUIDB.unlockHeightMatch = {}
end
return EllesmereUIDB.unlockHeightMatch
end
function MatchH.GetWidthMatchInfo(barKey)
local db = MatchH.GetWidthMatchDB()
return db and db[barKey] or nil
end
function MatchH.GetHeightMatchInfo(barKey)
local db = MatchH.GetHeightMatchDB()
return db and db[barKey] or nil
end
-- Detect cycles: walk the chain from targetKey and check if we'd
-- reach childKey, which would create an infinite loop.
function MatchH.WouldCreateCycle(db, childKey, targetKey)
local visited = {}
local current = targetKey
while current do
if current == childKey then return true end
if visited[current] then return false end
visited[current] = true
current = db[current]
end
return false
end
function MatchH.SetWidthMatch(childKey, targetKey)
local db = MatchH.GetWidthMatchDB()
if not db then return end
if MatchH.WouldCreateCycle(db, childKey, targetKey) then
-- Break the cycle: clear the link that targetKey has, then set ours
db[targetKey] = nil
end
db[childKey] = targetKey
end
function MatchH.SetHeightMatch(childKey, targetKey)
local db = MatchH.GetHeightMatchDB()
if not db then return end
if MatchH.WouldCreateCycle(db, childKey, targetKey) then
db[targetKey] = nil
end
db[childKey] = targetKey
end
function MatchH.ClearWidthMatch(childKey)
local db = MatchH.GetWidthMatchDB()
if not db then return end
-- Persist current width so elements with "0 = match parent" defaults
-- don't revert on reload. The element's setWidth saves to its own DB.
local elem = registeredElements[childKey]
if elem and elem.setWidth then
local frame = GetBarFrame(childKey)
if frame then
local curW = frame:GetWidth()
if curW and curW > 0 then
pcall(elem.setWidth, childKey, curW)
end
end
end
db[childKey] = nil
end
function MatchH.ClearHeightMatch(childKey)
local db = MatchH.GetHeightMatchDB()
if not db then return end
local elem = registeredElements[childKey]
if elem and elem.setHeight then
local frame = GetBarFrame(childKey)
if frame then
local curH = frame:GetHeight()
if curH and curH > 0 then
pcall(elem.setHeight, childKey, curH)
end
end
end
db[childKey] = nil
end
-------------------------------------------------------------------------------
-- Public API: query width/height match state from any addon
-------------------------------------------------------------------------------
function EllesmereUI.GetWidthMatchTarget(barKey)
local db = MatchH.GetWidthMatchDB()
return db and db[barKey] or nil
end
function EllesmereUI.GetHeightMatchTarget(barKey)
local db = MatchH.GetHeightMatchDB()
return db and db[barKey] or nil
end
-- Returns (disabled_fn, tooltip_fn, rawTooltip) for use on width/height sliders.
-- Composes with an optional existing disabled/tooltip so both conditions work.
-- rawTooltip=true tells the widget system to skip DisabledTooltip wrapping.
function EllesmereUI.MatchGuard(barKey, axis, existingDisabled, existingTooltip)
local isWidth = (axis == "Width" or axis == "width")
local getFn = isWidth and EllesmereUI.GetWidthMatchTarget or EllesmereUI.GetHeightMatchTarget
local disabled = function()
if getFn(barKey) then return true end
if existingDisabled then return existingDisabled() end
return false
end
local tooltip = function()
local target = getFn(barKey)
if target then
local name = (EllesmereUI.GetBarLabel and EllesmereUI.GetBarLabel(target)) or target
return axis .. " matched to " .. name .. ". Unmatch in Unlock Mode to edit."
end
if existingTooltip then
return type(existingTooltip) == "function" and existingTooltip() or existingTooltip
end
return ""
end
local rawTooltip = function()
return getFn(barKey) ~= nil
end
return disabled, tooltip, rawTooltip
end
-------------------------------------------------------------------------------
-- PruneStaleLinks -- removes all anchor/match relationships for a key,
-- both where the key is the child AND where it is the target.
-- Call when an element is unregistered so nothing points to a ghost key.
-------------------------------------------------------------------------------
local function PruneStaleLinks(key)
if not EllesmereUIDB then return end
-- Anchors: key as child
local anchors = EllesmereUIDB.unlockAnchors
if anchors then
anchors[key] = nil
-- key as target -- scan all children
for childKey, info in pairs(anchors) do
if info and info.target == key then
anchors[childKey] = nil
end
end
end
-- Width matches: key as child or target
local wm = EllesmereUIDB.unlockWidthMatch
if wm then
wm[key] = nil
for childKey, targetKey in pairs(wm) do
if targetKey == key then wm[childKey] = nil end
end
end
-- Height matches: key as child or target
local hm = EllesmereUIDB.unlockHeightMatch
if hm then
hm[key] = nil
for childKey, targetKey in pairs(hm) do
if targetKey == key then hm[childKey] = nil end
end
end
end
EllesmereUI.PruneStaleLinks = PruneStaleLinks
-- Override UnregisterUnlockElement so cleanup runs whenever an element
-- is removed (e.g. a custom CDM bar is deleted).
function EllesmereUI:UnregisterUnlockElement(key)
self._unlockRegisteredElements[key] = nil
self._unlockRegistrationDirty = true
PruneStaleLinks(key)
end
-- Validate all stored relationships against currently registered elements.
-- Removes any that point to an element that no longer exists.
-- Runs once on load so stale data from a previous session is cleaned up.
local function ValidateStoredLinks()
if not EllesmereUIDB then return end
local elems = EllesmereUI._unlockRegisteredElements
local anchors = EllesmereUIDB.unlockAnchors
if anchors then
for childKey, info in pairs(anchors) do
if not elems[childKey] or (info and not elems[info.target]) then
anchors[childKey] = nil
end
end
end
local wm = EllesmereUIDB.unlockWidthMatch
if wm then
for childKey, targetKey in pairs(wm) do
if not elems[childKey] or not elems[targetKey] then
wm[childKey] = nil
elseif elems[childKey].noResize or elems[targetKey].noResize then
wm[childKey] = nil
end
end
end
local hm = EllesmereUIDB.unlockHeightMatch
if hm then
for childKey, targetKey in pairs(hm) do
if not elems[childKey] or not elems[targetKey] then
hm[childKey] = nil
elseif elems[childKey].noResize or elems[targetKey].noResize then
hm[childKey] = nil
end
end
end
end
-- Apply width/height match: sync source size from target
-- _propagatingMatch prevents re-entrant loops: setWidth triggers OnSizeChanged
-- which calls NotifyElementResized which would call PropagateWidthMatch again.
local _propagatingMatch = false
function MatchH.ApplyWidthMatch(sourceKey, targetKey)
local targetElem = registeredElements[targetKey]
local targetBar = GetBarFrame(targetKey)
local targetW
if targetElem and targetElem.getSize then
targetW = targetElem.getSize(targetKey)
elseif targetBar then
targetW = targetBar:GetWidth()
end
if targetW and targetW > 0 then
-- Snap to physical pixel grid (round-to-nearest, not truncate).
-- PP.Scale truncates, which drops a pixel on boundary values due
-- to floating point. SnapForES uses floor(x/px + 0.5) which is safe.
local PPm = EllesmereUI and EllesmereUI.PP
if PPm and PPm.SnapForES and targetBar then
targetW = PPm.SnapForES(targetW, targetBar:GetEffectiveScale())
else
targetW = floor(targetW + 0.5)
end
-- Convert target width to source's coordinate space if scales differ
local sourceBar = GetBarFrame(sourceKey)
if targetBar and sourceBar then
local tES = targetBar:GetEffectiveScale()
local sES = sourceBar:GetEffectiveScale()
if math.abs(tES - sES) > 0.001 then
targetW = targetW * tES / sES
end
end
local sourceElem = registeredElements[sourceKey]
if sourceElem and sourceElem.setWidth then
if isUnlocked then
local sb = GetBarFrame(sourceKey)
local savedAlpha = sb and sb._euiRestoreAlpha
if sb and not savedAlpha then sb:SetAlpha(0) end
_propagatingMatch = true
pcall(sourceElem.setWidth, sourceKey, targetW)
_propagatingMatch = false
EllesmereUI.RecenterBarAnchor(sourceKey)
if sb and not savedAlpha then
C_Timer.After(0, function() sb:SetAlpha(1) end)
end
local m = movers[sourceKey]
if m then m:SyncSize() end
else
_propagatingMatch = true
pcall(sourceElem.setWidth, sourceKey, targetW)
_propagatingMatch = false
if sourceElem.loadPosition then
local pos = sourceElem.loadPosition(sourceKey)
if pos and pos.point == "CENTER" and pos.relPoint == "CENTER" then