addon/Addon/Code/Tactic.lua

217 lines
6.1 KiB
Lua
Raw Normal View History

2025-03-29 07:44:17 +01:00
local _, addon = ...
local TACTIC_TAB_ID = 9
local CURRENT_TAB_ID = 0
local PREVIOUS_TAB_ID = 0
local ENCOUNTER_ID = 0
local DIFFICULTY = 0
local function HideOtherContent()
local frames = { "overviewScroll", "LootContainer", 'detailsScroll', 'model', 'encounterTitle' }
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.TacticFrame:ClearHeaders()
end
local function RenderBossTactics(frame, bossName)
HideOtherContent()
local difficulty = 'lfg_raid' -- 17
2025-03-29 07:44:17 +01:00
if DIFFICULTY == 14 then
difficulty = 'normal_raid'
2025-03-29 07:44:17 +01:00
elseif DIFFICULTY == 15 then
difficulty = 'heroic_raid'
2025-03-29 07:44:17 +01:00
elseif DIFFICULTY == 16 then
difficulty = 'mythic_raid'
2025-03-29 07:44:17 +01:00
elseif DIFFICULTY == 1 then
difficulty = 'normal_dungeon'
2025-03-29 07:44:17 +01:00
elseif DIFFICULTY == 2 then
difficulty = 'heroic_dungeon'
2025-03-29 07:44:17 +01:00
elseif DIFFICULTY == 23 then
difficulty = 'mythic_dungeon'
elseif DIFFICULTY == 8 then
difficulty = 'mythicplus_dungeon'
2025-03-29 07:44:17 +01:00
end
local bossData = CzechQuestsAddon:GetData('tactic', bossName)
local tactic = bossData and bossData[difficulty] or nil
2025-03-29 07:44:17 +01:00
if not tactic then
frame.summary:SetText("Boss " .. bossName .. " nemá pro tuto obtížnost přeloženou taktiku.")
frame:GetParent():Show()
return
end
local function CreateHeaderDescription(data)
local description = ""
for _, item in ipairs(data) do
description = description
.. item.name .. "\n"
.. "|cff003366" .. item.description .. "|r "
.. "|cff004400" .. item.howTo .. "|r "
.. "|cff8b0000" .. item.dangerous .. "|r"
.. "\n\n"
end
return description
end
frame.summary:SetText(tactic.summary)
frame.inform:SetText("|cffffffffVždy dodržuj pokyny raid leadera.|r")
2025-03-29 07:44:17 +01:00
local tankHeader = frame:CreateHeader()
tankHeader.button.title:SetText("Tank")
tankHeader.description:SetText(CreateHeaderDescription(tactic.tank))
local healHeader = frame:CreateHeader()
healHeader.button.title:SetText("Healer")
healHeader.description:SetText(CreateHeaderDescription(tactic.heal))
local dpsHeader = frame:CreateHeader()
dpsHeader.button.title:SetText("DPS")
dpsHeader.description:SetText(CreateHeaderDescription(tactic.dps))
frame:GetParent():Show()
frame:UpdateHeaderPositions()
end
local function CreateCreaturesDropdown()
local frame = addon.TacticFrame
local encounterName = EJ_GetEncounterInfo(ENCOUNTER_ID)
local options = {}
local selectedValue = nil
for i = 1, 10 do
local id, name = EJ_GetCreatureInfo(i);
if id then
if addon.data.tactic[name] then
table.insert(options, { name, name })
end
end
end
if #options > 0 then
selectedValue = options[1][2]
end
local function IsSelected(value)
return value == selectedValue
end
local function SetSelected(value)
if value then
RenderBossTactics(addon.TacticFrame, value)
end
selectedValue = value
end
MenuUtil.CreateRadioMenu(frame.dropdown, IsSelected, SetSelected, unpack(options))
if #options > 0 then
SetSelected(selectedValue)
end
if #options == 0 then
frame.summary:SetText("V souboji " .. encounterName .. " není boss, který má přeloženou taktikou.")
frame:GetParent():Show()
frame.dropdown:Hide()
end
end
local function HideTacticNpcs()
addon.TacticFrame:GetParent():Hide()
addon.TacticFrame.dropdown:Hide()
end
local function ShowTacticNpcs()
CURRENT_TAB_ID = TACTIC_TAB_ID
HideOtherContent()
local frame = addon.TacticFrame
frame.tab:SetHighlight(true);
frame.dropdown:Show()
EncounterJournal.encounter.info.rightShadow:Show()
EncounterJournal.encounter.info.difficulty:Show()
CreateCreaturesDropdown()
end
local function SetupCustomTab()
addon.TacticFrame.tab:SetScript("OnClick", function()
ShowTacticNpcs()
end)
hooksecurefunc("EncounterJournal_DisplayEncounter", function(encounterID)
ENCOUNTER_ID = encounterID
addon.TacticFrame.tab:SetActive(true);
if CURRENT_TAB_ID == TACTIC_TAB_ID then
ShowTacticNpcs()
end
end)
hooksecurefunc("EncounterJournal_DisplayInstance", function()
addon.TacticFrame.tab:SetActive(false);
end)
hooksecurefunc("EncounterJournal_SetTab", function(tabId)
if CURRENT_TAB_ID ~= tabId then
addon.TacticFrame.tab:SetHighlight(false);
end
PREVIOUS_TAB_ID = CURRENT_TAB_ID
CURRENT_TAB_ID = tabId
HideTacticNpcs()
end)
hooksecurefunc("EncounterJournalBossButton_OnClick", function(encounterID)
if PREVIOUS_TAB_ID == TACTIC_TAB_ID then
ShowTacticNpcs()
end
end)
hooksecurefunc("EncounterJournal_UpdateDifficulty", function(difficulty)
DIFFICULTY = difficulty
if PREVIOUS_TAB_ID == TACTIC_TAB_ID and ENCOUNTER_ID then
ShowTacticNpcs()
end
end)
end
local function InitTactics()
local frame = addon.TacticFrame
-- Register EncounterJournal events
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, addonName)
if not CzechQuestsAddon_Store.config.TACTIC_ENABLED then
return
end
if addonName == 'Blizzard_EncounterJournal' then
addon.TacticFrame:Init()
SetupCustomTab()
end
end)
end
addon.API.InitTactics = InitTactics