Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.49 KB | None | 0 0
  1. --[[--------------------------------------------------------------------
  2. Grid
  3. Compact party and raid unit frames.
  4. Copyright (c) 2006-2014 Kyle Smith (Pastamancer), Phanx
  5. All rights reserved.
  6. See the accompanying README and LICENSE files for more information.
  7. http://www.wowinterface.com/downloads/info5747-Grid.html
  8. http://www.wowace.com/addons/grid/
  9. http://www.curse.com/addons/wow/grid
  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,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,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 showPets = Layout.db.profile.showPets -- Show Pets
  218. local splitGroups = Layout.db.profile.splitGroups -- Keep Groups Together
  219.  
  220. -- local numGroups, groupFilter = ceil(maxPlayers / 5), "1"
  221. -- for i = 2, numGroups do
  222. -- groupFilter = groupFilter .. "," .. i
  223. -- end
  224. local numGroups = 1
  225. local usedGroups = 1
  226.  
  227. if groupType == "raid" or groupType == "bg" then
  228. numGroups, usedGroups = UpdateNumGroups()
  229. elseif maxPlayers then
  230. numGroups = ceil(maxPlayers / 5)
  231. usedGroups = numGroups
  232. end
  233.  
  234. self:Debug("maxPlayers", maxPlayers, "numGroups", numGroups, "usedGroups", usedGroups, "showPets", showPets, "splitGroups", splitGroups)
  235.  
  236. if lastNumGroups == numGroups and lastUsedGroups == usedGroups and lastShowPets == showPets then
  237. self:Debug("no changes necessary")
  238. return false
  239. end
  240.  
  241. lastNumGroups = numGroups
  242. lastUsedGroups = usedGroups
  243. lastShowPets = showPets
  244.  
  245. -- Update class and role layouts
  246. if splitGroups then
  247. UpdateSplitGroups(Layouts.ByClass, numGroups, showPets)
  248. UpdateSplitGroups(Layouts.ByRole, numGroups, showPets)
  249. else
  250. UpdateMergedGroups(Layouts.ByClass, numGroups, showPets)
  251. UpdateMergedGroups(Layouts.ByRole, numGroups, showPets)
  252. end
  253.  
  254. -- By group should always be split group
  255. UpdateSplitGroups(Layouts.ByGroup, usedGroups, showPets)
  256.  
  257. -- Apply changes
  258. Layout:ReloadLayout()
  259.  
  260. return true
  261. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement