Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ChatPanelManager.c
Go to the documentation of this file.
1 // Type definition - callbacks of chat commands
3 void ChatCommandCallback(SCR_ChatPanel panel, string data);
4 typedef ScriptInvokerBase<ChatCommandCallback> ChatCommandInvoker;
5 
6 
11 [BaseContainerProps(configRoot: true)]
12 class 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 
29  // Registered chat commands
30  protected ref map<string, ref ChatCommandInvoker> m_mCommands = new map<string, ref ScriptInvokerBase<ChatCommandCallback>>;
31 
32  ScriptedChatEntity m_ChatEntity;
33 
34  //------------------------------------------------------------------------------------------------
35  // PUBLIC
36 
37 
38  //------------------------------------------------------------------------------------------------
40  void OpenChatPanel(notnull SCR_ChatPanel panel)
41  {
42  // Ensure all other panels are closed
43  foreach (SCR_ChatPanel p : m_aChatPanels)
44  {
45  if (p != panel)
46  p.Internal_Close();
47  }
48 
49  panel.Internal_Open();
50  }
51 
52 
53  //------------------------------------------------------------------------------------------------
55  void CloseChatPanel(notnull SCR_ChatPanel panel)
56  {
57  // To be safe, just close all of them
58  CloseAllChatPanels();
59  }
60 
61 
62  //------------------------------------------------------------------------------------------------
64  void ToggleChatPanel(notnull SCR_ChatPanel panel)
65  {
66  // Ensure all other panels are closed
67  foreach (SCR_ChatPanel p : m_aChatPanels)
68  {
69  if (p != panel)
70  p.Internal_Close();
71  }
72 
73  if (panel.IsOpen())
74  panel.Internal_Close();
75  else
76  panel.Internal_Open();
77  }
78 
79 
80  //------------------------------------------------------------------------------------------------
81  void OnMenuClosed()
82  {
83  MenuManager menuManager = GetGame().GetMenuManager();
84 
85  if (!menuManager || !menuManager.IsAnyMenuOpen())
86  ShowAllChatPanels();
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  void ShowAllChatPanels()
91  {
92  foreach (SCR_ChatPanel panel : m_aChatPanels)
93  {
94  panel.GetWidget().SetVisible(true);
95  }
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  void ShowChatPanel(notnull SCR_ChatPanel panel)
100  {
101  panel.GetWidget().SetVisible(true);
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  void HideAllChatPanels()
106  {
107  foreach (SCR_ChatPanel panel : m_aChatPanels)
108  {
109  panel.GetWidget().SetVisible(false);
110  }
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  void CloseAllChatPanels()
115  {
116  foreach (SCR_ChatPanel p : m_aChatPanels)
117  {
118  if (p.IsOpen())
119  p.Internal_Close();
120  }
121  }
122 
123 
124  //------------------------------------------------------------------------------------------------
126  static SCR_ChatPanelManager GetInstance()
127  {
129  }
130 
131 
132  //------------------------------------------------------------------------------------------------
134  array<ref SCR_ChatMessage> GetMessages()
135  {
136  return m_aMessages;
137  }
138 
139 
140 
141  //------------------------------------------------------------------------------------------------
143  array<string> GetAllRegisteredCommands()
144  {
145  array<string> a = {};
146  foreach (string comm, auto invoker : m_mCommands)
147  a.Insert(comm);
148  return a;
149  }
150 
151 
152  //------------------------------------------------------------------------------------------------
153  void ShowHelpMessage(string msg)
154  {
155  ref SCR_ChatMessage m = new SCR_ChatMessage(msg);
156 
157  this.OnNewMessage(m);
158  }
159 
160 
161  //------------------------------------------------------------------------------------------------
164  ChatCommandInvoker GetCommandInvoker(string name)
165  {
166  // Bail if name is incorrect
167  if (name.IsEmpty())
168  return null;
169 
170  ChatCommandInvoker invoker = m_mCommands.Get(name);
171 
172  if (!invoker)
173  {
174  invoker = new ChatCommandInvoker;
175  m_mCommands.Insert(name, invoker);
176  }
177 
178  // Verify
179  if (!m_mCommands.Get(name))
180  Print(string.Format("Error while registering chat command: %1", name), LogLevel.WARNING);
181 
182  return invoker;
183  }
184 
185 
186  //------------------------------------------------------------------------------------------------
188  bool GetAnyPanelFadedIn()
189  {
190  foreach (SCR_ChatPanel panel : m_aChatPanels)
191  {
192  if (panel.GetFadeIn())
193  return true;
194  }
195 
196  return false;
197  }
198 
199 
200  //------------------------------------------------------------------------------------------------
202 
203  //------------------------------------------------------------------------------------------------
204  void Register(SCR_ChatPanel panel)
205  {
206  if (!m_aChatPanels.Contains(panel))
207  m_aChatPanels.Insert(panel);
208 
209  CloseAllChatPanels();
210  }
211 
212  //------------------------------------------------------------------------------------------------
213  void Unregister(SCR_ChatPanel panel)
214  {
215  m_aChatPanels.RemoveItem(panel);
216  }
217 
218 
219 
220 
221  //------------------------------------------------------------------------------------------------
223 
224  //------------------------------------------------------------------------------------------------
225  void OnNewMessagePrivate(string msg, int senderId, int receiverId)
226  {
227  if (!m_ChatEntity)
228  return;
229 
230  int playerId = GetGame().GetPlayerController().GetPlayerId();
231 
232  if (! (senderId == playerId || receiverId == playerId))
233  return;
234 
236  msg,
237  m_ChatEntity.GetWhisperChannel(),
238  senderId,
239  GetGame().GetPlayerManager().GetPlayerName(senderId),
240  receiverId);
241 
242  OnNewMessage(m);
243  }
244 
245  //------------------------------------------------------------------------------------------------
246  void OnNewMessageRadioProtocol(string msg, int frequency)
247  {
249  msg,
250  frequency);
251 
252  this.OnNewMessage(m);
253  }
254 
255  //------------------------------------------------------------------------------------------------
256  void OnNewMessageGeneral(string msg, int channelId, int senderId)
257  {
259  msg,
260  m_ChatEntity.GetChannel(channelId),
261  senderId,
262  GetGame().GetPlayerManager().GetPlayerName(senderId));
263 
264  this.OnNewMessage(m);
265  }
266 
267  //------------------------------------------------------------------------------------------------
268  void OnNewMessage(string msg)
269  {
270  SCR_ChatMessage m = new SCR_ChatMessage(msg);
271 
272  this.OnNewMessage(m);
273  }
274 
275 
276 
277 
278  //------------------------------------------------------------------------------------------------
280 
281 
282  //------------------------------------------------------------------------------------------------
283  override void OnGameStart()
284  {
285  // Clear message array so we don't see messages from previous session
286  m_aMessages.Clear();
287 
288  m_ChatEntity = ScriptedChatEntity.Cast(GetGame().GetChat());
289 
290  // OnGameStart runs several time for same object,
291  // but this code must be run only once
292  if (!m_bInitDone)
293  {
294  InitDefaultChatCommands();
295  m_bInitDone = true;
296  }
297  }
298 
299  //------------------------------------------------------------------------------------------------
300  override void OnGameEnd()
301  {
302  m_aMessages.Clear();
303  }
304 
305  //------------------------------------------------------------------------------------------------
306  protected void InitDefaultChatCommands()
307  {
308  }
309 
310  //------------------------------------------------------------------------------------------------
312  void Internal_EnableAllChannels()
313  {
314  PlayerController pc = GetGame().GetPlayerController();
315 
316  if (!pc || !m_ChatEntity)
317  return;
318 
319  BaseChatComponent chatComp = BaseChatComponent.Cast(pc.FindComponent(BaseChatComponent));
320 
321  if (!chatComp)
322  return;
323 
324  for (int i = 0; i< m_ChatEntity.GetChannelsCount() ; i++)
325  {
326  BaseChatChannel chatChannel = m_ChatEntity.GetChannel(i);
327  chatComp.SetChannel(i, true);
328  }
329  }
330 
331 
332  //------------------------------------------------------------------------------------------------
334 
335  //------------------------------------------------------------------------------------------------
337  void Internal_OnChatCommand(SCR_ChatPanel panel, string command, string otherData)
338  {
339  auto invoker = m_mCommands.Get(command);
340 
341  if (!invoker)
342  return;
343 
344  invoker.Invoke(panel, otherData);
345  }
346 
347 
348 
349  //------------------------------------------------------------------------------------------------
350  // PROTECTED
351 
352 
353  //------------------------------------------------------------------------------------------------
354  protected void OnNewMessage(SCR_ChatMessage msg)
355  {
356  m_aMessages.Insert(msg);
357 
358  if (m_aMessages.Count() > CHAT_HISTORY_SIZE)
359  m_aMessages.RemoveOrdered(0);
360 
362  foreach (SCR_ChatPanel panel : m_aChatPanels)
363  panel.Internal_OnNewMessage(msg);
364  }
365 };
SCR_ChatMessageGeneral
Definition: SCR_ChatMessage.c:19
ScriptedChatEntity
Definition: ScriptedChatEntity.c:9
SCR_ChatMessagePrivate
Definition: SCR_ChatMessage.c:35
m_ChatEntity
protected ScriptedChatEntity m_ChatEntity
Definition: game.c:42
ChatCommandInvoker
ScriptInvokerBase< ChatCommandCallback > ChatCommandInvoker
Definition: SCR_ChatPanelManager.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ChatPanelManager
Definition: SCR_ChatPanelManager.c:12
SCR_GameCoresManager
Definition: SCR_GameCoresManager.c:8
SCR_ChatMessageRadioProtocol
Definition: SCR_ChatMessage.c:46
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_ChatPanel
Definition: SCR_ChatPanel.c:6
SCR_ChatMessage
Definition: SCR_ChatMessage.c:7
ChatCommandCallback
func ChatCommandCallback
Definition: SCR_ChatPanelManager.c:2
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
BaseChatChannel
Definition: BaseChatChannel.c:12
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468