Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.55 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. KvaernStyleTwenty = {
  67. name = L["Kvaern Style 20"],
  68. defaults = {
  69. sortMethod = "INDEX",
  70. unitsPerColumn = 5,
  71. maxColumns = 4,
  72. },
  73. [1] = {
  74. groupFilter = "1", -- updated dynamically
  75. },
  76. [2] = {
  77. groupFilter = "2",
  78. },
  79. [3] = {
  80. groupFilter = "3",
  81. },
  82. [4] = {
  83. groupFilter = "4",
  84. },
  85. },
  86. KvaernStyleTen = {
  87. name = L["Kvaern Style 10"],
  88. defaults = {
  89. sortMethod = "INDEX",
  90. unitsPerColumn = 5,
  91. maxColumns = 2,
  92. },
  93. [1] = {
  94. groupFilter = "1", -- updated dynamically
  95. },
  96. [2] = {
  97. groupFilter = "2", -- updated dynamically
  98. },
  99. }
  100. }
  101. --[===[@debug@
  102. GRIDLAYOUTS = Layouts
  103. --@end-debug@]===]
  104.  
  105. --------------------------------------------------------------------------------
  106.  
  107. local Manager = Layout:NewModule("GridLayoutManager", "AceEvent-3.0")
  108. Manager.Debug = Grid.Debug -- GridLayout doesn't have a module prototype
  109.  
  110. function Manager:OnInitialize()
  111. self:Debug("OnInitialize")
  112.  
  113. Grid:SetDebuggingEnabled(self.moduleName)
  114.  
  115. for k, v in pairs(Layouts) do
  116. Layout:AddLayout(k, v)
  117. end
  118.  
  119. self:RegisterMessage("Grid_RosterUpdated", "UpdateLayouts")
  120. end
  121.  
  122. --------------------------------------------------------------------------------
  123.  
  124. local lastNumGroups, lastUsedGroups, lastShowPets
  125.  
  126. local function AddPetGroup(t, numGroups, groupFilter)
  127. t = t or {}
  128. t.groupFilter = groupFilter
  129. t.maxColumns = numGroups
  130.  
  131. t.isPetGroup = true
  132. t.groupBy = "CLASS"
  133. t.groupingOrder = "HUNTER,WARLOCK,MAGE,DEATHKNIGHT,DRUID,PRIEST,SHAMAN,MONK,PALADIN,ROGUE,WARRIOR"
  134. -- t.sortMethod = "NAME"
  135.  
  136. return t
  137. end
  138.  
  139. local function UpdateSplitGroups(layout, numGroups, showPets)
  140. for i = 1, numGroups do
  141. local t = layout[i] or {}
  142. t.groupFilter = tostring(i)
  143. -- Reset attributes from merged layout
  144. t.maxColumns = 1
  145. -- Remove attributes for pet group
  146. t.isPetGroup = nil
  147. t.groupBy = nil
  148. t.groupingOrder = nil
  149. layout[i] = t
  150. end
  151. if showPets then
  152. local i = numGroups + 1
  153. layout[i] = AddPetGroup(layout[i], numGroups, groupFilter)
  154. numGroups = i
  155. end
  156. for i = numGroups + 1, #layout do
  157. layout[i] = nil
  158. end
  159. end
  160.  
  161. local function UpdateMergedGroups(layout, numGroups, showPets)
  162. layout[1].groupFilter = groupFilter
  163. layout[1].maxColumns = numGroups
  164. if showPets then
  165. layout[2] = AddPetGroup(layout[2], numGroups, groupFilter)
  166. else
  167. layout[2] = nil
  168. end
  169. for i = 3, numGroups do
  170. layout[i] = nil
  171. end
  172. end
  173.  
  174. -- These are the number of groups actually used
  175. local function UpdateNumGroups()
  176. local groupType, maxPlayers = Roster:GetPartyState()
  177. local usedGroups = {}
  178. local numGroups = 0
  179. local realGroups = 1
  180. -- local curZone = GetRealZoneText()
  181. -- GetCurrentMapAreaID does not match the mapID from UnitPosition
  182. -- local curMapID = GetCurrentMapAreaID()
  183. local _, _, _, curMapID = UnitPosition("player")
  184. local showOffline = Layout.db.profile.showOffline -- Show Offline groups
  185. -- Debug
  186. local offlineGroups = {}
  187. local zoneGroups = {}
  188. local showWrongZone = Layout:ShowWrongZone()
  189.  
  190. -- Manager:Debug("Layout.db.profile.showWrongZone ", Layout.db.profile.showWrongZone, ", showWrongZone ", showWrongZone, ", groupType ", groupType)
  191.  
  192. if groupType == "raid" or groupType == "bg" then
  193. if maxPlayers then
  194. numGroups = ceil(maxPlayers / 5)
  195. else
  196. numGroups = 1
  197. end
  198.  
  199. for i = 1, 8 do
  200. usedGroups[i] = false
  201. end
  202. for i = 1, GetNumGroupMembers() do
  203. local name, _, subgroup, _, _, _, zone, online = GetRaidRosterInfo(i);
  204. local unitid = "raid" .. i
  205. local _, _, _, mapID = UnitPosition(unitid)
  206. -- If the highest group only has offline players it will not be shown
  207. -- if name and online then
  208. -- usedGroups[subgroup] = true
  209. if name then
  210. -- GetRaidRosterInfo zone comparison can show players in the same instance
  211. -- when they are not. For example, outside Hellfire Citadel still shows
  212. -- "Hellfire Citadel" as the zone text.
  213. -- if (showOffline or online) and (showWrongZone or curZone == zone) then
  214. -- Manager:Debug("curMapID ", curMapID, " name ", name, " mapID ", mapID)
  215. if (showOffline or online) and (showWrongZone or curMapID == mapID) then
  216. usedGroups[subgroup] = true
  217. else
  218. if (not online) then
  219. offlineGroups[subgroup] = true
  220. end
  221. -- if (curZone ~= zone) then
  222. if (curMapID ~= mapID) then
  223. zoneGroups[subgroup] = true
  224. end
  225. end
  226. end
  227. end
  228. for i = 1, 8 do
  229. if usedGroups[i] and i > realGroups then
  230. -- realGroups = numGroups + 1
  231. realGroups = i
  232. end
  233. -- Debug
  234. if not usedGroups[i] and offlineGroups[i] then
  235. Manager:Debug("Group ", i, "is not used because players were offline.")
  236. elseif not usedGroups[i] and zoneGroups[i] then
  237. Manager:Debug("Group ", i, "is not used because players were in wrong zone.")
  238. end
  239. end
  240. else
  241. numGroups = 1
  242. end
  243. return numGroups, realGroups
  244. end
  245.  
  246.  
  247. function Manager:UpdateLayouts(event)
  248. self:Debug("UpdateLayouts", event)
  249.  
  250. local groupType, maxPlayers = Roster:GetPartyState()
  251. local showPets = Layout.db.profile.showPets -- Show Pets
  252. local splitGroups = Layout.db.profile.splitGroups -- Keep Groups Together
  253.  
  254. -- local numGroups, groupFilter = ceil(maxPlayers / 5), "1"
  255. -- for i = 2, numGroups do
  256. -- groupFilter = groupFilter .. "," .. i
  257. -- end
  258. local numGroups = 1
  259. local usedGroups = 1
  260.  
  261. if groupType == "raid" or groupType == "bg" then
  262. numGroups, usedGroups = UpdateNumGroups()
  263. elseif maxPlayers then
  264. numGroups = ceil(maxPlayers / 5)
  265. usedGroups = numGroups
  266. end
  267.  
  268. self:Debug("maxPlayers", maxPlayers, "numGroups", numGroups, "usedGroups", usedGroups, "showPets", showPets, "splitGroups", splitGroups)
  269.  
  270. if lastNumGroups == numGroups and lastUsedGroups == usedGroups and lastShowPets == showPets then
  271. self:Debug("no changes necessary")
  272. return false
  273. end
  274.  
  275. lastNumGroups = numGroups
  276. lastUsedGroups = usedGroups
  277. lastShowPets = showPets
  278.  
  279. -- Update class and role layouts
  280. if splitGroups then
  281. UpdateSplitGroups(Layouts.ByClass, numGroups, showPets)
  282. UpdateSplitGroups(Layouts.ByRole, numGroups, showPets)
  283. else
  284. UpdateMergedGroups(Layouts.ByClass, numGroups, showPets)
  285. UpdateMergedGroups(Layouts.ByRole, numGroups, showPets)
  286. end
  287.  
  288. -- By group should always be split group
  289. UpdateSplitGroups(Layouts.ByGroup, usedGroups, showPets)
  290.  
  291. -- Apply changes
  292. Layout:ReloadLayout()
  293.  
  294. return true
  295. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement