addon/CzechQuests.lua

266 lines
9.7 KiB
Lua
Raw Normal View History

2024-07-07 12:29:29 +02:00
local lastQuestFrameEvent = nil
local addonName, addonDataTable = ...
2024-07-15 13:37:24 +02:00
local function ResolveFemaleVersion(maleVersion, femaleVersion)
2024-07-07 12:29:29 +02:00
local gender = UnitSex("player")
if gender == 2 then
return maleVersion
2024-07-15 13:37:24 +02:00
end
2024-07-07 12:29:29 +02:00
if gender == 3 then
2024-07-15 13:37:24 +02:00
if (femaleVersion == "") then
return maleVersion
else
return femaleVersion
end
2024-07-07 12:29:29 +02:00
end
end
local function GetDataByKey(dataType, dataId)
if addonDataTable[dataType] then
if dataType == "questData" then
if addonDataTable[dataType][dataId] then
local quest = addonDataTable[dataType][dataId];
local standardQuest = {
2024-07-15 13:37:24 +02:00
title = ResolveFemaleVersion(quest.titleMale, quest.titleFemale),
objective = ResolveFemaleVersion(quest.objectiveMale, quest.objectiveFemale),
description = ResolveFemaleVersion(quest.descriptionMale, quest.descriptionFemale),
progress = ResolveFemaleVersion(quest.progressMale, quest.progressFemale),
completion = ResolveFemaleVersion(quest.completionMale, quest.completionFemale),
2024-07-07 12:29:29 +02:00
}
return standardQuest
end
elseif addonDataTable[dataType][dataId] then
return addonDataTable[dataType][dataId]
end
end
return nil
end
local function replacePlaceholders(text)
2024-07-15 13:37:24 +02:00
if text == nil then
return text
end
2024-07-07 12:29:29 +02:00
local playerName = UnitName("player")
local _, playerClass = UnitClass("player")
local _, playerRace = UnitRace("player")
local class = GetDataByKey("classData", playerClass);
local race = GetDataByKey("raceData", playerRace);
local formatted = text;
formatted = string.gsub(formatted, '<name>', playerName);
formatted = string.gsub(formatted, '<cF0>', class.f0);
formatted = string.gsub(formatted, '<cF1>', class.f1);
formatted = string.gsub(formatted, '<cF2>', class.f2);
formatted = string.gsub(formatted, '<cF3>', class.f3);
formatted = string.gsub(formatted, '<cF4>', class.f4);
formatted = string.gsub(formatted, '<cF5>', class.f5);
formatted = string.gsub(formatted, '<cM0>', class.m0);
formatted = string.gsub(formatted, '<cM1>', class.m1);
formatted = string.gsub(formatted, '<cM2>', class.m2);
formatted = string.gsub(formatted, '<cM3>', class.m3);
formatted = string.gsub(formatted, '<cM4>', class.m4);
formatted = string.gsub(formatted, '<rF0>', race.f0);
formatted = string.gsub(formatted, '<rF1>', race.f1);
formatted = string.gsub(formatted, '<rF2>', race.f2);
formatted = string.gsub(formatted, '<rF3>', race.f3);
formatted = string.gsub(formatted, '<rF4>', race.f4);
formatted = string.gsub(formatted, '<rF5>', race.f5);
formatted = string.gsub(formatted, '<rM0>', race.m0);
formatted = string.gsub(formatted, '<rM1>', race.m1);
formatted = string.gsub(formatted, '<rM2>', race.m2);
formatted = string.gsub(formatted, '<rM3>', race.m3);
formatted = string.gsub(formatted, '<rM4>', race.m4);
return formatted
end
2024-07-15 13:37:24 +02:00
local function ShowTranslatedQuestFrame(questId, headerText, objectiveText, descriptionHeader, descriptionText, parentFrame, yOffset)
2024-07-07 12:29:29 +02:00
objectiveText = replacePlaceholders(objectiveText);
descriptionText = replacePlaceholders(descriptionText);
if CzechQuestsOptions["DEBUG_MODE"] then
2024-07-15 13:37:24 +02:00
headerText = headerText .. " (" .. questId .. ")"
end
2024-07-15 13:37:24 +02:00
TranslationInfoFramePrimaryHeader:SetText(headerText:upper())
TranslationInfoFramePrimaryText:SetText(objectiveText)
TranslationInfoFrameSecondaryHeader:SetText(descriptionHeader:upper())
TranslationInfoFrameSecondaryText:SetText(descriptionText)
2024-07-07 12:29:29 +02:00
2024-07-15 13:37:24 +02:00
textTopMargin = -TranslationInfoFramePrimaryHeader:GetHeight() - 15
descriptionHeaderTopMargin = textTopMargin - TranslationInfoFramePrimaryText:GetHeight() - 20
descriptionTextTopMargin = descriptionHeaderTopMargin - TranslationInfoFrameSecondaryHeader:GetHeight() - 5
2024-07-07 12:29:29 +02:00
local heightPadding = 10
local addPadding = function(text, value)
if text ~= "" then
heightPadding = heightPadding + value
end
end
addPadding(headerText, 10)
addPadding(objectiveText, 5)
2024-07-15 13:37:24 +02:00
addPadding(descriptionHeader, 25)
2024-07-07 12:29:29 +02:00
addPadding(descriptionText, 5)
2024-07-15 13:37:24 +02:00
TranslationInfoFramePrimaryHeader:SetPoint("TOPLEFT", 10, -10)
TranslationInfoFramePrimaryText:SetPoint("TOPLEFT", 10, textTopMargin)
TranslationInfoFrameSecondaryHeader:SetPoint("TOPLEFT", 10, descriptionHeaderTopMargin)
TranslationInfoFrameSecondaryText:SetPoint("TOPLEFT", 10, descriptionTextTopMargin)
TranslationInfoFrame:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", -15, yOffset)
TranslationInfoFrame:SetParent(parentFrame)
TranslationInfoFrame:SetHeight(
TranslationInfoFramePrimaryHeader:GetHeight() +
TranslationInfoFramePrimaryText:GetHeight() +
TranslationInfoFrameSecondaryHeader:GetHeight() +
TranslationInfoFrameSecondaryText:GetHeight() +
2024-07-07 12:29:29 +02:00
heightPadding
)
end
2024-07-15 13:37:24 +02:00
local function ShowTranslatedQuestItemFrame(itemText, parentFrame, yOffset)
itemText = replacePlaceholders(itemText);
TranslationInfoFramePrimaryText:SetText(itemText)
TranslationInfoFramePrimaryText:SetPoint("TOPLEFT", 10, 5)
TranslationInfoFrame:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", -15, yOffset)
TranslationInfoFrame:SetParent(parentFrame)
TranslationInfoFrame:SetHeight(TranslationInfoFramePrimaryText:GetHeight() + 30)
TranslationInfoFramePrimaryText:SetPoint("TOPLEFT", 10, -10)
TranslationInfoFrame:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", -15, yOffset)
end
local function UpdateTranslationInfoFrame(frameEvent)
local selectedQuestIndex, questId, questData, itemName
2024-07-07 12:29:29 +02:00
if QuestLogFrame:IsShown() then
2024-07-07 12:29:29 +02:00
selectedQuestIndex = GetQuestLogSelection()
if selectedQuestIndex > 0 then
questId = select(8, GetQuestLogTitle(selectedQuestIndex))
questData = GetDataByKey("questData", questId)
if questData then
2024-07-15 13:37:24 +02:00
TranslationInfoFrame:Show()
ShowTranslatedQuestFrame(
questId,
questData.title,
questData.objective,
addonDataTable.translations["description"],
questData.description,
QuestLogFrame,
-80
2024-07-07 12:29:29 +02:00
)
else
2024-07-15 13:37:24 +02:00
TranslationInfoFrame:Hide()
2024-07-07 12:29:29 +02:00
end
end
end
if QuestFrame:IsShown() then
2024-07-07 12:29:29 +02:00
questId = GetQuestID()
if questId then
questData = GetDataByKey("questData", questId)
if questData then
2024-07-15 13:37:24 +02:00
TranslationInfoFrame:Show()
2024-07-07 12:29:29 +02:00
2024-07-15 13:37:24 +02:00
if frameEvent == "QUEST_PROGRESS" then
ShowTranslatedQuestFrame(
questId,
2024-07-07 12:29:29 +02:00
questData.title,
questData.progress,
"",
"",
QuestFrame,
-80
)
2024-07-15 13:37:24 +02:00
elseif frameEvent == "QUEST_COMPLETE" then
if CzechQuestsOptions["DEBUG_MODE"] then
QuestDoneFrame:Show()
QuestDoneFrame.text:SetText("Quest #" .. questId .. " is DONE!")
end
ShowTranslatedQuestFrame(
questId,
2024-07-07 12:29:29 +02:00
questData.title,
questData.completion,
"",
"",
QuestFrame,
-80
)
2024-07-15 13:37:24 +02:00
elseif frameEvent == "QUEST_DETAIL" then
ShowTranslatedQuestFrame(
questId,
2024-07-07 12:29:29 +02:00
questData.title,
questData.description,
addonDataTable.translations["objectives"],
questData.objective,
QuestFrame,
-80
)
2024-07-15 13:37:24 +02:00
elseif frameEvent == "QUEST_FINISHED" then
TranslationInfoFrame:Hide()
2024-07-07 12:29:29 +02:00
end
else
2024-07-15 13:37:24 +02:00
TranslationInfoFrame:Hide()
2024-07-07 12:29:29 +02:00
end
end
end
2024-07-15 13:37:24 +02:00
if ItemTextFrame:IsShown() then
itemName = ItemTextGetItem();
local itemText = GetDataByKey("questItems", itemName)
TranslationInfoFrame:Show()
ShowTranslatedQuestItemFrame(itemText, ItemTextFrame, -80)
end
2024-07-07 12:29:29 +02:00
end
2024-07-15 13:37:24 +02:00
TranslationInfoFrame:SetScript("OnEvent", function(self, event, ...)
2024-07-07 12:29:29 +02:00
if event == "QUEST_PROGRESS" or event == "QUEST_COMPLETE" or event == "QUEST_FINISHED" or event == "QUEST_DETAIL" then
2024-07-15 13:37:24 +02:00
UpdateTranslationInfoFrame(event)
end
if (event == "ITEM_TEXT_READY") then
UpdateTranslationInfoFrame(event)
2024-07-07 12:29:29 +02:00
end
end)
2024-07-15 13:37:24 +02:00
-- Hover is enabled only for QuestLogFrame because i do know event for change quest from list
local function SetHoverScripts(frame, children)
local frameName = frame:GetName()
if not string.find(frameName, "QuestLogItem") and not string.find(frameName, "QuestProgressItem") then
frame:SetScript("OnEnter", function()
UpdateTranslationInfoFrame()
end)
2024-07-07 12:29:29 +02:00
2024-07-15 13:37:24 +02:00
frame:SetScript("OnLeave", function()
TranslationInfoFrame:Hide()
end)
if children then
for i = 1, frame:GetNumChildren() do
local child = select(i, frame:GetChildren())
SetHoverScripts(child, true)
end
end
end
end
2024-07-07 12:29:29 +02:00
2024-07-15 13:37:24 +02:00
SetHoverScripts(QuestLogFrame, false)