recentchat: improvements
This commit is contained in:
+102
-314
@@ -13228,338 +13228,126 @@
|
|||||||
-- Recent chat window
|
-- Recent chat window
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
-- Replace your old RecentChatWindow block with this:
|
||||||
if LeaPlusLC["RecentChatWindow"] == "On" and not LeaLockList["RecentChatWindow"] then
|
if LeaPlusLC["RecentChatWindow"] == "On" and not LeaLockList["RecentChatWindow"] then
|
||||||
|
|
||||||
-- Create recent chat frame
|
-- initialize only once
|
||||||
local editFrame = CreateFrame("ScrollFrame", "LeatrixEditFrame", UIParent, "Leatrix_InputScrollFrameTemplate")
|
if not LeaPlusLC._RecentChatInit then
|
||||||
|
LeaPlusLC._RecentChatInit = true
|
||||||
|
|
||||||
-- Set frame parameters
|
-- 1) Main frame (keeps Leatrix look)
|
||||||
editFrame:ClearAllPoints()
|
local frame = CreateFrame("Frame", "LeaPlusRecentChatFrame", UIParent)
|
||||||
editFrame:SetPoint("BOTTOM", 0, 130)
|
frame:Hide()
|
||||||
editFrame:SetSize(600, LeaPlusLC["RecentChatSize"])
|
frame:SetSize(600, LeaPlusLC["RecentChatSize"])
|
||||||
editFrame:SetFrameStrata("HIGH")
|
frame:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 130)
|
||||||
editFrame:SetToplevel(true)
|
frame:SetFrameStrata("DIALOG")
|
||||||
editFrame:Hide()
|
frame:SetBackdrop({
|
||||||
editFrame.CharCount:Hide()
|
bgFile = "Interface\\BUTTONS\\WHITE8X8",
|
||||||
editFrame:SetHitRectInsets(10, 10, 10, 10)
|
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
||||||
|
tile = true, tileSize = 16,
|
||||||
|
edgeSize = 16, insets = { left=4, right=4, top=4, bottom=4 },
|
||||||
|
})
|
||||||
|
frame:SetBackdropColor(0, 0, 0, 0.6)
|
||||||
|
|
||||||
-- Set solid white color for background instead of using 8x8 texture
|
-- 2) Scroll frame using stock template
|
||||||
editFrame:SetBackdrop({
|
local scroll = CreateFrame("ScrollFrame", "LeaPlusRecentChatScroll", frame, "UIPanelScrollFrameTemplate")
|
||||||
bgFile = "Interface\\BUTTONS\\WHITE8X8", -- use 8x8 texture
|
scroll:SetAllPoints(frame)
|
||||||
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
local sb = scroll.ScrollBar
|
||||||
tile = true,
|
sb:ClearAllPoints()
|
||||||
tileEdge = true,
|
sb:SetPoint("TOPLEFT", scroll, "TOPRIGHT", 3, -16)
|
||||||
tileSize = 16,
|
sb:SetPoint("BOTTOMLEFT", scroll, "BOTTOMRIGHT", 3, 16)
|
||||||
edgeSize = 16,
|
|
||||||
insets = { left = 4, right = 4, top = 4, bottom = 4 }
|
|
||||||
})
|
|
||||||
editFrame:SetBackdropColor(0.00, 0.00, 0.0, 0.6) -- set transparency
|
|
||||||
|
|
||||||
|
-- 3) True multi-line EditBox child (parented to scroll)
|
||||||
|
local edit = CreateFrame("EditBox", "LeaPlusRecentChatEditBox", scroll)
|
||||||
|
edit:SetMultiLine(true)
|
||||||
|
edit:SetFontObject(ChatFontNormal)
|
||||||
|
edit:SetMaxLetters(99999)
|
||||||
|
edit:SetAutoFocus(false)
|
||||||
|
edit:SetWidth(scroll:GetWidth())
|
||||||
|
edit:SetPoint("TOPLEFT", scroll, "TOPLEFT", 0, 0)
|
||||||
|
edit:SetPoint("BOTTOMRIGHT", scroll, "BOTTOMRIGHT", 0, 0)
|
||||||
|
scroll:SetScrollChild(edit)
|
||||||
|
|
||||||
|
-- 4) Auto-scroll to bottom on new text
|
||||||
|
edit:SetScript("OnTextChanged", function(self, userInput)
|
||||||
|
if not userInput then
|
||||||
|
scroll:SetVerticalScroll(scroll:GetVerticalScrollRange())
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Create title bar
|
-- 5) Close on Escape
|
||||||
local titleFrame = CreateFrame("ScrollFrame", "LeatrixTitleFrame", editFrame, "Leatrix_InputScrollFrameTemplate")
|
edit:SetScript("OnEscapePressed", function() frame:Hide() end)
|
||||||
if titleFrame.EditBox then titleFrame.EditBox:Disable() end
|
|
||||||
if titleFrame.CharCount then titleFrame.CharCount:Hide() end
|
|
||||||
titleFrame:ClearAllPoints()
|
|
||||||
titleFrame:SetPoint("TOP", 0, 40)
|
|
||||||
titleFrame:SetSize(600, 36)
|
|
||||||
titleFrame:SetFrameStrata("MEDIUM")
|
|
||||||
titleFrame:SetToplevel(true)
|
|
||||||
titleFrame:SetHitRectInsets(-6, -6, -6, -6)
|
|
||||||
|
|
||||||
-- Set background texture for titleFrame
|
-- 6) Mouse-wheel: Shift=top/bottom, Alt=page, otherwise small step
|
||||||
titleFrame:SetBackdrop({
|
scroll:EnableMouseWheel(true)
|
||||||
bgFile = "Interface\\BUTTONS\\WHITE8X8", -- use 8x8 texture
|
scroll:SetScript("OnMouseWheel", function(self, delta)
|
||||||
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
|
local curr = self:GetVerticalScroll()
|
||||||
tile = true,
|
local max = self:GetVerticalScrollRange()
|
||||||
tileEdge = true,
|
local h = self:GetHeight()
|
||||||
tileSize = 16,
|
local step = 20
|
||||||
edgeSize = 16,
|
if delta > 0 then
|
||||||
insets = { left = 4, right = 4, top = 4, bottom = 4 }
|
if IsShiftKeyDown() then
|
||||||
})
|
curr = 0
|
||||||
titleFrame:SetBackdropColor(0.00, 0.00, 0.0, 0.6) -- set transparency
|
elseif IsAltKeyDown() then
|
||||||
|
curr = curr - h
|
||||||
|
else
|
||||||
|
curr = curr - step
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if IsShiftKeyDown() then
|
||||||
|
curr = max
|
||||||
|
elseif IsAltKeyDown() then
|
||||||
|
curr = curr + h
|
||||||
|
else
|
||||||
|
curr = curr + step
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if curr < 0 then curr = 0 elseif curr > max then curr = max end
|
||||||
|
self:SetVerticalScroll(curr)
|
||||||
|
end)
|
||||||
|
|
||||||
-- Add message count
|
-- 7) Helper to gather all lines from a ChatFrame
|
||||||
titleFrame.m = titleFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
|
local function GatherLines(chatFrame)
|
||||||
titleFrame.m:SetPoint("LEFT", 9, 0)
|
local t = {}
|
||||||
titleFrame.m:SetText(L["Messages"] .. ": 0")
|
local n = 0
|
||||||
titleFrame.m:SetFont(titleFrame.m:GetFont(), 16, nil)
|
for i = 1, chatFrame:GetNumMessages() do
|
||||||
|
local msg = select(1, chatFrame:GetMessageInfo(i))
|
||||||
-- Add right-click to close message
|
if msg then
|
||||||
titleFrame.x = titleFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
|
n = n + 1
|
||||||
titleFrame.x:SetPoint("RIGHT", -9, 0)
|
t[n] = msg
|
||||||
titleFrame.x:SetText(L["Drag to size"] .. " | " .. L["Right-click to close"])
|
end
|
||||||
titleFrame.x:SetFont(titleFrame.x:GetFont(), 16, nil)
|
end
|
||||||
titleFrame.x:SetWidth(600 - titleFrame.m:GetStringWidth() - 30)
|
return t, n
|
||||||
titleFrame.x:SetWordWrap(false)
|
|
||||||
titleFrame.x:SetJustifyH("RIGHT")
|
|
||||||
|
|
||||||
|
|
||||||
-- Drag to resize
|
|
||||||
editFrame:SetResizable(true)
|
|
||||||
editFrame:SetMinResize(600, 50)
|
|
||||||
editFrame:SetMaxResize(600, 680)
|
|
||||||
|
|
||||||
titleFrame:HookScript("OnMouseDown", function(self, btn)
|
|
||||||
if btn == "LeftButton" then
|
|
||||||
editFrame:StartSizing("TOP")
|
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
titleFrame:HookScript("OnMouseUp", function(self, btn)
|
|
||||||
if btn == "LeftButton" then
|
|
||||||
editFrame:StopMovingOrSizing()
|
|
||||||
LeaPlusLC["RecentChatSize"] = editFrame:GetHeight()
|
|
||||||
elseif btn == "MiddleButton" then
|
|
||||||
-- Reset frame size
|
|
||||||
LeaPlusLC["RecentChatSize"] = 170
|
|
||||||
editFrame:SetSize(600, LeaPlusLC["RecentChatSize"])
|
|
||||||
editFrame:ClearAllPoints()
|
|
||||||
editFrame:SetPoint("BOTTOM", 0, 130)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Create editbox
|
-- 8) Ctrl+Left-click on any ChatFrameXTab toggles & fills the window
|
||||||
local editBox = editFrame.EditBox
|
for i = 1, NUM_CHAT_WINDOWS do
|
||||||
editBox:SetAltArrowKeyMode(false)
|
local tab = _G["ChatFrame"..i.."Tab"]
|
||||||
editBox:SetTextInsets(10, 10, 10, 10)
|
if tab then
|
||||||
editBox:SetWidth(editFrame:GetWidth() - 50)
|
tab:HookScript("OnMouseUp", function(self, btn)
|
||||||
-- editBox:SetSecurityDisablePaste()
|
if btn == "LeftButton" and IsControlKeyDown() then
|
||||||
editBox:SetMaxLetters(0)
|
if frame:IsShown() then
|
||||||
|
frame:Hide()
|
||||||
-- Manage focus
|
else
|
||||||
editBox:HookScript("OnEditFocusLost", function()
|
local chat = _G["ChatFrame"..i]
|
||||||
if MouseIsOver(titleFrame) and IsMouseButtonDown("LeftButton") then
|
local lines, count = GatherLines(chat)
|
||||||
editBox:SetFocus()
|
edit:SetText(table.concat(lines, "\n", 1, count))
|
||||||
end
|
scroll:SetVerticalScroll(scroll:GetVerticalScrollRange())
|
||||||
end)
|
frame:Show()
|
||||||
|
|
||||||
-- Create custom scroll frame
|
|
||||||
local scrollFrame = CreateFrame("ScrollFrame", "LeatrixChatScroll", editFrame)
|
|
||||||
scrollFrame:SetPoint("TOPLEFT", editFrame, 26, -36)
|
|
||||||
scrollFrame:SetPoint("BOTTOMRIGHT", editFrame, "BOTTOMRIGHT", -34, 8)
|
|
||||||
scrollFrame:EnableMouseWheel(true)
|
|
||||||
|
|
||||||
-- Create CharCount font string to avoid lua error for it not existing on WoW Sirus
|
|
||||||
scrollFrame.CharCount = scrollFrame:CreateFontString(nil, "OVERLAY", "GameFontDisableLarge")
|
|
||||||
scrollFrame.CharCount:Hide()
|
|
||||||
|
|
||||||
|
|
||||||
-- Set the existing edit box as the scroll child
|
|
||||||
scrollFrame:SetScrollChild(editBox)
|
|
||||||
|
|
||||||
-- Create custom scrollbar
|
|
||||||
local scrollbar = CreateFrame("Slider", nil, editFrame, "UIPanelScrollBarTemplate")
|
|
||||||
scrollbar:SetPoint("TOPRIGHT", editFrame, "TOPRIGHT", -14, -36)
|
|
||||||
scrollbar:SetPoint("BOTTOMRIGHT", editFrame, "BOTTOMRIGHT", -14, 26)
|
|
||||||
scrollbar:SetMinMaxValues(1, 6000) -- Adjust the min and max values as needed
|
|
||||||
scrollbar:SetValueStep(1)
|
|
||||||
scrollbar:SetValue(1)
|
|
||||||
scrollbar:SetWidth(16)
|
|
||||||
scrollbar:SetScript("OnValueChanged", function(self, value)
|
|
||||||
scrollFrame:SetVerticalScroll(value)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Update scrollbar when scroll frame is scrolled
|
|
||||||
scrollFrame:SetScript("OnVerticalScroll", function(self, offset)
|
|
||||||
scrollbar:SetValue(offset)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Update scroll frame when scrollbar is moved
|
|
||||||
scrollbar:SetScript("OnMouseUp", function(self)
|
|
||||||
local value = scrollbar:GetValue()
|
|
||||||
scrollFrame:SetVerticalScroll(value)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Enable mousewheel scrolling within the scroll frame
|
|
||||||
scrollFrame:SetScript("OnMouseWheel", function(self, delta)
|
|
||||||
local currentValue = scrollbar:GetValue()
|
|
||||||
scrollbar:SetValue(currentValue - delta * 30)
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
-- Define a boolean variable to keep track of the editFrame visibility
|
|
||||||
local isNormWindowShown = false;
|
|
||||||
local isTempWindowShown = false;
|
|
||||||
|
|
||||||
|
|
||||||
-- Close frame with right-click of editframe or editbox
|
|
||||||
local function CloseRecentChatWindow()
|
|
||||||
editBox:SetText("")
|
|
||||||
editBox:ClearFocus()
|
|
||||||
editFrame:Hide()
|
|
||||||
end
|
|
||||||
|
|
||||||
editFrame:SetScript("OnMouseDown", function(self, btn)
|
|
||||||
if btn == "RightButton" then
|
|
||||||
CloseRecentChatWindow()
|
|
||||||
isNormWindowShown = false;
|
|
||||||
isTempWindowShown = false;
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
editBox:SetScript("OnMouseDown", function(self, btn)
|
|
||||||
if btn == "RightButton" then
|
|
||||||
CloseRecentChatWindow()
|
|
||||||
isNormWindowShown = false;
|
|
||||||
isTempWindowShown = false;
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
titleFrame:HookScript("OnMouseDown", function(self, btn)
|
|
||||||
if btn == "RightButton" then
|
|
||||||
CloseRecentChatWindow()
|
|
||||||
isNormWindowShown = false;
|
|
||||||
isTempWindowShown = false;
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Disable text changes while still allowing editing controls to work
|
|
||||||
editBox:EnableKeyboard(true)
|
|
||||||
editBox:SetScript("OnKeyDown", function()
|
|
||||||
end)
|
|
||||||
|
|
||||||
--- Clear highlighted text if escape key is pressed
|
|
||||||
editBox:HookScript("OnEscapePressed", function()
|
|
||||||
CloseRecentChatWindow()
|
|
||||||
isNormWindowShown = false;
|
|
||||||
isTempWindowShown = false;
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
-- Clear highlighted text and clear focus if enter key is pressed
|
|
||||||
editBox:SetScript("OnEnterPressed", function()
|
|
||||||
editBox:HighlightText(0, 0)
|
|
||||||
editBox:ClearFocus()
|
|
||||||
end)
|
|
||||||
|
|
||||||
----===== Hide ScrollBar if window too small. =====--
|
|
||||||
--local function HideScrollBar()
|
|
||||||
-- if editFrame:GetHeight() < 80 then
|
|
||||||
-- scroll:Hide()
|
|
||||||
-- else
|
|
||||||
-- scroll:Show()
|
|
||||||
-- end
|
|
||||||
--end
|
|
||||||
--
|
|
||||||
--editFrame:HookScript("OnSizeChanged", HideScrollBar)
|
|
||||||
--
|
|
||||||
--HideScrollBar()
|
|
||||||
--
|
|
||||||
--editFrame:SetScript("OnUpdate", function(self, elapsed)
|
|
||||||
-- HideScrollBar()
|
|
||||||
--end)
|
|
||||||
|
|
||||||
-- local titleBox = titleFrame.EditBox
|
|
||||||
-- titleBox:Hide()
|
|
||||||
-- titleBox:Disable(true)
|
|
||||||
|
|
||||||
-- Populate recent chat frame with chat messages
|
|
||||||
local function ShowChatbox(chtfrm)
|
|
||||||
editBox:SetText("")
|
|
||||||
local NumMsg = chtfrm:GetNumMessages()
|
|
||||||
if NumMsg == 0 then return end
|
|
||||||
scrollbar:SetMinMaxValues(1, 10 * NumMsg) -- Adjust the min and max values as needed
|
|
||||||
|
|
||||||
local StartMsg = 1
|
|
||||||
if NumMsg > 128 then
|
|
||||||
StartMsg = NumMsg - 127
|
|
||||||
end
|
|
||||||
local totalMsgCount = 0
|
|
||||||
for iMsg = StartMsg, NumMsg do
|
|
||||||
local chatMessage, r, g, b, chatTypeID = chtfrm:GetMessageInfo(iMsg)
|
|
||||||
if chatMessage then
|
|
||||||
|
|
||||||
-- Handle Battle.net messages
|
|
||||||
if string.match(chatMessage, "k:(%d+):(%d+):BN_WHISPER:")
|
|
||||||
or string.match(chatMessage, "k:(%d+):(%d+):BN_INLINE_TOAST_ALERT:")
|
|
||||||
or string.match(chatMessage, "k:(%d+):(%d+):BN_INLINE_TOAST_BROADCAST:")
|
|
||||||
then
|
|
||||||
local ctype
|
|
||||||
if string.match(chatMessage, "k:(%d+):(%d+):BN_WHISPER:") then
|
|
||||||
ctype = "BN_WHISPER"
|
|
||||||
elseif string.match(chatMessage, "k:(%d+):(%d+):BN_INLINE_TOAST_ALERT:") then
|
|
||||||
ctype = "BN_INLINE_TOAST_ALERT"
|
|
||||||
elseif string.match(chatMessage, "k:(%d+):(%d+):BN_INLINE_TOAST_BROADCAST:") then
|
|
||||||
ctype = "BN_INLINE_TOAST_BROADCAST"
|
|
||||||
end
|
|
||||||
local id = tonumber(string.match(chatMessage, "k:(%d+):%d+:" .. ctype .. ":"))
|
|
||||||
local totalBNFriends = BNGetNumFriends()
|
|
||||||
for friendIndex = 1, totalBNFriends do
|
|
||||||
local bnetAccountID, void, battleTag = BNGetFriendInfo(friendIndex)
|
|
||||||
if id == bnetAccountID then
|
|
||||||
battleTag = strsplit("#", battleTag)
|
|
||||||
chatMessage = chatMessage:gsub("(|HBNplayer%S-|k)(%d-)(:%S-" .. ctype .. "%S-|h)%[(%S-)%](|?h?)(:?)", "[" .. battleTag .. "]:")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
|
|
||||||
-- Handle colors
|
|
||||||
-- if r and g and b then
|
|
||||||
-- -- local colorCode = RGBToColorCode(r, g, b)
|
|
||||||
-- chatMessage = colorCode .. chatMessage
|
|
||||||
-- end
|
|
||||||
|
|
||||||
chatMessage = gsub(chatMessage, "|T.-|t", "") -- Remove textures
|
|
||||||
chatMessage = gsub(chatMessage, "|A.-|a", "") -- Remove atlases
|
|
||||||
editBox:Insert(chatMessage .. "|r|n")
|
|
||||||
|
|
||||||
end
|
end
|
||||||
totalMsgCount = totalMsgCount + 1
|
|
||||||
end
|
end
|
||||||
titleFrame.m:SetText(L["Messages"] .. ": " .. totalMsgCount)
|
|
||||||
editFrame:SetVerticalScroll(0)
|
-- store references if needed elsewhere
|
||||||
-- LibCompat.After(0.1, function() editFrame.ScrollBar.ScrollDownButton:Click() end)
|
LeaPlusLC.RecentChatFrame = frame
|
||||||
editFrame:Show()
|
LeaPlusLC.RecentChatScroll = scroll
|
||||||
editBox:ClearFocus()
|
LeaPlusLC.RecentChatEdit = edit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Hook normal chat frame tab clicks
|
|
||||||
for i = 1, 50 do
|
|
||||||
if _G["ChatFrame" .. i] then
|
|
||||||
_G["ChatFrame" .. i .. "Tab"]:HookScript("OnClick", function()
|
|
||||||
if IsControlKeyDown() then
|
|
||||||
editBox:SetFont(_G["ChatFrame" .. i]:GetFont())
|
|
||||||
ShowChatbox(_G["ChatFrame" .. i])
|
|
||||||
|
|
||||||
-- toggle editFrame visibility based on the current state
|
|
||||||
if isNormWindowShown then
|
|
||||||
editFrame:Hide()
|
|
||||||
isNormWindowShown = false
|
|
||||||
else
|
|
||||||
editFrame:Show()
|
|
||||||
isNormWindowShown = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Hook temporary chat frame tab clicks
|
|
||||||
hooksecurefunc("FCF_OpenTemporaryWindow", function()
|
|
||||||
local cf = FCF_GetCurrentChatFrame():GetName() or nil
|
|
||||||
if cf then
|
|
||||||
_G[cf .. "Tab"]:HookScript("OnClick", function()
|
|
||||||
if IsControlKeyDown() then
|
|
||||||
editBox:SetFont(_G[cf]:GetFont())
|
|
||||||
ShowChatbox(_G[cf])
|
|
||||||
|
|
||||||
-- toggle editFrame visibility based on the current state
|
|
||||||
if isTempWindowShown then
|
|
||||||
editFrame:Hide()
|
|
||||||
isTempWindowShown = false
|
|
||||||
else
|
|
||||||
editFrame:Show()
|
|
||||||
isTempWindowShown = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
-- Show cooldowns
|
-- Show cooldowns
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user