修改优化等

This commit is contained in:
rucky
2026-03-18 02:01:36 +08:00
parent 2a55dd6dad
commit 923a1f9ce2
15 changed files with 1578 additions and 371 deletions

167
Chat.lua
View File

@@ -74,8 +74,8 @@ local DEFAULT_FILTERS = {
raid = true,
whisper = true,
system = true,
loot = false,
money = false,
loot = true,
money = true,
}
local AUTO_TRANSLATE_TARGET_LANG = "zh"
@@ -737,6 +737,9 @@ local function GetChannelNameFromChatLine(text)
local _, _, label = string.find(text, "|Hchannel:[^|]+|h%[([^%]]+)%]|h")
if not label then
if string.byte(text, 1) ~= 124 and string.byte(text, 1) ~= 91 then
return nil
end
local raw = string.gsub(text, "|c%x%x%x%x%x%x%x%x", "")
raw = string.gsub(raw, "|r", "")
raw = string.gsub(raw, "^%s+", "")
@@ -1296,7 +1299,7 @@ end
local function BuildDefaultTab(id, name)
return {
id = id,
name = name or ("Tab" .. tostring(id)),
name = name or ("标签" .. tostring(id)),
filters = CopyTable(DEFAULT_FILTERS),
channelFilters = {},
translateFilters = BuildDefaultTranslateFilters(),
@@ -1340,11 +1343,11 @@ local function SanitizeTab(tab, fallbackId, fallbackName)
if type(tab.kind) ~= "string" then tab.kind = nil end
if type(tab.name) ~= "string" or tab.name == "" then
tab.name = fallbackName or ("Tab" .. tostring(tab.id))
tab.name = fallbackName or ("标签" .. tostring(tab.id))
else
tab.name = Trim(tab.name)
if tab.name == "" then
tab.name = fallbackName or ("Tab" .. tostring(tab.id))
tab.name = fallbackName or ("标签" .. tostring(tab.id))
end
end
@@ -1570,7 +1573,7 @@ local function EnsureDB()
local maxId = 0
for i = 1, table.getn(db.tabs) do
db.tabs[i] = SanitizeTab(db.tabs[i], i, "Tab" .. tostring(i))
db.tabs[i] = SanitizeTab(db.tabs[i], i, "标签" .. tostring(i))
if IsCombatTab(db.tabs[i]) then
db.tabs[i].kind = "combat"
end
@@ -1670,6 +1673,26 @@ local function FocusPopupEdit(popup)
if eb.HighlightText then eb:HighlightText() end
end
local function SkinPopupEditBox(popup)
local eb = GetPopupEditBox(popup)
if not eb or eb._sfSkinned then return end
eb._sfSkinned = true
local regions = { eb:GetRegions() }
for _, r in ipairs(regions) do
if r and r:GetObjectType() == "Texture" then
r:SetAlpha(0)
end
end
eb:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
})
eb:SetBackdropColor(0.08, 0.06, 0.1, 0.95)
eb:SetBackdropBorderColor(0.5, 0.4, 0.55, 0.8)
end
local function ResolvePopupFrame(whichKey, dialog)
if dialog and dialog.GetParent then
local parent = dialog:GetParent()
@@ -1740,6 +1763,7 @@ local function EnsurePopupDialogs()
OnShow = function(dialog)
local popup = ResolvePopupFrame("SFRAMES_CHAT_NEW_TAB", dialog)
if not popup then return end
SkinPopupEditBox(popup)
local suggested = "Tab"
if SFrames and SFrames.Chat and SFrames.Chat.GetNextTabName then
suggested = SFrames.Chat:GetNextTabName()
@@ -1781,6 +1805,7 @@ local function EnsurePopupDialogs()
OnShow = function(dialog, data)
local popup = ResolvePopupFrame("SFRAMES_CHAT_RENAME_TAB", dialog)
if not popup then return end
SkinPopupEditBox(popup)
local idx = tonumber(data or (popup and popup.data) or (SFrames and SFrames.Chat and SFrames.Chat.pendingRenameIndex))
local name = ""
if SFrames and SFrames.Chat then
@@ -1895,7 +1920,7 @@ end
function SFrames.Chat:GetNextTabName()
local db = EnsureDB()
local id = db.nextTabId or (table.getn(db.tabs) + 1)
return "Tab" .. tostring(id)
return "标签" .. tostring(id)
end
function SFrames.Chat:IsTabProtected(index)
@@ -2275,7 +2300,7 @@ function SFrames.Chat:ResetPosition()
if not SFramesDB.Positions then SFramesDB.Positions = {} end
SFramesDB.Positions["ChatFrame"] = nil
self.frame:ClearAllPoints()
self.frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 30, 30)
self.frame:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0, 0)
self:SavePosition()
if SFrames and SFrames.Print then
SFrames:Print("Chat frame position reset.")
@@ -2637,12 +2662,12 @@ function SFrames.Chat:RefreshTranslateConfigFrame()
if not self.translateConfigFrame then return end
if self.translateCurrentTabText then
self.translateCurrentTabText:SetText("Current Tab: " .. self:GetConfigFrameActiveTabName())
self.translateCurrentTabText:SetText("当前标签: " .. self:GetConfigFrameActiveTabName())
end
if self.translateChannelHint then
local channels = self:GetJoinedChannels()
self.translateChannelHint:SetText("Joined Channels: " .. tostring(table.getn(channels)))
self.translateChannelHint:SetText("已加入频道: " .. tostring(table.getn(channels)))
end
if self.translateConfigControls then
@@ -2690,7 +2715,7 @@ function SFrames.Chat:EnsureTranslateConfigFrame()
local title = panel:CreateFontString(nil, "OVERLAY")
title:SetFont(fontPath, 14, "OUTLINE")
title:SetPoint("TOP", panel, "TOP", 0, -12)
title:SetText("Chat AI Translate")
title:SetText("聊天 AI 翻译")
title:SetTextColor(CFG_THEME.title[1], CFG_THEME.title[2], CFG_THEME.title[3])
local closeBtn = CreateFrame("Button", nil, panel, "UIPanelCloseButton")
@@ -2701,24 +2726,24 @@ function SFrames.Chat:EnsureTranslateConfigFrame()
table.insert(controls, ctrl)
end
local tabSection = CreateCfgSection(panel, "Tab", 10, -36, 520, 92, fontPath)
local tabSection = CreateCfgSection(panel, "标签页", 10, -36, 520, 92, fontPath)
self.translateCurrentTabText = tabSection:CreateFontString(nil, "OVERLAY")
self.translateCurrentTabText:SetFont(fontPath, 11, "OUTLINE")
self.translateCurrentTabText:SetPoint("TOPLEFT", tabSection, "TOPLEFT", 14, -28)
self.translateCurrentTabText:SetText("Current Tab: " .. self:GetConfigFrameActiveTabName())
self.translateCurrentTabText:SetText("当前标签: " .. self:GetConfigFrameActiveTabName())
CreateCfgButton(tabSection, "Prev", 14, -48, 92, 22, function()
CreateCfgButton(tabSection, "上一个", 14, -48, 92, 22, function()
SFrames.Chat:StepTab(-1)
SFrames.Chat:RefreshConfigFrame()
SFrames.Chat:RefreshTranslateConfigFrame()
end)
CreateCfgButton(tabSection, "Next", 112, -48, 92, 22, function()
CreateCfgButton(tabSection, "下一个", 112, -48, 92, 22, function()
SFrames.Chat:StepTab(1)
SFrames.Chat:RefreshConfigFrame()
SFrames.Chat:RefreshTranslateConfigFrame()
end)
local filterSection = CreateCfgSection(panel, "Message Translate", 10, -134, 520, 126, fontPath)
local filterSection = CreateCfgSection(panel, "消息翻译", 10, -134, 520, 126, fontPath)
for i = 1, table.getn(TRANSLATE_FILTER_ORDER) do
local key = TRANSLATE_FILTER_ORDER[i]
local col = math.mod(i - 1, 2)
@@ -2739,13 +2764,13 @@ function SFrames.Chat:EnsureTranslateConfigFrame()
))
end
local channelSection = CreateCfgSection(panel, "Channel Translate", 10, -266, 520, 198, fontPath)
local channelSection = CreateCfgSection(panel, "频道翻译", 10, -266, 520, 198, fontPath)
self.translateChannelChecks = {}
self.translateChannelHint = channelSection:CreateFontString(nil, "OVERLAY")
self.translateChannelHint:SetFont(fontPath, 10, "OUTLINE")
self.translateChannelHint:SetPoint("BOTTOMLEFT", channelSection, "BOTTOMLEFT", 14, 8)
self.translateChannelHint:SetTextColor(0.84, 0.8, 0.86)
self.translateChannelHint:SetText("Joined Channels:")
self.translateChannelHint:SetText("已加入频道:")
local maxChannelChecks = 15
for i = 1, maxChannelChecks do
@@ -2813,10 +2838,10 @@ function SFrames.Chat:EnsureTranslateConfigFrame()
local tip = channelSection:CreateFontString(nil, "OVERLAY")
tip:SetFont(fontPath, 10, "OUTLINE")
tip:SetPoint("TOPLEFT", channelSection, "TOPLEFT", 14, -150)
tip:SetText("Only active receiving channels can auto-translate.")
tip:SetText("仅已启用接收的频道可自动翻译")
tip:SetTextColor(0.7, 0.7, 0.74)
local close = CreateCfgButton(panel, "Close", 200, -474, 140, 26, function()
local close = CreateCfgButton(panel, "关闭", 200, -474, 140, 26, function()
SFrames.Chat.translateConfigFrame:Hide()
end)
StyleCfgButton(close)
@@ -3961,18 +3986,36 @@ function SFrames.Chat:EnsureConfigFrame()
do
local hcControls = CreateCfgSection(hcPage, "硬核生存服务器专属", 0, 0, 584, 182, fontPath)
local hcStatusText = hcControls:CreateFontString(nil, "OVERLAY")
hcStatusText:SetFont(fontPath, 10, "OUTLINE")
AddControl(CreateCfgCheck(hcControls, "全局彻底关闭硬核频道接收", 16, -30,
function() return EnsureDB().hcGlobalDisable == true end,
function(checked) EnsureDB().hcGlobalDisable = (checked == true) end,
function() SFrames.Chat:RefreshConfigFrame() end
function(checked)
SendChatMessage(".hcc", "SAY")
if checked then
hcStatusText:SetText("HC Chat is now |cffff4444OFF|r")
hcStatusText:SetTextColor(1, 0.4, 0.4)
else
hcStatusText:SetText("HC Chat is now |cff44ff44ON|r")
hcStatusText:SetTextColor(0.4, 1, 0.4)
end
SFrames.Chat:RefreshConfigFrame()
end
))
hcStatusText:SetPoint("TOPLEFT", hcControls, "TOPLEFT", 230, -32)
hcStatusText:SetWidth(200)
hcStatusText:SetJustifyH("LEFT")
hcStatusText:SetText("")
local hcTip = hcControls:CreateFontString(nil, "OVERLAY")
hcTip:SetFont(fontPath, 10, "OUTLINE")
hcTip:SetPoint("TOPLEFT", hcControls, "TOPLEFT", 16, -56)
hcTip:SetWidth(540)
hcTip:SetJustifyH("LEFT")
hcTip:SetText("彻底无视HC频道的强制聊天推送。勾选后所有标签都不会收到硬核频道内容。")
hcTip:SetText("彻底无视HC频道的强制聊天推送。勾选后所有标签都不会收到硬核频道内容。(即时生效)")
hcTip:SetTextColor(0.8, 0.7, 0.7)
AddControl(CreateCfgCheck(hcControls, "全局屏蔽玩家死亡/满级信息", 16, -86,
@@ -3990,7 +4033,7 @@ function SFrames.Chat:EnsureConfigFrame()
deathTip:SetTextColor(0.8, 0.7, 0.7)
AddControl(CreateCfgSlider(hcControls, "最低死亡通报等级", 340, -82, 210, 0, 60, 1,
function() return EnsureDB().hcDeathLevelMin or 0 end,
function() return EnsureDB().hcDeathLevelMin or 10 end,
function(v) EnsureDB().hcDeathLevelMin = v end,
function(v) return (v == 0) and "所有击杀" or (tostring(v) .. " 级及以上") end,
function() SFrames.Chat:RefreshConfigFrame() end
@@ -4001,12 +4044,6 @@ function SFrames.Chat:EnsureConfigFrame()
SFrames.Chat.configFrame:Hide()
local db = EnsureDB()
-- Send Hardcore specific commands on Save
if SFrames.Chat.initialHcGlobalDisable ~= nil and db.hcGlobalDisable ~= SFrames.Chat.initialHcGlobalDisable then
SendChatMessage(".hcc", "SAY")
SFrames.Chat.initialHcGlobalDisable = db.hcGlobalDisable
end
if db.hcDeathDisable then
SendChatMessage(".hcm 60", "SAY")
elseif db.hcDeathLevelMin then
@@ -4052,7 +4089,6 @@ end
function SFrames.Chat:OpenConfigFrame(pageKey)
self:EnsureConfigFrame()
if not self.configFrame then return end
self.initialHcGlobalDisable = EnsureDB().hcGlobalDisable
self:ShowConfigPage(pageKey or self.configActivePage or "window")
self:RefreshConfigFrame()
self.configFrame:Show()
@@ -4245,7 +4281,7 @@ function SFrames.Chat:CreateContainer()
local f = CreateFrame("Frame", "SFramesChatContainer", UIParent)
f:SetWidth(DEFAULTS.width)
f:SetHeight(DEFAULTS.height)
f:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 30, 30)
f:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0, 0)
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
@@ -4455,7 +4491,42 @@ function SFrames.Chat:CreateContainer()
hint:Hide()
f.hint = hint
local leftCat = SFrames:CreateIcon(f, "logo", 14)
local titleBtn = CreateFrame("Button", nil, f)
titleBtn:SetPoint("TOPLEFT", f, "TOPLEFT", 4, -2)
titleBtn:SetHeight(20)
titleBtn:SetFrameStrata("HIGH")
titleBtn:SetFrameLevel(f:GetFrameLevel() + 20)
titleBtn:RegisterForClicks("LeftButtonUp")
local titleBtnThrottle = 0
titleBtn:SetScript("OnUpdate", function()
titleBtnThrottle = titleBtnThrottle + arg1
if titleBtnThrottle < 0.5 then return end
titleBtnThrottle = 0
local tw = title:GetStringWidth() or 40
this:SetWidth(tw + 28)
end)
titleBtn:SetScript("OnClick", function()
if SFrames and SFrames.ConfigUI then
SFrames.ConfigUI:OpenUI()
end
end)
titleBtn:SetScript("OnEnter", function()
title:SetTextColor(1, 0.92, 1)
if f.leftCat then f.leftCat:SetVertexColor(1, 0.92, 1, 1) end
GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT")
GameTooltip:ClearLines()
GameTooltip:AddLine("Nanami UI 设置", 1, 0.84, 0.94)
GameTooltip:AddLine("点击打开主设置面板", 0.85, 0.85, 0.85)
GameTooltip:Show()
end)
titleBtn:SetScript("OnLeave", function()
title:SetTextColor(1, 0.82, 0.93)
if f.leftCat then f.leftCat:SetVertexColor(1, 0.82, 0.9, 0.8) end
GameTooltip:Hide()
end)
f.titleBtn = titleBtn
local leftCat = SFrames:CreateIcon(titleBtn, "logo", 14)
leftCat:SetDrawLayer("OVERLAY")
leftCat:SetPoint("TOPLEFT", f, "TOPLEFT", 8, -5)
leftCat:SetVertexColor(1, 0.82, 0.9, 0.8)
@@ -4476,7 +4547,7 @@ function SFrames.Chat:CreateContainer()
local tabBar = CreateFrame("Frame", nil, f)
tabBar:SetPoint("LEFT", title, "RIGHT", 10, -1)
tabBar:SetPoint("RIGHT", configButton, "LEFT", -8, -1)
tabBar:SetPoint("RIGHT", configButton, "LEFT", -28, -1)
tabBar:SetHeight(18)
f.tabBar = tabBar
@@ -4571,7 +4642,7 @@ function SFrames.Chat:CreateContainer()
hiddenConfigButton:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 14, 132)
hiddenConfigButton:SetFrameStrata("DIALOG")
hiddenConfigButton:SetFrameLevel(220)
hiddenConfigButton:SetText("Chat Set")
hiddenConfigButton:SetText("聊天设置")
hiddenConfigButton:SetScript("OnClick", function()
if SFrames and SFrames.Chat then
SFrames.Chat:ToggleConfigFrame()
@@ -4580,9 +4651,9 @@ function SFrames.Chat:CreateContainer()
hiddenConfigButton:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_TOPLEFT")
GameTooltip:ClearLines()
GameTooltip:AddLine("Chat Settings", 1, 0.84, 0.94)
GameTooltip:AddLine("Shown while chat UI is hidden.", 0.86, 0.86, 0.86)
GameTooltip:AddLine("Click to open Nanami chat config.", 0.86, 0.86, 0.86)
GameTooltip:AddLine("聊天设置", 1, 0.84, 0.94)
GameTooltip:AddLine("聊天界面隐藏时显示此按钮", 0.86, 0.86, 0.86)
GameTooltip:AddLine("点击打开 Nanami 聊天配置", 0.86, 0.86, 0.86)
GameTooltip:Show()
end)
hiddenConfigButton:SetScript("OnLeave", function()
@@ -4599,7 +4670,7 @@ function SFrames.Chat:CreateContainer()
f:ClearAllPoints()
f:SetPoint(saved.point, UIParent, saved.relativePoint, saved.xOfs, saved.yOfs)
else
f:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 30, 30)
f:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0, 0)
end
f:SetWidth(Clamp(db.width, 320, 900))
f:SetHeight(Clamp(db.height, 120, 460))
@@ -5507,8 +5578,8 @@ function SFrames.Chat:RefreshTabButtons()
if not self.addTabButton then
local addBtn = CreateFrame("Button", nil, self.frame.tabBar)
addBtn:SetHeight(18)
addBtn:SetWidth(20)
addBtn:SetHeight(20)
addBtn:SetWidth(28)
addBtn:RegisterForClicks("LeftButtonUp")
EnsureButtonSkin(addBtn)
addBtn.sfText:SetText("+")
@@ -5535,8 +5606,8 @@ function SFrames.Chat:RefreshTabButtons()
if this.SetBackdropColor then this:SetBackdropColor(CFG_THEME.btnHoverBg[1], CFG_THEME.btnHoverBg[2], CFG_THEME.btnHoverBg[3], 0.96) end
GameTooltip:SetOwner(this, "ANCHOR_TOP")
GameTooltip:ClearLines()
GameTooltip:AddLine("New Tab", 1, 0.84, 0.94)
GameTooltip:AddLine("Create chat tab", 0.85, 0.85, 0.85)
GameTooltip:AddLine("新建标签", 1, 0.84, 0.94)
GameTooltip:AddLine("创建聊天标签页", 0.85, 0.85, 0.85)
GameTooltip:Show()
end)
addBtn:SetScript("OnLeave", function()
@@ -5551,7 +5622,7 @@ function SFrames.Chat:RefreshTabButtons()
end
local gap = 3
local addWidth = 20
local addWidth = 28
local barWidth = self.frame.tabBar:GetWidth() or 0
if barWidth <= 0 then
barWidth = (self.frame:GetWidth() or DEFAULTS.width) - 180
@@ -5579,7 +5650,7 @@ function SFrames.Chat:RefreshTabButtons()
btn:SetPoint("LEFT", self.frame.tabBar, "LEFT", x, 0)
btn:SetWidth(buttonWidth)
if btn.sfText then
btn.sfText:SetText(ShortText(tab.name or ("Tab" .. tostring(i)), maxChars))
btn.sfText:SetText(ShortText(tab.name or ("标签" .. tostring(i)), maxChars))
end
local idx = i
@@ -5601,9 +5672,9 @@ function SFrames.Chat:RefreshTabButtons()
end
GameTooltip:SetOwner(this, "ANCHOR_TOP")
GameTooltip:ClearLines()
GameTooltip:AddLine(tab.name or ("Tab" .. tostring(idx)), 1, 0.84, 0.94)
GameTooltip:AddLine("Left: switch", 0.82, 0.82, 0.82)
GameTooltip:AddLine("Right: menu", 1, 0.68, 0.79)
GameTooltip:AddLine(tab.name or ("标签" .. tostring(idx)), 1, 0.84, 0.94)
GameTooltip:AddLine("左键: 切换标签", 0.82, 0.82, 0.82)
GameTooltip:AddLine("右键: 打开菜单", 1, 0.68, 0.79)
GameTooltip:Show()
end)
btn:SetScript("OnLeave", function()
@@ -6174,7 +6245,7 @@ function SFrames.Chat:ApplyConfig()
if self.frame.tabBar and self.frame.title and self.frame.configButton then
self.frame.tabBar:ClearAllPoints()
self.frame.tabBar:SetPoint("LEFT", self.frame.title, "RIGHT", 10, -1)
self.frame.tabBar:SetPoint("RIGHT", self.frame.configButton, "LEFT", -8, -1)
self.frame.tabBar:SetPoint("RIGHT", self.frame.configButton, "LEFT", -28, -1)
self.frame.tabBar:SetHeight(18)
end