Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ChatPanelManager.c
Go to the documentation of this file.
1// Type definition - callbacks of chat commands
4typedef ScriptInvokerBase<ChatCommandCallback> ChatCommandInvoker;
5
6
11[BaseContainerProps(configRoot: true)]
12class SCR_ChatPanelManager : SCR_GameCoreBase
13{
14 // Constants
15
16 // Size of chat history. When more messages than this are added, old messages are deleted.
17 protected const int CHAT_HISTORY_SIZE = 256;
18
19 // Start character of each command
20 // note: admin commands are different and are not handled by this chat UI system. They start with a different character.
21 const string CHAT_COMMAND_CHARACTER = "/";
22
23
24 protected bool m_bInitDone = false;
25
26 protected ref array<ref SCR_ChatMessage> m_aMessages = {};
27 protected ref array<SCR_ChatPanel> m_aChatPanels = {};
28 protected ref array<ref SCR_ProfanityFilterRequestCallback> m_aProfanityCallbacks = {};
29
30 // Registered chat commands
32
34
35 //------------------------------------------------------------------------------------------------
36 // PUBLIC
37
38
39 //------------------------------------------------------------------------------------------------
41 void OpenChatPanel(notnull SCR_ChatPanel panel)
42 {
43 // Ensure all other panels are closed
44 foreach (SCR_ChatPanel p : m_aChatPanels)
45 {
46 if (p != panel)
47 p.Internal_Close();
48 }
49
50 panel.Internal_Open();
51 }
52
53
54 //------------------------------------------------------------------------------------------------
56 void CloseChatPanel(notnull SCR_ChatPanel panel)
57 {
58 // To be safe, just close all of them
60 }
61
62
63 //------------------------------------------------------------------------------------------------
65 void ToggleChatPanel(notnull SCR_ChatPanel panel)
66 {
67 // Ensure all other panels are closed
68 foreach (SCR_ChatPanel p : m_aChatPanels)
69 {
70 if (p != panel)
71 p.Internal_Close();
72 }
73
74 if (panel.IsOpen())
75 panel.Internal_Close();
76 else
77 panel.Internal_Open();
78 }
79
80
81 //------------------------------------------------------------------------------------------------
83 {
84 MenuManager menuManager = GetGame().GetMenuManager();
85
86 if (!menuManager || !menuManager.IsAnyMenuOpen())
88 }
89
90 //------------------------------------------------------------------------------------------------
92 {
93 foreach (SCR_ChatPanel panel : m_aChatPanels)
94 {
95 panel.GetWidget().SetVisible(true);
96 }
97 }
98
99 //------------------------------------------------------------------------------------------------
100 void ShowChatPanel(notnull SCR_ChatPanel panel)
101 {
102 panel.GetWidget().SetVisible(true);
103 }
104
105 //------------------------------------------------------------------------------------------------
107 {
108 foreach (SCR_ChatPanel panel : m_aChatPanels)
109 {
110 panel.GetWidget().SetVisible(false);
111 }
112 }
113
114 //------------------------------------------------------------------------------------------------
116 {
117 foreach (SCR_ChatPanel p : m_aChatPanels)
118 {
119 if (p.IsOpen())
120 p.Internal_Close();
121 }
122 }
123
124
125 //------------------------------------------------------------------------------------------------
131
132
133 //------------------------------------------------------------------------------------------------
135 array<ref SCR_ChatMessage> GetMessages()
136 {
137 return m_aMessages;
138 }
139
140
141
142 //------------------------------------------------------------------------------------------------
145 {
146 array<string> a = {};
147 foreach (string comm, auto invoker : m_mCommands)
148 a.Insert(comm);
149 return a;
150 }
151
152
153 //------------------------------------------------------------------------------------------------
154 void ShowHelpMessage(string msg)
155 {
156 ref SCR_ChatMessage m = new SCR_ChatMessage(msg);
157
158 this.OnNewMessage(m);
159 }
160
161
162 //------------------------------------------------------------------------------------------------
166 {
167 // Bail if name is incorrect
168 if (name.IsEmpty())
169 return null;
170
171 ChatCommandInvoker invoker = m_mCommands.Get(name);
172
173 if (!invoker)
174 {
175 invoker = new ChatCommandInvoker;
176 m_mCommands.Insert(name, invoker);
177 }
178
179 // Verify
180 if (!m_mCommands.Get(name))
181 Print(string.Format("Error while registering chat command: %1", name), LogLevel.WARNING);
182
183 return invoker;
184 }
185
186
187 //------------------------------------------------------------------------------------------------
190 {
191 foreach (SCR_ChatPanel panel : m_aChatPanels)
192 {
193 if (panel.GetFadeIn())
194 return true;
195 }
196
197 return false;
198 }
199
200
201 //------------------------------------------------------------------------------------------------
203
204 //------------------------------------------------------------------------------------------------
206 {
207 if (!m_aChatPanels.Contains(panel))
208 m_aChatPanels.Insert(panel);
209
211 }
212
213 //------------------------------------------------------------------------------------------------
215 {
216 m_aChatPanels.RemoveItem(panel);
217 }
218
219
220
221
222 //------------------------------------------------------------------------------------------------
224
225 //------------------------------------------------------------------------------------------------
226 void OnNewMessagePrivate(string msg, int senderId, int receiverId)
227 {
228 if (!m_ChatEntity)
229 return;
230
231 int playerId = GetGame().GetPlayerController().GetPlayerId();
232
233 if (! (senderId == playerId || receiverId == playerId))
234 return;
235
237 msg,
238 m_ChatEntity.GetWhisperChannel(),
239 senderId,
240 //GetGame().GetPlayerManager().GetPlayerName(senderId),
241 SCR_PlayerNamesFilterCache.GetInstance().GetPlayerDisplayName(senderId),
242 receiverId);
243
244 OnNewMessage(m);
245 }
246
247 //------------------------------------------------------------------------------------------------
248 void OnNewMessageRadioProtocol(string msg, int frequency)
249 {
251 msg,
252 frequency);
253
254 this.OnNewMessage(m);
255 }
256
257 //------------------------------------------------------------------------------------------------
258 void OnNewMessageGeneral(string msg, int channelId, int senderId)
259 {
261 msg,
262 m_ChatEntity.GetChannel(channelId),
263 senderId,
264 //GetGame().GetPlayerManager().GetPlayerName(senderId));
265 SCR_PlayerNamesFilterCache.GetInstance().GetPlayerDisplayName(senderId));
266
267 this.OnNewMessage(m);
268 }
269
270 //------------------------------------------------------------------------------------------------
271 void OnNewMessage(string msg)
272 {
273 SCR_ChatMessage m = new SCR_ChatMessage(msg);
274
275 this.OnNewMessage(m);
276 }
277
278
279
280
281 //------------------------------------------------------------------------------------------------
283
284
285 //------------------------------------------------------------------------------------------------
286 override void OnGameStart()
287 {
288 // Clear message array so we don't see messages from previous session
289 m_aMessages.Clear();
290
291 m_ChatEntity = ScriptedChatEntity.Cast(GetGame().GetChat());
292
293 // OnGameStart runs several time for same object,
294 // but this code must be run only once
295 if (!m_bInitDone)
296 {
298 m_bInitDone = true;
299 }
300 }
301
302 //------------------------------------------------------------------------------------------------
303 override void OnGameEnd()
304 {
305 m_aMessages.Clear();
306 }
307
308 //------------------------------------------------------------------------------------------------
309 protected void InitDefaultChatCommands()
310 {
311 }
312
313 //------------------------------------------------------------------------------------------------
316 {
317 PlayerController pc = GetGame().GetPlayerController();
318
319 if (!pc || !m_ChatEntity)
320 return;
321
322 BaseChatComponent chatComp = BaseChatComponent.Cast(pc.FindComponent(BaseChatComponent));
323
324 if (!chatComp)
325 return;
326
327 for (int i = 0; i< m_ChatEntity.GetChannelsCount() ; i++)
328 {
329 BaseChatChannel chatChannel = m_ChatEntity.GetChannel(i);
330 chatComp.SetChannel(i, true);
331 }
332 }
333
334
335 //------------------------------------------------------------------------------------------------
337
338 //------------------------------------------------------------------------------------------------
340 void Internal_OnChatCommand(SCR_ChatPanel panel, string command, string otherData)
341 {
342 auto invoker = m_mCommands.Get(command);
343
344 if (!invoker)
345 return;
346
347 invoker.Invoke(panel, otherData);
348 }
349
350
351
352 //------------------------------------------------------------------------------------------------
353 // PROTECTED
354
355
356 //------------------------------------------------------------------------------------------------
357 protected void OnNewMessage(SCR_ChatMessage msg)
358 {
360 array<string> textToFilter = {};
361 textToFilter.Insert(msg.m_sMessage);
362 filterCallback.m_OnResultInstance.Insert(OnMessageFiltered);
363 m_aProfanityCallbacks.Insert(filterCallback);
364
365 //if we return fail, we call the method manually to still show the unchanged text and delete callback
366 if (!GetGame().GetPlatformService().FilterProfanityAsync(textToFilter, filterCallback))
367 OnMessageFiltered(filterCallback, textToFilter, msg);
368 }
369
370 //------------------------------------------------------------------------------------------------
371 protected void OnMessageFiltered(SCR_ProfanityFilterRequestCallback callback, array<string> filteredTexts, SCR_ChatMessage originalMessage)
372 {
373 // We may get back multiple lines if the input used \n, so join them together.
374 const string multiLineString = SCR_StringHelper.Join("\n", filteredTexts, true);
375
376 if (GetGame().GetPlatformService().GetLocalPlatformKind() == PlatformKind.XBOX)
377 {
378 SCR_ProfaneFilter.ReplaceProfanities(multiLineString, originalMessage.m_sMessage);
379 }
380 else
381 {
382 originalMessage.m_sMessage = multiLineString;
383 }
384
385 m_aMessages.Insert(originalMessage);
386
387 if (m_aMessages.Count() > CHAT_HISTORY_SIZE)
388 m_aMessages.RemoveOrdered(0);
389
391 foreach (SCR_ChatPanel panel : m_aChatPanels)
392 panel.Internal_OnNewMessage(originalMessage);
393
394 m_aProfanityCallbacks.RemoveItem(callback);
395 }
396};
397
398class SCR_ProfanityFilterRequestCallback : SCR_ScriptProfanityFilterRequestCallback
399{
400 ref ScriptInvoker m_OnResultInstance = new ScriptInvoker; //(SCR_ProfanityFilterRequestCallback callback, array<string> filteredTexts, SCR_ChatMessage originalMessage)
401 ref SCR_ChatMessage m_OriginalMessage;
402
403 void SCR_ProfanityFilterRequestCallback(SCR_ChatMessage originalMgs)
404 {
405 m_OriginalMessage = originalMgs;
406 }
407
408 //------------------------------------------------------------------------------------------------
409 override void OnFilteredResult()
410 {
411 GetTexts(m_FilteredTexts);
412 m_OnResultInstance.Invoke(this, m_FilteredTexts, m_OriginalMessage);
413 }
414};
ArmaReforgerScripted GetGame()
Definition game.c:1398
PlatformKind
Definition PlatformKind.c:8
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
func ChatCommandCallback
ScriptInvokerBase< ChatCommandCallback > ChatCommandInvoker
Get all prefabs that have the spawner data
proto external bool IsAnyMenuOpen()
ScriptedChatEntity m_ChatEntity
void OpenChatPanel(notnull SCR_ChatPanel panel)
Opens the chat panel and ensures that all other panels are closed.
ref array< ref SCR_ProfanityFilterRequestCallback > m_aProfanityCallbacks
void ShowHelpMessage(string msg)
void Register(SCR_ChatPanel panel)
Registration of chat panels. These are called when a chat panel is created and destroyed.
void Internal_EnableAllChannels()
Enables all channels.
array< ref SCR_ChatMessage > GetMessages()
Returns the array of messages. Array is not a copy, so be careful.
void Internal_OnChatCommand(SCR_ChatPanel panel, string command, string otherData)
OTHER.
void ShowChatPanel(notnull SCR_ChatPanel panel)
override void OnGameStart()
Initializaiton.
void OnNewMessagePrivate(string msg, int senderId, int receiverId)
Handling of new messages. Called by SCR_ChatComponent.
void OnNewMessage(string msg)
array< string > GetAllRegisteredCommands()
Returns an array of all commands registered with GetCommandInvoker.
ref array< ref SCR_ChatMessage > m_aMessages
static SCR_ChatPanelManager GetInstance()
Returns SCR_ChatPanelManager instance.
ChatCommandInvoker GetCommandInvoker(string name)
void CloseChatPanel(notnull SCR_ChatPanel panel)
Closes the chat panel.
ref array< SCR_ChatPanel > m_aChatPanels
void OnNewMessage(SCR_ChatMessage msg)
ref map< string, ref ChatCommandInvoker > m_mCommands
void OnMessageFiltered(SCR_ProfanityFilterRequestCallback callback, array< string > filteredTexts, SCR_ChatMessage originalMessage)
bool GetAnyPanelFadedIn()
Returns true when there is any chat panel faded in.
void Unregister(SCR_ChatPanel panel)
void OnNewMessageGeneral(string msg, int channelId, int senderId)
void OnNewMessageRadioProtocol(string msg, int frequency)
const string CHAT_COMMAND_CHARACTER
void ToggleChatPanel(notnull SCR_ChatPanel panel)
Toggles the chat panel: opens if it's closed, closes if it's open.
static SCR_GameCoreBase GetCore(typename type)
Handles filtering profanities in texts.
static string Join(string separator, notnull array< string > pieces, bool joinEmptyEntries=true)
Definition Types.c:486
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134