local _, addon = ... local ENCOUNTER_TAB_ID = 9 local CURRENT_TAB_ID = 0 local PREVIOUS_TAB_ID = 0 local ENCOUNTER_ID = 0 local DIFFICULTY = 0 local TAG_TO_ICON = { tank = 0, dps = 1, healer = 2, important = 5, mythic = 12, interruptible = 6, magic = 7, curse = 8, poison = 9, heroic = 3, disease = 10, deadly = 4, enrage = 11 } local ORIGINALS = {} local function HideOtherContent() local frames = { "overviewScroll", "LootContainer", 'detailsScroll', 'model' } for _, frame in ipairs(frames) do EncounterJournal.encounter.info[frame]:Hide(); end local tabs = { "overviewTab", "lootTab", "bossTab", "modelTab" } for _, tab in ipairs(tabs) do EncounterJournal.encounter.info[tab].selected:Hide(); EncounterJournal.encounter.info[tab].unselected:Show(); EncounterJournal.encounter.info[tab]:UnlockHighlight(); end if EncounterJournal.encounter.info.creatureButtons then for _, button in pairs(EncounterJournal.encounter.info.creatureButtons) do button:Hide() end end addon.EncounterFrame:ClearHeaders() end local function SetAbilityIcon(header, tags) local result = {} for part in string.gmatch(tags, "([^,]+)") do table.insert(result, part) end for i, tag in pairs(result) do local tex = header.button:CreateTexture() if i == 1 then tex:SetAllPoints(header.button.icon1.icon) elseif i == 2 then tex:SetAllPoints(header.button.icon2.icon) elseif i == 3 then tex:SetAllPoints(header.button.icon3.icon) end tex:SetTexture("Interface/EncounterJournal/UI-EJ-Icons") local index = TAG_TO_ICON[string.lower(tag)] or nil if index ~= nil then EncounterJournal_SetFlagIcon(tex, index) end end end local function RenderBossAbilities(data, parent, layer) local frame = addon.EncounterFrame if not parent.children then parent.children = {} end for _, node in ipairs(data) do local abilityValue = addon.API.GetEncounterAbility(node.key) if abilityValue then local abilityParts = addon.API.ParseAbilities(abilityValue, "|") local name = abilityParts[1] local tag = abilityParts[3] local description = abilityParts[5] if name ~= "???" then local header = frame:CreateHeader() header:SetWidth(frame:GetWidth() - (layer * 20)) header.button.title:SetText(name) if tag and tag ~= '???' then SetAbilityIcon(header, tag) end header.description:SetWidth(header:GetWidth() - 20) header.description:SetText(addon.API.SetAbilityDescription(description, ORIGINALS[name])) if description == "" then header.empty = true end table.insert(parent.children, header) if node.children and #node.children > 0 then RenderBossAbilities(node.children, header, layer + 1) end else RenderBossAbilities(node.children, parent, layer) end end end end local function RenderBossEncounter(bossKey, bossName) local frame = addon.EncounterFrame HideOtherContent() local bossData = CzechQuestsAddon:GetData('encounter', bossKey) frame.summary:SetText( addon.API.SetAbilityDescription(bossData.overview, ORIGINALS['Overview']) ) local tankHeader = frame:CreateHeader() tankHeader.button.title:SetText("Tank") local tankDescription = addon.API.SetSummaryDescription(bossData.tank, ORIGINALS['Tanks']) tankHeader.description:SetText(tankDescription) table.insert(frame.headers, tankHeader) SetAbilityIcon(tankHeader, 'tank') local healHeader = frame:CreateHeader() healHeader.button.title:SetText("Healer") local healerDescription = addon.API.SetSummaryDescription(bossData.healer, ORIGINALS['Healers']) healHeader.description:SetText(healerDescription) table.insert(frame.headers, healHeader) SetAbilityIcon(healHeader, 'healer') local dpsHeader = frame:CreateHeader() dpsHeader.button.title:SetText("Damage Dealer") local dpsDescription = addon.API.SetSummaryDescription(bossData.dps, ORIGINALS['Damage Dealers']) dpsHeader.description:SetText(dpsDescription) table.insert(frame.headers, dpsHeader) SetAbilityIcon(dpsHeader, 'dps') local bossHeader = frame:CreateHeader() bossHeader.button.title:SetText(bossName) bossHeader.empty = true table.insert(frame.headers, bossHeader) RenderBossAbilities(bossData.abilities, bossHeader, 1) frame:GetParent():Show() frame:UpdateHeaderPositions() end local function StoreBossAbilities() ORIGINALS = {} local stack, _, _, _, curSectionID = {}, EJ_GetEncounterInfo(ENCOUNTER_ID) repeat local info = C_EncounterJournal.GetSectionInfo(curSectionID) if not info.filteredByDifficulty then ORIGINALS[info.title] = info.description end table.insert(stack, info.siblingSectionID) if not info.filteredByDifficulty then table.insert(stack, info.firstChildSectionID) end curSectionID = table.remove(stack) until not curSectionID end local function DetectBossToRender() local frame = addon.EncounterFrame local encounterName = EJ_GetEncounterInfo(ENCOUNTER_ID) local difficulty = 'lfg_raid' -- 17 if DIFFICULTY == 14 then difficulty = 'normal_raid' elseif DIFFICULTY == 15 then difficulty = 'heroic_raid' elseif DIFFICULTY == 16 then difficulty = 'mythic_raid' elseif DIFFICULTY == 1 then difficulty = 'normal_dungeon' elseif DIFFICULTY == 2 then difficulty = 'heroic_dungeon' elseif DIFFICULTY == 23 then difficulty = 'mythic_dungeon' end local bossKey = nil for i = 1, 10 do local id, name = EJ_GetCreatureInfo(i); if id then local key = name .. "_" .. difficulty if addon.data.encounter[key] then bossKey = key break end end end if bossKey then StoreBossAbilities() RenderBossEncounter(bossKey, encounterName) end if bossKey == nil then frame.summary:SetText("V souboji " .. encounterName .. " není tato obtížnost přeložena.") frame:GetParent():Show() end end local function HideEncounterContent() addon.EncounterFrame:GetParent():Hide() end local function ShowEncounterContent() CURRENT_TAB_ID = ENCOUNTER_TAB_ID HideOtherContent() local frame = addon.EncounterFrame frame.tab:SetHighlight(true); EncounterJournal.encounter.info.rightShadow:Show() EncounterJournal.encounter.info.difficulty:Show() DetectBossToRender() end local function SetupCustomTab() addon.EncounterFrame.tab:SetScript("OnClick", function() ShowEncounterContent() end) hooksecurefunc("EncounterJournal_DisplayEncounter", function(encounterID) ENCOUNTER_ID = encounterID addon.EncounterFrame.tab:SetActive(true); if CURRENT_TAB_ID == ENCOUNTER_TAB_ID then ShowEncounterContent() end end) hooksecurefunc("EncounterJournal_DisplayInstance", function() addon.EncounterFrame.tab:SetActive(false); end) hooksecurefunc("EncounterJournal_SetTab", function(tabId) if CURRENT_TAB_ID ~= tabId then addon.EncounterFrame.tab:SetHighlight(false); end PREVIOUS_TAB_ID = CURRENT_TAB_ID CURRENT_TAB_ID = tabId HideEncounterContent() end) hooksecurefunc("EncounterJournalBossButton_OnClick", function(encounterID) if PREVIOUS_TAB_ID == ENCOUNTER_TAB_ID then ShowEncounterContent() end end) hooksecurefunc("EncounterJournal_UpdateDifficulty", function(difficulty) DIFFICULTY = difficulty if PREVIOUS_TAB_ID == ENCOUNTER_TAB_ID and ENCOUNTER_ID then ShowEncounterContent() end end) end local function InitEncounters() local frame = addon.EncounterFrame frame:RegisterEvent("ADDON_LOADED") frame:SetScript("OnEvent", function(self, event, addonName) if not CzechQuestsAddon_Store.config.ENCOUNTER_ENABLED then return end if addonName == 'Blizzard_EncounterJournal' then addon.EncounterFrame:Init() SetupCustomTab() end end) end addon.API.InitEncounters = InitEncounters