聊天重做前缓存

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

164
Core.lua
View File

@@ -32,6 +32,40 @@ do
end
end
-- 保护 ComboFrame防止 fadeInfo 为 nil 导致的报错
-- (ComboFrame.lua:46: attempt to index local 'fadeInfo' (a nil value))
if ComboFrame then
if not ComboFrame.fadeInfo then
ComboFrame.fadeInfo = {}
end
local origComboScript = ComboFrame.GetScript and ComboFrame:GetScript("OnUpdate")
if origComboScript then
ComboFrame:SetScript("OnUpdate", function(elapsed)
if ComboFrame.fadeInfo then
origComboScript(elapsed)
end
end)
end
end
if ComboFrame_Update then
local _orig_ComboUpdate = ComboFrame_Update
ComboFrame_Update = function()
if ComboFrame and not ComboFrame.fadeInfo then
ComboFrame.fadeInfo = {}
end
return _orig_ComboUpdate()
end
end
if ComboFrame_OnUpdate then
local _orig_ComboOnUpdate = ComboFrame_OnUpdate
ComboFrame_OnUpdate = function(elapsed)
if ComboFrame and not ComboFrame.fadeInfo then
ComboFrame.fadeInfo = {}
end
return _orig_ComboOnUpdate(elapsed)
end
end
local origOnUpdate = UIParent and UIParent.GetScript and UIParent:GetScript("OnUpdate")
if origOnUpdate then
UIParent:SetScript("OnUpdate", function()
@@ -43,6 +77,11 @@ end
BINDING_HEADER_NANAMI_UI = "Nanami-UI"
BINDING_NAME_NANAMI_TOGGLE_NAV = "切换导航地图"
BINDING_HEADER_NANAMI_EXTRABAR = "Nanami-UI 额外动作条"
for _i = 1, 48 do
_G["BINDING_NAME_NANAMI_EXTRABAR" .. _i] = "额外动作条 按钮" .. _i
end
SFrames.eventFrame = CreateFrame("Frame", "SFramesEventFrame", UIParent)
SFrames.events = {}
@@ -140,6 +179,52 @@ function SFrames:Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|c" .. hex .. "[Nanami-UI]|r " .. tostring(msg))
end
local function IsBattlefieldMinimapVisible()
if BattlefieldMinimap and BattlefieldMinimap.IsVisible and BattlefieldMinimap:IsVisible() then
return true
end
if BattlefieldMinimapFrame and BattlefieldMinimapFrame ~= BattlefieldMinimap
and BattlefieldMinimapFrame.IsVisible and BattlefieldMinimapFrame:IsVisible() then
return true
end
return false
end
function SFrames:CaptureBattlefieldMinimapState()
return IsBattlefieldMinimapVisible()
end
function SFrames:RestoreBattlefieldMinimapState(wasVisible)
if wasVisible then
return
end
local frames = { BattlefieldMinimap, BattlefieldMinimapFrame }
local hidden = {}
for i = 1, table.getn(frames) do
local frame = frames[i]
if frame and not hidden[frame] and frame.Hide and frame.IsVisible and frame:IsVisible() then
hidden[frame] = true
pcall(frame.Hide, frame)
end
end
end
function SFrames:CallWithPreservedBattlefieldMinimap(func, a1, a2, a3, a4, a5, a6, a7, a8)
if type(func) ~= "function" then
return
end
local state = self:CaptureBattlefieldMinimapState()
local results = { pcall(func, a1, a2, a3, a4, a5, a6, a7, a8) }
self:RestoreBattlefieldMinimapState(state)
if not results[1] then
return nil, results[2]
end
return unpack(results, 2, table.getn(results))
end
-- Addon Loaded Initializer
SFrames:RegisterEvent("PLAYER_LOGIN", function()
SFrames:Initialize()
@@ -299,6 +384,10 @@ function SFrames:DoFullInitialize()
SFrames.Tooltip:SetAlpha(0)
SFrames.Tooltip:Hide()
if SFrames.AuraTracker and SFrames.AuraTracker.Initialize then
SFrames.AuraTracker:Initialize()
end
-- Phase 1: Critical modules (unit frames, action bars) — must load immediately
if SFramesDB.enableUnitFrames ~= false then
if SFramesDB.enablePlayerFrame ~= false then
@@ -319,6 +408,10 @@ function SFrames:DoFullInitialize()
SFrames.ActionBars:Initialize()
end
if SFrames.ExtraBar and SFrames.ExtraBar.Initialize then
SFrames.ExtraBar:Initialize()
end
self:InitSlashCommands()
-- Phase 2: Deferred modules — spread across multiple frames to avoid memory spike
@@ -375,6 +468,13 @@ function SFrames:GetAuraTimeLeft(unit, index, isBuff)
end
end
if SFrames.AuraTracker and SFrames.AuraTracker.GetAuraTimeLeft then
local trackerTime = SFrames.AuraTracker:GetAuraTimeLeft(unit, isBuff and "buff" or "debuff", index)
if trackerTime and trackerTime > 0 then
return trackerTime
end
end
-- Nanami-Plates SpellDB: combat log + spell DB tracking (most accurate for debuffs)
if not isBuff and NanamiPlates_SpellDB and NanamiPlates_SpellDB.UnitDebuff then
local effect, rank, tex, stacks, dtype, duration, timeleft, isOwn = NanamiPlates_SpellDB:UnitDebuff(unit, index)
@@ -420,6 +520,64 @@ function SFrames:FormatTime(seconds)
end
end
local POWER_RAINBOW_TEX = "Interface\\AddOns\\Nanami-UI\\img\\progress"
function SFrames:UpdateRainbowBar(bar, power, maxPower, unit)
-- 彩虹条仅适用于法力powerType 0怒气/能量等跳过
if unit and UnitPowerType(unit) ~= 0 then
if bar._rainbowActive then
if bar.rainbowTex then bar.rainbowTex:Hide() end
bar._rainbowActive = nil
end
return
end
if not (SFramesDB and SFramesDB.powerRainbow) then
if bar._rainbowActive then
if bar.rainbowTex then bar.rainbowTex:Hide() end
bar._rainbowActive = nil
end
return
end
if not bar.rainbowTex then
bar.rainbowTex = bar:CreateTexture(nil, "OVERLAY")
bar.rainbowTex:SetTexture(POWER_RAINBOW_TEX)
bar.rainbowTex:Hide()
end
if maxPower and maxPower > 0 then
local pct = power / maxPower
if pct >= 1.0 then
-- 满条:直接铺满,不依赖 GetWidth()(两锚点定尺寸的框体 GetWidth 可能返回 0
bar.rainbowTex:ClearAllPoints()
bar.rainbowTex:SetAllPoints(bar)
bar.rainbowTex:SetTexCoord(0, 1, 0, 1)
bar.rainbowTex:Show()
bar._rainbowActive = true
else
local barW = bar:GetWidth()
-- 双锚点定尺寸的框体如宠物能量条GetWidth() 可能返回 0
-- 回退到 GetRight()-GetLeft() 获取实际渲染宽度
if not barW or barW <= 0 then
local left = bar:GetLeft()
local right = bar:GetRight()
if left and right then
barW = right - left
end
end
if barW and barW > 0 then
bar.rainbowTex:ClearAllPoints()
bar.rainbowTex:SetPoint("TOPLEFT", bar, "TOPLEFT", 0, 0)
bar.rainbowTex:SetPoint("BOTTOMRIGHT", bar, "BOTTOMLEFT", barW * pct, 0)
bar.rainbowTex:SetTexCoord(0, pct, 0, 1)
bar.rainbowTex:Show()
bar._rainbowActive = true
end
end
else
bar.rainbowTex:Hide()
bar._rainbowActive = nil
end
end
function SFrames:InitSlashCommands()
DEFAULT_CHAT_FRAME:AddMessage("SF: InitSlashCommands called.")
SLASH_SFRAMES1 = "/nanami"
@@ -808,12 +966,16 @@ function SFrames:HideBlizzardFrames()
end
if ComboFrame then
ComboFrame:UnregisterAllEvents()
ComboFrame:SetScript("OnUpdate", nil)
ComboFrame:Hide()
ComboFrame.Show = function() end
ComboFrame.fadeInfo = ComboFrame.fadeInfo or {}
ComboFrame.fadeInfo = {}
if ComboFrame_Update then
ComboFrame_Update = function() end
end
if ComboFrame_OnUpdate then
ComboFrame_OnUpdate = function() end
end
end
end