MainMenuBarMicroButtons.lua

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