完成焦点等开发

This commit is contained in:
rucky
2026-03-31 18:03:23 +08:00
parent c7dd0f4848
commit 6e18269bfd
34 changed files with 6803 additions and 542 deletions

View File

@@ -21,31 +21,7 @@ local function GetChineseClassName(classToken, localizedClass)
end
local function GetIncomingHeals(unit)
if not (ShaguTweaks and ShaguTweaks.libpredict and ShaguTweaks.libpredict.UnitGetIncomingHeals) then
return 0, 0, 0
end
local libpredict = ShaguTweaks.libpredict
if libpredict.UnitGetIncomingHealsBreakdown then
local ok, total, mine, others = pcall(function()
return libpredict:UnitGetIncomingHealsBreakdown(unit, UnitName("player"))
end)
if ok then
total = math.max(0, tonumber(total) or 0)
mine = math.max(0, tonumber(mine) or 0)
others = math.max(0, tonumber(others) or 0)
return total, mine, others
end
end
local ok, amount = pcall(function()
return libpredict:UnitGetIncomingHeals(unit)
end)
if not ok then return 0, 0, 0 end
amount = tonumber(amount) or 0
if amount < 0 then amount = 0 end
return amount, 0, amount
return SFrames:GetIncomingHeals(unit)
end
local function Clamp(value, minValue, maxValue)
@@ -116,6 +92,15 @@ function SFrames.Player:ApplyConfig()
f:SetHeight(cfg.height)
f:SetAlpha(frameAlpha)
local bgA = tonumber(db.playerBgAlpha) or 0.9
local _A = SFrames.ActiveTheme
if _A and _A.panelBg and bgA < 0.89 then
if f.SetBackdropColor then f:SetBackdropColor(_A.panelBg[1], _A.panelBg[2], _A.panelBg[3], bgA) end
if f.healthBGFrame and f.healthBGFrame.SetBackdropColor then f.healthBGFrame:SetBackdropColor(_A.panelBg[1], _A.panelBg[2], _A.panelBg[3], bgA) end
if f.powerBGFrame and f.powerBGFrame.SetBackdropColor then f.powerBGFrame:SetBackdropColor(_A.panelBg[1], _A.panelBg[2], _A.panelBg[3], bgA) end
if f.portraitBG and f.portraitBG.SetBackdropColor then f.portraitBG:SetBackdropColor(_A.panelBg[1], _A.panelBg[2], _A.panelBg[3], bgA) end
end
if showPortrait then
if f.portrait then
f.portrait:SetWidth(cfg.portraitWidth)
@@ -295,15 +280,23 @@ function SFrames.Player:Initialize()
f.health.bg:SetVertexColor(_A.slotBg[1], _A.slotBg[2], _A.slotBg[3], _A.slotBg[4] or 1)
-- Heal prediction overlay (incoming heals)
f.health.healPredMine = f.health:CreateTexture(nil, "OVERLAY")
f.health.healPredMine = f.health:CreateTexture(nil, "ARTWORK")
f.health.healPredMine:SetTexture(SFrames:GetTexture())
f.health.healPredMine:SetVertexColor(0.4, 1.0, 0.55, 0.78)
f.health.healPredMine:SetDrawLayer("ARTWORK", 2)
f.health.healPredMine:Hide()
f.health.healPredOther = f.health:CreateTexture(nil, "OVERLAY")
f.health.healPredOther = f.health:CreateTexture(nil, "ARTWORK")
f.health.healPredOther:SetTexture(SFrames:GetTexture())
f.health.healPredOther:SetVertexColor(0.2, 0.9, 0.35, 0.5)
f.health.healPredOther:SetDrawLayer("ARTWORK", 2)
f.health.healPredOther:Hide()
f.health.healPredOver = f.health:CreateTexture(nil, "OVERLAY")
f.health.healPredOver:SetTexture(SFrames:GetTexture())
f.health.healPredOver:SetVertexColor(1.0, 0.3, 0.3, 0.6)
f.health.healPredOver:SetDrawLayer("OVERLAY", 7)
f.health.healPredOver:Hide()
-- Power Bar
f.power = SFrames:CreateStatusBar(f, "SFramesPlayerPower")
@@ -524,11 +517,13 @@ function SFrames.Player:Initialize()
f.unit = "player"
f:SetScript("OnEnter", function()
if SetMouseoverUnit then SetMouseoverUnit(this.unit) end
GameTooltip_SetDefaultAnchor(GameTooltip, this)
GameTooltip:SetUnit(this.unit)
GameTooltip:Show()
end)
f:SetScript("OnLeave", function()
if SetMouseoverUnit then SetMouseoverUnit() end
GameTooltip:Hide()
end)
end
@@ -1094,6 +1089,21 @@ end
function SFrames.Player:UpdateHealth()
local hp = UnitHealth("player")
local maxHp = UnitHealthMax("player")
if CheckSuperWow then
local ok, hasSW = pcall(CheckSuperWow)
if ok and hasSW then
local ok2, realHp = pcall(UnitHealth, "player")
if ok2 then
hp = realHp or hp
end
local ok3, realMaxHp = pcall(UnitHealthMax, "player")
if ok3 then
maxHp = realMaxHp or maxHp
end
end
end
self.frame.health:SetMinMaxValues(0, maxHp)
self.frame.health:SetValue(hp)
@@ -1107,25 +1117,47 @@ function SFrames.Player:UpdateHealth()
end
function SFrames.Player:UpdateHealPrediction()
if not (self.frame and self.frame.health and self.frame.health.healPredMine and self.frame.health.healPredOther) then return end
if not (self.frame and self.frame.health and self.frame.health.healPredMine and self.frame.health.healPredOther and self.frame.health.healPredOver) then return end
local predMine = self.frame.health.healPredMine
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("player") or 0
local maxHp = UnitHealthMax("player") or 0
if maxHp <= 0 or hp >= maxHp or UnitIsDeadOrGhost("player") then
if CheckSuperWow then
local ok, hasSW = pcall(CheckSuperWow)
if ok and hasSW then
local ok2, realHp = pcall(UnitHealth, "player")
if ok2 then
hp = realHp or hp
end
local ok3, realMaxHp = pcall(UnitHealthMax, "player")
if ok3 then
maxHp = realMaxHp or maxHp
end
end
end
if maxHp <= 0 or UnitIsDeadOrGhost("player") then
HidePredictions()
return
end
local _, mineIncoming, othersIncoming = GetIncomingHeals("player")
local totalIncoming, mineIncoming, othersIncoming = 0, 0, 0
local ok, t, m, o = pcall(function() return GetIncomingHeals("player") end)
if ok then
totalIncoming, mineIncoming, othersIncoming = t or 0, m or 0, o or 0
end
local missing = maxHp - hp
if missing <= 0 then
if missing <= 0 and (mineIncoming <= 0 and othersIncoming <= 0) then
HidePredictions()
return
end
@@ -1133,34 +1165,39 @@ function SFrames.Player:UpdateHealPrediction()
local mineShown = math.min(math.max(0, mineIncoming), missing)
local remaining = missing - mineShown
local otherShown = math.min(math.max(0, othersIncoming), remaining)
if mineShown <= 0 and otherShown <= 0 then
if mineShown <= 0 and otherShown <= 0 and (mineIncoming <= 0 and othersIncoming <= 0) then
HidePredictions()
return
end
local barWidth = self.frame.health:GetWidth() or 0
local showPortrait = SFramesDB and SFramesDB.playerShowPortrait ~= false
local barWidth = self.frame:GetWidth() - (showPortrait and (self.frame.portrait:GetWidth() + 2) or 2)
if barWidth <= 0 then
HidePredictions()
return
end
local currentWidth = math.floor((hp / maxHp) * barWidth + 0.5)
local currentWidth = (hp / maxHp) * barWidth
if currentWidth < 0 then currentWidth = 0 end
if currentWidth > barWidth then currentWidth = barWidth end
local availableWidth = barWidth - currentWidth
if availableWidth <= 0 then
if availableWidth <= 0 and (mineIncoming <= 0 and othersIncoming <= 0) then
HidePredictions()
return
end
local mineWidth = math.floor((mineShown / maxHp) * barWidth + 0.5)
local otherWidth = math.floor((otherShown / maxHp) * barWidth + 0.5)
if mineWidth < 0 then mineWidth = 0 end
if otherWidth < 0 then otherWidth = 0 end
if mineWidth > availableWidth then mineWidth = availableWidth end
if otherWidth > (availableWidth - mineWidth) then
otherWidth = availableWidth - mineWidth
local mineWidth = 0
local otherWidth = 0
if missing > 0 then
mineWidth = (mineShown / missing) * availableWidth
otherWidth = (otherShown / missing) * availableWidth
if mineWidth < 0 then mineWidth = 0 end
if otherWidth < 0 then otherWidth = 0 end
if mineWidth > availableWidth then mineWidth = availableWidth end
if otherWidth > (availableWidth - mineWidth) then
otherWidth = availableWidth - mineWidth
end
end
if mineWidth > 0 then
@@ -1168,6 +1205,7 @@ function SFrames.Player:UpdateHealPrediction()
predMine:SetPoint("TOPLEFT", self.frame.health, "TOPLEFT", currentWidth, 0)
predMine:SetPoint("BOTTOMLEFT", self.frame.health, "BOTTOMLEFT", currentWidth, 0)
predMine:SetWidth(mineWidth)
predMine:SetHeight(self.frame.health:GetHeight())
predMine:Show()
else
predMine:Hide()
@@ -1178,10 +1216,29 @@ function SFrames.Player:UpdateHealPrediction()
predOther:SetPoint("TOPLEFT", self.frame.health, "TOPLEFT", currentWidth + mineWidth, 0)
predOther:SetPoint("BOTTOMLEFT", self.frame.health, "BOTTOMLEFT", currentWidth + mineWidth, 0)
predOther:SetWidth(otherWidth)
predOther:SetHeight(self.frame.health:GetHeight())
predOther:Show()
else
predOther:Hide()
end
local totalIncomingValue = mineIncoming + othersIncoming
local overHeal = totalIncomingValue - missing
if overHeal > 0 then
local overWidth = math.floor((overHeal / maxHp) * barWidth + 0.5)
if overWidth > 0 then
predOver:ClearAllPoints()
predOver:SetPoint("TOPLEFT", self.frame.health, "TOPRIGHT", 0, 0)
predOver:SetPoint("BOTTOMLEFT", self.frame.health, "BOTTOMRIGHT", 0, 0)
predOver:SetWidth(overWidth)
predOver:SetHeight(self.frame.health:GetHeight())
predOver:Show()
else
predOver:Hide()
end
else
predOver:Hide()
end
end
function SFrames.Player:UpdatePowerType()
@@ -1426,7 +1483,7 @@ end
--------------------------------------------------------------------------------
function SFrames.Player:CreateAuras()
-- Create 16 Buff Slots
-- Create 32 Buff Slots
self.frame.buffs = {}
self.frame.debuffs = {}
local size = 24
@@ -1434,7 +1491,7 @@ function SFrames.Player:CreateAuras()
local rowSpacing = 1
local buffsPerRow = 9
for i = 1, 16 do
for i = 1, 32 do
local b = CreateFrame("Button", "SFramesPlayerBuff"..i, self.frame)
b:SetWidth(size)
b:SetHeight(size)
@@ -1474,17 +1531,25 @@ end
function SFrames.Player:UpdateAuras()
local slotIdx = 0
local hasGetPlayerBuffID = SFrames.superwow_active and type(GetPlayerBuffID) == "function"
for i = 0, 31 do
local buffIndex, untilCancelled = GetPlayerBuff(i, "HELPFUL")
if buffIndex and buffIndex >= 0 then
if not SFrames:IsBuffHidden(buffIndex) then
slotIdx = slotIdx + 1
if slotIdx > 16 then break end
if slotIdx > 32 then break end
local b = self.frame.buffs[slotIdx]
local texture = GetPlayerBuffTexture(buffIndex)
if texture then
b.icon:SetTexture(texture)
b.buffIndex = buffIndex
-- Store aura ID when SuperWoW is available
if hasGetPlayerBuffID then
local ok, auraID = pcall(GetPlayerBuffID, buffIndex)
b.auraID = ok and auraID or nil
else
b.auraID = nil
end
b:Show()
local timeLeft = GetPlayerBuffTimeLeft(buffIndex)
@@ -1499,8 +1564,9 @@ function SFrames.Player:UpdateAuras()
end
end
end
for j = slotIdx + 1, 16 do
for j = slotIdx + 1, 32 do
self.frame.buffs[j]:Hide()
self.frame.buffs[j].auraID = nil
end
end
@@ -1544,6 +1610,63 @@ end
-- Player Castbar
--------------------------------------------------------------------------------
local function GetLatencySeconds()
if GetNetStats then
local _, _, latency = GetNetStats()
if latency and latency > 0 then return latency / 1000 end
end
return 0
end
local function HSVtoRGB(h, s, v)
local i = math.floor(h * 6)
local f = h * 6 - i
local p = v * (1 - s)
local q = v * (1 - f * s)
local t = v * (1 - (1 - f) * s)
local m = math.mod(i, 6)
if m == 0 then return v, t, p
elseif m == 1 then return q, v, p
elseif m == 2 then return p, v, t
elseif m == 3 then return p, q, v
elseif m == 4 then return t, p, v
else return v, p, q end
end
local RAINBOW_TEX_PATH = "Interface\\AddOns\\Nanami-UI\\img\\progress"
local RAINBOW_SEG_COORDS = {
{40/512, 473/512, 45/512, 169/512},
{40/512, 473/512, 194/512, 318/512},
{40/512, 473/512, 343/512, 467/512},
}
local function UpdateRainbowProgress(cb, progress)
if not cb.rainbowSegs then return end
local barWidth = cb:GetWidth()
if barWidth <= 0 then return end
local fillW = progress * barWidth
for i = 1, 3 do
local seg = cb.rainbowSegs[i]
local segL = barWidth * (i - 1) / 3
local segR = barWidth * i / 3
if fillW <= segL then
seg:Hide()
else
local visR = math.min(fillW, segR)
local frac = (visR - segL) / (segR - segL)
if visR >= segR and i < 3 then
visR = segR + 2
end
seg:ClearAllPoints()
seg:SetPoint("TOPLEFT", cb, "TOPLEFT", segL, 0)
seg:SetPoint("BOTTOMRIGHT", cb, "BOTTOMLEFT", visR, 0)
local c = seg.fullCoords
seg:SetTexCoord(c[1], c[1] + (c[2] - c[1]) * frac, c[3], c[4])
seg:Show()
end
end
end
function SFrames.Player:CreateCastbar()
local cb = SFrames:CreateStatusBar(self.frame, "SFramesPlayerCastbar")
cb:SetHeight(SFrames.Config.castbarHeight)
@@ -1581,6 +1704,23 @@ function SFrames.Player:CreateCastbar()
ibg:SetFrameLevel(cb:GetFrameLevel() - 1)
SFrames:CreateUnitBackdrop(ibg)
local lagTex = cb:CreateTexture(nil, "OVERLAY")
lagTex:SetTexture(SFrames:GetTexture())
lagTex:SetVertexColor(1, 0.2, 0.2, 0.5)
lagTex:Hide()
cb.lagTex = lagTex
cb.rainbowSegs = {}
for i = 1, 3 do
local tex = cb:CreateTexture(nil, "ARTWORK")
tex:SetTexture(RAINBOW_TEX_PATH)
local c = RAINBOW_SEG_COORDS[i]
tex:SetTexCoord(c[1], c[2], c[3], c[4])
tex.fullCoords = c
tex:Hide()
cb.rainbowSegs[i] = tex
end
cb:Hide()
cbbg:Hide()
cb.icon:Hide()
@@ -1591,7 +1731,9 @@ function SFrames.Player:CreateCastbar()
self.frame.castbar.ibg = ibg
cb:SetScript("OnUpdate", function() SFrames.Player:CastbarOnUpdate() end)
self:ApplyCastbarPosition()
-- Hook events
SFrames:RegisterEvent("SPELLCAST_START", function() self:CastbarStart(arg1, arg2) end)
SFrames:RegisterEvent("SPELLCAST_STOP", function() self:CastbarStop() end)
@@ -1603,6 +1745,60 @@ function SFrames.Player:CreateCastbar()
SFrames:RegisterEvent("SPELLCAST_CHANNEL_STOP", function() self:CastbarStop() end)
end
function SFrames.Player:ApplyCastbarPosition()
local cb = self.frame.castbar
if not cb then return end
local db = SFramesDB or {}
cb:ClearAllPoints()
cb.cbbg:ClearAllPoints()
cb.icon:ClearAllPoints()
cb.ibg:ClearAllPoints()
if db.castbarStandalone then
cb:SetParent(UIParent)
cb.cbbg:SetParent(UIParent)
cb.ibg:SetParent(UIParent)
cb:SetWidth(280)
cb:SetHeight(20)
cb:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 120)
cb:SetFrameStrata("HIGH")
cb.cbbg:SetPoint("TOPLEFT", cb, "TOPLEFT", -1, 1)
cb.cbbg:SetPoint("BOTTOMRIGHT", cb, "BOTTOMRIGHT", 1, -1)
cb.cbbg:SetFrameLevel(math.max(1, cb:GetFrameLevel() - 1))
cb.icon:SetWidth(22)
cb.icon:SetHeight(22)
cb.icon:SetPoint("RIGHT", cb, "LEFT", -4, 0)
cb.ibg:SetPoint("TOPLEFT", cb.icon, "TOPLEFT", -1, 1)
cb.ibg:SetPoint("BOTTOMRIGHT", cb.icon, "BOTTOMRIGHT", 1, -1)
cb.ibg:SetFrameLevel(math.max(1, cb:GetFrameLevel() - 1))
if SFrames.Movers and SFrames.Movers.RegisterMover then
SFrames.Movers:RegisterMover("PlayerCastbar", cb, "施法条",
"BOTTOM", "UIParent", "BOTTOM", 0, 120)
end
else
cb:SetParent(self.frame)
cb.cbbg:SetParent(self.frame)
cb.ibg:SetParent(self.frame)
local cbH = SFrames.Config.castbarHeight
cb:SetWidth(0) -- 清除独立模式的显式宽度,让双锚点自动计算
cb:SetHeight(cbH)
cb:SetPoint("BOTTOMRIGHT", self.frame, "TOPRIGHT", 0, 6)
cb:SetPoint("BOTTOMLEFT", self.frame.portrait, "TOPLEFT", cbH + 6, 6)
cb:SetFrameStrata("MEDIUM")
cb.cbbg:SetPoint("TOPLEFT", cb, "TOPLEFT", -1, 1)
cb.cbbg:SetPoint("BOTTOMRIGHT", cb, "BOTTOMRIGHT", 1, -1)
cb.cbbg:SetFrameLevel(math.max(1, cb:GetFrameLevel() - 1))
cb.icon:SetWidth(cbH + 2)
cb.icon:SetHeight(cbH + 2)
cb.icon:SetPoint("RIGHT", cb, "LEFT", -4, 0)
cb.ibg:SetPoint("TOPLEFT", cb.icon, "TOPLEFT", -1, 1)
cb.ibg:SetPoint("BOTTOMRIGHT", cb.icon, "BOTTOMRIGHT", 1, -1)
cb.ibg:SetFrameLevel(math.max(1, cb:GetFrameLevel() - 1))
end
end
function SFrames.Player:CastbarStart(spellName, duration)
local cb = self.frame.castbar
cb.casting = true
@@ -1648,6 +1844,23 @@ function SFrames.Player:CastbarStart(spellName, duration)
end
cb:Show()
cb.cbbg:Show()
local lag = GetLatencySeconds()
if lag > 0 and cb.maxValue > 0 then
local barW = cb:GetWidth()
local lagW = math.min((lag / cb.maxValue) * barW, barW * 0.5)
if lagW >= 1 then
cb.lagTex:ClearAllPoints()
cb.lagTex:SetPoint("TOPRIGHT", cb, "TOPRIGHT", 0, 0)
cb.lagTex:SetPoint("BOTTOMRIGHT", cb, "BOTTOMRIGHT", 0, 0)
cb.lagTex:SetWidth(lagW)
cb.lagTex:Show()
else
cb.lagTex:Hide()
end
else
cb.lagTex:Hide()
end
end
function SFrames.Player:CastbarChannelStart(duration, spellName)
@@ -1696,6 +1909,23 @@ function SFrames.Player:CastbarChannelStart(duration, spellName)
end
cb:Show()
cb.cbbg:Show()
local lag = GetLatencySeconds()
if lag > 0 and cb.maxValue > 0 then
local barW = cb:GetWidth()
local lagW = math.min((lag / cb.maxValue) * barW, barW * 0.5)
if lagW >= 1 then
cb.lagTex:ClearAllPoints()
cb.lagTex:SetPoint("TOPLEFT", cb, "TOPLEFT", 0, 0)
cb.lagTex:SetPoint("BOTTOMLEFT", cb, "BOTTOMLEFT", 0, 0)
cb.lagTex:SetWidth(lagW)
cb.lagTex:Show()
else
cb.lagTex:Hide()
end
else
cb.lagTex:Hide()
end
end
function SFrames.Player:CastbarStop()
@@ -1703,7 +1933,7 @@ function SFrames.Player:CastbarStop()
cb.casting = nil
cb.channeling = nil
cb.fadeOut = true
-- keep showing for a short fade out
if cb.lagTex then cb.lagTex:Hide() end
end
function SFrames.Player:CastbarDelayed(delay)
@@ -1714,18 +1944,17 @@ function SFrames.Player:CastbarDelayed(delay)
end
end
function SFrames.Player:CastbarChannelUpdate(delay)
function SFrames.Player:CastbarChannelUpdate(remainingMs)
local cb = self.frame.castbar
if cb.channeling then
local add = delay / 1000
cb.maxValue = cb.maxValue + add
cb.endTime = cb.endTime + add
cb:SetMinMaxValues(0, cb.maxValue)
cb.endTime = GetTime() + remainingMs / 1000
end
end
function SFrames.Player:CastbarOnUpdate()
local cb = self.frame.castbar
local db = SFramesDB or {}
if cb.casting then
local elapsed = GetTime() - cb.startTime
if elapsed >= cb.maxValue then
@@ -1736,6 +1965,19 @@ function SFrames.Player:CastbarOnUpdate()
end
cb:SetValue(elapsed)
cb.time:SetText(string.format("%.1f", math.max(cb.maxValue - elapsed, 0)))
if db.castbarRainbow then
if not cb.rainbowActive then
cb:SetStatusBarColor(0, 0, 0, 0)
cb.rainbowActive = true
end
UpdateRainbowProgress(cb, elapsed / cb.maxValue)
elseif cb.rainbowActive then
cb:SetStatusBarColor(1, 0.7, 0)
if cb.rainbowSegs then
for i = 1, 3 do cb.rainbowSegs[i]:Hide() end
end
cb.rainbowActive = nil
end
if not cb.icon:IsShown() then
self:CastbarTryResolveIcon()
end
@@ -1749,10 +1991,28 @@ function SFrames.Player:CastbarOnUpdate()
end
cb:SetValue(timeRemaining)
cb.time:SetText(string.format("%.1f", timeRemaining))
if db.castbarRainbow then
if not cb.rainbowActive then
cb:SetStatusBarColor(0, 0, 0, 0)
cb.rainbowActive = true
end
UpdateRainbowProgress(cb, timeRemaining / cb.maxValue)
elseif cb.rainbowActive then
cb:SetStatusBarColor(1, 0.7, 0)
if cb.rainbowSegs then
for i = 1, 3 do cb.rainbowSegs[i]:Hide() end
end
cb.rainbowActive = nil
end
if not cb.icon:IsShown() then
self:CastbarTryResolveIcon()
end
elseif cb.fadeOut then
if cb.rainbowActive then
for i = 1, 3 do cb.rainbowSegs[i]:Hide() end
cb:SetStatusBarColor(1, 0.7, 0)
cb.rainbowActive = nil
end
local alpha = cb:GetAlpha() - 0.05
if alpha > 0 then
cb:SetAlpha(alpha)