Advertisement
Guest User

Grid Layout

a guest
Apr 23rd, 2017
533
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.83 KB | None | 0 0
  1. --[[--------------------------------------------------------------------
  2. Grid
  3. Compact party and raid unit frames.
  4. Copyright (c) 2006-2009 Kyle Smith (Pastamancer)
  5. Copyright (c) 2009-2016 Phanx <addons@phanx.net>
  6. All rights reserved. See the accompanying LICENSE file for details.
  7. https://github.com/Phanx/Grid
  8. https://mods.curse.com/addons/wow/grid
  9. http://www.wowinterface.com/downloads/info5747-Grid.html
  10. ----------------------------------------------------------------------]]
  11.  
  12. local _, Grid = ...
  13. local L = Grid.L
  14. local Layout = Grid:GetModule("GridLayout")
  15. local Roster = Grid:GetModule("GridRoster")
  16.  
  17. -- nameList = "",
  18. -- groupFilter = "",
  19. -- sortMethod = "INDEX", -- or "NAME"
  20. -- sortDir = "ASC", -- or "DESC"
  21. -- strictFiltering = false,
  22. -- unitsPerColumn = 5, -- treated specifically to do the right thing when available
  23. -- maxColumns = 5, -- mandatory if unitsPerColumn is set, or defaults to 1
  24. -- isPetGroup = true, -- special case, not part of the Header API
  25.  
  26. local Layouts = {
  27. None = {
  28. name = L["None"],
  29. },
  30. ByGroup = {
  31. name = L["By Group"],
  32. defaults = {
  33. sortMethod = "INDEX",
  34. unitsPerColumn = 5,
  35. maxColumns = 1,
  36. },
  37. [1] = {
  38. groupFilter = "1",
  39. },
  40. -- additional groups added/removed dynamically
  41. },
  42. ByClass = {
  43. name = L["By Class"],
  44. defaults = {
  45. groupBy = "CLASS",
  46. groupingOrder = "WARRIOR,DEATHKNIGHT,DEMONHUNTER,ROGUE,MONK,PALADIN,DRUID,SHAMAN,PRIEST,MAGE,WARLOCK,HUNTER",
  47. sortMethod = "NAME",
  48. unitsPerColumn = 5,
  49. },
  50. [1] = {
  51. groupFilter = "1", -- updated dynamically
  52. },
  53. },
  54. ByRole = {
  55. name = L["By Role"],
  56. defaults = {
  57. groupBy = "ASSIGNEDROLE",
  58. groupingOrder = "TANK,HEALER,DAMAGER,NONE",
  59. sortMethod = "NAME",
  60. unitsPerColumn = 5,
  61. },
  62. [1] = {
  63. groupFilter = "1", -- updated dynamically
  64. },
  65. }
  66. }
  67. --[===[@debug@
  68. GRIDLAYOUTS = Layouts
  69. --@end-debug@]===]
  70.  
  71. --------------------------------------------------------------------------------
  72.  
  73. local Manager = Layout:NewModule("GridLayoutManager", "AceEvent-3.0")
  74. Manager.Debug = Grid.Debug -- GridLayout doesn't have a module prototype
  75.  
  76. function Manager:OnInitialize()
  77. self:Debug("OnInitialize")
  78.  
  79. Grid:SetDebuggingEnabled(self.moduleName)
  80.  
  81. for k, v in pairs(Layouts) do
  82. Layout:AddLayout(k, v)
  83. end
  84.  
  85. self:RegisterMessage("Grid_RosterUpdated", "UpdateLayouts")
  86. end
  87.  
  88. --------------------------------------------------------------------------------
  89.  
  90. local lastNumGroups, lastUsedGroups, lastShowPets
  91.  
  92. local function AddPetGroup(t, numGroups, groupFilter)
  93. t = t or {}
  94. t.groupFilter = groupFilter
  95. t.maxColumns = numGroups
  96.  
  97. t.isPetGroup = true
  98. t.groupBy = "CLASS"
  99. t.groupingOrder = "HUNTER,WARLOCK,MAGE,DEATHKNIGHT,DRUID,PRIEST,SHAMAN,MONK,PALADIN,DEMONHUNTER,ROGUE,WARRIOR"
  100. -- t.sortMethod = "NAME"
  101.  
  102. return t
  103. end
  104.  
  105. local function UpdateSplitGroups(layout, numGroups, showPets)
  106. for i = 1, numGroups do
  107. local t = layout[i] or {}
  108. t.groupFilter = tostring(i)
  109. -- Reset attributes from merged layout
  110. t.maxColumns = 1
  111. -- Remove attributes for pet group
  112. t.isPetGroup = nil
  113. t.groupBy = nil
  114. t.groupingOrder = nil
  115. layout[i] = t
  116. end
  117. if showPets then
  118. local i = numGroups + 1
  119. layout[i] = AddPetGroup(layout[i], numGroups, groupFilter)
  120. numGroups = i
  121. end
  122. for i = numGroups + 1, #layout do
  123. layout[i] = nil
  124. end
  125. end
  126.  
  127. local function UpdateMergedGroups(layout, numGroups, showPets)
  128. layout[1].groupFilter = groupFilter
  129. layout[1].maxColumns = numGroups
  130. if showPets then
  131. layout[2] = AddPetGroup(layout[2], numGroups, groupFilter)
  132. else
  133. layout[2] = nil
  134. end
  135. for i = 3, numGroups do
  136. layout[i] = nil
  137. end
  138. end
  139.  
  140. -- These are the number of groups actually used
  141. local function UpdateNumGroups()
  142. local groupType, maxPlayers = Roster:GetPartyState()
  143. local usedGroups = {}
  144. local numGroups = 0
  145. local realGroups = 1
  146. -- local curZone = GetRealZoneText()
  147. -- GetCurrentMapAreaID does not match the mapID from UnitPosition
  148. -- local curMapID = GetCurrentMapAreaID()
  149. local _, _, _, curMapID = UnitPosition("player")
  150. local showOffline = Layout.db.profile.showOffline -- Show Offline groups
  151. -- Debug
  152. local offlineGroups = {}
  153. local zoneGroups = {}
  154. local showWrongZone = Layout:ShowWrongZone()
  155.  
  156. -- Manager:Debug("Layout.db.profile.showWrongZone ", Layout.db.profile.showWrongZone, ", showWrongZone ", showWrongZone, ", groupType ", groupType)
  157.  
  158. if groupType == "raid" or groupType == "bg" then
  159. if maxPlayers then
  160. numGroups = ceil(maxPlayers / 5)
  161. else
  162. numGroups = 1
  163. end
  164.  
  165. for i = 1, 8 do
  166. usedGroups[i] = false
  167. end
  168. for i = 1, GetNumGroupMembers() do
  169. local name, _, subgroup, _, _, _, zone, online = GetRaidRosterInfo(i);
  170. local unitid = "raid" .. i
  171. local _, _, _, mapID = UnitPosition(unitid)
  172. -- If the highest group only has offline players it will not be shown
  173. -- if name and online then
  174. -- usedGroups[subgroup] = true
  175. if name then
  176. -- GetRaidRosterInfo zone comparison can show players in the same instance
  177. -- when they are not. For example, outside Hellfire Citadel still shows
  178. -- "Hellfire Citadel" as the zone text.
  179. -- if (showOffline or online) and (showWrongZone or curZone == zone) then
  180. -- Manager:Debug("curMapID ", curMapID, " name ", name, " mapID ", mapID)
  181. if (showOffline or online) and (showWrongZone or curMapID == mapID) then
  182. usedGroups[subgroup] = true
  183. else
  184. if (not online) then
  185. offlineGroups[subgroup] = true
  186. end
  187. -- if (curZone ~= zone) then
  188. if (curMapID ~= mapID) then
  189. zoneGroups[subgroup] = true
  190. end
  191. end
  192. end
  193. end
  194. for i = 1, 8 do
  195. if usedGroups[i] and i > realGroups then
  196. -- realGroups = numGroups + 1
  197. realGroups = i
  198. end
  199. -- Debug
  200. if not usedGroups[i] and offlineGroups[i] then
  201. Manager:Debug("Group ", i, "is not used because players were offline.")
  202. elseif not usedGroups[i] and zoneGroups[i] then
  203. Manager:Debug("Group ", i, "is not used because players were in wrong zone.")
  204. end
  205. end
  206. else
  207. numGroups = 1
  208. end
  209. return numGroups, realGroups
  210. end
  211.  
  212.  
  213. function Manager:UpdateLayouts(event)
  214. self:Debug("UpdateLayouts", event)
  215.  
  216. local groupType, maxPlayers = Roster:GetPartyState()
  217. local _, _, difficultyIndex, _, _, playerDifficulty, isDynamic = GetInstanceInfo()
  218. local showPets = Layout.db.profile.showPets -- Show Pets
  219. local splitGroups = Layout.db.profile.splitGroups -- Keep Groups Together
  220.  
  221. -- local numGroups, groupFilter = ceil(maxPlayers / 5), "1"
  222. -- for i = 2, numGroups do
  223. -- groupFilter = groupFilter .. "," .. i
  224. -- end
  225. local numGroups = 8
  226. local usedGroups = 8
  227.  
  228. if groupType == "raid" and difficultyIndex == 15 or difficultyIndex == 14 then
  229. numGroups = 6
  230. usedGroups = numGroups
  231. elseif groupType == "raid" and difficultyIndex == 16 then
  232. numGroups = 4
  233. usedGroups = numGroups
  234. elseif groupType == "raid" and difficultyIndex == 17 then
  235. numGroups = 5
  236. usedGroups = numGroups
  237. end
  238.  
  239. self:Debug("maxPlayers", maxPlayers, "numGroups", numGroups, "usedGroups", usedGroups, "showPets", showPets, "splitGroups", splitGroups)
  240.  
  241. if lastNumGroups == numGroups and lastUsedGroups == usedGroups and lastShowPets == showPets then
  242. self:Debug("no changes necessary")
  243. return false
  244. end
  245.  
  246. lastNumGroups = numGroups
  247. lastUsedGroups = usedGroups
  248. lastShowPets = showPets
  249.  
  250. -- Update class and role layouts
  251. --[===[@debug@
  252. if splitGroups then
  253. UpdateSplitGroups(Layouts.ByClass, numGroups, showPets)
  254. UpdateSplitGroups(Layouts.ByRole, numGroups, showPets)
  255. else
  256. --@end-debug@]===]
  257. UpdateMergedGroups(Layouts.ByClass, numGroups, showPets)
  258. UpdateMergedGroups(Layouts.ByRole, numGroups, showPets)
  259. --[===[@debug@
  260. end
  261. --@end-debug@]===]
  262.  
  263. -- By group should always be split group
  264. UpdateSplitGroups(Layouts.ByGroup, usedGroups, showPets)
  265.  
  266. -- Apply changes
  267. Layout:ReloadLayout()
  268.  
  269. return true
  270. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement