addon/Addon/Addon.lua

254 lines
9.7 KiB
Lua
Executable file

function CzechQuestsAddon:ShowQuestTranslation(event)
-- Hide frame, may contain old texts
CzechQuestsAddon.translationQuestFrame: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:ShowTranslationQuestFrame(
questTitle,
questData.objective,
"Popis",
questData.description,
QuestLogFrame,
-14,
0
)
CzechQuestsAddon.translationQuestFrame: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:ShowTranslationQuestFrame(
questTitle,
questData.objective,
"Popis",
questData.description,
QuestMapFrame,
0,
xOffset
)
CzechQuestsAddon.translationQuestFrame:Show()
else
CzechQuestsAddon.translationQuestFrame: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.translationQuestFrame: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:ShowTranslationQuestFrame(
questTitle,
questData.progress,
"",
"",
QuestFrame,
-20,
xOffset
)
elseif event == "QUEST_COMPLETE" then
CzechQuestsAddon:ShowTranslationQuestFrame(
questTitle,
questData.completion,
"",
"",
QuestFrame,
-20,
xOffset
)
elseif event == "QUEST_DETAIL" then
CzechQuestsAddon:ShowTranslationQuestFrame(
questTitle,
questData.description,
"Cíl úkolu",
questData.objective,
QuestFrame,
-20,
xOffset
)
else
CzechQuestsAddon.translationQuestFrame:Hide()
end
else
CzechQuestsAddon.translationQuestFrame:Hide()
end
end
end
end
function CzechQuestsAddon:ShowQuestItemTranslation()
-- Hide frame, may contain old texts
CzechQuestsAddon.translationQuestFrame: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:ShowTranslationQuestFrame(
item.name,
item.content,
"",
"",
ItemTextFrame,
-20,
0
)
end
end
end
CzechQuestsAddon.translationQuestFrame:Show()
end
end
function CzechQuestsAddon:ShowSpeechTranslation(sender, message)
local blue = "|cffADD8E6"
local yellow = "|cffffd200"
local white = "|cffffffff"
local reset = "|r"
local text = nil
local translation = CzechQuestsAddon:GetData("speech", message)
if translation ~= nil then
text = translation.text
CzechQuestsAddon.translationSpeechFrame.npcName:SetText(sender)
CzechQuestsAddon.translationSpeechFrame.text:SetText(text)
CzechQuestsAddon.translationSpeechFrame.text:SetPoint(
"TOPLEFT", CzechQuestsAddon.translationSpeechFrame.npcName, "BOTTOMLEFT", 0, -10
)
CzechQuestsAddon.translationSpeechFrame:Show()
print(blue .. "[CZ]" .. reset .. " " .. yellow .. sender .. reset .. ": " .. white .. text .. reset)
end
if timerHandle then
timerHandle:Cancel()
end
timerHandle = C_Timer.NewTimer(10, function()
CzechQuestsAddon.translationSpeechFrame:Hide()
end)
end
-- Hover is enabled only for QuestLogFrame and QuestMapDetailsScrollFrame
local function SetHoverScripts(frame)
frame:SetScript("OnEnter", function()
CzechQuestsAddon:ShowQuestTranslation()
end)
frame:SetScript("OnLeave", function()
CzechQuestsAddon.translationQuestFrame:Hide()
end)
end
function CzechQuestsAddon:InitializeTranslations()
-- create translation frame
CzechQuestsAddon.translationQuestFrame = CzechQuestsAddon:CreateTranslationQuestFrame()
CzechQuestsAddon.translationSpeechFrame = CzechQuestsAddon:CreateTranslationSpeechFrame()
-- Register events
CzechQuestsAddon.translationQuestFrame:RegisterEvent("PLAYER_LOGIN")
CzechQuestsAddon.translationQuestFrame:RegisterEvent("QUEST_PROGRESS")
CzechQuestsAddon.translationQuestFrame:RegisterEvent("QUEST_COMPLETE")
CzechQuestsAddon.translationQuestFrame:RegisterEvent("QUEST_FINISHED")
CzechQuestsAddon.translationQuestFrame:RegisterEvent("QUEST_DETAIL")
CzechQuestsAddon.translationQuestFrame:RegisterEvent("ITEM_TEXT_READY")
CzechQuestsAddon.translationQuestFrame:RegisterEvent("PLAYER_STARTED_MOVING")
CzechQuestsAddon.translationQuestFrame:RegisterEvent("PLAYER_STOPPED_MOVING")
-- Define event handler for the main frame
CzechQuestsAddon.translationQuestFrame: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
if event == "PLAYER_STARTED_MOVING" then
CzechQuestsAddon.translationQuestFrame.texture:SetAlpha(
CzechQuestsAddon_Store.config.TRANSLATION_FRAME_TEXTURE_ALPHA / 100
)
elseif event == "PLAYER_STOPPED_MOVING" then
CzechQuestsAddon.translationQuestFrame.texture:SetAlpha(1)
end
end)
CzechQuestsAddon.translationSpeechFrame:RegisterEvent("CHAT_MSG_MONSTER_SAY")
CzechQuestsAddon.translationSpeechFrame:RegisterEvent("CHAT_MSG_MONSTER_YELL")
CzechQuestsAddon.translationSpeechFrame:RegisterEvent("CHAT_MSG_MONSTER_EMOTE")
CzechQuestsAddon.translationSpeechFrame:RegisterEvent("CHAT_MSG_MONSTER_PARTY")
CzechQuestsAddon.translationSpeechFrame:RegisterEvent("CHAT_MSG_MONSTER_WHISPER")
-- Define event handler for the main frame
CzechQuestsAddon.translationSpeechFrame:SetScript("OnEvent", function(self, event, message, sender)
CzechQuestsAddon:ShowSpeechTranslation(sender, message)
end)
end