-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathFlatRaidFrames.lua
More file actions
1408 lines (1206 loc) · 51.4 KB
/
Copy pathFlatRaidFrames.lua
File metadata and controls
1408 lines (1206 loc) · 51.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local addonName, DF = ...
-- ============================================================
-- FLAT RAID FRAMES - PinnedFrames-style implementation
-- Replaces the legacy raidCombinedHeader system
-- Uses SecureGroupHeaderTemplate with nameList for explicit control
-- ============================================================
local FlatRaidFrames = {}
DF.FlatRaidFrames = FlatRaidFrames
-- ============================================================
-- MODULE STATE
-- ============================================================
-- Frame storage
FlatRaidFrames.header = nil -- SecureGroupHeaderTemplate
FlatRaidFrames.innerContainer = nil -- Inner container for growth anchor control
FlatRaidFrames.initialized = false
-- Pending updates (for combat deferral)
FlatRaidFrames.pendingNameListUpdate = false
FlatRaidFrames.pendingLayoutUpdate = false
FlatRaidFrames.pendingVisibility = nil -- nil = no pending, true/false = pending state
FlatRaidFrames.pendingInitialize = false
FlatRaidFrames.pendingReinitialize = false
-- Debug flag
FlatRaidFrames.debug = false
-- ============================================================
-- DEBUG UTILITIES
-- ============================================================
local function DebugPrint(...)
if FlatRaidFrames.debug then
print("|cFF00FFFF[DF FlatRaid]|r", ...)
end
end
-- Build groupFilter string from raidGroupVisible setting
-- Returns e.g. "1,2,3,5,6,7" if group 4 and 8 are hidden
local function BuildGroupFilter()
local db = DF:GetRaidDB()
if not db or not db.raidGroupVisible then
return "1,2,3,4,5,6,7,8"
end
local groups = {}
for i = 1, 8 do
local visible = db.raidGroupVisible[i]
if visible == nil or visible then -- Default to visible
groups[#groups + 1] = tostring(i)
end
end
if #groups == 0 then
return "1,2,3,4,5,6,7,8" -- Safety fallback
end
return table.concat(groups, ",")
end
-- ============================================================
-- CONFIG ACCESS
-- ============================================================
-- Get raid DB (shortcut)
local function GetRaidDB()
return DF:GetRaidDB()
end
-- Check if we should be active (flat mode, not grouped mode)
local function ShouldBeActive()
local db = GetRaidDB()
return db and not db.raidUseGroups
end
-- ============================================================
-- ANCHOR CALCULATION
-- ============================================================
-- Get the corner anchor point for the header based on growth settings
-- This determines which corner of innerContainer the header anchors to
local function GetHeaderAnchorPoint(db)
local horizontal = (db.growDirection == "HORIZONTAL")
local frameAnchor = db.raidFlatFrameAnchor or "START"
local columnAnchor = db.raidFlatColumnAnchor or "START"
if horizontal then
-- Horizontal: frameAnchor controls left/right, columnAnchor controls top/bottom
if frameAnchor == "END" then
return (columnAnchor == "END") and "BOTTOMRIGHT" or "TOPRIGHT"
else
return (columnAnchor == "END") and "BOTTOMLEFT" or "TOPLEFT"
end
else
-- Vertical: frameAnchor controls top/bottom, columnAnchor controls left/right
if frameAnchor == "END" then
return (columnAnchor == "END") and "BOTTOMRIGHT" or "BOTTOMLEFT"
else
return (columnAnchor == "END") and "TOPRIGHT" or "TOPLEFT"
end
end
end
-- Get the anchor point for innerContainer within raidContainer
-- This is the "growth anchor" - where the frame group is positioned/grows from
-- Maps simplified options (START/CENTER/END) to WoW anchor points
-- The mapping depends on orientation (Rows vs Columns)
local function GetGrowthAnchorPoint(db)
local growthAnchor = db.raidFlatGrowthAnchor or "START"
local horizontal = (db.growDirection == "HORIZONTAL") -- true = Rows, false = Columns
if growthAnchor == "START" then
return "TOPLEFT"
elseif growthAnchor == "CENTER" then
return "CENTER"
elseif growthAnchor == "END" then
-- End position depends on orientation
if horizontal then
-- Rows: End means bottom-left
return "BOTTOMLEFT"
else
-- Columns: End means top-right
return "TOPRIGHT"
end
else
-- Legacy values - map directly
return growthAnchor
end
end
-- Get current group roster as a lookup table
-- Returns: { [name] = true, ... }
local function GetGroupRoster()
local roster = {}
local numMembers = GetNumGroupMembers()
if numMembers == 0 then
-- Solo
local name = UnitName("player")
if name then
roster[name] = true
end
return roster
end
local isRaid = IsInRaid()
for i = 1, numMembers do
local unit = isRaid and ("raid" .. i) or (i == 1 and "player" or "party" .. (i - 1))
local name = UnitName(unit)
if name then
roster[name] = true
end
end
return roster
end
-- Get player's full name (Name-Realm)
local function GetPlayerFullName()
local name = UnitName("player")
local realm = GetRealmName()
return name .. "-" .. realm
end
-- ============================================================
-- NAMELIST BUILDING
-- This is the core of the new system - we build a sorted list
-- of player names and let SecureGroupHeaderTemplate display them
-- ============================================================
-- Build a sorted nameList string based on current settings
-- This replaces the complex groupBy/groupingOrder/groupFilter juggling
function FlatRaidFrames:BuildSortedNameList()
local db = GetRaidDB()
if not db then return "" end
local numMembers = GetNumGroupMembers()
if numMembers == 0 then
-- Solo - just return player name
return UnitName("player") or ""
end
-- Settings
local separateMeleeRanged = db.sortSeparateMeleeRanged
local sortByClass = db.sortByClass
local sortAlphabetical = db.sortAlphabetical
-- Melee specs by specID (for melee/ranged separation)
local meleeSpecs = {
[250] = true, [251] = true, [252] = true, -- Death Knight
[577] = true, [581] = true, -- Demon Hunter
[103] = true, -- Druid Feral
[255] = true, -- Hunter Survival
[269] = true, -- Monk Windwalker
[70] = true, -- Paladin Ret
[259] = true, [260] = true, [261] = true, -- Rogue
[263] = true, -- Shaman Enh
[71] = true, [72] = true, -- Warrior Arms/Fury
}
-- Class-based melee fallback (when spec not available)
-- Only classes whose DPS spec is always melee
local meleeClasses = {
DEATHKNIGHT = true, DEMONHUNTER = true, ROGUE = true, WARRIOR = true, PALADIN = true
}
-- Get melee/ranged type for a unit
local function GetMeleeRangedType(unit, role, class)
if role ~= "DAMAGER" then return nil end
local specID
if UnitIsUnit(unit, "player") then
local spec = GetSpecialization()
if spec then
specID = GetSpecializationInfo(spec)
end
else
specID = GetInspectSpecialization(unit)
end
if specID and specID > 0 then
return meleeSpecs[specID] and "MELEE" or "RANGED"
end
-- Fallback to class-based detection
return meleeClasses[class] and "MELEE" or "RANGED"
end
-- Build role priority from settings
local roleOrder = db.sortRoleOrder or {"TANK", "HEALER", "MELEE", "RANGED"}
local rolePriority = {}
for i, role in ipairs(roleOrder) do
if separateMeleeRanged then
-- When separating melee/ranged, use MELEE and RANGED directly
rolePriority[role] = i
else
-- When not separating, map MELEE/RANGED to DAMAGER
if role == "MELEE" or role == "RANGED" then
if not rolePriority["DAMAGER"] then
rolePriority["DAMAGER"] = i
end
else
rolePriority[role] = i
end
end
end
-- Defaults
rolePriority["TANK"] = rolePriority["TANK"] or 1
rolePriority["HEALER"] = rolePriority["HEALER"] or 2
if separateMeleeRanged then
rolePriority["MELEE"] = rolePriority["MELEE"] or 3
rolePriority["RANGED"] = rolePriority["RANGED"] or 4
else
rolePriority["DAMAGER"] = rolePriority["DAMAGER"] or 3
end
rolePriority["NONE"] = 99
-- Class priority
local classOrder = db.sortClassOrder or {
"DEATHKNIGHT", "DEMONHUNTER", "DRUID", "EVOKER", "HUNTER",
"MAGE", "MONK", "PALADIN", "PRIEST", "ROGUE",
"SHAMAN", "WARLOCK", "WARRIOR"
}
local classPriority = {}
for i, className in ipairs(classOrder) do
classPriority[className] = i
end
-- Gather all raid members with their info
local members = {}
local playerName = UnitName("player")
local playerRealm = GetRealmName()
local playerEntry = nil
for i = 1, numMembers do
local unit = "raid" .. i
local name, realm = UnitName(unit)
if name then
-- Filter by group visibility
local _, _, subgroup = GetRaidRosterInfo(i)
if subgroup and db.raidGroupVisible and db.raidGroupVisible[subgroup] == false then
-- Skip members in hidden groups
else
-- Build full name with realm for nameList
-- Only append realm for cross-realm players (when realm is returned)
-- Same-server players should use just the name (matches SecureGroupHeaderTemplate behavior)
local fullName
if realm and realm ~= "" then
fullName = name .. "-" .. realm
else
fullName = name
end
local role = UnitGroupRolesAssigned(unit)
if role == "NONE" then role = "DAMAGER" end
local _, class = UnitClass(unit)
class = class or "UNKNOWN"
-- Determine sort role (may be MELEE/RANGED if separation enabled)
local sortRole
if separateMeleeRanged then
local meleeRanged = GetMeleeRangedType(unit, role, class)
sortRole = meleeRanged or role
else
sortRole = role
end
local isPlayer = UnitIsUnit(unit, "player")
local entry = {
name = name,
fullName = fullName,
realm = realm or playerRealm,
role = role,
sortRole = sortRole,
class = class,
classPriority = classPriority[class] or 99,
rolePriority = rolePriority[sortRole] or 99,
isPlayer = isPlayer,
unit = unit,
}
if isPlayer then
playerEntry = entry
else
table.insert(members, entry)
end
end -- group visibility filter
end
end
-- Sort function
local function sortFunc(a, b)
-- Sort by role priority first
if a.rolePriority ~= b.rolePriority then
return a.rolePriority < b.rolePriority
end
-- Then by class if enabled
if sortByClass then
if a.classPriority ~= b.classPriority then
return a.classPriority < b.classPriority
end
end
-- Then alphabetically if enabled
if sortAlphabetical then
if sortAlphabetical == "ZA" then
return a.name > b.name
else
return a.name < b.name
end
end
return false
end
-- Sort members
table.sort(members, sortFunc)
-- Build the nameList based on selfPosition setting
local selfPosition = db.sortSelfPosition or "FIRST"
local names = {}
if selfPosition == "FIRST" and playerEntry then
-- Player first (use short name for player)
table.insert(names, playerEntry.name)
for _, entry in ipairs(members) do
table.insert(names, entry.fullName)
end
elseif selfPosition == "LAST" and playerEntry then
-- Others first, player last
for _, entry in ipairs(members) do
table.insert(names, entry.fullName)
end
table.insert(names, playerEntry.name)
else
-- SORTED - include player in sorting
if playerEntry then
table.insert(members, playerEntry)
table.sort(members, sortFunc)
end
for _, entry in ipairs(members) do
if entry.isPlayer then
table.insert(names, entry.name)
else
table.insert(names, entry.fullName)
end
end
end
local result = table.concat(names, ",")
DebugPrint("BuildSortedNameList result:", result)
return result
end
-- ============================================================
-- FRAME CREATION
-- Uses the same "startingIndex trick" as PinnedFrames
-- ============================================================
function FlatRaidFrames:CreateFrames()
if self.header then
DebugPrint("Header already exists, skipping creation")
return
end
if InCombatLockdown() then
DebugPrint("In combat, cannot create frames")
return
end
-- Need raidContainer to exist
if not DF.raidContainer then
DebugPrint("raidContainer doesn't exist yet, deferring creation")
return
end
local db = GetRaidDB()
if not db then
DebugPrint("No raid DB available")
return
end
DebugPrint("Creating FlatRaidFrames...")
-- ============================================================
-- Create innerContainer - this handles growth anchor positioning
-- The innerContainer sits inside raidContainer and resizes to fit frames
-- Its anchor point within raidContainer determines growth direction
-- ============================================================
self.innerContainer = CreateFrame("Frame", "DandersFlatRaidInnerContainer", DF.raidContainer)
self.innerContainer:SetSize(100, 100) -- Will be resized by ResizeInnerContainer
-- Anchor innerContainer based on growth anchor setting
local growthAnchor = GetGrowthAnchorPoint(db)
self.innerContainer:SetPoint(growthAnchor, DF.raidContainer, growthAnchor, 0, 0)
DebugPrint("InnerContainer anchored to:", growthAnchor)
-- ============================================================
-- Create SecureGroupHeaderTemplate - parented to innerContainer
-- ============================================================
self.header = CreateFrame("Frame", "DandersFlatRaidHeader", self.innerContainer, "SecureGroupHeaderTemplate")
-- Show all raid members - nameList controls which are visible
self.header:SetAttribute("showPlayer", true)
self.header:SetAttribute("showParty", false)
self.header:SetAttribute("showRaid", true)
self.header:SetAttribute("showSolo", true)
self.header:SetAttribute("groupFilter", BuildGroupFilter())
-- Use same template as main frames
self.header:SetAttribute("template", "DandersUnitButtonTemplate")
-- ============================================================
-- CRITICAL: Apply layout attributes BEFORE startingIndex trick
-- This matches the original CreateRaidCombinedHeader order
-- ============================================================
self:ApplyLayoutAttributesInternal()
-- Store frame dimensions
self.header:SetAttribute("frameWidth", db.frameWidth or 80)
self.header:SetAttribute("frameHeight", db.frameHeight or 40)
-- ============================================================
-- STARTINGINDEX TRICK - Pre-create all 40 frames
-- ============================================================
self.header:SetAttribute("startingIndex", -39) -- Creates up to 40 frames
self.header:Show()
self.header:SetAttribute("startingIndex", 1) -- Reset to normal
-- DON'T hide - visibility is managed by SetEnabled later
-- Count created children and set their sizes
local childCount = 0
local frameWidth = db.frameWidth or 80
local frameHeight = db.frameHeight or 40
for i = 1, 40 do
local child = self.header:GetAttribute("child" .. i)
if child then
childCount = childCount + 1
child:SetSize(frameWidth, frameHeight)
child.isRaidFrame = true
end
end
DebugPrint("Created", childCount, "child frames, sized to", frameWidth, "x", frameHeight)
-- Now switch to nameList mode and set initial nameList
self.header:SetAttribute("sortMethod", "NAMELIST")
self.header:SetAttribute("groupFilter", nil) -- Clear groupFilter, nameList takes over
self:UpdateNameList()
-- Hide until SetEnabled is called
self.header:Hide()
self.innerContainer:Hide()
DebugPrint("FlatRaidFrames creation complete")
end
-- Internal function to apply layout attributes (called during creation)
-- Uses anchor calculations like PinnedFrames
function FlatRaidFrames:ApplyLayoutAttributesInternal()
local header = self.header
if not header then return end
local db = GetRaidDB()
if not db then return end
local horizontal = (db.growDirection == "HORIZONTAL")
local hSpacing = db.raidFlatHorizontalSpacing or 2
local vSpacing = db.raidFlatVerticalSpacing or 2
local unitsPerRow = db.raidPlayersPerRow or 5
local frameAnchor = db.raidFlatFrameAnchor or "START"
local columnAnchor = db.raidFlatColumnAnchor or "START"
-- Frame anchor point determines where first frame is placed and growth direction
-- HORIZONTAL: START=LEFT (grow right), END=RIGHT (grow left)
-- VERTICAL: START=TOP (grow down), END=BOTTOM (grow up)
local point, xOff, yOff
if horizontal then
if frameAnchor == "END" then
point = "RIGHT"
xOff = -hSpacing -- Negative to grow left
else
point = "LEFT"
xOff = hSpacing -- Positive to grow right
end
yOff = 0
else
if frameAnchor == "END" then
point = "BOTTOM"
yOff = vSpacing -- Positive to grow up
else
point = "TOP"
yOff = -vSpacing -- Negative to grow down
end
xOff = 0
end
header:SetAttribute("point", point)
header:SetAttribute("xOffset", xOff)
header:SetAttribute("yOffset", yOff)
-- Column anchor point determines where new columns/rows appear
-- HORIZONTAL: columns are vertical, START=TOP (down), END=BOTTOM (up)
-- VERTICAL: columns are horizontal, START=LEFT (right), END=RIGHT (left)
local colAnchorPoint, colSpacing
if horizontal then
colSpacing = vSpacing
colAnchorPoint = (columnAnchor == "END") and "BOTTOM" or "TOP"
else
colSpacing = hSpacing
colAnchorPoint = (columnAnchor == "END") and "RIGHT" or "LEFT"
end
header:SetAttribute("columnSpacing", colSpacing)
header:SetAttribute("columnAnchorPoint", colAnchorPoint)
header:SetAttribute("maxColumns", math.ceil(40 / unitsPerRow))
header:SetAttribute("unitsPerColumn", unitsPerRow)
-- Anchor header to innerContainer corner based on growth settings
local headerAnchorPoint = GetHeaderAnchorPoint(db)
header:ClearAllPoints()
header:SetPoint(headerAnchorPoint, self.innerContainer, headerAnchorPoint, 0, 0)
DebugPrint("ApplyLayoutAttributesInternal:")
DebugPrint(" headerAnchor:", headerAnchorPoint)
DebugPrint(" point:", point, "xOff:", xOff, "yOff:", yOff)
DebugPrint(" columnAnchorPoint:", colAnchorPoint)
end
-- ============================================================
-- LAYOUT SETTINGS
-- Applies positioning attributes to the header (for runtime changes)
-- ============================================================
function FlatRaidFrames:ApplyLayoutSettings(skipRefresh)
local header = self.header
if not header then return end
if InCombatLockdown() then
self.pendingLayoutUpdate = true
DebugPrint("Layout update deferred (combat)")
return
end
local db = GetRaidDB()
if not db then return end
local frameWidth = db.frameWidth or 80
local frameHeight = db.frameHeight or 40
local horizontal = (db.growDirection == "HORIZONTAL")
local hSpacing = db.raidFlatHorizontalSpacing or 2
local vSpacing = db.raidFlatVerticalSpacing or 2
local unitsPerRow = db.raidPlayersPerRow or 5
local frameAnchor = db.raidFlatFrameAnchor or "START"
local columnAnchor = db.raidFlatColumnAnchor or "START"
-- Frame anchor point determines where first frame is placed and growth direction
local point, xOff, yOff
if horizontal then
if frameAnchor == "END" then
point = "RIGHT"
xOff = -hSpacing
else
point = "LEFT"
xOff = hSpacing
end
yOff = 0
else
if frameAnchor == "END" then
point = "BOTTOM"
yOff = vSpacing
else
point = "TOP"
yOff = -vSpacing
end
xOff = 0
end
header:SetAttribute("point", point)
header:SetAttribute("xOffset", xOff)
header:SetAttribute("yOffset", yOff)
-- Column anchor point
local colAnchorPoint, colSpacing
if horizontal then
colSpacing = vSpacing
colAnchorPoint = (columnAnchor == "END") and "BOTTOM" or "TOP"
else
colSpacing = hSpacing
colAnchorPoint = (columnAnchor == "END") and "RIGHT" or "LEFT"
end
header:SetAttribute("columnSpacing", colSpacing)
header:SetAttribute("columnAnchorPoint", colAnchorPoint)
header:SetAttribute("maxColumns", math.ceil(40 / unitsPerRow))
header:SetAttribute("unitsPerColumn", unitsPerRow)
-- Store frame dimensions for the template
header:SetAttribute("frameWidth", frameWidth)
header:SetAttribute("frameHeight", frameHeight)
-- Update innerContainer anchor (growth anchor)
if self.innerContainer then
local growthAnchor = GetGrowthAnchorPoint(db)
self.innerContainer:ClearAllPoints()
self.innerContainer:SetPoint(growthAnchor, DF.raidContainer, growthAnchor, 0, 0)
end
-- Update header anchor to innerContainer corner
local headerAnchorPoint = GetHeaderAnchorPoint(db)
header:ClearAllPoints()
header:SetPoint(headerAnchorPoint, self.innerContainer, headerAnchorPoint, 0, 0)
DebugPrint("ApplyLayoutSettings:")
DebugPrint(" horizontal:", horizontal)
DebugPrint(" frameAnchor:", frameAnchor, "columnAnchor:", columnAnchor)
DebugPrint(" headerAnchor:", headerAnchorPoint)
DebugPrint(" frameSize:", frameWidth, "x", frameHeight)
DebugPrint(" spacing:", hSpacing, vSpacing)
DebugPrint(" unitsPerRow:", unitsPerRow)
-- ============================================================
-- CRITICAL: 4-step refresh to force repositioning
-- This is the secret sauce from the working PinnedFrames
-- Skip when called from SetEnabled - UpdateNameList() follows immediately
-- and does its own rebuild, making this stale-data refresh redundant
-- ============================================================
if not skipRefresh and header:IsShown() then
-- Save current sorting state
local currentNameList = header:GetAttribute("nameList")
local currentGroupBy = header:GetAttribute("groupBy")
local currentGroupingOrder = header:GetAttribute("groupingOrder")
local currentGroupFilter = header:GetAttribute("groupFilter")
local currentSortMethod = header:GetAttribute("sortMethod")
-- Step 1: Clear nameList/groupBy to remove unit assignments
header:SetAttribute("groupBy", nil)
header:SetAttribute("nameList", "")
-- Step 2: Clear all child positions and sync isRaidFrame flag
-- Always true: these are structurally raid children regardless of IsInRaid() state
for i = 1, 40 do
local child = header:GetAttribute("child" .. i)
if child then
child:ClearAllPoints()
child.isRaidFrame = true
end
end
-- Step 3: Force header to process by hiding and showing
header:Hide()
header:Show()
-- Step 4: Restore sorting - this reassigns units with new layout
if currentGroupBy then
-- Was using groupBy mode
header:SetAttribute("groupingOrder", currentGroupingOrder)
header:SetAttribute("groupFilter", currentGroupFilter)
header:SetAttribute("sortMethod", currentSortMethod)
header:SetAttribute("groupBy", currentGroupBy)
elseif currentNameList and currentNameList ~= "" then
-- Was using nameList mode
header:SetAttribute("nameList", currentNameList)
header:SetAttribute("sortMethod", "NAMELIST")
end
DebugPrint(" 4-step refresh complete")
end
-- Resize innerContainer to fit frames
self:ResizeInnerContainer()
end
-- Force the header to recalculate child positions
-- This is needed after changing layout attributes
function FlatRaidFrames:RefreshLayout()
local header = self.header
if not header then return end
if InCombatLockdown() then
self.pendingLayoutUpdate = true
return
end
local db = GetRaidDB()
local frameWidth = db and db.frameWidth or 80
local frameHeight = db and db.frameHeight or 40
DebugPrint("RefreshLayout - resizing children and toggling startingIndex")
-- FIRST: Resize all child frames and sync isRaidFrame flag (needed for proper positioning)
for i = 1, 40 do
local child = header:GetAttribute("child" .. i)
if child then
child:SetSize(frameWidth, frameHeight)
child.isRaidFrame = true
end
end
-- Force SecureGroupHeaderTemplate to re-evaluate child positions
-- by toggling startingIndex - this triggers a full layout refresh
-- (Same approach as legacy ApplyFlatLayoutAttributes)
local currentStartingIndex = header:GetAttribute("startingIndex") or 1
header:SetAttribute("startingIndex", currentStartingIndex == 1 and 2 or 1)
header:SetAttribute("startingIndex", 1)
DebugPrint("Layout refreshed - children resized, startingIndex toggled")
end
-- Resize innerContainer to fit the visible frames
-- This is what makes the CENTER growth anchor work - as innerContainer resizes,
-- it expands symmetrically from its center point
function FlatRaidFrames:ResizeInnerContainer()
if not self.innerContainer or not self.header then return end
DF:Debug("FLATRAID", "ResizeInnerContainer: recalculating")
local db = GetRaidDB()
if not db then return end
local frameWidth = db.frameWidth or 80
local frameHeight = db.frameHeight or 40
local horizontal = (db.growDirection == "HORIZONTAL")
local hSpacing = db.raidFlatHorizontalSpacing or 2
local vSpacing = db.raidFlatVerticalSpacing or 2
local unitsPerRow = db.raidPlayersPerRow or 5
-- Count visible children
local visibleCount = 0
for i = 1, 40 do
local child = self.header:GetAttribute("child" .. i)
if child and child:IsShown() then
visibleCount = visibleCount + 1
end
end
if visibleCount == 0 then
self.innerContainer:SetSize(frameWidth, frameHeight)
return
end
local rows = math.ceil(visibleCount / unitsPerRow)
local cols = math.min(visibleCount, unitsPerRow)
local width, height
if horizontal then
-- Horizontal: cols frames across, rows down
width = cols * frameWidth + (cols - 1) * hSpacing
height = rows * frameHeight + (rows - 1) * vSpacing
else
-- Vertical: rows frames down, cols across
width = rows * frameWidth + (rows - 1) * hSpacing
height = cols * frameHeight + (cols - 1) * vSpacing
end
self.innerContainer:SetSize(width, height)
DF:Debug("FLATRAID", "ResizeInnerContainer: %dx%d (%d visible, %d rows, %d cols)", width, height, visibleCount, rows, cols)
-- Only resize the shared raidContainer if flat mode is actually active
-- In grouped mode, the position handler manages container sizing — FlatRaid
-- must NOT touch it or grouped headers will jump to wrong positions
local rdb = GetRaidDB()
if rdb and not rdb.raidUseGroups then
self:UpdateContainerSize()
DF:SyncRaidMoverToContainer()
else
DF:Debug("FLATRAID", "ResizeInnerContainer: SKIPPING container resize (grouped mode active)")
end
end
-- Update container size based on layout settings
function FlatRaidFrames:UpdateContainerSize()
if not DF.raidContainer then return end
if InCombatLockdown() then return end
local db = GetRaidDB()
if not db then return end
local horizontal = (db.growDirection == "HORIZONTAL")
local hSpacing = db.raidFlatHorizontalSpacing or 2
local vSpacing = db.raidFlatVerticalSpacing or 2
local frameWidth = db.frameWidth or 80
local frameHeight = db.frameHeight or 40
local unitsPerRow = db.raidPlayersPerRow or 5
local maxColumns = math.ceil(40 / unitsPerRow)
local containerWidth, containerHeight
if horizontal then
containerWidth = unitsPerRow * frameWidth + (unitsPerRow - 1) * hSpacing
containerHeight = maxColumns * frameHeight + (maxColumns - 1) * vSpacing
else
containerWidth = maxColumns * frameWidth + (maxColumns - 1) * hSpacing
containerHeight = unitsPerRow * frameHeight + (unitsPerRow - 1) * vSpacing
end
local oldW, oldH = DF.raidContainer:GetSize()
DF.raidContainer:SetSize(containerWidth, containerHeight)
DF:Debug("FLATRAID", "UpdateContainerSize: %dx%d -> %dx%d (raidUseGroups=%s)",
math.floor(oldW + 0.5), math.floor(oldH + 0.5),
math.floor(containerWidth + 0.5), math.floor(containerHeight + 0.5),
tostring(db.raidUseGroups))
DebugPrint("Container size:", containerWidth, "x", containerHeight)
end
-- ============================================================
-- NAMELIST UPDATE
-- The key function - sets the nameList attribute
-- ============================================================
function FlatRaidFrames:UpdateSorting()
local header = self.header
if not header then
DebugPrint("UpdateSorting: no header")
return
end
-- Safety: bail out if grouped mode is active — FlatRaid should not be sorting
local rdb = GetRaidDB()
if rdb and rdb.raidUseGroups then
DF:Debug("FLATRAID", "UpdateSorting: BLOCKED (grouped mode active, raidUseGroups=true)")
return
end
if InCombatLockdown() then
self.pendingNameListUpdate = true
DF:Debug("FLATRAID", "UpdateSorting: deferred (combat lockdown)")
return
end
DF:Debug("FLATRAID", "UpdateSorting: starting")
local db = GetRaidDB()
if not db then return end
-- Re-apply layout attributes (point, xOffset, yOffset) from the DB
-- so that Hide/Show below rebuilds children with the correct spacing. (#269)
self:ApplyLayoutSettings(true)
-- Check sorting settings
local sortEnabled = db.sortEnabled
-- party/raid index option overrides all other custom sorting
if db.sortByPartyOrder then
sortEnabled = false
end
local selfPosition = db.sortSelfPosition or "SORTED"
local separateMeleeRanged = db.sortSeparateMeleeRanged
local sortByClass = db.sortByClass
local sortAlphabetical = db.sortAlphabetical
DebugPrint("UpdateSorting: sortEnabled=", sortEnabled, "selfPosition=", selfPosition, "partyOrder=", tostring(db.sortByPartyOrder))
DebugPrint(" separateMeleeRanged=", separateMeleeRanged, "sortByClass=", sortByClass, "sortAlphabetical=", sortAlphabetical)
-- CRITICAL: Handle sortEnabled=false first
-- Must clear ALL sorting attributes to prevent stale nameList/groupBy from persisting
if not sortEnabled then
DebugPrint(" Sorting DISABLED - using INDEX mode (clearing all attributes)")
-- Clear all sorting attributes with nil
header:SetAttribute("nameList", nil)
header:SetAttribute("groupBy", nil)
header:SetAttribute("groupingOrder", nil)
header:SetAttribute("roleFilter", nil)
header:SetAttribute("strictFiltering", nil)
header:SetAttribute("groupFilter", BuildGroupFilter()) -- Respect group visibility
header:SetAttribute("sortMethod", "INDEX")
-- Force header to recalculate by toggling visibility
if header:IsShown() then
header:Hide()
header:Show()
end
-- Resize innerContainer to fit visible frames
self:ResizeInnerContainer()
return
end
-- Determine if we need nameList (complex sorting) or can use groupBy (simple role sorting)
-- Use groupBy when: selfPosition=="SORTED" AND no advanced options
local useGroupBy = selfPosition == "SORTED"
and not separateMeleeRanged
and not sortByClass
and not sortAlphabetical
DebugPrint(" useGroupBy=", useGroupBy)
if useGroupBy then
-- Simple mode: use groupBy=ASSIGNEDROLE with groupingOrder from role priority
-- This matches how grouped layouts work
-- Build groupingOrder from role priority
local roleOrder = db.sortRoleOrder or {"TANK", "HEALER", "MELEE", "RANGED"}
local groupingOrder = {}
for _, role in ipairs(roleOrder) do
if role == "MELEE" or role == "RANGED" then
-- Map MELEE/RANGED to DAMAGER for groupBy (it only understands TANK/HEALER/DAMAGER)
if not tContains(groupingOrder, "DAMAGER") then
table.insert(groupingOrder, "DAMAGER")
end
else
table.insert(groupingOrder, role)
end
end
local orderString = table.concat(groupingOrder, ",")
DebugPrint(" Using groupBy mode, groupingOrder:", orderString)
-- Set attributes for groupBy mode
-- CRITICAL ORDER:
-- 1. Clear groupBy first (in case it was already set, setting other attrs would trigger update)
-- 2. Set all other attributes
-- 3. Set groupBy last (this triggers the update)
header:SetAttribute("groupBy", nil) -- Clear first!
header:SetAttribute("nameList", nil)
header:SetAttribute("groupingOrder", orderString)
header:SetAttribute("groupFilter", BuildGroupFilter())
header:SetAttribute("sortMethod", "NAME") -- Sort alphabetically within groups
header:SetAttribute("groupBy", "ASSIGNEDROLE") -- This triggers update, must be last
else
-- Complex mode: use nameList for full control over order
local nameList = self:BuildSortedNameList()
DebugPrint(" Using nameList mode:", nameList ~= "" and nameList or "(empty)")
-- Set attributes for nameList mode
-- Clear groupBy first to prevent triggering updates with old settings
header:SetAttribute("groupBy", nil)
header:SetAttribute("groupingOrder", nil)
header:SetAttribute("groupFilter", nil)
header:SetAttribute("nameList", nameList)
header:SetAttribute("sortMethod", "NAMELIST")
end
-- Force header to recalculate by toggling visibility
if header:IsShown() then
header:Hide()
header:Show()
end
-- Resize innerContainer to fit visible frames
-- Note: Call directly, no delays (combat safety)
self:ResizeInnerContainer()
-- Schedule private aura reanchor after all attribute changes settle (combat-safe)
if DF.SchedulePrivateAuraReanchor then
DF:SchedulePrivateAuraReanchor()
end
end
-- Alias for backward compatibility
function FlatRaidFrames:UpdateNameList()
self:UpdateSorting()
end
-- ============================================================