-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathChatTranslator.cs
More file actions
274 lines (255 loc) · 9.81 KB
/
ChatTranslator.cs
File metadata and controls
274 lines (255 loc) · 9.81 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
// TODOS
// Fix broken
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Threading;
using System.Threading.Tasks;
using Dalamud.Logging;
using Dalamud.Configuration;
using Dalamud.Data;
using Dalamud.IoC;
using Dalamud.Game.ClientState;
using Dalamud.Game.Command;
using Dalamud.Game.Gui;
using Dalamud.Game.Text;
using Dalamud.Plugin;
using Lumina.Excel.GeneratedSheets;
using System.Collections.Concurrent;
namespace ChatTranslator
{
public partial class ChatTranslator : IDalamudPlugin
{
[PluginService] public static DalamudPluginInterface PluginInterface { get; private set; } = null!;
[PluginService] public static CommandManager CommandManager { get; private set; } = null!;
[PluginService] public static DataManager Data { get; private set; }
[PluginService] public static ChatGui Chat { get; private set; } = null!;
[PluginService] public static ClientState ClientState { get; private set; }
public string Name => "Chat Translator";
private Config _configuration;
private bool _config;
private int _languageInt = 16;
private int _languageInt2;
private UiColorPick[] _textColour;
private UiColorPick _chooser;
private bool _picker;
private int _tranMode;
private int _oneInt;
private bool _oneChan;
private readonly string[] _tranModeOptions = { "Append", "Replace", "Additional" };
private Lumina.Excel.ExcelSheet<UIColor> _uiColours;
private bool _notSelf;
private bool _whitelist;
private List<string> _blacklist;
private List<int> _chosenLanguages;
private List<XivChatType> _channels = new List<XivChatType>();
private readonly List<string> _lastTranslations = new List<string>();
private ConcurrentQueue<Chatter> _chatters = new ConcurrentQueue<Chatter>();
//private List<Chatter> _chatters = new List<Chatter>();
private bool _chatEngine = true;
private readonly List<XivChatType> _order = new List<XivChatType>
{
XivChatType.None,
XivChatType.Debug,
XivChatType.Urgent,
XivChatType.Notice,
XivChatType.Say,
XivChatType.Shout,
XivChatType.TellOutgoing,
XivChatType.TellIncoming,
XivChatType.Party,
XivChatType.Alliance,
XivChatType.Ls1,
XivChatType.Ls2,
XivChatType.Ls3,
XivChatType.Ls4,
XivChatType.Ls5,
XivChatType.Ls6,
XivChatType.Ls7,
XivChatType.Ls8,
XivChatType.FreeCompany,
XivChatType.NoviceNetwork,
XivChatType.CustomEmote,
XivChatType.StandardEmote,
XivChatType.Yell,
XivChatType.CrossParty,
XivChatType.PvPTeam,
XivChatType.CrossLinkShell1,
XivChatType.Echo,
XivChatType.SystemMessage,
XivChatType.SystemError,
XivChatType.GatheringSystemMessage,
XivChatType.ErrorMessage,
XivChatType.RetainerSale,
XivChatType.CrossLinkShell2,
XivChatType.CrossLinkShell3,
XivChatType.CrossLinkShell4,
XivChatType.CrossLinkShell5,
XivChatType.CrossLinkShell6,
XivChatType.CrossLinkShell7,
XivChatType.CrossLinkShell8
};
private readonly string[] _orderString =
{
"None",
"Debug",
"Urgent",
"Notice",
"Say",
"Shout",
"TellOutgoing",
"TellIncoming",
"Party",
"Alliance",
"Ls1",
"Ls2",
"Ls3",
"Ls4",
"Ls5",
"Ls6",
"Ls7",
"Ls8",
"FreeCompany",
"NoviceNetwork",
"CustomEmote",
"StandardEmote",
"Yell",
"CrossParty",
"PvPTeam",
"CrossLinkShell1",
"Echo",
"SystemMessage",
"SystemError",
"GatheringSystemMessage",
"ErrorMessage",
"RetainerSale",
"CrossLinkShell2",
"CrossLinkShell3",
"CrossLinkShell4",
"CrossLinkShell5",
"CrossLinkShell6",
"CrossLinkShell7",
"CrossLinkShell8"
};
private readonly bool[] _yesNo = {
false, false, false, false, true,
true, false, true, true, true,
true, true, true, true, true,
true, true, true, true, true,
true, false, true, true, true,
true, true, false, false, false,
false, false, true, true, true,
true, true, true, true
};
private readonly string[] _codes = {
"af", "an", "ar", "az", "be_x_old",
"bg", "bn", "br", "bs",
"ca", "ceb", "cs", "cy", "da",
"de", "el", "en", "eo", "es",
"et", "eu", "fa", "fi", "fr",
"gl", "he", "hi", "hr", "ht",
"hu", "hy", "id", "is", "it",
"ja", "jv", "ka", "kk", "ko",
"la", "lb", "lt", "lv",
"mg", "mk", "ml", "mr", "ms",
"new", "nl", "nn", "no", "oc",
"pl", "pt", "ro", "roa_rup",
"ru", "sk", "sl",
"sq", "sr", "sv", "sw", "ta",
"te", "th", "tl", "tr", "uk",
"ur", "vi", "vo", "war", "zh",
"zh_classical", "zh_yue"
};
private readonly string[] _languages = {
"Afrikaans", "Aragonese", "Arabic", "Azerbaijani", "Belarusian",
"Bulgarian", "Bengali", "Breton", "Bosnian",
"Catalan; Valencian", "Cebuano", "Czech", "Welsh", "Danish",
"German", "Greek, Modern", "English", "Esperanto", "Spanish; Castilian",
"Estonian", "Basque", "Persian", "Finnish", "French",
"Galician", "Hebrew", "Hindi", "Croatian", "Haitian; Haitian Creole",
"Hungarian", "Armenian", "Indonesian", "Icelandic", "Italian",
"Japanese", "Javanese", "Georgian", "Kazakh", "Korean",
"Latin", "Luxembourgish; Letzeburgesch", "Lithuanian", "Latvian",
"Malagasy", "Macedonian", "Malayalam", "Marathi", "Malay",
"Nepal Bhasa; Newari", "Dutch; Flemish", "Norwegian Nynorsk; Nynorsk, Norwegian", "Norwegian", "Occitan (post 1500)",
"Polish", "Portuguese", "Romanian; Moldavian; Moldovan", "Romance languages",
"Russian", "Slovak", "Slovenian",
"Albanian", "Serbian", "Swedish", "Swahili", "Tamil",
"Telugu", "Thai", "Tagalog", "Turkish", "Ukrainian",
"Urdu", "Vietnamese", "Volapük", "Waray", "Chinese",
"Chinese Classical", "Chinese yue"
};
public ChatTranslator()
{
_configuration = PluginInterface.GetPluginConfig() as Config ?? new Config();
Chat.ChatMessage += Chat_OnChatMessage;
PluginInterface.UiBuilder.Draw += TranslatorConfigUi;
PluginInterface.UiBuilder.OpenConfigUi += OpenConfigUi;
CommandManager.AddHandler("/trn", new CommandInfo(Command)
{
HelpMessage = "Opens the Chat Translator config menu"
});
_uiColours = Data.Excel.GetSheet<UIColor>();
_channels = _configuration.Channels;
_textColour = _configuration.TextColour;
_tranMode = _configuration.TranMode;
_languageInt = _configuration.Lang;
_whitelist = _configuration.Whitelist;
_notSelf = _configuration.NotSelf;
_oneChan = _configuration.OneChan;
_oneInt = _configuration.OneInt;
_chosenLanguages = _configuration.ChosenLanguages;
_blacklist = _configuration.Blacklist;
Thread t = new Thread(new ThreadStart(ThreadProc));
t.Start();
}
public void ThreadProc()
{
PluginLog.Log("Translation Engine Started");
while (_chatEngine)
{
if(_chatters.Count>0)
{
_chatters.TryDequeue(out Chatter chat);
chat.Sent = true;
var tranSeString = Tran(chat.Message);
Chat.PrintChat(new XivChatEntry { Message = tranSeString, Name = chat.Sender, Type = chat.Type, SenderId = chat.SenderId });
}
}
}
public void Dispose()
{
Chat.ChatMessage -= Chat_OnChatMessage;
PluginInterface.UiBuilder.Draw -= TranslatorConfigUi;
PluginInterface.UiBuilder.OpenConfigUi -= OpenConfigUi;
CommandManager.RemoveHandler("/trn");
_chatEngine = false;
}
private void Command(string command, string arguments) => _config = true;
private void OpenConfigUi()
{
_config = true;
}
}
public class UiColorPick
{
public uint Choice { get; set; }
public uint Option { get; set; }
}
public class Config : IPluginConfiguration
{
public int Version { get; set; } = 0;
public List<XivChatType> Channels { get; set; } = new List<XivChatType>();
public int Lang { get; set; } = 16;
public UiColorPick[] TextColour { get; set; } =
{
new UiColorPick { Choice = 0, Option =0 }
};
public bool NotSelf { get; set; }
public bool Whitelist { get; set; }
public List<int> ChosenLanguages { get; set; } = new List<int>();
public bool OneChan { get; set; }
public int OneInt { get; set; }
public List<string> Blacklist { get; set; } = new List<string>();
public int TranMode { get; set; }
}
}