Repository navigation
Expand file tree
/
Copy pathCinematicChat.lua
More file actions
73 lines (64 loc) · 2.65 KB
/
Copy pathCinematicChat.lua
File metadata and controls
73 lines (64 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local ADDON, ns = ...
-- Chat input is a temporary Cinematic target override. It never Show/Hide's
-- chat frames directly: Core reveals the canonical Chat target, allowing the
-- Blizzard fallback or Ellesmere whole-chat adapter to retain ownership.
local hooked = false
local activateHooked = false
local deactivateHooked = false
local function Secret(value)
if type(issecretvalue) ~= "function" then return false end
local ok, secret = pcall(issecretvalue, value)
return ok and secret == true
end
local function ActiveEditBox()
if type(ChatEdit_GetActiveWindow) ~= "function" then return nil, false end
local ok, editBox = pcall(ChatEdit_GetActiveWindow)
if not ok or Secret(editBox) then return nil, false end
return editBox, true
end
local function SetInputActive(active)
if ns.SetCinematicChatInputActive then ns:SetCinematicChatInputActive(active) end
end
local function OnActivated()
SetInputActive(true)
end
local function OnDeactivated()
local function ConfirmInactive()
local editBox, readable = ActiveEditBox()
-- If Retail protects this value, fail visible until the next readable
-- lifecycle signal rather than hiding chat while the player may type.
if readable then SetInputActive(editBox ~= nil) end
end
if C_Timer and type(C_Timer.After) == "function" then
C_Timer.After(0, ConfirmInactive)
else
ConfirmInactive()
end
end
local function HookChatLifecycle()
if hooked or type(hooksecurefunc) ~= "function" then return hooked end
if type(ChatFrameUtil) == "table" then
if not activateHooked and type(ChatFrameUtil.ActivateChat) == "function" then
activateHooked = pcall(hooksecurefunc, ChatFrameUtil, "ActivateChat", OnActivated)
end
if not deactivateHooked and type(ChatFrameUtil.DeactivateChat) == "function" then
deactivateHooked = pcall(hooksecurefunc, ChatFrameUtil, "DeactivateChat", OnDeactivated)
end
end
if not activateHooked and type(ChatEdit_ActivateChat) == "function" then
activateHooked = pcall(hooksecurefunc, "ChatEdit_ActivateChat", OnActivated)
end
if not deactivateHooked and type(ChatEdit_DeactivateChat) == "function" then
deactivateHooked = pcall(hooksecurefunc, "ChatEdit_DeactivateChat", OnDeactivated)
end
hooked = activateHooked and deactivateHooked
local editBox, readable = ActiveEditBox()
if readable then SetInputActive(editBox ~= nil) end
return hooked
end
local events = CreateFrame("Frame")
events:RegisterEvent("PLAYER_LOGIN")
events:RegisterEvent("ADDON_LOADED")
events:SetScript("OnEvent", function()
HookChatLifecycle()
end)