local lastQuestFrameEvent = nil local addonName, addonDataTable = ... local function ResolveFemaleVersion(maleVersion, femaleVersion) local gender = UnitSex("player") if gender == 2 then return maleVersion end if gender == 3 then if (femaleVersion == "") then return maleVersion else return femaleVersion end 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 = { 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), } return standardQuest end elseif addonDataTable[dataType][dataId] then return addonDataTable[dataType][dataId] end end return nil end local function replacePlaceholders(text) if text == nil then return text end 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, '', playerName); formatted = string.gsub(formatted, '', class.f0); formatted = string.gsub(formatted, '', class.f1); formatted = string.gsub(formatted, '', class.f2); formatted = string.gsub(formatted, '', class.f3); formatted = string.gsub(formatted, '', class.f4); formatted = string.gsub(formatted, '', class.f5); formatted = string.gsub(formatted, '', class.m0); formatted = string.gsub(formatted, '', class.m1); formatted = string.gsub(formatted, '', class.m2); formatted = string.gsub(formatted, '', class.m3); formatted = string.gsub(formatted, '', class.m4); formatted = string.gsub(formatted, '', race.f0); formatted = string.gsub(formatted, '', race.f1); formatted = string.gsub(formatted, '', race.f2); formatted = string.gsub(formatted, '', race.f3); formatted = string.gsub(formatted, '', race.f4); formatted = string.gsub(formatted, '', race.f5); formatted = string.gsub(formatted, '', race.m0); formatted = string.gsub(formatted, '', race.m1); formatted = string.gsub(formatted, '', race.m2); formatted = string.gsub(formatted, '', race.m3); formatted = string.gsub(formatted, '', race.m4); return formatted end local function ShowTranslatedQuestFrame(questId, headerText, objectiveText, descriptionHeader, descriptionText, parentFrame, yOffset) objectiveText = replacePlaceholders(objectiveText); descriptionText = replacePlaceholders(descriptionText); if CzechQuestsOptions["DEBUG_MODE"] then headerText = headerText .. " (" .. questId .. ")" end TranslationInfoFramePrimaryHeader:SetText(headerText:upper()) TranslationInfoFramePrimaryText:SetText(objectiveText) TranslationInfoFrameSecondaryHeader:SetText(descriptionHeader:upper()) TranslationInfoFrameSecondaryText:SetText(descriptionText) textTopMargin = -TranslationInfoFramePrimaryHeader:GetHeight() - 15 descriptionHeaderTopMargin = textTopMargin - TranslationInfoFramePrimaryText:GetHeight() - 20 descriptionTextTopMargin = descriptionHeaderTopMargin - TranslationInfoFrameSecondaryHeader:GetHeight() - 5 local heightPadding = 10 local addPadding = function(text, value) if text ~= "" then heightPadding = heightPadding + value end end addPadding(headerText, 10) addPadding(objectiveText, 5) addPadding(descriptionHeader, 25) addPadding(descriptionText, 5) 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() + heightPadding ) end 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 if TranslationInfoFrame:IsShown() then TranslationInfoFrame:Hide() end if QuestLogFrame:IsShown() then selectedQuestIndex = GetQuestLogSelection() if selectedQuestIndex > 0 then questId = select(8, GetQuestLogTitle(selectedQuestIndex)) questData = GetDataByKey("questData", questId) if questData then TranslationInfoFrame:Show() ShowTranslatedQuestFrame( questId, questData.title, questData.objective, addonDataTable.translations["description"], questData.description, QuestLogFrame, -80 ) else TranslationInfoFrame:Hide() end end end if QuestFrame:IsShown() then questId = GetQuestID() if questId then questData = GetDataByKey("questData", questId) if questData then TranslationInfoFrame:Show() if frameEvent == "QUEST_PROGRESS" then ShowTranslatedQuestFrame( questId, questData.title, questData.progress, "", "", QuestFrame, -80 ) elseif frameEvent == "QUEST_COMPLETE" then ShowTranslatedQuestFrame( questId, questData.title, questData.completion, "", "", QuestFrame, -80 ) elseif frameEvent == "QUEST_DETAIL" then ShowTranslatedQuestFrame( questId, questData.title, questData.description, addonDataTable.translations["objectives"], questData.objective, QuestFrame, -80 ) elseif frameEvent == "QUEST_FINISHED" then TranslationInfoFrame:Hide() end else TranslationInfoFrame:Hide() end end end if ItemTextFrame:IsShown() then itemName = ItemTextGetItem(); local itemText = GetDataByKey("questItems", itemName) TranslationInfoFrame:Show() ShowTranslatedQuestItemFrame(itemText, ItemTextFrame, -80) end end TranslationInfoFrame:SetScript("OnEvent", function(self, event, ...) if event == "QUEST_PROGRESS" or event == "QUEST_COMPLETE" or event == "QUEST_FINISHED" or event == "QUEST_DETAIL" then UpdateTranslationInfoFrame(event) end if (event == "ITEM_TEXT_READY") then UpdateTranslationInfoFrame(event) end end) -- 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) 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 SetHoverScripts(QuestLogFrame, false)