This repository has been archived by the owner on Jan 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Layouts.lua
executable file
·249 lines (204 loc) · 6.82 KB
/
Layouts.lua
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
--[[--------------------------------------------------------------------
Grid
Compact party and raid unit frames.
Copyright (c) 2006-2009 Kyle Smith (Pastamancer)
Copyright (c) 2009-2018 Phanx <[email protected]>
All rights reserved. See the accompanying LICENSE file for details.
https://github.com/Phanx/Grid
https://www.curseforge.com/wow/addons/grid
https://www.wowinterface.com/downloads/info5747-Grid.html
----------------------------------------------------------------------]]
local _, Grid = ...
local L = Grid.L
local Layout = Grid:GetModule("GridLayout")
local Roster = Grid:GetModule("GridRoster")
-- 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
},
ByClass = {
name = L["By Class"],
defaults = {
groupBy = "CLASS",
groupingOrder = "WARRIOR,DEATHKNIGHT,DEMONHUNTER,ROGUE,MONK,PALADIN,DRUID,SHAMAN,PRIEST,MAGE,WARLOCK,HUNTER",
sortMethod = "NAME",
unitsPerColumn = 5,
},
[1] = {
groupFilter = "1", -- updated dynamically
},
},
ByRole = {
name = L["By Role"],
defaults = {
groupBy = "ASSIGNEDROLE",
groupingOrder = "TANK,HEALER,DAMAGER,NONE",
sortMethod = "NAME",
unitsPerColumn = 5,
},
[1] = {
groupFilter = "1", -- updated dynamically
},
}
}
--@debug@
GRIDLAYOUTS = Layouts
--@end-debug@
--------------------------------------------------------------------------------
local Manager = Layout:NewModule("GridLayoutManager", "AceEvent-3.0")
Manager.Debug = Grid.Debug -- GridLayout doesn't have a module prototype
function Manager:OnInitialize()
self:Debug("OnInitialize")
Grid:SetDebuggingEnabled(self.moduleName)
for k, v in pairs(Layouts) do
Layout:AddLayout(k, v)
end
self:RegisterMessage("Grid_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"
-- t.sortMethod = "NAME"
return t
end
local function UpdateSplitGroups(layout, groupFilter, numGroups, showPets)
--@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@
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
local function UpdateMergedGroups(layout, groupFilter, numGroups, showPets)
--@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@
layout[1].groupFilter = groupFilter
layout[1].maxColumns = numGroups
layout[2] = showPets and AddPetGroup(layout[2], groupFilter, numGroups) or nil
for i = 3, numGroups do
layout[i] = nil
end
end
local hideGroup = {}
function Manager:GetGroupFilter()
local groupType, maxPlayers = Roster:GetPartyState()
self:Debug("groupType", groupType, "maxPlayers", maxPlayers)
if groupType ~= "raid" and groupType ~= "bg" then
return "1", 1
end
local showOffline = Layout.db.profile.showOffline
local showWrongZone = Layout:ShowWrongZone()
local curMapID = C_Map.GetBestMapForUnit("player")
for i = 1, MAX_RAID_GROUPS do
hideGroup[i] = ""
end
for i = 1, GetNumGroupMembers() do
local name, _, subgroup, _, _, _, _, online = GetRaidRosterInfo(i)
local mapID = C_Map.GetBestMapForUnit("raid" .. i)
if (showOffline or online) and (showWrongZone or curMapID == mapID) then
hideGroup[subgroup] = nil
--@debug@
elseif curMapID ~= mapID and not showWrongZone then
hideGroup[subgroup] = (hideGroup[subgroup] or "") .. " ZONE"
elseif not online and not showOffline then
hideGroup[subgroup] = (hideGroup[subgroup] or "") .. " OFFLINE"
--@end-debug@
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 lastNumGroups, lastGroupFilter, lastShowPets
function Manager:UpdateLayouts(event)
self:Debug("UpdateLayouts", event)
local groupFilter, numGroups = self:GetGroupFilter()
local showPets = Layout.db.profile.showPets
local splitGroups = Layout.db.profile.splitGroups
self:Debug("groupFilter", groupFilter, "numGroups", numGroups, "showPets", showPets, "splitGroups", splitGroups)
if lastGroupFilter == groupFilter and lastShowPets == showPets then
self:Debug("No changes necessary")
return false
end
lastGroupFilter = groupFilter
lastShowPets = showPets
-- Update class and role layouts
if splitGroups then
UpdateSplitGroups(Layouts.ByClass, groupFilter, numGroups, showPets)
UpdateSplitGroups(Layouts.ByRole, groupFilter, numGroups, showPets)
else
UpdateMergedGroups(Layouts.ByClass, groupFilter, numGroups, showPets)
UpdateMergedGroups(Layouts.ByRole, groupFilter, numGroups, showPets)
end
-- Update group layout (always split)
UpdateSplitGroups(Layouts.ByGroup, groupFilter, numGroups, showPets)
-- Apply changes
Layout:ReloadLayout()
return true
end