Blizzard_CompactRaidFrames/Blizzard_CompactRaidFrameManager.lua

Blizzard_CompactRaidFrames/Blizzard_CompactRaidFrameManager.lua (8.3.7.35662; unchanged since 7.2.5.24330)
  1. NUM_WORLD_RAID_MARKERS = 8;
  2. NUM_RAID_ICONS = 8;
  3. WORLD_RAID_MARKER_ORDER = {};
  4. WORLD_RAID_MARKER_ORDER[1] = 8;
  5. WORLD_RAID_MARKER_ORDER[2] = 4;
  6. WORLD_RAID_MARKER_ORDER[3] = 1;
  7. WORLD_RAID_MARKER_ORDER[4] = 7;
  8. WORLD_RAID_MARKER_ORDER[5] = 2;
  9. WORLD_RAID_MARKER_ORDER[6] = 3;
  10. WORLD_RAID_MARKER_ORDER[7] = 6;
  11. WORLD_RAID_MARKER_ORDER[8] = 5;
  12. MINIMUM_RAID_CONTAINER_HEIGHT = 72;
  13. local RESIZE_HORIZONTAL_OUTSETS = 4;
  14. local RESIZE_VERTICAL_OUTSETS = 7;
  15. function CompactRaidFrameManager_OnLoad(self)
  16. self:SetBackdropColor(TOOLTIP_DEFAULT_BACKGROUND_COLOR.r, TOOLTIP_DEFAULT_BACKGROUND_COLOR.g, TOOLTIP_DEFAULT_BACKGROUND_COLOR.b);
  17. self.container = CompactRaidFrameContainer;
  18. self.container:SetParent(self);
  19. self:RegisterEvent("DISPLAY_SIZE_CHANGED");
  20. self:RegisterEvent("UI_SCALE_CHANGED");
  21. self:RegisterEvent("GROUP_ROSTER_UPDATE");
  22. self:RegisterEvent("UPDATE_ACTIVE_BATTLEFIELD");
  23. self:RegisterEvent("UNIT_FLAGS");
  24. self:RegisterEvent("PLAYER_FLAGS_CHANGED");
  25. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  26. self:RegisterEvent("PARTY_LEADER_CHANGED");
  27. self:RegisterEvent("RAID_TARGET_UPDATE");
  28. self:RegisterEvent("PLAYER_TARGET_CHANGED");
  29. self.containerResizeFrame:SetMinResize(self.container:GetWidth(), MINIMUM_RAID_CONTAINER_HEIGHT + RESIZE_VERTICAL_OUTSETS * 2 + 1);
  30. self.dynamicContainerPosition = true;
  31. CompactRaidFrameContainer_SetFlowFilterFunction(self.container, CRFFlowFilterFunc)
  32. CompactRaidFrameContainer_SetGroupFilterFunction(self.container, CRFGroupFilterFunc)
  33. CompactRaidFrameManager_UpdateContainerBounds(self);
  34. CompactRaidFrameManager_ResizeFrame_Reanchor(self);
  35. CompactRaidFrameManager_AttachPartyFrames(self);
  36. CompactRaidFrameManager_Collapse(self);
  37. --Set up the options flow container
  38. FlowContainer_Initialize(self.displayFrame.optionsFlowContainer);
  39. end
  40. local settings = { --[["Managed",]] "Locked", "SortMode", "KeepGroupsTogether", "DisplayPets", "DisplayMainTankAndAssist", "IsShown", "ShowBorders" };
  41. function CompactRaidFrameManager_OnEvent(self, event, ...)
  42. if ( event == "DISPLAY_SIZE_CHANGED" or event == "UI_SCALE_CHANGED" ) then
  43. CompactRaidFrameManager_UpdateContainerBounds(self);
  44. elseif ( event == "GROUP_ROSTER_UPDATE" or event == "UPDATE_ACTIVE_BATTLEFIELD" ) then
  45. CompactRaidFrameManager_UpdateShown(self);
  46. CompactRaidFrameManager_UpdateDisplayCounts(self);
  47. CompactRaidFrameManager_UpdateLabel(self);
  48. CompactRaidFrameManager_UpdateContainerLockVisibility(self);
  49. elseif ( event == "UNIT_FLAGS" or event == "PLAYER_FLAGS_CHANGED" ) then
  50. CompactRaidFrameManager_UpdateDisplayCounts(self);
  51. elseif ( event == "PLAYER_ENTERING_WORLD" ) then
  52. CompactRaidFrameManager_UpdateShown(self);
  53. CompactRaidFrameManager_UpdateDisplayCounts(self);
  54. CompactRaidFrameManager_UpdateOptionsFlowContainer(self);
  55. CompactRaidFrameManager_UpdateRaidIcons();
  56. elseif ( event == "PARTY_LEADER_CHANGED" ) then
  57. CompactRaidFrameManager_UpdateOptionsFlowContainer(self);
  58. elseif ( event == "RAID_TARGET_UPDATE" ) then
  59. CompactRaidFrameManager_UpdateRaidIcons();
  60. elseif ( event == "PLAYER_TARGET_CHANGED" ) then
  61. CompactRaidFrameManager_UpdateRaidIcons();
  62. end
  63. end
  64. function CompactRaidFrameManagerDisplayFrameProfileSelector_SetUp(self)
  65. UIDropDownMenu_SetWidth(self, 165);
  66. UIDropDownMenu_Initialize(self, CompactRaidFrameManagerDisplayFrameProfileSelector_Initialize);
  67. end
  68. function CompactRaidFrameManagerDisplayFrameProfileSelector_Initialize()
  69. local info = UIDropDownMenu_CreateInfo();
  70. for i=1, GetNumRaidProfiles() do
  71. local name = GetRaidProfileName(i);
  72. info.text = name;
  73. info.value = name;
  74. info.func = CompactRaidFrameManagerDisplayFrameProfileSelector_OnClick;
  75. info.checked = GetActiveRaidProfile() == info.value;
  76. UIDropDownMenu_AddButton(info);
  77. end
  78. end
  79. function CompactRaidFrameManagerDisplayFrameProfileSelector_OnClick(self)
  80. local profile = self.value;
  81. CompactUnitFrameProfiles_ActivateRaidProfile(profile);
  82. end
  83. function CompactRaidFrameManager_UpdateShown(self)
  84. if ( GetDisplayedAllyFrames() ) then
  85. self:Show();
  86. else
  87. self:Hide();
  88. end
  89. CompactRaidFrameManager_UpdateOptionsFlowContainer(self);
  90. CompactRaidFrameManager_UpdateContainerVisibility();
  91. end
  92. function CompactRaidFrameManager_UpdateLabel(self)
  93. if ( IsInRaid() ) then
  94. self.displayFrame.label:SetText(RAID_MEMBERS);
  95. else
  96. self.displayFrame.label:SetText(PARTY_MEMBERS);
  97. end
  98. end
  99. function CompactRaidFrameManager_Toggle(self)
  100. if ( self.collapsed ) then
  101. CompactRaidFrameManager_Expand(self);
  102. else
  103. CompactRaidFrameManager_Collapse(self);
  104. end
  105. end
  106. function CompactRaidFrameManager_Expand(self)
  107. self.collapsed = false;
  108. self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", -7, -140);
  109. self.displayFrame:Show();
  110. self.toggleButton:GetNormalTexture():SetTexCoord(0.5, 1, 0, 1);
  111. end
  112. function CompactRaidFrameManager_Collapse(self)
  113. self.collapsed = true;
  114. self:SetPoint("TOPLEFT", UIParent, "TOPLEFT", -182, -140);
  115. self.displayFrame:Hide();
  116. self.toggleButton:GetNormalTexture():SetTexCoord(0, 0.5, 0, 1);
  117. end
  118. function CompactRaidFrameManager_UpdateOptionsFlowContainer(self)
  119. local container = self.displayFrame.optionsFlowContainer;
  120. FlowContainer_RemoveAllObjects(container);
  121. FlowContainer_PauseUpdates(container);
  122. if ( GetDisplayedAllyFrames() == "raid" ) then
  123. FlowContainer_AddObject(container, self.displayFrame.profileSelector);
  124. self.displayFrame.profileSelector:Show();
  125. else
  126. self.displayFrame.profileSelector:Hide();
  127. end
  128. if ( IsInRaid() ) then
  129. FlowContainer_AddObject(container, self.displayFrame.filterOptions);
  130. self.displayFrame.filterOptions:Show();
  131. else
  132. self.displayFrame.filterOptions:Hide();
  133. end
  134. if ( not IsInRaid() or UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") ) then
  135. FlowContainer_AddObject(container, self.displayFrame.raidMarkers);
  136. self.displayFrame.raidMarkers:Show();
  137. else
  138. self.displayFrame.raidMarkers:Hide();
  139. end
  140. if ( not IsInRaid() or UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") ) then
  141. FlowContainer_AddObject(container, self.displayFrame.leaderOptions);
  142. self.displayFrame.leaderOptions:Show();
  143. else
  144. self.displayFrame.leaderOptions:Hide();
  145. end
  146. if ( not IsInRaid() and UnitIsGroupLeader("player") and not HasLFGRestrictions() ) then
  147. FlowContainer_AddLineBreak(container);
  148. FlowContainer_AddSpacer(container, 20);
  149. FlowContainer_AddObject(container, self.displayFrame.convertToRaid);
  150. self.displayFrame.convertToRaid:Show();
  151. else
  152. self.displayFrame.convertToRaid:Hide();
  153. end
  154. if ( GetDisplayedAllyFrames() == "raid" ) then
  155. FlowContainer_AddLineBreak(container);
  156. FlowContainer_AddSpacer(container, 20);
  157. FlowContainer_AddObject(container, self.displayFrame.lockedModeToggle);
  158. FlowContainer_AddObject(container, self.displayFrame.hiddenModeToggle);
  159. self.displayFrame.lockedModeToggle:Show();
  160. self.displayFrame.hiddenModeToggle:Show();
  161. else
  162. self.displayFrame.lockedModeToggle:Hide();
  163. self.displayFrame.hiddenModeToggle:Hide();
  164. end
  165. if ( IsInRaid() and UnitIsGroupLeader("player") ) then
  166. FlowContainer_AddLineBreak(container);
  167. FlowContainer_AddSpacer(container, 20);
  168. FlowContainer_AddObject(container, self.displayFrame.everyoneIsAssistButton);
  169. self.displayFrame.everyoneIsAssistButton:Show();
  170. else
  171. self.displayFrame.everyoneIsAssistButton:Hide();
  172. end
  173. FlowContainer_ResumeUpdates(container);
  174. local usedX, usedY = FlowContainer_GetUsedBounds(container);
  175. self:SetHeight(usedY + 40);
  176. --Then, we update which specific buttons are enabled.
  177. --Raid leaders and assistants and leaders of non-dungeon finder parties may initiate a role poll.
  178. if ( IsInGroup() and not HasLFGRestrictions() and (UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")) ) then
  179. self.displayFrame.leaderOptions.rolePollButton:Enable();
  180. self.displayFrame.leaderOptions.rolePollButton:SetAlpha(1);
  181. else
  182. self.displayFrame.leaderOptions.rolePollButton:Disable();
  183. self.displayFrame.leaderOptions.rolePollButton:SetAlpha(0.5);
  184. end
  185. --Any sort of leader may initiate a ready check.
  186. if ( IsInGroup() and (UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")) ) then
  187. self.displayFrame.leaderOptions.readyCheckButton:Enable();
  188. self.displayFrame.leaderOptions.readyCheckButton:SetAlpha(1);
  189. else
  190. self.displayFrame.leaderOptions.readyCheckButton:Disable();
  191. self.displayFrame.leaderOptions.readyCheckButton:SetAlpha(0.5);
  192. end
  193. end
  194. local function RaidWorldMarker_OnClick(self, arg1, arg2, checked)
  195. if ( checked ) then
  196. ClearRaidMarker(arg1);
  197. else
  198. PlaceRaidMarker(arg1);
  199. end
  200. end
  201. local function ClearRaidWorldMarker_OnClick(self, arg1, arg2, checked)
  202. ClearRaidMarker();
  203. end
  204. function CRFManager_RaidWorldMarkerDropDown_Update()
  205. local info = UIDropDownMenu_CreateInfo();
  206. info.isNotRadio = true;
  207. for i=1, NUM_WORLD_RAID_MARKERS do
  208. local index = WORLD_RAID_MARKER_ORDER[i];
  209. info.text = _G["WORLD_MARKER"..index];
  210. info.func = RaidWorldMarker_OnClick;
  211. info.checked = IsRaidMarkerActive(index);
  212. info.arg1 = index;
  213. UIDropDownMenu_AddButton(info);
  214. end
  215. info.notCheckable = 1;
  216. info.text = REMOVE_WORLD_MARKERS;
  217. info.func = ClearRaidWorldMarker_OnClick;
  218. info.arg1 = nil; --Remove everything
  219. UIDropDownMenu_AddButton(info);
  220. end
  221. function CompactRaidFrameManager_UpdateDisplayCounts(self)
  222. CRF_CountStuff();
  223. CompactRaidFrameManager_UpdateHeaderInfo(self);
  224. CompactRaidFrameManager_UpdateFilterInfo(self)
  225. end
  226. function CompactRaidFrameManager_UpdateHeaderInfo(self)
  227. self.displayFrame.memberCountLabel:SetFormattedText("%d/%d", RaidInfoCounts.totalAlive, RaidInfoCounts.totalCount);
  228. end
  229. local usedGroups = {};
  230. function CompactRaidFrameManager_UpdateFilterInfo(self)
  231. CompactRaidFrameManager_UpdateRoleFilterButton(self.displayFrame.filterOptions.filterRoleTank);
  232. CompactRaidFrameManager_UpdateRoleFilterButton(self.displayFrame.filterOptions.filterRoleHealer);
  233. CompactRaidFrameManager_UpdateRoleFilterButton(self.displayFrame.filterOptions.filterRoleDamager);
  234. RaidUtil_GetUsedGroups(usedGroups);
  235. for i=1, MAX_RAID_GROUPS do
  236. CompactRaidFrameManager_UpdateGroupFilterButton(self.displayFrame.filterOptions["filterGroup"..i], usedGroups);
  237. end
  238. end
  239. function CompactRaidFrameManager_UpdateRoleFilterButton(button)
  240. local totalAlive, totalCount = RaidInfoCounts["aliveRole"..button.role], RaidInfoCounts["totalRole"..button.role]
  241. button:SetFormattedText("%s %d/%d", button.roleTexture, totalAlive, totalCount);
  242. local keepGroupsTogether = CompactRaidFrameManager_GetSetting("KeepGroupsTogether");
  243. keepGroupsTogether = keepGroupsTogether and keepGroupsTogether ~= "0";
  244. if ( totalCount == 0 or keepGroupsTogether ) then
  245. button.selectedHighlight:Hide();
  246. button:Disable();
  247. button:SetAlpha(0.5);
  248. else
  249. button:Enable();
  250. button:SetAlpha(1);
  251. local isFiltered = CRF_GetFilterRole(button.role)
  252. if ( isFiltered ) then
  253. button.selectedHighlight:Show();
  254. else
  255. button.selectedHighlight:Hide();
  256. end
  257. end
  258. end
  259. function CompactRaidFrameManager_ToggleRoleFilter(role)
  260. CRF_SetFilterRole(role, not CRF_GetFilterRole(role));
  261. CompactRaidFrameManager_UpdateFilterInfo(CompactRaidFrameManager);
  262. CompactRaidFrameContainer_TryUpdate(CompactRaidFrameContainer);
  263. end
  264. function CompactRaidFrameManager_UpdateGroupFilterButton(button, usedGroups)
  265. local group = button:GetID();
  266. if ( usedGroups[group] ) then
  267. button:Enable();
  268. button:SetAlpha(1);
  269. local isFiltered = CRF_GetFilterGroup(group);
  270. if ( isFiltered ) then
  271. button.selectedHighlight:Show();
  272. else
  273. button.selectedHighlight:Hide();
  274. end
  275. else
  276. button.selectedHighlight:Hide();
  277. button:Disable();
  278. button:SetAlpha(0.5);
  279. end
  280. end
  281. function CompactRaidFrameManager_ToggleGroupFilter(group)
  282. CRF_SetFilterGroup(group, not CRF_GetFilterGroup(group));
  283. CompactRaidFrameManager_UpdateFilterInfo(CompactRaidFrameManager);
  284. CompactRaidFrameContainer_TryUpdate(CompactRaidFrameContainer);
  285. end
  286. function CompactRaidFrameManager_UpdateRaidIcons()
  287. local unit = "target";
  288. local disableAll = not CanBeRaidTarget(unit);
  289. for i=1, NUM_RAID_ICONS do
  290. local button = _G["CompactRaidFrameManagerDisplayFrameRaidMarkersRaidMarker"..i]; --.... /cry
  291. if ( disableAll or button:GetID() == GetRaidTargetIndex(unit) ) then
  292. button:GetNormalTexture():SetDesaturated(true);
  293. button:SetAlpha(0.7);
  294. button:Disable();
  295. else
  296. button:GetNormalTexture():SetDesaturated(false);
  297. button:SetAlpha(1);
  298. button:Enable();
  299. end
  300. end
  301. local removeButton = CompactRaidFrameManagerDisplayFrameRaidMarkersRaidMarkerRemove;
  302. if ( not GetRaidTargetIndex(unit) ) then
  303. removeButton:GetNormalTexture():SetDesaturated(true);
  304. removeButton:Disable();
  305. else
  306. removeButton:GetNormalTexture():SetDesaturated(false);
  307. removeButton:Enable();
  308. end
  309. end
  310. --Settings stuff
  311. local cachedSettings = {};
  312. local isSettingCached = {};
  313. function CompactRaidFrameManager_GetSetting(settingName)
  314. if ( not isSettingCached[settingName] ) then
  315. cachedSettings[settingName] = CompactRaidFrameManager_GetSettingBeforeLoad(settingName);
  316. isSettingCached[settingName] = true;
  317. end
  318. return cachedSettings[settingName];
  319. end
  320. function CompactRaidFrameManager_GetSettingBeforeLoad(settingName)
  321. if ( settingName == "Managed" ) then
  322. return true;
  323. elseif ( settingName == "Locked" ) then
  324. return true;
  325. elseif ( settingName == "SortMode" ) then
  326. return "role";
  327. elseif ( settingName == "KeepGroupsTogether" ) then
  328. return false;
  329. elseif ( settingName == "DisplayPets" ) then
  330. return false;
  331. elseif ( settingName == "DisplayMainTankAndAssist" ) then
  332. return true;
  333. elseif ( settingName == "IsShown" ) then
  334. return true;
  335. elseif ( settingName == "ShowBorders" ) then
  336. return true;
  337. elseif ( settingName == "HorizontalGroups" ) then
  338. return false;
  339. else
  340. GMError("Unknown setting "..tostring(settingName));
  341. end
  342. end
  343. do --Enclosure to make sure people go through SetSetting
  344. local function CompactRaidFrameManager_SetManaged(value)
  345. local container = CompactRaidFrameManager.container;
  346. end
  347. local function CompactRaidFrameManager_SetLocked(value)
  348. local manager = CompactRaidFrameManager;
  349. if ( value and value ~= "0" ) then
  350. CompactRaidFrameManagerDisplayFrameLockedModeToggle:SetText(UNLOCK);
  351. CompactRaidFrameManagerDisplayFrameLockedModeToggle.lockMode = false;
  352. CompactRaidFrameManager_UpdateContainerLockVisibility(manager);
  353. else
  354. CompactRaidFrameManagerDisplayFrameLockedModeToggle:SetText(LOCK);
  355. CompactRaidFrameManagerDisplayFrameLockedModeToggle.lockMode = true;
  356. CompactRaidFrameManager_UpdateContainerLockVisibility(manager);
  357. end
  358. end
  359. local function CompactRaidFrameManager_SetSortMode(value)
  360. local manager = CompactRaidFrameManager;
  361. if ( value == "group" ) then
  362. CompactRaidFrameContainer_SetFlowSortFunction(manager.container, CRFSort_Group);
  363. elseif ( value == "role" ) then
  364. CompactRaidFrameContainer_SetFlowSortFunction(manager.container, CRFSort_Role);
  365. elseif ( value == "alphabetical" ) then
  366. CompactRaidFrameContainer_SetFlowSortFunction(manager.container, CRFSort_Alphabetical);
  367. else
  368. CompactRaidFrameManager_SetSetting("SortMode", "role");
  369. GMError("Unknown sort mode: "..tostring(value));
  370. end
  371. end
  372. local function CompactRaidFrameManager_SetKeepGroupsTogether(value)
  373. local manager = CompactRaidFrameManager;
  374. local groupMode;
  375. if ( not value or value == "0" ) then
  376. groupMode = "flush";
  377. else
  378. groupMode = "discrete";
  379. end
  380. CompactRaidFrameContainer_SetGroupMode(manager.container, groupMode);
  381. CompactRaidFrameManager_UpdateFilterInfo(manager);
  382. end
  383. local function CompactRaidFrameManager_SetDisplayPets(value)
  384. local container = CompactRaidFrameManager.container;
  385. local displayPets;
  386. if ( value and value ~= "0" ) then
  387. displayPets = true;
  388. end
  389. CompactRaidFrameContainer_SetDisplayPets(container, displayPets);
  390. end
  391. local function CompactRaidFrameManager_SetDisplayMainTankAndAssist(value)
  392. local container = CompactRaidFrameManager.container;
  393. local displayFlaggedMembers;
  394. if ( value and value ~= "0" ) then
  395. displayFlaggedMembers = true;
  396. end
  397. CompactRaidFrameContainer_SetDisplayMainTankAndAssist(container, displayFlaggedMembers);
  398. end
  399. local function CompactRaidFrameManager_SetIsShown(value)
  400. local manager = CompactRaidFrameManager;
  401. if ( value and value ~= "0" ) then
  402. manager.container.enabled = true;
  403. CompactRaidFrameManagerDisplayFrameHiddenModeToggle:SetText(HIDE);
  404. CompactRaidFrameManagerDisplayFrameHiddenModeToggle.shownMode = false;
  405. else
  406. manager.container.enabled = false;
  407. CompactRaidFrameManagerDisplayFrameHiddenModeToggle:SetText(SHOW);
  408. CompactRaidFrameManagerDisplayFrameHiddenModeToggle.shownMode = true;
  409. end
  410. CompactRaidFrameManager_UpdateContainerVisibility();
  411. end
  412. local function CompactRaidFrameManager_SetBorderShown(value)
  413. local manager = CompactRaidFrameManager;
  414. local showBorder;
  415. if ( value and value ~= "0" ) then
  416. showBorder = true;
  417. end
  418. CUF_SHOW_BORDER = showBorder;
  419. CompactRaidFrameContainer_SetBorderShown(manager.container, showBorder);
  420. end
  421. local function CompactRaidFrameManager_SetHorizontalGroups(value)
  422. local horizontalGroups;
  423. if ( value and value ~= "0" ) then
  424. horizontalGroups = true;
  425. end
  426. CUF_HORIZONTAL_GROUPS = horizontalGroups;
  427. end
  428. function CompactRaidFrameManager_SetSetting(settingName, value)
  429. cachedSettings[settingName] = value;
  430. isSettingCached[settingName] = true;
  431. --Perform the actual functions
  432. if ( settingName == "Managed" ) then
  433. CompactRaidFrameManager_SetManaged(value);
  434. elseif ( settingName == "Locked" ) then
  435. CompactRaidFrameManager_SetLocked(value);
  436. elseif ( settingName == "SortMode" ) then
  437. CompactRaidFrameManager_SetSortMode(value);
  438. elseif ( settingName == "KeepGroupsTogether" ) then
  439. CompactRaidFrameManager_SetKeepGroupsTogether(value);
  440. elseif ( settingName == "DisplayPets" ) then
  441. CompactRaidFrameManager_SetDisplayPets(value);
  442. elseif ( settingName == "DisplayMainTankAndAssist" ) then
  443. CompactRaidFrameManager_SetDisplayMainTankAndAssist(value);
  444. elseif ( settingName == "IsShown" ) then
  445. CompactRaidFrameManager_SetIsShown(value);
  446. elseif ( settingName == "ShowBorders" ) then
  447. CompactRaidFrameManager_SetBorderShown(value);
  448. elseif ( settingName == "HorizontalGroups" ) then
  449. CompactRaidFrameManager_SetHorizontalGroups(value);
  450. else
  451. GMError("Unknown setting "..tostring(settingName));
  452. end
  453. end
  454. end
  455. function CompactRaidFrameManager_UpdateContainerVisibility()
  456. local manager = CompactRaidFrameManager;
  457. if ( GetDisplayedAllyFrames() == "raid" and manager.container.enabled ) then
  458. manager.container:Show();
  459. else
  460. manager.container:Hide();
  461. end
  462. end
  463. function CompactRaidFrameManager_AttachPartyFrames(manager)
  464. PartyMemberFrame1:ClearAllPoints();
  465. PartyMemberFrame1:SetPoint("TOPLEFT", manager, "TOPRIGHT", 0, -20);
  466. end
  467. function CompactRaidFrameManager_ResetContainerPosition()
  468. local manager = CompactRaidFrameManager;
  469. manager.dynamicContainerPosition = true;
  470. CompactRaidFrameManager_UpdateContainerBounds(manager);
  471. CompactRaidFrameManager_ResizeFrame_SavePosition(manager);
  472. end
  473. function CompactRaidFrameManager_UpdateContainerBounds(self) --Hah, "Bounds" instead of "SizeAndPosition". WHO NEEDS A THESAURUS NOW?!
  474. self.containerResizeFrame:SetMaxResize(self.containerResizeFrame:GetWidth(), GetScreenHeight() - 90);
  475. if ( self.dynamicContainerPosition ) then
  476. --Should be below the TargetFrameSpellBar at its lowest height..
  477. local top = GetScreenHeight() - 135;
  478. --Should be just above the FriendsFrameMicroButton.
  479. local bottom = 330;
  480. local managerTop = self:GetTop();
  481. self.containerResizeFrame:ClearAllPoints();
  482. self.containerResizeFrame:SetPoint("TOPLEFT", self, "TOPRIGHT", 0, top - managerTop);
  483. self.containerResizeFrame:SetHeight(top - bottom);
  484. CompactRaidFrameManager_ResizeFrame_UpdateContainerSize(self);
  485. end
  486. end
  487. function CompactRaidFrameManager_UpdateContainerLockVisibility(self)
  488. if ( GetDisplayedAllyFrames() ~= "raid" or not CompactRaidFrameManagerDisplayFrameLockedModeToggle.lockMode ) then
  489. CompactRaidFrameManager_LockContainer(self);
  490. else
  491. CompactRaidFrameManager_UnlockContainer(self);
  492. end
  493. end
  494. function CompactRaidFrameManager_LockContainer(self)
  495. self.containerResizeFrame:Hide();
  496. end
  497. function CompactRaidFrameManager_UnlockContainer(self)
  498. self.containerResizeFrame:Show();
  499. end
  500. --ResizeFrame related functions
  501. function CompactRaidFrameManager_ResizeFrame_Reanchor(manager)
  502. manager.container:SetPoint("TOPLEFT", manager.containerResizeFrame, "TOPLEFT", RESIZE_HORIZONTAL_OUTSETS, -RESIZE_VERTICAL_OUTSETS);
  503. end
  504. function CompactRaidFrameManager_ResizeFrame_OnDragStart(manager)
  505. manager.dynamicContainerPosition = false;
  506. manager.containerResizeFrame:StartMoving();
  507. end
  508. function CompactRaidFrameManager_ResizeFrame_OnDragStop(manager)
  509. manager.containerResizeFrame:StopMovingOrSizing();
  510. CompactRaidFrameManager_ResizeFrame_CheckMagnetism(manager);
  511. CompactRaidFrameManager_ResizeFrame_SavePosition(manager);
  512. end
  513. function CompactRaidFrameManager_ResizeFrame_OnResizeStart(manager)
  514. manager.dynamicContainerPosition = false;
  515. manager.containerResizeFrame:StartSizing("BOTTOM")
  516. manager.containerResizeFrame:SetScript("OnUpdate", CompactRaidFrameManager_ResizeFrame_OnUpdate);
  517. end
  518. function CompactRaidFrameManager_ResizeFrame_OnResizeStop(manager)
  519. manager.containerResizeFrame:StopMovingOrSizing();
  520. manager.containerResizeFrame:SetScript("OnUpdate", nil);
  521. CompactRaidFrameManager_ResizeFrame_UpdateContainerSize(manager);
  522. CompactRaidFrameManager_ResizeFrame_CheckMagnetism(manager);
  523. CompactRaidFrameManager_ResizeFrame_SavePosition(manager);
  524. end
  525. local RESIZE_UPDATE_INTERVAL = 0.5;
  526. function CompactRaidFrameManager_ResizeFrame_OnUpdate(self, elapsed)
  527. self.timeSinceUpdate = (self.timeSinceUpdate or 0) + elapsed;
  528. if ( self.timeSinceUpdate >= RESIZE_UPDATE_INTERVAL ) then
  529. local manager = self:GetParent();
  530. CompactRaidFrameManager_ResizeFrame_UpdateContainerSize(manager);
  531. CompactRaidFrameManager_ResizeFrame_CheckMagnetism(manager);
  532. CompactRaidFrameManager_ResizeFrame_SavePosition(manager);
  533. end
  534. end
  535. function CompactRaidFrameManager_ResizeFrame_UpdateContainerSize(manager)
  536. --If we're flow style, we want to make sure we exactly fit N frames.
  537. local keepGroupsTogether = CompactRaidFrameManager_GetSetting("KeepGroupsTogether");
  538. if ( keepGroupsTogether ~= "1" ) then
  539. local unitFrameHeight = DefaultCompactUnitFrameSetupOptions.height;
  540. local resizerHeight = manager.containerResizeFrame:GetHeight() - RESIZE_VERTICAL_OUTSETS * 2;
  541. local newHeight = unitFrameHeight * floor(resizerHeight / unitFrameHeight);
  542. manager.container:SetHeight(newHeight);
  543. else
  544. manager.container:SetHeight(manager.containerResizeFrame:GetHeight() - RESIZE_VERTICAL_OUTSETS * 2);
  545. end
  546. end
  547. local MAGNETIC_FIELD_RANGE = 10;
  548. function CompactRaidFrameManager_ResizeFrame_CheckMagnetism(manager)
  549. if ( abs(manager.containerResizeFrame:GetLeft() - manager:GetRight()) < MAGNETIC_FIELD_RANGE and
  550. manager.containerResizeFrame:GetTop() > manager:GetBottom() and manager.containerResizeFrame:GetBottom() < manager:GetTop() ) then
  551. manager.containerResizeFrame:ClearAllPoints();
  552. manager.containerResizeFrame:SetPoint("TOPLEFT", manager, "TOPRIGHT", 0, manager.containerResizeFrame:GetTop() - manager:GetTop());
  553. end
  554. end
  555. function CompactRaidFrameManager_ResizeFrame_SavePosition(manager)
  556. if ( manager.dynamicContainerPosition ) then
  557. SetRaidProfileSavedPosition(GetActiveRaidProfile(), true);
  558. return;
  559. end
  560. --The stuff we're actually saving
  561. local topPoint, topOffset;
  562. local bottomPoint, bottomOffset;
  563. local leftPoint, leftOffset;
  564. local screenHeight = GetScreenHeight();
  565. local top = manager.containerResizeFrame:GetTop();
  566. if ( top > screenHeight / 2 ) then
  567. topPoint = "TOP";
  568. topOffset = screenHeight - top;
  569. else
  570. topPoint = "BOTTOM";
  571. topOffset = top;
  572. end
  573. local bottom = manager.containerResizeFrame:GetBottom();
  574. if ( bottom > screenHeight / 2 ) then
  575. bottomPoint = "TOP";
  576. bottomOffset = screenHeight - bottom;
  577. else
  578. bottomPoint = "BOTTOM";
  579. bottomOffset = bottom;
  580. end
  581. local isAttached = (select(2, manager.containerResizeFrame:GetPoint(1)) == manager);
  582. if ( isAttached ) then
  583. leftPoint = "ATTACHED";
  584. leftOffset = 0;
  585. else
  586. local screenWidth = GetScreenWidth();
  587. local left = manager.containerResizeFrame:GetLeft();
  588. if ( left > screenWidth / 2 ) then
  589. leftPoint = "RIGHT";
  590. leftOffset = screenWidth - left;
  591. else
  592. leftPoint = "LEFT";
  593. leftOffset = left;
  594. end
  595. end
  596. SetRaidProfileSavedPosition(GetActiveRaidProfile(), false, topPoint, topOffset, bottomPoint, bottomOffset, leftPoint, leftOffset);
  597. end
  598. function CompactRaidFrameManager_ResizeFrame_LoadPosition(manager)
  599. local dynamic, topPoint, topOffset, bottomPoint, bottomOffset, leftPoint, leftOffset = GetRaidProfileSavedPosition(GetActiveRaidProfile());
  600. if ( dynamic ) then --We are automatically placed.
  601. manager.dynamicContainerPosition = true;
  602. CompactRaidFrameManager_UpdateContainerBounds(manager);
  603. return;
  604. else
  605. manager.dynamicContainerPosition = false;
  606. end
  607. --First, let's clear the container's current anchors.
  608. manager.containerResizeFrame:ClearAllPoints();
  609. local top;
  610. if ( topPoint == "TOP" ) then
  611. top = GetScreenHeight() - topOffset;
  612. else
  613. top = topOffset;
  614. end
  615. local bottom;
  616. if ( bottomPoint == "TOP" ) then
  617. bottom = GetScreenHeight() - bottomOffset;
  618. else
  619. bottom = bottomOffset
  620. end
  621. local height = top - bottom;
  622. height = max(height, MINIMUM_RAID_CONTAINER_HEIGHT);
  623. top = max(top, height);
  624. manager.containerResizeFrame:SetHeight(height);
  625. if ( leftPoint == "ATTACHED" ) then
  626. manager.containerResizeFrame:SetPoint("TOPLEFT", manager, "TOPRIGHT", 0, top - manager:GetTop());
  627. else
  628. local left;
  629. if ( leftPoint == "RIGHT" ) then
  630. left = GetScreenWidth() - leftOffset;
  631. else
  632. left = leftOffset;
  633. end
  634. manager.containerResizeFrame:SetPoint("TOPLEFT", nil, "BOTTOMLEFT", left, top);
  635. end
  636. CompactRaidFrameManager_ResizeFrame_UpdateContainerSize(manager);
  637. end
  638. -------------Utility functions-------------
  639. --Functions used for sorting and such
  640. function CRFSort_Group(token1, token2)
  641. if ( IsInRaid() ) then
  642. local id1 = tonumber(string.sub(token1, 5));
  643. local id2 = tonumber(string.sub(token2, 5));
  644. if ( not id1 or not id2 ) then
  645. return id1;
  646. end
  647. local _, _, subgroup1 = GetRaidRosterInfo(id1);
  648. local _, _, subgroup2 = GetRaidRosterInfo(id2);
  649. if ( subgroup1 and subgroup2 and subgroup1 ~= subgroup2 ) then
  650. return subgroup1 < subgroup2;
  651. end
  652. --Fallthrough: Sort by order in Raid window.
  653. return id1 < id2;
  654. else
  655. if ( token1 == "player" ) then
  656. return true;
  657. elseif ( token2 == "player" ) then
  658. return false;
  659. else
  660. return token1 < token2; --String compare is OK since we don't go above 1 digit for party.
  661. end
  662. end
  663. end
  664. local roleValues = { MAINTANK = 1, MAINASSIST = 2, TANK = 3, HEALER = 4, DAMAGER = 5, NONE = 6 };
  665. function CRFSort_Role(token1, token2)
  666. local id1, id2 = UnitInRaid(token1), UnitInRaid(token2);
  667. local role1, role2;
  668. if ( id1 ) then
  669. role1 = select(10, GetRaidRosterInfo(id1));
  670. end
  671. if ( id2 ) then
  672. role2 = select(10, GetRaidRosterInfo(id2));
  673. end
  674. role1 = role1 or UnitGroupRolesAssigned(token1);
  675. role2 = role2 or UnitGroupRolesAssigned(token2);
  676. local value1, value2 = roleValues[role1], roleValues[role2];
  677. if ( value1 ~= value2 ) then
  678. return value1 < value2;
  679. end
  680. --Fallthrough: Sort alphabetically.
  681. return CRFSort_Alphabetical(token1, token2);
  682. end
  683. function CRFSort_Alphabetical(token1, token2)
  684. local name1, name2 = UnitName(token1), UnitName(token2);
  685. if ( name1 and name2 ) then
  686. return name1 < name2;
  687. elseif ( name1 or name2 ) then
  688. return name1;
  689. end
  690. --Fallthrough: Alphabetic order of tokens (just here to make comparisons well-ordered)
  691. return token1 < token2;
  692. end
  693. --Functions used for filtering
  694. local filterOptions = {
  695. [1] = true,
  696. [2] = true,
  697. [3] = true,
  698. [4] = true,
  699. [5] = true,
  700. [6] = true,
  701. [7] = true,
  702. [8] = true,
  703. displayRoleNONE = true;
  704. displayRoleTANK = true;
  705. displayRoleHEALER = true;
  706. displayRoleDAMAGER = true;
  707. }
  708. function CRF_SetFilterRole(role, show)
  709. filterOptions["displayRole"..role] = show;
  710. end
  711. function CRF_GetFilterRole(role)
  712. return filterOptions["displayRole"..role];
  713. end
  714. function CRF_SetFilterGroup(group, show)
  715. assert(type(group) == "number");
  716. filterOptions[group] = show;
  717. end
  718. function CRF_GetFilterGroup(group)
  719. assert(type(group) == "number");
  720. return filterOptions[group];
  721. end
  722. function CRFFlowFilterFunc(token)
  723. if ( not UnitExists(token) ) then
  724. return false;
  725. end
  726. if ( not IsInRaid() ) then --We don't filter unless we're in a raid.
  727. return true;
  728. end
  729. local role = UnitGroupRolesAssigned(token);
  730. if ( not filterOptions["displayRole"..role] ) then
  731. return false;
  732. end
  733. local raidID = UnitInRaid(token);
  734. if ( raidID ) then
  735. local name, rank, subgroup, level, class, fileName, zone, online, isDead, raidRole, isML = GetRaidRosterInfo(raidID);
  736. if ( not filterOptions[subgroup] ) then
  737. return false;
  738. end
  739. local showingMTandMA = CompactRaidFrameManager_GetSetting("DisplayMainTankAndAssist");
  740. if ( raidRole and (showingMTandMA and showingMTandMA ~= "0") ) then --If this character is already displayed as a Main Tank/Main Assist, we don't want to show them a second time
  741. return false;
  742. end
  743. end
  744. return true;
  745. end
  746. function CRFGroupFilterFunc(groupNum)
  747. return filterOptions[groupNum];
  748. end
  749. --Counting functions
  750. RaidInfoCounts = {
  751. aliveRoleTANK = 0,
  752. totalRoleTANK = 0,
  753. aliveRoleHEALER = 0,
  754. totalRoleHEALER = 0,
  755. aliveRoleDAMAGER = 0,
  756. totalRoleDAMAGER = 0,
  757. aliveRoleNONE = 0,
  758. totalRoleNONE = 0,
  759. totalCount = 0,
  760. totalAlive = 0,
  761. }
  762. local function CRF_ResetCountedStuff()
  763. for key, val in pairs(RaidInfoCounts) do
  764. RaidInfoCounts[key] = 0;
  765. end
  766. end
  767. function CRF_CountStuff()
  768. CRF_ResetCountedStuff();
  769. if ( IsInRaid() ) then
  770. for i=1, GetNumGroupMembers() do
  771. local name, rank, subgroup, level, class, fileName, zone, online, isDead, role, isML, assignedRole = GetRaidRosterInfo(i); --Weird that we have 2 role return values, but... oh well
  772. if ( rank ) then
  773. CRF_AddToCount(isDead, assignedRole);
  774. end
  775. end
  776. else
  777. CRF_AddToCount(UnitIsDeadOrGhost("player") , UnitGroupRolesAssigned("player"));
  778. for i=1, GetNumSubgroupMembers() do
  779. local unit = "party"..i;
  780. CRF_AddToCount(UnitIsDeadOrGhost(unit), UnitGroupRolesAssigned(unit));
  781. end
  782. end
  783. end
  784. function CRF_AddToCount(isDead, assignedRole)
  785. RaidInfoCounts.totalCount = RaidInfoCounts.totalCount + 1;
  786. RaidInfoCounts["totalRole"..assignedRole] = RaidInfoCounts["totalRole"..assignedRole] + 1;
  787. if ( not isDead ) then
  788. RaidInfoCounts.totalAlive = RaidInfoCounts.totalAlive + 1;
  789. RaidInfoCounts["aliveRole"..assignedRole] = RaidInfoCounts["aliveRole"..assignedRole] + 1;
  790. end
  791. end