-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrChat.lua
More file actions
3161 lines (2510 loc) · 104 KB
/
rChat.lua
File metadata and controls
3161 lines (2510 loc) · 104 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
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
-- Registering libraries
local LAM = LibAddonMenu2
local LMP = LibMediaProvider
local SF = LibSFUtils
local RAM = rChat.AutoMsg
local L = GetString
local CACHE = rChatData
local HRS_TO_SEC = 3600
-- Init
local isAddonLoaded = false -- OnAddonLoaded() done
rChat.lastwhisp = nil
local lastwhisp = rChat.lastwhisp
-- ---- Mention specific options
local defmention = {
mentionEnabled = false,
emoteEnabled = false,
mentiontbl = {},
soundEnabled = false,
sound = SOUNDS.NEW_NOTIFICATION,
colorEnabled = false,
color = "|cFFFFFF",
}
-- ---- Anti Spam specific options
local defspam = {
spamGracePeriod = 5,
floodProtect = true,
floodGracePeriod = 30,
lookingForProtect = false,
wantToProtect = false,
guildProtect = false,
priceCheckProtect = false,
}
local defwhisper = {
soundEnabled = false,
incomingsound = SOUNDS.NEW_NOTIFICATION,
notifyIM = false,
}
local deftabs = {
-- ---- Chat Tab Settings
enableChatTabChannel = true,
defaultchannel = CHAT_CHANNEL_ZONE,
defaultTab = 1,
defaultTabName = "",
-- ---- Chat Tab Settings - End
}
-- Default variables to push in SavedVars
local defaults = {
mention = defmention,
spam = defspam,
whisper = defwhisper,
tabs = deftabs,
-- ---- Message Settings
allZonesSameColour = true,
allNPCSameColour = true,
nozonetags = true,
carriageReturn = false,
useESOcolors = true,
diffforESOcolors = 40,
showTagInEntry = true,
geoChannelsFormat = 2,
disableBrackets = true,
addChannelAndTargetToHistory = true,
urlHandling = true,
nicknames = "",
enableFriendStatus = true,
-- ---- Message Settings - End
-- ---- Timestamp Settings
showTimestamp = true,
timestampcolorislcol = false,
timestampFormat = "HH:m",
-- colors["timestamp"],
-- ---- Timestamp Settings - End
-- ---- Guild Settings
showGuildNumbers = false,
allGuildsSameColour = false,
guildTags = {},
officertag = {},
switchFor = {},
officerSwitchFor = {},
formatguild = {},
-- color[] stuff here too
-- ---- Guild Settings - End
-- ---- Group Settings
enablepartyswitch = true,
groupLeader = false,
-- colours["groupleader"]
-- colours["groupleader1"]
groupNames = 1,
-- ---- Group Settings - End
-- ---- Chat Window Settings specific options
windowDarkness = 6,
alwaysShowChat = false,
augmentHistoryBuffer = true,
oneColour = false,
chatMinimizedAtLaunch = false,
chatMinimizedInMenus = false,
chatMaximizedAfterMenus = false,
fonts = "ESO Standard Font",
enablecopy = true,
-- colours["tabwarning"],
disableDebugLoggerBlocking = true,
announce_zone = false,
-- ---- Chat Window Settings specific options - End
-- ---- Restore Options
restoreOnReloadUI = true,
restoreOnLogOut = true,
restoreOnAFK = true, -- kicked
timeBeforeRestore = 2,
restoreOnQuit = false,
restoreSystem = true,
restoreSystemOnly = false,
restoreWhisps = true,
restoreTextEntryHistoryAtLogOutQuit = false,
-- ---- Restore Options - End
-- ---- Sync Settings
chatSyncConfig = true,
-- localPlayer
chatConfSync = {}, -- not LAM
-- ---- Sync Settings - End
-- ----
newcolors = {
-- player colors
[CHAT_CHANNEL_SAY] = {"|cFFFFFF", "|cFFFFFF",}, -- say
[CHAT_CHANNEL_YELL] = {"|cE974D8", "|cFFB5F4",}, -- yell
[CHAT_CHANNEL_WHISPER] = {"|cB27BFF", "|cB27BFF",}, -- whisper
[CHAT_CHANNEL_WHISPER_SENT] = {"|c7E57B5", "|c7E57B5",}, -- whisper out
[CHAT_CHANNEL_PARTY] = {"|c6EABCA", "|cA1DAF7",}, -- group
[CHAT_CHANNEL_EMOTE] = {"|cA5A5A5", "|cA5A5A5",}, -- emote
-- npc colors
[CHAT_CHANNEL_MONSTER_SAY] = {"|c879B7D", "|c879B7D",}, -- npc say
[CHAT_CHANNEL_MONSTER_YELL] = {"|c879B7D", "|c879B7D",}, -- npc yell
[CHAT_CHANNEL_MONSTER_WHISPER] = {"|c879B7D", "|c879B7D",}, -- npc whisper
[CHAT_CHANNEL_MONSTER_EMOTE] = {"|c879B7D", "|c879B7D",}, -- npc emote
-- guild colors
[CHAT_CHANNEL_GUILD_1] = {"|c94E193", "|cC3F0C2",}, -- guild
[CHAT_CHANNEL_GUILD_2] = {"|c94E193", "|cC3F0C2",},
[CHAT_CHANNEL_GUILD_3] = {"|c94E193", "|cC3F0C2",},
[CHAT_CHANNEL_GUILD_4] = {"|c94E193", "|cC3F0C2",},
[CHAT_CHANNEL_GUILD_5] = {"|c94E193", "|cC3F0C2",},
[CHAT_CHANNEL_OFFICER_1] = {"|cC3F0C2", "|cC3F0C2",}, -- guild officers
[CHAT_CHANNEL_OFFICER_2] = {"|cC3F0C2", "|cC3F0C2",},
[CHAT_CHANNEL_OFFICER_3] = {"|cC3F0C2", "|cC3F0C2",},
[CHAT_CHANNEL_OFFICER_4] = {"|cC3F0C2", "|cC3F0C2",},
[CHAT_CHANNEL_OFFICER_5] = {"|cC3F0C2", "|cC3F0C2",},
-- other colors (zone)
[CHAT_CHANNEL_ZONE] = {"|cCEB36F", "|cB0A074",},
[CHAT_CHANNEL_ZONE_LANGUAGE_1] = {"|cCEB36F", "|cB0A074",}, -- EN zone
[CHAT_CHANNEL_ZONE_LANGUAGE_2] = {"|cCEB36F", "|cB0A074",}, -- FR zone
[CHAT_CHANNEL_ZONE_LANGUAGE_3] = {"|cCEB36F", "|cB0A074",}, -- DE zone
[CHAT_CHANNEL_ZONE_LANGUAGE_4] = {"|cCEB36F", "|cB0A074",}, -- JP zone
[CHAT_CHANNEL_ZONE_LANGUAGE_5] = {"|cCEB36F", "|cB0A074",}, -- RU zone
[CHAT_CHANNEL_ZONE_LANGUAGE_6] = {"|cCEB36F", "|cB0A074",}, -- SP zone
[CHAT_CHANNEL_ZONE_LANGUAGE_7] = {"|cCEB36F", "|cB0A074",}, -- ZH_Han zone
},
colours = {
-- misc
["timestamp"] = "|c8F8F8F", -- timestamp
["tabwarning"] = "|c76BCC3", -- tab Warning ~ "Azure" (ZOS default)
["groupleader"] = "|cC35582", --
["groupleader1"] = "|c76BCC3", --
},
}
rChat.defaults = defaults -- make accessible
-- used by convertSavedColors() for saved variable color conversion
-- between addon versions
local coloredChannels = {
CHAT_CATEGORY_SAY,
CHAT_CATEGORY_YELL,
CHAT_CATEGORY_WHISPER,
CHAT_CATEGORY_WHISPER_SENT,
CHAT_CATEGORY_ZONE,
CHAT_CATEGORY_PARTY,
CHAT_CATEGORY_EMOTE,
CHAT_CATEGORY_SYSTEM,
CHAT_CATEGORY_GUILD_1,
CHAT_CATEGORY_GUILD_2,
CHAT_CATEGORY_GUILD_3,
CHAT_CATEGORY_GUILD_4,
CHAT_CATEGORY_GUILD_5,
CHAT_CATEGORY_OFFICER_1,
CHAT_CATEGORY_OFFICER_2,
CHAT_CATEGORY_OFFICER_3,
CHAT_CATEGORY_OFFICER_4,
CHAT_CATEGORY_OFFICER_5,
CHAT_CATEGORY_ZONE_ENGLISH, -- LANGUAGE_1
CHAT_CATEGORY_ZONE_FRENCH, -- LANGUAGE_2
CHAT_CATEGORY_ZONE_GERMAN, -- LANGUAGE_3
CHAT_CATEGORY_ZONE_JAPANESE, -- LANGUAGE_4
CHAT_CATEGORY_ZONE_RUSSIAN, -- LANGUAGE_5
CHAT_CATEGORY_ZONE_SPANISH, -- LANGUAGE_6
CHAT_CATEGORY_MONSTER_SAY,
CHAT_CATEGORY_MONSTER_YELL,
CHAT_CATEGORY_MONSTER_WHISPER,
CHAT_CATEGORY_MONSTER_EMOTE,
}
-- SV
local db
local targetToWhisp
-- rData will receive variables and objects.
local rData = rChat.data
-- Used for rChat LinkHandling
local RCHAT_LINK = "p"
local RCHAT_URL_CHAN = 97
local RCHAT_CHANNEL_NONE = 99
-- Save AddMessage for internal debug - AVOID DOING A CHAT_SYSTEM:AddMessage()/CHAT_ROUTER:AddSystemMessage()
-- in rChat, it can cause recursive calls
CHAT_SYSTEM.Zo_AddMessage = CHAT_SYSTEM.AddMessage
-- used only by save and sync chat config
rData.chatCategories = {
CHAT_CATEGORY_SAY,
CHAT_CATEGORY_YELL,
CHAT_CATEGORY_WHISPER_INCOMING,
CHAT_CATEGORY_WHISPER_OUTGOING,
CHAT_CATEGORY_ZONE,
CHAT_CATEGORY_PARTY,
CHAT_CATEGORY_EMOTE,
CHAT_CATEGORY_SYSTEM,
CHAT_CATEGORY_GUILD_1,
CHAT_CATEGORY_GUILD_2,
CHAT_CATEGORY_GUILD_3,
CHAT_CATEGORY_GUILD_4,
CHAT_CATEGORY_GUILD_5,
CHAT_CATEGORY_OFFICER_1,
CHAT_CATEGORY_OFFICER_2,
CHAT_CATEGORY_OFFICER_3,
CHAT_CATEGORY_OFFICER_4,
CHAT_CATEGORY_OFFICER_5,
CHAT_CATEGORY_ZONE_ENGLISH,
CHAT_CATEGORY_ZONE_FRENCH,
CHAT_CATEGORY_ZONE_GERMAN,
CHAT_CATEGORY_ZONE_JAPANESE,
CHAT_CATEGORY_ZONE_RUSSIAN,
CHAT_CATEGORY_ZONE_SPANISH,
CHAT_CATEGORY_MONSTER_SAY,
CHAT_CATEGORY_MONSTER_YELL,
CHAT_CATEGORY_MONSTER_WHISPER,
CHAT_CATEGORY_MONSTER_EMOTE,
}
-- used only in savetabcategories
rData.guildCategories = {
CHAT_CATEGORY_GUILD_1,
CHAT_CATEGORY_GUILD_2,
CHAT_CATEGORY_GUILD_3,
CHAT_CATEGORY_GUILD_4,
CHAT_CATEGORY_GUILD_5,
CHAT_CATEGORY_OFFICER_1,
CHAT_CATEGORY_OFFICER_2,
CHAT_CATEGORY_OFFICER_3,
CHAT_CATEGORY_OFFICER_4,
CHAT_CATEGORY_OFFICER_5,
}
------------------------------------------------------
-- bring in/alias rChat_Internals functions
local formatLanguageTag = rChat_Internals.formatLanguageTag
local formatName = rChat_Internals.formatName
local formatSeparator = rChat_Internals.formatSeparator
local formatTag = rChat_Internals.formatTag
local formatText = rChat_Internals.formatText
local formatTimestamp = rChat_Internals.formatTimestamp
local formatWhisperTag = rChat_Internals.formatWhisperTag
local formatZoneTag = rChat_Internals.formatZoneTag
local produceDisplayString = rChat_Internals.produceDisplayString
local GetChannelColors = rChat_Internals.GetChannelColors
local GetGuildIndex = rChat_Internals.GetGuildIndex
local initColorTable = rChat_Internals.initColorTable
local produceCopyFrom = rChat_Internals.produceCopyFrom
local produceRawString = rChat_Internals.produceRawString
local reduceString = rChat_Internals.reduceString
local UseNameFormat = rChat_Internals.UseNameFormat
------------------------------------------------------
local MENU_CATEGORY_RCHAT = nil
-- get a color (hex) pair from the chat colors table (indexed by channel id)
function rChat.getColors(channelId)
local colorsEntry = db.newcolors[channelId]
if not colorsEntry then
colorsEntry = db.newcolors[1]
end
return colorsEntry[1], colorsEntry[2] -- left, right
end
function rChat.setLeftColor(channelId, r, g, b)
local colorsEntry = db.newcolors[channelId]
colorsEntry[1] = SF.ConvertRGBToHex(r, g, b)
return colorsEntry[2]
end
function rChat.setRightColor(channelId, r, g, b)
local colorsEntry = db.newcolors[channelId]
colorsEntry[2] = SF.ConvertRGBToHex(r, g, b)
return colorsEntry[2]
end
-- return the guild channel and guild officer channel for
-- a particular guild index
function rChat.GetGuildChannel(index)
local mem = CHAT_CHANNEL_GUILD_1 - 1 + index
local ofc = CHAT_CHANNEL_OFFICER_1 - 1 + index
return mem, ofc
end
-- Strip all of the color markers out of the
-- provided text, returning what is left.
--
local function stripColours(text)
-- get positions of all of the desired delimiters
local t1 = SF.getAllColorDelim(text)
if #t1 == 0 then
-- no delimiters in string
return text
end
-- remove color markers
return SF.stripColors(t1, text)
end
-- format ESO text to raw text
-- IE : Transforms LinkHandlers into their displayed value
function rChat.FormatRawText(text)
-- Strip colors from chat
local newtext = stripColours(text)
-- Transforms a LinkHandler into its localized displayed value
-- "|H(.-):(.-)|h(.-)|h" = pattern for Linkhandlers
-- Item : |H1:item:33753:25:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0|h|h = [Battaglir] in french -> Link to item 33753, etc
-- Achievement |H1:achievement:33753|h|h etc (not searched a lot, was easy)
-- DisplayName = |H1:display:Ayantir|h[@Ayantir]|h = [@Ayantir] -> link to DisplayName @Ayantir
-- Book = |H1:book:186|h|h = [Climat de guerre] in french -> Link to book 186 .. GetLoreBookTitleFromLink()
-- rChat = |H1:RCHAT_LINK:124:11|h[06:18]|h = [06:18] (here 124 is the line number reference and 11 is the chanCode) - URL handling : if chanCode = 97, it will popup a dialog to open internet browser
-- Character = |H1:character:salhamandhil^Mx|h[salhamandhil]|h = text(here salhamandhil is with brackets voluntary)
-- Quest_items = |H1:quest_item:4275|h|h
newtext = string.gsub(newtext, "|H(.-):(.-)|h(.-)|h", function (linkStyle, data, text)
-- linkStyle = style (0 = no brackets or 1 = brackets)
-- data = data separated by ":"
-- text = text displayed, used for Channels, DisplayName, Character, and some fake itemlinks (used by addons)
-- linktype is : item, achievement, character, channel, book, display, rchatlink
-- DOES NOT HANDLE ADDONS LINKTYPES
-- for all types, only param1 is important
local linkType, param1 = zo_strsplit(':', data)
-- param1 : itemID
-- Need to get
if linkType == ITEM_LINK_TYPE or linkType == COLLECTIBLE_LINK_TYPE then
-- Fakelink and GetItemLinkName
return "[" .. zo_strformat(SI_TOOLTIP_ITEM_NAME, GetItemLinkName("|H" .. linkStyle ..":" .. data .. "|h|h")) .. "]"
-- if linkType == GUILD_LINK_TYPE then
-- return "[" .. zo_strformat(GetItemLinkName("|H" .. linkStyle ..":" .. data .. "|h|h")) .. "]"
-- param1 : achievementID
elseif linkType == ACHIEVEMENT_LINK_TYPE then
-- zo_strformat to avoid masculine/feminine problems
return "[" .. zo_strformat(GetAchievementInfo(param1)) .. "]"
-- SysMessages Links CharacterNames
elseif linkType == CHARACTER_LINK_TYPE then
return text
elseif linkType == CHANNEL_LINK_TYPE then
return text
elseif linkType == BOOK_LINK_TYPE then
return "[" .. GetLoreBookTitleFromLink(newtext) .. "]"
-- SysMessages Links DisplayNames
elseif linkType == DISPLAY_NAME_LINK_TYPE then
-- No formatting here
return "[@" .. param1 .. "]"
-- Used for Sysmessages
elseif linkType == "quest_item" then
-- No formatting here
return "[" .. zo_strformat(SI_TOOLTIP_ITEM_NAME, GetQuestItemNameFromLink(newtext)) .. "]"
elseif linkType == RCHAT_LINK then
-- No formatting here .. maybe yes ?..
return text
end
end)
return newtext
end
-- ------------------------------------------------------
-- Automated Messages
-- Also called by bindings
function rChat.ShowAutoMsg()
if RAM then
RAM.ShowAutoMsg()
else
CHAT_SYSTEM.Zo_AddMessage("[rChat] Automated Message System is not enabled")
end
end
-- Register Slash commands
SLASH_COMMANDS["/rchat.msg"] = rChat.ShowAutoMsg
local automatedMessagesList = ZO_SortFilterList:Subclass()
-- Init Automated Messages
function automatedMessagesList:Init(control)
ZO_SortFilterList.InitializeSortFilterList(self, control)
local SortKeys = {
["name"] = {},
["message"] = {tiebreaker = "name"}
}
self.masterList = {}
ZO_ScrollList_AddDataType(self.list, 1, "rChatXMLAutoMsgRowTemplate",
32, function(control, data) self:SetupEntry(control, data) end)
ZO_ScrollList_EnableHighlight(self.list, "ZO_ThinListHighlight")
self.sortFunction = function(listEntry1, listEntry2) return ZO_TableOrderingFunction(listEntry1.data, listEntry2.data, self.currentSortKey, SortKeys, self.currentSortOrder) end
return self
end
function automatedMessagesList:SetupEntry(control, data)
control.data = data
control.name = GetControl(control, "Name")
control.message = GetControl(control, "Message")
local messageTrunc = rChat.FormatRawText(data.message)
if string.len(messageTrunc) > 53 then
messageTrunc = string.sub(messageTrunc, 1, 53) .. " .."
end
control.name:SetText(data.name)
control.message:SetText(messageTrunc)
ZO_SortFilterList.SetupRow(self, control, data)
end
function automatedMessagesList:BuildMasterList()
self.masterList = {}
local messages = db.automatedMessages
if messages then
for k, v in ipairs(messages) do
local data = v
table.insert(self.masterList, data)
end
end
end
function automatedMessagesList:SortScrollList()
local scrollData = ZO_ScrollList_GetDataList(self.list)
table.sort(scrollData, self.sortFunction)
end
function automatedMessagesList:FilterScrollList()
local scrollData = ZO_ScrollList_GetDataList(self.list)
ZO_ClearNumericallyIndexedTable(scrollData)
for i = 1, #self.masterList do
local data = self.masterList[i]
table.insert(scrollData, ZO_ScrollList_CreateDataEntry(1, data))
end
end
function rChat.SaveAutomatedMessage(name, message, isNew)
if db then
local alreadyFav = false
if isNew then
for k, v in pairs(db.automatedMessages) do
if "!" .. name == v.name then
alreadyFav = true
end
end
end
if not alreadyFav then
rChatXMLAutoMsg:GetNamedChild("Warning"):SetHidden(true)
rChatXMLAutoMsg:GetNamedChild("Warning"):SetText("")
if string.len(name) > 12 then
name = string.sub(name, 1, 12)
end
if string.len(message) > 350 then
message = string.sub(message, 1, 350)
end
local entryList = ZO_ScrollList_GetDataList(rData.automatedMessagesList.list)
if isNew then
local data = {name = "!" .. name, message = message}
local entry = ZO_ScrollList_CreateDataEntry(1, data)
table.insert(entryList, entry)
table.insert(db.automatedMessages, {name = "!" .. name, message = message}) -- "data" variable is modified by ZO_ScrollList_CreateDataEntry and will crash eso if saved to savedvars
else
local data = RAM.FindAutomatedMsg(name)
local _, index = RAM.FindSavedAutomatedMsg(name)
data.message = message
db.automatedMessages[index].message = message
end
ZO_ScrollList_Commit(rData.automatedMessagesList.list)
else
rChatXMLAutoMsg:GetNamedChild("Warning"):SetHidden(false)
rChatXMLAutoMsg:GetNamedChild("Warning"):SetText(L(RCHAT_SAVMSGERRALREADYEXISTS))
rChatXMLAutoMsg:GetNamedChild("Warning"):SetColor(1, 0, 0)
zo_callLater(function() rChatXMLAutoMsg:GetNamedChild("Warning"):SetHidden(true) end, 5000)
end
end
end
-- Init Automated messages, build the scene and handle array of automated strings
function rChat.InitAutomatedMessages()
-- Create Scene
RCHAT_AUTOMSG_SCENE = ZO_Scene:New("rChatAutomatedMessagesScene", SCENE_MANAGER)
-- Mouse standard position and background
RCHAT_AUTOMSG_SCENE:AddFragmentGroup(FRAGMENT_GROUP.MOUSE_DRIVEN_UI_WINDOW)
RCHAT_AUTOMSG_SCENE:AddFragmentGroup(FRAGMENT_GROUP.FRAME_TARGET_STANDARD_RIGHT_PANEL)
-- Background Right, it will set ZO_RightPanelFootPrint and its stuff.
RCHAT_AUTOMSG_SCENE:AddFragment(RIGHT_BG_FRAGMENT)
-- The title fragment
RCHAT_AUTOMSG_SCENE:AddFragment(TITLE_FRAGMENT)
-- Set Title
ZO_CreateStringId("SI_RCHAT_AUTOMSG_TITLE", rChat.name)
RCHAT_AUTOMSG_TITLE_FRAGMENT = ZO_SetTitleFragment:New(SI_RCHAT_AUTOMSG_TITLE)
RCHAT_AUTOMSG_SCENE:AddFragment(RCHAT_AUTOMSG_TITLE_FRAGMENT)
-- Add the XML to our scene
RCHAT_AUTOMSG_SCENE_WINDOW = ZO_FadeSceneFragment:New(rChatXMLAutoMsg)
RCHAT_AUTOMSG_SCENE:AddFragment(RCHAT_AUTOMSG_SCENE_WINDOW)
-- Register Scenes and the group name
SCENE_MANAGER:AddSceneGroup("rChatSceneGroup", ZO_SceneGroup:New("rChatAutomatedMessagesScene"))
local autoMsgDescriptor = {
alignment = KEYBIND_STRIP_ALIGN_CENTER,
{
name = L(RCHAT_AUTOMSG_ADD_AUTO_MSG),
keybind = "UI_SHORTCUT_PRIMARY",
control = self,
callback = function(descriptor) ZO_Dialogs_ShowDialog("RCHAT_AUTOMSG_SAVE_MSG", nil, {mainTextParams = {functionName}}) end,
visible = function(descriptor) return true end
},
{
name = L(RCHAT_AUTOMSG_EDIT_AUTO_MSG),
keybind = "UI_SHORTCUT_SECONDARY",
control = self,
callback = function(descriptor)
ZO_Dialogs_ShowDialog("RCHAT_AUTOMSG_EDIT_MSG", nil, {mainTextParams = {functionName}})
end,
visible = function(descriptor)
if rData.autoMessagesShowKeybind then
return true
else
return false
end
end
},
{
name = L(RCHAT_AUTOMSG_REMOVE_AUTO_MSG),
keybind = "UI_SHORTCUT_NEGATIVE",
control = self,
callback = function(descriptor) RAM.RemoveAutomatedMessage(db) end,
visible = function(descriptor)
if rData.autoMessagesShowKeybind then
return true
else
return false
end
end
},
}
local autoMessagesScene = SCENE_MANAGER:GetScene("rChatAutomatedMessagesScene")
autoMessagesScene:RegisterCallback("StateChange", function(oldState, newState)
if newState == SCENE_SHOWING then
KEYBIND_STRIP:AddKeybindButtonGroup(autoMsgDescriptor)
elseif newState == SCENE_HIDDEN then
if KEYBIND_STRIP:HasKeybindButtonGroup(autoMsgDescriptor) then
KEYBIND_STRIP:RemoveKeybindButtonGroup(autoMsgDescriptor)
end
end
end)
if not db.automatedMessages then
db.automatedMessages = {}
end
rData.automatedMessagesList = automatedMessagesList:Init(rChatXMLAutoMsg)
rData.automatedMessagesList:RefreshData()
RAM.CleanAutomatedMessageList(db)
rData.automatedMessagesList.keybindStripDescriptor = autoMsgDescriptor
end
-- Called by XML
function rChat_BuildAutomatedMessagesDialog(control, saveFunc)
RAM.BuildAutomatedMessagesDialog(control, saveFunc)
end
-- end Automated Messages code section
-- ------------------------------------------------------
-- Change ChatWindow Darkness by modifying its <Center> & <Edge>.
-- Originally defined in virtual object ZO_ChatContainerTemplate
-- in sharedchatsystem.xml
function rChat.ChangeChatWindowDarkness(changeSetting)
if dbWindowDarkness == 0 then
ZO_ChatWindowBg:SetCenterTexture("EsoUI/Art/ChatWindow/chat_BG_center.dds")
ZO_ChatWindowBg:SetEdgeTexture("EsoUI/Art/ChatWindow/chat_BG_edge.dds", 256, 256, 32)
else
ZO_ChatWindowBg:SetCenterColor(0, 0, 0, 1)
ZO_ChatWindowBg:SetEdgeColor(0, 0, 0, 1)
if db.windowDarkness == 11 and changeSetting then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_100.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_100.dds", 256, 256, 32)
elseif db.windowDarkness == 10 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_90.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_90.dds", 256, 256, 32)
elseif db.windowDarkness == 9 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_80.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_80.dds", 256, 256, 32)
elseif db.windowDarkness == 8 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_70.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_70.dds", 256, 256, 32)
elseif db.windowDarkness == 7 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_60.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_60.dds", 256, 256, 32)
elseif db.windowDarkness == 6 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_50.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_50.dds", 256, 256, 32)
elseif db.windowDarkness == 5 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_40.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_40.dds", 256, 256, 32)
elseif db.windowDarkness == 4 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_30.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_30.dds", 256, 256, 32)
elseif db.windowDarkness == 3 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_20.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_20.dds", 256, 256, 32)
elseif db.windowDarkness == 2 then
ZO_ChatWindowBg:SetCenterTexture("rChat/dds/chat_bg_center_10.dds")
ZO_ChatWindowBg:SetEdgeTexture("rChat/dds/chat_bg_edge_10.dds", 256, 256, 32)
elseif db.windowDarkness == 1 then
ZO_ChatWindowBg:SetCenterColor(0, 0, 0, 0)
ZO_ChatWindowBg:SetEdgeColor(0, 0, 0, 0)
end
end
end
-- ----------------------------------------------------------------
-- Whisper functions
-- Add IM label on XML Initialization, set anchor and set it hidden
function rChat_AddIMLabel(control)
control:SetParent(CHAT_SYSTEM.control)
control:ClearAnchors()
control:SetAnchor(RIGHT, ZO_ChatWindowOptions, LEFT, -5, 32)
CHAT_SYSTEM.IMLabel = control
end
-- Add IM label on XML Initialization, set anchor and set it hidden. Used for Chat Minibar
function rChat_AddIMLabelMin(control)
control:SetParent(CHAT_SYSTEM.control)
control:ClearAnchors()
control:SetAnchor(BOTTOM, CHAT_SYSTEM.minBar.maxButton, TOP, 2, 0)
CHAT_SYSTEM.IMLabelMin = control
end
-- Add IM close button on XML Initialization, set anchor and set it hidden
function rChat_AddIMButton(control)
control:SetParent(CHAT_SYSTEM.control)
control:ClearAnchors()
control:SetAnchor(RIGHT, ZO_ChatWindowOptions, LEFT, 2, 35)
CHAT_SYSTEM.IMbutton = control
end
-- Hide it
local function HideIMTooltip()
ClearTooltip(InformationTooltip)
end
-- Show IM notification tooltip
local function ShowIMTooltip(self, lineNumber)
local chatline = CACHE.getCacheEntry(lineNumber)
if not chatline then return end
local sender = chatline.rawT.from
local text = chatline.rawT.text --chatline.rawMessage
if (not IsDecoratedDisplayName(sender)) then
sender = zo_strformat(SI_UNIT_NAME, sender)
end
InitializeTooltip(InformationTooltip, self, BOTTOMLEFT, 0, 0, TOPRIGHT)
InformationTooltip:AddLine(sender, "ZoFontGame", 1, 1, 1, TOPLEFT, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_LEFT, true)
local r, g, b = ZO_NORMAL_TEXT:UnpackRGB()
InformationTooltip:AddLine(text, "ZoFontGame", r, g, b, TOPLEFT, MODIFY_TEXT_TYPE_NONE, TEXT_ALIGN_LEFT, true)
end
-- When an incoming Whisper is received
local function OnIMReceived(from, lineNumber)
if not CHAT_SYSTEM.primaryContainer then return end
if not db.whisper.notifyIM then return end
-- Display visual notification
-- If chat minimized, show the minified button
if (CHAT_SYSTEM:IsMinimized()) then
CHAT_SYSTEM.IMLabelMin:SetHandler("OnMouseEnter", function(self) ShowIMTooltip(self, lineNumber) end)
CHAT_SYSTEM.IMLabelMin:SetHandler("OnMouseExit", HideIMTooltip)
CHAT_SYSTEM.IMLabelMin:SetHidden(false)
else
-- Chat maximized
local _, scrollMax = CHAT_SYSTEM.primaryContainer.scrollbar:GetMinMax()
-- If whispers not show in the tab or we don't scroll at bottom
if ((not IsChatContainerTabCategoryEnabled(1, rData.activeTab, CHAT_CATEGORY_WHISPER_INCOMING)) or (IsChatContainerTabCategoryEnabled(1, rData.activeTab, CHAT_CATEGORY_WHISPER_INCOMING) and CHAT_SYSTEM.primaryContainer.scrollbar:GetValue() < scrollMax)) then
-- Undecorate (^F / ^M)
if (not IsDecoratedDisplayName(from)) then
from = zo_strformat(SI_UNIT_NAME, from)
end
-- Split if name too long
local displayedFrom = from
if string.len(displayedFrom) > 8 then
displayedFrom = string.sub(from, 1, 7) .. ".."
end
-- Show
CHAT_SYSTEM.IMLabel:SetText(displayedFrom)
CHAT_SYSTEM.IMLabel:SetHidden(false)
CHAT_SYSTEM.IMbutton:SetHidden(false)
-- Add handler
CHAT_SYSTEM.IMLabel:SetHandler("OnMouseEnter", function(self) ShowIMTooltip(self, lineNumber) end)
CHAT_SYSTEM.IMLabel:SetHandler("OnMouseExit", function(self) HideIMTooltip() end)
end
end
end
-- Hide IM notification when click on it. Can be Called by XML
function rChat_RemoveIMNotification()
CHAT_SYSTEM.IMLabel:SetHidden(true)
CHAT_SYSTEM.IMLabelMin:SetHidden(true)
CHAT_SYSTEM.IMbutton:SetHidden(true)
end
-- Will try to display the notified IM. Called by XML
function rChat_TryToJumpToIm(isMinimized)
if not CHAT_SYSTEM.primaryContainer then return end
-- Show chat first
if isMinimized then
CHAT_SYSTEM:Maximize()
CHAT_SYSTEM.IMLabelMin:SetHidden(true)
end
-- Tab get IM, scroll
if IsChatContainerTabCategoryEnabled(1, rData.activeTab, CHAT_CATEGORY_WHISPER_INCOMING) then
ZO_ChatSystem_ScrollToBottom(CHAT_SYSTEM.control)
rChat_RemoveIMNotification()
else
-- Tab don't have IM's, switch to next
local numTabs = #CHAT_SYSTEM.primaryContainer.windows
local actualTab = rData.activeTab + 1
local oldActiveTab = rData.activeTab
local PRESSED = 1
local UNPRESSED = 2
local hasSwitched = false
local maxt = 1
if not CHAT_SYSTEM.primaryContainer.HandleTabClick then return end
while actualTab <= numTabs and (not hasSwitched) do
if IsChatContainerTabCategoryEnabled(1, actualTab, CHAT_CATEGORY_WHISPER_INCOMING) then
CHAT_SYSTEM.primaryContainer:HandleTabClick(CHAT_SYSTEM.primaryContainer.windows[actualTab].tab)
local tabText = GetControl("ZO_ChatWindowTabTemplate" .. actualTab .. "Text")
tabText:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_SELECTED))
tabText:GetParent().state = PRESSED
local oldTabText = GetControl("ZO_ChatWindowTabTemplate" .. oldActiveTab .. "Text")
oldTabText:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_CONTRAST))
oldTabText:GetParent().state = UNPRESSED
ZO_ChatSystem_ScrollToBottom(CHAT_SYSTEM.control)
hasSwitched = true
else
actualTab = actualTab + 1
end
end
actualTab = 1
-- If we were on tab #3 and IM are show on tab #2, need to restart from 1
while actualTab < oldActiveTab and (not hasSwitched) do
if IsChatContainerTabCategoryEnabled(1, actualTab, CHAT_CATEGORY_WHISPER_INCOMING) then
CHAT_SYSTEM.primaryContainer:HandleTabClick(CHAT_SYSTEM.primaryContainer.windows[actualTab].tab)
local tabText = GetControl("ZO_ChatWindowTabTemplate" .. actualTab .. "Text")
tabText:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_SELECTED))
tabText:GetParent().state = PRESSED
local oldTabText = GetControl("ZO_ChatWindowTabTemplate" .. oldActiveTab .. "Text")
oldTabText:SetColor(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_CONTRAST))
oldTabText:GetParent().state = UNPRESSED
ZO_ChatSystem_ScrollToBottom(CHAT_SYSTEM.control)
hasSwitched = true
else
actualTab = actualTab + 1
end
end
end
end
-- end IM section
-- ----------------------------------------------------------------
-- ------------------------------------------------------
-- Copy functions
-- Set copied text into chatbox text entry, if possible
local function CopyToTextEntry(message)
if not message then return end
-- Max of inputbox is 351 chars
if #message < 351 then
if CHAT_SYSTEM.textEntry:GetText() == "" then
CHAT_SYSTEM.textEntry:Open(message)
ZO_ChatWindowTextEntryEditBox:SelectAll()
end
end
end
-- Copy message (only message)
local function CopyMessage(numLine)
-- Args are passed as string through LinkHandlerSystem
local entry = CACHE.getCacheEntry(numLine)
if entry and entry.rawT and entry.rawT.text then
CopyToTextEntry(entry.rawT.text)
end
end
--Copy line (including timestamp, from, channel, message, etc)
local function CopyLine(numLine)
-- Args are passed as string through LinkHandlerSystem
local entry = CACHE.getCacheEntry(numLine)
if entry and entry.rawLine then
CopyToTextEntry(entry.rawLine)
end
end
-- Popup a dialog message with text to copy
local function ShowCopyDialog(message)
local maxChars = 20000
-- editbox is 20000 chars max
if string.len(message) < maxChars then
rChatCopyDialogTLCTitle:SetText(L(RCHAT_COPYXMLTITLE))
rChatCopyDialogTLCLabel:SetText(L(RCHAT_COPYXMLLABEL))
rChatCopyDialogTLCNoteEdit:SetText(message)
rChatCopyDialogTLCNoteNext:SetHidden(true)
rChatCopyDialogTLC:SetHidden(false)
rChatCopyDialogTLCNoteEdit:SetEditEnabled(false)
rChatCopyDialogTLCNoteEdit:SelectAll()
else
rChatCopyDialogTLCTitle:SetText(L(RCHAT_COPYXMLTITLE))
rChatCopyDialogTLCLabel:SetText(L(RCHAT_COPYXMLTOOLONG))
rData.messageTableId = 1
rData.messageTable = rChat.strSplitMB(message, maxChars)
rChatCopyDialogTLCNoteNext:SetText(L(RCHAT_COPYXMLNEXT) .. " ( " .. rData.messageTableId .. " / " .. #rData.messageTable .. " )")
rChatCopyDialogTLCNoteEdit:SetText(rData.messageTable[rData.messageTableId])
rChatCopyDialogTLCNoteEdit:SetEditEnabled(false)
rChatCopyDialogTLCNoteEdit:SelectAll()
rChatCopyDialogTLC:SetHidden(false)
rChatCopyDialogTLCNoteNext:SetHidden(false)
rChatCopyDialogTLCNoteEdit:TakeFocus()
end
end
-- Copy discussion
-- It will copy all text mark with the same chanCode
-- Todo : Whisps by person
local function CopyDiscussion(chanNumber, numLine)
local entry = CACHE.getCacheEntry(numLine)
if not entry then return end
-- Args are passed as string through LinkHandlerSystem
local numChanCode = tonumber(chanNumber)
-- Whispers sent and received together
if numChanCode == CHAT_CHANNEL_WHISPER_SENT then
numChanCode = CHAT_CHANNEL_WHISPER
elseif numChanCode == RCHAT_URL_CHAN then
numChanCode = entry.channel
end
local stringToCopy = ""
for k, data in CACHE.iterCache() do
if numChanCode == CHAT_CHANNEL_WHISPER or numChanCode == CHAT_CHANNEL_WHISPER_SENT then
if data.channel == CHAT_CHANNEL_WHISPER or data.channel == CHAT_CHANNEL_WHISPER_SENT then
if stringToCopy == "" then
stringToCopy = data.rawLine
else
stringToCopy = stringToCopy .. "\r\n" .. data.rawLine
end
end
elseif data.channel == numChanCode then
if stringToCopy == "" then
stringToCopy = data.rawLine
else
stringToCopy = stringToCopy .. "\r\n" .. data.rawLine