addon/CzechQuests.lua

239 lines
8.8 KiB
Lua
Executable file

local lastQuestFrameEvent = nil
local addonName, addonDataTable = ...
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, '<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
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() 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() 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()
--end)
--frame:SetScript("OnLeave", function()
-- QuestTranslationFrame:Hide()
--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)