MainMenuBar.lua

MainMenuBar.lua (8.3.7.35284; unchanged since 8.2.5.31960)
  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 = MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()];
  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, showTokenFrameHonor = GetCVarBool("showTokenFrame"), GetCVarBool("showTokenFrameHonor");
  60. if ( not showTokenFrame or not showTokenFrameHonor ) then
  61. local name, isHeader, isExpanded, isUnused, isWatched, count, icon;
  62. local hasNormalTokens;
  63. for index=1, GetCurrencyListSize() do
  64. name, isHeader, isExpanded, isUnused, isWatched, count, icon = GetCurrencyListInfo(index);
  65. if ( (not isHeader) and count and (count > 0) ) then
  66. hasNormalTokens = true;
  67. end
  68. end
  69. if ( (not showTokenFrame) and (hasNormalTokens) ) then
  70. SetCVar("showTokenFrame", 1);
  71. if ( not CharacterFrame:IsVisible() ) then
  72. MicroButtonPulse(CharacterMicroButton, 60);
  73. end
  74. if ( not TokenFrame:IsVisible() ) then
  75. SetButtonPulse(CharacterFrameTab3, 60, 1);
  76. end
  77. end
  78. if ( hasNormalTokens or showTokenFrame or showTokenFrameHonor ) then
  79. TokenFrame_LoadUI();
  80. TokenFrame_Update();
  81. BackpackTokenFrame_Update();
  82. else
  83. CharacterFrameTab3:Hide();
  84. end
  85. else
  86. TokenFrame_LoadUI();
  87. TokenFrame_Update();
  88. BackpackTokenFrame_Update();
  89. end
  90. elseif ( event == "UNIT_LEVEL" ) then
  91. local unitToken = ...;
  92. if ( unitToken == "player" ) then
  93. UpdateMicroButtons();
  94. end
  95. elseif ( event == "PLAYER_ENTERING_WORLD" ) then
  96. local initialLogin, reloadingUI = ...;
  97. if ( initialLogin or reloadingUI ) then
  98. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "ReputationStatusBarTemplate");
  99. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "HonorStatusBarTemplate");
  100. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "ArtifactStatusBarTemplate");
  101. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "ExpStatusBarTemplate");
  102. StatusTrackingBarManager:AddBarFromTemplate("FRAME", "AzeriteBarTemplate");
  103. UIParent_ManageFramePositions();
  104. end
  105. elseif ( event == "TRIAL_STATUS_UPDATE" ) then
  106. UpdateMicroButtons();
  107. elseif ( event == "DISPLAY_SIZE_CHANGED" or event == "UI_SCALE_CHANGED" ) then
  108. self:ChangeMenuBarSizeAndPosition(SHOW_MULTI_ACTIONBAR_2 and IsNormalActionBarState());
  109. end
  110. self:SetPositionForStatusBars();
  111. end
  112. function MainMenuBarVehicleLeaveButton_OnLoad(self)
  113. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  114. self:RegisterEvent("UPDATE_BONUS_ACTIONBAR");
  115. self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR");
  116. self:RegisterEvent("UNIT_ENTERED_VEHICLE");
  117. self:RegisterEvent("UNIT_EXITED_VEHICLE");
  118. self:RegisterEvent("VEHICLE_UPDATE");
  119. end
  120. function MainMenuBarVehicleLeaveButton_OnEnter(self)
  121. if ( UnitOnTaxi("player") ) then
  122. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  123. GameTooltip:SetText(TAXI_CANCEL, 1, 1, 1);
  124. GameTooltip:AddLine(TAXI_CANCEL_DESCRIPTION, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, true);
  125. GameTooltip:Show();
  126. else
  127. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  128. GameTooltip_SetTitle(GameTooltip, LEAVE_VEHICLE);
  129. end
  130. end
  131. function MainMenuBarVehicleLeaveButton_OnEvent(self, event, ...)
  132. MainMenuBarVehicleLeaveButton_Update();
  133. end
  134. function MainMenuBarVehicleLeaveButton_Update()
  135. if ( CanExitVehicle() and ActionBarController_GetCurrentActionBarState() == LE_ACTIONBAR_STATE_MAIN ) then
  136. MainMenuBarVehicleLeaveButton:ClearAllPoints();
  137. if ( IsPossessBarVisible() ) then
  138. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", PossessButton2, "RIGHT", 30, 0);
  139. elseif ( GetNumShapeshiftForms() > 0 ) then
  140. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", "StanceButton"..GetNumShapeshiftForms(), "RIGHT", 30, 0);
  141. elseif ( HasMultiCastActionBar() ) then
  142. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", MultiCastActionBarFrame, "RIGHT", 30, 0);
  143. else
  144. MainMenuBarVehicleLeaveButton:SetPoint("LEFT", PossessBarFrame, "LEFT", 10, 0);
  145. end
  146. MainMenuBarVehicleLeaveButton:Show();
  147. MainMenuBarVehicleLeaveButton:Enable();
  148. ShowPetActionBar(true);
  149. else
  150. MainMenuBarVehicleLeaveButton:SetHighlightTexture([[Interface\Buttons\ButtonHilight-Square]], "ADD");
  151. MainMenuBarVehicleLeaveButton:UnlockHighlight();
  152. MainMenuBarVehicleLeaveButton:Hide();
  153. ShowPetActionBar(true);
  154. end
  155. UIParent_ManageFramePositions();
  156. end
  157. function MainMenuBarVehicleLeaveButton_OnClicked(self)
  158. if ( UnitOnTaxi("player") ) then
  159. TaxiRequestEarlyLanding();
  160. -- Show that the request for landing has been received.
  161. self:Disable();
  162. self:SetHighlightTexture([[Interface\Buttons\CheckButtonHilight]], "ADD");
  163. self:LockHighlight();
  164. else
  165. VehicleExit();
  166. end
  167. end
  168. -- latency bar
  169. local NUM_ADDONS_TO_DISPLAY = 3;
  170. local topAddOns = {}
  171. for i=1, NUM_ADDONS_TO_DISPLAY do
  172. topAddOns[i] = { value = 0, name = "" };
  173. end
  174. -- These are movieID from the MOVIE database file.
  175. local MovieList = {
  176. -- Movie sequence 1 = Wow Classic
  177. { 1, 2 },
  178. -- Movie sequence 2 = BC
  179. { 27 },
  180. -- Movie sequence 3 = LK
  181. { 18 },
  182. -- Movie sequence 4 = CC
  183. { 23 },
  184. -- Movie sequence 5 = MP
  185. { 115 },
  186. -- Movie sequence 6 = WoD
  187. -- TODO change movie ID when it is available
  188. { 115 },
  189. }
  190. function MainMenu_GetMovieDownloadProgress(id)
  191. local movieList = MovieList[id];
  192. if (not movieList) then return; end
  193. local anyInProgress = false;
  194. local allDownloaded = 0;
  195. local allTotal = 0;
  196. for _, movieId in ipairs(movieList) do
  197. local inProgress, downloaded, total = GetMovieDownloadProgress(movieId);
  198. anyInProgress = anyInProgress or inProgress;
  199. allDownloaded = allDownloaded + downloaded;
  200. allTotal = allTotal + total;
  201. end
  202. return anyInProgress, allDownloaded, allTotal;
  203. end
  204. local ipTypes = { "IPv4", "IPv6" }
  205. function MainMenuBarPerformanceBarFrame_OnEnter(self)
  206. local string = "";
  207. local i, j, k = 0, 0, 0;
  208. GameTooltip_SetDefaultAnchor(GameTooltip, self);
  209. GameTooltip_SetTitle(GameTooltip, self.tooltipText);
  210. -- latency
  211. local bandwidthIn, bandwidthOut, latencyHome, latencyWorld = GetNetStats();
  212. string = format(MAINMENUBAR_LATENCY_LABEL, latencyHome, latencyWorld);
  213. GameTooltip:AddLine(" ");
  214. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  215. GameTooltip:AddLine(" ");
  216. -- protocol types
  217. if ( GetCVarBool("useIPv6") ) then
  218. local ipTypeHome, ipTypeWorld = GetNetIpTypes();
  219. string = format(MAINMENUBAR_PROTOCOLS_LABEL, ipTypes[ipTypeHome or 0] or UNKNOWN, ipTypes[ipTypeWorld or 0] or UNKNOWN);
  220. GameTooltip:AddLine(" ");
  221. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  222. GameTooltip:AddLine(" ");
  223. end
  224. -- framerate
  225. string = format(MAINMENUBAR_FPS_LABEL, GetFramerate());
  226. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  227. GameTooltip:AddLine(" ");
  228. string = format(MAINMENUBAR_BANDWIDTH_LABEL, GetAvailableBandwidth());
  229. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  230. GameTooltip:AddLine(" ");
  231. local percent = floor(GetDownloadedPercentage()*100+0.5);
  232. string = format(MAINMENUBAR_DOWNLOAD_PERCENT_LABEL, percent);
  233. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  234. -- Downloaded cinematics
  235. local firstMovie = true;
  236. for i, movieList in next, MovieList do
  237. local inProgress, downloaded, total = MainMenu_GetMovieDownloadProgress(i);
  238. if ( inProgress ) then
  239. if ( firstMovie ) then
  240. GameTooltip:AddLine(" "..CINEMATICS, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, true);
  241. firstMovie = false;
  242. end
  243. 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);
  244. end
  245. end
  246. -- AddOn mem usage
  247. for i=1, NUM_ADDONS_TO_DISPLAY, 1 do
  248. topAddOns[i].value = 0;
  249. end
  250. UpdateAddOnMemoryUsage();
  251. local totalMem = 0;
  252. for i=1, GetNumAddOns(), 1 do
  253. local mem = GetAddOnMemoryUsage(i);
  254. totalMem = totalMem + mem;
  255. for j=1, NUM_ADDONS_TO_DISPLAY, 1 do
  256. if( mem > topAddOns[j].value ) then
  257. for k=NUM_ADDONS_TO_DISPLAY, 1, -1 do
  258. if( k == j ) then
  259. topAddOns[k].value = mem;
  260. topAddOns[k].name = GetAddOnInfo(i);
  261. break;
  262. elseif( k ~= 1 ) then
  263. topAddOns[k].value = topAddOns[k-1].value;
  264. topAddOns[k].name = topAddOns[k-1].name;
  265. end
  266. end
  267. break;
  268. end
  269. end
  270. end
  271. if ( totalMem > 0 ) then
  272. if ( totalMem > 1000 ) then
  273. totalMem = totalMem / 1000;
  274. string = format(TOTAL_MEM_MB_ABBR, totalMem);
  275. else
  276. string = format(TOTAL_MEM_KB_ABBR, totalMem);
  277. end
  278. GameTooltip:AddLine("\n");
  279. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  280. local size;
  281. for i=1, NUM_ADDONS_TO_DISPLAY, 1 do
  282. if ( topAddOns[i].value == 0 ) then
  283. break;
  284. end
  285. size = topAddOns[i].value;
  286. if ( size > 1000 ) then
  287. size = size / 1000;
  288. string = format(ADDON_MEM_MB_ABBR, size, topAddOns[i].name);
  289. else
  290. string = format(ADDON_MEM_KB_ABBR, size, topAddOns[i].name);
  291. end
  292. GameTooltip:AddLine(string, 1.0, 1.0, 1.0);
  293. end
  294. end
  295. GameTooltip:Show();
  296. end
  297. function MainMenuBarMixin:ChangeMenuBarSizeAndPosition(rightMultiBarShowing)
  298. local atlasInfo;
  299. if( rightMultiBarShowing ) then
  300. atlasInfo = C_Texture.GetAtlasInfo("hud-MainMenuBar-large");
  301. else
  302. atlasInfo = C_Texture.GetAtlasInfo("hud-MainMenuBar-small");
  303. end
  304. local width = atlasInfo and atlasInfo.width or 0;
  305. local height = atlasInfo and atlasInfo.height or 0;
  306. self:SetSize(width, height);
  307. MainMenuBarArtFrame:SetSize(width, height);
  308. MainMenuBarArtFrameBackground:SetSize(width, height);
  309. MainMenuBarArtFrameBackground.BackgroundLarge:SetShown(rightMultiBarShowing);
  310. MainMenuBarArtFrameBackground.BackgroundSmall:SetShown(not rightMultiBarShowing);
  311. MainMenuBarArtFrame.PageNumber:ClearAllPoints();
  312. if rightMultiBarShowing then
  313. MainMenuBarArtFrame.PageNumber:SetPoint("CENTER", MainMenuBarArtFrameBackground, "CENTER", 138, -3);
  314. else
  315. MainMenuBarArtFrame.PageNumber:SetPoint("RIGHT", MainMenuBarArtFrameBackground, "RIGHT", -6, -3);
  316. end
  317. local isLargeSize = rightMultiBarShowing;
  318. StatusTrackingBarManager:SetBarSize(isLargeSize);
  319. end