17 protected const int CHAT_HISTORY_SIZE = 256;
21 const string CHAT_COMMAND_CHARACTER =
"/";
24 protected bool m_bInitDone =
false;
26 protected ref array<ref SCR_ChatMessage> m_aMessages = {};
27 protected ref array<SCR_ChatPanel> m_aChatPanels = {};
30 protected ref map<string, ref ChatCommandInvoker> m_mCommands =
new map<string, ref ScriptInvokerBase<ChatCommandCallback>>;
49 panel.Internal_Open();
74 panel.Internal_Close();
76 panel.Internal_Open();
83 MenuManager menuManager =
GetGame().GetMenuManager();
85 if (!menuManager || !menuManager.IsAnyMenuOpen())
90 void ShowAllChatPanels()
94 panel.GetWidget().SetVisible(
true);
101 panel.GetWidget().SetVisible(
true);
105 void HideAllChatPanels()
109 panel.GetWidget().SetVisible(
false);
114 void CloseAllChatPanels()
134 array<ref SCR_ChatMessage> GetMessages()
143 array<string> GetAllRegisteredCommands()
145 array<string> a = {};
146 foreach (
string comm,
auto invoker : m_mCommands)
153 void ShowHelpMessage(
string msg)
157 this.OnNewMessage(m);
175 m_mCommands.Insert(name, invoker);
179 if (!m_mCommands.Get(name))
180 Print(
string.Format(
"Error while registering chat command: %1", name), LogLevel.WARNING);
188 bool GetAnyPanelFadedIn()
192 if (panel.GetFadeIn())
206 if (!m_aChatPanels.Contains(panel))
207 m_aChatPanels.Insert(panel);
209 CloseAllChatPanels();
215 m_aChatPanels.RemoveItem(panel);
225 void OnNewMessagePrivate(
string msg,
int senderId,
int receiverId)
230 int playerId =
GetGame().GetPlayerController().GetPlayerId();
232 if (! (senderId == playerId || receiverId == playerId))
239 GetGame().GetPlayerManager().GetPlayerName(senderId),
246 void OnNewMessageRadioProtocol(
string msg,
int frequency)
252 this.OnNewMessage(m);
256 void OnNewMessageGeneral(
string msg,
int channelId,
int senderId)
262 GetGame().GetPlayerManager().GetPlayerName(senderId));
264 this.OnNewMessage(m);
268 void OnNewMessage(
string msg)
272 this.OnNewMessage(m);
283 override void OnGameStart()
294 InitDefaultChatCommands();
300 override void OnGameEnd()
306 protected void InitDefaultChatCommands()
312 void Internal_EnableAllChannels()
314 PlayerController pc =
GetGame().GetPlayerController();
319 BaseChatComponent chatComp = BaseChatComponent.Cast(pc.FindComponent(BaseChatComponent));
324 for (
int i = 0; i<
m_ChatEntity.GetChannelsCount() ; i++)
327 chatComp.SetChannel(i,
true);
337 void Internal_OnChatCommand(
SCR_ChatPanel panel,
string command,
string otherData)
339 auto invoker = m_mCommands.Get(command);
344 invoker.Invoke(panel, otherData);
356 m_aMessages.Insert(msg);
358 if (m_aMessages.Count() > CHAT_HISTORY_SIZE)
359 m_aMessages.RemoveOrdered(0);
363 panel.Internal_OnNewMessage(msg);