Refactor Encounters, use new translations format for save space

This commit is contained in:
Roman Jaroš 2025-04-17 19:04:49 +02:00
parent 7d9f58650a
commit 908f45eb9b
59 changed files with 103852 additions and 58396 deletions

View file

@ -1,11 +1,11 @@
local _, addon = ...
local function ResolveGender(maleVersion, femaleVersion)
local function ResolveGender(obj)
local gender = UnitSex("player")
if gender == 2 then
return maleVersion
return obj.m
else
return femaleVersion == nil and maleVersion or femaleVersion
return obj.f == nil and obj.m or obj.f
end
end
addon.API.ResolveGender = ResolveGender
@ -16,6 +16,8 @@ function CzechQuestsAddon:GetData(key, id)
return addon.API.GetQuest(id)
elseif key == "speech" then
return addon.API.GetSpeech(id)
elseif key == "encounter" then
return addon.API.GetEncounter(id)
elseif addon.data[key][id] then
return addon.data[key][id]
end

300
Addon/Code/Encounter.lua Executable file
View file

@ -0,0 +1,300 @@
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 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 ColorSpellNames(text, color)
return text:gsub("%[(.-)%]", function(match)
return string.format("|c%s[%s]|r", color or "ffffffff", match)
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.ResolveGender(addon.API.GetEncounterAbility(node.key))
if abilityValue then
local abilityParts = addon.API.SplitAbilityParts(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(description)
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(bossName, bossKey)
local frame = addon.EncounterFrame
HideOtherContent()
local bossData = CzechQuestsAddon:GetData('encounter', bossKey)
local function CreateHeaderDescription(data)
local value = addon.API.ResolveGender(data)
local result = {}
for part in string.gmatch(value, "([^\n]+)") do
table.insert(result, part)
end
local description = ""
for i, part in pairs(result) do
description = description
.. "- "
.. ColorSpellNames(part)
.. (i == #result and "" or "\n\n")
end
return description
end
frame.summary:SetText(
ColorSpellNames(
addon.API.ResolveGender(bossData.overview)
)
)
local tankHeader = frame:CreateHeader()
tankHeader.button.title:SetText("Tank")
tankHeader.description:SetText(CreateHeaderDescription(bossData.tank))
table.insert(frame.headers, tankHeader)
SetAbilityIcon(tankHeader, 'tank')
local healHeader = frame:CreateHeader()
healHeader.button.title:SetText("Healer")
healHeader.description:SetText(CreateHeaderDescription(bossData.healer))
table.insert(frame.headers, healHeader)
SetAbilityIcon(healHeader, 'healer')
local dpsHeader = frame:CreateHeader()
dpsHeader.button.title:SetText("Damage Dealer")
dpsHeader.description:SetText(CreateHeaderDescription(bossData.dps))
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)
-- abilities
RenderBossAbilities(bossData.abilities, bossHeader, 1)
frame:GetParent():Show()
frame:UpdateHeaderPositions()
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 bossName = nil
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
bossName = name
bossKey = key
break
end
end
end
if bossKey then
RenderBossEncounter(bossName, bossKey)
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 HideEncounterFrame()
addon.EncounterFrame:GetParent():Hide()
end
local function ShowEncounterFrame()
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()
ShowEncounterFrame()
end)
hooksecurefunc("EncounterJournal_DisplayEncounter", function(encounterID)
ENCOUNTER_ID = encounterID
addon.EncounterFrame.tab:SetActive(true);
if CURRENT_TAB_ID == ENCOUNTER_TAB_ID then
ShowEncounterFrame()
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
HideEncounterFrame()
end)
hooksecurefunc("EncounterJournalBossButton_OnClick", function(encounterID)
if PREVIOUS_TAB_ID == ENCOUNTER_TAB_ID then
ShowEncounterFrame()
end
end)
hooksecurefunc("EncounterJournal_UpdateDifficulty", function(difficulty)
DIFFICULTY = difficulty
if PREVIOUS_TAB_ID == ENCOUNTER_TAB_ID and ENCOUNTER_ID then
ShowEncounterFrame()
end
end)
end
local function InitEncounters()
local frame = addon.EncounterFrame
-- Register EncounterJournal events
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

37
Addon/Code/EncounterDataApi.lua Executable file
View file

@ -0,0 +1,37 @@
local _, addon = ...
local function SplitAbilityParts(input, delimiter)
local result = {}
local pattern = "([^" .. delimiter .. "]*)"
local normalizedAbility = string.gsub(input, "||", "|???|")
local lastPos = 1
for part in string.gmatch(normalizedAbility, pattern) do
table.insert(result, part)
lastPos = lastPos + #part + 1
end
if input:sub(-1) == delimiter then
table.insert(result, "")
end
return result
end
addon.API.SplitAbilityParts = SplitAbilityParts
local function GetEncounterAbility(abilityKey)
return addon.data.encounter[abilityKey] or nil
end
addon.API.GetEncounterAbility = GetEncounterAbility
local function GetEncounter(bossKey)
return {
abilities = addon.data.encounter[bossKey] or nil,
overview = addon.data.encounter[bossKey .. "_summary_instance"] or nil,
tank = addon.data.encounter[bossKey .. "_summary_tank"] or nil,
healer = addon.data.encounter[bossKey .. "_summary_healer"] or nil,
dps = addon.data.encounter[bossKey .. "_summary_dps"] or nil,
}
end
addon.API.GetEncounter = GetEncounter

252
Addon/Code/EncounterFrame.lua Executable file
View file

@ -0,0 +1,252 @@
local _, addon = ...
local EncounterFrame = CreateFrame("Frame", nil)
EncounterFrame:Hide()
addon.EncounterFrame = EncounterFrame
EncounterFrame.headers = {}
local NEXT_HEADER_ID = 0
function EncounterFrame:Init()
local frame = self
if not EncounterJournal or not EncounterJournal.encounter or not EncounterJournal.encounter.info then
return
end
local scrollFrame = CreateFrame("ScrollFrame", "$parentOverviewScrollFrame", EncounterJournal.encounter.info, "ScrollFrameTemplate")
scrollFrame:SetSize(330, 370)
scrollFrame:SetPoint("TOPLEFT", EncounterJournal.encounter.info.overviewScroll, "TOPLEFT", 0, -7)
scrollFrame.scrollBarX = -25
scrollFrame.scrollBarTopY = -6
scrollFrame.scrollBarBottomY = 6
frame:SetParent(scrollFrame)
frame:SetSize(scrollFrame:GetWidth() - 10, 1)
frame:Show()
scrollFrame:SetScrollChild(frame)
frame.summary = addon.API.CreateCzechFont(
frame,
CzechQuestsAddon_Store.config.ENCOUNTER_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.ENCOUNTER_TEXT_FONT_SIZE
)
frame.summary:SetTextColor(0.251, 0.145, 0.012)
frame.summary:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, 0)
frame.summary:SetWidth(scrollFrame:GetWidth() - 10)
frame:UpdateSettings()
frame:InitTab()
end
function EncounterFrame:UpdateSettings()
local frame = self
addon.API.UpdateCzechFont(
frame.summary,
CzechQuestsAddon_Store.config.ENCOUNTER_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.ENCOUNTER_TEXT_FONT_SIZE
)
for _, header in ipairs(self.headers) do
addon.API.UpdateCzechFont(
header.description,
CzechQuestsAddon_Store.config.ENCOUNTER_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.ENCOUNTER_TEXT_FONT_SIZE
)
end
end
function EncounterFrame:InitTab()
local frame = self
local tab = CreateFrame("Button", "EncounterJournalCustomTab", EncounterJournal.encounter.info, "EncounterTabTemplate")
tab:SetPoint("TOP", EncounterJournal.encounter.info.modelTab, "BOTTOM", -3, -12)
tab:SetSize(50, 40)
tab.tooltip = "Taktika"
local selected = tab:CreateTexture(nil, "BACKGROUND")
selected:SetTexture("Interface\\EncounterJournal\\UI-EncounterJournalTextures")
selected:SetAllPoints(tab)
selected:SetBlendMode("ADD")
selected:SetDrawLayer("OVERLAY")
selected:SetTexCoord(0, 0.126953125, 0.90234375, 0.9599609375)
selected:Hide()
tab.selected = selected
function tab:SetActive(enable)
self:SetEnabled(enable);
self:GetDisabledTexture():SetDesaturated(not enable);
end
function tab:SetHighlight(enable)
if not enable then
self.selected:Hide();
else
self.selected:Show();
end
end
frame.tab = tab
end
function EncounterFrame:CreateHeader()
local frame = self
local id = NEXT_HEADER_ID + 1
NEXT_HEADER_ID = id
local HeaderFrame = CreateFrame("FRAME", "CzechQuestsEncounterHeader" .. id, frame, "EncounterInfoTemplate")
HeaderFrame:SetSize(self:GetParent():GetWidth() - 10, 30)
addon.API.UpdateCzechFont(
HeaderFrame.description,
CzechQuestsAddon_Store.config.ENCOUNTER_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.ENCOUNTER_TEXT_FONT_SIZE
)
HeaderFrame.button.abilityIcon:Hide()
HeaderFrame.button.portrait:Hide()
HeaderFrame.button.icon2:Hide()
HeaderFrame.button.icon3:Hide()
HeaderFrame.button.icon4:Hide()
HeaderFrame.button.expandedIcon:SetPoint("TOPLEFT", HeaderFrame.button, "TOPLEFT", 10, -6);
HeaderFrame.button.expandedIcon:SetText("+")
HeaderFrame.expanded = false
HeaderFrame.empty = false
HeaderFrame.button.title:SetPoint("TOPLEFT", HeaderFrame, "TOPLEFT", 40, -7);
HeaderFrame.button.title:SetWidth(self:GetParent():GetWidth() - 110)
for i = 1, #HeaderFrame.Bullets do
HeaderFrame.Bullets[i]:Hide()
end
wipe(HeaderFrame.Bullets)
for _, icon in ipairs(HeaderFrame.button.icons) do
icon:Hide()
end
HeaderFrame.description:SetWidth(HeaderFrame:GetWidth() - 20)
HeaderFrame.description:Hide()
HeaderFrame.overviewDescription:Hide()
HeaderFrame.descriptionBG:Hide()
HeaderFrame.descriptionBGBottom:Hide()
function HeaderFrame:Open()
local header = self
header.button.expandedIcon:SetText("-")
header.button.expandedIcon:SetPoint("TOPLEFT", HeaderFrame.button, "TOPLEFT", 10, -5);
if (header.empty == false) then
header.description:Show()
header.descriptionBG:Show()
header.descriptionBGBottom:Show()
end
end
function HeaderFrame:Close()
local header = self
header.button.expandedIcon:SetText("+")
header.button.expandedIcon:SetPoint("TOPLEFT", HeaderFrame.button, "TOPLEFT", 10, -6);
header.description:Hide()
header.descriptionBG:Hide()
header.descriptionBGBottom:Hide()
end
HeaderFrame.button:SetScript("OnClick", function(self)
local header = self:GetParent()
header.expanded = not header.expanded
EncounterJournal_UpdateButtonState(header.button)
if header.expanded then
header:Open()
else
header:Close()
end
frame:ToggleHeader(header)
end)
return HeaderFrame
end
function EncounterFrame:UpdateHeaderPositions()
local yOffset = -40
local function updatePosition(headers)
for _, header in ipairs(headers) do
header:SetPoint("BOTTOMRIGHT", self.summary, "BOTTOMRIGHT", 0, yOffset)
if header.expanded then
yOffset = yOffset - header.description:GetHeight()
if header.empty == false then
yOffset = yOffset - 50
else
yOffset = yOffset - 30
end
if header.children and #header.children > 0 then
yOffset = updatePosition(header.children)
end
else
yOffset = yOffset - 30
end
end
return yOffset
end
updatePosition(self.headers)
end
function EncounterFrame:ToggleHeader(header)
if header.expanded and header.children then
for _, child in ipairs(header.children) do
child:Show()
end
end
if not header.expanded and header.children then
local function hideChildren(children)
for _, child in ipairs(children) do
child.expanded = false
child:Close()
child:Hide()
if child.children then
hideChildren(child.children)
end
end
end
hideChildren(header.children)
end
self:UpdateHeaderPositions()
end
function EncounterFrame:ClearHeaders()
local function clear(headers)
for _, header in ipairs(headers) do
-- Skrytí aktuálního záhlaví
header:Hide()
header:SetParent(nil)
-- Rekurzivně skrýváme podřízená záhlaví
if header.children and #header.children > 0 then
clear(header.children)
end
-- Vymazání záhlaví
header = nil
end
-- Vyprázdnění seznamu
wipe(headers)
end
-- Vymazání všech hlavních záhlaví
clear(self.headers)
end

