修改优化等

This commit is contained in:
rucky
2026-03-18 02:01:36 +08:00
parent 2a55dd6dad
commit 923a1f9ce2
15 changed files with 1578 additions and 371 deletions

View File

@@ -110,6 +110,22 @@ end
function AFK:Build()
if self.frame then return end
local existing = getglobal("NanamiAFKScreen")
if existing then
existing:SetScript("OnUpdate", nil)
existing:SetScript("OnKeyDown", nil)
existing:SetScript("OnMouseDown", nil)
existing:EnableKeyboard(false)
existing:EnableMouse(false)
existing:Hide()
end
local existingWatcher = getglobal("NanamiAFKWatcher")
if existingWatcher then
existingWatcher:SetScript("OnUpdate", nil)
existingWatcher:Hide()
end
local f = CreateFrame("Frame", "NanamiAFKScreen", WorldFrame)
f:SetFrameStrata("FULLSCREEN_DIALOG")
f:SetFrameLevel(100)
@@ -947,7 +963,7 @@ function AFK:ScanWorldBuffs()
local matched = {}
if not self._buffTip then
self._buffTip = CreateFrame("GameTooltip", "NanamiAFKBuffTip", WorldFrame, "GameTooltipTemplate")
self._buffTip = getglobal("NanamiAFKBuffTip") or CreateFrame("GameTooltip", "NanamiAFKBuffTip", UIParent, "GameTooltipTemplate")
end
-- Build texture → remaining time mapping
@@ -1149,7 +1165,7 @@ end
--------------------------------------------------------------------------------
function AFK:OnUpdate(elapsed)
if not elapsed then return end
if not elapsed or not self.frame then return end
-- Fade logic
if self.fadeDirection then
@@ -1209,6 +1225,7 @@ function AFK:OnUpdate(elapsed)
-- Particle animation
local now = GetTime()
if not self.particles then return end
local sw = self.frame:GetWidth()
local sh = self.frame:GetHeight()
if sw < 100 then sw = 1024 end
@@ -1329,6 +1346,39 @@ function AFK:ForceHide()
UIParent:Show()
end
function AFK:Cleanup()
if self.model and self.model.ClearModel then
pcall(function() self.model:ClearModel() end)
end
if self.frame then
self.frame:SetScript("OnUpdate", nil)
self.frame:SetScript("OnKeyDown", nil)
self.frame:SetScript("OnMouseDown", nil)
self.frame:EnableKeyboard(false)
self.frame:EnableMouse(false)
self.frame:Hide()
self.frame:SetAlpha(0)
end
local watcher = getglobal("NanamiAFKWatcher")
if watcher then
watcher:SetScript("OnUpdate", nil)
watcher:Hide()
end
if self._buffTip then
self._buffTip:Hide()
end
self.isShowing = false
self.fadeDirection = nil
self._exiting = false
self._danceWait = nil
UIParent:Show()
end
function AFK:RequestExit()
if self._exiting then return end
self:Hide()
@@ -1413,6 +1463,9 @@ end
--------------------------------------------------------------------------------
function AFK:Initialize()
UIParent:Show()
self:Cleanup()
self:Build()
self._isAFK = false
self._lastActivity = GetTime()
@@ -1421,30 +1474,32 @@ function AFK:Initialize()
AFK._lastActivity = GetTime()
end
-- Hook action bar usage
local origUseAction = UseAction
UseAction = function(a1, a2, a3)
MarkActive()
return origUseAction(a1, a2, a3)
end
if not self._hooked then
self._hooked = true
if CastSpellByName then
local origCast = CastSpellByName
CastSpellByName = function(a1, a2)
local origUseAction = UseAction
UseAction = function(a1, a2, a3)
MarkActive()
return origCast(a1, a2)
return origUseAction(a1, a2, a3)
end
if CastSpellByName then
local origCast = CastSpellByName
CastSpellByName = function(a1, a2)
MarkActive()
return origCast(a1, a2)
end
end
if JumpOrAscendStart then
local origJump = JumpOrAscendStart
JumpOrAscendStart = function()
MarkActive()
return origJump()
end
end
end
if JumpOrAscendStart then
local origJump = JumpOrAscendStart
JumpOrAscendStart = function()
MarkActive()
return origJump()
end
end
-- Events that indicate LOCAL player activity (not other players)
local activityEvents = {
"PLAYER_STARTED_MOVING", "PLAYER_STOPPED_MOVING",
"SPELLCAST_START", "SPELLCAST_STOP",
@@ -1457,17 +1512,16 @@ function AFK:Initialize()
SFrames:RegisterEvent(ev, function() AFK:ResetIdleTimer() end)
end
-- Watcher frame: tracks cursor movement + checks idle time
local watcher = CreateFrame("Frame", "NanamiAFKWatcher", UIParent)
local watcher = getglobal("NanamiAFKWatcher") or CreateFrame("Frame", "NanamiAFKWatcher", UIParent)
watcher._checkTimer = 0
watcher._lastCursorX = 0
watcher._lastCursorY = 0
watcher:Show()
watcher:SetScript("OnUpdate", function()
this._checkTimer = (this._checkTimer or 0) + arg1
if this._checkTimer < 1 then return end
this._checkTimer = 0
-- Detect mouse cursor movement (catches all mouse activity)
local cx, cy = GetCursorPosition()
if cx ~= this._lastCursorX or cy ~= this._lastCursorY then
this._lastCursorX = cx
@@ -1494,7 +1548,6 @@ function AFK:Initialize()
end
end)
-- Server AFK message as secondary instant trigger
SFrames:RegisterEvent("CHAT_MSG_SYSTEM", function()
AFK:OnSystemMessage(arg1)
end)
@@ -1526,4 +1579,8 @@ function AFK:Initialize()
end
end
end)
SFrames:RegisterEvent("PLAYER_LEAVING_WORLD", function()
AFK:Cleanup()
end)
end