聊天重做前缓存

This commit is contained in:
rucky
2026-04-09 09:46:47 +08:00
parent 6e18269bfd
commit e915bbd74a
39 changed files with 8501 additions and 2308 deletions

View File

@@ -1,19 +1,48 @@
-- Helper function to generate ElvUI-style backdrop and shadow border
function SFrames:CreateBackdrop(frame)
frame:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = 1, right = 1, top = 1, bottom = 1 }
})
local A = SFrames.ActiveTheme
if A and A.panelBg then
frame:SetBackdropColor(A.panelBg[1], A.panelBg[2], A.panelBg[3], A.panelBg[4] or 0.9)
frame:SetBackdropBorderColor(A.panelBorder[1], A.panelBorder[2], A.panelBorder[3], A.panelBorder[4] or 1)
function SFrames:ApplyBackdropStyle(frame, opts)
opts = opts or {}
local radius = tonumber(opts.cornerRadius) or 0
local showBorder = opts.showBorder ~= false
local useRounded = radius and radius > 0
if useRounded then
local edgeSize = math.max(8, math.min(18, math.floor(radius + 0.5)))
frame:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = showBorder and "Interface\\Tooltips\\UI-Tooltip-Border" or nil,
tile = true, tileSize = 16, edgeSize = edgeSize,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
})
else
frame:SetBackdropColor(0.1, 0.1, 0.1, 0.9)
frame:SetBackdropBorderColor(0, 0, 0, 1)
frame:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = showBorder and "Interface\\Buttons\\WHITE8X8" or nil,
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = 1, right = 1, top = 1, bottom = 1 }
})
end
local A = SFrames.ActiveTheme
local bgAlpha = opts.bgAlpha
if A and A.panelBg then
frame:SetBackdropColor(A.panelBg[1], A.panelBg[2], A.panelBg[3], bgAlpha or A.panelBg[4] or 0.9)
if showBorder then
frame:SetBackdropBorderColor(A.panelBorder[1], A.panelBorder[2], A.panelBorder[3], A.panelBorder[4] or 1)
else
frame:SetBackdropBorderColor(0, 0, 0, 0)
end
else
frame:SetBackdropColor(0.1, 0.1, 0.1, bgAlpha or 0.9)
if showBorder then
frame:SetBackdropBorderColor(0, 0, 0, 1)
else
frame:SetBackdropBorderColor(0, 0, 0, 0)
end
end
end
function SFrames:CreateBackdrop(frame)
self:ApplyBackdropStyle(frame)
end
function SFrames:CreateRoundBackdrop(frame)
@@ -38,6 +67,78 @@ function SFrames:CreateUnitBackdrop(frame)
frame:SetBackdropBorderColor(0, 0, 0, 1)
end
function SFrames:ApplyConfiguredUnitBackdrop(frame, prefix, isPortrait)
if not frame then return end
local db = SFramesDB or {}
local bgAlphaKey = prefix .. (isPortrait and "PortraitBgAlpha" or "BgAlpha")
self:ApplyBackdropStyle(frame, {
showBorder = false,
cornerRadius = 0,
bgAlpha = tonumber(db[bgAlphaKey]) or (isPortrait and tonumber(db[prefix .. "BgAlpha"]) or nil),
})
end
--------------------------------------------------------------------------------
-- Frame Style Preset helpers
--------------------------------------------------------------------------------
function SFrames:GetFrameStylePreset()
return (SFramesDB and SFramesDB.frameStylePreset) or "classic"
end
function SFrames:IsGradientStyle()
return self:GetFrameStylePreset() == "gradient"
end
-- Apply a gradient darkening overlay on a StatusBar.
-- Uses a separate Texture on OVERLAY layer with purple-black vertex color
-- and alpha gradient from 0 (left) to ~0.6 (right).
-- This approach does NOT touch the StatusBar texture itself,
-- so it survives SetStatusBarColor calls.
function SFrames:ApplyGradientStyle(bar)
if not bar then return end
if not bar._gradOverlay then
local ov = bar:CreateTexture(nil, "OVERLAY")
ov:SetTexture("Interface\\Buttons\\WHITE8X8")
bar._gradOverlay = ov
end
local ov = bar._gradOverlay
ov:ClearAllPoints()
ov:SetAllPoints(bar:GetStatusBarTexture())
-- Dark purple-ish tint color
ov:SetVertexColor(0.04, 0.0, 0.08, 1)
-- Alpha gradient: left fully transparent → right 65% opaque
if ov.SetGradientAlpha then
ov:SetGradientAlpha("HORIZONTAL",
1, 1, 1, 0,
1, 1, 1, 0.65)
end
ov:Show()
end
function SFrames:RemoveGradientStyle(bar)
if not bar then return end
if bar._gradOverlay then
bar._gradOverlay:Hide()
end
end
-- No-op wrappers kept for compatibility with unit files
function SFrames:ApplyBarGradient(bar)
-- Gradient is now persistent overlay; no per-color-update needed
end
function SFrames:ClearBarGradient(bar)
self:RemoveGradientStyle(bar)
end
-- Strip backdrop from a frame (used in gradient style)
function SFrames:ClearBackdrop(frame)
if not frame then return end
if frame.SetBackdrop then
frame:SetBackdrop(nil)
end
end
-- Generator for StatusBars
function SFrames:CreateStatusBar(parent, name)
local bar = CreateFrame("StatusBar", name, parent)
@@ -50,6 +151,11 @@ function SFrames:CreateStatusBar(parent, name)
return bar
end
function SFrames:ApplyStatusBarTexture(bar, settingKey, fallbackKey)
if not bar or not bar.SetStatusBarTexture then return end
bar:SetStatusBarTexture(self:ResolveBarTexture(settingKey, fallbackKey))
end
-- Generator for FontStrings
function SFrames:CreateFontString(parent, size, justifyH)
local fs = parent:CreateFontString(nil, "OVERLAY")
@@ -59,6 +165,29 @@ function SFrames:CreateFontString(parent, size, justifyH)
return fs
end
function SFrames:ApplyFontString(fs, size, fontSettingKey, fallbackFontKey, outlineSettingKey, fallbackOutlineKey)
if not fs or not fs.SetFont then return end
local fontPath = self:ResolveFont(fontSettingKey, fallbackFontKey)
local outline = self:ResolveFontOutline(outlineSettingKey, fallbackOutlineKey)
fs:SetFont(fontPath, size or 12, outline)
end
function SFrames:FormatCompactNumber(value)
local num = tonumber(value) or 0
local sign = num < 0 and "-" or ""
num = math.abs(num)
if num >= 1000000 then
return string.format("%s%.1fM", sign, num / 1000000)
elseif num >= 10000 then
return string.format("%s%.1fK", sign, num / 1000)
end
return sign .. tostring(math.floor(num + 0.5))
end
function SFrames:FormatCompactPair(currentValue, maxValue)
return self:FormatCompactNumber(currentValue) .. " / " .. self:FormatCompactNumber(maxValue)
end
-- Generator for 3D Portraits
function SFrames:CreatePortrait(parent, name)
local portrait = CreateFrame("PlayerModel", name, parent)