MainMenuBar.lua

MainMenuBar.lua (9.1.5.40906; unchanged since 9.0.5.37864)
  1. local MAINMENU_SLIDETIME = 0.30;
  2. local MAINMENU_GONEYPOS = 130; --Distance off screen for MainMenuBar to be completely hidden
  3. local MAINMENU_XPOS = 0;
  4. MAIN_MENU_BAR_MARGIN = 75; -- number of art pixels on one side, used by UIParent_ManageFramePositions. It's not the art's full size, don't care about the gryphon's tail.
  5. MainMenuBarMixin = { };
  6. function MainMenuBarMixin:OnStatusBarsUpdated()
  7. self:SetPositionForStatusBars();
  8. end
  9. function MainMenuBarMixin:OnLoad()
  10. self:RegisterEvent("ACTIONBAR_PAGE_CHANGED");
  11. self:RegisterEvent("CURRENCY_DISPLAY_UPDATE");
  12. self:RegisterEvent("UNIT_LEVEL");
  13. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  14. self:RegisterEvent("TRIAL_STATUS_UPDATE");
  15. self:RegisterEvent("DISPLAY_SIZE_CHANGED");
  16. self:RegisterEvent("UI_SCALE_CHANGED");
  17. CreateFrame("FRAME", "StatusTrackingBarManager", self, "StatusTrackingBarManagerTemplate");
  18. MAX_PLAYER_LEVEL = GetMaxLevelForPlayerExpansion();
  19. self.state = "player";
  20. MainMenuBarArtFrame.PageNumber:SetText(GetActionBarPage());
  21. MicroButtonAndBagsBar:SetFrameLevel(self:GetFrameLevel()+2);
  22. end
  23. function MainMenuBarMixin:OnShow()
  24. UpdateMicroButtonsParent(MainMenuBarArtFrame);
  25. MoveMicroButtons("BOTTOMLEFT", MicroButtonAndBagsBar, "BOTTOMLEFT", 6, 3, false);
  26. end
  27. function MainMenuBarMixin:SetYOffset(yOffset)
  28. self.yOffset = yOffset;
  29. end
  30. function MainMenuBarMixin:GetYOffset()
  31. return self.yOffset;
  32. end
  33. function MainMenuBarMixin:SetPositionForStatusBars()
  34. MainMenuBar:ClearAllPoints();
  35. MainMenuBarArtFrame.LeftEndCap:ClearAllPoints();
  36. MainMenuBarArtFrame.RightEndCap:ClearAllPoints();
  37. if ( StatusTrackingBarManager:GetNumberVisibleBars() == 2 ) then
  38. self:SetYOffset(19);
  39. MainMenuBarArtFrame.LeftEndCap:SetPoint("BOTTOMLEFT", MainMenuBar, -98, -19);
  40. MainMenuBarArtFrame.RightEndCap:SetPoint("BOTTOMRIGHT", MainMenuBar, 98, -19);
  41. elseif ( StatusTrackingBarManager:GetNumberVisibleBars() == 1 ) then
  42. self:SetYOffset(14);
  43. MainMenuBarArtFrame.LeftEndCap:SetPoint("BOTTOMLEFT", MainMenuBar, -98, -14);
  44. MainMenuBarArtFrame.RightEndCap:SetPoint("BOTTOMRIGHT", MainMenuBar, 98, -14);
  45. else
  46. self:SetYOffset(0);
  47. MainMenuBarArtFrame.LeftEndCap:SetPoint("BOTTOMLEFT", MainMenuBar, -98, 0);
  48. MainMenuBarArtFrame.RightEndCap:SetPoint("BOTTOMRIGHT", MainMenuBar, 98, 0);
  49. end
  50. if ( IsPlayerInWorld() ) then
  51. UIParent_ManageFramePositions();
  52. end
  53. end
  54. local firstEnteringWorld = true;
  55. function MainMenuBarMixin:OnEvent(event, ...)
  56. if ( event == "ACTIONBAR_PAGE_CHANGED" ) then
  57. MainMenuBarArtFrame.PageNumber:SetText(GetActionBarPage());
  58. elseif ( event == "CURRENCY_DISPLAY_UPDATE" ) then
  59. local showTokenFrame = GetCVarBool("showTokenFrame");
  60. if ( not showTokenFrame ) then
  61. if ( C_CurrencyInfo.GetCurrencyListSize() > 0 ) then
  62. SetCVar("showTokenFrame", 1);
  63. if ( not CharacterFrame:IsVisible() ) then
  64. MicroButtonPulse(CharacterMicroButton, 60);
  65. end
  66. if ( not TokenFrame:IsVisible() ) then
  67. SetButtonPulse(CharacterFrameTab3, 60, 1);
  68. end
  69. TokenFrame_Update();
  70. BackpackTokenFrame_Update();
  71. else
  72. CharacterFrameTab3:Hide();
  73. end
  74. else
  75. TokenFrame_Update();
  76. BackpackTokenFrame_Update();
  77. end
  78. elseif ( event == "UNIT_LEVEL" ) then
  79. local unitToken = ...;
  80. if ( unitToken == "player" ) then
  81. UpdateMicroButtons();
  82. end
  83. elseif ( event == "PLAYER_ENTERING_WORLD" ) then
  84. local initialLogin, reloadingUI = ...;
  85. if ( initialLogin or reloadingUI ) then
  86. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "ReputationStatusBarTemplate");
  87. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "HonorStatusBarTemplate");
  88. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "ArtifactStatusBarTemplate");
  89. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "ExpStatusBarTemplate");
  90. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "AzeriteBarTemplate");
  91. UIParent_ManageFramePositions();
  92. end
  93. elseif ( event == "TRIAL_STATUS_UPDATE" ) then
  94. UpdateMicroButtons();
  95. elseif ( event == "DISPLAY_SIZE_CHANGED" or event == "UI_SCALE_CHANGED" ) then
  96. self:ChangeMenuBarSizeAndPosition(SHOW_MULTI_ACTIONBAR_2 and IsNormalActionBarState());
  97. end
  98. self:SetPositionForStatusBars();
  99. end
  100. function MainMenuBarVehicleLeaveButton_OnLoad(self)
  101. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  102. self:RegisterEvent("UPDATE_BONUS_ACTIONBAR");
  103. self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR");
  104. self:RegisterEvent("UNIT_ENTERED_VEHICLE");
  105. self:RegisterEvent("UNIT_EXITED_VEHICLE");
  106. self:RegisterEvent("VEHICLE_UPDATE");
  107. end
  108. function MainMenuBarVehicleLeaveButton_OnEnter(self)
  109. if ( UnitOnTaxi("player") ) then
  110. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  111. GameTooltip_SetTitle(GameTooltip, TAXI_CANCEL);
  112. GameTooltip:AddLine(TAXI_CANCEL_DESCRIPTION, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, true);
  113. GameTooltip:Show();
  114. else
  115. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  116. GameTooltip_SetTitle(GameTooltip, LEAVE_VEHICLE);
  117. GameTooltip:Show();
  118. end
  119. end
  120. function MainMenuBarVehicleLeaveButton_OnEvent(self, event, ...)
  121. MainMenuBarVehicleLeaveButton_Update();
  122. end
  123. function MainMenuBarVehicleLeaveButton_Update()
  124. if ( CanExitVehicle() and ActionBarController_GetCurrentActionBarState() == LE_ACTIONBAR_STATE_MAIN ) then
  125. MainMenuBarVehicleLeaveButton:ClearAllPoints();
  126. if ( IsPossessBarVisible() ) then
  127. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", PossessButton2, "RIGHT", 30, 0);
  128. elseif ( GetNumShapeshiftForms() > 0 ) then
  129. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", "StanceButton"..GetNumShapeshiftForms(), "RIGHT", 30, 0);
  130. elseif ( HasMultiCastActionBar() ) then
  131. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", MultiCastActionBarFrame, "RIGHT", 30, 0);
  132. else
  133. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", PossessBarFrame, "LEFT", 10, 0);
  134. end
  135. MainMenuBarVehicleLeaveButton:Show();
  136. MainMenuBarVehicleLeaveButton:Enable();
  137. ShowPetActionBar(true);
  138. else
  139. MainMenuBarVehicleLeaveButton:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]], "ADD");
  140. MainMenuBarVehicleLeaveButton:UnlockHighlight();
  141. MainMenuBarVehicleLeaveButton:Hide();
  142. ShowPetActionBar(true);
  143. end
  144. UIParent_ManageFramePositions();
  145. end
  146. function MainMenuBarVehicleLeaveButton_OnClicked(self)
  147. if ( UnitOnTaxi("player") ) then
  148. TaxiRequestEarlyLanding();
  149. -- Show that the request for landing has been received.
  150. self:Disable();
  151. self:SetHighlightTexture([[Interface\Buttons\CheckButtonHilight]], "ADD");
  152. self:LockHighlight();
  153. else
  154. VehicleExit();
  155. end
  156. end
  157. -- latency bar
  158. local NUM_ADDONS_TO_DISPLAY = 3;
  159. local topAddOns = {}
  160. for i=1, NUM_ADDONS_TO_DISPLAY do
  161. topAddOns[i] = { value = 0, name = "" };
  162. end
  163. -- These are movieID from the MOVIE database file.
  164. local MovieList = {
  165. -- Movie sequence 1 = Wow Classic
  166. { 1, 2 },
  167. -- Movie sequence 2 = BC
  168. { 27 },
  169. -- Movie sequence 3 = LK
  170. { 18 },
  171. -- Movie sequence 4 = CC
  172. { 23 },
  173. -- Movie sequence 5 = MP
  174. { 115 },
  175. -- Movie sequence 6 = WoD
  176. -- TODO change movie ID when it is available
  177. { 115 },
  178. }
  179. function MainMenu_GetMovieDownloadProgress(id)
  180. local movieList = MovieList[id];
  181. if (not movieList) then return; end
  182. local anyInProgress = false;
  183. local allDownloaded = 0;
  184. local allTotal = 0;
  185. for _, movieId in ipairs(movieList) do
  186. local inProgress, downloaded, total = GetMovieDownloadProgress(movieId);
  187. anyInProgress = anyInProgress or inProgress;
  188. allDownloaded = allDownloaded + downloaded;
  189. allTotal = allTotal + total;
  190. end
  191. return anyInProgress, allDownloaded, allTotal;
  192. end
  193. local ipTypes = { "IPv4", "IPv6" }
  194. function MainMenuBarPerformanceBarFrame_OnEnter(self)
  195. local string = "";
  196. local i, j, k = 0, 0, 0;
  197. GameTooltip_SetDefaultAnchor(GameTooltip, self);
  198. GameTooltip_SetTitle(GameTooltip, self.tooltipText);
  199. -- latency
  200. local bandwidthIn, bandwidthOut, latencyHome, latencyWorld = GetNetStats();
  201. string = format(MAINMENUBAR_LATENCY_LABEL, latencyHome, latencyWorld);
  202. GameTooltip:AddLine(" ");
  203. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  204. GameTooltip:AddLine(" ");
  205. -- protocol types
  206. if ( GetCVarBool("useIPv6") ) then
  207. local ipTypeHome, ipTypeWorld = GetNetIpTypes();
  208. string = format(MAINMENUBAR_PROTOCOLS_LABEL, ipTypes[ipTypeHome or 0] or UNKNOWN, ipTypes[ipTypeWorld or 0] or UNKNOWN);
  209. GameTooltip:AddLine(" ");
  210. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  211. GameTooltip:AddLine(" ");
  212. end
  213. -- framerate
  214. string = format(MAINMENUBAR_FPS_LABEL, GetFramerate());
  215. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  216. GameTooltip:AddLine(" ");
  217. string = format(MAINMENUBAR_BANDWIDTH_LABEL, GetAvailableBandwidth());
  218. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  219. GameTooltip:AddLine(" ");
  220. local percent = floor(GetDownloadedPercentage()*100+0.5);
  221. string = format(MAINMENUBAR_DOWNLOAD_PERCENT_LABEL, percent);
  222. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  223. -- Downloaded cinematics
  224. local firstMovie = true;
  225. for i, movieList in next, MovieList do
  226. local inProgress, downloaded, total = MainMenu_GetMovieDownloadProgress(i);
  227. if ( inProgress ) then
  228. if ( firstMovie ) then
  229. GameTooltip:AddLine(" "..CINEMATICS, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, true);
  230. firstMovie = false;
  231. end
  232. GameTooltip:AddLine(" "..format(CINEMATIC_DOWNLOAD_FORMAT, _G["CINEMATIC_NAME_"..i], downloaded/total*100), GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b, true);
  233. end
  234. end
  235. -- AddOn mem usage
  236. for i=1, NUM_ADDONS_TO_DISPLAY, 1 do
  237. topAddOns[i].value = 0;
  238. end
  239. UpdateAddOnMemoryUsage();
  240. local totalMem = 0;
  241. for i=1, GetNumAddOns(), 1 do
  242. local mem = GetAddOnMemoryUsage(i);
  243. totalMem = totalMem + mem;
  244. for j=1, NUM_ADDONS_TO_DISPLAY, 1 do
  245. if( mem > topAddOns[j].value ) then
  246. for k=NUM_ADDONS_TO_DISPLAY, 1, -1 do
  247. if( k == j ) then
  248. topAddOns[k].value = mem;
  249. topAddOns[k].name = GetAddOnInfo(i);
  250. break;
  251. elseif( k ~= 1 ) then
  252. topAddOns[k].value = topAddOns[k-1].value;
  253. topAddOns[k].name = topAddOns[k-1].name;
  254. end
  255. end
  256. break;
  257. end
  258. end
  259. end
  260. if ( totalMem > 0 ) then
  261. if ( totalMem > 1000 ) then
  262. totalMem = totalMem / 1000;
  263. string = format(TOTAL_MEM_MB_ABBR, totalMem);
  264. else
  265. string = format(TOTAL_MEM_KB_ABBR, totalMem);
  266. end
  267. GameTooltip:AddLine("\n");
  268. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  269. local size;
  270. for i=1, NUM_ADDONS_TO_DISPLAY, 1 do
  271. if ( topAddOns[i].value == 0 ) then
  272. break;
  273. end
  274. size = topAddOns[i].value;
  275. if ( size > 1000 ) then
  276. size = size / 1000;
  277. string = format(ADDON_MEM_MB_ABBR, size, topAddOns[i].name);
  278. else
  279. string = format(ADDON_MEM_KB_ABBR, size, topAddOns[i].name);
  280. end
  281. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  282. end
  283. end
  284. GameTooltip:Show();
  285. end
  286. function MainMenuBarMixin:ChangeMenuBarSizeAndPosition(rightMultiBarShowing)
  287. local atlasInfo;
  288. if( rightMultiBarShowing ) then
  289. atlasInfo = C_Texture.GetAtlasInfo("hud-MainMenuBar-large");
  290. else
  291. atlasInfo = C_Texture.GetAtlasInfo("hud-MainMenuBar-small");
  292. end
  293. local width = atlasInfo and atlasInfo.width or 0;
  294. local height = atlasInfo and atlasInfo.height or 0;
  295. self:SetSize(width, height);
  296. MainMenuBarArtFrame:SetSize(width, height);
  297. MainMenuBarArtFrameBackground:SetSize(width, height);
  298. MainMenuBarArtFrameBackground.BackgroundLarge:SetShown(rightMultiBarShowing);
  299. MainMenuBarArtFrameBackground.BackgroundSmall:SetShown(not rightMultiBarShowing);
  300. MainMenuBarArtFrame.PageNumber:ClearAllPoints();
  301. if rightMultiBarShowing then
  302. MainMenuBarArtFrame.PageNumber:SetPoint("CENTER", MainMenuBarArtFrameBackground, "CENTER", 138, -3);
  303. else
  304. MainMenuBarArtFrame.PageNumber:SetPoint("RIGHT", MainMenuBarArtFrameBackground, "RIGHT", -6, -3);
  305. end
  306. local isLargeSize = rightMultiBarShowing;
  307. StatusTrackingBarManager:SetBarSize(isLargeSize);
  308. end
  309. function MainMenuBarMixin:SetQuickKeybindModeEffectsShown(showEffects)
  310. local artFrameBG = self.ArtFrame.Background;
  311. local microBar = self.MicroButtonAndBagsBar;
  312. artFrameBG.QuickKeybindBottomShadow:SetShown(showEffects);
  313. local useLargeBackground = artFrameBG.BackgroundLarge:IsShown();
  314. artFrameBG.QuickKeybindGlowSmall:SetShown(not useLargeBackground and showEffects);
  315. artFrameBG.QuickKeybindGlowLarge:SetShown(useLargeBackground and showEffects);
  316. microBar.QuickKeybindsMicroBagBarGlow:SetShown(showEffects);
  317. local useRightShadow = MultiBarRight:IsShown();
  318. artFrameBG.QuickKeybindRightShadow:SetShown(useRightShadow and showEffects);
  319. end