MainMenuBarMicroButtons.lua

MainMenuBarMicroButtons.lua (9.1.5.40906; unchanged since 9.1.5.40871)
  1. DISPLAYED_COMMUNITIES_INVITATIONS = DISPLAYED_COMMUNITIES_INVITATIONS or {};
  2. PERFORMANCEBAR_UPDATE_INTERVAL = 1;
  3. MICRO_BUTTONS = {
  4. "CharacterMicroButton",
  5. "SpellbookMicroButton",
  6. "TalentMicroButton",
  7. "AchievementMicroButton",
  8. "QuestLogMicroButton",
  9. "GuildMicroButton",
  10. "LFDMicroButton",
  11. "EJMicroButton",
  12. "CollectionsMicroButton",
  13. "MainMenuMicroButton",
  14. "HelpMicroButton",
  15. "StoreMicroButton",
  16. }
  17. EJ_ALERT_TIME_DIFF = 60*60*24*7*2; -- 2 weeks
  18. local g_microButtonAlertsEnabledLocks = { };
  19. local g_activeMicroButtonAlert;
  20. local g_acknowledgedMicroButtonAlerts = {};
  21. local g_microButtonAlertPriority = { };
  22. local g_processAlertCloseCallback = true;
  23. local g_flashingMicroButtons = {};
  24. function LoadMicroButtonTextures(self, name)
  25. self:RegisterForClicks("AnyUp");
  26. self:RegisterEvent("UPDATE_BINDINGS");
  27. self:RegisterEvent("NEUTRAL_FACTION_SELECT_RESULT");
  28. local prefix = "hud-microbutton-";
  29. self:SetNormalAtlas(prefix..name.."-Up", true);
  30. self:SetPushedAtlas(prefix..name.."-Down", true);
  31. self:SetDisabledAtlas(prefix..name.."-Disabled", true);
  32. self:SetHighlightAtlas("hud-microbutton-highlight", true);
  33. end
  34. function MicroButtonTooltipText(text, action)
  35. local keyStringFormat = NORMAL_FONT_COLOR_CODE.."(%s)"..FONT_COLOR_CODE_CLOSE;
  36. local bindingAvailableFormat = "%s %s";
  37. return FormatBindingKeyIntoText(text, action, bindingAvailableFormat, keyStringFormat);
  38. end
  39. LFDMicroButtonMixin = {};
  40. function LFDMicroButtonMixin:OnLoad()
  41. LoadMicroButtonTextures(self, "LFG");
  42. self:RegisterEvent("QUEST_LOG_UPDATE");
  43. SetDesaturation(self:GetDisabledTexture(), true);
  44. self.tooltipText = MicroButtonTooltipText(DUNGEONS_BUTTON, "TOGGLEGROUPFINDER");
  45. self.newbieText = NEWBIE_TOOLTIP_LFGPARENT;
  46. self.disabledTooltip = function()
  47. local canUse, failureReason = C_LFGInfo.CanPlayerUseGroupFinder();
  48. return canUse and FEATURE_UNAVAILBLE_PLAYER_IS_NEUTRAL or failureReason;
  49. end
  50. self.IsActive = function()
  51. local factionGroup = UnitFactionGroup("player");
  52. local canUse, failureReason = C_LFGInfo.CanPlayerUseGroupFinder();
  53. return canUse and factionGroup ~= "Neutral" and not Kiosk.IsEnabled();
  54. end
  55. end
  56. function LFDMicroButtonMixin:OnEvent(event, ...)
  57. if ( Kiosk.IsEnabled() ) then
  58. return;
  59. end
  60. if ( event == "UPDATE_BINDINGS" ) then
  61. self.tooltipText = MicroButtonTooltipText(DUNGEONS_BUTTON, "TOGGLEGROUPFINDER");
  62. end
  63. self.newbieText = NEWBIE_TOOLTIP_LFGPARENT;
  64. UpdateMicroButtons();
  65. end
  66. function LFDMicroButtonMixin:OnClick(button, down)
  67. if ( not KeybindFrames_InQuickKeybindMode() ) then
  68. PVEFrame_ToggleFrame();
  69. end
  70. end
  71. MainMenuBarMicroButtonMixin = {};
  72. function MainMenuBarMicroButtonMixin:OnEnter()
  73. if ( not KeybindFrames_InQuickKeybindMode() ) then
  74. if ( self:IsEnabled() or self.minLevel or self.disabledTooltip or self.factionGroup) then
  75. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  76. GameTooltip_SetTitle(GameTooltip, self.tooltipText);
  77. if ( not self:IsEnabled() ) then
  78. if ( self.factionGroup == "Neutral" ) then
  79. GameTooltip:AddLine(FEATURE_NOT_AVAILBLE_PANDAREN, RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b, true);
  80. elseif ( self.minLevel ) then
  81. GameTooltip:AddLine(format(FEATURE_BECOMES_AVAILABLE_AT_LEVEL, self.minLevel), RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b, true);
  82. elseif ( self.disabledTooltip ) then
  83. local disabledTooltipText = GetValueOrCallFunction(self, "disabledTooltip");
  84. GameTooltip:AddLine(disabledTooltipText, RED_FONT_COLOR.r, RED_FONT_COLOR.g, RED_FONT_COLOR.b, true);
  85. end
  86. end
  87. GameTooltip:Show();
  88. end
  89. end
  90. end
  91. function UpdateMicroButtonsParent(parent)
  92. for i=1, #MICRO_BUTTONS do
  93. _G[MICRO_BUTTONS[i]]:SetParent(parent);
  94. end
  95. end
  96. function MoveMicroButtons(anchor, anchorTo, relAnchor, x, y, isStacked)
  97. CharacterMicroButton:ClearAllPoints();
  98. CharacterMicroButton:SetPoint(anchor, anchorTo, relAnchor, x, y);
  99. LFDMicroButton:ClearAllPoints();
  100. if ( isStacked ) then
  101. LFDMicroButton:SetPoint("TOPLEFT", CharacterMicroButton, "BOTTOMLEFT", 0, -1);
  102. else
  103. LFDMicroButton:SetPoint("BOTTOMLEFT", GuildMicroButton, "BOTTOMRIGHT", -2, 0);
  104. end
  105. UpdateMicroButtons();
  106. end
  107. function SetKioskTooltip(frame)
  108. if (Kiosk.IsEnabled()) then
  109. frame.minLevel = nil;
  110. frame.disabledTooltip = ERR_SYSTEM_DISABLED;
  111. end
  112. end
  113. local function GuildFrameIsOpen()
  114. return ( CommunitiesFrame and CommunitiesFrame:IsShown() ) or ( GuildFrame and GuildFrame:IsShown() );
  115. end
  116. function UpdateMicroButtons()
  117. local playerLevel = UnitLevel("player");
  118. local factionGroup = UnitFactionGroup("player");
  119. if ( factionGroup == "Neutral" ) then
  120. GuildMicroButton.factionGroup = factionGroup;
  121. LFDMicroButton.factionGroup = factionGroup;
  122. else
  123. GuildMicroButton.factionGroup = nil;
  124. LFDMicroButton.factionGroup = nil;
  125. end
  126. if ( CharacterFrame and CharacterFrame:IsShown() ) then
  127. CharacterMicroButton_SetPushed();
  128. else
  129. CharacterMicroButton_SetNormal();
  130. end
  131. if ( SpellBookFrame and SpellBookFrame:IsShown() ) then
  132. SpellbookMicroButton:SetButtonState("PUSHED", true);
  133. else
  134. SpellbookMicroButton:SetButtonState("NORMAL");
  135. end
  136. if ( PlayerTalentFrame and PlayerTalentFrame:IsShown() ) then
  137. TalentMicroButton:SetButtonState("PUSHED", true);
  138. else
  139. if not C_SpecializationInfo.CanPlayerUseTalentSpecUI() then
  140. TalentMicroButton:Disable();
  141. else
  142. TalentMicroButton:Enable();
  143. TalentMicroButton:SetButtonState("NORMAL");
  144. end
  145. end
  146. if ( WorldMapFrame and WorldMapFrame:IsShown() ) then
  147. QuestLogMicroButton:SetButtonState("PUSHED", true);
  148. else
  149. QuestLogMicroButton:SetButtonState("NORMAL");
  150. end
  151. if ( ( GameMenuFrame and GameMenuFrame:IsShown() )
  152. or ( InterfaceOptionsFrame:IsShown())
  153. or ( KeyBindingFrame and KeyBindingFrame:IsShown())
  154. or ( MacroFrame and MacroFrame:IsShown()) ) then
  155. MainMenuMicroButton:SetPushed();
  156. else
  157. MainMenuMicroButton:SetNormal();
  158. end
  159. GuildMicroButton:UpdateTabard();
  160. if ( IsCommunitiesUIDisabledByTrialAccount() or factionGroup == "Neutral" or Kiosk.IsEnabled() ) then
  161. GuildMicroButton:Disable();
  162. if (Kiosk.IsEnabled()) then
  163. SetKioskTooltip(GuildMicroButton);
  164. else
  165. GuildMicroButton.disabledTooltip = ERR_RESTRICTED_ACCOUNT_TRIAL;
  166. end
  167. elseif ( C_Club.IsEnabled() and not BNConnected() ) then
  168. GuildMicroButton:Disable();
  169. GuildMicroButton.disabledTooltip = BLIZZARD_COMMUNITIES_SERVICES_UNAVAILABLE;
  170. elseif ( C_Club.IsEnabled() and C_Club.IsRestricted() ~= Enum.ClubRestrictionReason.None ) then
  171. GuildMicroButton:Disable();
  172. GuildMicroButton.disabledTooltip = UNAVAILABLE;
  173. elseif ( GuildFrameIsOpen() ) then
  174. GuildMicroButton:Enable();
  175. GuildMicroButton:SetButtonState("PUSHED", true);
  176. GuildMicroButtonTabard:SetPoint("TOPLEFT", -1, -2);
  177. GuildMicroButtonTabard:SetAlpha(0.70);
  178. else
  179. GuildMicroButton:Enable();
  180. GuildMicroButton:SetButtonState("NORMAL");
  181. GuildMicroButtonTabard:SetPoint("TOPLEFT", 0, 0);
  182. GuildMicroButtonTabard:SetAlpha(1);
  183. if ( CommunitiesFrame_IsEnabled() ) then
  184. GuildMicroButton.tooltipText = MicroButtonTooltipText(GUILD_AND_COMMUNITIES, "TOGGLEGUILDTAB");
  185. GuildMicroButton.newbieText = NEWBIE_TOOLTIP_COMMUNITIESTAB;
  186. elseif ( IsInGuild() ) then
  187. GuildMicroButton.tooltipText = MicroButtonTooltipText(GUILD, "TOGGLEGUILDTAB");
  188. GuildMicroButton.newbieText = NEWBIE_TOOLTIP_GUILDTAB;
  189. else
  190. GuildMicroButton.tooltipText = MicroButtonTooltipText(LOOKINGFORGUILD, "TOGGLEGUILDTAB");
  191. GuildMicroButton.newbieText = NEWBIE_TOOLTIP_LOOKINGFORGUILDTAB;
  192. end
  193. end
  194. GuildMicroButton:UpdateNotificationIcon(GuildMicroButton);
  195. if ( PVEFrame and PVEFrame:IsShown() ) then
  196. LFDMicroButton:SetButtonState("PUSHED", true);
  197. else
  198. if not LFDMicroButton:IsActive() then
  199. if (Kiosk.IsEnabled()) then
  200. SetKioskTooltip(LFDMicroButton);
  201. end
  202. LFDMicroButton:Disable();
  203. else
  204. LFDMicroButton:Enable();
  205. LFDMicroButton:SetButtonState("NORMAL");
  206. end
  207. end
  208. if ( AchievementFrame and AchievementFrame:IsShown() ) then
  209. AchievementMicroButton:SetButtonState("PUSHED", true);
  210. else
  211. if ( ( HasCompletedAnyAchievement() or IsInGuild() ) and CanShowAchievementUI() and not Kiosk.IsEnabled() ) then
  212. AchievementMicroButton:Enable();
  213. AchievementMicroButton:SetButtonState("NORMAL");
  214. else
  215. if (Kiosk.IsEnabled()) then
  216. SetKioskTooltip(AchievementMicroButton);
  217. end
  218. AchievementMicroButton:Disable();
  219. end
  220. end
  221. EJMicroButton:UpdateDisplay();
  222. if ( CollectionsJournal and CollectionsJournal:IsShown() ) then
  223. CollectionsMicroButton:SetButtonState("PUSHED", true);
  224. else
  225. if ( not Kiosk.IsEnabled() ) then
  226. CollectionsMicroButton:Enable();
  227. CollectionsMicroButton:SetButtonState("NORMAL");
  228. else
  229. SetKioskTooltip(CollectionsMicroButton);
  230. CollectionsMicroButton:Disable();
  231. end
  232. end
  233. if ( StoreFrame and StoreFrame_IsShown() ) then
  234. StoreMicroButton:SetButtonState("PUSHED", true);
  235. else
  236. StoreMicroButton:SetButtonState("NORMAL");
  237. end
  238. StoreMicroButton:Show();
  239. HelpMicroButton:Hide();
  240. if ( C_StorePublic.IsDisabledByParentalControls() ) then
  241. StoreMicroButton.disabledTooltip = BLIZZARD_STORE_ERROR_PARENTAL_CONTROLS;
  242. StoreMicroButton:Disable();
  243. elseif ( Kiosk.IsEnabled() ) then
  244. StoreMicroButton.disabledTooltip = ERR_SYSTEM_DISABLED;
  245. StoreMicroButton:Disable();
  246. elseif ( not C_StorePublic.IsEnabled() ) then
  247. if ( GetCurrentRegionName() == "CN" ) then
  248. HelpMicroButton:Show();
  249. StoreMicroButton:Hide();
  250. else
  251. StoreMicroButton.disabledTooltip = BLIZZARD_STORE_ERROR_UNAVAILABLE;
  252. StoreMicroButton:Disable();
  253. end
  254. elseif C_PlayerInfo.IsPlayerNPERestricted() then
  255. local tutorials = TutorialLogic and TutorialLogic.Tutorials;
  256. if tutorials and tutorials.UI_Watcher and tutorials.UI_Watcher.IsActive then
  257. StoreMicroButton:Hide();
  258. end
  259. else
  260. StoreMicroButton.disabledTooltip = nil;
  261. StoreMicroButton:Enable();
  262. end
  263. end
  264. function MicroButtonPulse(self, duration)
  265. if not MainMenuMicroButton_AreAlertsEnabled() then
  266. return;
  267. end
  268. g_flashingMicroButtons[self] = true;
  269. UIFrameFlash(self.Flash, 1.0, 1.0, duration or -1, false, 0, 0, "microbutton");
  270. end
  271. function MicroButtonPulseStop(self)
  272. UIFrameFlashStop(self.Flash);
  273. g_flashingMicroButtons[self] = nil;
  274. end
  275. function MicroButton_KioskModeDisable(self)
  276. if (Kiosk.IsEnabled()) then
  277. self:Disable();
  278. end
  279. end
  280. AchievementMicroButtonMixin = {};
  281. function AchievementMicroButtonMixin:OnLoad()
  282. LoadMicroButtonTextures(self, "Achievement");
  283. self:RegisterEvent("RECEIVED_ACHIEVEMENT_LIST");
  284. self:RegisterEvent("ACHIEVEMENT_EARNED");
  285. self.tooltipText = MicroButtonTooltipText(ACHIEVEMENT_BUTTON, "TOGGLEACHIEVEMENT");
  286. self.newbieText = NEWBIE_TOOLTIP_ACHIEVEMENT;
  287. self.minLevel = 10; --Just used for display. But we know that it will become available by level 10 due to the level 10 achievement.
  288. if (Kiosk.IsEnabled()) then
  289. self:Disable();
  290. end
  291. end
  292. function AchievementMicroButtonMixin:OnClick(button, down)
  293. if ( not KeybindFrames_InQuickKeybindMode() ) then
  294. ToggleAchievementFrame();
  295. end
  296. end
  297. function AchievementMicroButtonMixin:OnEvent(event, ...)
  298. if (Kiosk.IsEnabled()) then
  299. return;
  300. end
  301. if ( event == "UPDATE_BINDINGS" ) then
  302. AchievementMicroButton.tooltipText = MicroButtonTooltipText(ACHIEVEMENT_BUTTON, "TOGGLEACHIEVEMENT");
  303. else
  304. UpdateMicroButtons();
  305. end
  306. end
  307. GuildMicroButtonMixin = {};
  308. function GuildMicroButtonMixin:OnLoad()
  309. LoadMicroButtonTextures(self, "Socials");
  310. self.tooltipText = MicroButtonTooltipText(LOOKINGFORGUILD, "TOGGLEGUILDTAB");
  311. self.newbieText = NEWBIE_TOOLTIP_LOOKINGFORGUILDTAB;
  312. self:RegisterEvent("PLAYER_GUILD_UPDATE");
  313. self:RegisterEvent("NEUTRAL_FACTION_SELECT_RESULT");
  314. self:RegisterEvent("STREAM_VIEW_MARKER_UPDATED");
  315. self:RegisterEvent("INITIAL_CLUBS_LOADED");
  316. self:RegisterEvent("CLUB_INVITATION_ADDED_FOR_SELF");
  317. self:RegisterEvent("CLUB_INVITATION_REMOVED_FOR_SELF");
  318. self:RegisterEvent("BN_DISCONNECTED");
  319. self:RegisterEvent("BN_CONNECTED");
  320. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  321. self:RegisterEvent("CLUB_FINDER_COMMUNITY_OFFLINE_JOIN");
  322. self:UpdateTabard(true);
  323. if ( IsCommunitiesUIDisabledByTrialAccount() ) then
  324. self:Disable();
  325. self.disabledTooltip = ERR_RESTRICTED_ACCOUNT_TRIAL;
  326. end
  327. if (Kiosk.IsEnabled()) then
  328. self:Disable();
  329. end
  330. end
  331. function GuildMicroButtonMixin:OnEvent(event, ...)
  332. if ( Kiosk.IsEnabled() ) then
  333. return;
  334. end
  335. if ( event == "PLAYER_ENTERING_WORLD" ) then
  336. self:EvaluateAlertVisibility();
  337. C_ClubFinder.PlayerRequestPendingClubsList(Enum.ClubFinderRequestType.All);
  338. elseif ( event == "UPDATE_BINDINGS" ) then
  339. if ( CommunitiesFrame_IsEnabled() ) then
  340. GuildMicroButton.tooltipText = MicroButtonTooltipText(GUILD_AND_COMMUNITIES, "TOGGLEGUILDTAB");
  341. elseif ( IsInGuild() ) then
  342. GuildMicroButton.tooltipText = MicroButtonTooltipText(GUILD, "TOGGLEGUILDTAB");
  343. else
  344. GuildMicroButton.tooltipText = MicroButtonTooltipText(LOOKINGFORGUILD, "TOGGLEGUILDTAB");
  345. end
  346. elseif ( event == "PLAYER_GUILD_UPDATE" or event == "NEUTRAL_FACTION_SELECT_RESULT" ) then
  347. GuildMicroButtonTabard.needsUpdate = true;
  348. UpdateMicroButtons();
  349. elseif ( event == "BN_DISCONNECTED" or event == "BN_CONNECTED" ) then
  350. UpdateMicroButtons();
  351. elseif ( event == "INITIAL_CLUBS_LOADED" ) then
  352. self:UpdateNotificationIcon(GuildMicroButton);
  353. local previouslyDisplayedInvitations = DISPLAYED_COMMUNITIES_INVITATIONS;
  354. DISPLAYED_COMMUNITIES_INVITATIONS = {};
  355. local invitations = C_Club.GetInvitationsForSelf();
  356. for i, invitation in ipairs(invitations) do
  357. local clubId = invitation.club.clubId;
  358. DISPLAYED_COMMUNITIES_INVITATIONS[clubId] = previouslyDisplayedInvitations[clubId];
  359. end
  360. UpdateMicroButtons();
  361. elseif ( event == "STREAM_VIEW_MARKER_UPDATED" or event == "CLUB_INVITATION_ADDED_FOR_SELF" or event == "CLUB_INVITATION_REMOVED_FOR_SELF" ) then
  362. self:UpdateNotificationIcon(GuildMicroButton);
  363. elseif ( event == "CLUB_FINDER_COMMUNITY_OFFLINE_JOIN" ) then
  364. local newClubId = ...;
  365. self:SetNewClubId(newClubId);
  366. self.showOfflineJoinAlert = true;
  367. self:EvaluateAlertVisibility();
  368. elseif ( event == "CHAT_DISABLED_CHANGE_FAILED" or event == "CHAT_DISABLED_CHANGED" ) then
  369. self:UpdateNotificationIcon(GuildMicroButton);
  370. end
  371. end
  372. function GuildMicroButtonMixin:OnClick(button, down)
  373. if ( not KeybindFrames_InQuickKeybindMode() ) then
  374. ToggleGuildFrame();
  375. end
  376. end
  377. function GuildMicroButtonMixin:EvaluateAlertVisibility()
  378. if Kiosk.IsEnabled() then
  379. return false;
  380. end
  381. local alertShown = false;
  382. if (self.showOfflineJoinAlert) then
  383. alertShown = MainMenuMicroButton_ShowAlert(self, CLUB_FINDER_NEW_COMMUNITY_JOINED);
  384. if alertShown then
  385. self.showOfflineJoinAlert = false;
  386. end
  387. end
  388. return alertShown;
  389. end
  390. function GuildMicroButtonMixin:MarkCommunitiesInvitiationDisplayed(clubId)
  391. DISPLAYED_COMMUNITIES_INVITATIONS[clubId] = true;
  392. self:UpdateNotificationIcon(GuildMicroButton);
  393. end
  394. function GuildMicroButtonMixin:HasUnseenInvitations()
  395. local invitations = C_Club.GetInvitationsForSelf();
  396. for i, invitation in ipairs(invitations) do
  397. if not DISPLAYED_COMMUNITIES_INVITATIONS[invitation.club.clubId] then
  398. return true;
  399. end
  400. end
  401. return false;
  402. end
  403. function GuildMicroButtonMixin:UpdateNotificationIcon(self)
  404. if CommunitiesFrame_IsEnabled() and self:IsEnabled() then
  405. self.NotificationOverlay:SetShown(not C_SocialRestrictions.IsChatDisabled() and (self:HasUnseenInvitations() or CommunitiesUtil.DoesAnyCommunityHaveUnreadMessages()));
  406. else
  407. self.NotificationOverlay:SetShown(false);
  408. end
  409. end
  410. function GuildMicroButtonMixin:UpdateTabard(forceUpdate)
  411. local tabard = GuildMicroButtonTabard;
  412. if ( not tabard.needsUpdate and not forceUpdate ) then
  413. return;
  414. end
  415. -- switch textures if the guild has a custom tabard
  416. local emblemFilename = select(10, GetGuildLogoInfo());
  417. if ( emblemFilename ) then
  418. if ( not tabard:IsShown() ) then
  419. local button = GuildMicroButton;
  420. button:SetNormalAtlas("hud-microbutton-Character-Up", true);
  421. button:SetPushedAtlas("hud-microbutton-Character-Down", true);
  422. -- no need to change disabled texture, should always be available if you're in a guild
  423. tabard:Show();
  424. end
  425. SetSmallGuildTabardTextures("player", tabard.emblem, tabard.background);
  426. else
  427. if ( tabard:IsShown() ) then
  428. local button = GuildMicroButton;
  429. button:SetNormalAtlas("hud-microbutton-Socials-Up", true);
  430. button:SetPushedAtlas("hud-microbutton-Socials-Down", true);
  431. button:SetDisabledAtlas("hud-microbutton-Socials-Disabled", true);
  432. tabard:Hide();
  433. end
  434. end
  435. tabard.needsUpdate = nil;
  436. end
  437. function GuildMicroButtonMixin:SetNewClubId(newClubId)
  438. self.newClubId = newClubId;
  439. end
  440. function GuildMicroButtonMixin:GetNewClubId()
  441. return self.newClubId;
  442. end
  443. CharacterMicroButtonMixin = {};
  444. function CharacterMicroButtonMixin:OnLoad()
  445. self:RegisterEvent("UNIT_PORTRAIT_UPDATE");
  446. self:RegisterEvent("PORTRAITS_UPDATED");
  447. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  448. LoadMicroButtonTextures(self, "Character");
  449. self.tooltipText = MicroButtonTooltipText(CHARACTER_BUTTON, "TOGGLECHARACTER0");
  450. end
  451. function CharacterMicroButtonMixin:OnMouseDown()
  452. if ( not KeybindFrames_InQuickKeybindMode() ) then
  453. if ( self.down ) then
  454. self.down = nil;
  455. ToggleCharacter("PaperDollFrame");
  456. else
  457. CharacterMicroButton_SetPushed();
  458. self.down = 1;
  459. end
  460. end
  461. end
  462. function CharacterMicroButtonMixin:OnMouseUp(button)
  463. if ( KeybindFrames_InQuickKeybindMode() ) then
  464. self:QuickKeybindButtonOnClick(button);
  465. else
  466. if ( self.down ) then
  467. self.down = nil;
  468. if ( self:IsMouseOver() ) then
  469. ToggleCharacter("PaperDollFrame");
  470. end
  471. UpdateMicroButtons();
  472. elseif ( self:GetButtonState() == "NORMAL" ) then
  473. CharacterMicroButton_SetPushed();
  474. self.down = 1;
  475. else
  476. CharacterMicroButton_SetNormal();
  477. self.down = 1;
  478. end
  479. end
  480. end
  481. function CharacterMicroButtonMixin:OnEvent(event, ...)
  482. if ( event == "UNIT_PORTRAIT_UPDATE" ) then
  483. local unit = ...;
  484. if ( unit == "player" ) then
  485. SetPortraitTexture(MicroButtonPortrait, "player");
  486. end
  487. elseif ( event == "PORTRAITS_UPDATED" ) then
  488. SetPortraitTexture(MicroButtonPortrait, "player");
  489. elseif ( event == "PLAYER_ENTERING_WORLD" ) then
  490. SetPortraitTexture(MicroButtonPortrait, "player");
  491. elseif ( event == "UPDATE_BINDINGS" ) then
  492. self.tooltipText = MicroButtonTooltipText(CHARACTER_BUTTON, "TOGGLECHARACTER0");
  493. end
  494. end
  495. function CharacterMicroButton_SetPushed()
  496. MicroButtonPortrait:SetTexCoord(0.2666, 0.8666, 0, 0.8333);
  497. MicroButtonPortrait:SetAlpha(0.5);
  498. CharacterMicroButton:SetButtonState("PUSHED", true);
  499. end
  500. function CharacterMicroButton_SetNormal()
  501. MicroButtonPortrait:SetTexCoord(0.2, 0.8, 0.0666, 0.9);
  502. MicroButtonPortrait:SetAlpha(1.0);
  503. CharacterMicroButton:SetButtonState("NORMAL");
  504. end
  505. SpellbookMicroButtonMixin = {};
  506. function SpellbookMicroButtonMixin:OnLoad()
  507. LoadMicroButtonTextures(self, "Spellbook");
  508. self.tooltipText = MicroButtonTooltipText(SPELLBOOK_ABILITIES_BUTTON, "TOGGLESPELLBOOK");
  509. end
  510. function SpellbookMicroButtonMixin:OnClick(button, down)
  511. if ( not KeybindFrames_InQuickKeybindMode() ) then
  512. ToggleSpellBook(BOOKTYPE_SPELL);
  513. end
  514. end
  515. function SpellbookMicroButtonMixin:OnEvent(event, ...)
  516. if ( event == "UPDATE_BINDINGS" ) then
  517. self.tooltipText = MicroButtonTooltipText(SPELLBOOK_ABILITIES_BUTTON, "TOGGLESPELLBOOK");
  518. end
  519. end
  520. MainMenuMicroButtonMixin = {};
  521. function MainMenuMicroButtonMixin:OnLoad()
  522. LoadMicroButtonTextures(self, "MainMenu");
  523. self.tooltipText = MicroButtonTooltipText(MAINMENU_BUTTON, "TOGGLEGAMEMENU");
  524. self.newbieText = NEWBIE_TOOLTIP_MAINMENU;
  525. PERFORMANCEBAR_LOW_LATENCY = 300;
  526. PERFORMANCEBAR_MEDIUM_LATENCY = 600;
  527. self.hover = nil;
  528. self.updateInterval = 0;
  529. self:RegisterForClicks("AnyUp");
  530. end
  531. function MainMenuMicroButtonMixin:OnUpdate(elapsed)
  532. if ( self.updateInterval > 0 ) then
  533. self.updateInterval = self.updateInterval - elapsed;
  534. else
  535. self.updateInterval = PERFORMANCEBAR_UPDATE_INTERVAL;
  536. local status = GetFileStreamingStatus();
  537. if ( status == 0 ) then
  538. status = (GetBackgroundLoadingStatus()~=0) and 1 or 0;
  539. end
  540. if ( status == 0 ) then
  541. MainMenuBarDownload:Hide();
  542. self:SetNormalAtlas("hud-microbutton-MainMenu-Up", true);
  543. self:SetPushedAtlas("hud-microbutton-MainMenu-Down", true);
  544. self:SetDisabledAtlas("hud-microbutton-MainMenu-Disabled", true);
  545. else
  546. self:SetNormalTexture("Interface\\Buttons\\UI-MicroButtonStreamDL-Up");
  547. self:SetPushedTexture("Interface\\Buttons\\UI-MicroButtonStreamDL-Down");
  548. self:SetDisabledTexture("Interface\\Buttons\\UI-MicroButtonStreamDL-Up");
  549. if ( status == 1 ) then
  550. MainMenuBarDownload:SetTexture("Interface\\BUTTONS\\UI-MicroStream-Green");
  551. elseif ( status == 2 ) then
  552. MainMenuBarDownload:SetTexture("Interface\\BUTTONS\\UI-MicroStream-Yellow");
  553. elseif ( status == 3 ) then
  554. MainMenuBarDownload:SetTexture("Interface\\BUTTONS\\UI-MicroStream-Red");
  555. end
  556. MainMenuBarDownload:Show();
  557. end
  558. local bandwidthIn, bandwidthOut, latencyHome, latencyWorld = GetNetStats();
  559. local latency = latencyHome > latencyWorld and latencyHome or latencyWorld;
  560. if ( latency > PERFORMANCEBAR_MEDIUM_LATENCY ) then
  561. MainMenuBarPerformanceBar:SetVertexColor(1, 0, 0);
  562. elseif ( latency > PERFORMANCEBAR_LOW_LATENCY ) then
  563. MainMenuBarPerformanceBar:SetVertexColor(1, 1, 0);
  564. else
  565. MainMenuBarPerformanceBar:SetVertexColor(0, 1, 0);
  566. end
  567. if ( self.hover and not KeybindFrames_InQuickKeybindMode() ) then
  568. self.tooltipText = MicroButtonTooltipText(MAINMENU_BUTTON, "TOGGLEGAMEMENU");
  569. MainMenuBarPerformanceBarFrame_OnEnter(self);
  570. end
  571. end
  572. end
  573. function MainMenuMicroButtonMixin:OnMouseDown(button)
  574. self:SetPushed();
  575. self.down = 1;
  576. end
  577. function MainMenuMicroButtonMixin:OnMouseUp(button)
  578. if ( self.down ) then
  579. self.down = nil;
  580. if ( self:IsMouseOver() ) then
  581. if ( not GameMenuFrame:IsShown() ) then
  582. if ( VideoOptionsFrame:IsShown() ) then
  583. VideoOptionsFrameCancel:Click();
  584. elseif ( AudioOptionsFrame:IsShown() ) then
  585. AudioOptionsFrameCancel:Click();
  586. elseif ( InterfaceOptionsFrame:IsShown() ) then
  587. InterfaceOptionsFrameCancel:Click();
  588. end
  589. CloseMenus();
  590. CloseAllWindows();
  591. PlaySound(SOUNDKIT.IG_MAINMENU_OPEN);
  592. ShowUIPanel(GameMenuFrame);
  593. else
  594. PlaySound(SOUNDKIT.IG_MAINMENU_QUIT);
  595. HideUIPanel(GameMenuFrame);
  596. self:SetNormal();
  597. end
  598. end
  599. UpdateMicroButtons();
  600. return;
  601. end
  602. if ( self:GetButtonState() == "NORMAL" ) then
  603. self:SetPushed();
  604. self.down = 1;
  605. else
  606. self:SetNormal();
  607. self.down = 1;
  608. end
  609. end
  610. function MainMenuMicroButtonMixin:OnEnter()
  611. self.hover = 1;
  612. self.updateInterval = 0;
  613. if ( KeybindFrames_InQuickKeybindMode() ) then
  614. self:QuickKeybindButtonOnEnter();
  615. end
  616. end
  617. function MainMenuMicroButtonMixin:OnLeave()
  618. self.hover = nil;
  619. GameTooltip:Hide();
  620. if ( KeybindFrames_InQuickKeybindMode() ) then
  621. self:QuickKeybindButtonOnLeave();
  622. end
  623. end
  624. function MainMenuMicroButtonMixin:SetPushed()
  625. self:SetButtonState("PUSHED", true);
  626. end
  627. function MainMenuMicroButtonMixin:SetNormal()
  628. self:SetButtonState("NORMAL");
  629. end
  630. function MainMenuMicroButton_Init()
  631. g_microButtonAlertPriority = { CollectionsMicroButton, TalentMicroButton, EJMicroButton, GuildMicroButton };
  632. end
  633. function MainMenuMicroButton_SetAlertsEnabled(enabled, reason)
  634. if not reason then
  635. error("Must provide a reason");
  636. end
  637. if enabled then
  638. g_microButtonAlertsEnabledLocks[reason] = nil;
  639. else
  640. g_microButtonAlertsEnabledLocks[reason] = true;
  641. end
  642. MainMenuMicroButton_UpdateAlertsEnabled();
  643. end
  644. function MainMenuMicroButton_UpdateAlertsEnabled(microButtonToSkip)
  645. if MainMenuMicroButton_AreAlertsEnabled() then
  646. -- If anything is shown, leave it in that state
  647. if g_activeMicroButtonAlert then
  648. return;
  649. end
  650. -- Nothing shown, try evaluating its visibility
  651. for priority, microButton in ipairs(g_microButtonAlertPriority) do
  652. if microButtonToSkip ~= microButton then
  653. if microButton:EvaluateAlertVisibility() then
  654. return;
  655. end
  656. end
  657. end
  658. else
  659. if g_activeMicroButtonAlert then
  660. HelpTip:HideAllSystem("MicroButtons");
  661. end
  662. for flashingButton in pairs(g_flashingMicroButtons) do
  663. MicroButtonPulseStop(flashingButton);
  664. end
  665. g_flashingMicroButtons = {};
  666. end
  667. -- wipe acknowledgements so future events can still show the appropriate ones
  668. wipe(g_acknowledgedMicroButtonAlerts);
  669. end
  670. function MainMenuMicroButton_AreAlertsEnabled()
  671. return not next(g_microButtonAlertsEnabledLocks);
  672. end
  673. function MainMenuMicroButton_GetAlertPriority(microButton)
  674. for priority, frame in ipairs(g_microButtonAlertPriority) do
  675. if frame == microButton then
  676. return priority;
  677. end
  678. end
  679. return math.huge;
  680. end
  681. local function MainMenuMicroButton_OnAlertClose(acknowledged, microButton)
  682. if not g_processAlertCloseCallback then
  683. return;
  684. end
  685. if acknowledged then
  686. g_acknowledgedMicroButtonAlerts[microButton] = true;
  687. end
  688. g_activeMicroButtonAlert = nil;
  689. MainMenuMicroButton_UpdateAlertsEnabled(microButton);
  690. end
  691. function MainMenuMicroButton_ShowAlert(microButton, text, tutorialIndex, cvarBitfield)
  692. if not MainMenuMicroButton_AreAlertsEnabled() then
  693. return false;
  694. end
  695. if g_acknowledgedMicroButtonAlerts[microButton] then
  696. return false;
  697. end
  698. cvarBitfield = cvarBitfield or "closedInfoFrames";
  699. if tutorialIndex and GetCVarBitfield(cvarBitfield, tutorialIndex) then
  700. return false;
  701. end
  702. if g_activeMicroButtonAlert then
  703. local visiblePriority = MainMenuMicroButton_GetAlertPriority(g_activeMicroButtonAlert);
  704. local thisPriority = MainMenuMicroButton_GetAlertPriority(microButton);
  705. if visiblePriority < thisPriority then
  706. -- Higher priority is shown
  707. return false;
  708. else
  709. -- Lower priority alert is visible, kill it
  710. g_processAlertCloseCallback = false;
  711. HelpTip:HideAllSystem("MicroButtons");
  712. g_processAlertCloseCallback = true;
  713. end
  714. end
  715. local helpTipInfo = {
  716. text = text,
  717. buttonStyle = HelpTip.ButtonStyle.Close,
  718. targetPoint = HelpTip.Point.TopEdgeCenter,
  719. system = "MicroButtons",
  720. onHideCallback = MainMenuMicroButton_OnAlertClose,
  721. callbackArg = microButton,
  722. autoHorizontalSlide = true,
  723. };
  724. if tutorialIndex then
  725. helpTipInfo.cvarBitfield = cvarBitfield;
  726. helpTipInfo.bitfieldFlag = tutorialIndex;
  727. end
  728. if HelpTip:Show(UIParent, helpTipInfo, microButton) then
  729. g_activeMicroButtonAlert = microButton;
  730. end
  731. return true;
  732. end
  733. function MainMenuMicroButton_HideAlert(microButton)
  734. if g_activeMicroButtonAlert == microButton then
  735. HelpTip:HideAllSystem("MicroButtons");
  736. end
  737. end
  738. TalentMicroButtonMixin = {};
  739. function TalentMicroButtonMixin:OnLoad()
  740. LoadMicroButtonTextures(self, "Talents");
  741. self.tooltipText = MicroButtonTooltipText(TALENTS_BUTTON, "TOGGLETALENTS");
  742. self.newbieText = NEWBIE_TOOLTIP_TALENTS;
  743. self.disabledTooltip = function()
  744. local _, failureReason = C_SpecializationInfo.CanPlayerUseTalentSpecUI();
  745. return failureReason;
  746. end
  747. self:RegisterEvent("PLAYER_TALENT_UPDATE");
  748. self:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED");
  749. self:RegisterEvent("UPDATE_BATTLEFIELD_STATUS");
  750. self:RegisterEvent("HONOR_LEVEL_UPDATE");
  751. self:RegisterEvent("PLAYER_PVP_TALENT_UPDATE");
  752. self:RegisterEvent("PLAYER_LEVEL_CHANGED");
  753. end
  754. local TALENT_FRAME_PRIORITIES =
  755. {
  756. TALENT_MICRO_BUTTON_SPEC_TUTORIAL = 1,
  757. TALENT_MICRO_BUTTON_TALENT_TUTORIAL = 2,
  758. TALENT_MICRO_BUTTON_NO_SPEC = 3,
  759. TALENT_MICRO_BUTTON_UNSPENT_TALENTS = 4,
  760. TALENT_MICRO_BUTTON_UNSPENT_PVP_TALENT_SLOT = 5,
  761. TALENT_MICRO_BUTTON_NEW_PVP_TALENT = 6,
  762. }
  763. local LOWEST_TALENT_FRAME_PRIORITY = 1000;
  764. function TalentMicroButtonMixin:HasTalentAlertToShow()
  765. if not IsPlayerInWorld() then
  766. return nil, LOWEST_TALENT_FRAME_PRIORITY;
  767. end
  768. local canUseTalentSpecUI = C_SpecializationInfo.CanPlayerUseTalentSpecUI();
  769. if self.canUseTalentSpecUI == nil then
  770. self.canUseTalentSpecUI = canUseTalentSpecUI;
  771. end
  772. local canUseTalentUI = C_SpecializationInfo.CanPlayerUseTalentUI();
  773. if self.canUseTalentUI == nil then
  774. self.canUseTalentUI = canUseTalentUI;
  775. end
  776. local alert;
  777. if not self.canUseTalentSpecUI and canUseTalentSpecUI then
  778. alert = "TALENT_MICRO_BUTTON_SPEC_TUTORIAL";
  779. elseif not self.canUseTalentUI and canUseTalentUI then
  780. alert = "TALENT_MICRO_BUTTON_TALENT_TUTORIAL";
  781. elseif canUseTalentSpecUI and IsPlayerInitialSpec() then
  782. alert = "TALENT_MICRO_BUTTON_NO_SPEC";
  783. elseif canUseTalentUI and not AreTalentsLocked() and GetNumUnspentTalents() > 0 then
  784. alert = "TALENT_MICRO_BUTTON_UNSPENT_TALENTS";
  785. end
  786. self.canUseTalentSpecUI = canUseTalentSpecUI;
  787. self.canUseTalentUI = canUseTalentUI;
  788. return _G[alert], TALENT_FRAME_PRIORITIES[alert] or LOWEST_TALENT_FRAME_PRIORITY;
  789. end
  790. function TalentMicroButtonMixin:HasPvpTalentAlertToShow()
  791. local isInterestedInPvP = C_PvP.IsWarModeDesired() or PVPUtil.IsInActiveBattlefield();
  792. if not isInterestedInPvP or not IsPlayerInWorld() or not C_SpecializationInfo.CanPlayerUsePVPTalentUI() then
  793. return nil, LOWEST_TALENT_FRAME_PRIORITY;
  794. end
  795. local alert;
  796. local hasEmptySlot, hasNewTalent = C_SpecializationInfo.GetPvpTalentAlertStatus();
  797. if (hasEmptySlot) then
  798. alert = "TALENT_MICRO_BUTTON_UNSPENT_PVP_TALENT_SLOT";
  799. elseif (hasNewTalent) then
  800. alert = "TALENT_MICRO_BUTTON_NEW_PVP_TALENT";
  801. end
  802. return _G[alert], TALENT_FRAME_PRIORITIES[alert] or LOWEST_TALENT_FRAME_PRIORITY;
  803. end
  804. function TalentMicroButtonMixin:EvaluateAlertVisibility()
  805. local alertText, alertPriority = self:HasTalentAlertToShow();
  806. local pvpAlertText, pvpAlertPriority = self:HasPvpTalentAlertToShow();
  807. if not alertText or pvpAlertPriority < alertPriority then
  808. -- pvpAlert is higher priority, use that instead
  809. alertText = pvpAlertText;
  810. end
  811. if not alertText then
  812. MicroButtonPulseStop(self);
  813. return false;
  814. end
  815. if not PlayerTalentFrame or not PlayerTalentFrame:IsShown() then
  816. if MainMenuMicroButton_ShowAlert(self, alertText) then
  817. MicroButtonPulse(self);
  818. if IsPlayerInitialSpec() then
  819. TalentMicroButton.suggestedTab = 1;
  820. else
  821. TalentMicroButton.suggestedTab = 2;
  822. end
  823. return true;
  824. end
  825. end
  826. TalentMicroButton.suggestedTab = nil;
  827. return false;
  828. end
  829. --Talent button specific functions
  830. function TalentMicroButtonMixin:OnEvent(event, ...)
  831. if ( event == "PLAYER_SPECIALIZATION_CHANGED" or event == "PLAYER_LEVEL_CHANGED" or event == "UPDATE_BATTLEFIELD_STATUS" ) then
  832. self:EvaluateAlertVisibility();
  833. elseif ( event == "PLAYER_TALENT_UPDATE" or event == "NEUTRAL_FACTION_SELECT_RESULT" or event == "HONOR_LEVEL_UPDATE" ) then
  834. UpdateMicroButtons();
  835. self:EvaluateAlertVisibility();
  836. elseif ( event == "UPDATE_BINDINGS" ) then
  837. self.tooltipText = MicroButtonTooltipText(TALENTS_BUTTON, "TOGGLETALENTS");
  838. end
  839. end
  840. function TalentMicroButtonMixin:OnClick(button, down)
  841. if ( not KeybindFrames_InQuickKeybindMode() ) then
  842. ToggleTalentFrame(self.suggestedTab);
  843. end
  844. end
  845. local function SafeSetCollectionJournalTab(tab)
  846. if CollectionsJournal_SetTab then
  847. CollectionsJournal_SetTab(CollectionsJournal, tab);
  848. else
  849. SetCVar("petJournalTab", tab);
  850. end
  851. end
  852. CollectionMicroButtonMixin = {};
  853. function CollectionMicroButtonMixin:EvaluateAlertVisibility()
  854. if Kiosk.IsEnabled() then
  855. return false;
  856. end
  857. if CollectionsJournal and CollectionsJournal:IsShown() then
  858. return false;
  859. end
  860. local numMountsNeedingFanfare = C_MountJournal.GetNumMountsNeedingFanfare();
  861. local numPetsNeedingFanfare = C_PetJournal.GetNumPetsNeedingFanfare();
  862. local alertShown = false;
  863. if numMountsNeedingFanfare > self.lastNumMountsNeedingFanfare or numPetsNeedingFanfare > self.lastNumPetsNeedingFanfare then
  864. alertShown = MainMenuMicroButton_ShowAlert(self, numMountsNeedingFanfare + numPetsNeedingFanfare > 1 and COLLECTION_UNOPENED_PLURAL or COLLECTION_UNOPENED_SINGULAR);
  865. if alertShown then
  866. MicroButtonPulse(self);
  867. SafeSetCollectionJournalTab(numMountsNeedingFanfare > 0 and 1 or 2);
  868. end
  869. end
  870. self.lastNumMountsNeedingFanfare = numMountsNeedingFanfare;
  871. self.lastNumPetsNeedingFanfare = numPetsNeedingFanfare;
  872. return alertShown;
  873. end
  874. function CollectionMicroButtonMixin:OnLoad()
  875. LoadMicroButtonTextures(self, "Mounts");
  876. SetDesaturation(self:GetDisabledTexture(), true);
  877. self:RegisterEvent("HEIRLOOMS_UPDATED");
  878. self:RegisterEvent("PET_JOURNAL_NEW_BATTLE_SLOT");
  879. self:RegisterEvent("TOYS_UPDATED");
  880. self:RegisterEvent("COMPANION_LEARNED");
  881. self:RegisterEvent("PET_JOURNAL_LIST_UPDATE");
  882. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  883. self.tooltipText = MicroButtonTooltipText(COLLECTIONS, "TOGGLECOLLECTIONS");
  884. end
  885. function CollectionMicroButtonMixin:OnEvent(event, ...)
  886. if CollectionsJournal and CollectionsJournal:IsShown() then
  887. return;
  888. end
  889. if ( event == "HEIRLOOMS_UPDATED" ) then
  890. local itemID, updateReason = ...;
  891. if itemID and updateReason == "NEW" then
  892. if MainMenuMicroButton_ShowAlert(CollectionsMicroButton, HEIRLOOMS_MICRO_BUTTON_SPEC_TUTORIAL, LE_FRAME_TUTORIAL_HEIRLOOM_JOURNAL) then
  893. local tabIndex = 4;
  894. CollectionsMicroButton_SetAlert(tabIndex);
  895. end
  896. end
  897. elseif ( event == "PET_JOURNAL_NEW_BATTLE_SLOT" ) then
  898. if MainMenuMicroButton_ShowAlert(CollectionsMicroButton, COMPANIONS_MICRO_BUTTON_NEW_BATTLE_SLOT) then
  899. local tabIndex = 2;
  900. CollectionsMicroButton_SetAlert(tabIndex);
  901. end
  902. elseif ( event == "TOYS_UPDATED" ) then
  903. local itemID, new = ...;
  904. if itemID and new then
  905. if MainMenuMicroButton_ShowAlert(CollectionsMicroButton, TOYBOX_MICRO_BUTTON_SPEC_TUTORIAL, LE_FRAME_TUTORIAL_TOYBOX) then
  906. local tabIndex = 3;
  907. CollectionsMicroButton_SetAlert(tabIndex);
  908. end
  909. end
  910. elseif ( event == "COMPANION_LEARNED" or event == "PLAYER_ENTERING_WORLD" or event == "PET_JOURNAL_LIST_UPDATE" ) then
  911. self:EvaluateAlertVisibility();
  912. elseif ( event == "UPDATE_BINDINGS" ) then
  913. self.tooltipText = MicroButtonTooltipText(COLLECTIONS, "TOGGLECOLLECTIONS");
  914. end
  915. end
  916. function CollectionsMicroButton_SetAlert(tabIndex)
  917. CollectionsMicroButton_SetAlertShown(true);
  918. SafeSetCollectionJournalTab(tabIndex);
  919. end
  920. function CollectionsMicroButton_SetAlertShown(shown)
  921. if shown then
  922. MicroButtonPulse(CollectionsMicroButton);
  923. else
  924. MicroButtonPulseStop(CollectionsMicroButton);
  925. end
  926. end
  927. function CollectionMicroButtonMixin:OnClick(button, down)
  928. if ( not KeybindFrames_InQuickKeybindMode() ) then
  929. ToggleCollectionsJournal();
  930. end
  931. end
  932. -- Encounter Journal
  933. EJMicroButtonMixin = {};
  934. local EJMicroButtonEvents = {
  935. "NEW_RUNEFORGE_POWER_ADDED",
  936. };
  937. function EJMicroButtonMixin:OnLoad()
  938. LoadMicroButtonTextures(self, "EJ");
  939. SetDesaturation(self:GetDisabledTexture(), true);
  940. self.tooltipText = MicroButtonTooltipText(ENCOUNTER_JOURNAL, "TOGGLEENCOUNTERJOURNAL");
  941. self.newbieText = NEWBIE_TOOLTIP_ENCOUNTER_JOURNAL;
  942. --events that can trigger a refresh of the adventure journal
  943. self:RegisterEvent("VARIABLES_LOADED");
  944. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  945. self:RegisterEvent("ZONE_CHANGED_NEW_AREA");
  946. end
  947. function EJMicroButtonMixin:EvaluateAlertVisibility()
  948. local alertShown = false;
  949. if self.playerEntered and self.varsLoaded and self.zoneEntered then
  950. if self:IsEnabled() then
  951. local showAlert = not Kiosk.IsEnabled() and not GetCVarBool("hideAdventureJournalAlerts");
  952. if( showAlert ) then
  953. -- display alert if the player hasn't opened the journal for a long time
  954. local lastTimeOpened = tonumber(GetCVar("advJournalLastOpened"));
  955. if ( GetServerTime() - lastTimeOpened > EJ_ALERT_TIME_DIFF ) then
  956. alertShown = MainMenuMicroButton_ShowAlert(self, AJ_MICRO_BUTTON_ALERT_TEXT);
  957. if alertShown then
  958. MicroButtonPulse(EJMicroButton);
  959. end
  960. end
  961. if ( lastTimeOpened ~= 0 ) then
  962. SetCVar("advJournalLastOpened", GetServerTime() );
  963. end
  964. self:UpdateAlerts(true);
  965. end
  966. self:UpdateLastEvaluations();
  967. end
  968. end
  969. if not alertShown and self.runeforgePowerAdded and not GetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_FIRST_RUNEFORGE_LEGENDARY_POWER) then
  970. alertShown = MainMenuMicroButton_ShowAlert(self, FIRST_RUNEFORGE_LEGENDARY_POWER_TUTORIAL, LE_FRAME_TUTORIAL_FIRST_RUNEFORGE_LEGENDARY_POWER);
  971. if alertShown then
  972. MicroButtonPulse(EJMicroButton);
  973. end
  974. end
  975. return alertShown;
  976. end
  977. function EJMicroButtonMixin:UpdateLastEvaluations()
  978. local playerLevel = UnitLevel("player");
  979. self.lastEvaluatedLevel = playerLevel;
  980. if (playerLevel == GetMaxLevelForPlayerExpansion()) then
  981. local spec = GetSpecialization();
  982. local ilvl = GetAverageItemLevel();
  983. self.lastEvaluatedSpec = spec;
  984. self.lastEvaluatedIlvl = ilvl;
  985. end
  986. end
  987. function EJMicroButtonMixin:OnShow()
  988. FrameUtil.RegisterFrameForEvents(self, EJMicroButtonEvents);
  989. MicroButton_KioskModeDisable(self);
  990. end
  991. function EJMicroButtonMixin:OnHide()
  992. FrameUtil.UnregisterFrameForEvents(self, EJMicroButtonEvents);
  993. end
  994. function EJMicroButtonMixin:OnEvent(event, ...)
  995. if( event == "UPDATE_BINDINGS" ) then
  996. self.tooltipText = MicroButtonTooltipText(ADVENTURE_JOURNAL, "TOGGLEENCOUNTERJOURNAL");
  997. self.newbieText = NEWBIE_TOOLTIP_ENCOUNTER_JOURNAL;
  998. UpdateMicroButtons();
  999. elseif( event == "VARIABLES_LOADED" ) then
  1000. self:UnregisterEvent("VARIABLES_LOADED");
  1001. self.varsLoaded = true;
  1002. elseif ( event == "PLAYER_ENTERING_WORLD" ) then
  1003. self.lastEvaluatedLevel = UnitLevel("player");
  1004. self:UnregisterEvent("PLAYER_ENTERING_WORLD");
  1005. self.playerEntered = true;
  1006. elseif ( event == "UNIT_LEVEL" ) then
  1007. local unitToken = ...;
  1008. if unitToken == "player" and (not self.lastEvaluatedLevel or UnitLevel(unitToken) > self.lastEvaluatedLevel) then
  1009. self.lastEvaluatedLevel = UnitLevel(unitToken);
  1010. if ( self:IsEnabled() ) then
  1011. C_AdventureJournal.UpdateSuggestions(true);
  1012. end
  1013. end
  1014. elseif ( event == "PLAYER_AVG_ITEM_LEVEL_UPDATE" ) then
  1015. local playerLevel = UnitLevel("player");
  1016. local spec = GetSpecialization();
  1017. local ilvl = GetAverageItemLevel();
  1018. if ( playerLevel == GetMaxLevelForPlayerExpansion() and ((not self.lastEvaluatedSpec or self.lastEvaluatedSpec ~= spec) or (not self.lastEvaluatedIlvl or self.lastEvaluatedIlvl < ilvl))) then
  1019. self.lastEvaluatedSpec = spec;
  1020. self.lastEvaluatedIlvl = ilvl;
  1021. if ( self:IsEnabled() ) then
  1022. C_AdventureJournal.UpdateSuggestions(false);
  1023. end
  1024. end
  1025. elseif ( event == "ZONE_CHANGED_NEW_AREA" ) then
  1026. self:UnregisterEvent("ZONE_CHANGED_NEW_AREA");
  1027. self.zoneEntered = true;
  1028. elseif ( event == "NEW_RUNEFORGE_POWER_ADDED" ) then
  1029. local powerID = ...;
  1030. self.runeforgePowerAdded = powerID;
  1031. self:EvaluateAlertVisibility();
  1032. end
  1033. if( event == "PLAYER_ENTERING_WORLD" or event == "VARIABLES_LOADED" or event == "ZONE_CHANGED_NEW_AREA" ) then
  1034. if self.playerEntered and self.varsLoaded and self.zoneEntered then
  1035. self:UpdateDisplay();
  1036. if self:IsEnabled() then
  1037. C_AdventureJournal.UpdateSuggestions();
  1038. self:EvaluateAlertVisibility();
  1039. end
  1040. end
  1041. end
  1042. end
  1043. function EJMicroButtonMixin:UpdateNewAdventureNotice()
  1044. if ( self:IsEnabled()) then
  1045. if ( not EncounterJournal or not EncounterJournal:IsShown() ) then
  1046. self.Flash:Show();
  1047. self.NewAdventureNotice:Show();
  1048. end
  1049. end
  1050. end
  1051. function EJMicroButtonMixin:ClearNewAdventureNotice()
  1052. self.Flash:Hide();
  1053. self.NewAdventureNotice:Hide();
  1054. end
  1055. function EJMicroButtonMixin:UpdateDisplay()
  1056. if ( EncounterJournal and EncounterJournal:IsShown() ) then
  1057. self:SetButtonState("PUSHED", true);
  1058. else
  1059. local inKioskMode = Kiosk.IsEnabled();
  1060. local disabled = inKioskMode or not C_AdventureJournal.CanBeShown();
  1061. if ( disabled ) then
  1062. self:Disable();
  1063. self.disabledTooltip = inKioskMode and ERR_SYSTEM_DISABLED or FEATURE_NOT_YET_AVAILABLE;
  1064. self:ClearNewAdventureNotice();
  1065. else
  1066. self:Enable();
  1067. self:SetButtonState("NORMAL");
  1068. end
  1069. end
  1070. end
  1071. function EJMicroButtonMixin:UpdateAlerts(flag)
  1072. if ( flag ) then
  1073. self:RegisterEvent("UNIT_LEVEL");
  1074. self:RegisterEvent("PLAYER_AVG_ITEM_LEVEL_UPDATE");
  1075. if (self:IsEnabled()) then
  1076. C_AdventureJournal.UpdateSuggestions(false);
  1077. end
  1078. else
  1079. self:UnregisterEvent("UNIT_LEVEL");
  1080. self:UnregisterEvent("PLAYER_AVG_ITEM_LEVEL_UPDATE");
  1081. self:ClearNewAdventureNotice()
  1082. end
  1083. end
  1084. function EJMicroButtonMixin:OnClick(button, down)
  1085. if ( not KeybindFrames_InQuickKeybindMode() ) then
  1086. ToggleEncounterJournal();
  1087. end
  1088. end
  1089. function EJMicroButtonMixin:ShouldShowPowerTab(button, down)
  1090. return (self.runeforgePowerAdded ~= nil) and not GetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_FIRST_RUNEFORGE_LEGENDARY_POWER), self.runeforgePowerAdded;
  1091. end
  1092. StoreMicroButtonMixin = {};
  1093. function StoreMicroButtonMixin:OnLoad()
  1094. LoadMicroButtonTextures(self, "BStore");
  1095. self.tooltipText = BLIZZARD_STORE;
  1096. self:RegisterEvent("STORE_STATUS_CHANGED");
  1097. if ( Kiosk.IsEnabled() ) then
  1098. self:Disable();
  1099. end
  1100. if ( IsRestrictedAccount() ) then
  1101. self:RegisterEvent("PLAYER_LEVEL_UP");
  1102. self:RegisterEvent("PLAYER_ENTERING_WORLD");
  1103. end
  1104. end
  1105. function StoreMicroButtonMixin:OnEvent(event, ...)
  1106. if ( event == "PLAYER_LEVEL_UP" ) then
  1107. local level = ...;
  1108. self:EvaluateAlertVisibility(level);
  1109. elseif ( event == "PLAYER_ENTERING_WORLD" ) then
  1110. self:EvaluateAlertVisibility(UnitLevel("player"));
  1111. end
  1112. UpdateMicroButtons();
  1113. if (Kiosk.IsEnabled()) then
  1114. self:Disable();
  1115. end
  1116. end
  1117. function StoreMicroButtonMixin:EvaluateAlertVisibility(level)
  1118. local alertShown = false;
  1119. if (IsTrialAccount()) then
  1120. local rLevel = GetRestrictedAccountData();
  1121. if (level >= rLevel and not GetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_TRIAL_BANKED_XP)) then
  1122. alertShown = MainMenuMicroButton_ShowAlert(self, STORE_MICRO_BUTTON_ALERT_TRIAL_CAP_REACHED);
  1123. if alertShown then
  1124. SetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_TRIAL_BANKED_XP, true);
  1125. end
  1126. end
  1127. end
  1128. return alertShown;
  1129. end
  1130. QuestLogMicroButtonMixin = {};
  1131. function QuestLogMicroButtonMixin:OnLoad()
  1132. LoadMicroButtonTextures(self, "Quest");
  1133. self:UpdateTooltipText();
  1134. end
  1135. function QuestLogMicroButtonMixin:OnEvent(event, ...)
  1136. if ( event == "UPDATE_BINDINGS" ) then
  1137. self:UpdateTooltipText();
  1138. end
  1139. end
  1140. function QuestLogMicroButtonMixin:UpdateTooltipText()
  1141. self.tooltipText = MicroButtonTooltipText(QUESTLOG_BUTTON, "TOGGLEQUESTLOG");
  1142. self.newbieText = NEWBIE_TOOLTIP_QUESTLOG;
  1143. end
  1144. function QuestLogMicroButtonMixin:OnClick(button)
  1145. if ( not KeybindFrames_InQuickKeybindMode() ) then
  1146. ToggleQuestLog();
  1147. end
  1148. end