Skip to content

Commit 98781a9

Browse files
Added party sorting and also supporting putting the player last at the same time
1 parent ccb5892 commit 98781a9

7 files changed

Lines changed: 175 additions & 23 deletions

File tree

Config.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,10 @@ DF.PartyDefaults = {
16411641
"WARLOCK",
16421642
"WARRIOR",
16431643
},
1644+
1645+
-- Sorting
16441646
sortEnabled = true,
1647+
sortByPartyOrder = false, -- keep units in their original party/raid index order
16451648
sortRoleOrder = {"TANK", "HEALER", "MELEE", "RANGED"},
16461649
sortSelfPosition = "SORTED",
16471650
sortSeparateMeleeRanged = false,
@@ -2848,7 +2851,10 @@ DF.RaidDefaults = {
28482851
"WARLOCK",
28492852
"WARRIOR",
28502853
},
2854+
2855+
-- Sorting
28512856
sortEnabled = true,
2857+
sortByPartyOrder = false, -- keep units in their original party/raid index order
28522858
sortRoleOrder = {"TANK", "HEALER", "MELEE", "RANGED"},
28532859
sortSelfPosition = "SORTED",
28542860
sortSeparateMeleeRanged = false,

ExportCategories.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ DF.ExportCategories = {
3939

4040
-- Sorting
4141
"sortEnabled",
42+
"sortByPartyOrder",
4243
"sortAlphabetical",
4344
"sortByClass",
4445
"sortClassOrder",

Features/FlatRaidFrames.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,12 +883,16 @@ function FlatRaidFrames:UpdateSorting()
883883

884884
-- Check sorting settings
885885
local sortEnabled = db.sortEnabled
886+
-- party/raid index option overrides all other custom sorting
887+
if db.sortByPartyOrder then
888+
sortEnabled = false
889+
end
886890
local selfPosition = db.sortSelfPosition or "SORTED"
887891
local separateMeleeRanged = db.sortSeparateMeleeRanged
888892
local sortByClass = db.sortByClass
889893
local sortAlphabetical = db.sortAlphabetical
890894

891-
DebugPrint("UpdateSorting: sortEnabled=", sortEnabled, "selfPosition=", selfPosition)
895+
DebugPrint("UpdateSorting: sortEnabled=", sortEnabled, "selfPosition=", selfPosition, "partyOrder=", tostring(db.sortByPartyOrder))
892896
DebugPrint(" separateMeleeRanged=", separateMeleeRanged, "sortByClass=", sortByClass, "sortAlphabetical=", sortAlphabetical)
893897

894898
-- CRITICAL: Handle sortEnabled=false first

Features/SecureSort.lua

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,11 +596,20 @@ function SecureSort:CreateHandler()
596596
-- STEP 2: Get sort settings
597597
-- =====================================================
598598
local sortEnabled = self:GetAttribute("sortEnabled")
599+
local sortByPartyOrder = self:GetAttribute("sortByPartyOrder") or false
600+
local partyOrderSort = sortByPartyOrder
599601
local selfPosition = self:GetAttribute("selfPosition") or "NORMAL"
600602
local sortAlphabetical = self:GetAttribute("sortAlphabetical") or false
601603
local sortAlphaReverse = (sortAlphabetical == "ZA")
602604
local sortByClass = self:GetAttribute("sortByClass") or false
603605
606+
if sortByPartyOrder then
607+
-- ignore other criteria when using raw party order
608+
sortEnabled = false
609+
sortAlphabetical = false
610+
sortByClass = false
611+
end
612+
604613
-- =====================================================
605614
-- STEP 3: Query roles (if sorting enabled)
606615
-- =====================================================
@@ -700,11 +709,23 @@ function SecureSort:CreateHandler()
700709
for idx = 0, frameCount - 1 do
701710
local i = visibleFrames[idx]
702711
local unit = frameUnits[i]
703-
local role = unit2role[unit] or "DAMAGER"
704-
local rp = rolePriority[role] or 99
705-
local cls = unit2class[unit]
706-
local cp = sortByClass and (classPriority[cls] or 99) or 0
707-
frameSortKey[idx] = rp * 100 + cp
712+
if partyOrderSort then
713+
-- When using "party/raid index order", we want to KEEP the
714+
-- existing visual order of the frames and only apply the
715+
-- selfPosition override (player first/last/numeric slot).
716+
--
717+
-- The existing order is exactly the order of visibleFrames,
718+
-- so we just use the current index as the sort key. This
719+
-- guarantees non-player units stay in their current order,
720+
-- matching the behavior when sorting is disabled.
721+
frameSortKey[idx] = idx
722+
else
723+
local role = unit2role[unit] or "DAMAGER"
724+
local rp = rolePriority[role] or 99
725+
local cls = unit2class[unit]
726+
local cp = sortByClass and (classPriority[cls] or 99) or 0
727+
frameSortKey[idx] = rp * 100 + cp
728+
end
708729
709730
-- Read name from attribute (pushed by Lua code)
710731
frameName[idx] = self:GetAttribute("frameName" .. i) or ""
@@ -720,7 +741,7 @@ function SecureSort:CreateHandler()
720741
end
721742
722743
-- Bubble sort by sort key, then by name as tiebreaker
723-
if sortEnabled then
744+
if sortEnabled or partyOrderSort then
724745
for i = 0, frameCount - 2 do
725746
for j = 0, frameCount - 2 - i do
726747
local a = sortOrder[j]
@@ -2023,6 +2044,7 @@ function SecureSort:PushSortSettings()
20232044
self.sortButton:SetAttribute("roleOrder3", roleOrder[3] or "DAMAGER")
20242045
self.sortButton:SetAttribute("selfPosition", db.sortSelfPosition or "SORTED")
20252046
self.sortButton:SetAttribute("sortEnabled", db.sortEnabled or false)
2047+
self.sortButton:SetAttribute("sortByPartyOrder", db.sortByPartyOrder or false)
20262048
self.sortButton:SetAttribute("sortByClass", db.sortByClass or false)
20272049
self.sortButton:SetAttribute("meleeBeforeRanged", meleeBeforeRanged)
20282050
self.sortButton:SetAttribute("sortAlphabetical", db.sortAlphabetical or false)
@@ -2034,6 +2056,7 @@ function SecureSort:PushSortSettings()
20342056
self.handler:SetAttribute("roleOrder3", roleOrder[3] or "DAMAGER")
20352057
self.handler:SetAttribute("selfPosition", db.sortSelfPosition or "SORTED")
20362058
self.handler:SetAttribute("sortEnabled", db.sortEnabled or false)
2059+
self.handler:SetAttribute("sortByPartyOrder", db.sortByPartyOrder or false)
20372060
self.handler:SetAttribute("sortByClass", db.sortByClass or false)
20382061
self.handler:SetAttribute("meleeBeforeRanged", meleeBeforeRanged)
20392062
self.handler:SetAttribute("sortAlphabetical", db.sortAlphabetical or false)
@@ -2063,6 +2086,7 @@ function SecureSort:PushSortSettings()
20632086
DebugPrint("Sort settings pushed: " ..
20642087
(roleOrder[1] or "?") .. ">" .. (roleOrder[2] or "?") .. ">" .. (roleOrder[3] or "?") ..
20652088
" self=" .. (db.sortSelfPosition or "SORTED") ..
2089+
" partyOrder=" .. tostring(db.sortByPartyOrder) ..
20662090
" class=" .. tostring(db.sortByClass or false) ..
20672091
" alpha=" .. tostring(db.sortAlphabetical or false))
20682092

Features/Sort.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ local addonName, DF = ...
99
local pairs, ipairs, type, wipe = pairs, ipairs, type, wipe
1010
local sort = table.sort
1111
local tinsert = table.insert
12+
1213
local UnitExists = UnitExists
1314
local UnitGUID = UnitGUID
1415
local UnitGroupRolesAssigned = UnitGroupRolesAssigned
1516
local UnitClass = UnitClass
17+
local UnitIsUnit = UnitIsUnit
18+
local UnitName = UnitName
1619
local GetSpecializationInfoByID = GetSpecializationInfoByID
20+
local GetSpecialization = GetSpecialization
21+
local InCombatLockdown = InCombatLockdown
1722

1823
-- NOTE: Previously used reusable tables here, but that caused bugs when
1924
-- SortFrameList was called while iterating over a previous result.
@@ -157,6 +162,31 @@ end
157162

158163
-- Compare function for sorting frames
159164
function Sort:CompareUnits(unitA, unitB, db)
165+
-- Option to ignore role/class/name and simply use party/raid index
166+
if db.sortByPartyOrder then
167+
local function GetIndex(u)
168+
if not u then return 9999 end
169+
if UnitIsUnit(u, "player") then return 0 end
170+
171+
-- Prefer a GUID->party slot lookup so the "index order" matches the actual party roster
172+
-- even if the unit-id on a frame isn't literally "partyN" (e.g. raidN assignment).
173+
local guid = UnitGUID(u)
174+
if guid then
175+
for i = 1, 4 do
176+
local pu = "party" .. i
177+
if UnitExists(pu) and UnitGUID(pu) == guid then
178+
return i
179+
end
180+
end
181+
end
182+
183+
-- Fallback: parse digits from the unit string (party1/raid1/etc)
184+
local num = tonumber((u:match("%d+")))
185+
return num or 9999
186+
end
187+
return GetIndex(unitA) < GetIndex(unitB)
188+
end
189+
160190
local roleA = self:GetUnitRole(unitA)
161191
local roleB = self:GetUnitRole(unitB)
162192

@@ -199,6 +229,13 @@ end
199229

200230
-- Compare function for test mode using test data
201231
function Sort:CompareTestData(dataA, dataB, db)
232+
-- If party-order sorting is requested, use the precomputed index
233+
if db.sortByPartyOrder then
234+
local idxA = dataA.index or 9999
235+
local idxB = dataB.index or 9999
236+
return idxA < idxB
237+
end
238+
202239
-- Get roles from test data
203240
local roleA = dataA.role or "DAMAGER"
204241
local roleB = dataB.role or "DAMAGER"
@@ -424,6 +461,7 @@ SlashCmdList["DFSORT"] = function(msg)
424461
print(" sortByClass:", db.sortByClass)
425462
print(" sortAlphabetical:", tostring(db.sortAlphabetical))
426463
print(" sortSeparateMeleeRanged:", db.sortSeparateMeleeRanged)
464+
print(" sortByPartyOrder:", tostring(db.sortByPartyOrder))
427465
print(" sortRoleOrder:", table.concat(db.sortRoleOrder or {}, ", "))
428466
if db.sortByClass then
429467
print(" sortClassOrder:", table.concat(db.sortClassOrder or {}, ", "))

Frames/Headers.lua

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3928,6 +3928,7 @@ function DF:ApplyRaidGroupSorting()
39283928
end
39293929

39303930
-- Determine if we need nameList for advanced sorting
3931+
-- Party order option disables custom sorting entirely (sortEnabled=false above)
39313932
-- Use nameList for ALL groups when:
39323933
-- - Player position is FIRST/LAST (player's group only)
39333934
-- - OR any advanced option is enabled (all groups need it)
@@ -4323,19 +4324,78 @@ function DF:BuildRaidGroupNameList(groupIndex, selfPosition)
43234324
return DF:BuildSortedNameList(members, DF:GetRaidDB(), selfPosition, playerInGroup)
43244325
end
43254326

4326-
-- Build a namelist for party that puts player first or last, sorted by role priority
4327+
-- Build a nameList for party, honoring sortByPartyOrder and selfPosition
43274328
function DF:BuildPartyNameList(selfPosition)
4328-
-- Get members in party (player + party1-4)
4329-
local members = {}
4329+
local db = DF:GetDB()
43304330
local playerName = UnitName("player")
4331-
4331+
4332+
if db.sortByPartyOrder then
4333+
local names = {}
4334+
4335+
local partyNames = {}
4336+
for i = 1, 4 do
4337+
local unit = "party" .. i
4338+
if UnitExists(unit) and not UnitIsUnit(unit, "player") then
4339+
local name, realm = UnitName(unit)
4340+
if name then
4341+
local fullName = name
4342+
if realm and realm ~= "" then
4343+
fullName = name .. "-" .. realm
4344+
end
4345+
table.insert(partyNames, fullName)
4346+
end
4347+
end
4348+
end
4349+
4350+
local targetPos
4351+
if selfPosition == "FIRST" or selfPosition == "1" then
4352+
targetPos = 1
4353+
elseif selfPosition == "LAST" then
4354+
targetPos = #partyNames + 1
4355+
else
4356+
local n = tonumber(selfPosition)
4357+
if n and n >= 1 then
4358+
if n > (#partyNames + 1) then n = #partyNames + 1 end
4359+
targetPos = n
4360+
else
4361+
targetPos = nil
4362+
end
4363+
end
4364+
4365+
if targetPos then
4366+
local inserted = false
4367+
for i = 1, #partyNames + 1 do
4368+
if i == targetPos then
4369+
table.insert(names, playerName)
4370+
inserted = true
4371+
end
4372+
if i <= #partyNames then
4373+
table.insert(names, partyNames[i])
4374+
end
4375+
end
4376+
if not inserted then
4377+
table.insert(names, playerName)
4378+
end
4379+
else
4380+
table.insert(names, playerName)
4381+
for _, n in ipairs(partyNames) do
4382+
table.insert(names, n)
4383+
end
4384+
end
4385+
4386+
return table.concat(names, ",")
4387+
end
4388+
4389+
-- Default path: role/class/name sorting via unified function
4390+
local members = {}
4391+
43324392
-- Add player
43334393
table.insert(members, {
43344394
unit = "player",
43354395
name = playerName,
43364396
isPlayer = true
43374397
})
4338-
4398+
43394399
-- Add party members
43404400
for i = 1, 4 do
43414401
local unit = "party" .. i
@@ -4355,8 +4415,7 @@ function DF:BuildPartyNameList(selfPosition)
43554415
end
43564416
end
43574417

4358-
-- Use the unified sorting function
4359-
return DF:BuildSortedNameList(members, DF:GetDB(), selfPosition, true)
4418+
return DF:BuildSortedNameList(members, db, selfPosition, true)
43604419
end
43614420

43624421
-- ============================================================
@@ -5750,8 +5809,12 @@ function DF:ApplyPartyGroupSorting()
57505809
local sortByClass = db.sortByClass
57515810
local sortAlphabetical = db.sortAlphabetical
57525811

5753-
-- Determine if we need nameList (any advanced option or FIRST/LAST)
5754-
local needsNameList = (selfPosition ~= "SORTED") or separateMeleeRanged or sortByClass or sortAlphabetical
5812+
-- Determine if we need nameList (any advanced option, FIRST/LAST, or party-index mode)
5813+
local needsNameList = db.sortByPartyOrder
5814+
or (selfPosition ~= "SORTED")
5815+
or separateMeleeRanged
5816+
or sortByClass
5817+
or sortAlphabetical
57555818

57565819
if DF.debugHeaders then
57575820
print("|cFF00FF00[DF Headers]|r ApplyPartyGroupSorting:")
@@ -6780,10 +6843,12 @@ function DF:DumpHeaderInfo()
67806843
print(" growthAnchor:", db.growthAnchor or "nil")
67816844
print(" sortSelfPosition:", db.sortSelfPosition or "nil")
67826845
print(" sortEnabled:", db.sortEnabled and "true" or "false")
6846+
print(" sortByPartyOrder:", db.sortByPartyOrder and "true" or "false")
67836847
print("Raid Settings:")
67846848
print(" raidUseGroups:", raidDb.raidUseGroups and "true" or "false")
67856849
print(" raidEnabled:", raidDb.raidEnabled and "true" or "false")
67866850
print(" sortEnabled:", raidDb.sortEnabled and "true" or "false")
6851+
print(" sortByPartyOrder:", raidDb.sortByPartyOrder and "true" or "false")
67876852
print(" sortSelfPosition:", raidDb.sortSelfPosition or "nil")
67886853
print(" sortSeparateMeleeRanged:", raidDb.sortSeparateMeleeRanged and "true" or "false")
67896854
print(" sortByClass:", raidDb.sortByClass and "true" or "false")

0 commit comments

Comments
 (0)