-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXanChat.lua
2104 lines (1766 loc) · 71.4 KB
/
XanChat.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local ADDON_NAME, addon = ...
if not _G[ADDON_NAME] then
_G[ADDON_NAME] = CreateFrame("Frame", ADDON_NAME, UIParent, BackdropTemplateMixin and "BackdropTemplate")
end
addon = _G[ADDON_NAME]
local debugf = tekDebug and tekDebug:GetFrame(ADDON_NAME)
local function Debug(...)
if debugf then debugf:AddMessage(string.join(", ", tostringall(...))) end
end
local WOW_PROJECT_ID = _G.WOW_PROJECT_ID
local WOW_PROJECT_MAINLINE = _G.WOW_PROJECT_MAINLINE
local WOW_PROJECT_CLASSIC = _G.WOW_PROJECT_CLASSIC
--local WOW_PROJECT_BURNING_CRUSADE_CLASSIC = _G.WOW_PROJECT_BURNING_CRUSADE_CLASSIC
local WOW_PROJECT_WRATH_CLASSIC = _G.WOW_PROJECT_WRATH_CLASSIC
addon.IsRetail = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
addon.IsClassic = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
--BSYC.IsTBC_C = WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC
addon.IsWLK_C = WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC
--We need to use a customFrame since AceEvent is loaded and it takes over the RegisterEvent frames
local eventFrame = CreateFrame("Frame", ADDON_NAME.."EventFrame", UIParent, BackdropTemplateMixin and "BackdropTemplate")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", function(self, event, ...)
if event == "ADDON_LOADED" or event == "PLAYER_LOGIN" then
if event == "ADDON_LOADED" then
local arg1 = ...
if arg1 and arg1 == ADDON_NAME then
eventFrame:UnregisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
end
return
end
if IsLoggedIn() then
addon:EnableAddon(event, ...)
eventFrame:UnregisterEvent("PLAYER_LOGIN")
eventFrame = nil
end
return
end
end)
local L = LibStub("AceLocale-3.0"):GetLocale(ADDON_NAME)
LibStub("AceEvent-3.0"):Embed(addon)
--[[------------------------
Scrolling and Chat Links
--------------------------]]
local addonLoaded = false
local function scrollChat(frame, delta)
--Faster Scroll
if IsControlKeyDown() then
--Faster scrolling by triggering a few scroll up in a loop
if ( delta > 0 ) then
for i = 1,5 do frame:ScrollUp(); end;
elseif ( delta < 0 ) then
for i = 1,5 do frame:ScrollDown(); end;
end
elseif IsAltKeyDown() then
--Scroll to the top or bottom
if ( delta > 0 ) then
frame:ScrollToTop();
elseif ( delta < 0 ) then
frame:ScrollToBottom();
end
else
--Normal Scroll
if delta > 0 then
frame:ScrollUp()
elseif delta < 0 then
frame:ScrollDown()
end
end
end
--[[------------------------
URL COPY
--------------------------]]
local function doColor(url)
url = " |cff99FF33|Hurl:"..url.."|h["..url.."]|h|r "
return url
end
local function urlFilter(self, event, msg, author, ...)
if strfind(msg, "(%a+)://(%S+)%s?") then
return false, gsub(msg, "(%a+)://(%S+)%s?", doColor("%1://%2")), author, ...
end
if strfind(msg, "www%.([_A-Za-z0-9-]+)%.(%S+)%s?") then
return false, gsub(msg, "www%.([_A-Za-z0-9-]+)%.(%S+)%s?", doColor("www.%1.%2")), author, ...
end
if strfind(msg, "([_A-Za-z0-9-%.]+)@([_A-Za-z0-9-]+)(%.+)([_A-Za-z0-9-%.]+)%s?") then
return false, gsub(msg, "([_A-Za-z0-9-%.]+)@([_A-Za-z0-9-]+)(%.+)([_A-Za-z0-9-%.]+)%s?", doColor("%1@%2%3%4")), author, ...
end
if strfind(msg, "(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?):(%d%d?%d?%d?%d?)%s?") then
return false, gsub(msg, "(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?):(%d%d?%d?%d?%d?)%s?", doColor("%1.%2.%3.%4:%5")), author, ...
end
if strfind(msg, "(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%s?") then
return false, gsub(msg, "(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%s?", doColor("%1.%2.%3.%4")), author, ...
end
if strfind(msg, "[wWhH][wWtT][wWtT][\46pP]%S+[^%p%s]") then
return false, gsub(msg, "[wWhH][wWtT][wWtT][\46pP]%S+[^%p%s]", doColor("%1")), author, ...
end
end
StaticPopupDialogs["LINKME"] = {
text = L.URLCopy,
button2 = CANCEL,
hasEditBox = true,
hasWideEditBox = true,
timeout = 0,
exclusive = 1,
hideOnEscape = 1,
EditBoxOnEscapePressed = function(self) self:GetParent():Hide() end,
whileDead = 1,
maxLetters = 255,
}
local SetHyperlink = _G.ItemRefTooltip.SetHyperlink
function _G.ItemRefTooltip:SetHyperlink(link, ...)
if type(link) ~= "string" then return end
if link and (strsub(link, 1, 3) == "url") then
local url = strsub(link, 5)
local dialog = StaticPopup_Show("LINKME")
local editbox = _G[dialog:GetName().."EditBox"]
editbox:SetText(url)
editbox:SetFocus()
editbox:HighlightText()
local button = _G[dialog:GetName().."Button2"]
button:ClearAllPoints()
button:SetPoint("CENTER", editbox, "CENTER", 0, -30)
return
end
SetHyperlink(self, link, ...)
end
--register them all
for group, values in pairs(ChatTypeGroup) do
for _, value in pairs(values) do
ChatFrame_AddMessageEventFilter(value, urlFilter)
end
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_ADDON", urlFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_ADDON_LOGGED", urlFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND", urlFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND_LEADER", urlFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_CONVERSATION", urlFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_CONVERSATION_LIST", urlFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_CONVERSATION_NOTICE", urlFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_INLINE_TOAST_CONVERSATION", urlFilter)
--[[------------------------
Stylized Player Names
--------------------------]]
--https://www.wowinterface.com/forums/showthread.php?t=39328
local messageIndex = 0
local lastMsgEvent = {}
local function playerInfoFilter(self, event, msg, author, arg1, arg2, arg3, ...)
if not addon.isFilterListEnabled or not XCHT_DB.enablePlayerChatStyle then return false end
--capture the events for AddMessage since they aren't forwarded. Filters always go first before AddMessage
--use a messageIndex to keep track when messages are filtered or not, otherwise AddMessage can have something sent that didn't go through these filters.
messageIndex = messageIndex + 1
lastMsgEvent = {event=event, msg=msg, author=author, messageIndex=messageIndex, arg1=arg1, arg2=arg2, arg3=arg3}
return false
end
--register them all
for group, values in pairs(ChatTypeGroup) do
for _, value in pairs(values) do
ChatFrame_AddMessageEventFilter(value, playerInfoFilter)
end
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_ADDON", playerInfoFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_ADDON_LOGGED", playerInfoFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND", playerInfoFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BATTLEGROUND_LEADER", playerInfoFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_CONVERSATION", playerInfoFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_CONVERSATION_LIST", playerInfoFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_CONVERSATION_NOTICE", playerInfoFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_BN_INLINE_TOAST_CONVERSATION", playerInfoFilter)
local function ToHex(r, g, b, a)
return string.format('%02X%02X%02X%02X', a * 255, r * 255, g * 255, b * 255)
end
--this is used as a super last resort
local function slowPlayerLinkStrip(msg)
if not msg then return end
local newMsg = msg
local playerLink, player
local p1_Start, p1_End
local p2_Start, p2_End
local p3_Start, p3_End
--lets grab the first part
p1_Start, p1_End = string.find(newMsg, "|Hplayer:", 1, true)
--do we have anything to work with on first part
if p1_Start and p1_End then
--lets edit the message and move the pointer forward
newMsg = newMsg:sub(p1_End + 1)
--lets grab the second part
if newMsg then
p2_Start, p2_End = string.find(newMsg, "|h[", 1, true)
end
--do we have anything to work with on second part
if p2_Start and p2_End then
--first grab the playerLink
playerLink = newMsg:sub(1, p2_Start - 1)
--now move the pointer forward
newMsg = newMsg:sub(p2_End + 1)
--finally check for our third part
if newMsg then
p3_Start, p3_End = string.find(newMsg, "]|h", 1, true)
end
--do we have anything to work with?
if p3_Start and p3_End then
player = newMsg:sub(1, p3_Start - 1)
--if we have playerlink and player then return it, otherwise nil
if playerLink and player then
return playerLink, player
end
end
end
end
end
--string.gsub has issues with special characters when doing replaces. So use this instead
local function plainTextReplace(text, old, new)
local b, e = text:find(old, 1, true)
if b == nil then
return text, false
else
return text:sub(1,b-1)..new..text:sub(e+1), true
end
end
local function stripAndLowercase(text)
text = string.lower(text)
text = text:gsub("%s+", "") --remove empty spaces
return text
end
local function ContainsWholeWord(input, word)
--return string.find(input, "%f[%a]" .. word .. "%f[%A]")
return string.find(input, "%f[^%z%s]"..word.."%f[%z%s]")
end
local function replaceText(source, findStr, replaceStr, wholeword)
if wholeword then
--findStr = '%f[%a]'..findStr..'%f[%A]' --does not properly escape certain characters like : and /
findStr = "%f[^%z%s]"..findStr.."%f[%z%s]"
end
return (source:gsub(findStr, replaceStr))
end
local function parsePlayerInfo(frame, text, ...)
--local red, green, blue, messageId, holdTime = ...
text = text or "" --fix string just in case, avoid nulls
local playerLink, player, pmsg
playerLink, player, pmsg = string.match(text, "|Hplayer:(.-)|h%[(.-)%]|h(.+)")
if not playerLink or not player then
--only use this if top fails
playerLink, player = slowPlayerLinkStrip(text)
end
--gsub(message, '|HBNplayer:(.-)|h%[(.-)%]|h', FormatBNPlayer)
if playerLink and player then
--check if our actual player has a hyphen server
local chkPlayer, chkServer = player:match("([^%-]+)%-?(.*)")
local linkName, linkMessageID, linkChannel = strsplit(":", playerLink)
local playerName, playerServer
if linkName then
playerName, playerServer = linkName:match("([^%-]+)%-?(.*)")
if not playerName or not playerServer then
if chkPlayer and chkServer and string.len(chkPlayer) > 0 and string.len(chkServer) > 0 then
playerName = chkPlayer
playerServer = chkServer
else
--last case scenario, using a really crappy method
local findFirst = string.find(linkName, "-", 1, true)
if findFirst then
playerName = string.sub(linkName, 1, findFirst - 1)
playerServer = string.sub(linkName, findFirst + 1)
else
--didn't find anything, so give up
return
end
end
end
end
if not playerName or not playerServer then return end
if string.len(playerName) <= 0 or string.len(playerServer) <= 0 then return end
local playerInfo
--lets check our list
if addon.playerList[playerName.."@"..stripAndLowercase(playerServer)] then
playerInfo = addon.playerList[playerName.."@"..stripAndLowercase(playerServer)]
elseif addon.playerList[playerName.."@"..playerServer] then
playerInfo = addon.playerList[playerName.."@"..playerServer]
elseif addon.playerList[stripAndLowercase(playerName).."@"..stripAndLowercase(playerServer)] then
playerInfo = addon.playerList[stripAndLowercase(playerName).."@"..stripAndLowercase(playerServer)]
else
--last resort for playername checking
for k, v in pairs(addon.playerList) do
--just in case
if k and v then
local pN, pR = strsplit("@", k)
if pN and pR and pN == playerName then
playerInfo = v
break
end
end
end
end
if not playerInfo then return end
--Debug(playerInfo.name, playerInfo.realm, playerInfo.level, playerInfo.class, playerInfo.BNname)
local playerLevel = playerInfo.level
local colorFunc = GetQuestDifficultyColor or GetDifficultyColor
local color = colorFunc(playerLevel)
if color and playerInfo.level > 0 then
--local colorCode = RGBTableToColorCode(colorFunc(playerLevel))
local colorCode = ToHex(color.r, color.g, color.b, 1)
if colorCode then
playerLevel = "|c"..colorCode..playerLevel.."|r"
return "|Hplayer:"..playerLink.."|h["..player.."]|h", "|Hplayer:"..playerLink.."|h["..playerLevel..":"..player.."]|h", playerLink, player, playerName, playerServer, playerInfo
end
end
end
end
local function addToPlayerList(name, realm, level, class, BNname)
if not name or not level or not class then return end
if not addon.playerList then addon.playerList = {} end
if level <= 0 then return end --don't store anything with no actual level
--do the class list if it's missing, this is to check for localized classes, so we can get proper color
if not addon.chkClassList then
addon.chkClassList = {}
for i = 1, GetNumClasses() do
local className, classFile, classID = GetClassInfo(i)
if className and classFile then
addon.chkClassList[className] = classFile
end
end
end
local playerName, playerServer = name:match("([^%-]+)%-?(.*)")
if playerName and string.len(playerName) > 0 then
name = playerName
end
if playerServer and string.len(playerServer) > 0 then
realm = playerServer
end
--one last try
-- if not realm and string.find(name, "-", 1 true) then
-- playerName = string.sub(linkName, 1, findFirst - 1)
-- playerServer = string.sub(linkName, findFirst + 1)
-- if playerServer and string.len(playerServer) > 0 then
-- realm = playerServer
-- end
-- end
if not realm or string.len(realm) <= 0 then
realm = GetRealmName()
end
if not name or not realm then return end
--fix the class color if needed, get the non-local blizzard one, that way we can grab the correct color
if addon.chkClassList[class] then class = addon.chkClassList[class] end
addon.playerList[name.."@"..stripAndLowercase(realm)] = {name=name, realm=realm, stripRealm=stripAndLowercase(realm), level=level, class=class, BNname=BNname}
end
local function initUpdateCurrentPlayer()
local class = select(2, UnitClass("player"))
local name, realm = UnitName("player")
local level = UnitLevel("player")
addToPlayerList(name, realm, level, class)
end
local function doRosterUpdate()
local chkRaid = IsInRaid()
local IsInGroup = chkRaid or IsInGroup()
if IsInGroup then
local playerNum, unit = (chkRaid and GetNumGroupMembers()) or MAX_PARTY_MEMBERS, (chkRaid and "raid") or "party"
for i = 1, playerNum do
if UnitExists(unit..i) then
local playerName, playerServer = UnitName(unit..i)
local _, class = UnitClass(unit..i)
local level = UnitLevel(unit..i)
addToPlayerList(playerName, playerServer, level, class)
end
end
end
end
local function doFriendUpdate()
for i = 1, C_FriendList.GetNumFriends() do
local info = C_FriendList.GetFriendInfoByIndex(i)
--make sure they are online
if info and info.connected then
addToPlayerList(info.name, GetRealmName(), info.level, info.className)
end
end
if C_BattleNet then
local numBNet, onlineBNet = BNGetNumFriends()
for i = 1, numBNet do
local accountInfo = C_BattleNet.GetFriendAccountInfo(i)
if accountInfo and accountInfo.gameAccountInfo then
local friendInfo = accountInfo.gameAccountInfo
--make sure they are online and playing WOW
if friendInfo and friendInfo.isOnline and friendInfo.clientProgram == BNET_CLIENT_WOW then
--Whether or not the friend is known by their BattleTag
local friendAccountName = accountInfo.isBattleTagFriend and accountInfo.battleTag or accountInfo.accountName
if friendInfo.characterName and friendInfo.realmName and friendInfo.characterLevel and friendInfo.className then
addToPlayerList(friendInfo.characterName, friendInfo.realmName, friendInfo.characterLevel, friendInfo.className, friendAccountName)
end
end
end
end
end
end
local function doGuildUpdate()
if IsInGuild() then
C_GuildInfo.GuildRoster()
for i = 1, GetNumGuildMembers(true) do
local name, _, _, level, _, _, _, _, online, _, class = GetGuildRosterInfo(i)
if online then
--only do online players
local playerName, playerServer = name:match("([^%-]+)%-?(.*)")
if playerName and playerServer then
addToPlayerList(playerName, playerServer, level, class)
else
addToPlayerList(name, GetRealmName(), level, class)
end
end
end
end
end
local function initPlayerInfo()
if not XCHT_DB.enablePlayerChatStyle then return end
addon:RegisterEvent("GUILD_ROSTER_UPDATE", function() doGuildUpdate() end)
addon:RegisterEvent("FRIENDLIST_UPDATE", function() doFriendUpdate() end)
addon:RegisterEvent("BN_FRIEND_ACCOUNT_ONLINE", function() doFriendUpdate() end)
addon:RegisterEvent("RAID_ROSTER_UPDATE", function() doRosterUpdate() end)
addon:RegisterEvent("PLAYER_ENTERING_WORLD", function() doRosterUpdate() end)
addon:RegisterEvent("UPDATE_INSTANCE_INFO", function() doRosterUpdate() end)
addon:RegisterEvent("ZONE_CHANGED_NEW_AREA", function() doRosterUpdate() end)
addon:RegisterEvent("UNIT_NAME_UPDATE", function() doRosterUpdate() end)
addon:RegisterEvent("UNIT_PORTRAIT_UPDATE", function() doRosterUpdate() end)
addon:RegisterEvent("GROUP_ROSTER_UPDATE", function() doRosterUpdate() end)
addon:RegisterEvent("PLAYER_LEVEL_UP", function() initUpdateCurrentPlayer() end)
end
--[[------------------------
CORE LOAD
--------------------------]]
local dummy = function(self) self:Hide() end
local msgHooks = {}
local HistoryDB
StaticPopupDialogs["XANCHAT_APPLYCHANGES"] = {
text = L.ApplyChanges,
button1 = L.Yes,
button2 = L.No,
OnShow = function ()
addon.xanChatReloadPopup = true
end,
OnHide = function ()
addon.xanChatReloadPopup = false
end,
OnAccept = function()
ReloadUI()
end,
OnCancel = function ()
addon.xanChatReloadPopup = false
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
local lastMsgIndex = 0
local AddMessage = function(frame, text, ...)
if XCHT_DB.shortNames and type(text) == "string" then
local chatNum = string.match(text,"%d+") or ""
if not tonumber(chatNum) then chatNum = "" else chatNum = chatNum..":" end
text = gsub(text, L.ChannelGeneral, "["..chatNum..L.ShortGeneral.."]")
text = gsub(text, L.ChannelTradeServices, "["..chatNum..L.ShortTradeServices.."]")
text = gsub(text, L.ChannelTrade, "["..chatNum..L.ShortTrade.."]")
text = gsub(text, L.ChannelWorldDefense, "["..chatNum..L.ShortWorldDefense.."]")
text = gsub(text, L.ChannelLocalDefense, "["..chatNum..L.ShortLocalDefense.."]")
text = gsub(text, L.ChannelLookingForGroup, "["..chatNum..L.ShortLookingForGroup.."]")
text = gsub(text, L.ChannelGuildRecruitment, "["..chatNum..L.ShortGuildRecruitment.."]")
text = gsub(text, L.ChannelNewComerChat, "["..chatNum..L.ShortNewComerChat.."]")
end
--only do stylized player names if it's even enabled and we have the filter list
if addon.isFilterListEnabled and XCHT_DB.enablePlayerChatStyle and type(text) == "string" then
--The string.find method provides an optional 4th parameter to enforce a plaintext search by itself.
if string.find(text, "|Hplayer:", 1, true) then
local old, new, playerLink, player, playerName, playerServer, playerInfo = parsePlayerInfo(frame, text, ...)
if old and new and string.find(text, old, 1, true) then
text = plainTextReplace(text, old, new)
end
end
--ChatFrame_MessageEventHandler
if lastMsgEvent and lastMsgEvent.event then
--Debug(lastMsgEvent, lastMsgEvent.event, lastMsgEvent.messageIndex, text)
--lastMsgEvent = {event=event, msg=msg, author=author, messageIndex=messageIndex, arg1=arg1, arg2=arg2, arg3=arg3}
if lastMsgEvent and lastMsgEvent.messageIndex and lastMsgEvent.messageIndex ~= lastMsgIndex then
lastMsgIndex = lastMsgEvent.messageIndex
--Debug(lastMsgEvent.event, lastMsgEvent.msg, lastMsgEvent.author, lastMsgEvent.messageIndex, lastMsgEvent.arg1, lastMsgEvent.arg2, lastMsgEvent.arg3)
--don't do this on strings with player links and we have a positive filter
if not string.find(text, "|Hplayer:", 1, true) and not string.find(text, "|HBNplayer:", 1, true) and addon:searchFilterList(lastMsgEvent.event, text) then
--Debug('system', lastMsgEvent.event, lastMsgEvent.msg, lastMsgEvent.author, lastMsgEvent.messageIndex, lastMsgEvent.arg1, lastMsgEvent.arg2, lastMsgEvent.arg3)
local origText = text
--check for names
for k, v in pairs(addon.playerList) do
--just in case
if k and v then
local pN, pR = strsplit("@", k)
local passChk = false
--playerName, playerServer = linkName:match("([^%-]+)%-?(.*)")
--make sure we even have a player in the string before editing it
if pN and pR and string.find(text, pN, 1, true) and v.class then
--do the replace here
local color = CUSTOM_CLASS_COLORS and CUSTOM_CLASS_COLORS[v.class] or RAID_CLASS_COLORS[v.class]
if color then
local colorCode = ToHex(color.r, color.g, color.b, 1)
--replace if we have the name and hyphen server
local hasReplaced = false
--only do this for system messages that don't have a player link in it, otherwise it will ruin the player link
if v.realm and v.stripRealm then
text, passChk = plainTextReplace(text, pN.."-"..v.realm, "|c"..colorCode..pN.."-"..v.realm.."|r")
if not passChk then
text, passChk = plainTextReplace(text, pN.."-"..v.stripRealm, "|c"..colorCode..pN.."-"..v.stripRealm.."|r")
end
if passChk then
hasReplaced = true
end
end
if not hasReplaced then
--replace only whole words
text = replaceText(text, pN, "|c"..colorCode..pN.."|r", true)
end
--exit out of loop
break
else
--something went wrong, exit the loop
break
end
end
end
end
end
end
end
end
msgHooks[frame:GetName()].AddMessage(frame, text, ...)
end
--save and restore layout functions
local function SaveLayout(chatFrame)
if not addonLoaded then return end
if not chatFrame then return end
if XCHT_DB.lockChatSettings then return end
if not XCHT_DB then return end
if not XCHT_DB.frames then XCHT_DB.frames = {} end
--first check to see if we even store this chatFrame
if chatFrame == DEFAULT_CHAT_FRAME or chatFrame.isDocked or chatFrame:IsShown() then
if not XCHT_DB.frames[chatFrame:GetID()] then XCHT_DB.frames[chatFrame:GetID()] = {} end
else
--don't store it
if XCHT_DB.frames[chatFrame:GetID()] then XCHT_DB.frames[chatFrame:GetID()] = nil end
return
end
local db = XCHT_DB.frames[chatFrame:GetID()]
local point, relativeTo, relativePoint, xOffset, yOffset = chatFrame:GetPoint()
--error check for invalid object type for relativeTo
if relativeTo == nil then
relativeTo = "UIParent"
elseif type(relativeTo) == "table" then
relativeTo = relativeTo:GetName() or "UIParent"
end
db.point = point
--relativeTo returns the actual object, we just want the name
db.relativeTo = relativeTo
db.relativePoint = relativePoint
db.xOffset = xOffset
db.yOffset = yOffset
db.width = chatFrame:GetWidth()
db.height = chatFrame:GetHeight()
end
local function RestoreLayout(chatFrame)
if not chatFrame then return end
if not XCHT_DB then return end
if not XCHT_DB.frames then return end
if not XCHT_DB.frames[chatFrame:GetID()] then return end
local db = XCHT_DB.frames[chatFrame:GetID()]
if addon.IsRetail and chatFrame == DEFAULT_CHAT_FRAME then return end --don't set anything for the default chat frame in retail, it causes taints
if ( db.width and db.height ) then
if not addon.IsRetail then
chatFrame:SetSize(db.width, db.height) --causes a taint if you try to set the DEFAULT_CHAT_FRAME height and width in any way in retail due to edit mode
end
--force the sizing in blizzards settings
SetChatWindowSavedDimensions(chatFrame:GetID(), db.width, db.height)
if ( not chatFrame.isTemporary and not chatFrame.isDocked) then
FCF_RestorePositionAndDimensions(chatFrame)
end
end
local sSwitch = false
--check to see if we can even move the frame
if not chatFrame:IsMovable() then
chatFrame:SetMovable(true)
sSwitch = true
end
if not chatFrame:IsMouseEnabled() then
chatFrame:EnableMouse(true)
end
if ( chatFrame:IsMovable() and db.point and db.xOffset) then
chatFrame:SetUserPlaced(true)
--error check for invalid object type for relativeTo
if db.relativeTo == nil or type(db.relativeTo) == "table" then db.relativeTo = "UIParent" end --reset it if it's a table, we just want the name
--don't move docked chats
if chatFrame == DEFAULT_CHAT_FRAME or not chatFrame.isDocked or not db.windowInfo[9] then
chatFrame:ClearAllPoints()
chatFrame:SetPoint(db.point, _G[db.relativeTo], db.relativePoint, db.xOffset, db.yOffset)
else
FCF_DockFrame(chatFrame, db.windowInfo[9])
end
end
if sSwitch then
chatFrame:SetMovable(false)
end
end
local function SaveSettings(chatFrame)
if not addonLoaded then return end
if not chatFrame then return end
if XCHT_DB.lockChatSettings then return end
if not XCHT_DB then return end
if not XCHT_DB.frames then XCHT_DB.frames = {} end
--first check to see if we even store this chatFrame
if chatFrame == DEFAULT_CHAT_FRAME or chatFrame.isDocked or chatFrame:IsShown() then
if not XCHT_DB.frames[chatFrame:GetID()] then XCHT_DB.frames[chatFrame:GetID()] = {} end
else
--don't store it
if XCHT_DB.frames[chatFrame:GetID()] then XCHT_DB.frames[chatFrame:GetID()] = nil end
return
end
if chatFrame.isMoving or chatFrame.isDragging then return end
local db = XCHT_DB.frames[chatFrame:GetID()]
local name, fontSize, r, g, b, alpha, shown, locked, docked, uninteractable = GetChatWindowInfo(chatFrame:GetID())
local windowMessages = { GetChatWindowMessages(chatFrame:GetID())}
local windowChannels = { GetChatWindowChannels(chatFrame:GetID())}
local windowMessageColors = {}
--lets save all the message type colors
--https://www.townlong-yak.com/framexml/live/ChatConfigFrame.lua#1464
for k=1, #windowMessages do
if windowMessages[k] and ChatTypeGroup[windowMessages[k]] then
local colorR, colorG, colorB, messageType = GetMessageTypeColor(windowMessages[k])
if colorR and colorG and colorB then
windowMessageColors[k] = {colorR, colorG, colorB, windowMessages[k]}
end
end
end
db.chatParent = chatFrame:GetParent():GetName()
db.windowInfo = {name, fontSize, r, g, b, alpha, shown, locked, docked, uninteractable}
db.windowMessages = windowMessages
db.windowChannels = windowChannels
db.windowMessageColors = windowMessageColors
db.windowChannelColors = nil --remove old db stuff
db.fadingDuration = chatFrame:GetTimeVisible() or 120
db.defaultFrameAlpha = DEFAULT_CHATFRAME_ALPHA
end
local function RestoreSettings(chatFrame)
if not chatFrame then return end
if not XCHT_DB then return end
if not XCHT_DB.frames then return end
if not XCHT_DB.frames[chatFrame:GetID()] then return end
local db = XCHT_DB.frames[chatFrame:GetID()]
if db.windowMessages then
--remove current window messages
local oldWindowMessages = { GetChatWindowMessages(chatFrame:GetID())}
for k=1, #oldWindowMessages do
RemoveChatWindowMessages(chatFrame:GetID(), oldWindowMessages[k])
end
--add the stored ones
local newWindowMessages = db.windowMessages
for k=1, #newWindowMessages do
AddChatWindowMessages(chatFrame:GetID(), newWindowMessages[k])
end
end
--lets set the windowMessageColors
if db.windowMessageColors then
--add the stored ones
local newWindowMessageColors = db.windowMessageColors
for k=1, #newWindowMessageColors do
if newWindowMessageColors[k] and newWindowMessageColors[k][4] then
--in future ChangeChatColor FCF_StripChatMsg() may be required. https://www.townlong-yak.com/framexml/live/ChatConfigFrame.lua
ChangeChatColor(newWindowMessageColors[k][4], newWindowMessageColors[k][1], newWindowMessageColors[k][2], newWindowMessageColors[k][3])
end
end
end
if db.windowChannels then
--remove current window channels
local oldWindowChannels = { GetChatWindowChannels(chatFrame:GetID())}
for k=1, #oldWindowChannels do
RemoveChatWindowChannel(chatFrame:GetID(), oldWindowChannels[k])
end
--add the stored ones
local newWindowChannels = db.windowChannels
for k=1, #newWindowChannels do
AddChatWindowChannel(chatFrame:GetID(), newWindowChannels[k])
end
end
-- --lets set the windowChannelColors
if XCHT_DB.channelColors then
for k = 1, MAX_WOW_CHAT_CHANNELS do
if XCHT_DB.channelColors[k] then
local colorData = XCHT_DB.channelColors[k]
if colorData then
ChangeChatColor("CHANNEL"..k, colorData.r, colorData.g, colorData.b)
end
end
end
end
if db.windowInfo and db.windowInfo[1] then
SetChatWindowName(chatFrame:GetID(), db.windowInfo[1])
SetChatWindowSize(chatFrame:GetID(), db.windowInfo[2])
SetChatWindowColor(chatFrame:GetID(), db.windowInfo[3], db.windowInfo[4], db.windowInfo[5])
SetChatWindowAlpha(chatFrame:GetID(), db.windowInfo[6])
SetChatWindowShown(chatFrame:GetID(), db.windowInfo[7])
SetChatWindowLocked(chatFrame:GetID(), db.windowInfo[8])
SetChatWindowDocked(chatFrame:GetID(), db.windowInfo[9])
SetChatWindowUninteractable(chatFrame:GetID(), db.windowInfo[10])
end
if db.chatParent then
local checkParent = (type(db.chatParent) == "table" and db.chatParent) or _G[db.chatParent]
chatFrame:SetParent(checkParent)
end
--handling chat frame fading
if XCHT_DB then
if XCHT_DB.enableChatTextFade then
chatFrame:SetFading(true)
chatFrame:SetTimeVisible(db.fadingDuration or 120)
else
chatFrame:SetFading(false)
end
end
end
local function SaveChannelColors()
if not addonLoaded then return end
if XCHT_DB.lockChatSettings then return end
if not XCHT_DB.channelColors then XCHT_DB.channelColors = {} end
local function GetColorInfo(...)
local count = 1
for i=1, select("#", ...), 3 do
local channelNum = select(i, ...)
local tag = "CHANNEL"..channelNum
local channelName = select(i+1, ...)
local disabled = select(i+2, ...)
if ChatTypeInfo[tag] then
local colorR, colorG, colorB, messageType = GetMessageTypeColor(tag)
if colorR and colorG and colorB then
XCHT_DB.channelColors[count] = {r=colorR, g=colorG, b=colorB, channelNum=channelNum, channelName=channelName, tag=tag}
end
end
count = count + 1
end
end
GetColorInfo(GetChannelList())
end
local function SaveDebugInfo(chatFrame)
if not addonLoaded then return end
if not chatFrame then return end
if not XCHT_DB then return end
if XCHT_DB.debugChannels then XCHT_DB.debugChannels = nil end --remove old debug table
if not XCHT_DB.debugInfo then XCHT_DB.debugInfo = {} end
if chatFrame == DEFAULT_CHAT_FRAME or chatFrame.isDocked or chatFrame:IsShown() then
if not XCHT_DB.debugInfo[chatFrame:GetID()] then XCHT_DB.debugInfo[chatFrame:GetID()] = {} end
else
--don't store it
if XCHT_DB.debugInfo[chatFrame:GetID()] then XCHT_DB.debugInfo[chatFrame:GetID()] = nil end
return
end
local debugDB = XCHT_DB.debugInfo[chatFrame:GetID()]
local channelList = chatFrame.channelList
local zoneChannelList = chatFrame.zoneChannelList
local function IsChannelNameChecked(channelName)
if not channelList then return false end
for index, value in pairs(channelList) do
if value == channelName then
return true
end
end
return false
end
local function GetChannelID(channelName)
if not channelList then return 0 end
if not zoneChannelList then return 0 end
for index, value in pairs(channelList) do
if value == channelName then
if zoneChannelList[index] then
return zoneChannelList[index]
end
return 0
end
end
return 0
end
local function GetDebugInfo(...)
if not channelList or #channelList < 1 then return end
if not zoneChannelList or #zoneChannelList < 1 then return end
for i=1, select("#", ...), 3 do
local channelNum = select(i, ...)
local tag = "CHANNEL"..channelNum
local channelName = select(i+1, ...)
local disabled = select(i+2, ...)
local checked = IsChannelNameChecked(channelName)
if channelNum then
local _, longChannelName, instanceID, isCommunitiesChannel = GetChannelName(channelNum)
debugDB[channelNum] = {
channelNum = channelNum,
tag = tag,
channelName = channelName,
isDisabled = disabled,
isChecked = checked,
chatFrameID = chatFrame:GetID() or 0,
chatFrameName = chatFrame:GetName() or "Unknown",
channelID = GetChannelID(channelName),
longChannelName = longChannelName,
instanceID = instanceID,
isCommunitiesChannel = isCommunitiesChannel,
channelShortcut = C_ChatInfo and C_ChatInfo.GetChannelShortcutForChannelID(GetChannelID(channelName)) or "?",
}
end
end
end
GetDebugInfo(GetChannelList())
end
local function saveChatSettings(f)
SaveLayout(f)
SaveSettings(f)
SaveDebugInfo(f)
SaveChannelColors()
end
local function restoreChatSettings(f)
RestoreSettings(f)
RestoreLayout(f)
end
local function doSaveCurrentChatFrame()
local chatFrame = FCF_GetCurrentChatFrame()
if chatFrame then
saveChatSettings(chatFrame)
end
end
local function doValueUpdate(checkBool, groupType)
saveChatSettings(FCF_GetCurrentChatFrame() or nil)
end
hooksecurefunc("ToggleChatMessageGroup", doValueUpdate)
hooksecurefunc("ToggleMessageSource", doValueUpdate)
hooksecurefunc("ToggleMessageDest", doValueUpdate)
hooksecurefunc("ToggleMessageTypeGroup", doValueUpdate)
hooksecurefunc("ToggleMessageType", doValueUpdate)
hooksecurefunc("ToggleChatColorNamesByClassGroup", doValueUpdate)
hooksecurefunc("FCF_SavePositionAndDimensions", function(chatFrame) saveChatSettings(chatFrame) end)
hooksecurefunc("FCF_RestorePositionAndDimensions", function(chatFrame) saveChatSettings(chatFrame) end)
hooksecurefunc("FCF_Close", function(chatFrame) saveChatSettings(chatFrame) end)
hooksecurefunc("FCF_ToggleLock", function() doSaveCurrentChatFrame() end)
hooksecurefunc("FCF_ToggleLockOnDockedFrame", function() doSaveCurrentChatFrame() end)
hooksecurefunc("FCF_ToggleUninteractable", function() doSaveCurrentChatFrame() end)
hooksecurefunc("FCF_DockFrame", function(chatFrame, index, selected) saveChatSettings(chatFrame) end)
hooksecurefunc("FCF_Close", function(chatFrame, fallback) saveChatSettings(chatFrame) end)
hooksecurefunc("FCF_StopDragging", function(chatFrame) saveChatSettings(chatFrame) end)
hooksecurefunc("FCF_Tab_OnClick", function(self, button)
local chatFrame = _G["ChatFrame"..self:GetID()]
if chatFrame then
saveChatSettings(chatFrame)
end
end)