Refactor whole addon to follow best practices
This commit is contained in:
parent
43fc252902
commit
414aef6924
31 changed files with 7843 additions and 29579 deletions
202
Addon/Code/Quest.lua
Executable file → Normal file
202
Addon/Code/Quest.lua
Executable file → Normal file
|
@ -1,27 +1,23 @@
|
|||
function CzechQuestsAddon:ShowQuestTranslation(event)
|
||||
-- Hide frame, may contain old texts
|
||||
CzechQuestsAddon.translationQuestFrame:Hide()
|
||||
local _, addon = ...
|
||||
|
||||
local function GetQuestTitle(title, questId)
|
||||
return title .. (CzechQuestsAddon_Store.config.DEBUG_MODE and " (" .. questId .. ")" or "")
|
||||
end
|
||||
|
||||
local function ShowQuestTranslation(event)
|
||||
local frame = addon.QuestFrame
|
||||
frame:Hide()
|
||||
|
||||
-- Classic Era has QuestLogFrame
|
||||
if QuestLogFrame then
|
||||
if QuestLogFrame:IsShown() then
|
||||
if QuestLogFrame:IsVisible() 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()
|
||||
local data = CzechQuestsAddon:GetData("quest", questId)
|
||||
if data then
|
||||
local title = GetQuestTitle(data.title, questId)
|
||||
frame:SetData(title, data.objective, "Popis", data.description, QuestLogFrame, 0, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -32,23 +28,11 @@ function CzechQuestsAddon:ShowQuestTranslation(event)
|
|||
if QuestMapDetailsScrollFrame:IsVisible() then
|
||||
local questId = C_QuestLog.GetSelectedQuest()
|
||||
local hasModel = QuestModelScene:IsVisible()
|
||||
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 50
|
||||
CzechQuestsAddon:ShowTranslationQuestFrame(
|
||||
questTitle,
|
||||
questData.objective,
|
||||
"Popis",
|
||||
questData.description,
|
||||
QuestMapFrame,
|
||||
0,
|
||||
xOffset
|
||||
)
|
||||
CzechQuestsAddon.translationQuestFrame:Show()
|
||||
else
|
||||
CzechQuestsAddon.translationQuestFrame:Hide()
|
||||
local data = CzechQuestsAddon:GetData("quest", questId)
|
||||
if data then
|
||||
local yOffset = hasModel and 210 or 50
|
||||
local title = GetQuestTitle(data.title, questId)
|
||||
frame:SetData(title, data.objective, "Popis", data.description, QuestMapFrame, 0, yOffset)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -56,89 +40,103 @@ function CzechQuestsAddon:ShowQuestTranslation(event)
|
|||
-- If quest is right from NPC, this work for both wow version
|
||||
if event ~= nil then
|
||||
local questId = GetQuestID()
|
||||
if questId == 0 then
|
||||
return
|
||||
end
|
||||
local hasModel = QuestModelScene and QuestModelScene:IsShown() or false
|
||||
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
|
||||
local data = CzechQuestsAddon:GetData("quest", questId)
|
||||
if data then
|
||||
local title = GetQuestTitle(data.title, questId)
|
||||
local xOffset = hasModel and 210 or 10
|
||||
if event == "QUEST_PROGRESS" then
|
||||
CzechQuestsAddon:ShowTranslationQuestFrame(
|
||||
questTitle,
|
||||
questData.progress,
|
||||
"",
|
||||
"",
|
||||
QuestFrame,
|
||||
-20,
|
||||
xOffset
|
||||
)
|
||||
frame:SetData(title, data.progress, "", "", QuestFrame, -20, xOffset)
|
||||
elseif event == "QUEST_COMPLETE" then
|
||||
CzechQuestsAddon:ShowTranslationQuestFrame(
|
||||
questTitle,
|
||||
questData.completion,
|
||||
"",
|
||||
"",
|
||||
QuestFrame,
|
||||
-20,
|
||||
xOffset
|
||||
)
|
||||
frame:SetData(title, data.completion, "", "", QuestFrame, -20, xOffset)
|
||||
elseif event == "QUEST_DETAIL" then
|
||||
CzechQuestsAddon:ShowTranslationQuestFrame(
|
||||
questTitle,
|
||||
questData.description,
|
||||
"Cíl úkolu",
|
||||
questData.objective,
|
||||
QuestFrame,
|
||||
-20,
|
||||
xOffset
|
||||
)
|
||||
frame:SetData(title, data.description, "Cíl úkolu", data.objective, QuestFrame, -20, xOffset)
|
||||
else
|
||||
CzechQuestsAddon.translationQuestFrame:Hide()
|
||||
frame:Hide()
|
||||
end
|
||||
else
|
||||
CzechQuestsAddon.translationQuestFrame:Hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function CzechQuestsAddon:ShowQuestItemTranslation()
|
||||
-- Hide frame, may contain old texts
|
||||
CzechQuestsAddon.translationQuestFrame:Hide()
|
||||
local function ShowQuestItemTranslation()
|
||||
local frame = addon.QuestFrame
|
||||
frame:Hide()
|
||||
|
||||
-- should work for both wow version
|
||||
if ItemTextFrame:IsShown() then
|
||||
local item = {}
|
||||
|
||||
-- get item name
|
||||
-- classic and retail has same frame
|
||||
if ItemTextFrame:IsVisible() then
|
||||
local itemName = ItemTextGetItem();
|
||||
local titlePage = CzechQuestsAddon:GetData("item", itemName)
|
||||
|
||||
-- check if item is translated
|
||||
if titlePage ~= nil then
|
||||
item.name = titlePage.titleMale;
|
||||
local itemNameTranslation = CzechQuestsAddon:GetData("item", itemName)
|
||||
if itemNameTranslation then
|
||||
local pageNum = ItemTextGetPage()
|
||||
local contentPage = CzechQuestsAddon:GetData("item", itemName .. '__' .. pageNum)
|
||||
local itemPageContentTranslation = CzechQuestsAddon:GetData("item", itemName .. '__' .. pageNum)
|
||||
if itemPageContentTranslation then
|
||||
frame:SetData(
|
||||
itemNameTranslation.title,
|
||||
itemPageContentTranslation.text,
|
||||
"",
|
||||
"",
|
||||
ItemTextFrame,
|
||||
-20,
|
||||
0
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- check if item is translated
|
||||
if contentPage ~= nil then
|
||||
item.content = contentPage.text
|
||||
if item.name ~= nil and item.content ~= nil then
|
||||
CzechQuestsAddon:ShowTranslationQuestFrame(
|
||||
item.name,
|
||||
item.content,
|
||||
"",
|
||||
"",
|
||||
ItemTextFrame,
|
||||
-20,
|
||||
0
|
||||
)
|
||||
end
|
||||
local function InitQuests()
|
||||
local frame = addon.QuestFrame
|
||||
|
||||
frame:RegisterEvent("PLAYER_LOGIN")
|
||||
frame:RegisterEvent("QUEST_PROGRESS")
|
||||
frame:RegisterEvent("QUEST_COMPLETE")
|
||||
frame:RegisterEvent("QUEST_FINISHED")
|
||||
frame:RegisterEvent("QUEST_DETAIL")
|
||||
frame:RegisterEvent("ITEM_TEXT_READY")
|
||||
frame:RegisterEvent("PLAYER_STARTED_MOVING")
|
||||
frame:RegisterEvent("PLAYER_STOPPED_MOVING")
|
||||
|
||||
frame:SetScript("OnEvent", function(_, event)
|
||||
if not CzechQuestsAddon_Store.config.QUEST_ENABLED then
|
||||
return
|
||||
end
|
||||
|
||||
if event == "PLAYER_LOGIN" then
|
||||
-- classic
|
||||
if QuestLogFrame then
|
||||
QuestLogFrame:SetScript("OnEnter", function() ShowQuestTranslation() end)
|
||||
QuestLogFrame:SetScript("OnLeave", function() frame:Hide() end)
|
||||
end
|
||||
-- retail
|
||||
if QuestMapDetailsScrollFrame then
|
||||
QuestMapDetailsScrollFrame:SetScript("OnEnter", function() ShowQuestTranslation() end)
|
||||
QuestMapDetailsScrollFrame:SetScript("OnLeave", function() frame:Hide() end)
|
||||
end
|
||||
|
||||
frame:Init()
|
||||
end
|
||||
|
||||
if event == "QUEST_PROGRESS" or event == "QUEST_COMPLETE" or event == "QUEST_DETAIL" or event == "QUEST_FINISHED" then
|
||||
ShowQuestTranslation(event)
|
||||
end
|
||||
|
||||
if (event == "ITEM_TEXT_READY") then
|
||||
ShowQuestItemTranslation()
|
||||
end
|
||||
|
||||
if CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING then
|
||||
if event == "PLAYER_STARTED_MOVING" then
|
||||
frame.Texture:SetAlpha(CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA / 100)
|
||||
elseif event == "PLAYER_STOPPED_MOVING" then
|
||||
frame.Texture:SetAlpha(1)
|
||||
end
|
||||
end
|
||||
|
||||
CzechQuestsAddon.translationQuestFrame:Show()
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
addon.API.InitQuests = InitQuests
|
Loading…
Add table
Add a link
Reference in a new issue