Blizzard_CompactRaidFrames/Blizzard_CompactRaidFrameManager.lua

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