forked from phanx-wow/Grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Layouts.lua
executable file
·267 lines (233 loc) · 7.57 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
--[[--------------------------------------------------------------------
Grid
Compact party and raid unit frames.
Copyright (c) 2006-2009 Kyle Smith (Pastamancer)
Copyright (c) 2009-2016 Phanx <[email protected]>
All rights reserved. See the accompanying LICENSE file for details.
https://github.com/Phanx/Grid
https://mods.curse.com/addons/wow/grid
http: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 lastNumGroups, lastUsedGroups, lastShowPets
local function AddPetGroup(t, numGroups, groupFilter)
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, numGroups, showPets)
for i = 1, numGroups do
local t = layout[i] or {}
t.groupFilter = tostring(i)
-- Reset attributes from merged layout
t.maxColumns = 1
-- Remove attributes for pet group
t.isPetGroup = nil
t.groupBy = nil
t.groupingOrder = nil
layout[i] = t
end
if showPets then
local i = numGroups + 1
layout[i] = AddPetGroup(layout[i], numGroups, groupFilter)
numGroups = i
end
for i = numGroups + 1, #layout do
layout[i] = nil
end
end
local function UpdateMergedGroups(layout, numGroups, showPets)
layout[1].groupFilter = groupFilter
layout[1].maxColumns = numGroups
if showPets then
layout[2] = AddPetGroup(layout[2], numGroups, groupFilter)
else
layout[2] = nil
end
for i = 3, numGroups do
layout[i] = nil
end
end
-- These are the number of groups actually used
local function UpdateNumGroups()
local groupType, maxPlayers = Roster:GetPartyState()
local usedGroups = {}
local numGroups = 0
local realGroups = 1
-- local curZone = GetRealZoneText()
-- GetCurrentMapAreaID does not match the mapID from UnitPosition
-- local curMapID = GetCurrentMapAreaID()
local _, _, _, curMapID = UnitPosition("player")
local showOffline = Layout.db.profile.showOffline -- Show Offline groups
-- Debug
local offlineGroups = {}
local zoneGroups = {}
local showWrongZone = Layout:ShowWrongZone()
-- Manager:Debug("Layout.db.profile.showWrongZone ", Layout.db.profile.showWrongZone, ", showWrongZone ", showWrongZone, ", groupType ", groupType)
if groupType == "raid" or groupType == "bg" then
if maxPlayers then
numGroups = ceil(maxPlayers / 5)
else
numGroups = 1
end
for i = 1, 8 do
usedGroups[i] = false
end
for i = 1, GetNumGroupMembers() do
local name, _, subgroup, _, _, _, zone, online = GetRaidRosterInfo(i);
local unitid = "raid" .. i
local _, _, _, mapID = UnitPosition(unitid)
-- If the highest group only has offline players it will not be shown
-- if name and online then
-- usedGroups[subgroup] = true
if name then
-- GetRaidRosterInfo zone comparison can show players in the same instance
-- when they are not. For example, outside Hellfire Citadel still shows
-- "Hellfire Citadel" as the zone text.
-- if (showOffline or online) and (showWrongZone or curZone == zone) then
-- Manager:Debug("curMapID ", curMapID, " name ", name, " mapID ", mapID)
if (showOffline or online) and (showWrongZone or curMapID == mapID) then
usedGroups[subgroup] = true
else
if (not online) then
offlineGroups[subgroup] = true
end
-- if (curZone ~= zone) then
if (curMapID ~= mapID) then
zoneGroups[subgroup] = true
end
end
end
end
for i = 1, 8 do
if usedGroups[i] and i > realGroups then
-- realGroups = numGroups + 1
realGroups = i
end
-- Debug
if not usedGroups[i] and offlineGroups[i] then
Manager:Debug("Group ", i, "is not used because players were offline.")
elseif not usedGroups[i] and zoneGroups[i] then
Manager:Debug("Group ", i, "is not used because players were in wrong zone.")
end
end
else
numGroups = 1
end
return numGroups, realGroups
end
function Manager:UpdateLayouts(event)
self:Debug("UpdateLayouts", event)
local groupType, maxPlayers = Roster:GetPartyState()
local showPets = Layout.db.profile.showPets -- Show Pets
local splitGroups = Layout.db.profile.splitGroups -- Keep Groups Together
-- local numGroups, groupFilter = ceil(maxPlayers / 5), "1"
-- for i = 2, numGroups do
-- groupFilter = groupFilter .. "," .. i
-- end
local numGroups = 1
local usedGroups = 1
if groupType == "raid" or groupType == "bg" then
numGroups, usedGroups = UpdateNumGroups()
elseif maxPlayers then
numGroups = ceil(maxPlayers / 5)
usedGroups = numGroups
end
self:Debug("maxPlayers", maxPlayers, "numGroups", numGroups, "usedGroups", usedGroups, "showPets", showPets, "splitGroups", splitGroups)
if lastNumGroups == numGroups and lastUsedGroups == usedGroups and lastShowPets == showPets then
self:Debug("no changes necessary")
return false
end
lastNumGroups = numGroups
lastUsedGroups = usedGroups
lastShowPets = showPets
-- Update class and role layouts
--@debug@
if splitGroups then
UpdateSplitGroups(Layouts.ByClass, numGroups, showPets)
UpdateSplitGroups(Layouts.ByRole, numGroups, showPets)
else
--@end-debug@
UpdateMergedGroups(Layouts.ByClass, numGroups, showPets)
UpdateMergedGroups(Layouts.ByRole, numGroups, showPets)
--@debug@
end
--@end-debug@
-- By group should always be split group
UpdateSplitGroups(Layouts.ByGroup, usedGroups, showPets)
-- Apply changes
Layout:ReloadLayout()
return true
end