MultiActionBars.lua

MultiActionBars.lua (9.0.2.36294; unchanged since 9.0.1.36230)
  1. NUM_MULTIBAR_BUTTONS = 12;
  2. VERTICAL_MULTI_BAR_HEIGHT = 503;
  3. VERTICAL_MULTI_BAR_WIDTH = 41;
  4. VERTICAL_MULTI_BAR_VERTICAL_SPACING = 20;
  5. VERTICAL_MULTI_BAR_HORIZONTAL_SPACING = 2;
  6. VERTICAL_MULTI_BAR_MIN_SCALE = 0.8333;
  7. function MultiActionButtonDown (bar, id)
  8. local button = _G[bar.."Button"..id];
  9. if ( button:GetButtonState() == "NORMAL" ) then
  10. button:SetButtonState("PUSHED");
  11. end
  12. if (GetCVarBool("ActionButtonUseKeyDown")) then
  13. SecureActionButton_OnClick(button, "LeftButton");
  14. button:UpdateState();
  15. end
  16. end
  17. function MultiActionButtonUp (bar, id)
  18. local button = _G[bar.."Button"..id];
  19. if ( button:GetButtonState() == "PUSHED" ) then
  20. button:SetButtonState("NORMAL");
  21. if(not GetCVarBool("ActionButtonUseKeyDown")) then
  22. SecureActionButton_OnClick(button, "LeftButton");
  23. button:UpdateState();
  24. end
  25. end
  26. end
  27. function IsNormalActionBarState()
  28. return MainMenuBar:IsShown();
  29. end
  30. local function UpdateMultiActionBar(frame, var, pageVar, cb)
  31. if (var and IsNormalActionBarState()) then
  32. frame:SetShown(true);
  33. VIEWABLE_ACTION_BAR_PAGES[pageVar] = nil;
  34. else
  35. frame:SetShown(false);
  36. VIEWABLE_ACTION_BAR_PAGES[pageVar] = 1;
  37. end
  38. if (cb) then
  39. cb(var);
  40. end
  41. end
  42. local function UpdateMainMenuBar(rightBarShowing)
  43. MainMenuBar:ChangeMenuBarSizeAndPosition(rightBarShowing);
  44. StatusTrackingBarManager:UpdateBarsShown();
  45. end
  46. function MultiActionBar_OnLoad(self)
  47. self:RegisterEvent("DISPLAY_SIZE_CHANGED");
  48. self:RegisterEvent("UI_SCALE_CHANGED");
  49. end
  50. function MultiActionBar_OnEvent(self, event, ...)
  51. if IsPlayerInWorld() then
  52. MultiActionBar_Update();
  53. end
  54. end
  55. function MultiActionBar_Update ()
  56. local showLeft = false;
  57. local showRight = false;
  58. UpdateMultiActionBar(MultiBarBottomLeft, SHOW_MULTI_ACTIONBAR_1, BOTTOMLEFT_ACTIONBAR_PAGE);
  59. UpdateMultiActionBar(MultiBarBottomRight, SHOW_MULTI_ACTIONBAR_2, BOTTOMRIGHT_ACTIONBAR_PAGE, UpdateMainMenuBar);
  60. UpdateMultiActionBar(MultiBarRight, SHOW_MULTI_ACTIONBAR_3, RIGHT_ACTIONBAR_PAGE, function(var) showRight = var; end);
  61. UpdateMultiActionBar(MultiBarLeft, SHOW_MULTI_ACTIONBAR_3 and SHOW_MULTI_ACTIONBAR_4, LEFT_ACTIONBAR_PAGE, function(var) showLeft = var; end);
  62. if ( showRight ) then
  63. local topLimit = MinimapCluster:GetBottom() - 10; -- increasing by 14 here because we can overlap since the cluster is bigger than the elements it contains
  64. local bottomLimit = MicroButtonAndBagsBar:GetTop() + 24;
  65. local availableSpace = topLimit - bottomLimit;
  66. local contentWidth = VERTICAL_MULTI_BAR_WIDTH;
  67. local contentHeight = VERTICAL_MULTI_BAR_HEIGHT;
  68. if ( showLeft ) then
  69. contentHeight = contentHeight + VERTICAL_MULTI_BAR_HEIGHT + VERTICAL_MULTI_BAR_VERTICAL_SPACING;
  70. MultiBarLeft:ClearAllPoints();
  71. if ( contentHeight * VERTICAL_MULTI_BAR_MIN_SCALE > availableSpace or not GetCVarBool("multiBarRightVerticalLayout")) then
  72. MultiBarLeft:SetPoint("TOPRIGHT", MultiBarRight, "TOPLEFT", -VERTICAL_MULTI_BAR_HORIZONTAL_SPACING, 0);
  73. contentHeight = VERTICAL_MULTI_BAR_HEIGHT;
  74. contentWidth = VERTICAL_MULTI_BAR_WIDTH * 2 + VERTICAL_MULTI_BAR_HORIZONTAL_SPACING;
  75. else
  76. MultiBarLeft:SetPoint("TOP", MultiBarRight, "BOTTOM", 0, -VERTICAL_MULTI_BAR_VERTICAL_SPACING);
  77. end
  78. end
  79. local scale = 1;
  80. if ( contentHeight > availableSpace ) then
  81. scale = availableSpace / contentHeight;
  82. end
  83. MultiBarRight:SetScale(scale);
  84. if ( showLeft ) then
  85. MultiBarLeft:SetScale(scale);
  86. end
  87. VerticalMultiBarsContainer:SetSize(contentWidth * scale, contentHeight * scale);
  88. -- center position (of the available space), and if we run into the minimap cluster, move it down or up just enough
  89. local yOffset = ((contentHeight - VERTICAL_MULTI_BAR_HEIGHT) / 2) - ((GetScreenHeight() / 2) - ((availableSpace / 2) + bottomLimit));
  90. VerticalMultiBarsContainer:SetPoint("RIGHT", 0, yOffset);
  91. local barTop = VerticalMultiBarsContainer:GetTop();
  92. local barBottom = VerticalMultiBarsContainer:GetBottom();
  93. if ( topLimit < barTop or bottomLimit > barBottom) then
  94. yOffset = yOffset + math.min(topLimit - barTop, barBottom - bottomLimit);
  95. VerticalMultiBarsContainer:SetPoint("RIGHT", 0, yOffset);
  96. end
  97. else
  98. VerticalMultiBarsContainer:SetSize(0, 0);
  99. end
  100. -- TODO: Evaluate how often we're doing multiple calls of UIParent_ManageFramePositions per frame
  101. UIParent_ManageFramePositions();
  102. end
  103. function MultiActionBar_ShowAllGrids (reason, force)
  104. MultiActionBar_UpdateGrid("MultiBarBottomLeft", true, reason, force);
  105. MultiActionBar_UpdateGrid("MultiBarBottomRight", true, reason, force);
  106. MultiActionBar_UpdateGrid("MultiBarRight", true, reason, force);
  107. MultiActionBar_UpdateGrid("MultiBarLeft", true, reason, force);
  108. end
  109. function MultiActionBar_HideAllGrids (reason)
  110. MultiActionBar_UpdateGrid("MultiBarBottomLeft", false, reason);
  111. MultiActionBar_UpdateGrid("MultiBarBottomRight", false, reason);
  112. MultiActionBar_UpdateGrid("MultiBarRight", false, reason);
  113. MultiActionBar_UpdateGrid("MultiBarLeft", false, reason);
  114. end
  115. function MultiActionBar_UpdateGrid (barName, show, reason, force)
  116. for i = 1, NUM_MULTIBAR_BUTTONS do
  117. local button = _G[barName.."Button"..i];
  118. if ( show and (force or not button.noGrid) ) then
  119. button:ShowGrid(reason);
  120. else
  121. button:HideGrid(reason);
  122. end
  123. end
  124. end
  125. function MultiActionBar_UpdateGridVisibility ()
  126. if ( ALWAYS_SHOW_MULTIBARS == "1" or ALWAYS_SHOW_MULTIBARS == 1 ) then
  127. MultiActionBar_ShowAllGrids(ACTION_BUTTON_SHOW_GRID_REASON_CVAR);
  128. else
  129. MultiActionBar_HideAllGrids(ACTION_BUTTON_SHOW_GRID_REASON_CVAR);
  130. end
  131. end
  132. function MultiActionBar_SetAllQuickKeybindModeEffectsShown(showEffects)
  133. MultiBarBottomLeft.QuickKeybindGlow:SetShown(showEffects);
  134. MultiBarBottomRight.QuickKeybindGlow:SetShown(showEffects);
  135. MultiBarLeft.QuickKeybindGlow:SetShown(showEffects);
  136. MultiBarRight.QuickKeybindGlow:SetShown(showEffects);
  137. end
  138. function Multibar_EmptyFunc (show)
  139. end
  140. function MultibarGrid_IsVisible ()
  141. STATE_AlwaysShowMultibars = ALWAYS_SHOW_MULTIBARS;
  142. return ALWAYS_SHOW_MULTIBARS;
  143. end
  144. function MultiBar1_IsVisible ()
  145. STATE_MultiBar1 = SHOW_MULTI_ACTIONBAR_1;
  146. return SHOW_MULTI_ACTIONBAR_1;
  147. end
  148. function MultiBar2_IsVisible ()
  149. STATE_MultiBar2 = SHOW_MULTI_ACTIONBAR_2;
  150. return SHOW_MULTI_ACTIONBAR_2;
  151. end
  152. function MultiBar3_IsVisible ()
  153. STATE_MultiBar3 = SHOW_MULTI_ACTIONBAR_3;
  154. return SHOW_MULTI_ACTIONBAR_3;
  155. end
  156. function MultiBar4_IsVisible ()
  157. STATE_MultiBar4 = SHOW_MULTI_ACTIONBAR_4;
  158. return SHOW_MULTI_ACTIONBAR_4;
  159. end