Refactor Encounters, use new translations format for save space
This commit is contained in:
parent
7d9f58650a
commit
908f45eb9b
59 changed files with 103852 additions and 58396 deletions
300
Addon/Code/Encounter.lua
Executable file
300
Addon/Code/Encounter.lua
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue