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
|
@ -1,149 +1,23 @@
|
|||
local QuestTextMethod = {
|
||||
Description = GetQuestText,
|
||||
Objective = GetObjectiveText,
|
||||
};
|
||||
|
||||
local function GetQuestText(method)
|
||||
local text = QuestTextMethod[method]();
|
||||
if text then
|
||||
return text
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
local function GetQuestLogQuestIndex(questID)
|
||||
local numEntries = C_QuestLog.GetNumQuestLogEntries()
|
||||
for questLogIndex = 1, numEntries do
|
||||
local info = C_QuestLog.GetInfo(questLogIndex)
|
||||
if info and info.questID == questID then
|
||||
return questLogIndex
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function ApplyQuestPlaceholders(text)
|
||||
if text == nil then
|
||||
return text
|
||||
end
|
||||
|
||||
local playerName = UnitName("player")
|
||||
local _, playerClass = UnitClass("player")
|
||||
local _, playerRace = UnitRace("player")
|
||||
|
||||
local class = CzechQuestsAddon:GetData("class", playerClass);
|
||||
local race = CzechQuestsAddon:GetData("race", 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, '<cP0>', class.p0);
|
||||
formatted = string.gsub(formatted, '<cP1>', class.p1);
|
||||
formatted = string.gsub(formatted, '<cP3>', class.m3);
|
||||
|
||||
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);
|
||||
|
||||
formatted = string.gsub(formatted, '<rP0>', race.p0);
|
||||
formatted = string.gsub(formatted, '<rP1>', race.p1);
|
||||
formatted = string.gsub(formatted, '<rP3>', race.p3);
|
||||
|
||||
return formatted
|
||||
end
|
||||
|
||||
local function TransformQuestText(text)
|
||||
return ApplyQuestPlaceholders(text)
|
||||
end
|
||||
local _, addon = ...
|
||||
|
||||
local function ResolveGender(maleVersion, femaleVersion)
|
||||
local gender = UnitSex("player")
|
||||
if gender == 2 then
|
||||
return TransformQuestText(maleVersion)
|
||||
return maleVersion
|
||||
else
|
||||
return femaleVersion == nil and TransformQuestText(maleVersion) or TransformQuestText(femaleVersion)
|
||||
return femaleVersion == nil and maleVersion or femaleVersion
|
||||
end
|
||||
end
|
||||
|
||||
local function GetQuest(id)
|
||||
local quest = CzechQuestsAddon.data.quest[id];
|
||||
if quest then
|
||||
local description = ""
|
||||
local objective = ""
|
||||
if QuestMapDetailsScrollFrame and QuestMapDetailsScrollFrame:IsVisible() then
|
||||
local index = GetQuestLogQuestIndex(id)
|
||||
description, objective = GetQuestLogQuestText(index)
|
||||
else
|
||||
description = GetQuestText("Description")
|
||||
objective = GetQuestText("Objective")
|
||||
end
|
||||
return {
|
||||
title = ResolveGender(quest.titleMale, quest.titleFemale),
|
||||
objective = CzechQuestsAddon:TransformIntoParagraphs(
|
||||
objective, ResolveGender(quest.objectiveMale, quest.objectiveFemale)
|
||||
),
|
||||
description = CzechQuestsAddon:TransformIntoParagraphs(
|
||||
description, ResolveGender(quest.descriptionMale, quest.descriptionFemale)
|
||||
),
|
||||
progress = ResolveGender(quest.progressMale, quest.progressFemale),
|
||||
completion = ResolveGender(quest.completionMale, quest.completionFemale),
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
local function ApplySpeechPlaceholders(text)
|
||||
if text == nil then
|
||||
return text
|
||||
end
|
||||
|
||||
local playerName = UnitName("player")
|
||||
|
||||
local formatted = text;
|
||||
formatted = string.gsub(formatted, '<name>', playerName);
|
||||
formatted = string.gsub(formatted, 'Champions', playerName);
|
||||
formatted = string.gsub(formatted, 'champions', playerName);
|
||||
|
||||
return formatted
|
||||
end
|
||||
|
||||
local function GetSpeech(message)
|
||||
local speech = CzechQuestsAddon.data.speech[message];
|
||||
local text = speech and speech.text or nil
|
||||
return ApplySpeechPlaceholders(text)
|
||||
end
|
||||
addon.API.ResolveGender = ResolveGender
|
||||
|
||||
function CzechQuestsAddon:GetData(key, id)
|
||||
if CzechQuestsAddon.data[key] then
|
||||
if addon.data[key] then
|
||||
if key == "quest" then
|
||||
return GetQuest(id)
|
||||
return addon.API.GetQuest(id)
|
||||
elseif key == "speech" then
|
||||
return GetSpeech(id)
|
||||
elseif CzechQuestsAddon.data[key][id] then
|
||||
return CzechQuestsAddon.data[key][id]
|
||||
return addon.API.GetSpeech(id)
|
||||
elseif addon.data[key][id] then
|
||||
return addon.data[key][id]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
|
|
26
Addon/Code/FontUtils.lua
Normal file
26
Addon/Code/FontUtils.lua
Normal file
|
@ -0,0 +1,26 @@
|
|||
local _, addon = ...
|
||||
|
||||
local FontPath = "Interface\\AddOns\\CzechQuests\\Assets\\Fonts\\"
|
||||
|
||||
local TestFont = UIParent:CreateFontString(nil, "BACKGROUND", "GameFontNormal")
|
||||
TestFont:SetPoint("TOP", UIParent, "BOTTOM", 0, -64);
|
||||
|
||||
local function CreateCzechFont(frame, name, size, flags)
|
||||
local font = frame:CreateFontString(nil, "OVERLAY")
|
||||
font:SetTextColor(0, 0, 0, 1)
|
||||
font:SetJustifyH("LEFT")
|
||||
font:SetWidth(frame:GetWidth())
|
||||
font:SetFont(FontPath ..name, size, flags or "")
|
||||
return font
|
||||
end
|
||||
addon.API.CreateCzechFont = CreateCzechFont
|
||||
|
||||
local function GetFontContainer()
|
||||
local container = Settings.CreateControlTextContainer()
|
||||
container:Add("morpheus_cz.ttf", "Morpheus (cz)")
|
||||
container:Add("frizquadratatt_cz.ttf", "Friz Quadrata TT (cz)")
|
||||
container:Add("quicksand.ttf", "Quicksand")
|
||||
container:Add("caveat.ttf", "Caveat")
|
||||
return container:GetData()
|
||||
end
|
||||
addon.API.GetFontContainer = GetFontContainer
|
152
Addon/Code/Options.lua
Normal file
152
Addon/Code/Options.lua
Normal file
|
@ -0,0 +1,152 @@
|
|||
local _, addon = ...
|
||||
|
||||
local Options = {}
|
||||
addon.Options = Options
|
||||
|
||||
local function RegisterAddOnSettings(name, title)
|
||||
return Settings.RegisterAddOnSetting(
|
||||
Options.category,
|
||||
"CzechQuestsAddon__" .. name,
|
||||
name,
|
||||
CzechQuestsAddon_Store.config,
|
||||
type(CzechQuestsAddon_Store.config[name]),
|
||||
title,
|
||||
CzechQuestsAddon_Store.config[name]
|
||||
)
|
||||
end
|
||||
|
||||
local function RegisterProxySettings(name, title, setter)
|
||||
return Settings.RegisterProxySetting(
|
||||
Options.category,
|
||||
"CzechQuestsAddon__" .. name,
|
||||
type(CzechQuestsAddon_Store.config[name]),
|
||||
title,
|
||||
CzechQuestsAddon_Store.config[name],
|
||||
function()
|
||||
return CzechQuestsAddon_Store.config[name]
|
||||
end,
|
||||
setter
|
||||
)
|
||||
end
|
||||
|
||||
local function CreateCheckbox(name, title)
|
||||
Settings.CreateCheckbox(
|
||||
Options.category,
|
||||
RegisterAddOnSettings(name, title)
|
||||
)
|
||||
end
|
||||
|
||||
local function CreateDropdown(name, title, items, setter)
|
||||
Settings.CreateDropdown(
|
||||
Options.category,
|
||||
RegisterProxySettings(name, title, setter),
|
||||
items
|
||||
)
|
||||
end
|
||||
|
||||
local function CreateSlider(name, title, min, max, step, setter)
|
||||
local options = Settings.CreateSliderOptions(min, max, step)
|
||||
options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right);
|
||||
Settings.CreateSlider(
|
||||
Options.category,
|
||||
RegisterProxySettings(name, title, setter),
|
||||
options
|
||||
)
|
||||
end
|
||||
|
||||
local function CreateButton(title, label, setter)
|
||||
Options.layout:AddInitializer(
|
||||
CreateSettingsButtonInitializer(title, label, setter, nil, title)
|
||||
)
|
||||
end
|
||||
|
||||
local function InitQuests()
|
||||
local function CreateQuestDropdown(name, title, items)
|
||||
CreateDropdown(name, title, items, function (value)
|
||||
CzechQuestsAddon_Store.config[name] = value
|
||||
addon.QuestFrame:UpdateSettings()
|
||||
end)
|
||||
end
|
||||
|
||||
local function CreateQuestSlider(name, title, min, max, step)
|
||||
CreateSlider(name, title, min, max, step, function (value)
|
||||
CzechQuestsAddon_Store.config[name] = value
|
||||
addon.QuestFrame:UpdateSettings()
|
||||
end)
|
||||
end
|
||||
|
||||
local layout = Options.layout
|
||||
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Questy"))
|
||||
|
||||
CreateCheckbox("QUEST_ENABLED", "Zapnout")
|
||||
|
||||
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
|
||||
CreateCheckbox("QUEST_DARK_MODE", "Pouzit tmavy rezim")
|
||||
end
|
||||
|
||||
CreateQuestDropdown("QUEST_HEADER_FONT_NAME", "Pismo nadpisu", addon.API.GetFontContainer)
|
||||
CreateQuestDropdown("QUEST_TEXT_FONT_NAME", "Pismo textu", addon.API.GetFontContainer)
|
||||
|
||||
CreateQuestSlider("QUEST_HEADER_FONT_SIZE", "Velikost nadpisu", 10, 30, 1)
|
||||
CreateQuestSlider("QUEST_TEXT_FONT_SIZE", "Velikost textu", 10, 30, 1)
|
||||
|
||||
CreateSlider("QUEST_TEXTURE_ALPHA", "Pruhlednost pozadi", 10, 100, 10)
|
||||
CreateCheckbox("QUEST_TEXTURE_ALPHA_ONLY_MOVING", "Pruhlednost pouze pri chuzi")
|
||||
end
|
||||
|
||||
local function InitSpeeches()
|
||||
local function CreateSpeechDropdown(name, title, items)
|
||||
CreateDropdown(name, title, items, function (value)
|
||||
CzechQuestsAddon_Store.config[name] = value
|
||||
addon.SpeechFrame:UpdateSettings()
|
||||
end)
|
||||
end
|
||||
|
||||
local function CreateSpeechSlider(name, title, min, max, step)
|
||||
CreateSlider(name, title, min, max, step, function (value)
|
||||
CzechQuestsAddon_Store.config[name] = value
|
||||
addon.SpeechFrame:UpdateSettings()
|
||||
end)
|
||||
end
|
||||
|
||||
local layout = Options.layout
|
||||
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Bubliny"))
|
||||
|
||||
CreateCheckbox("SPEECH_ENABLED", "Zapnout")
|
||||
|
||||
CreateSpeechDropdown("SPEECH_TEXT_FONT_NAME", "Pismo *", addon.API.GetFontContainer)
|
||||
CreateSpeechSlider("SPEECH_TEXT_FONT_SIZE", "Velikost pisma *", 10, 30, 1)
|
||||
|
||||
CreateSpeechSlider("SPEECH_FRAME_WIDTH", "Sirka okna", 200, 1000, 10)
|
||||
|
||||
CreateCheckbox("SPEECH_ORIGINAL_WHEN_MISSING", "Original pokud není preklad ")
|
||||
|
||||
CreateButton('Resetovat pozici okna', "RESET", function()
|
||||
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION = { x = 0, y = 0}
|
||||
addon.SpeechFrame:SetPoint(
|
||||
"TOPLEFT", UIParent, "TOPLEFT",
|
||||
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.x,
|
||||
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.y
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
local function InitOthers()
|
||||
local layout = Options.layout
|
||||
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("Ostatni"))
|
||||
|
||||
CreateCheckbox("DEBUG_MODE", "Zapnout DEBUG")
|
||||
end
|
||||
|
||||
local function InitOptions()
|
||||
local category, layout = Settings.RegisterVerticalLayoutCategory("CzechQuests")
|
||||
Options.category = category
|
||||
Options.layout = layout
|
||||
|
||||
InitQuests()
|
||||
InitSpeeches()
|
||||
InitOthers()
|
||||
|
||||
Settings.RegisterAddOnCategory(category)
|
||||
end
|
||||
addon.API.InitOptions = InitOptions
|
|
@ -1,3 +1,5 @@
|
|||
local _, addon = ...
|
||||
|
||||
local function SplitParagraphs(text)
|
||||
local paragraphs = {}
|
||||
for paragraph in string.gmatch(text, "([^\n]+)") do
|
||||
|
@ -17,20 +19,27 @@ local function SplitSentences(paragraph)
|
|||
return sentences
|
||||
end
|
||||
|
||||
function CzechQuestsAddon:TransformIntoParagraphs(original_text, translation_text)
|
||||
local function ParseParagraphs(original_text, translation_text)
|
||||
if original_text == "" or original_text == nil then
|
||||
return translation_text
|
||||
end
|
||||
|
||||
translation_text = string.gsub(translation_text, "(%d+)%.", function(numberPart)
|
||||
local numberWithDot = numberPart .. "."
|
||||
if string.find(original_text, numberWithDot, 1, true) then
|
||||
return numberWithDot
|
||||
else
|
||||
return numberPart
|
||||
end
|
||||
end)
|
||||
|
||||
local original_paragraphs = SplitParagraphs(original_text)
|
||||
local translation_paragraphs = {}
|
||||
|
||||
local translation_sentences = SplitSentences(translation_text)
|
||||
local counter = 1
|
||||
|
||||
for _, orig_paragraph in ipairs(original_paragraphs) do
|
||||
local orig_sentences = SplitSentences(orig_paragraph)
|
||||
|
||||
local paragraph_sentence_count = #orig_sentences
|
||||
local collected = {}
|
||||
|
||||
|
@ -42,10 +51,11 @@ function CzechQuestsAddon:TransformIntoParagraphs(original_text, translation_tex
|
|||
break
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(translation_paragraphs, table.concat(collected, " "))
|
||||
end
|
||||
|
||||
local final_text = table.concat(translation_paragraphs, "\n")
|
||||
|
||||
return final_text
|
||||
end
|
||||
end
|
||||
addon.API.ParseParagraphs = ParseParagraphs
|
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
|
109
Addon/Code/QuestDataApi.lua
Executable file
109
Addon/Code/QuestDataApi.lua
Executable file
|
@ -0,0 +1,109 @@
|
|||
local _, addon = ...
|
||||
|
||||
local WowQuestTextMethod = {
|
||||
Description = GetQuestText,
|
||||
Objective = GetObjectiveText,
|
||||
};
|
||||
|
||||
local function GetWowQuestText(method)
|
||||
local text = WowQuestTextMethod[method]();
|
||||
if text then
|
||||
return text
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
local function GetQuestLogQuestIndex(questID)
|
||||
local numEntries = C_QuestLog.GetNumQuestLogEntries()
|
||||
for questLogIndex = 1, numEntries do
|
||||
local info = C_QuestLog.GetInfo(questLogIndex)
|
||||
if info and info.questID == questID then
|
||||
return questLogIndex
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
local function FillPlaceholders(text)
|
||||
if text == nil then
|
||||
return text
|
||||
end
|
||||
|
||||
local playerName = UnitName("player")
|
||||
local _, playerClass = UnitClass("player")
|
||||
local _, playerRace = UnitRace("player")
|
||||
|
||||
local class = CzechQuestsAddon:GetData("class", playerClass);
|
||||
local race = CzechQuestsAddon:GetData("race", 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, '<cP0>', class.p0);
|
||||
formatted = string.gsub(formatted, '<cP1>', class.p1);
|
||||
formatted = string.gsub(formatted, '<cP3>', class.m3);
|
||||
|
||||
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);
|
||||
|
||||
formatted = string.gsub(formatted, '<rP0>', race.p0);
|
||||
formatted = string.gsub(formatted, '<rP1>', race.p1);
|
||||
formatted = string.gsub(formatted, '<rP3>', race.p3);
|
||||
|
||||
return formatted
|
||||
end
|
||||
|
||||
local function GetQuestText(maleText, femaleText, original)
|
||||
local translation = addon.API.ResolveGender(maleText, femaleText)
|
||||
local paragraphs = addon.API.ParseParagraphs(original, translation)
|
||||
return FillPlaceholders(paragraphs)
|
||||
end
|
||||
|
||||
local function GetQuest(id)
|
||||
local quest = addon.data.quest[id];
|
||||
if quest then
|
||||
local description = ""
|
||||
local objective = ""
|
||||
|
||||
if QuestMapDetailsScrollFrame and QuestMapDetailsScrollFrame:IsVisible() then
|
||||
local index = GetQuestLogQuestIndex(id)
|
||||
description, objective = GetQuestLogQuestText(index)
|
||||
else
|
||||
description = GetWowQuestText("Description")
|
||||
objective = GetWowQuestText("Objective")
|
||||
end
|
||||
|
||||
return {
|
||||
title = GetQuestText(quest.titleMale, quest.titleFemale),
|
||||
objective = GetQuestText(quest.objectiveMale, quest.objectiveFemale, objective),
|
||||
description = GetQuestText(quest.descriptionMale, quest.descriptionFemale, description),
|
||||
progress = GetQuestText(quest.progressMale, quest.progressFemale),
|
||||
completion = GetQuestText(quest.completionMale, quest.completionFemale),
|
||||
}
|
||||
end
|
||||
end
|
||||
addon.API.GetQuest = GetQuest
|
147
Addon/Code/QuestFrame.lua
Executable file
147
Addon/Code/QuestFrame.lua
Executable file
|
@ -0,0 +1,147 @@
|
|||
local _, addon = ...
|
||||
|
||||
local QuestFrame = CreateFrame("Frame", "CzechQuestsQuestFrame", UIParent, "BackdropTemplate")
|
||||
QuestFrame:Hide()
|
||||
|
||||
addon.QuestFrame = QuestFrame
|
||||
|
||||
function QuestFrame:CreateHeader()
|
||||
local font = addon.API.CreateCzechFont(
|
||||
self,
|
||||
CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_NAME,
|
||||
CzechQuestsAddon_Store.config.QUEST_HEADER_FONT_SIZE
|
||||
)
|
||||
font:SetWidth(self:GetWidth() - 20)
|
||||
return font;
|
||||
end
|
||||
|
||||
function QuestFrame:CreateText()
|
||||
local font = addon.API.CreateCzechFont(
|
||||
self,
|
||||
CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_NAME,
|
||||
CzechQuestsAddon_Store.config.QUEST_TEXT_FONT_SIZE
|
||||
)
|
||||
font:SetWidth(self:GetWidth() - 20)
|
||||
return font;
|
||||
end
|
||||
|
||||
function QuestFrame:Init()
|
||||
-- Default style
|
||||
self:SetSize(300, 200)
|
||||
self:SetBackdrop({ edgeFile = "Interface/Tooltips/UI-Tooltip-Border", edgeSize = 8 })
|
||||
|
||||
-- Background Parchment texture
|
||||
self.Texture = self:CreateTexture(nil, "BACKGROUND", nil, -1);
|
||||
self.Texture:SetAllPoints(true)
|
||||
self.Texture:SetHorizTile(true)
|
||||
|
||||
-- Load settings
|
||||
self:UpdateSettings()
|
||||
end
|
||||
|
||||
function QuestFrame:UpdateSettings()
|
||||
self.Title = self:CreateHeader()
|
||||
self.Text1 = self:CreateText()
|
||||
self.Header = self:CreateHeader()
|
||||
self.Text2 = self:CreateText()
|
||||
|
||||
self:ApplyTheme()
|
||||
|
||||
if not CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA_ONLY_MOVING then
|
||||
self.Texture:SetAlpha(CzechQuestsAddon_Store.config.QUEST_TEXTURE_ALPHA / 100)
|
||||
end
|
||||
end
|
||||
|
||||
function QuestFrame:ResetText()
|
||||
self.Title:SetText("")
|
||||
self.Header:SetText("")
|
||||
self.Text1:SetText("")
|
||||
self.Text2:SetText("")
|
||||
end
|
||||
|
||||
function QuestFrame:SetTextColor(r, g, b, a)
|
||||
self.Title:SetTextColor(r, g, b, a)
|
||||
self.Header:SetTextColor(r, g, b, a)
|
||||
self.Text1:SetTextColor(r, g, b, a)
|
||||
self.Text2:SetTextColor(r, g, b, a)
|
||||
end
|
||||
|
||||
function QuestFrame:ApplyTheme()
|
||||
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
|
||||
self.Texture:SetTexture("Interface/QUESTFRAME/QuestBG");
|
||||
self.Texture:SetTexCoord(0, .58, 0.005, 0.66)
|
||||
self:SetTextColor(0, 0, 0, 1)
|
||||
if not CzechQuestsAddon_Store.config.QUEST_DARK_MODE then
|
||||
self:SetBackdropColor(0, 0, 0, 1)
|
||||
self.Texture:SetColorTexture(0, 0, 0, 1)
|
||||
self:SetTextColor(255, 255, 255, 1)
|
||||
end
|
||||
else
|
||||
self.Texture:SetTexture("Interface/QUESTFRAME/QuestBackgroundParchment");
|
||||
self.Texture:SetTexCoord(0, .01, 0, 0.4)
|
||||
self:SetTextColor(0, 0, 0, 1)
|
||||
local questTextContrast = C_CVar.GetCVar("questTextContrast")
|
||||
if questTextContrast == "1" then -- Brown
|
||||
self.Texture:SetTexCoord(0, .01, .4, .8)
|
||||
elseif questTextContrast == "2" or questTextContrast == "3" then -- Gray
|
||||
self.Texture:SetColorTexture(255, 255, 255, 1)
|
||||
elseif questTextContrast == "4" then -- Black
|
||||
self.Texture:SetColorTexture(0, 0, 0, 1)
|
||||
self:SetTextColor(0, 0, 0, 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function QuestFrame:CalculateHeight()
|
||||
local height = 0;
|
||||
local heights = {
|
||||
self.Title:GetHeight() ,
|
||||
self.Text1:GetHeight(),
|
||||
self.Header:GetHeight(),
|
||||
self.Text2:GetHeight(),
|
||||
10
|
||||
}
|
||||
for _, value in ipairs(heights) do
|
||||
height = height + value + 10
|
||||
end
|
||||
self:SetHeight(height)
|
||||
end
|
||||
|
||||
function QuestFrame:SetData(name, text1, header, text2, parentFrame, yOffset, xOffset)
|
||||
-- Reset previously values
|
||||
self:ResetText()
|
||||
|
||||
-- Set parent
|
||||
self:SetParent(parentFrame)
|
||||
|
||||
-- set text to labels
|
||||
self.Title:SetText(name)
|
||||
self.Text1:SetText(text1)
|
||||
self.Header:SetText(header)
|
||||
self.Text2:SetText(text2)
|
||||
|
||||
-- apply text positions
|
||||
self.Title:SetPoint("TOPLEFT", self, "TOPLEFT", 10, -10)
|
||||
self.Text1:SetPoint("TOPLEFT", self.Title, "BOTTOMLEFT", 0, -5)
|
||||
self.Header:SetPoint("TOPLEFT", self.Text1, "BOTTOMLEFT", 0, -20)
|
||||
self.Text2:SetPoint("TOPLEFT", self.Header, "BOTTOMLEFT", 0, -5)
|
||||
|
||||
-- apply frame position
|
||||
if (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
|
||||
self:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", xOffset, yOffset)
|
||||
else
|
||||
self:SetPoint("TOPLEFT", parentFrame, "TOPRIGHT", xOffset, yOffset)
|
||||
end
|
||||
|
||||
self:Show()
|
||||
|
||||
-- wait for font render before calculate height
|
||||
local height = self.Title:GetStringHeight()
|
||||
if height == 0 then
|
||||
C_Timer.After(0.5, function()
|
||||
self:CalculateHeight()
|
||||
end)
|
||||
else
|
||||
self:CalculateHeight()
|
||||
end
|
||||
end
|
108
Addon/Code/Speech.lua
Executable file
108
Addon/Code/Speech.lua
Executable file
|
@ -0,0 +1,108 @@
|
|||
local _, addon = ...
|
||||
local messages = {}
|
||||
|
||||
local function ReflowMessages()
|
||||
local offsetY = 5
|
||||
for i = #messages, 1, -1 do
|
||||
local Frame = messages[i]
|
||||
Frame:ClearAllPoints()
|
||||
Frame:SetPoint("BOTTOMLEFT", addon.SpeechFrame.ContentFrame, "BOTTOMLEFT", 5, offsetY)
|
||||
Frame:Show()
|
||||
offsetY = offsetY + Frame:GetHeight()
|
||||
end
|
||||
|
||||
if #messages == 0 then
|
||||
addon.SpeechFrame:Hide()
|
||||
end
|
||||
|
||||
-- calculate Content height
|
||||
-- cannot be smaller then SpeechFrame
|
||||
offsetY = offsetY + 5
|
||||
if offsetY < 150 then
|
||||
offsetY = 150
|
||||
end
|
||||
addon.SpeechFrame.ContentFrame:SetHeight(offsetY)
|
||||
|
||||
-- Scroll down
|
||||
addon.SpeechFrame:UpdateScrollChildRect()
|
||||
local maxScroll = addon.SpeechFrame:GetVerticalScrollRange()
|
||||
addon.SpeechFrame:SetVerticalScroll(maxScroll)
|
||||
end
|
||||
|
||||
local function RemoveMessage(frame)
|
||||
for i, fs in ipairs(messages) do
|
||||
if fs == frame then
|
||||
local animation = fs:CreateAnimationGroup()
|
||||
local fadeOut = animation:CreateAnimation("Alpha")
|
||||
fadeOut:SetFromAlpha(1)
|
||||
fadeOut:SetToAlpha(0)
|
||||
fadeOut:SetDuration(1)
|
||||
fadeOut:SetStartDelay(0)
|
||||
animation:SetScript("OnFinished", function()
|
||||
table.remove(messages, i)
|
||||
fs:Hide()
|
||||
ReflowMessages()
|
||||
end)
|
||||
animation:Play()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function AddMessage(sender, message)
|
||||
local text = string.format("|cffffd200%s|r\n%s", sender, message)
|
||||
local MessageFrame = addon.SpeechFrame.ContentFrame:CreateMessage(text)
|
||||
|
||||
-- put into table and rerender while queue
|
||||
table.insert(messages, MessageFrame)
|
||||
ReflowMessages()
|
||||
|
||||
-- hide after timeout
|
||||
C_Timer.After(20, function()
|
||||
RemoveMessage(MessageFrame)
|
||||
end)
|
||||
end
|
||||
|
||||
local function ShowSpeechTranslation(sender, message)
|
||||
local text = CzechQuestsAddon:GetData("speech", message)
|
||||
if text == nil and CzechQuestsAddon_Store.config.SPEECH_ORIGINAL_WHEN_MISSING then
|
||||
text = message
|
||||
end
|
||||
|
||||
if text ~= nil then
|
||||
addon.SpeechFrame:Show()
|
||||
addon.SpeechFrame.ContentFrame:Show()
|
||||
AddMessage(sender, text)
|
||||
end
|
||||
end
|
||||
|
||||
local function InitSpeeches()
|
||||
local frame = addon.SpeechFrame
|
||||
|
||||
-- Register Speech events
|
||||
frame:RegisterEvent("PLAYER_LOGIN")
|
||||
frame:RegisterEvent("CHAT_MSG_MONSTER_SAY")
|
||||
frame:RegisterEvent("CHAT_MSG_MONSTER_YELL")
|
||||
frame:RegisterEvent("CHAT_MSG_MONSTER_EMOTE")
|
||||
frame:RegisterEvent("CHAT_MSG_MONSTER_PARTY")
|
||||
frame:RegisterEvent("CHAT_MSG_MONSTER_WHISPER")
|
||||
|
||||
frame:SetScript("OnEvent", function(self, event, message, sender)
|
||||
if not CzechQuestsAddon_Store.config.SPEECH_ENABLED then
|
||||
return
|
||||
end
|
||||
|
||||
if event == "PLAYER_LOGIN" then
|
||||
frame:Init()
|
||||
end
|
||||
|
||||
if event == "CHAT_MSG_MONSTER_SAY"
|
||||
or event == "CHAT_MSG_MONSTER_YELL"
|
||||
or event == "CHAT_MSG_MONSTER_EMOTE"
|
||||
or event == "CHAT_MSG_MONSTER_PARTY"
|
||||
or event == "CHAT_MSG_MONSTER_WHISPER" then
|
||||
ShowSpeechTranslation(sender, message)
|
||||
end
|
||||
end)
|
||||
end
|
||||
addon.API.InitSpeeches = InitSpeeches
|
23
Addon/Code/SpeechDataApi.lua
Executable file
23
Addon/Code/SpeechDataApi.lua
Executable file
|
@ -0,0 +1,23 @@
|
|||
local _, addon = ...
|
||||
|
||||
local function FillPlaceholders(text)
|
||||
if text == nil then
|
||||
return text
|
||||
end
|
||||
|
||||
local playerName = UnitName("player")
|
||||
|
||||
local formatted = text;
|
||||
formatted = string.gsub(formatted, '<name>', playerName);
|
||||
formatted = string.gsub(formatted, 'Champions', playerName);
|
||||
formatted = string.gsub(formatted, 'champions', playerName);
|
||||
|
||||
return formatted
|
||||
end
|
||||
|
||||
local function GetSpeech(message)
|
||||
local speech = addon.data.speech[message];
|
||||
local text = speech and speech.text or nil
|
||||
return FillPlaceholders(text)
|
||||
end
|
||||
addon.API.GetSpeech = GetSpeech
|
101
Addon/Code/SpeechFrame.lua
Executable file
101
Addon/Code/SpeechFrame.lua
Executable file
|
@ -0,0 +1,101 @@
|
|||
local _, addon = ...
|
||||
|
||||
local SpeechFrame = CreateFrame("ScrollFrame", "CzechQuestsSpeechFrame", UIParent, "UIPanelScrollFrameTemplate")
|
||||
SpeechFrame:Hide()
|
||||
|
||||
local ContentFrame = CreateFrame("Frame", nil, SpeechFrame)
|
||||
ContentFrame:Hide()
|
||||
|
||||
addon.SpeechFrame = SpeechFrame
|
||||
SpeechFrame.ContentFrame = ContentFrame
|
||||
|
||||
function SpeechFrame:Init()
|
||||
local frame = self
|
||||
|
||||
-- Default style
|
||||
self:SetSize(CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH, 150)
|
||||
|
||||
-- Make movable
|
||||
self:SetMovable(true)
|
||||
self:EnableMouse(true)
|
||||
self:RegisterForDrag("LeftButton")
|
||||
|
||||
-- Hide sidebar
|
||||
self.ScrollBar:Hide()
|
||||
|
||||
-- Register drag event
|
||||
self:SetScript("OnDragStart", function()
|
||||
frame:StartMoving()
|
||||
end)
|
||||
self:SetScript("OnDragStop", function(self)
|
||||
frame:StopMovingOrSizing()
|
||||
local finalLeft, finalTop = self:GetLeft(), self:GetTop()
|
||||
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION = {
|
||||
x = finalLeft,
|
||||
y = finalTop
|
||||
}
|
||||
end)
|
||||
|
||||
-- Create ContentFrame
|
||||
ContentFrame:Init()
|
||||
SpeechFrame:SetScrollChild(SpeechFrame.ContentFrame)
|
||||
|
||||
-- Register hover events
|
||||
self:SetScript("OnEnter", function() self.ContentFrame.Texture:SetAlpha(0.8) end)
|
||||
self:SetScript("OnLeave", function() self.ContentFrame.Texture:SetAlpha(0.2) end)
|
||||
|
||||
self:UpdateSettings()
|
||||
end
|
||||
|
||||
function ContentFrame:Init()
|
||||
-- Default style
|
||||
self:SetSize(SpeechFrame:GetWidth(), 1)
|
||||
|
||||
-- Texture for control color and alpha
|
||||
self.Texture = self:CreateTexture(nil, "ARTWORK")
|
||||
self.Texture:SetTexture("Interface\\Buttons\\WHITE8x8")
|
||||
self.Texture:SetVertexColor(0, 0, 0, 0.2)
|
||||
|
||||
-- Set points to edges
|
||||
self.Texture:SetPoint("TOPLEFT", self ,"TOPLEFT", 0, 0)
|
||||
self.Texture:SetPoint("BOTTOMRIGHT", self ,"BOTTOMRIGHT", 0, 0)
|
||||
|
||||
-- Set ContentFrame position
|
||||
self:SetPoint("BOTTOMLEFT", SpeechFrame, "BOTTOMLEFT", 0, 0)
|
||||
end
|
||||
|
||||
function ContentFrame:CreateMessage(message)
|
||||
-- Default style
|
||||
local MessageFrame = CreateFrame("Frame", nil, SpeechFrame.ContentFrame)
|
||||
MessageFrame:SetSize(SpeechFrame.ContentFrame:GetWidth() - 20, 1)
|
||||
|
||||
-- Define Message
|
||||
MessageFrame.Message = addon.API.CreateCzechFont(
|
||||
MessageFrame,
|
||||
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_NAME,
|
||||
CzechQuestsAddon_Store.config.SPEECH_TEXT_FONT_SIZE,
|
||||
"THICK"
|
||||
)
|
||||
MessageFrame.Message:SetTextColor(1, 1, 1)
|
||||
MessageFrame.Message:SetPoint("TOPLEFT", MessageFrame, "TOPLEFT", 5, -5)
|
||||
MessageFrame.Message:SetPoint("BOTTOMRIGHT", MessageFrame, "BOTTOMRIGHT", -5, 5)
|
||||
|
||||
-- Set text and height
|
||||
MessageFrame.Message:SetText(message)
|
||||
MessageFrame:SetHeight(MessageFrame.Message:GetHeight() + 10)
|
||||
|
||||
return MessageFrame
|
||||
end
|
||||
|
||||
function SpeechFrame:UpdateSettings()
|
||||
self:SetWidth(CzechQuestsAddon_Store.config.SPEECH_FRAME_WIDTH)
|
||||
self.ContentFrame:SetWidth(self:GetWidth())
|
||||
|
||||
-- Set position
|
||||
self:ClearAllPoints()
|
||||
self:SetPoint(
|
||||
"TOPLEFT", UIParent, "TOPLEFT",
|
||||
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.x,
|
||||
CzechQuestsAddon_Store.config.SPEECH_FRAME_POSITION.y
|
||||
)
|
||||
end
|
|
@ -1,81 +0,0 @@
|
|||
local messages = {}
|
||||
|
||||
local function ReflowMessages()
|
||||
local offsetY = 5
|
||||
for i = #messages, 1, -1 do
|
||||
local fs = messages[i]
|
||||
fs:ClearAllPoints()
|
||||
fs:SetPoint(
|
||||
"BOTTOMLEFT",
|
||||
CzechQuestsAddon.translationSpeechFrame.content,
|
||||
"BOTTOMLEFT",
|
||||
5,
|
||||
offsetY
|
||||
)
|
||||
fs:Show()
|
||||
offsetY = offsetY + fs:GetHeight()
|
||||
end
|
||||
|
||||
if #messages == 0 then
|
||||
CzechQuestsAddon.translationSpeechFrame:Hide()
|
||||
end
|
||||
|
||||
offsetY = offsetY + 5
|
||||
if offsetY < 150 then
|
||||
offsetY = 150
|
||||
end
|
||||
|
||||
CzechQuestsAddon.translationSpeechFrame.content:SetHeight(offsetY)
|
||||
|
||||
CzechQuestsAddon.translationSpeechFrame:UpdateScrollChildRect()
|
||||
local maxScroll = CzechQuestsAddon.translationSpeechFrame:GetVerticalScrollRange()
|
||||
CzechQuestsAddon.translationSpeechFrame:SetVerticalScroll(maxScroll)
|
||||
|
||||
end
|
||||
|
||||
local function RemoveMessage(frame)
|
||||
for i, fs in ipairs(messages) do
|
||||
if fs == frame then
|
||||
local fadeAnimationGroup = fs:CreateAnimationGroup()
|
||||
local fadeOut = fadeAnimationGroup:CreateAnimation("Alpha")
|
||||
fadeOut:SetFromAlpha(1)
|
||||
fadeOut:SetToAlpha(0)
|
||||
fadeOut:SetDuration(1)
|
||||
fadeOut:SetStartDelay(0)
|
||||
|
||||
fadeAnimationGroup:SetScript("OnFinished", function()
|
||||
table.remove(messages, i)
|
||||
fs:Hide()
|
||||
ReflowMessages()
|
||||
end)
|
||||
|
||||
fadeAnimationGroup:Play()
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function AddMessage(sender, message)
|
||||
local formattedText = string.format("|cffffd200%s|r\n%s", sender, message)
|
||||
local frame = CzechQuestsAddon:CreateTranslationSpeechFrameMessage(formattedText)
|
||||
|
||||
table.insert(messages, frame)
|
||||
ReflowMessages()
|
||||
|
||||
C_Timer.After(20, function()
|
||||
RemoveMessage(frame)
|
||||
end)
|
||||
end
|
||||
|
||||
function CzechQuestsAddon:ShowSpeechTranslation(sender, message)
|
||||
local text = CzechQuestsAddon:GetData("speech", message)
|
||||
if text == nil and CzechQuestsAddon_Store.config.TRANSLATION_SPEECH_FRAME_ORIGINAL_WHEN_MISSING then
|
||||
text = message
|
||||
end
|
||||
|
||||
if text ~= nil then
|
||||
CzechQuestsAddon.translationSpeechFrame:Show()
|
||||
AddMessage(sender, text)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue