Files
pfUI/modules/chatcopy.lua
T
Brues 796f20eadf Show chat copy and the share box in ClassicAPI's scrolling edit box
pfUIScrollingEditBoxTemplate (api/ui-widgets.xml) is ScrollingEditBoxTemplate
with pfUIScrollBarTemplate beside the text. Its mixin's SetFont gives the
box a font object of its own, since the edit box sets its font by object on
every SetText and pfUI fonts are paths. ui-widgets.lua now loads before the
XML, which needs the mixin.

The share box no longer recomputes its scroll child on every text change.

Chat copy reads each chat frame's messages with ClassicAPI's
GetMessageInfo when it opens, so the AddMessage hook, its 100-line copy of
the history and the skip of combat frames are gone. It shows every line
the frame keeps, lines from before login included. It puts the caret at
the end to scroll to the newest line instead of three OnUpdate passes, and
Escape now leaves copy mode on every chat frame.
2026-10-30 00:38:54 -05:00

97 lines
2.9 KiB
Lua

pfUI:RegisterModule("chatcopy", function ()
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function()
if not pfUI.chat then return end
local button = CreateFrame("Button", "pfChatCopyButton", pfUI.chat.left.panelTop)
button:SetPoint("TOPRIGHT", 0, 0)
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:SetWidth(16)
button:SetHeight(16)
button:SetAlpha(.25)
button.icon = button:CreateTexture(nil,"BACKGROUND")
button.icon:SetTexture("Interface\\Buttons\\UI-GuildButton-PublicNote-Disabled")
button.icon:SetAllPoints()
-- show or hide the copy box of every chat frame
local function SetCopyMode(state)
button.state = state
for i=1, _G.NUM_CHAT_WINDOWS do
local scroll = _G["ChatFrame"..i].scroll
if scroll then
scroll:SetShown(state)
end
end
if state then
button.icon:SetTexture("Interface\\Buttons\\UI-GuildButton-PublicNote-Up")
else
button.icon:SetTexture("Interface\\Buttons\\UI-GuildButton-PublicNote-Disabled")
end
end
button:SetScript("OnClick", function()
if arg1 == "LeftButton" then
SetCopyMode(not this.state)
elseif arg1 == "RightButton" then
if ChatMenu:IsShown() then
ChatMenu:Hide()
else
ChatMenu:Show()
ChatMenu:ClearAllPoints()
ChatMenu:SetPoint("BOTTOMLEFT", this, "TOPRIGHT", 0, 0)
end
end
end)
button:SetScript("OnEnter", function()
this:SetAlpha(1)
end)
button:SetScript("OnLeave", function()
this:SetAlpha(.4)
end)
for i=1, _G.NUM_CHAT_WINDOWS do
local frame = _G["ChatFrame"..i]
-- the chat frame's messages in an edit box to copy from
local scroll = CreateFrame("Frame", "pfChatCopy" .. i, frame, "pfUIScrollingEditBoxTemplate")
scroll:SetAllPoints(frame)
scroll.tex = scroll:CreateTexture(nil, "BACKGROUND")
scroll.tex:SetTexture(0,0,0,.95)
scroll.tex:SetPoint("TOPLEFT", -3, 3)
scroll.tex:SetPoint("BOTTOMRIGHT", 3, -3)
scroll:Hide()
scroll:RegisterCallback("OnEscapePressed", function()
SetCopyMode(false)
end, scroll)
scroll:HookScript("OnShow", function()
-- each line in its own color, which also replaces the |r resets inside it
local lines = {}
for index=1, frame:GetNumMessages() do
local text, r, g, b = frame:GetMessageInfo(index)
local color = rgbhex(r, g, b)
table.insert(lines, color .. text:gsub("|r", color))
end
local text = table.concat(lines, "\n")
scroll:SetFont(frame:GetFont())
scroll:SetText(text)
-- the cursor at the end scrolls the box to the newest line
scroll:SetFocus()
scroll:SetCursorPosition(#text)
end)
frame.scroll = scroll
end
this:UnregisterAllEvents()
end)
end)