local lastQuestFrameEvent = nil local addonName, addonDataTable = ... local questFrameBeingHovered = false local function GetQuestInfo(maleVersion, femaleVersion) local gender = UnitSex("player") if gender == 2 then return maleVersion end if gender == 3 then return femaleVersion 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 = GetQuestInfo(quest.titleMale, quest.titleFemale), objective = GetQuestInfo(quest.objectiveMale, quest.objectiveFemale), description = GetQuestInfo(quest.descriptionMale, quest.descriptionFemale), progress = GetQuestInfo(quest.progressMale, quest.progressFemale), completion = GetQuestInfo(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 SetQuestDetails(questId, headerText, objectiveText, descriptionHeader, descriptionText, parentFrame, yOffset) objectiveText = replacePlaceholders(objectiveText); descriptionText = replacePlaceholders(descriptionText); if CzechQuestsOptions["DEBUG_MODE"] then headerText = headerText .. " (" .. questId ..")" end QuestTranslationFramePrimaryHeader:SetText(headerText:upper()) QuestTranslationFramePrimaryText:SetText(objectiveText) QuestTranslationFrameSecondaryHeader:SetText(descriptionHeader:upper()) QuestTranslationFrameSecondaryText:SetText(descriptionText) textTopMargin = -QuestTranslationFramePrimaryHeader:GetHeight() - 15 descriptionHeaderTopMargin = textTopMargin - QuestTranslationFramePrimaryText:GetHeight() - 10 descriptionTextTopMargin = descriptionHeaderTopMargin - QuestTranslationFrameSecondaryHeader: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, 20) addPadding(descriptionText, 5) QuestTranslationFramePrimaryHeader:SetPoint("TOPLEFT", 10, -10) QuestTranslationFramePrimaryText:SetPoint("TOPLEFT", 10, textTopMargin) QuestTranslationFrameSecondaryHeader:SetPoint("TOPLEFT", 10, descriptionHeaderTopMargin) QuestTranslationFrameSecondaryText:SetPoint("TOPLEFT", 10, descriptionTextTopMargin) QuestTranslationFrame:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", -15, yOffset) QuestTranslationFrame:SetParent(parentFrame) QuestTranslationFrame:SetHeight( QuestTranslationFramePrimaryHeader:GetHeight() + QuestTranslationFramePrimaryText:GetHeight() + QuestTranslationFrameSecondaryHeader:GetHeight() + QuestTranslationFrameSecondaryText:GetHeight() + heightPadding ) end local function UpdateQuestTranslationFrame() local selectedQuestIndex, questId, questData if QuestLogFrame:IsShown() and QuestLogFrame:IsMouseOver() then selectedQuestIndex = GetQuestLogSelection() if selectedQuestIndex > 0 then questId = select(8, GetQuestLogTitle(selectedQuestIndex)) questData = GetDataByKey("questData", questId) if questData then QuestTranslationFrame:Show() SetQuestDetails( questId, questData.title, questData.objective, addonDataTable.translations["description"], questData.description, QuestLogFrame, -80 ) else QuestTranslationFrame:Hide() end end end if QuestFrame:IsShown() and QuestFrame:IsMouseOver() then questId = GetQuestID() if questId then questData = GetDataByKey("questData", questId) if questData then QuestTranslationFrame:Show() if lastQuestFrameEvent == "QUEST_PROGRESS" then SetQuestDetails( questId, questData.title, questData.progress, "", "", QuestFrame, -80 ) elseif lastQuestFrameEvent == "QUEST_COMPLETE" then SetQuestDetails( questId, questData.title, questData.completion, "", "", QuestFrame, -80 ) elseif lastQuestFrameEvent == "QUEST_DETAIL" then SetQuestDetails( questId, questData.title, questData.description, addonDataTable.translations["objectives"], questData.objective, QuestFrame, -80 ) elseif lastQuestFrameEvent == "QUEST_FINISHED" then QuestTranslationFrame:Hide() end else QuestTranslationFrame:Hide() end end end end local function SetQuestHoverScripts(frame, children) local frameName = frame:GetName() if frameName ~= "QuestLogListScrollFrame" and not string.find(frameName, "QuestLogItem") and not string.find(frameName, "QuestProgressItem") then frame:SetScript("OnEnter", function() UpdateQuestTranslationFrame() questFrameBeingHovered = true end) frame:SetScript("OnLeave", function() QuestTranslationFrame:Hide() questFrameBeingHovered = false end) if children then for i = 1, frame:GetNumChildren() do local child = select(i, frame:GetChildren()) SetQuestHoverScripts(child, true) end end end end QuestTranslationFrame:SetScript("OnEvent", function(self, event, ...) if event == "QUEST_PROGRESS" or event == "QUEST_COMPLETE" or event == "QUEST_FINISHED" or event == "QUEST_DETAIL" then lastQuestFrameEvent = event UpdateQuestTranslationFrame() end end) SetQuestHoverScripts(QuestLogFrame, true) SetQuestHoverScripts(QuestFrame, false) SetQuestHoverScripts(QuestProgressScrollFrame, true) SetQuestHoverScripts(QuestDetailScrollFrame, true) SetQuestHoverScripts(QuestRewardScrollFrame, true) SetQuestHoverScripts(QuestFrameCompleteButton, true) SetQuestHoverScripts(QuestFrameCompleteQuestButton, true) SetQuestHoverScripts(QuestFrameGoodbyeButton, true) SetQuestHoverScripts(QuestFrameCancelButton, true)