MainMenuBar.lua

MainMenuBar.lua (9.0.2.37474; unchanged since 9.0.1.36230)
  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:SetText(TAXI_CANCEL, 1, 1, 1);
  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. end
  118. end
  119. function MainMenuBarVehicleLeaveButton_OnEvent(self, event, ...)
  120. MainMenuBarVehicleLeaveButton_Update();
  121. end
  122. function MainMenuBarVehicleLeaveButton_Update()
  123. if ( CanExitVehicle() and ActionBarController_GetCurrentActionBarState() == LE_ACTIONBAR_STATE_MAIN ) then
  124. MainMenuBarVehicleLeaveButton:ClearAllPoints();
  125. if ( IsPossessBarVisible() ) then
  126. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", PossessButton2, "RIGHT", 30, 0);
  127. elseif ( GetNumShapeshiftForms() > 0 ) then
  128. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", "StanceButton"..GetNumShapeshiftForms(), "RIGHT", 30, 0);
  129. elseif ( HasMultiCastActionBar() ) then
  130. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", MultiCastActionBarFrame, "RIGHT", 30, 0);
  131. else
  132. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", PossessBarFrame, "LEFT", 10, 0);
  133. end
  134. MainMenuBarVehicleLeaveButton:Show();
  135. MainMenuBarVehicleLeaveButton:Enable();
  136. ShowPetActionBar(true);
  137. else
  138. MainMenuBarVehicleLeaveButton:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]], "ADD");
  139. MainMenuBarVehicleLeaveButton:UnlockHighlight();
  140. MainMenuBarVehicleLeaveButton:Hide();
  141. ShowPetActionBar(true);
  142. end
  143. UIParent_ManageFramePositions();
  144. end
  145. function MainMenuBarVehicleLeaveButton_OnClicked(self)
  146. if ( UnitOnTaxi("player") ) then
  147. TaxiRequestEarlyLanding();
  148. -- Show that the request for landing has been received.
  149. self:Disable();
  150. self:SetHighlightTexture([[Interface\Buttons\CheckButtonHilight]], "ADD");
  151. self:LockHighlight();
  152. else
  153. VehicleExit();
  154. end
  155. end
  156. -- latency bar
  157. local NUM_ADDONS_TO_DISPLAY = 3;
  158. local topAddOns = {}
  159. for i=1, NUM_ADDONS_TO_DISPLAY do
  160. topAddOns[i] = { value = 0, name = "" };
  161. end
  162. -- These are movieID from the MOVIE database file.
  163. local MovieList = {
  164. -- Movie sequence 1 = Wow Classic
  165. { 1, 2 },
  166. -- Movie sequence 2 = BC
  167. { 27 },
  168. -- Movie sequence 3 = LK
  169. { 18 },
  170. -- Movie sequence 4 = CC
  171. { 23 },
  172. -- Movie sequence 5 = MP
  173. { 115 },
  174. -- Movie sequence 6 = WoD
  175. -- TODO change movie ID when it is available
  176. { 115 },
  177. }
  178. function MainMenu_GetMovieDownloadProgress(id)
  179. local movieList = MovieList[id];
  180. if (not movieList) then return; end
  181. local anyInProgress = false;
  182. local allDownloaded = 0;
  183. local allTotal = 0;
  184. for _, movieId in ipairs(movieList) do
  185. local inProgress, downloaded, total = GetMovieDownloadProgress(movieId);
  186. anyInProgress = anyInProgress or inProgress;
  187. allDownloaded = allDownloaded + downloaded;
  188. allTotal = allTotal + total;
  189. end
  190. return anyInProgress, allDownloaded, allTotal;
  191. end
  192. local ipTypes = { "IPv4", "IPv6" }
  193. function MainMenuBarPerformanceBarFrame_OnEnter(self)
  194. local string = "";
  195. local i, j, k = 0, 0, 0;
  196. GameTooltip_SetDefaultAnchor(GameTooltip, self);
  197. GameTooltip_SetTitle(GameTooltip, self.tooltipText);
  198. -- latency
  199. local bandwidthIn, bandwidthOut, latencyHome, latencyWorld = GetNetStats();
  200. string = format(MAINMENUBAR_LATENCY_LABEL, latencyHome, latencyWorld);
  201. GameTooltip:AddLine(" ");
  202. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  203. GameTooltip:AddLine(" ");
  204. -- protocol types
  205. if ( GetCVarBool("useIPv6") ) then
  206. local ipTypeHome, ipTypeWorld = GetNetIpTypes();
  207. string = format(MAINMENUBAR_PROTOCOLS_LABEL, ipTypes[ipTypeHome or 0] or UNKNOWN, ipTypes[ipTypeWorld or 0] or UNKNOWN);
  208. GameTooltip:AddLine(" ");
  209. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  210. GameTooltip:AddLine(" ");
  211. end
  212. -- framerate
  213. string = format(MAINMENUBAR_FPS_LABEL, GetFramerate());
  214. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  215. GameTooltip:AddLine(" ");
  216. string = format(MAINMENUBAR_BANDWIDTH_LABEL, GetAvailableBandwidth());
  217. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  218. GameTooltip:AddLine(" ");
  219. local percent = floor(GetDownloadedPercentage()*100+0.5);
  220. string = format(MAINMENUBAR_DOWNLOAD_PERCENT_LABEL, percent);
  221. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  222. -- Downloaded cinematics
  223. local firstMovie = true;
  224. for i, movieList in next, MovieList do
  225. local inProgress, downloaded, total = MainMenu_GetMovieDownloadProgress(i);
  226. if ( inProgress ) then
  227. if ( firstMovie ) then
  228. GameTooltip:AddLine(" "..CINEMATICS, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, true);
  229. firstMovie = false;
  230. end
  231. 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);
  232. end
  233. end
  234. -- AddOn mem usage
  235. for i=1, NUM_ADDONS_TO_DISPLAY, 1 do
  236. topAddOns[i].value = 0;
  237. end
  238. UpdateAddOnMemoryUsage();
  239. local totalMem = 0;
  240. for i=1, GetNumAddOns(), 1 do
  241. local mem = GetAddOnMemoryUsage(i);
  242. totalMem = totalMem + mem;
  243. for j=1, NUM_ADDONS_TO_DISPLAY, 1 do
  244. if( mem > topAddOns[j].value ) then
  245. for k=NUM_ADDONS_TO_DISPLAY, 1, -1 do
  246. if( k == j ) then
  247. topAddOns[k].value = mem;
  248. topAddOns[k].name = GetAddOnInfo(i);
  249. break;
  250. elseif( k ~= 1 ) then
  251. topAddOns[k].value = topAddOns[k-1].value;
  252. topAddOns[k].name = topAddOns[k-1].name;
  253. end
  254. end
  255. break;
  256. end
  257. end
  258. end
  259. if ( totalMem > 0 ) then
  260. if ( totalMem > 1000 ) then
  261. totalMem = totalMem / 1000;
  262. string = format(TOTAL_MEM_MB_ABBR, totalMem);
  263. else
  264. string = format(TOTAL_MEM_KB_ABBR, totalMem);
  265. end
  266. GameTooltip:AddLine("\n");
  267. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  268. local size;
  269. for i=1, NUM_ADDONS_TO_DISPLAY, 1 do
  270. if ( topAddOns[i].value == 0 ) then
  271. break;
  272. end
  273. size = topAddOns[i].value;
  274. if ( size > 1000 ) then
  275. size = size / 1000;
  276. string = format(ADDON_MEM_MB_ABBR, size, topAddOns[i].name);
  277. else
  278. string = format(ADDON_MEM_KB_ABBR, size, topAddOns[i].name);
  279. end
  280. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  281. end
  282. end
  283. GameTooltip:Show();
  284. end
  285. function MainMenuBarMixin:ChangeMenuBarSizeAndPosition(rightMultiBarShowing)
  286. local atlasInfo;
  287. if( rightMultiBarShowing ) then
  288. atlasInfo = C_Texture.GetAtlasInfo("hud-MainMenuBar-large");
  289. else
  290. atlasInfo = C_Texture.GetAtlasInfo("hud-MainMenuBar-small");
  291. end
  292. local width = atlasInfo and atlasInfo.width or 0;
  293. local height = atlasInfo and atlasInfo.height or 0;
  294. self:SetSize(width, height);
  295. MainMenuBarArtFrame:SetSize(width, height);
  296. MainMenuBarArtFrameBackground:SetSize(width, height);
  297. MainMenuBarArtFrameBackground.BackgroundLarge:SetShown(rightMultiBarShowing);
  298. MainMenuBarArtFrameBackground.BackgroundSmall:SetShown(not rightMultiBarShowing);
  299. MainMenuBarArtFrame.PageNumber:ClearAllPoints();
  300. if rightMultiBarShowing then
  301. MainMenuBarArtFrame.PageNumber:SetPoint("CENTER", MainMenuBarArtFrameBackground, "CENTER", 138, -3);
  302. else
  303. MainMenuBarArtFrame.PageNumber:SetPoint("RIGHT", MainMenuBarArtFrameBackground, "RIGHT", -6, -3);
  304. end
  305. local isLargeSize = rightMultiBarShowing;
  306. StatusTrackingBarManager:SetBarSize(isLargeSize);
  307. end
  308. function MainMenuBarMixin:SetQuickKeybindModeEffectsShown(showEffects)
  309. local artFrameBG = self.ArtFrame.Background;
  310. local microBar = self.MicroButtonAndBagsBar;
  311. artFrameBG.QuickKeybindBottomShadow:SetShown(showEffects);
  312. local useLargeBackground = artFrameBG.BackgroundLarge:IsShown();
  313. artFrameBG.QuickKeybindGlowSmall:SetShown(not useLargeBackground and showEffects);
  314. artFrameBG.QuickKeybindGlowLarge:SetShown(useLargeBackground and showEffects);
  315. microBar.QuickKeybindsMicroBagBarGlow:SetShown(showEffects);
  316. local useRightShadow = MultiBarRight:IsShown();
  317. artFrameBG.QuickKeybindRightShadow:SetShown(useRightShadow and showEffects);
  318. end