Blizzard_EncounterJournal/Blizzard_EncounterJournal.lua

Blizzard_EncounterJournal/Blizzard_EncounterJournal.lua (9.1.5.40906; unchanged since 9.1.5.40871)
  1. --FILE CONSTANTS
  2. local HEADER_INDENT = 15;
  3. local MAX_CREATURES_PER_ENCOUNTER = 9;
  4. local SECTION_BUTTON_OFFSET = 6;
  5. local SECTION_DESCRIPTION_OFFSET = 27;
  6. local EJ_STYPE_ITEM = 0;
  7. local EJ_STYPE_ENCOUNTER = 1;
  8. local EJ_STYPE_CREATURE = 2;
  9. local EJ_STYPE_SECTION = 3;
  10. local EJ_STYPE_INSTANCE = 4;
  11. local EJ_HTYPE_OVERVIEW = 3;
  12. local EJ_NUM_INSTANCE_PER_ROW = 4;
  13. local EJ_LORE_MAX_HEIGHT = 97;
  14. local EJ_MAX_SECTION_MOVE = 320;
  15. local EJ_NUM_SEARCH_PREVIEWS = 5;
  16. local EJ_SHOW_ALL_SEARCH_RESULTS_INDEX = EJ_NUM_SEARCH_PREVIEWS + 1;
  17. local EJ_TIER_INDEX_SHADOWLANDS = 9;
  18. local EncounterJournalData = {};
  19. EncounterJournalData.lootDividerIndex = nil;
  20. EncounterJournalData.itemLootCount = 0;
  21. EncounterJournalData.itemInfoList = {};
  22. AJ_MAX_NUM_SUGGESTIONS = 3;
  23. -- Priority list for *not my spec*
  24. local overviewPriorities = {
  25. [1] = "DAMAGER",
  26. [2] = "HEALER",
  27. [3] = "TANK",
  28. [4] = "NONE",
  29. }
  30. local NONE_FLAG = -1;
  31. local flagsByRole = {
  32. ["DAMAGER"] = 1,
  33. ["HEALER"] = 2,
  34. ["TANK"] = 0,
  35. ["NONE"] = NONE_FLAG,
  36. }
  37. local EJ_Tabs = {};
  38. EJ_Tabs[1] = {frame="overviewScroll", button="overviewTab"};
  39. EJ_Tabs[2] = {frame="lootScroll", button="lootTab"};
  40. EJ_Tabs[3] = {frame="detailsScroll", button="bossTab"};
  41. EJ_Tabs[4] = {frame="model", button="modelTab"};
  42. local EJ_section_openTable = {};
  43. local EJ_LINK_INSTANCE = 0;
  44. local EJ_LINK_ENCOUNTER = 1;
  45. local EJ_LINK_SECTION = 3;
  46. local EJ_DIFFICULTIES = {
  47. DifficultyUtil.ID.DungeonNormal,
  48. DifficultyUtil.ID.DungeonHeroic,
  49. DifficultyUtil.ID.DungeonMythic,
  50. DifficultyUtil.ID.DungeonTimewalker,
  51. DifficultyUtil.ID.RaidLFR,
  52. DifficultyUtil.ID.Raid10Normal,
  53. DifficultyUtil.ID.Raid10Heroic,
  54. DifficultyUtil.ID.Raid25Normal,
  55. DifficultyUtil.ID.Raid25Heroic,
  56. DifficultyUtil.ID.PrimaryRaidLFR,
  57. DifficultyUtil.ID.PrimaryRaidNormal,
  58. DifficultyUtil.ID.PrimaryRaidHeroic,
  59. DifficultyUtil.ID.PrimaryRaidMythic,
  60. DifficultyUtil.ID.RaidTimewalker,
  61. };
  62. local function IsEJDifficulty(difficultyID)
  63. return tContains(EJ_DIFFICULTIES, difficultyID);
  64. end
  65. local function GetEJDifficultySize(difficultyID)
  66. if difficultyID ~= DifficultyUtil.ID.RaidTimewalker and not DifficultyUtil.IsPrimaryRaid(difficultyID) then
  67. return DifficultyUtil.GetMaxPlayers(difficultyID);
  68. end
  69. return nil;
  70. end
  71. local function GetEJDifficultyString(difficultyID)
  72. local name = DifficultyUtil.GetDifficultyName(difficultyID);
  73. local size = GetEJDifficultySize(difficultyID);
  74. if size then
  75. return string.format(ENCOUNTER_JOURNAL_DIFF_TEXT, size, name);
  76. else
  77. return name;
  78. end
  79. end
  80. local EJ_TIER_DATA =
  81. {
  82. [1] = { backgroundAtlas = "UI-EJ-Classic", r = 1.0, g = 0.8, b = 0.0 },
  83. [2] = { backgroundAtlas = "UI-EJ-BurningCrusade", r = 0.6, g = 0.8, b = 0.0 },
  84. [3] = { backgroundAtlas = "UI-EJ-WrathoftheLichKing", r = 0.2, g = 0.8, b = 1.0 },
  85. [4] = { backgroundAtlas = "UI-EJ-Cataclysm", r = 1.0, g = 0.4, b = 0.0 },
  86. [5] = { backgroundAtlas = "UI-EJ-MistsofPandaria", r = 0.0, g = 0.6, b = 0.2 },
  87. [6] = { backgroundAtlas = "UI-EJ-WarlordsofDraenor", r = 0.82, g = 0.55, b = 0.1 },
  88. [7] = { backgroundAtlas = "UI-EJ-Legion", r = 0.0, g = 0.6, b = 0.2 },
  89. [8] = { backgroundAtlas = "UI-EJ-BattleforAzeroth", r = 0.8, g = 0.4, b = 0.0 },
  90. [9] = { backgroundAtlas = "UI-EJ-Shadowlands", r = 0.278, g = 0.471, b = .937 },
  91. }
  92. EJButtonMixin = {}
  93. function EJButtonMixin:OnLoad()
  94. local l, t, _, b, r = self.UpLeft:GetTexCoord();
  95. self.UpLeft:SetTexCoord(l, l + (r-l)/2, t, b);
  96. l, t, _, b, r = self.UpRight:GetTexCoord();
  97. self.UpRight:SetTexCoord(l + (r-l)/2, r, t, b);
  98. l, t, _, b, r = self.DownLeft:GetTexCoord();
  99. self.DownLeft:SetTexCoord(l, l + (r-l)/2, t, b);
  100. l, t, _, b, r = self.DownRight:GetTexCoord();
  101. self.DownRight:SetTexCoord(l + (r-l)/2, r, t, b);
  102. l, t, _, b, r = self.HighLeft:GetTexCoord();
  103. self.HighLeft:SetTexCoord(l, l + (r-l)/2, t, b);
  104. l, t, _, b, r = self.HighRight:GetTexCoord();
  105. self.HighRight:SetTexCoord(l + (r-l)/2, r, t, b);
  106. end
  107. function EJButtonMixin:OnMouseDown(button)
  108. self.UpLeft:Hide();
  109. self.UpRight:Hide();
  110. self.DownLeft:Show();
  111. self.DownRight:Show();
  112. end
  113. function EJButtonMixin:OnMouseUp(button)
  114. self.UpLeft:Show();
  115. self.UpRight:Show();
  116. self.DownLeft:Hide();
  117. self.DownRight:Hide();
  118. end
  119. function GetEJTierData(tier)
  120. return EJ_TIER_DATA[tier] or EJ_TIER_DATA[1];
  121. end
  122. ExpansionEnumToEJTierDataTableId = {
  123. [LE_EXPANSION_CLASSIC] = 1,
  124. [LE_EXPANSION_BURNING_CRUSADE] = 2,
  125. [LE_EXPANSION_WRATH_OF_THE_LICH_KING] = 3,
  126. [LE_EXPANSION_CATACLYSM] = 4,
  127. [LE_EXPANSION_MISTS_OF_PANDARIA] = 5,
  128. [LE_EXPANSION_WARLORDS_OF_DRAENOR] = 6,
  129. [LE_EXPANSION_LEGION] = 7,
  130. [LE_EXPANSION_BATTLE_FOR_AZEROTH] = 8,
  131. [LE_EXPANSION_SHADOWLANDS] = 9,
  132. }
  133. function GetEJTierDataTableID(expansion)
  134. local data = ExpansionEnumToEJTierDataTableId[expansion];
  135. if data then
  136. return data;
  137. end
  138. return ExpansionEnumToEJTierDataTableId[LE_EXPANSION_CLASSIC];
  139. end
  140. local SlotFilterToSlotName = {
  141. [Enum.ItemSlotFilterType.Head] = INVTYPE_HEAD,
  142. [Enum.ItemSlotFilterType.Neck] = INVTYPE_NECK,
  143. [Enum.ItemSlotFilterType.Shoulder] = INVTYPE_SHOULDER,
  144. [Enum.ItemSlotFilterType.Cloak] = INVTYPE_CLOAK,
  145. [Enum.ItemSlotFilterType.Chest] = INVTYPE_CHEST,
  146. [Enum.ItemSlotFilterType.Wrist] = INVTYPE_WRIST,
  147. [Enum.ItemSlotFilterType.Hand] = INVTYPE_HAND,
  148. [Enum.ItemSlotFilterType.Waist] = INVTYPE_WAIST,
  149. [Enum.ItemSlotFilterType.Legs] = INVTYPE_LEGS,
  150. [Enum.ItemSlotFilterType.Feet] = INVTYPE_FEET,
  151. [Enum.ItemSlotFilterType.MainHand] = INVTYPE_WEAPONMAINHAND,
  152. [Enum.ItemSlotFilterType.OffHand] = INVTYPE_WEAPONOFFHAND,
  153. [Enum.ItemSlotFilterType.Finger] = INVTYPE_FINGER,
  154. [Enum.ItemSlotFilterType.Trinket] = INVTYPE_TRINKET,
  155. [Enum.ItemSlotFilterType.Other] = EJ_LOOT_SLOT_FILTER_OTHER,
  156. }
  157. local BOSS_LOOT_BUTTON_HEIGHT = 45;
  158. local INSTANCE_LOOT_BUTTON_HEIGHT = 64;
  159. function EncounterJournal_OnLoad(self)
  160. EncounterJournalTitleText:SetText(ADVENTURE_JOURNAL);
  161. EncounterJournal:SetPortraitToAsset("Interface\\EncounterJournal\\UI-EJ-PortraitIcon");
  162. self:RegisterEvent("EJ_LOOT_DATA_RECIEVED");
  163. self:RegisterEvent("EJ_DIFFICULTY_UPDATE");
  164. self:RegisterEvent("UNIT_PORTRAIT_UPDATE");
  165. self:RegisterEvent("PORTRAITS_UPDATED");
  166. self:RegisterEvent("SEARCH_DB_LOADED");
  167. self:RegisterEvent("UI_MODEL_SCENE_INFO_UPDATED");
  168. self.encounter.freeHeaders = {};
  169. self.encounter.usedHeaders = {};
  170. self.encounter.overviewFrame = self.encounter.info.overviewScroll.child;
  171. self.encounter.overviewFrame.isOverview = true;
  172. self.encounter.overviewFrame.overviews = {};
  173. self.encounter.info.overviewScroll.ScrollBar.scrollStep = 30;
  174. self.encounter.infoFrame = self.encounter.info.detailsScroll.child;
  175. self.encounter.info.detailsScroll.ScrollBar.scrollStep = 30;
  176. self.encounter.bossesFrame = self.encounter.info.bossesScroll.child;
  177. self.encounter.info.bossesScroll.ScrollBar.scrollStep = 30;
  178. self.encounter.info.overviewTab:Click();
  179. self.encounter.info.lootScroll.update = EncounterJournal_LootUpdate;
  180. self.encounter.info.lootScroll.scrollBar.doNotHide = true;
  181. self.encounter.info.lootScroll.dynamic = EncounterJournal_LootCalcScroll;
  182. HybridScrollFrame_CreateButtons(self.encounter.info.lootScroll, "EncounterItemTemplate", 0, 0);
  183. self.searchResults.scrollFrame.update = EncounterJournal_SearchUpdate;
  184. self.searchResults.scrollFrame.scrollBar.doNotHide = true;
  185. HybridScrollFrame_CreateButtons(self.searchResults.scrollFrame, "EncounterSearchLGTemplate", 0, 0);
  186. local homeData = {
  187. name = HOME,
  188. OnClick = function()
  189. if self.selectedTab then
  190. EJ_ContentTab_Select(self.selectedTab);
  191. else
  192. EJSuggestFrame_OpenFrame();
  193. end
  194. end,
  195. }
  196. NavBar_Initialize(self.navBar, "NavButtonTemplate", homeData, self.navBar.home, self.navBar.overflow);
  197. UIDropDownMenu_Initialize(self.encounter.info.lootScroll.lootFilter, EncounterJournal_InitLootFilter, "MENU");
  198. UIDropDownMenu_Initialize(self.encounter.info.lootScroll.lootSlotFilter, EncounterJournal_InitLootSlotFilter, "MENU");
  199. -- initialize tabs
  200. local instanceSelect = EncounterJournal.instanceSelect;
  201. local tierName = EJ_GetTierInfo(EJ_GetCurrentTier());
  202. UIDropDownMenu_SetText(instanceSelect.tierDropDown, tierName);
  203. -- check if tabs are active
  204. local dungeonInstanceID = EJ_GetInstanceByIndex(1, false);
  205. if( not dungeonInstanceID ) then
  206. instanceSelect.dungeonsTab.grayBox:Show();
  207. end
  208. local raidInstanceID = EJ_GetInstanceByIndex(1, true);
  209. if( not raidInstanceID ) then
  210. instanceSelect.raidsTab.grayBox:Show();
  211. end
  212. -- set the suggestion panel frame to open by default
  213. EJSuggestFrame_OpenFrame();
  214. end
  215. function EncounterJournal_EnableTierDropDown()
  216. local tierName = EJ_GetTierInfo(EJ_GetCurrentTier());
  217. UIDropDownMenu_SetText(EncounterJournal.instanceSelect.tierDropDown, tierName);
  218. UIDropDownMenu_EnableDropDown(EncounterJournal.instanceSelect.tierDropDown);
  219. end
  220. function EncounterJournal_DisableTierDropDown(removeText)
  221. UIDropDownMenu_DisableDropDown(EncounterJournal.instanceSelect.tierDropDown);
  222. if ( removeText ) then
  223. UIDropDownMenu_SetText(EncounterJournal.instanceSelect.tierDropDown, nil);
  224. else
  225. local tierName = EJ_GetTierInfo(EJ_GetCurrentTier());
  226. UIDropDownMenu_SetText(EncounterJournal.instanceSelect.tierDropDown, tierName);
  227. end
  228. end
  229. function EncounterJournal_HasChangedContext(instanceID, instanceType, difficultyID)
  230. if ( instanceType == "none" ) then
  231. -- we've gone from a dungeon to the open world
  232. return EncounterJournal.lastInstance ~= nil;
  233. elseif ( instanceID ~= 0 and (instanceID ~= EncounterJournal.lastInstance or EncounterJournal.lastDifficulty ~= difficultyID) ) then
  234. -- dungeon or difficulty has changed
  235. return true;
  236. end
  237. return false;
  238. end
  239. function EncounterJournal_ResetDisplay(instanceID, instanceType, difficultyID)
  240. if ( instanceType == "none" ) then
  241. EncounterJournal.lastInstance = nil;
  242. EncounterJournal.lastDifficulty = nil;
  243. EJSuggestFrame_OpenFrame();
  244. else
  245. EJ_ContentTab_Select(EncounterJournal.instanceSelect.dungeonsTab.id);
  246. EncounterJournal_DisplayInstance(instanceID);
  247. EncounterJournal.lastInstance = instanceID;
  248. -- try to set difficulty to current instance difficulty
  249. if ( EJ_IsValidInstanceDifficulty(difficultyID) ) then
  250. EJ_SetDifficulty(difficultyID);
  251. end
  252. EncounterJournal.lastDifficulty = difficultyID;
  253. end
  254. end
  255. function EncounterJournal_OnShow(self)
  256. self:RegisterEvent("SPELL_TEXT_UPDATE");
  257. if ( tonumber(GetCVar("advJournalLastOpened")) == 0 ) then
  258. SetCVar("advJournalLastOpened", GetServerTime() );
  259. end
  260. MainMenuMicroButton_HideAlert(EJMicroButton);
  261. MicroButtonPulseStop(EJMicroButton);
  262. UpdateMicroButtons();
  263. PlaySound(SOUNDKIT.IG_CHARACTER_INFO_OPEN);
  264. EncounterJournal_LootUpdate();
  265. local instanceSelect = EncounterJournal.instanceSelect;
  266. --automatically navigate to the current dungeon if you are in one;
  267. local mapID = C_Map.GetBestMapForUnit("player");
  268. local instanceID = mapID and EJ_GetInstanceForMap(mapID) or 0;
  269. local _, instanceType, difficultyID = GetInstanceInfo();
  270. if ( EncounterJournal_HasChangedContext(instanceID, instanceType, difficultyID) ) then
  271. EncounterJournal_ResetDisplay(instanceID, instanceType, difficultyID);
  272. EncounterJournal.queuedPortraitUpdate = nil;
  273. elseif ( self.encounter.overviewFrame:IsShown() and EncounterJournal.overviewDefaultRole and not EncounterJournal.encounter.overviewFrame.linkSection ) then
  274. local spec, role;
  275. spec = GetSpecialization();
  276. if (spec) then
  277. role = GetSpecializationRole(spec);
  278. else
  279. role = "DAMAGER";
  280. end
  281. if ( EncounterJournal.overviewDefaultRole ~= role ) then
  282. EncounterJournal_ToggleHeaders(EncounterJournal.encounter.overviewFrame);
  283. end
  284. end
  285. if ( EncounterJournal.queuedPortraitUpdate ) then
  286. -- fixes portraits when switching between fullscreen and windowed mode
  287. EncounterJournal.queuedPortraitUpdate = false;
  288. EncounterJournal_UpdatePortraits();
  289. end
  290. local tierData = GetEJTierData(EJ_GetCurrentTier());
  291. if ( not instanceSelect.suggestTab:IsEnabled() or EncounterJournal.suggestFrame:IsShown() ) then
  292. tierData = GetEJTierData(EJSuggestTab_GetPlayerTierIndex());
  293. end
  294. instanceSelect.bg:SetAtlas(tierData.backgroundAtlas, true);
  295. instanceSelect.raidsTab.selectedGlow:SetVertexColor(tierData.r, tierData.g, tierData.b);
  296. instanceSelect.dungeonsTab.selectedGlow:SetVertexColor(tierData.r, tierData.g, tierData.b);
  297. local shouldShowPowerTab, powerID = EJMicroButton:ShouldShowPowerTab();
  298. if shouldShowPowerTab then
  299. self.LootJournal:SetPendingPowerID(powerID);
  300. EJ_ContentTab_Select(instanceSelect.LootJournalTab.id);
  301. SetCVarBitfield("closedInfoFrames", LE_FRAME_TUTORIAL_FIRST_RUNEFORGE_LEGENDARY_POWER, true);
  302. elseif EncounterJournal.instanceSelect:IsShown() then
  303. EJ_ContentTab_Select(self.selectedTab);
  304. end
  305. EncounterJournal_CheckAndDisplayLootTab();
  306. -- Request raid locks to show the defeated overlay for bosses the player has killed this week.
  307. RequestRaidInfo();
  308. end
  309. function EncounterJournal_CheckAndDisplayLootTab()
  310. local instanceSelect = EncounterJournal.instanceSelect;
  311. if EJ_GetCurrentTier() == EJ_TIER_INDEX_SHADOWLANDS then
  312. PanelTemplates_ShowTab(instanceSelect, instanceSelect.LootJournalTab.id);
  313. else
  314. PanelTemplates_HideTab(instanceSelect, instanceSelect.LootJournalTab.id);
  315. end
  316. end
  317. function EncounterJournal_OnHide(self)
  318. self:UnregisterEvent("SPELL_TEXT_UPDATE");
  319. UpdateMicroButtons();
  320. PlaySound(SOUNDKIT.IG_CHARACTER_INFO_CLOSE);
  321. if self.searchBox.clearButton then
  322. self.searchBox.clearButton:Click();
  323. end
  324. EJ_EndSearch();
  325. self.shouldDisplayDifficulty = nil;
  326. end
  327. local function EncounterJournal_IsHeaderTypeOverview(headerType)
  328. return headerType == EJ_HTYPE_OVERVIEW;
  329. end
  330. local function EncounterJournal_GetRootAfterOverviews(rootSectionID)
  331. local nextSectionID = rootSectionID;
  332. repeat
  333. local info = C_EncounterJournal.GetSectionInfo(nextSectionID);
  334. local isOverview = info and EncounterJournal_IsHeaderTypeOverview(info.headerType);
  335. if isOverview then
  336. nextSectionID = info.siblingSectionID;
  337. end
  338. until not isOverview;
  339. return nextSectionID;
  340. end
  341. local function EncounterJournal_CheckForOverview(rootSectionID)
  342. local sectionInfo = C_EncounterJournal.GetSectionInfo(rootSectionID);
  343. return sectionInfo and EncounterJournal_IsHeaderTypeOverview(sectionInfo.headerType);
  344. end
  345. local function EncounterJournal_SearchForOverview(instanceID)
  346. local bossIndex = 1;
  347. local _, _, bossID = EJ_GetEncounterInfoByIndex(bossIndex);
  348. while bossID do
  349. local _, _, _, rootSectionID = EJ_GetEncounterInfo(bossID);
  350. if (EncounterJournal_CheckForOverview(rootSectionID)) then
  351. return true;
  352. end
  353. bossIndex = bossIndex + 1;
  354. _, _, bossID = EJ_GetEncounterInfoByIndex(bossIndex);
  355. end
  356. return false;
  357. end
  358. local function EncounterJournal_UpdateSpellText(self, spellID)
  359. if self.encounter.encounterID then
  360. local rootSectionID = select(4, EJ_GetEncounterInfo(self.encounter.encounterID));
  361. if (EncounterJournal_CheckForOverview(rootSectionID)) then
  362. if self.encounter.overviewFrame.spellID == spellID then
  363. local sectionInfo = C_EncounterJournal.GetSectionInfo(rootSectionID);
  364. EncounterJournal_SetBullets(self.encounter.overviewFrame.overviewDescription, sectionInfo.description, false);
  365. end
  366. end
  367. end
  368. -- Overview frames
  369. for overviewIndex, overview in ipairs(self.encounter.overviewFrame.overviews) do
  370. if overview.spellID == spellID then
  371. local sectionInfo = C_EncounterJournal.GetSectionInfo(overview.sectionID);
  372. EncounterJournal_SetDescriptionWithBullets(overview, sectionInfo.description);
  373. end
  374. end
  375. -- Section info
  376. EncounterJournal.encounter.infoFrame.updatingSpells = true;
  377. for headerIndex, header in ipairs(self.encounter.usedHeaders) do
  378. if header.spellID == spellID then
  379. local sectionInfo = C_EncounterJournal.GetSectionInfo(header.myID);
  380. local description = sectionInfo.description:gsub("\|cffffffff(.-)\|r", "%1");
  381. header.description:SetText(description);
  382. if EJ_section_openTable[header.myID] then
  383. EncounterJournal_ToggleHeaders(header);
  384. EncounterJournal_ToggleHeaders(header);
  385. end
  386. end
  387. end
  388. EncounterJournal.encounter.infoFrame.updatingSpells = nil;
  389. end
  390. function EncounterJournal_OnEvent(self, event, ...)
  391. if event == "EJ_LOOT_DATA_RECIEVED" then
  392. local itemID = ...
  393. if itemID and not EJ_IsLootListOutOfDate() then
  394. EncounterJournal_LootCallback(itemID);
  395. if EncounterJournal.searchResults:IsShown() then
  396. EncounterJournal_SearchUpdate();
  397. elseif EncounterJouranl_IsSearchPreviewShown() then
  398. EncounterJournal_UpdateSearchPreview();
  399. end
  400. else
  401. EncounterJournal_LootUpdate();
  402. end
  403. elseif event == "EJ_DIFFICULTY_UPDATE" then
  404. --fix the difficulty buttons
  405. EncounterJournal_UpdateDifficulty(...);
  406. elseif event == "UNIT_PORTRAIT_UPDATE" then
  407. local unit = ...;
  408. if not unit then
  409. EncounterJournal_UpdatePortraits();
  410. end
  411. elseif event == "PORTRAITS_UPDATED" then
  412. EncounterJournal_UpdatePortraits();
  413. elseif event == "SEARCH_DB_LOADED" then
  414. EncounterJournal_RestartSearchTracking();
  415. elseif event == "UI_MODEL_SCENE_INFO_UPDATED" then
  416. local forceUpdate = true;
  417. EncounterJournal_ShowCreatures(forceUpdate);
  418. elseif event == "SPELL_TEXT_UPDATE" then
  419. local spellID = ...;
  420. EncounterJournal_UpdateSpellText(self, spellID);
  421. end
  422. end
  423. function EncounterJournal_UpdateDifficulty(newDifficultyID)
  424. if IsEJDifficulty(newDifficultyID) then
  425. local difficultyStr = GetEJDifficultyString(newDifficultyID);
  426. EncounterJournal.encounter.info.difficulty:SetText(difficultyStr);
  427. EncounterJournal_Refresh();
  428. end
  429. end
  430. function EncounterJournal_GetCreatureButton(index)
  431. if index > MAX_CREATURES_PER_ENCOUNTER then
  432. return nil;
  433. end
  434. local self = EncounterJournal.encounter.info;
  435. local button = self.creatureButtons[index];
  436. if (not button) then
  437. button = CreateFrame("BUTTON", nil, self, "EncounterCreatureButtonTemplate");
  438. button:SetPoint("TOPLEFT", self.creatureButtons[index-1], "BOTTOMLEFT", 0, 8);
  439. self.creatureButtons[index] = button;
  440. end
  441. return button;
  442. end
  443. function EncounterJournal_FindCreatureButtonForDisplayInfo(displayInfo)
  444. for index, button in ipairs(EncounterJournal.encounter.info.creatureButtons) do
  445. if button.displayInfo == displayInfo then
  446. return button;
  447. end
  448. end
  449. return nil;
  450. end
  451. function EncounterJournal_UpdatePortraits()
  452. if ( EncounterJournal:IsShown() ) then
  453. local creatures = EncounterJournal.encounter.info.creatureButtons;
  454. for i = 1, #creatures do
  455. local button = creatures[i];
  456. if ( button and button:IsShown() ) then
  457. SetPortraitTextureFromCreatureDisplayID(button.creature, button.displayInfo);
  458. else
  459. break;
  460. end
  461. end
  462. local usedHeaders = EncounterJournal.encounter.usedHeaders;
  463. for _, header in pairs(usedHeaders) do
  464. if ( header.button.portrait.displayInfo ) then
  465. SetPortraitTextureFromCreatureDisplayID(header.button.portrait.icon, header.button.portrait.displayInfo);
  466. end
  467. end
  468. else
  469. EncounterJournal.queuedPortraitUpdate = true;
  470. end
  471. end
  472. local infiniteLoopPolice = false; --design might make a tier that has no instances at all sigh
  473. function EncounterJournal_ListInstances()
  474. local instanceSelect = EncounterJournal.instanceSelect;
  475. local tierName = EJ_GetTierInfo(EJ_GetCurrentTier());
  476. UIDropDownMenu_SetText(instanceSelect.tierDropDown, tierName);
  477. NavBar_Reset(EncounterJournal.navBar);
  478. EncounterJournal.encounter:Hide();
  479. instanceSelect:Show();
  480. local showRaid = not instanceSelect.raidsTab:IsEnabled();
  481. local scrollFrame = instanceSelect.scroll.child;
  482. local index = 1;
  483. local instanceID, name, description, _, buttonImage, _, _, _, link = EJ_GetInstanceByIndex(index, showRaid);
  484. --No instances in this tab
  485. if not instanceID and not infiniteLoopPolice then
  486. --disable this tab and select the other one.
  487. infiniteLoopPolice = true;
  488. if ( showRaid ) then
  489. instanceSelect.raidsTab.grayBox:Show();
  490. EJ_ContentTab_Select(instanceSelect.dungeonsTab.id);
  491. else
  492. instanceSelect.dungeonsTab.grayBox:Show();
  493. EJ_ContentTab_Select(instanceSelect.raidsTab.id);
  494. end
  495. return;
  496. end
  497. infiniteLoopPolice = false;
  498. while instanceID do
  499. local instanceButton = scrollFrame["instance"..index];
  500. if not instanceButton then -- create button
  501. instanceButton = CreateFrame("BUTTON", scrollFrame:GetParent():GetName().."instance"..index, scrollFrame, "EncounterInstanceButtonTemplate");
  502. if ( EncounterJournal.localizeInstanceButton ) then
  503. EncounterJournal.localizeInstanceButton(instanceButton);
  504. end
  505. scrollFrame["instance"..index] = instanceButton;
  506. if mod(index-1, EJ_NUM_INSTANCE_PER_ROW) == 0 then
  507. instanceButton:SetPoint("TOP", scrollFrame["instance"..(index-EJ_NUM_INSTANCE_PER_ROW)], "BOTTOM", 0, -15);
  508. else
  509. instanceButton:SetPoint("LEFT", scrollFrame["instance"..(index-1)], "RIGHT", 15, 0);
  510. end
  511. end
  512. instanceButton.name:SetText(name);
  513. instanceButton.bgImage:SetTexture(buttonImage);
  514. instanceButton.instanceID = instanceID;
  515. instanceButton.tooltipTitle = name;
  516. instanceButton.tooltipText = description;
  517. instanceButton.link = link;
  518. instanceButton:Show();
  519. index = index + 1;
  520. instanceID, name, description, _, buttonImage, _, _, _, link = EJ_GetInstanceByIndex(index, showRaid);
  521. end
  522. EJ_HideInstances(index);
  523. --check if the other tab is empty
  524. local instanceText = EJ_GetInstanceByIndex(1, not showRaid);
  525. --No instances in the other tab
  526. if not instanceText then
  527. --disable the other tab.
  528. if ( showRaid ) then
  529. instanceSelect.dungeonsTab.grayBox:Show();
  530. else
  531. instanceSelect.raidsTab.grayBox:Show();
  532. end
  533. end
  534. end
  535. function EncounterJournalInstanceButton_OnClick(self)
  536. NavBar_Reset(EncounterJournal.navBar);
  537. EncounterJournal_DisplayInstance(EncounterJournal.instanceID);
  538. end
  539. local function EncounterJournal_SetupIconFlags(sectionID, infoHeaderButton)
  540. local iconFlags = C_EncounterJournal.GetSectionIconFlags(sectionID);
  541. local textRightAnchor;
  542. for index, icon in ipairs(infoHeaderButton.icons) do
  543. local iconFlag = iconFlags and iconFlags[index];
  544. icon:SetShown(iconFlag ~= nil);
  545. if iconFlag then
  546. textRightAnchor = icon;
  547. icon:Show();
  548. icon.tooltipTitle = _G["ENCOUNTER_JOURNAL_SECTION_FLAG"..iconFlag];
  549. icon.tooltipText = _G["ENCOUNTER_JOURNAL_SECTION_FLAG_DESCRIPTION"..iconFlag];
  550. EncounterJournal_SetFlagIcon(icon.icon, iconFlag);
  551. end
  552. end
  553. if textRightAnchor then
  554. infoHeaderButton.title:SetPoint("RIGHT", textRightAnchor, "LEFT", -5, 0);
  555. else
  556. infoHeaderButton.title:SetPoint("RIGHT", infoHeaderButton, "RIGHT", -5, 0);
  557. end
  558. end
  559. local function UpdateDifficultyAnchoring(difficultyFrame)
  560. local infoFrame = difficultyFrame:GetParent();
  561. infoFrame.reset:ClearAllPoints();
  562. if difficultyFrame:IsShown() then
  563. infoFrame.reset:SetPoint("RIGHT", difficultyFrame, "LEFT", -10, 0);
  564. else
  565. infoFrame.reset:SetPoint("TOPRIGHT", infoFrame, "TOPRIGHT", -19, -13);
  566. end
  567. end
  568. local function UpdateDifficultyVisibility()
  569. local shouldDisplayDifficulty = select(9, EJ_GetInstanceInfo());
  570. -- As long as the current tab isn't the model tab, which always suppresses the difficulty, then update the shown state.
  571. local info = EncounterJournal.encounter.info;
  572. info.difficulty:SetShown(shouldDisplayDifficulty and (info.tab ~= 4));
  573. UpdateDifficultyAnchoring(info.difficulty);
  574. end
  575. local IconIndexByDifficulty = {
  576. [15] = 3, -- Heroic
  577. [16] = 12, -- Mythic
  578. };
  579. local function GetIconIndexForDifficultyID(difficultyID)
  580. return IconIndexByDifficulty[difficultyID];
  581. end
  582. function EncounterJournal_DisplayInstance(instanceID, noButton)
  583. EJ_HideNonInstancePanels();
  584. local difficultyID = EJ_GetDifficulty();
  585. local self = EncounterJournal.encounter;
  586. EncounterJournal.instanceSelect:Hide();
  587. EncounterJournal.encounter:Show();
  588. EncounterJournal.creatureDisplayID = 0;
  589. EncounterJournal.instanceID = instanceID;
  590. EncounterJournal.encounterID = nil;
  591. EJ_SelectInstance(instanceID);
  592. EncounterJournal_LootUpdate();
  593. EncounterJournal_ClearDetails();
  594. local instanceName, description, bgImage, _, loreImage, buttonImage, dungeonAreaMapID = EJ_GetInstanceInfo();
  595. self.instance.title:SetText(instanceName);
  596. self.instance.titleBG:SetWidth(self.instance.title:GetStringWidth() + 80);
  597. self.instance.loreBG:SetTexture(loreImage);
  598. self.info.instanceTitle:ClearAllPoints();
  599. local iconIndex = GetIconIndexForDifficultyID(difficultyID);
  600. local hasDifficultyIcon = iconIndex ~= nil;
  601. self.info.difficultyIcon:SetShown(hasDifficultyIcon);
  602. if hasDifficultyIcon then
  603. self.info.instanceTitle:SetPoint("LEFT", self.info.difficultyIcon, "RIGHT", -6, -0);
  604. EncounterJournal_SetFlagIcon(self.info.difficultyIcon, iconIndex);
  605. else
  606. self.info.instanceTitle:SetPoint("TOPLEFT", 65, -20);
  607. end
  608. self.info.instanceTitle:SetText(instanceName);
  609. self.instance.mapButton:SetShown(dungeonAreaMapID and dungeonAreaMapID > 0);
  610. self.instance.loreScroll.ScrollBar:Hide();
  611. self.instance.loreScroll.child.lore:SetWidth(335);
  612. self.instance.loreScroll.child.lore:SetText(description);
  613. local loreHeight = self.instance.loreScroll.child.lore:GetHeight();
  614. self.instance.loreScroll.ScrollBar:SetValue(0);
  615. if loreHeight > EJ_LORE_MAX_HEIGHT then
  616. self.instance.loreScroll.ScrollBar:Show();
  617. self.instance.loreScroll.child.lore:SetWidth(313);
  618. end
  619. self.info.instanceButton.instanceID = instanceID;
  620. self.info.instanceButton.icon:SetMask("Interface\\CharacterFrame\\TempPortraitAlphaMask");
  621. self.info.instanceButton.icon:SetTexture(buttonImage);
  622. self.info.model.dungeonBG:SetTexture(bgImage);
  623. UpdateDifficultyVisibility();
  624. local bossIndex = 1;
  625. local name, description, bossID, rootSectionID, link = EJ_GetEncounterInfoByIndex(bossIndex);
  626. local bossButton;
  627. local hasBossAbilities = false;
  628. while bossID do
  629. bossButton = _G["EncounterJournalBossButton"..bossIndex];
  630. if not bossButton then -- create a new header;
  631. bossButton = CreateFrame("BUTTON", "EncounterJournalBossButton"..bossIndex, EncounterJournal.encounter.bossesFrame, "EncounterBossButtonTemplate");
  632. if bossIndex > 1 then
  633. bossButton:SetPoint("TOPLEFT", _G["EncounterJournalBossButton"..(bossIndex-1)], "BOTTOMLEFT", 0, -15);
  634. else
  635. bossButton:SetPoint("TOPLEFT", EncounterJournal.encounter.bossesFrame, "TOPLEFT", 0, -10);
  636. end
  637. end
  638. bossButton.link = link;
  639. bossButton:SetText(name);
  640. bossButton:Show();
  641. bossButton.encounterID = bossID;
  642. --Use the boss' first creature as the button icon
  643. local _, _, _, _, bossImage = EJ_GetCreatureInfo(1, bossID);
  644. bossImage = bossImage or "Interface\\EncounterJournal\\UI-EJ-BOSS-Default";
  645. bossButton.creature:SetTexture(bossImage);
  646. bossButton:UnlockHighlight();
  647. EncounterJournalBossButton_UpdateDifficultyOverlay(bossButton);
  648. if ( not hasBossAbilities ) then
  649. hasBossAbilities = rootSectionID > 0;
  650. end
  651. bossIndex = bossIndex + 1;
  652. name, description, bossID, rootSectionID, link = EJ_GetEncounterInfoByIndex(bossIndex);
  653. end
  654. EncounterJournal_SetTabEnabled(EncounterJournal.encounter.info.overviewTab, true);
  655. --disable model tab and abilities tab, no boss selected
  656. EncounterJournal_SetTabEnabled(EncounterJournal.encounter.info.modelTab, false);
  657. EncounterJournal_SetTabEnabled(EncounterJournal.encounter.info.bossTab, false);
  658. EncounterJournal_SetTabEnabled(EncounterJournal.encounter.info.lootTab, C_EncounterJournal.InstanceHasLoot());
  659. if (EncounterJournal_SearchForOverview(instanceID)) then
  660. EJ_Tabs[1].frame = "overviewScroll";
  661. EJ_Tabs[3].frame = "detailsScroll"; -- flip them back
  662. self.info[EJ_Tabs[1].button].tooltip = OVERVIEW;
  663. self.info[EJ_Tabs[3].button]:Show();
  664. self.info[EJ_Tabs[4].button]:SetPoint("TOP", self.info[EJ_Tabs[3].button], "BOTTOM", 0, 2)
  665. self.info.overviewFound = true;
  666. else
  667. EJ_Tabs[1].frame = "detailsScroll";
  668. EJ_Tabs[3].frame = "overviewScroll"; -- flip these so detailsScroll won't get hidden, overview will never be shown here
  669. if ( hasBossAbilities ) then
  670. self.info[EJ_Tabs[1].button].tooltip = ABILITIES;
  671. else
  672. self.info[EJ_Tabs[1].button].tooltip = OVERVIEW;
  673. end
  674. self.info[EJ_Tabs[3].button]:Hide();
  675. self.info[EJ_Tabs[4].button]:SetPoint("TOP", self.info[EJ_Tabs[2].button], "BOTTOM", 0, 2)
  676. self.info.overviewFound = false;
  677. end
  678. self.instance:Show();
  679. self.info.overviewScroll:Hide();
  680. self.info.detailsScroll:Hide();
  681. self.info.lootScroll:Hide();
  682. self.info.rightShadow:Hide();
  683. if (self.info.tab < 3) then
  684. self.info[EJ_Tabs[self.info.tab].button]:Click()
  685. else
  686. self.info.overviewTab:Click();
  687. end
  688. if not noButton then
  689. local buttonData = {
  690. id = instanceID,
  691. name = instanceName,
  692. OnClick = EJNAV_RefreshInstance,
  693. listFunc = EJNAV_GetInstanceList,
  694. }
  695. NavBar_AddButton(EncounterJournal.navBar, buttonData);
  696. end
  697. end
  698. function EncounterJournal_DisplayEncounter(encounterID, noButton)
  699. local self = EncounterJournal.encounter;
  700. local ename, description, _, rootSectionID = EJ_GetEncounterInfo(encounterID);
  701. if (EncounterJournal.encounterID == encounterID) then
  702. --navbar is already set to the right button, don't add another
  703. noButton = true;
  704. elseif (EncounterJournal.encounterID) then
  705. --make sure the previous navbar button is the instance button
  706. NavBar_OpenTo(EncounterJournal.navBar, EncounterJournal.instanceID);
  707. end
  708. EncounterJournal.encounterID = encounterID;
  709. EJ_SelectEncounter(encounterID);
  710. EncounterJournal_LootUpdate();
  711. --need to clear details, but don't want to scroll to top of bosses list
  712. local bossListScrollValue = self.info.bossesScroll.ScrollBar:GetValue()
  713. EncounterJournal_ClearDetails();
  714. EncounterJournal.encounter.info.bossesScroll.ScrollBar:SetValue(bossListScrollValue);
  715. self.info.encounterTitle:SetText(ename);
  716. EncounterJournal_SetTabEnabled(EncounterJournal.encounter.info.overviewTab, (rootSectionID > 0));
  717. EncounterJournal_SetTabEnabled(EncounterJournal.encounter.info.lootTab, C_EncounterJournal.InstanceHasLoot());
  718. local sectionInfo = C_EncounterJournal.GetSectionInfo(rootSectionID);
  719. local overviewFound;
  720. if (sectionInfo and EncounterJournal_IsHeaderTypeOverview(sectionInfo.headerType)) then
  721. self.overviewFrame.spellID = sectionInfo.spellID;
  722. self.overviewFrame.loreDescription:SetHeight(0);
  723. self.overviewFrame.loreDescription:SetWidth(self.overviewFrame:GetWidth() - 5);
  724. self.overviewFrame.loreDescription:SetText(description);
  725. self.overviewFrame.overviewDescription:SetWidth(self.overviewFrame:GetWidth() - 5);
  726. self.overviewFrame.overviewDescription.Text:SetWidth(self.overviewFrame:GetWidth() - 5);
  727. EncounterJournal_SetBullets(self.overviewFrame.overviewDescription, sectionInfo.description, false);
  728. local bulletHeight = 0;
  729. if (self.overviewFrame.Bullets and #self.overviewFrame.Bullets > 0) then
  730. for i = 1, #self.overviewFrame.Bullets do
  731. bulletHeight = bulletHeight + self.overviewFrame.Bullets[i]:GetHeight();
  732. end
  733. local bullet = self.overviewFrame.Bullets[1];
  734. bullet:ClearAllPoints();
  735. bullet:SetPoint("TOPLEFT", self.overviewFrame.overviewDescription, "BOTTOMLEFT", 0, -9);
  736. end
  737. self.overviewFrame.descriptionHeight = self.overviewFrame.loreDescription:GetHeight() + self.overviewFrame.overviewDescription:GetHeight() + bulletHeight + 42;
  738. self.overviewFrame.rootOverviewSectionID = rootSectionID;
  739. rootSectionID = EncounterJournal_GetRootAfterOverviews(rootSectionID);
  740. overviewFound = true;
  741. end
  742. self.infoFrame.description:SetWidth(self.infoFrame:GetWidth() -5);
  743. self.infoFrame.description:SetText(description);
  744. self.infoFrame.descriptionHeight = self.infoFrame.description:GetHeight();
  745. self.infoFrame.encounterID = encounterID;
  746. self.infoFrame.rootSectionID = rootSectionID;
  747. self.infoFrame.expanded = false;
  748. local bossIndex = 1;
  749. local name, description, bossID, _, link = EJ_GetEncounterInfoByIndex(bossIndex);
  750. local bossButton;
  751. while bossID do
  752. bossButton = _G["EncounterJournalBossButton"..bossIndex];
  753. if not bossButton then -- create a new header;
  754. bossButton = CreateFrame("BUTTON", "EncounterJournalBossButton"..bossIndex, EncounterJournal.encounter.bossesFrame, "EncounterBossButtonTemplate");
  755. if bossIndex > 1 then
  756. bossButton:SetPoint("TOPLEFT", _G["EncounterJournalBossButton"..(bossIndex-1)], "BOTTOMLEFT", 0, -15);
  757. else
  758. bossButton:SetPoint("TOPLEFT", EncounterJournal.encounter.bossesFrame, "TOPLEFT", 0, -10);
  759. end
  760. end
  761. bossButton.link = link;
  762. bossButton:SetText(name);
  763. bossButton:Show();
  764. bossButton.encounterID = bossID;
  765. --Use the boss' first creature as the button icon
  766. local _, _, _, _, bossImage = EJ_GetCreatureInfo(1, bossID);
  767. bossImage = bossImage or "Interface\\EncounterJournal\\UI-EJ-BOSS-Default";
  768. bossButton.creature:SetTexture(bossImage);
  769. if (encounterID == bossID) then
  770. bossButton:LockHighlight();
  771. else
  772. bossButton:UnlockHighlight();
  773. end
  774. bossIndex = bossIndex + 1;
  775. name, description, bossID, _, link = EJ_GetEncounterInfoByIndex(bossIndex);
  776. end
  777. -- Setup Creatures
  778. local id, name, displayInfo, iconImage;
  779. for i=1,MAX_CREATURES_PER_ENCOUNTER do
  780. id, name, description, displayInfo, iconImage, uiModelSceneID = EJ_GetCreatureInfo(i);
  781. if id then
  782. local button = EncounterJournal_GetCreatureButton(i);
  783. SetPortraitTextureFromCreatureDisplayID(button.creature, displayInfo);
  784. button.name = name;
  785. button.id = id;
  786. button.description = description;
  787. button.displayInfo = displayInfo;
  788. button.uiModelSceneID = uiModelSceneID;
  789. end
  790. end
  791. --enable model and abilities tab
  792. EncounterJournal_SetTabEnabled(EncounterJournal.encounter.info.modelTab, true);
  793. EncounterJournal_SetTabEnabled(EncounterJournal.encounter.info.bossTab, true);
  794. if (overviewFound) then
  795. EncounterJournal_ToggleHeaders(self.overviewFrame);
  796. self.overviewFrame:Show();
  797. else
  798. self.overviewFrame:Hide();
  799. end
  800. EncounterJournal_ToggleHeaders(self.infoFrame);
  801. self:Show();
  802. --make sure we stay on the tab we were on
  803. self.info[EJ_Tabs[self.info.tab].button]:Click()
  804. if not noButton then
  805. local buttonData = {
  806. id = encounterID,
  807. name = ename,
  808. OnClick = EJNAV_RefreshEncounter,
  809. listFunc = EJNAV_GetEncounterList,
  810. }
  811. NavBar_AddButton(EncounterJournal.navBar, buttonData);
  812. end
  813. end
  814. function EncounterJournal_DisplayCreature(self, forceUpdate)
  815. if EncounterJournal.encounter.info.shownCreatureButton then
  816. EncounterJournal.encounter.info.shownCreatureButton:Enable();
  817. end
  818. local modelScene = EncounterJournal.encounter.info.model;
  819. if self.displayInfo and (EncounterJournal.creatureDisplayID ~= self.displayInfo or forceUpdate) then
  820. modelScene:SetFromModelSceneID(self.uiModelSceneID, forceUpdate);
  821. local creature = modelScene:GetActorByTag("creature");
  822. if creature then
  823. creature:SetModelByCreatureDisplayID(self.displayInfo, forceUpdate);
  824. end
  825. EncounterJournal.creatureDisplayID = self.displayInfo;
  826. end
  827. modelScene.imageTitle:SetText(self.name);
  828. local isGMClient = IsGMClient();
  829. modelScene.modelName:SetShown(isGMClient);
  830. modelScene.modelDisplayId:SetShown(isGMClient);
  831. modelScene.modelNameLabel:SetShown(isGMClient);
  832. modelScene.modelDisplayIdLabel:SetShown(isGMClient);
  833. if (isGMClient) then
  834. local numActors = modelScene:GetNumActors();
  835. local actor = (numActors > 0) and modelScene:GetActorAtIndex(1);
  836. local displayID = actor and actor:GetModelFileID() or "";
  837. local name = actor and actor:GetModelPath() or "";
  838. modelScene.modelName:SetText(name);
  839. modelScene.modelDisplayId:SetText(displayID);
  840. if (modelScene.modelName:IsTruncated()) then
  841. local pos = string.find(name, "\\[^\\]*$");
  842. name = name:sub(1, pos - 1) .. "\\\n" .. name:sub(pos + 1);
  843. modelScene.modelName:SetText(name);
  844. end
  845. end
  846. self:Disable();
  847. EncounterJournal.encounter.info.shownCreatureButton = self;
  848. -- Ensure that the models tab properly updates the selected button (it's possible to display creatures here
  849. -- that only have a portrait/creature button on the abilities tab).
  850. local creatureButton = EncounterJournal_FindCreatureButtonForDisplayInfo(self.displayInfo);
  851. if creatureButton and creatureButton:IsShown() then
  852. creatureButton:Click();
  853. end
  854. end
  855. function EncounterJournal_ShowCreatures(forceUpdate)
  856. for index, creatureButton in ipairs(EncounterJournal.encounter.info.creatureButtons) do
  857. if (creatureButton.displayInfo) then
  858. creatureButton:Show();
  859. if index == 1 then
  860. EncounterJournal_DisplayCreature(creatureButton, forceUpdate);
  861. end
  862. end
  863. end
  864. end
  865. function EncounterJournal_HideCreatures(clearDisplayInfo)
  866. for index, creatureButton in ipairs(EncounterJournal.encounter.info.creatureButtons) do
  867. creatureButton:Hide();
  868. if clearDisplayInfo then
  869. creatureButton.displayInfo = nil;
  870. creatureButton.uiModelSceneID = nil;
  871. end
  872. end
  873. end
  874. local toggleTempList = {};
  875. local headerCount = 0;
  876. function EncounterJournal_UpdateButtonState(self)
  877. local oldtex = self.textures.expanded;
  878. if self:GetParent().expanded then
  879. self.tex = self.textures.expanded;
  880. oldtex = self.textures.collapsed;
  881. self.expandedIcon:SetTextColor(PAPER_FRAME_EXPANDED_COLOR:GetRGB());
  882. self.title:SetTextColor(PAPER_FRAME_EXPANDED_COLOR:GetRGB());
  883. else
  884. self.tex = self.textures.collapsed;
  885. self.expandedIcon:SetTextColor(PAPER_FRAME_COLLAPSED_COLOR:GetRGB());
  886. self.title:SetTextColor(PAPER_FRAME_COLLAPSED_COLOR:GetRGB());
  887. end
  888. oldtex.up[1]:Hide();
  889. oldtex.up[2]:Hide();
  890. oldtex.up[3]:Hide();
  891. oldtex.down[1]:Hide();
  892. oldtex.down[2]:Hide();
  893. oldtex.down[3]:Hide();
  894. self.tex.up[1]:Show();
  895. self.tex.up[2]:Show();
  896. self.tex.up[3]:Show();
  897. self.tex.down[1]:Hide();
  898. self.tex.down[2]:Hide();
  899. self.tex.down[3]:Hide();
  900. end
  901. function EncounterJournal_OnClick(self)
  902. if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then
  903. if self.link then
  904. ChatEdit_InsertLink(self.link);
  905. end
  906. return;
  907. end
  908. EncounterJournal_ToggleHeaders(self:GetParent())
  909. self:GetScript("OnShow")(self);
  910. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  911. end
  912. function EncounterJournal_OnHyperlinkEnter(self, link, text, fontString, left, bottom, width, height)
  913. self.tooltipFrame:SetOwner(self, "ANCHOR_PRESERVE");
  914. self.tooltipFrame:ClearAllPoints();
  915. self.tooltipFrame:SetPoint("BOTTOMLEFT", fontString, "TOPLEFT", left + width, bottom);
  916. self.tooltipFrame:SetHyperlink(link, EJ_GetDifficulty(), EJ_GetContentTuningID());
  917. end
  918. function EncounterJournal_CleanBullets(self, start, keep)
  919. if (not self.Bullets) then return end
  920. start = start or 1;
  921. for i = start, #self.Bullets do
  922. self.Bullets[i]:Hide();
  923. if (not keep) then
  924. if (not self.BulletCache) then
  925. self.BulletCache = {};
  926. end
  927. self.Bullets[i]:ClearAllPoints();
  928. tinsert(self.BulletCache, self.Bullets[i]);
  929. self.Bullets[i] = nil;
  930. end
  931. end
  932. end
  933. function EncounterJournal_SetBullets(object, description, hideBullets)
  934. local parent = object:GetParent();
  935. if (not string.find(description, "\$bullet;")) then
  936. object.Text:SetText(description);
  937. object.textString = description;
  938. object:SetHeight(object.Text:GetContentHeight());
  939. EncounterJournal_CleanBullets(parent);
  940. return;
  941. end
  942. local desc = strtrim(string.match(description, "(.-)\$bullet;"));
  943. if (desc) then
  944. object.Text:SetText(desc);
  945. object.textString = desc;
  946. object:SetHeight(object.Text:GetContentHeight());
  947. end
  948. local bullets = {}
  949. for v in string.gmatch(description,"\$bullet;([^$]+)") do
  950. tinsert(bullets, v);
  951. end
  952. local k = 1;
  953. local skipped = 0;
  954. for j = 1,#bullets do
  955. local text = strtrim(bullets[j]).."|n|n";
  956. if (text and text ~= "") then
  957. local bullet;
  958. bullet = parent.Bullets and parent.Bullets[k];
  959. if (not bullet) then
  960. if (parent.BulletCache and #parent.BulletCache > 0) then
  961. -- We only need to check for BulletCache because the BulletCache is created when we clean the bullets, so the BulletCache existing also means the Bullets exist.
  962. parent.Bullets[k] = tremove(parent.BulletCache);
  963. bullet = parent.Bullets[k];
  964. else
  965. bullet = CreateFrame("Frame", nil, parent, "EncounterOverviewBulletTemplate");
  966. end
  967. bullet:SetWidth(parent:GetWidth() - 13);
  968. bullet.Text:SetWidth(bullet:GetWidth() - 26);
  969. end
  970. bullet:ClearAllPoints();
  971. if (k == 1) then
  972. if (parent.button) then
  973. bullet:SetPoint("TOPLEFT", parent.button, "BOTTOMLEFT", 13, -9 - object:GetHeight());
  974. else
  975. bullet:SetPoint("TOPLEFT", parent, "TOPLEFT", 13, -9 - object:GetHeight());
  976. end
  977. else
  978. bullet:SetPoint("TOP", parent.Bullets[k-1], "BOTTOM", 0, 0);
  979. end
  980. bullet.Text:SetText(text);
  981. if (bullet.Text:GetContentHeight() ~= 0) then
  982. bullet:SetHeight(bullet.Text:GetContentHeight());
  983. end
  984. if (hideBullets) then
  985. bullet:Hide();
  986. else
  987. bullet:Show();
  988. end
  989. k = k + 1;
  990. else
  991. skipped = skipped + 1;
  992. end
  993. end
  994. EncounterJournal_CleanBullets(parent, (#bullets - skipped) + 1);
  995. end
  996. function EncounterJournal_SetDescriptionWithBullets(infoHeader, description)
  997. EncounterJournal_SetBullets(infoHeader.overviewDescription, description, true);
  998. infoHeader.descriptionBG:ClearAllPoints();
  999. infoHeader.descriptionBG:SetPoint("TOPLEFT", infoHeader.button, "BOTTOMLEFT", 1, 0);
  1000. if (infoHeader.Bullets and #infoHeader.Bullets > 0) then
  1001. infoHeader.descriptionBG:SetPoint("BOTTOMRIGHT", infoHeader.Bullets[#infoHeader.Bullets], -1, -11);
  1002. else
  1003. infoHeader.descriptionBG:SetPoint("BOTTOMRIGHT", infoHeader.overviewDescription, 9, -11);
  1004. end
  1005. infoHeader.descriptionBG:Hide();
  1006. infoHeader.descriptionBGBottom:Hide();
  1007. end
  1008. function EncounterJournal_SetUpOverview(self, overviewSectionID, index)
  1009. local infoHeader;
  1010. if not self.overviews[index] then -- create a new header;
  1011. infoHeader = CreateFrame("FRAME", "EncounterJournalOverviewInfoHeader"..index, EncounterJournal.encounter.overviewFrame, "EncounterInfoTemplate");
  1012. infoHeader.description:Hide();
  1013. infoHeader.overviewDescription:Hide();
  1014. infoHeader.descriptionBG:Hide();
  1015. infoHeader.descriptionBGBottom:Hide();
  1016. infoHeader.button.abilityIcon:Hide();
  1017. infoHeader.button.portrait:Hide();
  1018. infoHeader.button.portrait.name = nil;
  1019. infoHeader.button.portrait.displayInfo = nil;
  1020. infoHeader.button.portrait.uiModelSceneID = nil;
  1021. infoHeader.button.icon2:Hide();
  1022. infoHeader.button.icon3:Hide();
  1023. infoHeader.button.icon4:Hide();
  1024. infoHeader.overviewIndex = index;
  1025. infoHeader.isOverview = true;
  1026. local textLeftAnchor = infoHeader.button.expandedIcon;
  1027. local textRightAnchor = infoHeader.button.icon1;
  1028. infoHeader.button.title:SetPoint("LEFT", textLeftAnchor, "RIGHT", 5, 0);
  1029. infoHeader.button.title:SetPoint("RIGHT", textRightAnchor, "LEFT", -5, 0);
  1030. self.overviews[index] = infoHeader;
  1031. else
  1032. infoHeader = self.overviews[index];
  1033. end
  1034. infoHeader.button.expandedIcon:SetText("+");
  1035. infoHeader.expanded = false;
  1036. infoHeader:ClearAllPoints();
  1037. if (index == 1) then
  1038. infoHeader:SetPoint("TOPLEFT", 0, -15 - self.descriptionHeight - SECTION_BUTTON_OFFSET);
  1039. infoHeader:SetPoint("TOPRIGHT", 0, -15 - self.descriptionHeight - SECTION_BUTTON_OFFSET);
  1040. else
  1041. infoHeader:SetPoint("TOPLEFT", self.overviews[index-1], "BOTTOMLEFT", 0, -9);
  1042. infoHeader:SetPoint("TOPRIGHT", self.overviews[index-1], "BOTTOMRIGHT", 0, -9);
  1043. end
  1044. infoHeader.description:Hide();
  1045. for i = 1, #infoHeader.Bullets do
  1046. infoHeader.Bullets[i]:Hide();
  1047. end
  1048. wipe(infoHeader.Bullets);
  1049. local sectionInfo = C_EncounterJournal.GetSectionInfo(overviewSectionID);
  1050. if (not sectionInfo) then
  1051. infoHeader:Hide();
  1052. return;
  1053. end
  1054. EncounterJournal_SetupIconFlags(overviewSectionID, infoHeader.button);
  1055. infoHeader.spellID = sectionInfo.spellID;
  1056. infoHeader.button.title:SetText(sectionInfo.title);
  1057. infoHeader.button.link = sectionInfo.link;
  1058. infoHeader.sectionID = overviewSectionID;
  1059. infoHeader.overviewDescription:SetWidth(infoHeader:GetWidth() - 20);
  1060. EncounterJournal_SetDescriptionWithBullets(infoHeader, sectionInfo.description);
  1061. infoHeader:Show();
  1062. end
  1063. local function GetOverviewSections(rootOverviewSectionID)
  1064. local overviewSections = {};
  1065. local overviewInfo = C_EncounterJournal.GetSectionInfo(rootOverviewSectionID);
  1066. local nextSectionID = overviewInfo.firstChildSectionID;
  1067. while nextSectionID do
  1068. local currentSectionID = nextSectionID; -- cache current one to get icons
  1069. local sectionInfo = C_EncounterJournal.GetSectionInfo(nextSectionID);
  1070. nextSectionID = sectionInfo and sectionInfo.siblingSectionID;
  1071. if sectionInfo then
  1072. if not sectionInfo.filteredByDifficulty then
  1073. local iconFlags = C_EncounterJournal.GetSectionIconFlags(currentSectionID);
  1074. overviewSections[currentSectionID] = iconFlags and iconFlags[1] or NONE_FLAG;
  1075. end
  1076. end
  1077. end
  1078. return overviewSections;
  1079. end
  1080. local function GetOverviewSectionIDForRole(overviewSections, role)
  1081. for sectionID, flag in pairs(overviewSections) do
  1082. if (flag == flagsByRole[role]) then
  1083. return sectionID;
  1084. end
  1085. end
  1086. return nil;
  1087. end
  1088. local function SetUpSectionsForRole(self, overviewSections, role, currentIndex)
  1089. local roleSectionID = GetOverviewSectionIDForRole(overviewSections, role);
  1090. while ( roleSectionID ) do
  1091. EncounterJournal_SetUpOverview(self, roleSectionID, currentIndex);
  1092. currentIndex = currentIndex + 1;
  1093. overviewSections[roleSectionID] = nil;
  1094. roleSectionID = GetOverviewSectionIDForRole(overviewSections, role);
  1095. end
  1096. return currentIndex;
  1097. end
  1098. function EncounterJournal_ToggleHeaders(self, doNotShift)
  1099. local numAdded = 0;
  1100. local infoHeader, parentID, _;
  1101. local hWidth = self:GetWidth();
  1102. local nextSectionID;
  1103. local topLevelSection = false;
  1104. local isOverview = self.isOverview;
  1105. local hideHeaders;
  1106. if (not self.isOverview or (self.isOverview and self.overviewIndex)) then
  1107. self.expanded = not self.expanded;
  1108. hideHeaders = not self.expanded;
  1109. end
  1110. if hideHeaders then
  1111. self.button.expandedIcon:SetText("+");
  1112. self.description:Hide();
  1113. if (self.overviewDescription) then
  1114. self.overviewDescription:Hide();
  1115. end
  1116. self.descriptionBG:Hide();
  1117. self.descriptionBGBottom:Hide();
  1118. EncounterJournal_CleanBullets(self, nil, true);
  1119. if (self.overviewIndex) then
  1120. local overview = EncounterJournal.encounter.overviewFrame.overviews[self.overviewIndex + 1];
  1121. if (overview) then
  1122. overview:SetPoint("TOPLEFT", self, "BOTTOMLEFT", 0, -9);
  1123. end
  1124. else
  1125. EncounterJournal_ClearChildHeaders(self);
  1126. end
  1127. else
  1128. if (not isOverview) then
  1129. if strlen(self.description:GetText() or "") > 0 then
  1130. self.description:Show();
  1131. if (self.overviewDescription) then
  1132. self.overviewDescription:Hide();
  1133. end
  1134. if self.button then
  1135. self.descriptionBG:Show();
  1136. self.descriptionBGBottom:Show();
  1137. self.button.expandedIcon:SetText("-");
  1138. end
  1139. elseif self.button then
  1140. self.description:Hide();
  1141. if (self.overviewDescription) then
  1142. self.overviewDescription:Hide();
  1143. end
  1144. self.descriptionBG:Hide();
  1145. self.descriptionBGBottom:Hide();
  1146. self.button.expandedIcon:SetText("-");
  1147. end
  1148. else
  1149. if (self.overviewIndex) then
  1150. self.button.expandedIcon:SetText("-");
  1151. for i = 1, #self.Bullets do
  1152. self.Bullets[i]:Show();
  1153. end
  1154. self.description:Hide();
  1155. self.overviewDescription:Show();
  1156. self.descriptionBG:Show();
  1157. self.descriptionBGBottom:Show();
  1158. local overview = EncounterJournal.encounter.overviewFrame.overviews[self.overviewIndex + 1];
  1159. if (overview) then
  1160. if (self.Bullets and #self.Bullets > 0) then
  1161. overview:SetPoint("TOPLEFT", self.Bullets[#self.Bullets], "BOTTOMLEFT", -13, -18);
  1162. else
  1163. local yoffset = -18 - self:GetHeight();
  1164. overview:SetPoint("TOPLEFT", self, "BOTTOMLEFT", 0, yoffset);
  1165. end
  1166. end
  1167. EncounterJournal_UpdateButtonState(self.button);
  1168. end
  1169. end
  1170. -- Get Section Info
  1171. if (not isOverview) then
  1172. local freeHeaders = EncounterJournal.encounter.freeHeaders;
  1173. local usedHeaders = EncounterJournal.encounter.usedHeaders;
  1174. local listEnd = #usedHeaders;
  1175. if self.myID then -- this is from a button click
  1176. local sectionInfo = C_EncounterJournal.GetSectionInfo(self.myID);
  1177. nextSectionID = sectionInfo and sectionInfo.firstChildSectionID;
  1178. parentID = self.myID;
  1179. self.description:SetWidth(self:GetWidth() -20);
  1180. hWidth = hWidth - HEADER_INDENT;
  1181. else
  1182. --This sets the base encounter header
  1183. parentID = self.encounterID;
  1184. nextSectionID = self.rootSectionID;
  1185. topLevelSection = true;
  1186. end
  1187. while nextSectionID do
  1188. local sectionInfo = C_EncounterJournal.GetSectionInfo(nextSectionID);
  1189. if not sectionInfo then
  1190. break;
  1191. end
  1192. if not sectionInfo.filteredByDifficulty then --ignore all sections that should not be shown with our current difficulty settings, but do not stop iteration
  1193. if #freeHeaders == 0 then -- create a new header;
  1194. headerCount = headerCount + 1; -- the is a file local
  1195. infoHeader = CreateFrame("FRAME", "EncounterJournalInfoHeader"..headerCount, EncounterJournal.encounter.infoFrame, "EncounterInfoTemplate");
  1196. infoHeader:Hide();
  1197. else
  1198. infoHeader = freeHeaders[#freeHeaders];
  1199. freeHeaders[#freeHeaders] = nil;
  1200. end
  1201. numAdded = numAdded + 1;
  1202. toggleTempList[#toggleTempList+1] = infoHeader;
  1203. infoHeader.spellID = sectionInfo.spellID;
  1204. infoHeader.button.link = sectionInfo.link;
  1205. infoHeader.parentID = parentID;
  1206. infoHeader.myID = nextSectionID;
  1207. -- Spell names can show up in white, which clashes with the parchment, strip out white color codes.
  1208. local description;
  1209. if sectionInfo.description then
  1210. description = sectionInfo.description:gsub("\|cffffffff(.-)\|r", "%1");
  1211. else
  1212. description = RETRIEVING_DATA;
  1213. end
  1214. infoHeader.description:SetText(description);
  1215. infoHeader.button.title:SetText(sectionInfo.title);
  1216. if topLevelSection then
  1217. infoHeader.button.title:SetFontObject("GameFontNormalMed3");
  1218. else
  1219. infoHeader.button.title:SetFontObject("GameFontNormal");
  1220. end
  1221. --All headers start collapsed
  1222. infoHeader.expanded = false
  1223. infoHeader.description:Hide();
  1224. infoHeader.descriptionBG:Hide();
  1225. infoHeader.descriptionBGBottom:Hide();
  1226. infoHeader.button.expandedIcon:SetText("+");
  1227. for i = 1, #infoHeader.Bullets do
  1228. infoHeader.Bullets[i]:Hide();
  1229. end
  1230. local textLeftAnchor = infoHeader.button.expandedIcon;
  1231. --Show ability Icon
  1232. if sectionInfo.abilityIcon then
  1233. infoHeader.button.abilityIcon:SetTexture(sectionInfo.abilityIcon);
  1234. infoHeader.button.abilityIcon:Show();
  1235. textLeftAnchor = infoHeader.button.abilityIcon;
  1236. else
  1237. infoHeader.button.abilityIcon:Hide();
  1238. end
  1239. --Show Creature Portrait
  1240. if sectionInfo.creatureDisplayID ~= 0 then
  1241. SetPortraitTextureFromCreatureDisplayID(infoHeader.button.portrait.icon, sectionInfo.creatureDisplayID);
  1242. infoHeader.button.portrait.name = sectionInfo.title;
  1243. infoHeader.button.portrait.displayInfo = sectionInfo.creatureDisplayID;
  1244. infoHeader.button.portrait.uiModelSceneID = sectionInfo.uiModelSceneID;
  1245. infoHeader.button.portrait:Show();
  1246. textLeftAnchor = infoHeader.button.portrait;
  1247. infoHeader.button.abilityIcon:Hide();
  1248. else
  1249. infoHeader.button.portrait:Hide();
  1250. infoHeader.button.portrait.name = nil;
  1251. infoHeader.button.portrait.displayInfo = nil;
  1252. infoHeader.button.portrait.uiModelSceneID = nil;
  1253. end
  1254. infoHeader.button.title:SetPoint("LEFT", textLeftAnchor, "RIGHT", 5, 0);
  1255. EncounterJournal_SetupIconFlags(nextSectionID, infoHeader.button);
  1256. infoHeader.index = nil;
  1257. infoHeader:SetWidth(hWidth);
  1258. -- If this section has not be seen and should start open
  1259. if EJ_section_openTable[infoHeader.myID] == nil and sectionInfo.startsOpen then
  1260. EJ_section_openTable[infoHeader.myID] = true;
  1261. end
  1262. --toggleNested?
  1263. if EJ_section_openTable[infoHeader.myID] then
  1264. infoHeader.expanded = false; -- setting false to expand it in EncounterJournal_ToggleHeaders
  1265. numAdded = numAdded + EncounterJournal_ToggleHeaders(infoHeader, true);
  1266. end
  1267. infoHeader:Show();
  1268. end -- if not filteredByDifficulty
  1269. nextSectionID = sectionInfo.siblingSectionID;
  1270. end
  1271. if not doNotShift and numAdded > 0 then
  1272. --fix the usedlist
  1273. local startIndex = self.index or 0;
  1274. for i=listEnd,startIndex+1,-1 do
  1275. usedHeaders[i+numAdded] = usedHeaders[i];
  1276. usedHeaders[i+numAdded].index = i + numAdded;
  1277. usedHeaders[i] = nil
  1278. end
  1279. for i=1,numAdded do
  1280. usedHeaders[startIndex + i] = toggleTempList[i];
  1281. usedHeaders[startIndex + i].index = startIndex + i;
  1282. toggleTempList[i] = nil;
  1283. end
  1284. end
  1285. if topLevelSection and usedHeaders[1] then
  1286. usedHeaders[1]:SetPoint("TOPRIGHT", 0 , -8 - EncounterJournal.encounter.infoFrame.descriptionHeight - SECTION_BUTTON_OFFSET);
  1287. end
  1288. elseif (not self.overviewIndex) then
  1289. for i = 1, #self.overviews do
  1290. self.overviews[i]:Hide();
  1291. end
  1292. EncounterJournal.overviewDefaultRole = nil;
  1293. if (not self.rootOverviewSectionID) then
  1294. return;
  1295. end
  1296. local spec, role;
  1297. spec = GetSpecialization();
  1298. if (spec) then
  1299. role = GetSpecializationRole(spec);
  1300. else
  1301. role = "DAMAGER";
  1302. end
  1303. local overviewSections = GetOverviewSections(self.rootOverviewSectionID);
  1304. -- character role
  1305. local nextIndex = SetUpSectionsForRole(self, overviewSections, role, 1);
  1306. local hasRoleSection = nextIndex > 1;
  1307. -- other roles
  1308. for i, otherRole in ipairs(overviewPriorities) do
  1309. if (otherRole ~= role) then
  1310. nextIndex = SetUpSectionsForRole(self, overviewSections, otherRole, nextIndex);
  1311. end
  1312. end
  1313. if (self.linkSection) then
  1314. for i = 1, 3 do
  1315. local overview = self.overviews[i];
  1316. if (overview.sectionID == self.linkSection) then
  1317. overview.expanded = false;
  1318. EncounterJournal_ToggleHeaders(overview);
  1319. overview.cbCount = 0;
  1320. overview.flashAnim:Play();
  1321. overview:SetScript("OnUpdate", EncounterJournal_FocusSectionCallback);
  1322. else
  1323. overview.expanded = true;
  1324. EncounterJournal_ToggleHeaders(overview);
  1325. overview.flashAnim:Stop();
  1326. overview:SetScript("OnUpdate", nil);
  1327. end
  1328. end
  1329. self.linkSection = nil;
  1330. else
  1331. self.overviews[1].expanded = false;
  1332. EncounterJournal.overviewDefaultRole = role;
  1333. if ( hasRoleSection ) then
  1334. EncounterJournal_ToggleHeaders(self.overviews[1]);
  1335. end
  1336. end
  1337. end
  1338. end
  1339. if (not isOverview) then
  1340. if self.myID then
  1341. EJ_section_openTable[self.myID] = self.expanded;
  1342. end
  1343. if not doNotShift then
  1344. EncounterJournal_ShiftHeaders(self.index or 1);
  1345. --check to see if it is offscreen
  1346. if self.index and not EncounterJournal.encounter.infoFrame.updatingSpells then
  1347. local scrollValue = EncounterJournal.encounter.info.detailsScroll.ScrollBar:GetValue();
  1348. local cutoff = EncounterJournal.encounter.info.detailsScroll:GetHeight() + scrollValue;
  1349. local _, _, _, _, anchorY = self:GetPoint();
  1350. anchorY = anchorY - self:GetHeight();
  1351. if self.description:IsShown() then
  1352. anchorY = anchorY - self.description:GetHeight() - SECTION_DESCRIPTION_OFFSET;
  1353. end
  1354. if cutoff < abs(anchorY) then
  1355. self.frameCount = 0;
  1356. self:SetScript("OnUpdate", EncounterJournal_MoveSectionUpdate);
  1357. end
  1358. end
  1359. end
  1360. return numAdded;
  1361. else
  1362. return 0;
  1363. end
  1364. end
  1365. function EncounterJournal_ShiftHeaders(index)
  1366. local usedHeaders = EncounterJournal.encounter.usedHeaders;
  1367. if not usedHeaders[index] then
  1368. return;
  1369. end
  1370. local _, _, _, _, anchorY = usedHeaders[index]:GetPoint();
  1371. for i=index,#usedHeaders-1 do
  1372. anchorY = anchorY - usedHeaders[i]:GetHeight();
  1373. if usedHeaders[i].description:IsShown() then
  1374. anchorY = anchorY - usedHeaders[i].description:GetHeight() - SECTION_DESCRIPTION_OFFSET;
  1375. else
  1376. anchorY = anchorY - SECTION_BUTTON_OFFSET;
  1377. end
  1378. usedHeaders[i+1]:SetPoint("TOPRIGHT", 0 , anchorY);
  1379. end
  1380. end
  1381. function EncounterJournal_ResetHeaders()
  1382. for key,_ in pairs(EJ_section_openTable) do
  1383. EJ_section_openTable[key] = nil;
  1384. end
  1385. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  1386. EncounterJournal_Refresh();
  1387. end
  1388. function EncounterJournal_FocusSection(sectionID)
  1389. if (not EncounterJournal_CheckForOverview(sectionID)) then
  1390. local usedHeaders = EncounterJournal.encounter.usedHeaders;
  1391. for _, section in pairs(usedHeaders) do
  1392. if section.myID == sectionID then
  1393. section.cbCount = 0;
  1394. section.flashAnim:Play();
  1395. section:SetScript("OnUpdate", EncounterJournal_FocusSectionCallback);
  1396. else
  1397. section.flashAnim:Stop();
  1398. section:SetScript("OnUpdate", nil);
  1399. end
  1400. end
  1401. end
  1402. end
  1403. function EncounterJournal_FocusSectionCallback(self)
  1404. if self.cbCount > 0 then
  1405. local _, _, _, _, anchorY = self:GetPoint();
  1406. local scrollFrame = self:GetParent():GetParent();
  1407. if ( self.isOverview ) then
  1408. -- +4 puts the scrollbar all the way at the bottom when going to the last section
  1409. anchorY = scrollFrame:GetBottom() - self.descriptionBG:GetBottom() + 4;
  1410. else
  1411. anchorY = abs(anchorY);
  1412. anchorY = anchorY - scrollFrame:GetHeight()/2;
  1413. end
  1414. scrollFrame.ScrollBar:SetValue(anchorY);
  1415. self:SetScript("OnUpdate", nil);
  1416. end
  1417. self.cbCount = self.cbCount + 1;
  1418. end
  1419. function EncounterJournal_MoveSectionUpdate(self)
  1420. if self.frameCount > 0 then
  1421. local _, _, _, _, anchorY = self:GetPoint();
  1422. local height = min(EJ_MAX_SECTION_MOVE, self:GetHeight() + self.description:GetHeight() + SECTION_DESCRIPTION_OFFSET);
  1423. local scrollValue = abs(anchorY) - (EncounterJournal.encounter.info.detailsScroll:GetHeight()-height);
  1424. EncounterJournal.encounter.info.detailsScroll.ScrollBar:SetValue(scrollValue);
  1425. self:SetScript("OnUpdate", nil);
  1426. end
  1427. self.frameCount = self.frameCount + 1;
  1428. end
  1429. function EncounterJournal_ClearChildHeaders(self, doNotShift)
  1430. local usedHeaders = EncounterJournal.encounter.usedHeaders;
  1431. local freeHeaders = EncounterJournal.encounter.freeHeaders;
  1432. local numCleared = 0
  1433. for key,header in pairs(usedHeaders) do
  1434. if header.parentID == self.myID then
  1435. if header.expanded then
  1436. numCleared = numCleared + EncounterJournal_ClearChildHeaders(header, true)
  1437. end
  1438. header:Hide();
  1439. usedHeaders[key] = nil;
  1440. freeHeaders[#freeHeaders+1] = header;
  1441. numCleared = numCleared + 1;
  1442. end
  1443. end
  1444. if numCleared > 0 and not doNotShift then
  1445. local placeIndex = self.index + 1;
  1446. local shiftHeader = usedHeaders[placeIndex + numCleared];
  1447. while shiftHeader do
  1448. usedHeaders[placeIndex] = shiftHeader;
  1449. usedHeaders[placeIndex].index = placeIndex;
  1450. usedHeaders[placeIndex + numCleared] = nil;
  1451. placeIndex = placeIndex + 1;
  1452. shiftHeader = usedHeaders[placeIndex + numCleared];
  1453. end
  1454. end
  1455. return numCleared
  1456. end
  1457. function EncounterJournal_ClearDetails()
  1458. EncounterJournal.encounter.instance:Hide();
  1459. EncounterJournal.encounter.infoFrame.description:SetText("");
  1460. EncounterJournal.encounter.info.encounterTitle:SetText("");
  1461. EncounterJournal.encounter.info.overviewScroll.ScrollBar:SetValue(0);
  1462. EncounterJournal.encounter.info.lootScroll.scrollBar:SetValue(0);
  1463. EncounterJournal.encounter.info.detailsScroll.ScrollBar:SetValue(0);
  1464. EncounterJournal.encounter.info.bossesScroll.ScrollBar:SetValue(0);
  1465. local freeHeaders = EncounterJournal.encounter.freeHeaders;
  1466. local usedHeaders = EncounterJournal.encounter.usedHeaders;
  1467. for key,used in pairs(usedHeaders) do
  1468. used:Hide();
  1469. usedHeaders[key] = nil;
  1470. freeHeaders[#freeHeaders+1] = used;
  1471. end
  1472. local clearDisplayInfo = true;
  1473. EncounterJournal_HideCreatures(clearDisplayInfo);
  1474. local bossIndex = 1
  1475. local bossButton = _G["EncounterJournalBossButton"..bossIndex];
  1476. while bossButton do
  1477. bossButton:Hide();
  1478. bossIndex = bossIndex + 1;
  1479. bossButton = _G["EncounterJournalBossButton"..bossIndex];
  1480. end
  1481. EncounterJournal.searchResults:Hide();
  1482. EncounterJournal_HideSearchPreview();
  1483. EncounterJournal.searchBox:ClearFocus();
  1484. end
  1485. function EncounterJournal_TabClicked(self, button)
  1486. local tabType = self:GetID();
  1487. EncounterJournal_SetTab(tabType);
  1488. PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
  1489. end
  1490. function EncounterJournal_SetTab(tabType)
  1491. local info = EncounterJournal.encounter.info;
  1492. info.tab = tabType;
  1493. for key, data in pairs(EJ_Tabs) do
  1494. if key == tabType then
  1495. info[data.frame]:Show();
  1496. info[data.button].selected:Show();
  1497. info[data.button].unselected:Hide();
  1498. info[data.button]:LockHighlight();
  1499. else
  1500. info[data.frame]:Hide();
  1501. info[data.button].selected:Hide();
  1502. info[data.button].unselected:Show();
  1503. info[data.button]:UnlockHighlight();
  1504. end
  1505. end
  1506. UpdateDifficultyVisibility();
  1507. end
  1508. function EncounterJournal_SetTabEnabled(tab, enabled)
  1509. tab:SetEnabled(enabled);
  1510. tab:GetDisabledTexture():SetDesaturated(not enabled);
  1511. tab.unselected:SetDesaturated(not enabled);
  1512. if not enabled then
  1513. EncounterJournal_ValidateSelectedTab();
  1514. end
  1515. end
  1516. function EncounterJournal_ValidateSelectedTab()
  1517. local info = EncounterJournal.encounter.info;
  1518. local selectedTabButton = info[EJ_Tabs[info.tab].button];
  1519. if not selectedTabButton:IsEnabled() then
  1520. for index, data in ipairs(EJ_Tabs) do
  1521. local tabButton = info[data.button];
  1522. if tabButton:IsEnabled() then
  1523. EncounterJournal_SetTab(index);
  1524. break;
  1525. end
  1526. end
  1527. end
  1528. end
  1529. function EncounterJournal_SetLootButton(item)
  1530. local itemInfo = EncounterJournalData.itemInfoList[item.index];
  1531. item.encounterID = itemInfo and itemInfo.encounterID;
  1532. item.itemID = itemInfo and itemInfo.itemID;
  1533. item.link = itemInfo and itemInfo.link;
  1534. if item.showingTooltip then
  1535. EncounterJournal_SetTooltip(item.link);
  1536. end
  1537. if itemInfo.type and itemInfo.type == "divider" then
  1538. item.dividerFrame.name:SetText(itemInfo.name);
  1539. item:Show();
  1540. item.lootFrame:Hide();
  1541. item.dividerFrame:Show();
  1542. item:SetEnabled(false);
  1543. return;
  1544. else
  1545. item.lootFrame:Show();
  1546. item.dividerFrame:Hide();
  1547. item:SetEnabled(true);
  1548. end
  1549. local currentFrame = item.lootFrame;
  1550. if not itemInfo or not itemInfo.name then
  1551. currentFrame.name:SetText(RETRIEVING_ITEM_INFO);
  1552. currentFrame.icon:SetTexture("Interface\\Icons\\INV_Misc_QuestionMark");
  1553. currentFrame.slot:SetText("");
  1554. currentFrame.armorType:SetText("");
  1555. currentFrame.boss:SetText("");
  1556. item:Show();
  1557. return;
  1558. end
  1559. currentFrame.name:SetText(WrapTextInColorCode(itemInfo.name, itemInfo.itemQuality));
  1560. currentFrame.icon:SetTexture(itemInfo.icon);
  1561. if itemInfo.handError then
  1562. currentFrame.slot:SetText(INVALID_EQUIPMENT_COLOR:WrapTextInColorCode(itemInfo.slot));
  1563. else
  1564. currentFrame.slot:SetText(itemInfo.slot);
  1565. end
  1566. if itemInfo.weaponTypeError then
  1567. currentFrame.armorType:SetText(INVALID_EQUIPMENT_COLOR:WrapTextInColorCode(itemInfo.armorType));
  1568. else
  1569. currentFrame.armorType:SetText(itemInfo.armorType);
  1570. end
  1571. local trueIndex = itemInfo.lootIndex;
  1572. local numEncounters = EJ_GetNumEncountersForLootByIndex(trueIndex);
  1573. if ( numEncounters == 1 ) then
  1574. currentFrame.boss:SetFormattedText(BOSS_INFO_STRING, EJ_GetEncounterInfo(itemInfo.encounterID));
  1575. elseif ( numEncounters == 2) then
  1576. local itemInfoSecond = C_EncounterJournal.GetLootInfoByIndex(trueIndex, 2);
  1577. local secondEncounterID = itemInfoSecond and itemInfoSecond.encounterID;
  1578. if ( itemInfo.encounterID and secondEncounterID ) then
  1579. currentFrame.boss:SetFormattedText(BOSS_INFO_STRING_TWO, EJ_GetEncounterInfo(itemInfo.encounterID), EJ_GetEncounterInfo(secondEncounterID));
  1580. end
  1581. elseif ( numEncounters > 2 ) then
  1582. currentFrame.boss:SetFormattedText(BOSS_INFO_STRING_MANY, EJ_GetEncounterInfo(itemInfo.encounterID));
  1583. end
  1584. local itemName, _, quality = GetItemInfo(itemInfo.link);
  1585. SetItemButtonQuality(currentFrame, quality, itemInfo.link);
  1586. item:Show();
  1587. end
  1588. function EncounterJournal_LootCallback(itemID)
  1589. local scrollFrame = EncounterJournal.encounter.info.lootScroll;
  1590. for i, item in ipairs(scrollFrame.buttons) do
  1591. if item.itemID == itemID and item:IsShown() then
  1592. EncounterJournal_SetLootButton(item, item.index);
  1593. end
  1594. end
  1595. end
  1596. local lootDividerItem = {
  1597. name = BONUS_LOOT_TOOLTIP_TITLE,
  1598. icon = nil,
  1599. slot = nil,
  1600. armorType = nil,
  1601. boss = nil,
  1602. type = "divider",
  1603. }
  1604. function EncounterJournal_BuildLootItemList()
  1605. EncounterJournalData.itemLootCount = EJ_GetNumLoot();
  1606. EncounterJournalData.itemInfoList = {};
  1607. local bonusItemInfoList = {};
  1608. for i = 1, EncounterJournalData.itemLootCount do
  1609. local itemInfo = C_EncounterJournal.GetLootInfoByIndex(i);
  1610. itemInfo.lootIndex = i;
  1611. if itemInfo.displayAsPerPlayerLoot then
  1612. tinsert(bonusItemInfoList, itemInfo);
  1613. else
  1614. tinsert(EncounterJournalData.itemInfoList, itemInfo);
  1615. end
  1616. end
  1617. if #bonusItemInfoList > 0 then
  1618. tinsert(EncounterJournalData.itemInfoList, lootDividerItem);
  1619. -- add one for the nwe divider we just added
  1620. EncounterJournalData.itemLootCount = EncounterJournalData.itemLootCount + 1;
  1621. EncounterJournalData.lootDividerIndex = #EncounterJournalData.itemInfoList;
  1622. tAppendAll(EncounterJournalData.itemInfoList, bonusItemInfoList);
  1623. else
  1624. EncounterJournalData.lootDividerIndex = nil;
  1625. end
  1626. end
  1627. function EncounterJournal_LootUpdate()
  1628. EncounterJournal_UpdateFilterString();
  1629. local scrollFrame = EncounterJournal.encounter.info.lootScroll;
  1630. local offset = HybridScrollFrame_GetOffset(scrollFrame);
  1631. local item, index;
  1632. EncounterJournal_BuildLootItemList();
  1633. local buttonSize = BOSS_LOOT_BUTTON_HEIGHT;
  1634. local buttons = scrollFrame.buttons;
  1635. for i = 1, #buttons do
  1636. button = buttons[i];
  1637. index = offset + i;
  1638. button.dividerFrame:Hide();
  1639. local currentFrame = button.lootFrame;
  1640. if index <= EncounterJournalData.itemLootCount then
  1641. if EncounterJournalData.lootDividerIndex and index == EncounterJournalData.lootDividerIndex then
  1642. -- we have a divider
  1643. button:SetHeight(BOSS_LOOT_BUTTON_HEIGHT);
  1644. currentFrame.boss:Hide();
  1645. currentFrame.bossTexture:Hide();
  1646. currentFrame.bosslessTexture:Show();
  1647. elseif (EncounterJournal.encounterID) then
  1648. button:SetHeight(BOSS_LOOT_BUTTON_HEIGHT);
  1649. currentFrame.boss:Hide();
  1650. currentFrame.bossTexture:Hide();
  1651. currentFrame.bosslessTexture:Show();
  1652. else
  1653. buttonSize = INSTANCE_LOOT_BUTTON_HEIGHT;
  1654. button:SetHeight(INSTANCE_LOOT_BUTTON_HEIGHT);
  1655. currentFrame.boss:Show();
  1656. currentFrame.bossTexture:Show();
  1657. currentFrame.bosslessTexture:Hide();
  1658. end
  1659. button.index = index;
  1660. EncounterJournal_SetLootButton(button);
  1661. else
  1662. button:Hide();
  1663. end
  1664. end
  1665. local totalHeight = EncounterJournalData.itemLootCount * buttonSize;
  1666. HybridScrollFrame_Update(scrollFrame, totalHeight, scrollFrame:GetHeight());
  1667. end
  1668. function EncounterJournal_LootCalcScroll(offset)
  1669. local buttonHeight = BOSS_LOOT_BUTTON_HEIGHT;
  1670. if (not EncounterJournal.encounterID) then
  1671. buttonHeight = INSTANCE_LOOT_BUTTON_HEIGHT;
  1672. end
  1673. local index = floor(offset/buttonHeight)
  1674. return index, offset - (index*buttonHeight);
  1675. end
  1676. function EncounterJournal_Loot_OnUpdate(self)
  1677. if GameTooltip:IsOwned(self) then
  1678. if IsModifiedClick("DRESSUP") then
  1679. ShowInspectCursor();
  1680. else
  1681. ResetCursor();
  1682. end
  1683. end
  1684. end
  1685. function EncounterJournal_Loot_OnClick(self)
  1686. if (EncounterJournal.encounterID ~= self.encounterID) then
  1687. PlaySound(SOUNDKIT.IG_SPELLBOOK_OPEN);
  1688. EncounterJournal_DisplayEncounter(self.encounterID);
  1689. end
  1690. end
  1691. function EncounterJournal_SetTooltip(link)
  1692. if (not link) then
  1693. return;
  1694. end
  1695. local classID, specID = EJ_GetLootFilter();
  1696. if (specID == 0) then
  1697. local spec = GetSpecialization();
  1698. if (spec and classID == select(3, UnitClass("player"))) then
  1699. specID = GetSpecializationInfo(spec, nil, nil, nil, UnitSex("player"));
  1700. else
  1701. specID = -1;
  1702. end
  1703. end
  1704. GameTooltip:SetAnchorType("ANCHOR_RIGHT");
  1705. GameTooltip:SetHyperlink(link, classID, specID);
  1706. GameTooltip_ShowCompareItem();
  1707. end
  1708. function EncounterJournal_SetFlagIcon(texture, index)
  1709. local iconSize = 32;
  1710. local columns = 256/iconSize;
  1711. local rows = 64/iconSize;
  1712. local l = mod(index, columns) / columns;
  1713. local r = l + (1/columns);
  1714. local t = floor(index/columns) / rows;
  1715. local b = t + (1/rows);
  1716. texture:SetTexCoord(l,r,t,b);
  1717. end
  1718. function EncounterJournal_Refresh(self)
  1719. if EncounterJournal.encounterID then
  1720. EncounterJournal_DisplayEncounter(EncounterJournal.encounterID, true)
  1721. elseif EncounterJournal.instanceID then
  1722. EncounterJournal_DisplayInstance(EncounterJournal.instanceID, true);
  1723. end
  1724. end
  1725. function EncounterJournal_GetSearchDisplay(index)
  1726. local spellID, name, icon, path, typeText, displayInfo, itemID, _;
  1727. local id, stype, _, instanceID, encounterID, itemLink = EJ_GetSearchResult(index);
  1728. if stype == EJ_STYPE_INSTANCE then
  1729. name, _, _, icon = EJ_GetInstanceInfo(id);
  1730. typeText = ENCOUNTER_JOURNAL_INSTANCE;
  1731. elseif stype == EJ_STYPE_ENCOUNTER then
  1732. name = EJ_GetEncounterInfo(id);
  1733. typeText = ENCOUNTER_JOURNAL_ENCOUNTER;
  1734. path = EJ_GetInstanceInfo(instanceID);
  1735. icon = "Interface\\EncounterJournal\\UI-EJ-GenericSearchCreature"
  1736. elseif stype == EJ_STYPE_SECTION then
  1737. local sectionInfo = C_EncounterJournal.GetSectionInfo(id);
  1738. spellID = sectionInfo and sectionInfo.spellID;
  1739. displayInfo = sectionInfo and sectionInfo.creatureDisplayID or 0;
  1740. name = sectionInfo and sectionInfo.title;
  1741. if displayInfo > 0 then
  1742. typeText = ENCOUNTER_JOURNAL_ENCOUNTER_ADD;
  1743. displayInfo = nil;
  1744. icon = "Interface\\EncounterJournal\\UI-EJ-GenericSearchCreature";
  1745. else
  1746. typeText = ENCOUNTER_JOURNAL_ABILITY;
  1747. if (sectionInfo) then
  1748. icon = sectionInfo.abilityIcon;
  1749. end
  1750. end
  1751. path = EJ_GetInstanceInfo(instanceID).." > "..EJ_GetEncounterInfo(encounterID);
  1752. elseif stype == EJ_STYPE_ITEM then
  1753. local lootInfo = C_EncounterJournal.GetLootInfo(id);
  1754. itemID = lootInfo.itemID;
  1755. name = lootInfo.name and WrapTextInColorCode(lootInfo.name, lootInfo.itemQuality);
  1756. icon = lootInfo.icon;
  1757. typeText = ENCOUNTER_JOURNAL_ITEM;
  1758. path = EJ_GetInstanceInfo(instanceID).." > "..EJ_GetEncounterInfo(encounterID);
  1759. elseif stype == EJ_STYPE_CREATURE then
  1760. for i=1,MAX_CREATURES_PER_ENCOUNTER do
  1761. local cId, cName, _, cDisplayInfo = EJ_GetCreatureInfo(i, encounterID);
  1762. if cId == id then
  1763. name = cName
  1764. break;
  1765. end
  1766. end
  1767. icon = "Interface\\EncounterJournal\\UI-EJ-GenericSearchCreature"
  1768. typeText = ENCOUNTER_JOURNAL_ENCOUNTER
  1769. path = EJ_GetInstanceInfo(instanceID).." > "..EJ_GetEncounterInfo(encounterID);
  1770. end
  1771. return spellID, name, icon, path, typeText, displayInfo, itemID, stype, itemLink;
  1772. end
  1773. function EncounterJournal_SelectSearch(index)
  1774. local _;
  1775. local id, stype, difficultyID, instanceID, encounterID = EJ_GetSearchResult(index);
  1776. local sectionID, creatureID, itemID;
  1777. if stype == EJ_STYPE_INSTANCE then
  1778. instanceID = id;
  1779. elseif stype == EJ_STYPE_SECTION then
  1780. sectionID = id;
  1781. elseif stype == EJ_STYPE_ITEM then
  1782. itemID = id;
  1783. elseif stype == EJ_STYPE_CREATURE then
  1784. creatureID = id;
  1785. end
  1786. EncounterJournal_OpenJournal(difficultyID, instanceID, encounterID, sectionID, creatureID, itemID);
  1787. EncounterJournal.searchResults:Hide();
  1788. end
  1789. function EncounterJournal_SearchUpdate()
  1790. local scrollFrame = EncounterJournal.searchResults.scrollFrame;
  1791. local offset = HybridScrollFrame_GetOffset(scrollFrame);
  1792. local results = scrollFrame.buttons;
  1793. local result, index;
  1794. local numResults = EJ_GetNumSearchResults();
  1795. for i = 1,#results do
  1796. result = results[i];
  1797. index = offset + i;
  1798. if index <= numResults then
  1799. local spellID, name, icon, path, typeText, displayInfo, itemID, stype, itemLink = EncounterJournal_GetSearchDisplay(index);
  1800. if stype == EJ_STYPE_INSTANCE then
  1801. result.icon:SetTexCoord(0.16796875, 0.51171875, 0.03125, 0.71875);
  1802. else
  1803. result.icon:SetTexCoord(0, 1, 0, 1);
  1804. end
  1805. result.spellID = spellID;
  1806. result.name:SetText(name);
  1807. result.resultType:SetText(typeText);
  1808. result.path:SetText(path);
  1809. result.icon:SetTexture(icon);
  1810. result.link = itemLink;
  1811. if displayInfo and displayInfo > 0 then
  1812. SetPortraitTextureFromCreatureDisplayID(result.icon, displayInfo);
  1813. end
  1814. result:SetID(index);
  1815. result:Show();
  1816. if result.showingTooltip then
  1817. if itemLink then
  1818. GameTooltip:SetOwner(result, "ANCHOR_RIGHT");
  1819. GameTooltip:SetHyperlink(itemLink);
  1820. GameTooltip_ShowCompareItem();
  1821. else
  1822. GameTooltip:Hide();
  1823. end
  1824. end
  1825. else
  1826. result:Hide();
  1827. end
  1828. end
  1829. local totalHeight = numResults * 49;
  1830. HybridScrollFrame_Update(scrollFrame, totalHeight, 370);
  1831. end
  1832. function EncounterJournal_ShowFullSearch()
  1833. local numResults = EJ_GetNumSearchResults();
  1834. if numResults == 0 then
  1835. EncounterJournal.searchResults:Hide();
  1836. return;
  1837. end
  1838. EncounterJournal.searchResults.TitleText:SetText(string.format(ENCOUNTER_JOURNAL_SEARCH_RESULTS, EncounterJournal.searchBox:GetText(), numResults));
  1839. EncounterJournal.searchResults:Show();
  1840. EncounterJournal_SearchUpdate();
  1841. EncounterJournal.searchResults.scrollFrame.scrollBar:SetValue(0);
  1842. EncounterJournal_HideSearchPreview();
  1843. EncounterJournal.searchBox:ClearFocus();
  1844. end
  1845. function EncounterJournal_RestartSearchTracking()
  1846. if EJ_IsSearchFinished() then
  1847. EncounterJournal_ShowSearch();
  1848. else
  1849. EncounterJournal.searchBox.searchPreviewUpdateDelay = 0;
  1850. EncounterJournal.searchBox:SetScript("OnUpdate", EncounterJournalSearchBox_OnUpdate);
  1851. --Since we just restarted the search we hide the progress bar until the search delay is done.
  1852. EncounterJournal.searchBox.searchProgress:Hide();
  1853. EncounterJournal_FixSearchPreviewBottomBorder();
  1854. end
  1855. end
  1856. function EncounterJournal_ShowSearch()
  1857. if EncounterJournal.searchResults:IsShown() then
  1858. EncounterJournal_ShowFullSearch();
  1859. else
  1860. EncounterJournal_UpdateSearchPreview();
  1861. end
  1862. end
  1863. -- There is a delay before the search is updated to avoid a search progress bar if the search
  1864. -- completes within the grace period.
  1865. local ENCOUNTER_JOURNAL_SEARCH_PREVIEW_UPDATE_DELAY = 0.6;
  1866. function EncounterJournalSearchBox_OnUpdate(self, elapsed)
  1867. if EJ_IsSearchFinished() then
  1868. EncounterJournal_ShowSearch();
  1869. self.searchPreviewUpdateDelay = nil;
  1870. self:SetScript("OnUpdate", nil);
  1871. return;
  1872. end
  1873. self.searchPreviewUpdateDelay = (self.searchPreviewUpdateDelay or 0) + elapsed;
  1874. if self.searchPreviewUpdateDelay > ENCOUNTER_JOURNAL_SEARCH_PREVIEW_UPDATE_DELAY then
  1875. self.searchPreviewUpdateDelay = nil;
  1876. self:SetScript("OnUpdate", nil);
  1877. EncounterJournal_UpdateSearchPreview();
  1878. return;
  1879. end
  1880. end
  1881. function EncounterJournalSearchBoxSearchProgressBar_OnLoad(self)
  1882. self:SetStatusBarColor(0, .6, 0, 1);
  1883. self:SetMinMaxValues(0, 1000);
  1884. self:SetValue(0);
  1885. self:GetStatusBarTexture():SetDrawLayer("BORDER");
  1886. end
  1887. function EncounterJournalSearchBoxSearchProgressBar_OnShow(self)
  1888. self:SetScript("OnUpdate", EncounterJournalSearchBoxSearchProgressBar_OnUpdate);
  1889. end
  1890. function EncounterJournalSearchBoxSearchProgressBar_OnHide(self)
  1891. self:SetScript("OnUpdate", nil);
  1892. self:SetValue(0);
  1893. self.previousResults = nil;
  1894. end
  1895. -- If the searcher does not finish within the update delay then a search progress bar is displayed that
  1896. -- will fill until the search is finished and then display the search preview results.
  1897. function EncounterJournalSearchBoxSearchProgressBar_OnUpdate(self, elapsed)
  1898. if EJ_GetSearchSize() == 0 then
  1899. self:SetValue(0);
  1900. return;
  1901. end
  1902. local _, maxValue = self:GetMinMaxValues();
  1903. self:SetValue((EJ_GetSearchProgress() / EJ_GetSearchSize()) * maxValue);
  1904. --If we don't already have the max number of search previews keep checking if
  1905. --we have new results we can display (unless we are delaying updates).
  1906. if (self.previousResults == nil) or (self.previousResults < EJ_NUM_SEARCH_PREVIEWS) and
  1907. (EncounterJournal.searchBox.searchPreviewUpdateDelay == nil) then
  1908. local numResults = EJ_GetNumSearchResults();
  1909. if (self.previousResults == nil and numResults > 0) or (numResults ~= self.previousResults) then
  1910. EncounterJournal_UpdateSearchPreview();
  1911. end
  1912. self.previousResults = numResults;
  1913. end
  1914. if self:GetValue() >= maxValue then
  1915. self:SetScript("OnUpdate", nil);
  1916. self:SetValue(0);
  1917. EncounterJournal.searchBox.searchProgress:Hide();
  1918. EncounterJournal_ShowSearch();
  1919. end
  1920. end
  1921. function EncounterJournal_UpdateSearchPreview()
  1922. if strlen(EncounterJournal.searchBox:GetText()) < MIN_CHARACTER_SEARCH then
  1923. EncounterJournal_HideSearchPreview();
  1924. EncounterJournal.searchResults:Hide();
  1925. return;
  1926. end
  1927. local numResults = EJ_GetNumSearchResults();
  1928. if numResults == 0 and EJ_IsSearchFinished() then
  1929. EncounterJournal_HideSearchPreview();
  1930. return;
  1931. end
  1932. local lastShown = EncounterJournal.searchBox;
  1933. for index = 1, EJ_NUM_SEARCH_PREVIEWS do
  1934. local button = EncounterJournal.searchBox.searchPreview[index];
  1935. if index <= numResults then
  1936. local spellID, name, icon, path, typeText, displayInfo, itemID, stype, itemLink = EncounterJournal_GetSearchDisplay(index);
  1937. button.spellID = spellID;
  1938. button.name:SetText(name);
  1939. button.icon:SetTexture(icon);
  1940. button.link = itemLink;
  1941. if displayInfo and displayInfo > 0 then
  1942. SetPortraitTextureFromCreatureDisplayID(button.icon, displayInfo);
  1943. end
  1944. button:SetID(index);
  1945. button:Show();
  1946. lastShown = button;
  1947. else
  1948. button:Hide();
  1949. end
  1950. end
  1951. EncounterJournal.searchBox.showAllResults:Hide();
  1952. EncounterJournal.searchBox.searchProgress:Hide();
  1953. if not EJ_IsSearchFinished() then
  1954. EncounterJournal.searchBox.searchProgress:SetPoint("TOP", lastShown, "BOTTOM", 0, 0);
  1955. -- If there are no items to search then the search DB isn't loaded yet.
  1956. if EJ_GetSearchSize() == 0 then
  1957. EncounterJournal.searchBox.searchProgress.loading:Show();
  1958. EncounterJournal.searchBox.searchProgress.bar:Hide();
  1959. else
  1960. EncounterJournal.searchBox.searchProgress.loading:Hide();
  1961. EncounterJournal.searchBox.searchProgress.bar:Show();
  1962. end
  1963. EncounterJournal.searchBox.searchProgress:Show();
  1964. elseif numResults > EJ_NUM_SEARCH_PREVIEWS then
  1965. EncounterJournal.searchBox.showAllResults.text:SetText(string.format(ENCOUNTER_JOURNAL_SHOW_SEARCH_RESULTS, numResults));
  1966. EncounterJournal.searchBox.showAllResults:Show();
  1967. end
  1968. EncounterJournal_FixSearchPreviewBottomBorder();
  1969. EncounterJournal.searchBox.searchPreviewContainer:Show();
  1970. end
  1971. function EncounterJournal_FixSearchPreviewBottomBorder()
  1972. local lastShownButton = nil;
  1973. if EncounterJournal.searchBox.showAllResults:IsShown() then
  1974. lastShownButton = EncounterJournal.searchBox.showAllResults;
  1975. elseif EncounterJournal.searchBox.searchProgress:IsShown() then
  1976. lastShownButton = EncounterJournal.searchBox.searchProgress;
  1977. else
  1978. for index = 1, EJ_NUM_SEARCH_PREVIEWS do
  1979. local button = EncounterJournal.searchBox.searchPreview[index];
  1980. if button:IsShown() then
  1981. lastShownButton = button;
  1982. end
  1983. end
  1984. end
  1985. if lastShownButton ~= nil then
  1986. EncounterJournal.searchBox.searchPreviewContainer.botRightCorner:SetPoint("BOTTOM", lastShownButton, "BOTTOM", 0, -8);
  1987. EncounterJournal.searchBox.searchPreviewContainer.botLeftCorner:SetPoint("BOTTOM", lastShownButton, "BOTTOM", 0, -8);
  1988. else
  1989. EncounterJournal_HideSearchPreview();
  1990. end
  1991. end
  1992. function EncounterJouranl_IsSearchPreviewShown()
  1993. return EncounterJournal.searchBox.searchPreviewContainer:IsShown();
  1994. end
  1995. function EncounterJournal_HideSearchPreview()
  1996. EncounterJournal.searchBox.showAllResults:Hide();
  1997. EncounterJournal.searchBox.searchProgress:Hide();
  1998. local index = 1;
  1999. local unusedButton = EncounterJournal.searchBox.searchPreview[index];
  2000. while unusedButton do
  2001. unusedButton:Hide();
  2002. index = index + 1;
  2003. unusedButton = EncounterJournal.searchBox.searchPreview[index];
  2004. end
  2005. EncounterJournal.searchBox.searchPreviewContainer:Hide();
  2006. end
  2007. function EncounterJournal_ClearSearch()
  2008. EncounterJournal.searchResults:Hide();
  2009. EncounterJournal_HideSearchPreview();
  2010. end
  2011. function EncounterJournalSearchBox_OnLoad(self)
  2012. SearchBoxTemplate_OnLoad(self);
  2013. self.HasStickyFocus = function()
  2014. local ancestry = EncounterJournal.searchBox;
  2015. return DoesAncestryInclude(ancestry, GetMouseFocus());
  2016. end
  2017. self.selectedIndex = 1;
  2018. end
  2019. function EncounterJournalSearchBox_OnShow(self)
  2020. self:SetFrameLevel(self:GetParent():GetFrameLevel() + 10);
  2021. end
  2022. function EncounterJournalSearchBox_OnHide(self)
  2023. self.searchPreviewUpdateDelay = nil;
  2024. self:SetScript("OnUpdate", nil);
  2025. end
  2026. function EncounterJournalSearchBox_OnTextChanged(self)
  2027. SearchBoxTemplate_OnTextChanged(self);
  2028. local text = self:GetText();
  2029. if strlen(text) < MIN_CHARACTER_SEARCH then
  2030. EJ_ClearSearch();
  2031. EncounterJournal_HideSearchPreview();
  2032. EncounterJournal.searchResults:Hide();
  2033. return;
  2034. end
  2035. EncounterJournal_SetSearchPreviewSelection(1);
  2036. EJ_SetSearch(text);
  2037. EncounterJournal_RestartSearchTracking();
  2038. end
  2039. function EncounterJournalSearchBox_OnEnterPressed(self)
  2040. if self.selectedIndex > EJ_SHOW_ALL_SEARCH_RESULTS_INDEX or self.selectedIndex < 0 then
  2041. return;
  2042. elseif self.selectedIndex == EJ_SHOW_ALL_SEARCH_RESULTS_INDEX then
  2043. if EncounterJournal.searchBox.showAllResults:IsShown() then
  2044. EncounterJournal.searchBox.showAllResults:Click();
  2045. end
  2046. else
  2047. local preview = EncounterJournal.searchBox.searchPreview[self.selectedIndex];
  2048. if preview:IsShown() then
  2049. preview:Click();
  2050. end
  2051. end
  2052. EncounterJournal_HideSearchPreview();
  2053. end
  2054. function EncounterJournalSearchBox_OnKeyDown(self, key)
  2055. if key == "UP" then
  2056. EncounterJournal_SetSearchPreviewSelection(EncounterJournal.searchBox.selectedIndex - 1);
  2057. elseif key == "DOWN" then
  2058. EncounterJournal_SetSearchPreviewSelection(EncounterJournal.searchBox.selectedIndex + 1);
  2059. end
  2060. end
  2061. function EncounterJournalSearchBox_OnFocusLost(self)
  2062. SearchBoxTemplate_OnEditFocusLost(self);
  2063. EncounterJournal_HideSearchPreview();
  2064. end
  2065. function EncounterJournalSearchBox_OnFocusGained(self)
  2066. SearchBoxTemplate_OnEditFocusGained(self);
  2067. EncounterJournal.searchResults:Hide();
  2068. EncounterJournal_SetSearchPreviewSelection(1);
  2069. EncounterJournal_UpdateSearchPreview();
  2070. end
  2071. function EncounterJournalSearchBoxShowAllResults_OnEnter(self)
  2072. EncounterJournal_SetSearchPreviewSelection(EJ_SHOW_ALL_SEARCH_RESULTS_INDEX);
  2073. end
  2074. function EncounterJournal_SetSearchPreviewSelection(selectedIndex)
  2075. local searchBox = EncounterJournal.searchBox;
  2076. local numShown = 0;
  2077. for index = 1, EJ_NUM_SEARCH_PREVIEWS do
  2078. searchBox.searchPreview[index].selectedTexture:Hide();
  2079. if searchBox.searchPreview[index]:IsShown() then
  2080. numShown = numShown + 1;
  2081. end
  2082. end
  2083. if searchBox.showAllResults:IsShown() then
  2084. numShown = numShown + 1;
  2085. end
  2086. searchBox.showAllResults.selectedTexture:Hide();
  2087. if numShown == 0 then
  2088. selectedIndex = 1;
  2089. elseif selectedIndex > numShown then
  2090. -- Wrap under to the beginning.
  2091. selectedIndex = 1;
  2092. elseif selectedIndex < 1 then
  2093. -- Wrap over to the end;
  2094. selectedIndex = numShown;
  2095. end
  2096. searchBox.selectedIndex = selectedIndex;
  2097. if selectedIndex == EJ_SHOW_ALL_SEARCH_RESULTS_INDEX then
  2098. searchBox.showAllResults.selectedTexture:Show();
  2099. else
  2100. searchBox.searchPreview[selectedIndex].selectedTexture:Show();
  2101. end
  2102. end
  2103. function EncounterJournal_OpenJournalLink(tag, jtype, id, difficultyID)
  2104. jtype = tonumber(jtype);
  2105. id = tonumber(id);
  2106. difficultyID = tonumber(difficultyID);
  2107. local instanceID, encounterID, sectionID, tierIndex = EJ_HandleLinkPath(jtype, id);
  2108. EncounterJournal_OpenJournal(difficultyID, instanceID, encounterID, sectionID, nil, nil, tierIndex);
  2109. end
  2110. function EncounterJournal_OpenToPowerID(powerID)
  2111. ShowUIPanel(EncounterJournal);
  2112. EJ_ContentTab_Select(EncounterJournal.instanceSelect.LootJournalTab.id);
  2113. EncounterJournal.LootJournal:OpenToPowerID(powerID);
  2114. end
  2115. function EncounterJournal_OpenJournal(difficultyID, instanceID, encounterID, sectionID, creatureID, itemID, tierIndex)
  2116. EJ_HideNonInstancePanels();
  2117. ShowUIPanel(EncounterJournal);
  2118. if instanceID then
  2119. NavBar_Reset(EncounterJournal.navBar);
  2120. EncounterJournal_DisplayInstance(instanceID);
  2121. if difficultyID then
  2122. EJ_SetDifficulty(difficultyID);
  2123. end
  2124. if encounterID then
  2125. if sectionID then
  2126. if (EncounterJournal_CheckForOverview(sectionID)) then
  2127. EncounterJournal.encounter.overviewFrame.linkSection = sectionID;
  2128. else
  2129. local sectionPath = {EJ_GetSectionPath(sectionID)};
  2130. for _, id in pairs(sectionPath) do
  2131. EJ_section_openTable[id] = true;
  2132. end
  2133. end
  2134. end
  2135. EncounterJournal_DisplayEncounter(encounterID);
  2136. end
  2137. if sectionID then
  2138. if (EncounterJournal_CheckForOverview(sectionID) or not EncounterJournal_SearchForOverview(instanceID)) then
  2139. EncounterJournal.encounter.info.overviewTab:Click();
  2140. else
  2141. EncounterJournal.encounter.info.bossTab:Click();
  2142. end
  2143. EncounterJournal_FocusSection(sectionID);
  2144. elseif itemID then
  2145. EncounterJournal.encounter.info.lootTab:Click();
  2146. end
  2147. elseif tierIndex then
  2148. EncounterJournal_TierDropDown_Select(EncounterJournal, tierIndex+1);
  2149. else
  2150. EncounterJournal_ListInstances()
  2151. end
  2152. end
  2153. function EncounterJournal_SelectDifficulty(self, value)
  2154. EJ_SetDifficulty(value);
  2155. end
  2156. function EncounterJournal_DifficultyInit(self, level)
  2157. local currDifficulty = EJ_GetDifficulty();
  2158. local info = UIDropDownMenu_CreateInfo();
  2159. for i, difficultyID in ipairs(EJ_DIFFICULTIES) do
  2160. if EJ_IsValidInstanceDifficulty(difficultyID) then
  2161. info.func = EncounterJournal_SelectDifficulty;
  2162. info.text = GetEJDifficultyString(difficultyID);
  2163. info.arg1 = difficultyID;
  2164. info.checked = currDifficulty == difficultyID;
  2165. UIDropDownMenu_AddButton(info);
  2166. end
  2167. end
  2168. end
  2169. function EJ_HideInstances(index)
  2170. if ( not index ) then
  2171. index = 1;
  2172. end
  2173. local scrollChild = EncounterJournal.instanceSelect.scroll.child;
  2174. local instanceButton = scrollChild["instance"..index];
  2175. while instanceButton do
  2176. instanceButton:Hide();
  2177. index = index + 1;
  2178. instanceButton = scrollChild["instance"..index];
  2179. end
  2180. end
  2181. -- TODO: Fix for Level Squish
  2182. function EJSuggestTab_GetPlayerTierIndex()
  2183. return GetEJTierDataTableID(GetExpansionForLevel(UnitLevel("player")));
  2184. end
  2185. function EJ_ContentTab_OnClick(self)
  2186. EJ_ContentTab_Select(self.id);
  2187. end
  2188. function EJ_ContentTab_Select(id)
  2189. local instanceSelect = EncounterJournal.instanceSelect;
  2190. local selectedTab = nil;
  2191. for i = 1, #instanceSelect.Tabs do
  2192. local tab = instanceSelect.Tabs[i];
  2193. if ( tab.id ~= id ) then
  2194. tab:Enable();
  2195. tab:GetFontString():SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
  2196. tab.selectedGlow:Hide();
  2197. else
  2198. tab:GetFontString():SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
  2199. tab:Disable();
  2200. selectedTab = tab;
  2201. end
  2202. end
  2203. EncounterJournal.selectedTab = id;
  2204. -- Setup background
  2205. local tierData;
  2206. if ( id == instanceSelect.suggestTab.id ) then
  2207. tierData = GetEJTierData(EJSuggestTab_GetPlayerTierIndex());
  2208. else
  2209. tierData = GetEJTierData(EJ_GetCurrentTier());
  2210. end
  2211. selectedTab.selectedGlow:SetVertexColor(tierData.r, tierData.g, tierData.b);
  2212. selectedTab.selectedGlow:Show();
  2213. instanceSelect.bg:SetAtlas(tierData.backgroundAtlas, true);
  2214. EncounterJournal.encounter:Hide();
  2215. EncounterJournal.instanceSelect:Show();
  2216. if ( id == instanceSelect.suggestTab.id ) then
  2217. EJ_HideInstances();
  2218. EJ_HideLootJournalPanel();
  2219. instanceSelect.scroll:Hide();
  2220. EncounterJournal.suggestFrame:Show();
  2221. if ( not instanceSelect.dungeonsTab.grayBox:IsShown() or not instanceSelect.raidsTab.grayBox:IsShown() ) then
  2222. EncounterJournal_DisableTierDropDown(true);
  2223. else
  2224. EncounterJournal_EnableTierDropDown();
  2225. end
  2226. elseif ( id == instanceSelect.LootJournalTab.id ) then
  2227. EJ_HideInstances();
  2228. EJ_HideSuggestPanel();
  2229. instanceSelect.scroll:Hide();
  2230. EncounterJournal_DisableTierDropDown(true);
  2231. EncounterJournal.LootJournal:Show();
  2232. elseif ( id == instanceSelect.dungeonsTab.id or id == instanceSelect.raidsTab.id ) then
  2233. EJ_HideNonInstancePanels();
  2234. instanceSelect.scroll:Show();
  2235. EncounterJournal_ListInstances();
  2236. EncounterJournal_EnableTierDropDown();
  2237. end
  2238. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  2239. end
  2240. function EJ_HideSuggestPanel()
  2241. local instanceSelect = EncounterJournal.instanceSelect;
  2242. local suggestTab = instanceSelect.suggestTab;
  2243. if ( not suggestTab:IsEnabled() or EncounterJournal.suggestFrame:IsShown() ) then
  2244. suggestTab:Enable();
  2245. suggestTab:GetFontString():SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
  2246. suggestTab.selectedGlow:Hide();
  2247. EncounterJournal.suggestFrame:Hide();
  2248. EncounterJournal_EnableTierDropDown();
  2249. local tierData = GetEJTierData(EJ_GetCurrentTier());
  2250. instanceSelect.bg:SetAtlas(tierData.backgroundAtlas, true);
  2251. instanceSelect.raidsTab.selectedGlow:SetVertexColor(tierData.r, tierData.g, tierData.b);
  2252. instanceSelect.dungeonsTab.selectedGlow:SetVertexColor(tierData.r, tierData.g, tierData.b);
  2253. instanceSelect.scroll:Show();
  2254. EncounterJournal.suggestFrame:Hide();
  2255. end
  2256. end
  2257. function EJ_HideLootJournalPanel()
  2258. if ( EncounterJournal.LootJournal ) then
  2259. EncounterJournal.LootJournal:Hide();
  2260. end
  2261. end
  2262. function EJ_HideNonInstancePanels()
  2263. EJ_HideSuggestPanel();
  2264. EJ_HideLootJournalPanel();
  2265. end
  2266. function EJTierDropDown_OnLoad(self)
  2267. UIDropDownMenu_Initialize(self, EJTierDropDown_Initialize, "MENU");
  2268. end
  2269. function EJTierDropDown_Initialize(self, level)
  2270. local info = UIDropDownMenu_CreateInfo();
  2271. local numTiers = EJ_GetNumTiers();
  2272. local currTier = EJ_GetCurrentTier();
  2273. for i=1,numTiers do
  2274. info.text = EJ_GetTierInfo(i);
  2275. info.func = EncounterJournal_TierDropDown_Select
  2276. info.checked = i == currTier;
  2277. info.arg1 = i;
  2278. UIDropDownMenu_AddButton(info, level)
  2279. end
  2280. end
  2281. function EncounterJournal_TierDropDown_Select(_, tier)
  2282. EJ_SelectTier(tier);
  2283. local instanceSelect = EncounterJournal.instanceSelect;
  2284. instanceSelect.dungeonsTab.grayBox:Hide();
  2285. instanceSelect.raidsTab.grayBox:Hide();
  2286. local tierData = GetEJTierData(tier);
  2287. instanceSelect.bg:SetAtlas(tierData.backgroundAtlas, true);
  2288. instanceSelect.raidsTab.selectedGlow:SetVertexColor(tierData.r, tierData.g, tierData.b);
  2289. instanceSelect.dungeonsTab.selectedGlow:SetVertexColor(tierData.r, tierData.g, tierData.b);
  2290. EncounterJournal_CheckAndDisplayLootTab();
  2291. UIDropDownMenu_SetText(instanceSelect.tierDropDown, EJ_GetTierInfo(EJ_GetCurrentTier()));
  2292. EncounterJournal_ListInstances();
  2293. end
  2294. function EncounterJournal_OnFilterChanged(self)
  2295. CloseDropDownMenus(1);
  2296. EncounterJournal_LootUpdate();
  2297. end
  2298. function EncounterJournal_SetClassAndSpecFilter(self, classID, specID)
  2299. EJ_SetLootFilter(classID, specID);
  2300. EncounterJournal_OnFilterChanged(self);
  2301. end
  2302. function EncounterJournal_RefreshSlotFilterText(self)
  2303. local text = ALL_INVENTORY_SLOTS;
  2304. local slotFilter = C_EncounterJournal.GetSlotFilter();
  2305. if slotFilter ~= Enum.ItemSlotFilterType.NoFilter then
  2306. for _, filter in pairs(Enum.ItemSlotFilterType) do
  2307. if ( filter == slotFilter ) then
  2308. text = SlotFilterToSlotName[filter];
  2309. break;
  2310. end
  2311. end
  2312. end
  2313. EncounterJournal.encounter.info.lootScroll.slotFilter:SetText(text);
  2314. end
  2315. function EncounterJournal_SetSlotFilter(self, slot)
  2316. C_EncounterJournal.SetSlotFilter(slot);
  2317. EncounterJournal_RefreshSlotFilterText(self);
  2318. EncounterJournal_OnFilterChanged(self);
  2319. end
  2320. function EncounterJournal_UpdateFilterString()
  2321. local name, _;
  2322. local classID, specID = EJ_GetLootFilter();
  2323. if (specID > 0) then
  2324. _, name = GetSpecializationInfoByID(specID, UnitSex("player"))
  2325. elseif (classID > 0) then
  2326. local classInfo = C_CreatureInfo.GetClassInfo(classID);
  2327. if classInfo then
  2328. name = classInfo.className;
  2329. end
  2330. end
  2331. if name then
  2332. EncounterJournal.encounter.info.lootScroll.classClearFilter.text:SetText(string.format(EJ_CLASS_FILTER, name));
  2333. EncounterJournal.encounter.info.lootScroll.classClearFilter:Show();
  2334. EncounterJournal.encounter.info.lootScroll:SetHeight(360);
  2335. else
  2336. EncounterJournal.encounter.info.lootScroll.classClearFilter:Hide();
  2337. EncounterJournal.encounter.info.lootScroll:SetHeight(382);
  2338. end
  2339. end
  2340. local CLASS_DROPDOWN = 1;
  2341. function EncounterJournal_InitLootFilter(self, level)
  2342. local filterClassID, filterSpecID = EJ_GetLootFilter();
  2343. local sex = UnitSex("player");
  2344. local classDisplayName, classTag, classID;
  2345. local info = UIDropDownMenu_CreateInfo();
  2346. info.keepShownOnClick = nil;
  2347. if (UIDROPDOWNMENU_MENU_VALUE == CLASS_DROPDOWN) then
  2348. info.text = ALL_CLASSES;
  2349. info.checked = (filterClassID == 0);
  2350. info.arg1 = 0;
  2351. info.arg2 = 0;
  2352. info.func = EncounterJournal_SetClassAndSpecFilter;
  2353. UIDropDownMenu_AddButton(info, level);
  2354. local numClasses = GetNumClasses();
  2355. for i = 1, numClasses do
  2356. classDisplayName, classTag, classID = GetClassInfo(i);
  2357. info.text = classDisplayName;
  2358. info.checked = (filterClassID == classID);
  2359. info.arg1 = classID;
  2360. info.arg2 = 0;
  2361. info.func = EncounterJournal_SetClassAndSpecFilter;
  2362. UIDropDownMenu_AddButton(info, level);
  2363. end
  2364. end
  2365. if (level == 1) then
  2366. info.text = CLASS;
  2367. info.func = nil;
  2368. info.notCheckable = true;
  2369. info.hasArrow = true;
  2370. info.value = CLASS_DROPDOWN;
  2371. UIDropDownMenu_AddButton(info, level)
  2372. if ( filterClassID > 0 ) then
  2373. classID = filterClassID;
  2374. local classInfo = C_CreatureInfo.GetClassInfo(filterClassID);
  2375. if classInfo then
  2376. classDisplayName = classInfo.className;
  2377. classTag = classInfo.classFile;
  2378. end
  2379. else
  2380. classDisplayName, classTag, classID = UnitClass("player");
  2381. end
  2382. info.text = classDisplayName;
  2383. info.notCheckable = true;
  2384. info.arg1 = nil;
  2385. info.arg2 = nil;
  2386. info.func = nil;
  2387. info.hasArrow = false;
  2388. UIDropDownMenu_AddButton(info, level);
  2389. info.notCheckable = nil;
  2390. local numSpecs = GetNumSpecializationsForClassID(classID);
  2391. for i = 1, numSpecs do
  2392. local specID, specName = GetSpecializationInfoForClassID(classID, i, sex);
  2393. info.leftPadding = 10;
  2394. info.text = specName;
  2395. info.checked = (filterSpecID == specID);
  2396. info.arg1 = classID;
  2397. info.arg2 = specID;
  2398. info.func = EncounterJournal_SetClassAndSpecFilter;
  2399. UIDropDownMenu_AddButton(info, level);
  2400. end
  2401. info.text = ALL_SPECS;
  2402. info.leftPadding = 10;
  2403. info.checked = (classID == filterClassID) and (filterSpecID == 0);
  2404. info.arg1 = classID;
  2405. info.arg2 = 0;
  2406. info.func = EncounterJournal_SetClassAndSpecFilter;
  2407. UIDropDownMenu_AddButton(info, level);
  2408. end
  2409. end
  2410. function EncounterJournal_InitLootSlotFilter(self, level)
  2411. local slotFilter = C_EncounterJournal.GetSlotFilter();
  2412. local info = UIDropDownMenu_CreateInfo();
  2413. info.text = ALL_INVENTORY_SLOTS;
  2414. info.checked = slotFilter == Enum.ItemSlotFilterType.NoFilter;
  2415. info.arg1 = Enum.ItemSlotFilterType.NoFilter;
  2416. info.func = EncounterJournal_SetSlotFilter;
  2417. UIDropDownMenu_AddButton(info);
  2418. C_EncounterJournal.ResetSlotFilter();
  2419. local isLootSlotPresent = {};
  2420. for i = 1, EncounterJournalData.itemLootCount do
  2421. local itemInfo = EncounterJournalData.itemInfoList[i];
  2422. local filterType = itemInfo and itemInfo.filterType;
  2423. if ( filterType ) then
  2424. isLootSlotPresent[filterType] = true;
  2425. end
  2426. end
  2427. C_EncounterJournal.SetSlotFilter(slotFilter);
  2428. for _, filter in pairs(Enum.ItemSlotFilterType) do
  2429. if ( (isLootSlotPresent[filter] or filter == slotFilter) and filter ~= Enum.ItemSlotFilterType.NoFilter ) then
  2430. info.text = SlotFilterToSlotName[filter];
  2431. info.checked = slotFilter == filter;
  2432. info.arg1 = filter;
  2433. UIDropDownMenu_AddButton(info);
  2434. end
  2435. end
  2436. end
  2437. ----------------------------------------
  2438. --------------Nav Bar Func--------------
  2439. ----------------------------------------
  2440. function EJNAV_RefreshInstance()
  2441. EncounterJournal_DisplayInstance(EncounterJournal.instanceID, true);
  2442. end
  2443. function EJNAV_SelectInstance(self, index, navBar)
  2444. local instanceID = EJ_GetInstanceByIndex(index, EJ_InstanceIsRaid());
  2445. --Clear any previous selection.
  2446. NavBar_Reset(navBar);
  2447. EncounterJournal_DisplayInstance(instanceID);
  2448. end
  2449. function EJNAV_GetInstanceList(self)
  2450. local list = { };
  2451. local _, name = EJ_GetInstanceByIndex(1, EJ_InstanceIsRaid());
  2452. while name do
  2453. local entry = { text = name, id = #list + 1, func = EJNAV_SelectInstance };
  2454. tinsert(list, entry);
  2455. _, name = EJ_GetInstanceByIndex(#list + 1, EJ_InstanceIsRaid());
  2456. end
  2457. return list;
  2458. end
  2459. function EJNAV_RefreshEncounter()
  2460. EncounterJournal_DisplayInstance(EncounterJournal.encounterID);
  2461. end
  2462. function EJNAV_SelectEncounter(self, index, navBar)
  2463. local _, _, bossID = EJ_GetEncounterInfoByIndex(index);
  2464. EncounterJournal_DisplayEncounter(bossID);
  2465. end
  2466. function EJNAV_GetEncounterList(self)
  2467. local list = { };
  2468. local name = EJ_GetEncounterInfoByIndex(1);
  2469. while name do
  2470. local entry = { text = name, id = #list + 1, func = EJNAV_SelectEncounter };
  2471. tinsert(list, entry);
  2472. name = EJ_GetEncounterInfoByIndex(#list + 1);
  2473. end
  2474. return list;
  2475. end
  2476. -------------------------------------------------
  2477. --------------Suggestion Panel Func--------------
  2478. -------------------------------------------------
  2479. function EJSuggestFrame_OnLoad(self)
  2480. self.suggestions = {};
  2481. self:RegisterEvent("AJ_REWARD_DATA_RECEIVED");
  2482. self:RegisterEvent("AJ_REFRESH_DISPLAY");
  2483. end
  2484. function EJSuggestFrame_OnEvent(self, event, ...)
  2485. if ( event == "AJ_REFRESH_DISPLAY" ) then
  2486. if self:GetParent().selectedTab == EncounterJournal.instanceSelect.suggestTab.id then
  2487. EJSuggestFrame_RefreshDisplay();
  2488. local newAdventureNotice = ...;
  2489. if ( newAdventureNotice ) then
  2490. EJMicroButton:UpdateNewAdventureNotice();
  2491. end
  2492. end
  2493. elseif ( event == "AJ_REWARD_DATA_RECEIVED" ) then
  2494. EJSuggestFrame_RefreshRewards()
  2495. end
  2496. end
  2497. function EJSuggestFrame_OnShow(self)
  2498. EJMicroButton:ClearNewAdventureNotice();
  2499. C_AdventureJournal.UpdateSuggestions();
  2500. EJSuggestFrame_RefreshDisplay();
  2501. EncounterJournal_RefreshSlotFilterText();
  2502. end
  2503. function EJSuggestFrame_NextSuggestion()
  2504. if ( C_AdventureJournal.GetPrimaryOffset() < C_AdventureJournal.GetNumAvailableSuggestions()-1 ) then
  2505. C_AdventureJournal.SetPrimaryOffset(C_AdventureJournal.GetPrimaryOffset()+1);
  2506. PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
  2507. end
  2508. end
  2509. function EJSuggestFrame_PrevSuggestion()
  2510. if( C_AdventureJournal.GetPrimaryOffset() > 0 ) then
  2511. C_AdventureJournal.SetPrimaryOffset(C_AdventureJournal.GetPrimaryOffset()-1);
  2512. PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
  2513. end
  2514. end
  2515. function EJSuggestFrame_OnMouseWheel( self, value )
  2516. if ( value > 0 ) then
  2517. EJSuggestFrame_PrevSuggestion();
  2518. else
  2519. EJSuggestFrame_NextSuggestion()
  2520. end
  2521. end
  2522. function EJSuggestFrame_OpenFrame()
  2523. EJ_ContentTab_Select(EncounterJournal.instanceSelect.suggestTab.id);
  2524. NavBar_Reset(EncounterJournal.navBar);
  2525. end
  2526. function EJSuggestFrame_UpdateRewards(suggestion)
  2527. local rewardData = C_AdventureJournal.GetReward( suggestion.index );
  2528. suggestion.reward.data = rewardData;
  2529. if ( rewardData ) then
  2530. local texture = rewardData.itemIcon or rewardData.currencyIcon or
  2531. "Interface\\Icons\\achievement_guildperk_mobilebanking";
  2532. if ( rewardData.isRewardTable ) then
  2533. texture = "Interface\\Icons\\achievement_guildperk_mobilebanking";
  2534. end
  2535. suggestion.reward.icon:SetMask("Interface\\CharacterFrame\\TempPortraitAlphaMask");
  2536. suggestion.reward.icon:SetTexture(texture);
  2537. suggestion.reward:Show();
  2538. end
  2539. end
  2540. AdventureJournal_LeftTitleFonts = {
  2541. "DestinyFontHuge", -- 32pt font
  2542. "QuestFont_Enormous", -- 30pt font
  2543. "QuestFont_Super_Huge", -- 24pt font
  2544. };
  2545. local AdventureJournal_RightTitleFonts = {
  2546. "QuestFont_Huge", -- 18pt font
  2547. "Fancy16Font", -- 16pt font
  2548. };
  2549. local AdventureJournal_RightDescriptionFonts = {
  2550. "SystemFont_Med1", -- 12pt font
  2551. -- "SystemFont_Small", -- 10pt font
  2552. };
  2553. function EJSuggestFrame_RefreshDisplay()
  2554. local instanceSelect = EncounterJournal.instanceSelect;
  2555. local tab = EncounterJournal.instanceSelect.suggestTab;
  2556. local tierData = GetEJTierData(EJSuggestTab_GetPlayerTierIndex());
  2557. tab.selectedGlow:SetVertexColor(tierData.r, tierData.g, tierData.b);
  2558. tab.selectedGlow:Show();
  2559. instanceSelect.bg:SetAtlas(tierData.backgroundAtlas, true);
  2560. local self = EncounterJournal.suggestFrame;
  2561. C_AdventureJournal.GetSuggestions(self.suggestions);
  2562. -- hide all the display info
  2563. for i = 1, AJ_MAX_NUM_SUGGESTIONS do
  2564. local suggestion = self["Suggestion"..i];
  2565. suggestion.centerDisplay:Hide();
  2566. if ( i == 1 ) then
  2567. -- the left suggestion's button isn't on the centerDisplay frame
  2568. suggestion.button:Hide();
  2569. else
  2570. suggestion.centerDisplay.button:Hide();
  2571. end
  2572. suggestion.reward:Hide();
  2573. suggestion.icon:Hide();
  2574. suggestion.iconRing:Hide();
  2575. end
  2576. -- setup the primary suggestion display
  2577. if ( #self.suggestions > 0 ) then
  2578. local suggestion = self.Suggestion1;
  2579. local data = self.suggestions[1];
  2580. local centerDisplay = suggestion.centerDisplay;
  2581. local titleText = centerDisplay.title.text;
  2582. local descText = centerDisplay.description.text;
  2583. centerDisplay:SetHeight(suggestion:GetHeight());
  2584. centerDisplay:Show();
  2585. centerDisplay.title:SetHeight(0);
  2586. centerDisplay.description:SetHeight(0);
  2587. titleText:SetText(data.title);
  2588. descText:SetText(data.description);
  2589. -- find largest font that will not go past 2 lines
  2590. for i = 1, #AdventureJournal_LeftTitleFonts do
  2591. titleText:SetFontObject(AdventureJournal_LeftTitleFonts[i]);
  2592. local numLines = titleText:GetNumLines();
  2593. if ( numLines <= 2 and not titleText:IsTruncated() ) then
  2594. break;
  2595. end
  2596. end
  2597. -- resize the title to be 2 lines at most
  2598. local numLines = min(2, titleText:GetNumLines());
  2599. local fontHeight = select(2, titleText:GetFont());
  2600. centerDisplay.title:SetHeight(numLines * fontHeight + 2);
  2601. centerDisplay.description:SetHeight(descText:GetStringHeight());
  2602. -- adjust the center display to keep the text centered
  2603. local top = centerDisplay.title:GetTop();
  2604. local bottom = centerDisplay.description:GetBottom();
  2605. centerDisplay:SetHeight(top - bottom);
  2606. if ( data.buttonText and #data.buttonText > 0 ) then
  2607. suggestion.button:SetText( data.buttonText );
  2608. local btnWidth = max( suggestion.button:GetTextWidth()+42, 150 );
  2609. btnWidth = min( btnWidth, centerDisplay:GetWidth() );
  2610. suggestion.button:SetWidth( btnWidth );
  2611. suggestion.button:Show();
  2612. end
  2613. suggestion.icon:Show();
  2614. suggestion.iconRing:Show();
  2615. if ( data.iconPath ) then
  2616. suggestion.icon:SetMask("Interface\\CharacterFrame\\TempPortraitAlphaMask");
  2617. suggestion.icon:SetTexture(data.iconPath);
  2618. else
  2619. suggestion.icon:SetMask("Interface\\CharacterFrame\\TempPortraitAlphaMask");
  2620. suggestion.icon:SetTexture(QUESTION_MARK_ICON);
  2621. end
  2622. suggestion.prevButton:SetEnabled(C_AdventureJournal.GetPrimaryOffset() > 0);
  2623. suggestion.nextButton:SetEnabled(C_AdventureJournal.GetPrimaryOffset() < C_AdventureJournal.GetNumAvailableSuggestions()-1);
  2624. if ( titleText:IsTruncated() ) then
  2625. centerDisplay.title:SetScript("OnEnter", EJSuggestFrame_SuggestionTextOnEnter);
  2626. centerDisplay.title:SetScript("OnLeave", GameTooltip_Hide);
  2627. else
  2628. centerDisplay.title:SetScript("OnEnter", nil);
  2629. centerDisplay.title:SetScript("OnLeave", nil);
  2630. end
  2631. EJSuggestFrame_UpdateRewards(suggestion);
  2632. else
  2633. local suggestion = self.Suggestion1;
  2634. suggestion.prevButton:SetEnabled(false);
  2635. suggestion.nextButton:SetEnabled(false);
  2636. end
  2637. -- setup secondary suggestions display
  2638. if ( #self.suggestions > 1 ) then
  2639. local minTitleIndex = 1;
  2640. local minDescIndex = 1;
  2641. for i = 2, #self.suggestions do
  2642. local suggestion = self["Suggestion"..i];
  2643. if ( not suggestion ) then
  2644. break;
  2645. end
  2646. suggestion.centerDisplay:Show();
  2647. local data = self.suggestions[i];
  2648. suggestion.centerDisplay.title.text:SetText(data.title);
  2649. suggestion.centerDisplay.description.text:SetText(data.description ~= "" and data.description or " ");
  2650. -- find largest font that will not truncate the title
  2651. for fontIndex = minTitleIndex, #AdventureJournal_RightTitleFonts do
  2652. suggestion.centerDisplay.title.text:SetFontObject(AdventureJournal_RightTitleFonts[fontIndex]);
  2653. minTitleIndex = fontIndex
  2654. if (not suggestion.centerDisplay.title.text:IsTruncated()) then
  2655. break;
  2656. end
  2657. end
  2658. -- find largest font that will not go past 4 lines
  2659. for fontIndex = minDescIndex, #AdventureJournal_RightDescriptionFonts do
  2660. suggestion.centerDisplay.description.text:SetFontObject(AdventureJournal_RightDescriptionFonts[fontIndex]);
  2661. minDescIndex = fontIndex;
  2662. if ( suggestion.centerDisplay.description.text:GetNumLines() <= 4 and
  2663. not suggestion.centerDisplay.description.text:IsTruncated() ) then
  2664. break;
  2665. end
  2666. end
  2667. if ( data.buttonText and #data.buttonText > 0 ) then
  2668. suggestion.centerDisplay.button:SetText( data.buttonText );
  2669. local btnWidth = max(suggestion.centerDisplay.button:GetTextWidth()+42, 116);
  2670. btnWidth = min( btnWidth, suggestion.centerDisplay:GetWidth() );
  2671. suggestion.centerDisplay.button:SetWidth( btnWidth );
  2672. suggestion.centerDisplay.button:Show();
  2673. end
  2674. suggestion.icon:Show();
  2675. suggestion.iconRing:Show();
  2676. if ( data.iconPath ) then
  2677. suggestion.icon:SetMask("Interface\\CharacterFrame\\TempPortraitAlphaMask");
  2678. suggestion.icon:SetTexture(data.iconPath);
  2679. else
  2680. suggestion.icon:SetMask("Interface\\CharacterFrame\\TempPortraitAlphaMask");
  2681. suggestion.icon:SetTexture(QUESTION_MARK_ICON);
  2682. end
  2683. EJSuggestFrame_UpdateRewards(suggestion);
  2684. end
  2685. -- set the fonts to be the same for both right side sections
  2686. -- adjust the center display to keep the text centered
  2687. for i = 2, #self.suggestions do
  2688. local suggestion = self["Suggestion"..i];
  2689. suggestion.centerDisplay:SetHeight(suggestion:GetHeight());
  2690. local title = suggestion.centerDisplay.title;
  2691. local description = suggestion.centerDisplay.description;
  2692. title.text:SetFontObject(AdventureJournal_RightTitleFonts[minTitleIndex]);
  2693. description.text:SetFontObject(AdventureJournal_RightDescriptionFonts[minDescIndex]);
  2694. local fontHeight = select(2, title.text:GetFont());
  2695. title:SetHeight(fontHeight);
  2696. local numLines = min(4, description.text:GetNumLines());
  2697. fontHeight = select(2, description.text:GetFont());
  2698. description:SetHeight(numLines * fontHeight);
  2699. -- adjust the center display to keep the text centered
  2700. local top = title:GetTop();
  2701. local bottom = description:GetBottom();
  2702. if ( suggestion.centerDisplay.button:IsShown() ) then
  2703. bottom = suggestion.centerDisplay.button:GetBottom();
  2704. end
  2705. if ( title.text:IsTruncated() ) then
  2706. title:SetScript("OnEnter", EJSuggestFrame_SuggestionTextOnEnter);
  2707. title:SetScript("OnLeave", GameTooltip_Hide);
  2708. else
  2709. title:SetScript("OnEnter", nil);
  2710. title:SetScript("OnLeave", nil);
  2711. end
  2712. if ( description.text:IsTruncated() ) then
  2713. description:SetScript("OnEnter", EJSuggestFrame_SuggestionTextOnEnter);
  2714. description:SetScript("OnLeave", GameTooltip_Hide);
  2715. else
  2716. description:SetScript("OnEnter", nil);
  2717. description:SetScript("OnLeave", nil);
  2718. end
  2719. suggestion.centerDisplay:SetHeight(top - bottom);
  2720. end
  2721. end
  2722. end
  2723. function EJSuggestFrame_SuggestionTextOnEnter(self)
  2724. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  2725. GameTooltip:SetText(self.text:GetText(), 1, 1, 1, 1, true);
  2726. GameTooltip:Show();
  2727. end
  2728. function EJSuggestFrame_RefreshRewards()
  2729. for i = 1, AJ_MAX_NUM_SUGGESTIONS do
  2730. local suggestion = EncounterJournal.suggestFrame["Suggestion"..i];
  2731. suggestion.reward:Hide();
  2732. EJSuggestFrame_UpdateRewards(suggestion);
  2733. end
  2734. end
  2735. function EJSuggestFrame_OnClick(self)
  2736. C_AdventureJournal.ActivateEntry(self.index);
  2737. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON);
  2738. end
  2739. function AdventureJournal_Reward_OnEnter(self)
  2740. local rewardData = self.data;
  2741. if ( rewardData ) then
  2742. local frame = EncounterJournalTooltip;
  2743. frame:SetPoint("BOTTOMLEFT", self, "TOPRIGHT", 0, 0);
  2744. frame.clickText:Hide();
  2745. local suggestion = EncounterJournal.suggestFrame.suggestions[self:GetParent().index];
  2746. local rewardHeaderText = "";
  2747. if ( rewardData.rewardDesc ) then
  2748. rewardHeaderText = rewardData.rewardDesc;
  2749. elseif ( rewardData.isRewardTable ) then
  2750. if ( not suggestion.hideDifficulty and suggestion.difficultyID and suggestion.difficultyID > 1 ) then
  2751. local difficultyStr = DifficultyUtil.GetDifficultyName(suggestion.difficultyID);
  2752. if( rewardData.itemLevel ) then
  2753. rewardHeaderText = format(AJ_LFG_REWARD_DIFFICULTY_TEXT, suggestion.title, difficultyStr, rewardData.itemLevel);
  2754. elseif ( rewardData.minItemLevel ) then
  2755. rewardHeaderText = format(AJ_LFG_REWARD_DIFFICULTY_IRANGE_TEXT, suggestion.title, difficultyStr, rewardData.minItemLevel, rewardData.maxItemLevel);
  2756. end
  2757. else
  2758. if( rewardData.itemLevel ) then
  2759. rewardHeaderText = format(AJ_LFG_REWARD_DEFAULT_TEXT, suggestion.title, rewardData.itemLevel);
  2760. elseif ( rewardData.minItemLevel ) then
  2761. rewardHeaderText = format(AJ_LFG_REWARD_DEFAULT_IRANGE_TEXT, suggestion.title, rewardData.minItemLevel, rewardData.maxItemLevel);
  2762. end
  2763. end
  2764. if( rewardData.itemLink ) then
  2765. rewardHeaderText = rewardHeaderText..AJ_SAMPLE_REWARD_TEXT;
  2766. end
  2767. end
  2768. if ( rewardData.itemLink and rewardData.currencyType ) then
  2769. local itemName, _, quality = GetItemInfo(rewardData.itemLink);
  2770. frame.Item1.text:SetText(itemName);
  2771. frame.Item1.text:Show();
  2772. frame.Item1.icon:SetTexture(rewardData.itemIcon);
  2773. frame.Item1.tooltip:Hide();
  2774. frame.Item1:SetSize(256, 28);
  2775. frame.Item1:Show();
  2776. if ( rewardData.itemQuantity and rewardData.itemQuantity > 1 ) then
  2777. frame.Item1.Count:SetText(rewardData.itemQuantity);
  2778. frame.Item1.Count:Show();
  2779. else
  2780. frame.Item1.Count:Hide();
  2781. end
  2782. SetItemButtonQuality(frame.Item1, quality, rewardData.itemLink);
  2783. if (quality > Enum.ItemQuality.Common and BAG_ITEM_QUALITY_COLORS[quality]) then
  2784. frame.Item1.text:SetTextColor(BAG_ITEM_QUALITY_COLORS[quality].r, BAG_ITEM_QUALITY_COLORS[quality].g, BAG_ITEM_QUALITY_COLORS[quality].b);
  2785. end
  2786. local currencyInfo = C_CurrencyInfo.GetCurrencyInfo(rewardData.currencyType);
  2787. local quality = currencyInfo.quality;
  2788. frame.Item2.icon:SetTexture(currencyInfo.iconFileID);
  2789. frame.Item2.text:SetText(currencyInfo.name);
  2790. frame.Item2:Show();
  2791. SetItemButtonQuality(frame.Item2, quality);
  2792. if (quality > Enum.ItemQuality.Common and BAG_ITEM_QUALITY_COLORS[quality]) then
  2793. frame.Item2.text:SetTextColor(BAG_ITEM_QUALITY_COLORS[quality].r, BAG_ITEM_QUALITY_COLORS[quality].g, BAG_ITEM_QUALITY_COLORS[quality].b);
  2794. end
  2795. if ( rewardData.currencyQuantity and rewardData.currencyQuantity > 1 ) then
  2796. frame.Item2.Count:SetText(rewardData.currencyQuantity);
  2797. frame.Item2.Count:Show();
  2798. else
  2799. frame.Item2.Count:Hide();
  2800. end
  2801. local height = 100;
  2802. frame:SetWidth(256);
  2803. if ( rewardHeaderText and rewardHeaderText ~= "" ) then
  2804. frame.headerText:SetText(rewardHeaderText);
  2805. frame.Item1:SetPoint("TOPLEFT", frame.headerText, "BOTTOMLEFT", 0, -16);
  2806. height = height + frame.headerText:GetHeight();
  2807. frame.headerText:Show();
  2808. else
  2809. frame.headerText:Hide();
  2810. frame.Item1:SetPoint("TOPLEFT", 11, -10);
  2811. end
  2812. frame:SetHeight(height);
  2813. elseif ( rewardData.itemLink or rewardData.currencyType ) then
  2814. frame.Item2:Hide();
  2815. frame.Item1:Show();
  2816. frame.Item1.text:Hide();
  2817. local tooltip = frame.Item1.tooltip;
  2818. tooltip:SetOwner(frame.Item1, "ANCHOR_NONE");
  2819. frame.Item1.UpdateTooltip = function() AdventureJournal_Reward_OnEnter(self) end;
  2820. if ( rewardData.itemLink ) then
  2821. tooltip:SetHyperlink(rewardData.itemLink);
  2822. GameTooltip_ShowCompareItem(tooltip, frame.Item1.tooltip);
  2823. local quality = select(3, GetItemInfo(rewardData.itemLink));
  2824. SetItemButtonQuality(frame.Item1, quality, rewardData.itemLink);
  2825. if ( rewardData.itemQuantity and rewardData.itemQuantity > 1 ) then
  2826. frame.Item1.Count:SetText(rewardData.itemQuantity);
  2827. frame.Item1.Count:Show();
  2828. else
  2829. frame.Item1.Count:Hide();
  2830. end
  2831. self:SetScript("OnUpdate", EncounterJournal_AJ_OnUpdate);
  2832. frame.Item1.icon:SetTexture(rewardData.itemIcon);
  2833. elseif ( rewardData.currencyType ) then
  2834. tooltip:SetCurrencyByID(rewardData.currencyType);
  2835. local quality = C_CurrencyInfo.GetCurrencyInfo(rewardData.currencyType).quality;
  2836. SetItemButtonQuality(frame.Item1, quality);
  2837. if ( rewardData.currencyQuantity and rewardData.currencyQuantity > 1 ) then
  2838. frame.Item1.Count:SetText(rewardData.currencyQuantity);
  2839. frame.Item1.Count:Show();
  2840. else
  2841. frame.Item1.Count:Hide();
  2842. end
  2843. frame.Item1.icon:SetTexture(rewardData.currencyIcon);
  2844. end
  2845. frame:SetWidth(tooltip:GetWidth()+54);
  2846. if ( rewardHeaderText and rewardHeaderText ~= "" ) then
  2847. frame.headerText:SetText(rewardHeaderText);
  2848. frame.headerText:Show();
  2849. frame.Item1:SetPoint("TOPLEFT", frame.headerText, "BOTTOMLEFT", 0, -16);
  2850. else
  2851. frame.headerText:Hide();
  2852. frame.Item1:SetPoint("TOPLEFT", 11, -10);
  2853. end
  2854. tooltip:SetPoint("TOPLEFT", frame.Item1.icon, "TOPRIGHT", 0, 10);
  2855. tooltip:Show();
  2856. frame.Item1:SetSize(tooltip:GetWidth()+44, tooltip:GetHeight());
  2857. local height = tooltip:GetHeight() + 6;
  2858. if ( frame.headerText:IsShown() ) then
  2859. height = height + frame.headerText:GetHeight() + 14;
  2860. end
  2861. if (rewardData.isRewardTable) then
  2862. frame.clickText:Show();
  2863. self.iconRingHighlight:Show();
  2864. height = height + 24;
  2865. end
  2866. frame:SetHeight(height);
  2867. elseif ( rewardHeaderText and rewardHeaderText ~= "" ) then
  2868. frame:SetWidth(256);
  2869. frame.Item1:Hide();
  2870. frame.Item2:Hide();
  2871. frame.headerText:SetText(rewardHeaderText);
  2872. frame:SetHeight(frame.headerText:GetStringHeight()+20); -- add padding for tooltip border
  2873. frame.headerText:Show();
  2874. else
  2875. return;
  2876. end
  2877. frame:Show();
  2878. end
  2879. end
  2880. function EncounterJournal_AJ_OnUpdate(self)
  2881. local frame = EncounterJournalTooltip;
  2882. local tooltip = frame.Item1.tooltip;
  2883. end
  2884. function AdventureJournal_Reward_OnLeave(self)
  2885. EncounterJournalTooltip:Hide();
  2886. self:SetScript("OnUpdate", nil);
  2887. ResetCursor();
  2888. self.iconRingHighlight:Hide();
  2889. end
  2890. function AdventureJournal_Reward_OnMouseDown(self)
  2891. local index = self:GetParent().index;
  2892. local data = EncounterJournal.suggestFrame.suggestions[index];
  2893. if ( data.ej_instanceID ) then
  2894. EncounterJournal_DisplayInstance(data.ej_instanceID);
  2895. -- try to set difficulty to current instance difficulty
  2896. if ( EJ_IsValidInstanceDifficulty(data.difficultyID) ) then
  2897. EJ_SetDifficulty(data.difficultyID);
  2898. end
  2899. -- select the loot tab
  2900. EncounterJournal.encounter.info[EJ_Tabs[2].button]:Click();
  2901. elseif ( data.isRandomDungeon ) then
  2902. EJ_ContentTab_Select(EncounterJournal.instanceSelect.dungeonsTab.id);
  2903. EncounterJournal_TierDropDown_Select(nil, data.expansionLevel);
  2904. end
  2905. end
  2906. function EncounterJournalBossButton_UpdateDifficultyOverlay(self)
  2907. if self.encounterID then
  2908. local name, description, bossID, rootSectionID, link, journalInstanceID, dungeonEncounterID, mapID = EJ_GetEncounterInfo(self.encounterID);
  2909. local difficultyID = EJ_GetDifficulty();
  2910. local defeatedOnCurrentDifficulty = mapID and dungeonEncounterID and C_RaidLocks.IsEncounterComplete(mapID, dungeonEncounterID, difficultyID);
  2911. local hasDefeatedBoss = defeatedOnCurrentDifficulty and IsEJDifficulty(difficultyID);
  2912. self.DefeatedOverlay:SetShown(hasDefeatedBoss);
  2913. if hasDefeatedBoss then
  2914. local name = DifficultyUtil.GetDifficultyName(difficultyID);
  2915. self.DefeatedOverlay.tooltipText = ENCOUNTER_JOURNAL_ENCOUNTER_STATUS_DEFEATED_TOOLTIP:format(name);
  2916. end
  2917. end
  2918. end
  2919. function EncounterJournalBossButton_OnShow(self)
  2920. self:RegisterEvent("UPDATE_INSTANCE_INFO");
  2921. end
  2922. function EncounterJournalBossButton_OnHide(self)
  2923. self:UnregisterEvent("UPDATE_INSTANCE_INFO");
  2924. end
  2925. function EncounterJournalBossButton_OnEvent(self, event)
  2926. if event == "UPDATE_INSTANCE_INFO" then
  2927. EncounterJournalBossButton_UpdateDifficultyOverlay(self)
  2928. end
  2929. end
  2930. function EncounterJournalBossButton_OnClick(self)
  2931. if IsModifiedClick("CHATLINK") and ChatEdit_GetActiveWindow() then
  2932. if self.link then
  2933. ChatEdit_InsertLink(self.link);
  2934. end
  2935. return;
  2936. end
  2937. local _, _, _, rootSectionID = EJ_GetEncounterInfo(self.encounterID);
  2938. if ( rootSectionID == 0 ) then
  2939. EncounterJournal_SetTab(EncounterJournal.encounter.info.lootTab:GetID());
  2940. end
  2941. EncounterJournal_DisplayEncounter(self.encounterID);
  2942. PlaySound(SOUNDKIT.IG_ABILITY_PAGE_TURN);
  2943. end
  2944. function EncounterJournalBossButtonDefeatedOverlay_OnEnter(self)
  2945. if self.tooltipText then
  2946. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  2947. local wrap = true;
  2948. GameTooltip_AddNormalLine(GameTooltip, self.tooltipText, wrap);
  2949. GameTooltip:Show();
  2950. end
  2951. end
  2952. EncounterJournalScrollBarMixin = {};
  2953. function EncounterJournalScrollBarMixin:OnLoad()
  2954. self.trackBG:SetVertexColor(ENCOUNTER_JOURNAL_SCROLL_BAR_BACKGROUND_COLOR:GetRGBA());
  2955. end
  2956. function EncounterInstanceButtonTemplate_OnClick(self)
  2957. if not ChatEdit_TryInsertChatLink(self.link) then
  2958. EncounterJournal_DisplayInstance(self.instanceID);
  2959. PlaySound(SOUNDKIT.IG_SPELLBOOK_OPEN);
  2960. end
  2961. end
  2962. function EncounterTabTemplate_OnClick(self)
  2963. EncounterJournal_TabClicked(self, button);
  2964. if (not EncounterJournal.encounterID and EncounterJournal.instanceID) then
  2965. EncounterJournal_DisplayInstance(EncounterJournal.instanceID, true);
  2966. end
  2967. end
  2968. function EncounterItemTemplate_OnClick(self)
  2969. if (not HandleModifiedItemClick(self.link)) then
  2970. EncounterJournal_Loot_OnClick(self);
  2971. else
  2972. PlaySound(SOUNDKIT.IG_MAINMENU_OPTION);
  2973. end
  2974. end
  2975. function EncounterItemTemplate_OnEnter(self)
  2976. GameTooltip:SetOwner(self, "ANCHOR_LEFT");
  2977. EncounterJournal_SetTooltip(self.link);
  2978. self.showingTooltip = true;
  2979. self:SetScript("OnUpdate", EncounterJournal_Loot_OnUpdate);
  2980. end
  2981. function EncounterItemTemplate_OnLeave(self)
  2982. GameTooltip:Hide();
  2983. self.showingTooltip = false;
  2984. self:SetScript("OnUpdate", nil);
  2985. ResetCursor();
  2986. end
  2987. function EncounterItemTemplate_DividerFrameTipOnEnter(self)
  2988. GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  2989. GameTooltip:SetText(BONUS_LOOT_TOOLTIP_TITLE, 1, 1, 1);
  2990. GameTooltip:AddLine(BONUS_LOOT_TOOLTIP_BODY, nil, nil, nil, true);
  2991. GameTooltip:Show();
  2992. end