addon/Addon/Code/Speeches.lua

81 lines
No EOL
2.2 KiB
Lua
Executable file

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