Files
pfUI/modules/bubbles.lua
T
Brues caf7112651 Scan chat bubbles once per frame with DirtiableMixin
Each chat message queued its own scan for the next frame, so a busy frame scanned the same bubbles several times. MarkDirty runs one scan for all of that frame's messages.
2026-10-31 14:28:01 -05:00

65 lines
2.4 KiB
Lua

pfUI:RegisterModule("bubbles", function ()
local alpha = tonumber(C.chat.bubbles.alpha)
pfUI.bubbles = Mixin(CreateFrame("Frame", "pfChatBubbles", UIParent), DirtiableMixin)
pfUI.bubbles:RegisterEvent("CHAT_MSG_SAY")
pfUI.bubbles:RegisterEvent("CHAT_MSG_YELL")
pfUI.bubbles:RegisterEvent("CHAT_MSG_PARTY")
pfUI.bubbles:RegisterEvent("CHAT_MSG_PARTY_LEADER")
pfUI.bubbles:RegisterEvent("CHAT_MSG_MONSTER_SAY")
pfUI.bubbles:RegisterEvent("CHAT_MSG_MONSTER_YELL")
pfUI.bubbles:RegisterEvent("CHAT_MSG_MONSTER_PARTY")
function pfUI.bubbles:ProcessBubble(f)
f.text:Hide()
f.text:SetFont(pfUI.font_default, tonumber(C.global.font_size) * UIParent:GetScale(), "OUTLINE")
local r,g,b,a = f.text:GetTextColor()
f.frame.text:SetText(f.text:GetText())
f.frame.text:SetTextColor(r,g,b,a)
local border_alpha = C.chat.bubbles.borders == "1" and a or 0
f.frame.backdrop:SetBackdropBorderColor(r,g,b,border_alpha)
end
function pfUI.bubbles:ScanBubbles()
for _, f in ipairs(C_ChatBubbles.GetAllChatBubbles()) do
if not f.frame then
local textures = {f:GetRegions()}
for _, object in pairs(textures) do
if object:GetObjectType() == "Texture" then
object:SetTexture('')
elseif object:GetObjectType() == 'FontString' then
f.text = object
end
end
f.frame = CreateFrame("Frame", nil, f)
f.frame:SetScale(UIParent:GetScale())
f.frame:SetAllPoints(f)
f.frame.text = f.frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.frame.text:SetFont(pfUI.font_default, C.global.font_size, "OUTLINE")
f.frame.text:SetJustifyH("CENTER")
f.frame.text:SetJustifyV("CENTER")
f.frame.text:SetAllPoints(f.frame)
CreateBackdrop(f.frame, nil, nil, alpha)
CreateBackdropShadow(f.frame)
f.frame.backdrop:SetPoint("TOPLEFT", f, "TOPLEFT", -10, -10)
f.frame.backdrop:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", 10, 10)
pfUI.bubbles:ProcessBubble(f)
f:SetScript("OnShow", function()
pfUI.bubbles:ProcessBubble(this)
end)
end
end
end
-- Bubble frames are attached to WorldFrame after the chat event fires, so
-- the scan waits a frame, and runs once for all of that frame's messages.
pfUI.bubbles:SetDirtyMethod(pfUI.bubbles.ScanBubbles)
pfUI.bubbles:SetScript("OnEvent", pfUI.bubbles.MarkDirty)
end)