View file

@ -5,8 +5,8 @@ local FontPath = "Interface\\AddOns\\CzechQuests\\Assets\\Fonts\\"
local TestFont = UIParent:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
TestFont:SetPoint("TOP", UIParent, "BOTTOM", 0, -64);
local function CreateCzechFont(frame, name, size, flags)
local font = frame:CreateFontString(nil, "OVERLAY")
local function CreateCzechFont(frame, name, size, flags, style)
local font = frame:CreateFontString(nil, "OVERLAY", style)
font:SetTextColor(0, 0, 0, 1)
font:SetJustifyH("LEFT")
font:SetWidth(frame:GetWidth())

View file

@ -116,20 +116,20 @@ local function InitSpeeches()
end
local function InitTactics()
local function InitEncounters()
local function Update(name, value)
CzechQuestsAddon_Store.config[name] = value
addon.TacticFrame:UpdateSettings()
addon.EncounterFrame:UpdateSettings()
end
local layout = Options.layout
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Taktiky"))
CreateCheckbox("TACTIC_ENABLED", "Zapnout *", Update)
CreateCheckbox("ENCOUNTER_ENABLED", "Zapnout *", Update)
CreateDropdown("TACTIC_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer, Update)
CreateDropdown("ENCOUNTER_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer, Update)
CreateSlider("TACTIC_TEXT_FONT_SIZE", "Velikost pisma *", 10, 30, 1, Update)
CreateSlider("ENCOUNTER_TEXT_FONT_SIZE", "Velikost pisma *", 10, 30, 1, Update)
end
local function InitOthers()
@ -148,7 +148,7 @@ local function InitOptions()
InitQuests()
InitSpeeches()
if (WOW_PROJECT_ID ~= WOW_PROJECT_CLASSIC) then
InitTactics()
InitEncounters()
end
InitOthers()

View file

@ -66,17 +66,17 @@ local function ShowQuestTranslation(event)
end
end
local function ShowQuestItemTranslation()
local function ShowBookTranslation()
local frame = addon.QuestFrame
frame:Hide()
-- classic and retail has same frame
if ItemTextFrame:IsVisible() then
local itemName = ItemTextGetItem();
local itemNameTranslation = CzechQuestsAddon:GetData("item", itemName)
local itemNameTranslation = CzechQuestsAddon:GetData("book", itemName .. "_name")
if itemNameTranslation then
local pageNum = ItemTextGetPage()
local itemPageContentTranslation = CzechQuestsAddon:GetData("item", itemName .. '__' .. pageNum)
local itemPageContentTranslation = CzechQuestsAddon:GetData("book", itemName .. '_page_' .. pageNum)
if itemPageContentTranslation then
frame:SetData(
itemNameTranslation.title,
@ -137,7 +137,7 @@ local function InitQuests()
end
if (event == "ITEM_TEXT_READY") then
ShowQuestItemTranslation()
ShowBookTranslation()
end
if CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING then

View file

@ -77,15 +77,20 @@ local function FillPlaceholders(text)
return formatted
end
local function GetQuestText(maleText, femaleText, original)
local translation = addon.API.ResolveGender(maleText, femaleText)
local function GetQuestText(questTranslation, original)
local translation = addon.API.ResolveGender(questTranslation)
local paragraphs = addon.API.ParseParagraphs(original, translation)
return FillPlaceholders(paragraphs)
end
local function GetQuest(id)
local quest = addon.data.quest[id];
if quest then
local questName = addon.data.quest[id .. '_name'];
local questObjective = addon.data.quest[id .. '_objective'];
local questDescription = addon.data.quest[id .. '_description'];
local questProgress = addon.data.quest[id .. '_progress'];
local questCompletion = addon.data.quest[id .. '_completion'];
if questName or questObjective or questDescription or questProgress or questCompletion then
local description = ""
local objective = ""
@ -98,11 +103,11 @@ local function GetQuest(id)
end
return {
title = GetQuestText(quest.titleMale, quest.titleFemale),
objective = GetQuestText(quest.objectiveMale, quest.objectiveFemale, objective),
description = GetQuestText(quest.descriptionMale, quest.descriptionFemale, description),
progress = GetQuestText(quest.progressMale, quest.progressFemale),
completion = GetQuestText(quest.completionMale, quest.completionFemale),
title = GetQuestText(questName),
objective = GetQuestText(questObjective, objective),
description = GetQuestText(questDescription, description),
progress = GetQuestText(questProgress),
completion = GetQuestText(questCompletion),
}
end
end

View file

@ -39,7 +39,7 @@ end
local function GetSpeech(message)
local index = BuildIndex(message)
local speech = addon.data.speech[index];
local text = speech and speech.text or nil
local text = speech and speech.m or nil
if text then
return FillPlaceholders(FillNumbers(text, message))
else

View file

@ -45,8 +45,7 @@ function SpeechFrame:CreateMessage()
MessageFrame.Message = addon.API.CreateCzechFont(
MessageFrame,
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE,
"THICK"
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE
)
MessageFrame.Message:SetTextColor(1, 1, 1)
MessageFrame.Message:SetPoint("TOPLEFT", MessageFrame, "TOPLEFT", 5, -5)

View file

@ -1,223 +0,0 @@
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 instanceType = 'raidu'
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'
instanceType = 'dungeonu'
elseif DIFFICULTY == 2 then
difficulty = 'heroic_dungeon'
instanceType = 'dungeonu'
elseif DIFFICULTY == 23 then
difficulty = 'mythic_dungeon'
instanceType = 'dungeonu'
elseif DIFFICULTY == 8 then
difficulty = 'mythicplus_dungeon'
instanceType = 'dungeonu'
end
local bossData = CzechQuestsAddon:GetData('tactic', bossName)
local tactic = bossData and bossData[difficulty] or nil
if not tactic then
frame.summary:SetText("Boss " .. bossName .. " nemá pro tuto obtížnost přeloženou taktiku.")
frame.inform:Hide()
frame:GetParent():Show()
return
end
local function CreateHeaderDescription(data)
local description = ""
for _, item in ipairs(data) do
description = description
.. "|cff003366" .. item[1] .. "|r\n"
.. "" .. item[3] .. " "
.. "|cff004400" .. item[4] .. "|r"
.. "\n\n"
end
return description
end
frame.summary:SetText(tactic.summary)
frame.inform:SetText("|cffffffffVždy dodržuj pokyny leadera " .. instanceType .. ".|r")
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()
frame.inform: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

View file

@ -1,216 +0,0 @@
local _, addon = ...
local TacticFrame = CreateFrame("Frame", nil)
TacticFrame:Hide()
addon.TacticFrame = TacticFrame
TacticFrame.headers = {}
local NEXT_HEADER_ID = 0
function TacticFrame:Init()
local frame = self
if not EncounterJournal or not EncounterJournal.encounter or not EncounterJournal.encounter.info then
return
end
local scrollFrame = CreateFrame("ScrollFrame", "$parentOverviewScrollFrame", EncounterJournal.encounter.info, "ScrollFrameTemplate")
scrollFrame:SetSize(330, 370)
scrollFrame:SetPoint("TOPLEFT", EncounterJournal.encounter.info.overviewScroll, "TOPLEFT", 0, -7)
scrollFrame.scrollBarX = -25
scrollFrame.scrollBarTopY = -6
scrollFrame.scrollBarBottomY = 6
frame:SetParent(scrollFrame)
frame:SetSize(scrollFrame:GetWidth() - 10, 1)
frame:Show()
scrollFrame:SetScrollChild(frame)
frame.summary = addon.API.CreateCzechFont(
frame,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE
)
frame.summary:SetTextColor(0.251, 0.145, 0.012)
frame.summary:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, 0)
frame.summary:SetWidth(scrollFrame:GetWidth() - 10)
frame.inform = addon.API.CreateCzechFont(
frame,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE
)
frame.inform:SetTextColor(0.251, 0.145, 0.012)
frame.inform:SetPoint("BOTTOMLEFT", frame.summary, "BOTTOMLEFT", 2, -20)
frame.inform:SetWidth(scrollFrame:GetWidth() - 10)
local dropdown = CreateFrame("DropdownButton", nil, EncounterJournal.encounter.info, "WowStyle1DropdownTemplate")
dropdown:SetPoint("BOTTOMRIGHT", EncounterJournal.encounter.info.encounterTitle, "BOTTOMRIGHT", 2, -2)
dropdown:SetWidth(200)
dropdown:Hide()
frame.dropdown = dropdown
frame:UpdateSettings()
frame:InitTab()
end
function TacticFrame:UpdateSettings()
local frame = self
addon.API.UpdateCzechFont(
frame.summary,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE
)
addon.API.UpdateCzechFont(
frame.inform,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE
)
for _, header in ipairs(self.headers) do
addon.API.UpdateCzechFont(
header.description,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE
)
end
end
function TacticFrame:InitTab()
local frame = self
local tab = CreateFrame("Button", "EncounterJournalCustomTab", EncounterJournal.encounter.info, "EncounterTabTemplate")
tab:SetPoint("TOP", EncounterJournal.encounter.info.modelTab, "BOTTOM", -3, -12)
tab:SetSize(50, 40)
tab.tooltip = "Taktika"
local selected = tab:CreateTexture(nil, "BACKGROUND")
selected:SetTexture("Interface\\EncounterJournal\\UI-EncounterJournalTextures")
selected:SetAllPoints(tab)
selected:SetBlendMode("ADD")
selected:SetDrawLayer("OVERLAY")
selected:SetTexCoord(0, 0.126953125, 0.90234375, 0.9599609375)
selected:Hide()
tab.selected = selected
function tab:SetActive(enable)
self:SetEnabled(enable);
self:GetDisabledTexture():SetDesaturated(not enable);
end
function tab:SetHighlight(enable)
if not enable then
self.selected:Hide();
else
self.selected:Show();
end
end
frame.tab = tab
end
function TacticFrame:CreateHeader()
local frame = self
local id = NEXT_HEADER_ID + 1
NEXT_HEADER_ID = id
local HeaderFrame = CreateFrame("FRAME", "CzechQuestsTacticHeader" .. id, frame, "EncounterInfoTemplate")
HeaderFrame:SetSize(self:GetParent():GetWidth() - 10, 30)
addon.API.UpdateCzechFont(
HeaderFrame.description,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_NAME,
CzechQuestsAddon_Store.config.TACTIC_TEXT_FONT_SIZE
)
HeaderFrame.button.abilityIcon:Hide()
HeaderFrame.button.portrait:Hide()
HeaderFrame.button.icon2:Hide()
HeaderFrame.button.icon3:Hide()
HeaderFrame.button.icon4:Hide()
HeaderFrame.button.expandedIcon:SetPoint("TOPLEFT", HeaderFrame.button, "TOPLEFT", 10, -6);
HeaderFrame.button.expandedIcon:SetText("+")
HeaderFrame.expanded = false
HeaderFrame.button.title:SetPoint("TOPLEFT", HeaderFrame, "TOPLEFT", 40, -7);
HeaderFrame.button.title:SetWidth(self:GetParent():GetWidth() - 110)
for i = 1, #HeaderFrame.Bullets do
HeaderFrame.Bullets[i]:Hide()
end
wipe(HeaderFrame.Bullets)
for _, icon in ipairs(HeaderFrame.button.icons) do
icon:Hide();
end
HeaderFrame.description:SetWidth(HeaderFrame:GetWidth() - 20)
HeaderFrame.description:Hide()
HeaderFrame.overviewDescription:Hide()
HeaderFrame.descriptionBG:Hide()
HeaderFrame.descriptionBGBottom:Hide()
function HeaderFrame:Open()
local parent = self
parent.button.expandedIcon:SetText("-")
parent.button.expandedIcon:SetPoint("TOPLEFT", HeaderFrame.button, "TOPLEFT", 10, -5);
parent.description:Show()
parent.descriptionBG:Show()
parent.descriptionBGBottom:Show()
end
function HeaderFrame:Close()
local parent = self
parent.button.expandedIcon:SetText("+")
parent.button.expandedIcon:SetPoint("TOPLEFT", HeaderFrame.button, "TOPLEFT", 10, -6);
parent.description:Hide()
parent.descriptionBG:Hide()
parent.descriptionBGBottom:Hide()
end
HeaderFrame.button:SetScript("OnClick", function(self)
local parent = self:GetParent()
parent.expanded = not parent.expanded
if parent.expanded then
parent:Open()
else
parent:Close()
end
frame:UpdateHeaderPositions()
end)
table.insert(self.headers, HeaderFrame)
return HeaderFrame
end
function TacticFrame:UpdateHeaderPositions()
local yOffset = -40
for _, header in ipairs(self.headers) do
header:SetPoint("BOTTOMLEFT", self.inform, "BOTTOMLEFT", 0, yOffset)
if header.expanded then
yOffset = yOffset - header.description:GetHeight() - 50
else
yOffset = yOffset - 30
end
end
end
function TacticFrame:ClearHeaders()
for _, header in ipairs(self.headers) do
header:Hide()
header:SetParent(nil)
header = nil
end
wipe(self.headers)
end