-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
history.lua
100 lines (90 loc) · 2.85 KB
/
history.lua
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
--[[ History Module ]]--
local _, BCM = ...
BCM.earlyModules[#BCM.earlyModules+1] = function()
if bcmDB.BCM_History then bcmDB.lines, bcmDB.savedChat = nil, nil end
if not bcmDB.lines then bcmDB.lines = {["ChatFrame1"] = 1000} end
for k, v in next, bcmDB.lines do
local f = _G[k]
f.historyBuffer.maxElements = v
if k == "ChatFrame2" then
COMBATLOG_MESSAGE_LIMIT = v -- Blizzard keeps changing the combat log max lines in Blizzard_CombatLog_Refilter... this better not cause taint issues.
end
end
if true and bcmDB.savedChat then
for k, v in next, bcmDB.savedChat do
local cF = _G[k]
if cF then
local buffer = cF.historyBuffer
local num = buffer.headIndex
local prevElements = buffer.elements
local curTime = GetTime()
local restore = {
{message = "|cFF33FF99BasicChatMods|r: ---Begin chat restore---", timestamp = curTime},
}
for i = 1, #v do
local tbl = v[i]
tbl.timestamp = curTime -- Update timestamp on restored chat. If it's really old, it will show as hidden after the reload.
restore[#restore+1] = tbl
end
restore[#restore+1] = {message = "|cFF33FF99BasicChatMods|r: ---Chat restored from reload---", timestamp = curTime}
for i = 1, num do -- Restore any early chat we removed (usually addon prints)
local element = prevElements[i]
if element then -- Safety
element.timestamp = curTime
restore[#restore+1] = element
end
end
buffer.headIndex = #restore
for i = 1, #restore do
prevElements[i] = restore[i]
restore[i] = nil
end
end
end
end
bcmDB.savedChat = nil
if true then -- XXX add an option
local isReloadingUI = 0
BCM.Events.PLAYER_LOGOUT = function()
if (GetTime() - isReloadingUI) > 2 then return end
bcmDB.savedChat = {}
for cfNum = 1, BCM.chatFrames do
if cfNum ~= 2 then -- No combat log
local name = ("ChatFrame%d"):format(cfNum)
local cf = _G[name]
if cf then
local tbl = {1, 2, 3, 4, 5}
local num = cf.historyBuffer.headIndex
local tblCount = 5
for i = num, -10, -1 do
if i > 0 then
if type(cf.historyBuffer.elements[i]) == "table" and cf.historyBuffer.elements[i].message then -- Compensate for nil entries
tbl[tblCount] = cf.historyBuffer.elements[i]
tblCount = tblCount - 1
if tblCount == 0 then
break
end
end
else -- Compensate for less than 5 lines of history
if tblCount > 0 then
tremove(tbl, tblCount)
tblCount = tblCount - 1
else
break
end
end
end
if #tbl > 0 then
bcmDB.savedChat[name] = tbl
end
end
end
end
end
BCM.Events:RegisterEvent("PLAYER_LOGOUT")
BCM.Events.LOADING_SCREEN_ENABLED = function()
isReloadingUI = GetTime()
end
BCM.Events:RegisterEvent("LOADING_SCREEN_ENABLED")
end
end