聊天重做前缓存

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

@@ -9,10 +9,76 @@ local UNIT_PADDING = 2
local RAID_UNIT_LOOKUP = {}
for i = 1, 40 do RAID_UNIT_LOOKUP["raid" .. i] = true end
-- Pre-allocated tables reused every UpdateAuras call to avoid per-call garbage
local _foundIndicators = { [1] = false, [2] = false, [3] = false, [4] = false }
local _debuffColor = { r = 0, g = 0, b = 0 }
-- Module-level helper: match aura name against a list (no closure allocation)
local function MatchesList(auraName, list)
for _, name in ipairs(list) do
if string.find(auraName, name) then
return true
end
end
return false
end
-- Module-level helper: get buff name via SuperWoW aura ID or tooltip scan
local function RaidGetBuffName(unit, index)
if SFrames.superwow_active and SpellInfo then
local texture, auraID = UnitBuff(unit, index)
if auraID and SpellInfo then
local spellName = SpellInfo(auraID)
if spellName and spellName ~= "" then
return spellName, texture
end
end
end
SFrames.Tooltip:SetOwner(UIParent, "ANCHOR_NONE")
SFrames.Tooltip:SetUnitBuff(unit, index)
local buffName = SFramesScanTooltipTextLeft1:GetText()
SFrames.Tooltip:Hide()
return buffName, UnitBuff(unit, index)
end
local function RaidGetDebuffName(unit, index)
if SFrames.superwow_active and SpellInfo then
local texture, count, dtype, auraID = UnitDebuff(unit, index)
if auraID and SpellInfo then
local spellName = SpellInfo(auraID)
if spellName and spellName ~= "" then
return spellName, texture, count, dtype
end
end
end
SFrames.Tooltip:SetOwner(UIParent, "ANCHOR_NONE")
SFrames.Tooltip:SetUnitDebuff(unit, index)
local debuffName = SFramesScanTooltipTextLeft1:GetText()
SFrames.Tooltip:Hide()
local texture, count, dtype = UnitDebuff(unit, index)
return debuffName, texture, count, dtype
end
local function GetIncomingHeals(unit)
return SFrames:GetIncomingHeals(unit)
end
local function Clamp(value, minValue, maxValue)
if value < minValue then
return minValue
end
if value > maxValue then
return maxValue
end
return value
end
local function SetTextureIfPresent(region, texturePath)
if region and region.SetTexture and texturePath then
region:SetTexture(texturePath)
end
end
function SFrames.Raid:GetMetrics()
local db = SFramesDB or {}
@@ -25,29 +91,66 @@ function SFrames.Raid:GetMetrics()
local healthHeight = tonumber(db.raidHealthHeight) or math.floor((height - 3) * 0.8)
healthHeight = math.max(10, math.min(height - 6, healthHeight))
local powerHeight = height - healthHeight - 3
local powerHeight = tonumber(db.raidPowerHeight) or (height - healthHeight - 3)
powerHeight = math.max(0, math.min(height - 3, powerHeight))
if not db.raidShowPower then
powerHeight = 0
healthHeight = height - 2
end
local gradientStyle = SFrames:IsGradientStyle()
local availablePowerWidth = width - 2
if availablePowerWidth < 20 then
availablePowerWidth = 20
end
local rawPowerWidth = tonumber(db.raidPowerWidth)
local legacyFullWidth = tonumber(db.raidFrameWidth) or width
local defaultPowerWidth = gradientStyle and width or availablePowerWidth
local maxPowerWidth = gradientStyle and width or availablePowerWidth
local powerWidth
if gradientStyle then
-- 渐变风格:能量条始终与血条等宽(全宽)
powerWidth = width
elseif not rawPowerWidth
or math.abs(rawPowerWidth - legacyFullWidth) < 0.5
or math.abs(rawPowerWidth - availablePowerWidth) < 0.5 then
powerWidth = defaultPowerWidth
else
powerWidth = rawPowerWidth
end
powerWidth = Clamp(math.floor(powerWidth + 0.5), 20, maxPowerWidth)
local powerOffsetX = Clamp(math.floor((tonumber(db.raidPowerOffsetX) or 0) + 0.5), -120, 120)
local powerOffsetY = Clamp(math.floor((tonumber(db.raidPowerOffsetY) or 0) + 0.5), -80, 80)
local hgap = tonumber(db.raidHorizontalGap) or UNIT_PADDING
local vgap = tonumber(db.raidVerticalGap) or UNIT_PADDING
local groupGap = tonumber(db.raidGroupGap) or GROUP_PADDING
local nameFont = tonumber(db.raidNameFontSize) or 10
local valueFont = tonumber(db.raidValueFontSize) or 9
local healthFont = tonumber(db.raidHealthFontSize) or valueFont
local powerFont = tonumber(db.raidPowerFontSize) or valueFont
return {
width = width,
height = height,
healthHeight = healthHeight,
powerHeight = powerHeight,
powerWidth = powerWidth,
powerOffsetX = powerOffsetX,
powerOffsetY = powerOffsetY,
powerOnTop = db.raidPowerOnTop == true,
horizontalGap = hgap,
verticalGap = vgap,
groupGap = groupGap,
nameFont = nameFont,
valueFont = valueFont,
healthFont = healthFont,
powerFont = powerFont,
healthTexture = SFrames:ResolveBarTexture("raidHealthTexture", "barTexture"),
powerTexture = SFrames:ResolveBarTexture("raidPowerTexture", "barTexture"),
showPower = db.raidShowPower ~= false,
}
end
@@ -87,8 +190,8 @@ function SFrames.Raid:ApplyFrameStyle(frame, metrics)
frame.power:Show()
if frame.powerBGFrame then frame.powerBGFrame:Show() end
frame.power:ClearAllPoints()
frame.power:SetPoint("TOPLEFT", frame.health, "BOTTOMLEFT", 0, -1)
frame.power:SetPoint("TOPRIGHT", frame.health, "BOTTOMRIGHT", 0, 0)
frame.power:SetPoint("TOPLEFT", frame.health, "BOTTOMLEFT", metrics.powerOffsetX, -1 + metrics.powerOffsetY)
frame.power:SetWidth(metrics.powerWidth)
frame.power:SetHeight(metrics.powerHeight)
else
frame.power:Hide()
@@ -96,14 +199,80 @@ function SFrames.Raid:ApplyFrameStyle(frame, metrics)
end
end
local outline = (SFrames and SFrames.Media and SFrames.Media.fontOutline) or "OUTLINE"
local fontPath = SFrames:GetFont()
SFrames:ApplyStatusBarTexture(frame.health, "raidHealthTexture", "barTexture")
SFrames:ApplyStatusBarTexture(frame.power, "raidPowerTexture", "barTexture")
if frame.health and frame.power then
local healthLevel = frame:GetFrameLevel() + 2
local powerLevel = metrics.powerOnTop and (healthLevel + 1) or (healthLevel - 1)
frame.health:SetFrameLevel(healthLevel)
frame.power:SetFrameLevel(powerLevel)
end
SFrames:ApplyConfiguredUnitBackdrop(frame, "raid")
if frame.healthBGFrame then SFrames:ApplyConfiguredUnitBackdrop(frame.healthBGFrame, "raid") end
if frame.powerBGFrame then SFrames:ApplyConfiguredUnitBackdrop(frame.powerBGFrame, "raid") end
SetTextureIfPresent(frame.health and frame.health.bg, metrics.healthTexture)
SetTextureIfPresent(frame.health and frame.health.healPredMine, metrics.healthTexture)
SetTextureIfPresent(frame.health and frame.health.healPredOther, metrics.healthTexture)
SetTextureIfPresent(frame.health and frame.health.healPredOver, metrics.healthTexture)
SetTextureIfPresent(frame.power and frame.power.bg, metrics.powerTexture)
-- Gradient style preset
if SFrames:IsGradientStyle() then
-- Strip backdrops
SFrames:ClearBackdrop(frame)
SFrames:ClearBackdrop(frame.healthBGFrame)
SFrames:ClearBackdrop(frame.powerBGFrame)
-- Health bar full width
if frame.health then
frame.health:ClearAllPoints()
frame.health:SetPoint("TOPLEFT", frame, "TOPLEFT", 0, 0)
frame.health:SetPoint("TOPRIGHT", frame, "TOPRIGHT", 0, 0)
frame.health:SetHeight(metrics.healthHeight)
end
-- Power bar full width
if frame.power and metrics.showPower then
frame.power:ClearAllPoints()
frame.power:SetPoint("TOPLEFT", frame.health, "BOTTOMLEFT", metrics.powerOffsetX, -1 + metrics.powerOffsetY)
frame.power:SetWidth(metrics.powerWidth)
frame.power:SetHeight(metrics.powerHeight)
end
-- Apply gradient overlays
SFrames:ApplyGradientStyle(frame.health)
SFrames:ApplyGradientStyle(frame.power)
-- Flush BG frames
if frame.healthBGFrame then
frame.healthBGFrame:ClearAllPoints()
frame.healthBGFrame:SetPoint("TOPLEFT", frame.health, "TOPLEFT", 0, 0)
frame.healthBGFrame:SetPoint("BOTTOMRIGHT", frame.health, "BOTTOMRIGHT", 0, 0)
end
if frame.powerBGFrame then
frame.powerBGFrame:ClearAllPoints()
frame.powerBGFrame:SetPoint("TOPLEFT", frame.power, "TOPLEFT", 0, 0)
frame.powerBGFrame:SetPoint("BOTTOMRIGHT", frame.power, "BOTTOMRIGHT", 0, 0)
end
-- Hide bar backgrounds (transparent)
if frame.healthBGFrame then frame.healthBGFrame:Hide() end
if frame.powerBGFrame then frame.powerBGFrame:Hide() end
if frame.health and frame.health.bg then frame.health.bg:Hide() end
if frame.power and frame.power.bg then frame.power.bg:Hide() end
else
SFrames:RemoveGradientStyle(frame.health)
SFrames:RemoveGradientStyle(frame.power)
-- Restore bar backgrounds
if frame.healthBGFrame then frame.healthBGFrame:Show() end
if frame.powerBGFrame then frame.powerBGFrame:Show() end
if frame.health and frame.health.bg then frame.health.bg:Show() end
if frame.power and frame.power.bg then frame.power.bg:Show() end
end
if frame.nameText then
frame.nameText:SetFont(fontPath, metrics.nameFont, outline)
SFrames:ApplyFontString(frame.nameText, metrics.nameFont, "raidNameFontKey", "fontKey")
end
if frame.healthText then
frame.healthText:SetFont(fontPath, metrics.valueFont, outline)
SFrames:ApplyFontString(frame.healthText, metrics.healthFont, "raidHealthFontKey", "fontKey")
end
if frame.powerText then
SFrames:ApplyFontString(frame.powerText, metrics.powerFont, "raidPowerFontKey", "fontKey")
end
end
@@ -724,6 +893,9 @@ function SFrames.Raid:UpdateFrame(unit)
f.nameText:SetTextColor(1, 1, 1)
end
end
if SFrames:IsGradientStyle() then
SFrames:ApplyBarGradient(f.health)
end
self:UpdateHealth(unit)
self:UpdatePower(unit)
@@ -794,11 +966,10 @@ function SFrames.Raid:UpdateHealth(unit)
txt = percent .. "%"
elseif db.raidHealthFormat == "deficit" then
if maxHp - hp > 0 then
txt = "-" .. (maxHp - hp)
txt = "-" .. SFrames:FormatCompactNumber(maxHp - hp)
end
else
txt = (math.floor(hp/100)/10).."k" -- default compact e.g. 4.5k
if hp < 1000 then txt = tostring(hp) end
txt = SFrames:FormatCompactNumber(hp)
end
f.healthText:SetText(txt)
@@ -826,14 +997,8 @@ function SFrames.Raid:UpdateHealPrediction(unit)
local predOther = f.health.healPredOther
local predOver = f.health.healPredOver
local function HidePredictions()
predMine:Hide()
predOther:Hide()
predOver:Hide()
end
if not UnitExists(unit) or not UnitIsConnected(unit) then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -855,7 +1020,7 @@ function SFrames.Raid:UpdateHealPrediction(unit)
end
if maxHp <= 0 then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -872,7 +1037,7 @@ function SFrames.Raid:UpdateHealPrediction(unit)
end
local missing = maxHp - hp
if missing <= 0 and (mineIncoming <= 0 and othersIncoming <= 0) then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -880,13 +1045,13 @@ function SFrames.Raid:UpdateHealPrediction(unit)
local remaining = missing - mineShown
local otherShown = math.min(math.max(0, othersIncoming), remaining)
if mineIncoming <= 0 and othersIncoming <= 0 then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
local barWidth = f:GetWidth() - 2
if barWidth <= 0 then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -896,7 +1061,7 @@ function SFrames.Raid:UpdateHealPrediction(unit)
local availableWidth = barWidth - currentPosition
if availableWidth <= 0 and (mineIncoming <= 0 and othersIncoming <= 0) then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -972,6 +1137,10 @@ function SFrames.Raid:UpdatePower(unit)
local pType = UnitPowerType(unit)
local color = SFrames.Config.colors.power[pType] or SFrames.Config.colors.power[0]
f.power:SetStatusBarColor(color.r, color.g, color.b)
if SFrames:IsGradientStyle() then
SFrames:ApplyBarGradient(f.power)
end
SFrames:UpdateRainbowBar(f.power, power, maxPower, unit)
break
end
end
@@ -1072,7 +1241,11 @@ function SFrames.Raid:UpdateAuras(unit)
local f = frameData.frame
local buffsNeeded = self:GetClassBuffs()
local foundIndicators = { [1] = false, [2] = false, [3] = false, [4] = false }
-- Reuse pre-allocated table
_foundIndicators[1] = false
_foundIndicators[2] = false
_foundIndicators[3] = false
_foundIndicators[4] = false
-- Hide all first
for i = 1, 4 do
@@ -1085,70 +1258,22 @@ function SFrames.Raid:UpdateAuras(unit)
return
end
local function MatchesList(auraName, list)
for _, name in ipairs(list) do
if string.find(auraName, name) then
return true
end
end
return false
end
-- Helper: get buff name via SuperWoW aura ID (fast) or tooltip scan (fallback)
local hasSuperWoW = SFrames.superwow_active and SpellInfo
local function GetBuffName(unit, index)
if hasSuperWoW then
local texture, auraID = UnitBuff(unit, index)
if auraID and SpellInfo then
local spellName = SpellInfo(auraID)
if spellName and spellName ~= "" then
return spellName, texture
end
end
end
-- Fallback: tooltip scan
SFrames.Tooltip:SetOwner(UIParent, "ANCHOR_NONE")
SFrames.Tooltip:SetUnitBuff(unit, index)
local buffName = SFramesScanTooltipTextLeft1:GetText()
SFrames.Tooltip:Hide()
return buffName, UnitBuff(unit, index)
end
local function GetDebuffName(unit, index)
if hasSuperWoW then
local texture, count, dtype, auraID = UnitDebuff(unit, index)
if auraID and SpellInfo then
local spellName = SpellInfo(auraID)
if spellName and spellName ~= "" then
return spellName, texture, count, dtype
end
end
end
-- Fallback: tooltip scan
SFrames.Tooltip:SetOwner(UIParent, "ANCHOR_NONE")
SFrames.Tooltip:SetUnitDebuff(unit, index)
local debuffName = SFramesScanTooltipTextLeft1:GetText()
SFrames.Tooltip:Hide()
local texture, count, dtype = UnitDebuff(unit, index)
return debuffName, texture, count, dtype
end
-- Check Buffs
-- Check Buffs (using module-level helpers, no closures)
for i = 1, 32 do
local texture, applications = UnitBuff(unit, i)
if not texture then break end
local buffName = GetBuffName(unit, i)
local buffName = RaidGetBuffName(unit, i)
if buffName then
for pos, listData in pairs(buffsNeeded) do
if pos <= 4 and not listData.isDebuff and not foundIndicators[pos] then
if pos <= 4 and not listData.isDebuff and not _foundIndicators[pos] then
if MatchesList(buffName, listData) then
f.indicators[pos].icon:SetTexture(texture)
f.indicators[pos].index = i
f.indicators[pos].isDebuff = false
f.indicators[pos]:Show()
foundIndicators[pos] = true
_foundIndicators[pos] = true
end
end
end
@@ -1156,7 +1281,10 @@ function SFrames.Raid:UpdateAuras(unit)
end
local hasDebuff = false
local debuffColor = {r=_A.slotBg[1], g=_A.slotBg[2], b=_A.slotBg[3]}
-- Reuse pre-allocated table
_debuffColor.r = _A.slotBg[1]
_debuffColor.g = _A.slotBg[2]
_debuffColor.b = _A.slotBg[3]
-- Check Debuffs
for i = 1, 16 do
@@ -1165,24 +1293,24 @@ function SFrames.Raid:UpdateAuras(unit)
if dispelType then
hasDebuff = true
if dispelType == "Magic" then debuffColor = {r=0.2, g=0.6, b=1}
elseif dispelType == "Curse" then debuffColor = {r=0.6, g=0, b=1}
elseif dispelType == "Disease" then debuffColor = {r=0.6, g=0.4, b=0}
elseif dispelType == "Poison" then debuffColor = {r=0, g=0.6, b=0}
if dispelType == "Magic" then _debuffColor.r = 0.2; _debuffColor.g = 0.6; _debuffColor.b = 1
elseif dispelType == "Curse" then _debuffColor.r = 0.6; _debuffColor.g = 0; _debuffColor.b = 1
elseif dispelType == "Disease" then _debuffColor.r = 0.6; _debuffColor.g = 0.4; _debuffColor.b = 0
elseif dispelType == "Poison" then _debuffColor.r = 0; _debuffColor.g = 0.6; _debuffColor.b = 0
end
end
local debuffName = GetDebuffName(unit, i)
local debuffName = RaidGetDebuffName(unit, i)
if debuffName then
for pos, listData in pairs(buffsNeeded) do
if pos <= 4 and listData.isDebuff and not foundIndicators[pos] then
if pos <= 4 and listData.isDebuff and not _foundIndicators[pos] then
if MatchesList(debuffName, listData) then
f.indicators[pos].icon:SetTexture(texture)
f.indicators[pos].index = i
f.indicators[pos].isDebuff = true
f.indicators[pos]:Show()
foundIndicators[pos] = true
_foundIndicators[pos] = true
end
end
end
@@ -1190,9 +1318,8 @@ function SFrames.Raid:UpdateAuras(unit)
end
if hasDebuff then
f.health.bg:SetVertexColor(debuffColor.r, debuffColor.g, debuffColor.b, 1)
f.health.bg:SetVertexColor(_debuffColor.r, _debuffColor.g, _debuffColor.b, 1)
else
f.health.bg:SetVertexColor(_A.slotBg[1], _A.slotBg[2], _A.slotBg[3], _A.slotBg[4] or 1)
end
end