-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLayouts.lua
More file actions
412 lines (355 loc) · 12.9 KB
/
Layouts.lua
File metadata and controls
412 lines (355 loc) · 12.9 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
--[[--------------------------------------------------------------------
Plexus
Compact party and raid unit frames.
Copyright (c) 2006-2009 Kyle Smith (Pastamancer)
Copyright (c) 2009-2018 Phanx <addons@phanx.net>
Copyright (c) 2018-2025 Doadin <doadinaddons@gmail.com>
All rights reserved. See the accompanying LICENSE file for details.
----------------------------------------------------------------------]]
local _, Plexus = ...
local L = Plexus.L
local GetNumGroupMembers = GetNumGroupMembers
local GetRaidRosterInfo = GetRaidRosterInfo
local Layout = Plexus:GetModule("PlexusLayout")
local Roster = Plexus:GetModule("PlexusRoster")
local DEFAULT_ROLE = Plexus:IsClassicWow() and 'ROLE' or 'ASSIGNEDROLE'
local DEFAULT_ROLE_ORDER = Plexus:IsClassicWow() and 'MAINTANK,MAINASSIST,NONE' or 'TANK,HEALER,DAMAGER,NONE'
-- nameList = "",
-- groupFilter = "",
-- sortMethod = "INDEX", -- or "NAME"
-- sortDir = "ASC", -- or "DESC"
-- strictFiltering = false,
-- unitsPerColumn = 5, -- treated specifically to do the right thing when available
-- maxColumns = 5, -- mandatory if unitsPerColumn is set, or defaults to 1
-- isPetGroup = true, -- special case, not part of the Header API
local Layouts = {
None = {
name = L["None"],
},
ByGroup = {
name = L["By Group"],
defaults = {
sortMethod = "INDEX",
unitsPerColumn = 5,
maxColumns = 1,
},
[1] = {
groupFilter = "1",
},
-- additional groups added/removed dynamically
},
ByGroupPets = {
name = L["By Group With Pets"],
defaults = {
sortMethod = "INDEX",
unitsPerColumn = 5,
maxColumns = 1,
},
[1] = {
groupFilter = "1",
},
-- additional groups added/removed dynamically
},
ByGroupRole = {
name = L["By Group & Role"],
defaults = {
groupBy = DEFAULT_ROLE,
groupingOrder = DEFAULT_ROLE_ORDER,
sortMethod = "NAME",
unitsPerColumn = 5,
maxColumns = 1,
},
[1] = {
groupFilter = "1",
},
-- additional groups added/removed dynamically
},
ByGroupRolePets = {
name = L["By Group & Role With Pets"],
defaults = {
groupBy = DEFAULT_ROLE,
groupingOrder = DEFAULT_ROLE_ORDER,
sortMethod = "NAME",
unitsPerColumn = 5,
maxColumns = 1,
},
[1] = {
groupFilter = "1",
},
-- additional groups added/removed dynamically
},
ByClass = {
name = L["By Class"],
defaults = {
groupBy = "CLASS",
groupingOrder = "WARRIOR,DEATHKNIGHT,DEMONHUNTER,ROGUE,MONK,PALADIN,DRUID,SHAMAN,PRIEST,MAGE,WARLOCK,HUNTER,EVOKER",
sortMethod = "NAME",
unitsPerColumn = 5,
},
[1] = {
groupFilter = "1", -- updated dynamically
},
},
ByClassPets = {
name = L["By Class With Pets"],
defaults = {
groupBy = "CLASS",
groupingOrder = "WARRIOR,DEATHKNIGHT,DEMONHUNTER,ROGUE,MONK,PALADIN,DRUID,SHAMAN,PRIEST,MAGE,WARLOCK,HUNTER,EVOKER",
sortMethod = "NAME",
unitsPerColumn = 5,
},
[1] = {
groupFilter = "1", -- updated dynamically
},
},
ByRole = {
name = L["By Role"],
defaults = {
groupBy = DEFAULT_ROLE,
groupingOrder = DEFAULT_ROLE_ORDER,
sortMethod = "NAME",
unitsPerColumn = 5,
},
[1] = {
groupFilter = "1", -- updated dynamically
},
},
ByRolePets = {
name = L["By Role With Pets"],
defaults = {
groupBy = DEFAULT_ROLE,
groupingOrder = DEFAULT_ROLE_ORDER,
sortMethod = "NAME",
unitsPerColumn = 5,
},
[1] = {
groupFilter = "1", -- updated dynamically
},
},
ByName = {
name = L["By Name"],
defaults = {
sortMethod = "NAME",
unitsPerColumn = 5;NOREPEAT, --luacheck: ignore
maxColumns = 8,
},
[1] = {
groupFilter = "1", -- updated dynamically
},
},
ByNamePets = {
name = L["By Name With Pets"],
defaults = {
sortMethod = "NAME",
unitsPerColumn = 5;NOREPEAT, --luacheck: ignore
maxColumns = 8,
},
[1] = {
groupFilter = "1", -- updated dynamically
},
},
}
--------------------------------------------------------------------------------
local Manager = Layout:NewModule("PlexusLayoutManager", "AceEvent-3.0")
Manager.Debug = Plexus.Debug -- PlexusLayout doesn't have a module prototype
function Manager:OnInitialize()
self:Debug("OnInitialize")
Plexus:SetDebuggingEnabled(self.moduleName)
for k, v in pairs(Layouts) do
Layout:AddLayout(k, v)
end
self:RegisterMessage("Plexus_RosterUpdated", "UpdateLayouts")
end
--------------------------------------------------------------------------------
local function AddPetGroup(t, groupFilter, numGroups)
--@debug@
assert(t == nil or type(t) == "table")
assert(type(groupFilter) == "string")
assert(string.len(groupFilter) > 0 and string.len(groupFilter) % 2 == 1)
assert(type(numGroups) == "number")
assert(numGroups == (1 + string.len(groupFilter)) / 2)
--@end-debug@
t = t or {}
t.groupFilter = groupFilter
t.maxColumns = numGroups
t.isPetGroup = true
t.groupBy = "CLASS"
t.groupingOrder = "HUNTER,WARLOCK,MAGE,DEATHKNIGHT,DRUID,PRIEST,SHAMAN,MONK,PALADIN,DEMONHUNTER,ROGUE,WARRIOR,EVOKER"
-- t.sortMethod = "NAME"
return t
end
local function UpdateSplitGroups(layout, groupFilter, numGroups, showPets, showPetsFirst)
--@debug@
assert(type(layout) == "table")
assert(type(groupFilter) == "string")
assert(string.len(groupFilter) > 0 and string.len(groupFilter) % 2 == 1)
assert(type(numGroups) == "number")
assert(numGroups == (1 + string.len(groupFilter)) / 2)
--@end-debug@
if showPetsFirst then
local offset = showPets and 1 or 0
-- Add pet group first if showPets is true
if showPets then
layout[1] = AddPetGroup(layout[1], groupFilter, numGroups)
end
-- Update the remaining groups
for i = 1, numGroups do
local t = layout[i + offset] or {}
layout[i + offset] = t
t.groupFilter = string.sub(groupFilter, i * 2 - 1, i * 2)
-- Reset attributes from merged layout
t.maxColumns = 1
-- Remove attributes for pet group
t.isPetGroup = nil
t.groupBy = nil
t.groupingOrder = nil
end
-- Clear any leftover groups
for i = numGroups + offset + 1, #layout do
layout[i] = nil
end
else
for i = 1, numGroups do
local t = layout[i] or {}
layout[i] = t
t.groupFilter = string.sub(groupFilter, i * 2 - 1, i * 2)
-- Reset attributes from merged layout
t.maxColumns = 1
-- Remove attributes for pet group
t.isPetGroup = nil
t.groupBy = nil
t.groupingOrder = nil
end
if showPets then
local i = numGroups + 1
layout[i] = AddPetGroup(layout[i], groupFilter, numGroups)
numGroups = i
end
for i = numGroups + 1, #layout do
layout[i] = nil
end
end
end
local function UpdateMergedGroups(layout, groupFilter, numGroups, showPets, showPetsFirst)
--@debug@
assert(type(layout) == "table")
assert(type(groupFilter) == "string")
assert(string.len(groupFilter) > 0 and string.len(groupFilter) % 2 == 1)
assert(type(numGroups) == "number")
assert(numGroups == (1 + string.len(groupFilter)) / 2)
--@end-debug@
if showPets and showPetsFirst then
-- Add pet group as the first group
layout[1] = AddPetGroup(layout[1], groupFilter, numGroups)
-- Shift the main group to the second position
layout[2] = layout[2] or {}
layout[2].groupFilter = groupFilter
layout[2].maxColumns = numGroups
-- Clear any leftover groups
for i = 3, #layout do
layout[i] = nil
end
else
-- Add main group as the first group
layout[1].groupFilter = groupFilter
layout[1].maxColumns = numGroups
-- Add pet group as the second group if showPets is true
layout[2] = showPets and AddPetGroup(layout[2], groupFilter, numGroups) or nil
-- Clear any leftover groups
for i = 3, #layout do
layout[i] = nil
end
end
end
local hideGroup = {}
function Manager:GetGroupFilter()
local groupType, maxPlayers = Roster:GetPartyState()
self:Debug("groupType", groupType, "maxPlayers", maxPlayers)
-- GetNumGroupMembers when solo returns 0 even in world BG zones such as wintergrasp
-- Therefore even in BG if GetNumGroupMembers == 0 return 1
if groupType ~= "raid" and groupType ~= "bg" or (groupType == "bg" and GetNumGroupMembers() == 0) then
return "1", 1
end
local showOffline = Layout.db.profile.showOffline
local showWrongZone = Layout:ShowWrongZone()
local playerMapID = C_Map.GetBestMapForUnit("player")
local MAX_RAID_GROUPS = MAX_RAID_GROUPS or 8
local MAX_RAID_MEMBERS = MAX_RAID_MEMBERS or 40
for i = 1, MAX_RAID_GROUPS do
hideGroup[i] = ""
end
--discouraged to use GetNumGroupMembers
for i = 1, MAX_RAID_MEMBERS do
--name, rank, subgroup, level, class, fileName, zone, online, isDead, role, isML, combatRole
local _, _, subgroup, _, _, _, _, online = GetRaidRosterInfo(i)
local raidMemberMapID = C_Map.GetBestMapForUnit("raid" .. i)
local playerMapGroupID
local raidMemberMapGroupID
if playerMapID and raidMemberMapID then
playerMapGroupID = C_Map.GetMapGroupID(playerMapID)
raidMemberMapGroupID = C_Map.GetMapGroupID(raidMemberMapID)
end
if playerMapGroupID and raidMemberMapGroupID then
if (showOffline or online) and (showWrongZone or playerMapGroupID == raidMemberMapGroupID) then
hideGroup[subgroup] = nil
end
elseif playerMapID and raidMemberMapID then
if (showOffline or online) and (showWrongZone or playerMapID == raidMemberMapID) then
hideGroup[subgroup] = nil
end
-- if we cant get zone info for a unit just show the group
else
if (showOffline or online) then
hideGroup[subgroup] = nil
end
end
end
local groupFilter, numGroups = "", 0
for i = 1, MAX_RAID_GROUPS do
if not hideGroup[i] then
groupFilter = groupFilter .. "," .. i
numGroups = numGroups + 1
--@debug@
else
self:Debug("Group", i, "hidden:", hideGroup[i])
--@end-debug@
end
end
return groupFilter:sub(2), numGroups
end
local lastGroupFilter
function Manager:UpdateLayouts(event)
self:Debug("UpdateLayouts", event)
local groupFilter, numGroups = self:GetGroupFilter()
local splitGroups = Layout.db.profile.splitGroups
local showPetsFirst = Layout.db.profile.showPetsFirst
if not groupFilter then
return false
end
self:Debug("groupFilter", groupFilter, "numGroups", numGroups, "splitGroups", splitGroups)
if lastGroupFilter == groupFilter then
self:Debug("No changes necessary")
return false
end
lastGroupFilter = groupFilter
-- Update class and role layouts
if splitGroups then
UpdateSplitGroups(Layouts.ByClass, groupFilter, numGroups, false, showPetsFirst)
UpdateSplitGroups(Layouts.ByRole, groupFilter, numGroups, false, showPetsFirst)
else
UpdateMergedGroups(Layouts.ByClass, groupFilter, numGroups, false, showPetsFirst)
UpdateMergedGroups(Layouts.ByClassPets, groupFilter, numGroups, true, showPetsFirst)
UpdateMergedGroups(Layouts.ByRole, groupFilter, numGroups, false, showPetsFirst)
UpdateMergedGroups(Layouts.ByRolePets, groupFilter, numGroups, true, showPetsFirst)
end
-- Update group layout (always split)
UpdateSplitGroups(Layouts.ByGroup, groupFilter, numGroups, false, showPetsFirst)
UpdateSplitGroups(Layouts.ByGroupPets, groupFilter, numGroups, true, showPetsFirst)
UpdateSplitGroups(Layouts.ByGroupRole, groupFilter, numGroups, false, showPetsFirst)
UpdateSplitGroups(Layouts.ByGroupRolePets, groupFilter, numGroups, true, showPetsFirst)
UpdateSplitGroups(Layouts.ByName, groupFilter, numGroups, false, showPetsFirst)
UpdateSplitGroups(Layouts.ByNamePets, groupFilter, numGroups, true, showPetsFirst)
-- Apply changes
Layout:ReloadLayout()
return true
end