function CzechQuestsAddon:ShowTranslationFrame(primaryHeader, primaryText, secondaryHeader, secondaryText, parentFrame, yOffset, xOffset) -- replace placeholders with current values primaryText = CzechQuestsAddon:replacePlaceholders(primaryText); secondaryText = CzechQuestsAddon:replacePlaceholders(secondaryText); -- when user change own setting, does not require reload, just apply it CzechQuestsAddon:SetTextureFromSettings(CzechQuestsAddon.translationFrame) -- reset all texts CzechQuestsAddon:ResetTranslationText(CzechQuestsAddon.translationFrame) -- set text to labels CzechQuestsAddon.translationFrame.primaryHeader:SetText(primaryHeader) CzechQuestsAddon.translationFrame.primaryText:SetText(primaryText) CzechQuestsAddon.translationFrame.secondaryHeader:SetText(secondaryHeader) CzechQuestsAddon.translationFrame.secondaryText:SetText(secondaryText) local primaryTextTopMargin = -CzechQuestsAddon.translationFrame.primaryHeader:GetHeight() - 15 local secondaryHeaderTopMargin = primaryTextTopMargin - CzechQuestsAddon.translationFrame.primaryText:GetHeight() - 20 local secondaryTextTopMargin = secondaryHeaderTopMargin - CzechQuestsAddon.translationFrame.secondaryHeader:GetHeight() - 5 -- apply gap between headers and texts local gap = 10 local function addPadding(text, value) if text ~= "" then gap = gap + value end end addPadding(primaryHeader, 10) addPadding(primaryText, 5) addPadding(secondaryHeader, 25) addPadding(secondaryText, 5) -- apply positions CzechQuestsAddon.translationFrame.primaryHeader:SetPoint("TOPLEFT", 10, -10) CzechQuestsAddon.translationFrame.primaryText:SetPoint("TOPLEFT", 10, primaryTextTopMargin) CzechQuestsAddon.translationFrame.secondaryHeader:SetPoint("TOPLEFT", 10, secondaryHeaderTopMargin) CzechQuestsAddon.translationFrame.secondaryText:SetPoint("TOPLEFT", 10, secondaryTextTopMargin) -- apply changes per wow if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then CzechQuestsAddon.translationFrame:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", -8 + xOffset, yOffset) else CzechQuestsAddon.translationFrame:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", 8 + xOffset, yOffset) end -- calculate height local height = 0; local heights = { CzechQuestsAddon.translationFrame.primaryHeader:GetHeight(), CzechQuestsAddon.translationFrame.primaryText:GetHeight(), CzechQuestsAddon.translationFrame.secondaryHeader:GetHeight(), CzechQuestsAddon.translationFrame.secondaryText:GetHeight(), gap, 10 } for _, value in ipairs(heights) do height = height + value end CzechQuestsAddon.translationFrame:SetParent(parentFrame) CzechQuestsAddon.translationFrame:SetHeight(height < 200 and 200 or height) end function CzechQuestsAddon:ShowQuestTranslation(event) -- Hide frame, may contain old texts CzechQuestsAddon.translationFrame:Hide() -- Classic Era has QuestLogFrame if QuestLogFrame then if QuestLogFrame:IsShown() then local questIndex = GetQuestLogSelection() if questIndex > 0 then local questId = select(8, GetQuestLogTitle(questIndex)) local questData = CzechQuestsAddon:GetData("quest", questId) if questData then local suffix = CzechQuestsAddon_Store.config.DEBUG_MODE and " (" .. questId .. ")" or "" local questTitle = questData.title .. suffix CzechQuestsAddon:ShowTranslationFrame( questTitle, questData.objective, "Popis", questData.description, QuestLogFrame, -14, 0 ) CzechQuestsAddon.translationFrame:Show() end end end end -- Retail has QuestMapDetailsScrollFrame if QuestMapDetailsScrollFrame then if QuestMapDetailsScrollFrame:IsShown() then -- get quest ID local questId = C_QuestLog.GetSelectedQuest() -- detect if quest frame does not include npc preview local hasModel = QuestModelScene:IsShown() -- show translation frame local questData = CzechQuestsAddon:GetData("quest", questId) if questData then local suffix = CzechQuestsAddon_Store.config.DEBUG_MODE and " (" .. questId .. ")" or "" local questTitle = questData.title .. suffix local xOffset = hasModel and 210 or 0 CzechQuestsAddon:ShowTranslationFrame( questTitle, questData.objective, "Popis", questData.description, QuestMapFrame, 0, xOffset ) CzechQuestsAddon.translationFrame:Show() else CzechQuestsAddon.translationFrame:Hide() end end end -- If quest is right from NPC, this work for both wow version if event ~= nil then -- get quest ID local questId = GetQuestID() -- detect if quest frame does not include npc preview local hasModel = QuestModelScene and QuestModelScene:IsShown() or false -- show translation frame if questId then local questData = CzechQuestsAddon:GetData("quest", questId) if questData then CzechQuestsAddon.translationFrame:Show() local suffix = CzechQuestsAddon_Store.config.DEBUG_MODE and " (" .. questId .. ")" or "" local questTitle = questData.title .. suffix local xOffset = hasModel and 210 or 0 if event == "QUEST_PROGRESS" then CzechQuestsAddon:ShowTranslationFrame( questTitle, questData.progress, "", "", QuestFrame, -20, xOffset ) elseif event == "QUEST_COMPLETE" then CzechQuestsAddon:ShowTranslationFrame( questTitle, questData.completion, "", "", QuestFrame, -20, xOffset ) elseif event == "QUEST_DETAIL" then CzechQuestsAddon:ShowTranslationFrame( questTitle, questData.description, "Cíl úkolu", questData.objective, QuestFrame, -20, xOffset ) else CzechQuestsAddon.translationFrame:Hide() end else CzechQuestsAddon.translationFrame:Hide() end end end end function CzechQuestsAddon:ShowQuestItemTranslation() -- Hide frame, may contain old texts CzechQuestsAddon.translationFrame:Hide() -- should work for both wow version if ItemTextFrame:IsShown() then local item = {} -- get item name local itemName = ItemTextGetItem(); local titlePage = CzechQuestsAddon:GetData("item", itemName) -- check if item is translated if titlePage ~= nil then item.name = titlePage.titleMale; local pageNum = ItemTextGetPage() local contentPage = CzechQuestsAddon:GetData("item", itemName..'__'..pageNum) -- check if item is translated if contentPage ~= nil then item.content = contentPage.descriptionMale if item.name ~= nil and item.content ~= nil then CzechQuestsAddon:ShowTranslationFrame( item.name, item.content, "", "", ItemTextFrame, -20, 0 ) end end end CzechQuestsAddon.translationFrame:Show() end end -- Hover is enabled only for QuestLogFrame and QuestMapDetailsScrollFrame local function SetHoverScripts(frame) local frameName = frame:GetName() if not string.find(frameName, "QuestLogItem") and not string.find(frameName, "QuestProgressItem") then frame:SetScript("OnEnter", function() CzechQuestsAddon:ShowQuestTranslation() end) frame:SetScript("OnLeave", function() CzechQuestsAddon.translationFrame:Hide() end) end end function CzechQuestsAddon:InitializeTranslations() -- create translation frame CzechQuestsAddon.translationFrame = CzechQuestsAddon:CreateTranslationFrame() -- Register events with the main frame CzechQuestsAddon.translationFrame:RegisterEvent("PLAYER_LOGIN") CzechQuestsAddon.translationFrame:RegisterEvent("QUEST_PROGRESS") CzechQuestsAddon.translationFrame:RegisterEvent("QUEST_COMPLETE") CzechQuestsAddon.translationFrame:RegisterEvent("QUEST_FINISHED") CzechQuestsAddon.translationFrame:RegisterEvent("QUEST_DETAIL") CzechQuestsAddon.translationFrame:RegisterEvent("ITEM_TEXT_READY") -- Preparation for eventually show translation when hover quest in quest tracker for retail --if (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE) then -- _G.EventRegistry:RegisterCallback("OnQuestBlockHeader.OnEnter", function(sender, self, questID, isGroup) -- print(questID) -- end) --end -- Define event handler for the main frame CzechQuestsAddon.translationFrame:SetScript("OnEvent", function(self, event, ...) if event == "PLAYER_LOGIN" then -- classic if QuestLogFrame then SetHoverScripts(QuestLogFrame) end -- retail if QuestMapDetailsScrollFrame then SetHoverScripts(QuestMapDetailsScrollFrame) end end if event == "QUEST_PROGRESS" or event == "QUEST_COMPLETE" or event == "QUEST_DETAIL" or event == "QUEST_FINISHED" then CzechQuestsAddon:ShowQuestTranslation(event) end if (event == "ITEM_TEXT_READY") then CzechQuestsAddon:ShowQuestItemTranslation() end end) end