聊天重做前缓存

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

@@ -225,16 +225,22 @@ function SFrames.Pet:Initialize()
local f = CreateFrame("Button", "SFramesPetFrame", UIParent)
f:SetWidth(150)
f:SetHeight(30)
if SFramesDB and SFramesDB.Positions and SFramesDB.Positions["PetFrame"] then
local pos = SFramesDB.Positions["PetFrame"]
f:SetPoint(pos.point, UIParent, pos.relativePoint, pos.xOfs, pos.yOfs)
else
f:SetPoint("TOPLEFT", SFramesPlayerFrame, "BOTTOMLEFT", 10, -55)
end
local frameScale = (SFramesDB and type(SFramesDB.petFrameScale) == "number") and SFramesDB.petFrameScale or 1
f:SetScale(Clamp(frameScale, 0.7, 1.8))
if SFramesDB and SFramesDB.Positions and SFramesDB.Positions["PetFrame"] then
local pos = SFramesDB.Positions["PetFrame"]
local fScale = f:GetEffectiveScale() / UIParent:GetEffectiveScale()
if fScale > 0.01 and math.abs(fScale - 1) > 0.001 then
f:SetPoint(pos.point, UIParent, pos.relativePoint,
(pos.xOfs or 0) / fScale, (pos.yOfs or 0) / fScale)
else
f:SetPoint(pos.point, UIParent, pos.relativePoint, pos.xOfs or 0, pos.yOfs or 0)
end
else
f:SetPoint("TOPLEFT", SFramesPlayerFrame, "BOTTOMLEFT", 0, -75)
end
f:SetMovable(true)
f:EnableMouse(true)
@@ -245,6 +251,11 @@ function SFrames.Pet:Initialize()
if not SFramesDB then SFramesDB = {} end
if not SFramesDB.Positions then SFramesDB.Positions = {} end
local point, relativeTo, relativePoint, xOfs, yOfs = f:GetPoint()
local fScale = f:GetEffectiveScale() / UIParent:GetEffectiveScale()
if fScale > 0.01 and math.abs(fScale - 1) > 0.001 then
xOfs = (xOfs or 0) * fScale
yOfs = (yOfs or 0) * fScale
end
SFramesDB.Positions["PetFrame"] = { point = point, relativePoint = relativePoint, xOfs = xOfs, yOfs = yOfs }
end)
@@ -294,6 +305,8 @@ function SFrames.Pet:Initialize()
hbg:SetFrameLevel(f:GetFrameLevel() - 1)
SFrames:CreateUnitBackdrop(hbg)
f.healthBGFrame = hbg
f.health.bg = f.health:CreateTexture(nil, "BACKGROUND")
f.health.bg:SetAllPoints()
f.health.bg:SetTexture(SFrames:GetTexture())
@@ -328,6 +341,7 @@ function SFrames.Pet:Initialize()
pbg:SetPoint("BOTTOMRIGHT", f.power, "BOTTOMRIGHT", 1, -1)
pbg:SetFrameLevel(f:GetFrameLevel() - 1)
SFrames:CreateUnitBackdrop(pbg)
f.powerBGFrame = pbg
f.power.bg = f.power:CreateTexture(nil, "BACKGROUND")
f.power.bg:SetAllPoints()
@@ -394,11 +408,13 @@ function SFrames.Pet:Initialize()
SFrames:RegisterEvent("PLAYER_ENTERING_WORLD", function() self:UpdateAll() end)
self:InitFoodFeature()
self:ApplyConfig()
self:UpdateAll()
if SFrames.Movers and SFrames.Movers.RegisterMover and self.frame then
SFrames.Movers:RegisterMover("PetFrame", self.frame, "宠物",
"TOPLEFT", "SFramesPlayerFrame", "BOTTOMLEFT", 10, -55)
"TOPLEFT", "SFramesPlayerFrame", "BOTTOMLEFT", 0, -75,
nil, { alwaysShowInLayout = true })
end
if StaticPopup_Show then
@@ -413,6 +429,90 @@ function SFrames.Pet:Initialize()
end
end
function SFrames.Pet:ApplyConfig()
if not self.frame then return end
local f = self.frame
-- Apply bar textures
SFrames:ApplyStatusBarTexture(f.health, "petHealthTexture", "barTexture")
SFrames:ApplyStatusBarTexture(f.power, "petPowerTexture", "barTexture")
local healthTex = SFrames:ResolveBarTexture("petHealthTexture", "barTexture")
local powerTex = SFrames:ResolveBarTexture("petPowerTexture", "barTexture")
if f.health and f.health.bg then f.health.bg:SetTexture(healthTex) end
if f.power and f.power.bg then f.power.bg:SetTexture(powerTex) end
if SFrames:IsGradientStyle() then
-- Strip backdrops
SFrames:ClearBackdrop(f)
SFrames:ClearBackdrop(f.healthBGFrame)
SFrames:ClearBackdrop(f.powerBGFrame)
-- Health bar full width
if f.health then
f.health:ClearAllPoints()
f.health:SetPoint("TOPLEFT", f, "TOPLEFT", 0, 0)
f.health:SetPoint("TOPRIGHT", f, "TOPRIGHT", 0, 0)
f.health:SetHeight(18)
end
-- Power bar full width
if f.power then
f.power:ClearAllPoints()
f.power:SetPoint("TOPLEFT", f.health, "BOTTOMLEFT", 0, -2)
f.power:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", 0, 0)
end
-- Apply gradient overlays
SFrames:ApplyGradientStyle(f.health)
SFrames:ApplyGradientStyle(f.power)
-- Flush BG frames
if f.healthBGFrame then
f.healthBGFrame:ClearAllPoints()
f.healthBGFrame:SetPoint("TOPLEFT", f.health, "TOPLEFT", 0, 0)
f.healthBGFrame:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT", 0, 0)
end
if f.powerBGFrame then
f.powerBGFrame:ClearAllPoints()
f.powerBGFrame:SetPoint("TOPLEFT", f.power, "TOPLEFT", 0, 0)
f.powerBGFrame:SetPoint("BOTTOMRIGHT", f.power, "BOTTOMRIGHT", 0, 0)
end
-- Hide bar backgrounds (transparent)
if f.healthBGFrame then f.healthBGFrame:Hide() end
if f.powerBGFrame then f.powerBGFrame:Hide() end
if f.health and f.health.bg then f.health.bg:Hide() end
if f.power and f.power.bg then f.power.bg:Hide() end
else
-- Classic style: restore backdrops
SFrames:CreateUnitBackdrop(f)
if f.health and f.health.bg then f.health.bg:Show() end
if f.power and f.power.bg then f.power.bg:Show() end
if f.healthBGFrame then
SFrames:CreateUnitBackdrop(f.healthBGFrame)
f.healthBGFrame:Show()
f.healthBGFrame:ClearAllPoints()
f.healthBGFrame:SetPoint("TOPLEFT", f.health, "TOPLEFT", -1, 1)
f.healthBGFrame:SetPoint("BOTTOMRIGHT", f.health, "BOTTOMRIGHT", 1, -1)
end
if f.powerBGFrame then
SFrames:CreateUnitBackdrop(f.powerBGFrame)
f.powerBGFrame:Show()
f.powerBGFrame:ClearAllPoints()
f.powerBGFrame:SetPoint("TOPLEFT", f.power, "TOPLEFT", -1, 1)
f.powerBGFrame:SetPoint("BOTTOMRIGHT", f.power, "BOTTOMRIGHT", 1, -1)
end
if f.health then
f.health:ClearAllPoints()
f.health:SetPoint("TOPLEFT", f, "TOPLEFT", 1, -1)
f.health:SetPoint("TOPRIGHT", f, "TOPRIGHT", -1, -1)
f.health:SetHeight(18)
end
if f.power then
f.power:ClearAllPoints()
f.power:SetPoint("TOPLEFT", f.health, "BOTTOMLEFT", 0, -1)
f.power:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -1, 1)
end
SFrames:RemoveGradientStyle(f.health)
SFrames:RemoveGradientStyle(f.power)
end
end
function SFrames.Pet:UpdateAll()
if UnitExists("pet") then
if SFramesDB and SFramesDB.showPetFrame == false then
@@ -437,6 +537,9 @@ function SFrames.Pet:UpdateAll()
local r, g, b = 0.33, 0.59, 0.33
self.frame.health:SetStatusBarColor(r, g, b)
if SFrames:IsGradientStyle() then
SFrames:ApplyBarGradient(self.frame.health)
end
else
self.frame:Hide()
if self.foodPanel then self.foodPanel:Hide() end
@@ -465,12 +568,6 @@ function SFrames.Pet:UpdateHealPrediction()
local predOther = self.frame.health.healPredOther
local predOver = self.frame.health.healPredOver
local function HidePredictions()
predMine:Hide()
predOther:Hide()
predOver:Hide()
end
local hp = UnitHealth("pet") or 0
local maxHp = UnitHealthMax("pet") or 0
@@ -485,7 +582,7 @@ function SFrames.Pet:UpdateHealPrediction()
end
if maxHp <= 0 or UnitIsDeadOrGhost("pet") then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -497,7 +594,7 @@ function SFrames.Pet:UpdateHealPrediction()
local missing = maxHp - hp
if missing <= 0 and (mineIncoming <= 0 and othersIncoming <= 0) then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -505,13 +602,13 @@ function SFrames.Pet:UpdateHealPrediction()
local remaining = missing - mineShown
local otherShown = math.min(math.max(0, othersIncoming), remaining)
if mineShown <= 0 and otherShown <= 0 and (mineIncoming <= 0 and othersIncoming <= 0) then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
local barWidth = self.frame.health:GetWidth()
if barWidth <= 0 then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -521,7 +618,7 @@ function SFrames.Pet:UpdateHealPrediction()
local availableWidth = barWidth - currentWidth
if availableWidth <= 0 and (mineIncoming <= 0 and othersIncoming <= 0) then
HidePredictions()
predMine:Hide(); predOther:Hide(); predOver:Hide()
return
end
@@ -587,6 +684,9 @@ function SFrames.Pet:UpdatePowerType()
else
self.frame.power:SetStatusBarColor(0, 0, 1)
end
if SFrames:IsGradientStyle() then
SFrames:ApplyBarGradient(self.frame.power)
end
end
function SFrames.Pet:UpdatePower()
@@ -594,6 +694,7 @@ function SFrames.Pet:UpdatePower()
local maxPower = UnitManaMax("pet")
self.frame.power:SetMinMaxValues(0, maxPower)
self.frame.power:SetValue(power)
SFrames:UpdateRainbowBar(self.frame.power, power, maxPower, "pet")
end
function SFrames.Pet:UpdateHappiness()