Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_NotificationsComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Network", description: "")]
2 class SCR_NotificationsComponentClass: ScriptComponentClass
3 {
4  [Attribute("{7134157CA6B1FA8E}Configs/Notifications/Notifications.conf", desc: "Link to config that holds all notification data", params: "conf class=SCR_NotificationConfig")]
5  protected ResourceName m_sNotificationConfig;
6 
7  protected ref map<ENotification, ref SCR_NotificationDisplayData> m_mNotificationDisplayDataMap = new map<ENotification, ref SCR_NotificationDisplayData>();
8 
9  protected ref SCR_NotificationConfig notificationConfig;
10 
11  //------------------------------------------------------------------------------------------------
15  SCR_NotificationDisplayData GetNotificationDisplayData(ENotification notificationID)
16  {
17  SCR_NotificationDisplayData notificationData;
18 
19  if (m_mNotificationDisplayDataMap.Find(notificationID, notificationData))
20  return notificationData;
21 
22  Print("Notification data not found in 'SCR_NotificationsComponent' for key: '" + typename.EnumToString(ENotification, notificationID) + "'.", LogLevel.WARNING);
23  m_mNotificationDisplayDataMap.Find(ENotification.UNKNOWN, notificationData);
24 
25  return notificationData;
26  }
27 
28  //------------------------------------------------------------------------------------------------
30  array<string> GetStickyNotifications()
31  {
32  return notificationConfig.GetStickyNotifications();
33  }
34 
35  //------------------------------------------------------------------------------------------------
37  array<ref SCR_NotificationDisplayColor> GetNotificationDisplayColor()
38  {
39  return notificationConfig.GetNotificationDisplayColor();
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  // constructor
45  //~ Constructor creates notification map for the system to get the notification data for each ENotification
46  void SCR_NotificationsComponentClass(BaseContainer prefab)
47  {
48  //~ Notification map already filled
49  if (!m_mNotificationDisplayDataMap.IsEmpty())
50  return;
51 
52  //~ Get config
53  notificationConfig = SCR_NotificationConfig.Cast(SCR_BaseContainerTools.CreateInstanceFromPrefab(m_sNotificationConfig, true));
54  if (!notificationConfig)
55  {
56  Print("'SCR_NotificationsComponentClass' failed to load notifications config!", LogLevel.ERROR);
57  return;
58  }
59 
60  //~ Get data
61  array<ref SCR_NotificationDisplayData> data = {};
62  int count = notificationConfig.GetNotificationData(data);
63 
64  //~ Gegenerate
65  for(int i = 0; i < count; i++)
66  {
67  if (!m_mNotificationDisplayDataMap.Contains(data[i].m_NotificationKey))
68  m_mNotificationDisplayDataMap.Set(data[i].m_NotificationKey, data[i]);
69  else
70  Print("Notification data in 'SCR_NotificationsLogDisplay' has duplicate notification info key: '" + typename.EnumToString(ENotification, data[i].m_NotificationKey) + "'. There should only be one of each key!", LogLevel.WARNING);
71  }
72  }
73 }
74 
76 class SCR_NotificationsComponent : ScriptComponent
77 {
78  protected ref array<ref SCR_NotificationData> m_aHistory = {};
79  protected ref ScriptInvoker Event_OnNotification = new ScriptInvoker();
80 
83 
84  //How long each notification exists before it gets deleted, Time in seconds
85  static const int NOTIFICATION_DELETE_TIME = 30;
86 
87  //How many notifications are remembered in history.
88  static const int NOTIFICATION_HISTORY_LENGTH = 10;
89 
90  //Hot fix for when player names cannot be found
91  protected ref map <int, string> m_mPlayerNameHistory = new map <int, string>();
92 
93  //------------------------------------------------------------------------------------------------
96  ScriptInvoker GetOnNotification()
97  {
98  return Event_OnNotification;
99  }
100 
101  //------------------------------------------------------------------------------------------------
105  int GetHistoryNewToOld(out notnull array<SCR_NotificationData> outHistory)
106  {
107  int count = m_aHistory.Count();
108  foreach (SCR_NotificationData entry : m_aHistory)
109  {
110  outHistory.Insert(entry);
111  }
112  return count;
113  }
114 
115  //------------------------------------------------------------------------------------------------
120  int GetHistoryOldToNew(out notnull array<SCR_NotificationData> outHistory, int maxHistoryIndex = -1)
121  {
122  int count = m_aHistory.Count();
123  if (maxHistoryIndex > 0 && count > maxHistoryIndex)
124  count = maxHistoryIndex;
125 
126  for (int i = count -1; i >= 0; i--)
127  {
128  outHistory.Insert(m_aHistory[i]);
129  }
130  return count;
131  }
132 
133  //------------------------------------------------------------------------------------------------
139  {
140  if (index < m_aHistory.Count())
141  {
142  data = m_aHistory[index];
143  return true;
144  }
145  else
146  {
147  return false;
148  }
149  }
150 
151  //------------------------------------------------------------------------------------------------
155  bool GetLastNotificationLocation(out vector lastLocation)
156  {
158  return false;
159 
160  return m_LastNotificationWithLocation.GetDisplayData().GetPosition(m_LastNotificationWithLocation, lastLocation);
161  }
162 
163  //------------------------------------------------------------------------------------------------
166  static SCR_NotificationsComponent GetInstance()
167  {
168  PlayerController playerController = GetGame().GetPlayerController();
169  if (playerController)
170  return SCR_NotificationsComponent.Cast(playerController.FindComponent(SCR_NotificationsComponent));
171  else
172  return null;
173  }
174 
175  //------------------------------------------------------------------------------------------------
185  static bool SendToEveryone(ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
186  {
187  return SendToEveryone(notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
188  }
189 
190  //------------------------------------------------------------------------------------------------
201  static bool SendToEveryone(ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
202  {
203  //~ Send from client to server to broadcast
204  if (!Replication.IsServer())
205  {
206  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(SCR_PlayerController.GetLocalPlayerId()));
207  if (!playerController)
208  return false;
209 
210  SCR_NotificationsComponent notificationsComponent = SCR_NotificationsComponent.Cast(playerController.FindComponent(SCR_NotificationsComponent));
211  if (!notificationsComponent)
212  return false;
213 
214  array<int> paramArray = {};
215  CreateParamArray(paramArray, param1, param2, param3, param4, param5, param6);
216 
217  notificationsComponent.Rpc(notificationsComponent.Rpc_SendToEveryone, notificationID, position, paramArray);
218  return true;
219  }
220 
221  SCR_NotificationData newNotificationData = SCR_NotificationData();
222  newNotificationData.SetParameters(ENotificationReceiver.EVERYONE, param1, param2, param3, param4, param5, param6);
223  newNotificationData.SetPosition(position);
224  return SendToEveryoneData(notificationID, newNotificationData);
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  //~ Allows client to broadcast notification to everyone
229  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
230  protected void Rpc_SendToEveryone(ENotification notificationID, vector position, notnull array<int> paramArray)
231  {
232  int param1, param2, param3, param4, param5, param6;
233  GetParamsFromArray(paramArray, param1, param2, param3, param4, param5, param6);
234 
235  SendToEveryone(notificationID, position, param1, param2, param3, param4, param5, param6);
236  }
237 
238  //------------------------------------------------------------------------------------------------
239  //Set the actual data to players
240  protected static bool SendToEveryoneData(ENotification notificationID, SCR_NotificationData data)
241  {
242  //--- Only server can broadcast messages
243  if (!Replication.IsServer())
244  return false;
245 
246  array<int> players = {};
247  for (int i = 0, count = GetGame().GetPlayerManager().GetPlayers(players); i < count; i++)
248  {
249  SendToPlayerData(players[i], notificationID, data);
250  }
251  return true;
252  }
253 
254  //------------------------------------------------------------------------------------------------
265  static bool SendToPlayer(int playerID, ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
266  {
267  return SendToPlayer(playerID, notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
268  }
269 
270  //------------------------------------------------------------------------------------------------
282  static bool SendToPlayer(int playerID, ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
283  {
284  //~ Send from client to server
285  if (!Replication.IsServer())
286  {
287  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(SCR_PlayerController.GetLocalPlayerId()));
288  if (!playerController)
289  return false;
290 
291  SCR_NotificationsComponent notificationsComponent = SCR_NotificationsComponent.Cast(playerController.FindComponent(SCR_NotificationsComponent));
292  if (!notificationsComponent)
293  return false;
294 
295  array<int> paramArray = {};
296  CreateParamArray(paramArray, param1, param2, param3, param4, param5, param6);
297 
298  notificationsComponent.Rpc(notificationsComponent.Rpc_SendToPlayer, playerID, notificationID, position, paramArray);
299  return true;
300  }
301 
302  SCR_NotificationData newNotificationData = SCR_NotificationData();
303  newNotificationData.SetParameters(ENotificationReceiver.SPECIFIC_PLAYER, param1, param2, param3, param4, param5, param6);
304  newNotificationData.SetPosition(position);
305  return SendToPlayerData(playerID, notificationID, newNotificationData);
306  }
307 
308  //------------------------------------------------------------------------------------------------
309  //~ Allows client to broadcast notification to specific player
310  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
311  protected void Rpc_SendToPlayer(int playerID, ENotification notificationID, vector position, notnull array<int> paramArray)
312  {
313  int param1, param2, param3, param4, param5, param6;
314  GetParamsFromArray(paramArray, param1, param2, param3, param4, param5, param6);
315 
316  SendToPlayer(playerID, notificationID, position, param1, param2, param3, param4, param5, param6);
317  }
318 
319  //------------------------------------------------------------------------------------------------
320  //Set the actual data to player
321  protected static bool SendToPlayerData(int playerID, ENotification notificationID, SCR_NotificationData data)
322  {
323  //~ Only server can broadcast messages
324  if (!Replication.IsServer())
325  return false;
326 
327  PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerID);
328  if (!playerController)
329  return false;
330 
331  SCR_NotificationsComponent notificationsComponent = SCR_NotificationsComponent.Cast(playerController.FindComponent(SCR_NotificationsComponent));
332  if (!notificationsComponent)
333  return false;
334 
335  notificationsComponent.SendToOwner(notificationID, data);
336  return true;
337  }
338 
339  //------------------------------------------------------------------------------------------------
351  static bool SendToFaction(notnull SCR_Faction faction, bool includeFriendlyFactions, ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
352  {
353  return SendToFaction(faction, includeFriendlyFactions, notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
354  }
355 
356  //------------------------------------------------------------------------------------------------
369  static bool SendToFaction(notnull SCR_Faction faction, bool includeFriendlyFactions, ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
370  {
371  //~ Send from client to server
372  if (!Replication.IsServer())
373  {
374  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(SCR_PlayerController.GetLocalPlayerId()));
375  if (!playerController)
376  return false;
377 
378  SCR_NotificationsComponent notificationsComponent = SCR_NotificationsComponent.Cast(playerController.FindComponent(SCR_NotificationsComponent));
379  if (!notificationsComponent)
380  return false;
381 
382  FactionManager factionManager = GetGame().GetFactionManager();
383  if (!factionManager)
384  return false;
385 
386  array<int> paramArray = {};
387  CreateParamArray(paramArray, param1, param2, param3, param4, param5, param6);
388 
389  notificationsComponent.Rpc(notificationsComponent.Rpc_SendToFaction, factionManager.GetFactionIndex(faction), includeFriendlyFactions, notificationID, position, paramArray);
390  return true;
391  }
392 
393  SCR_NotificationData newNotificationData = SCR_NotificationData();
394  newNotificationData.SetParameters(ENotificationReceiver.SPECIFIC_PLAYER, param1, param2, param3, param4, param5, param6);
395  newNotificationData.SetPosition(position);
396  return SendToFactionData(faction, includeFriendlyFactions, notificationID, newNotificationData);
397  }
398 
399  //------------------------------------------------------------------------------------------------
400  //~ Allows client to broadcast notification to faction
401  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
402  protected void Rpc_SendToFaction(int factionIndex, bool includeFriendlyFactions, ENotification notificationID, vector position, notnull array<int> paramArray)
403  {
404  FactionManager factionManager = GetGame().GetFactionManager();
405  if (!factionManager)
406  return;
407 
408  SCR_Faction faction = SCR_Faction.Cast(factionManager.GetFactionByIndex(factionIndex));
409  if (!faction)
410  return;
411 
412  int param1, param2, param3, param4, param5, param6;
413  GetParamsFromArray(paramArray, param1, param2, param3, param4, param5, param6);
414 
415  SendToFaction(faction, includeFriendlyFactions, notificationID, position, param1, param2, param3, param4, param5, param6);
416  }
417 
418  //------------------------------------------------------------------------------------------------
419  //Set the actual data to players in faction
420  protected static bool SendToFactionData(notnull SCR_Faction faction, bool includeFriendlyFactions, ENotification notificationID, SCR_NotificationData data)
421  {
422  //--- Only server can broadcast messages
423  if (!Replication.IsServer())
424  return false;
425 
426  array<int> players = {};
427  faction.GetPlayersInFaction(players);
428 
429  foreach(int playerID : players)
430  {
431  SendToPlayerData(playerID, notificationID, data);
432  }
433 
434  if (!includeFriendlyFactions)
435  return true;
436 
437  //~ If also include friendly factions send it to those factions as well
438  FactionManager factionManager = GetGame().GetFactionManager();
439 
440  if (factionManager)
441  {
442  array<Faction> allFactions = {};
443  SCR_Faction scrFaction;
444  factionManager.GetFactionsList(allFactions);
445 
446  foreach(Faction otherFaction : allFactions)
447  {
448  if (otherFaction == faction)
449  continue;
450 
451  scrFaction = SCR_Faction.Cast(otherFaction);
452  if (!scrFaction)
453  continue;
454 
455  if (!faction.IsFactionFriendly(scrFaction))
456  continue;
457 
458  //~ Send to all players
459  scrFaction.GetPlayersInFaction(players);
460  foreach(int playerID : players)
461  {
462  SendToPlayerData(playerID, notificationID, data);
463  }
464  }
465  }
466 
467  return true;
468  }
469 
470  //------------------------------------------------------------------------------------------------
480  static bool SendToUnlimitedEditorPlayers(ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
481  {
482  return SendToUnlimitedEditorPlayers(notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
483  }
484 
485  //------------------------------------------------------------------------------------------------
496  static bool SendToUnlimitedEditorPlayers(ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
497  {
498  //~ Send from client to server to broadcast
499  if (!Replication.IsServer())
500  {
501  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(SCR_PlayerController.GetLocalPlayerId()));
502  if (!playerController)
503  return false;
504 
505  SCR_NotificationsComponent notificationsComponent = SCR_NotificationsComponent.Cast(playerController.FindComponent(SCR_NotificationsComponent));
506  if (!notificationsComponent)
507  return false;
508 
509  array<int> paramArray = {};
510  CreateParamArray(paramArray, param1, param2, param3, param4, param5, param6);
511 
512  notificationsComponent.Rpc(notificationsComponent.Rpc_SendToUnlimitedEditorPlayers, notificationID, position, paramArray);
513  return true;
514  }
515 
516  SCR_NotificationData newNotificationData = SCR_NotificationData();
517  newNotificationData.SetParameters(ENotificationReceiver.GM_ONLY, param1, param2, param3, param4, param5, param6);
518  newNotificationData.SetPosition(position);
519  return SendToUnlimitedEditorPlayersData(notificationID, newNotificationData);
520  }
521 
522  //------------------------------------------------------------------------------------------------
523  //~ Allows client to broadcast notification to players with unlimited editors
524  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
525  protected void Rpc_SendToUnlimitedEditorPlayers(ENotification notificationID, vector position, notnull array<int> paramArray)
526  {
527  int param1, param2, param3, param4, param5, param6;
528  GetParamsFromArray(paramArray, param1, param2, param3, param4, param5, param6);
529 
530  SendToUnlimitedEditorPlayers(notificationID, position, param1, param2, param3, param4, param5, param6);
531  }
532 
533  //------------------------------------------------------------------------------------------------
534  //Set the actual data to players that have an unlimited editor
535  protected static bool SendToUnlimitedEditorPlayersData(ENotification notificationID, SCR_NotificationData data, int playerID = -1)
536  {
537  //--- Only server can broadcast messages
538  if (!Replication.IsServer())
539  return false;
540 
541  array<int> players = {};
542  for (int i = 0, count = GetGame().GetPlayerManager().GetPlayers(players); i < count; i++)
543  {
544  if (playerID == players[i])
545  {
546  SendToPlayerData(players[i], notificationID, data);
547  continue;
548  }
549 
551  if (!core)
552  continue;
553 
554  SCR_EditorManagerEntity editorManager = core.GetEditorManager(players[i]);
555  if (!editorManager)
556  continue;
557 
558  if (!editorManager.IsLimited())
559  SendToPlayerData(players[i], notificationID, data);
560  }
561 
562  return true;
563  }
564 
565  //------------------------------------------------------------------------------------------------
576  static bool SendToUnlimitedEditorPlayersAndPlayer(int playerID, ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
577  {
578  return SendToUnlimitedEditorPlayersAndPlayer(playerID, notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
579  }
580 
581  //------------------------------------------------------------------------------------------------
593  static bool SendToUnlimitedEditorPlayersAndPlayer(int playerID, ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
594  {
595  //~ Send from client to server to broadcast
596  if (!Replication.IsServer())
597  {
598  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(SCR_PlayerController.GetLocalPlayerId()));
599  if (!playerController)
600  return false;
601 
602  SCR_NotificationsComponent notificationsComponent = SCR_NotificationsComponent.Cast(playerController.FindComponent(SCR_NotificationsComponent));
603  if (!notificationsComponent)
604  return false;
605 
606  array<int> paramArray = {};
607  CreateParamArray(paramArray, param1, param2, param3, param4, param5, param6);
608 
609  notificationsComponent.Rpc(notificationsComponent.Rpc_SendToUnlimitedEditorPlayersAndPlayer, playerID, notificationID, position, paramArray);
610  return true;
611  }
612 
613  SCR_NotificationData newNotificationData = SCR_NotificationData();
614  newNotificationData.SetParameters(ENotificationReceiver.GM_OR_AFFECTED_PLAYER_ONLY, param1, param2, param3, param4, param5, param6);
615  newNotificationData.SetPosition(position);
616  return SendToUnlimitedEditorPlayersData(notificationID, newNotificationData, playerID);
617  }
618 
619  //------------------------------------------------------------------------------------------------
620  //~ Allows client to broadcast notification to all players with unlimited editors and an the given specific player
621  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
622  protected void Rpc_SendToUnlimitedEditorPlayersAndPlayer(int playerID, ENotification notificationID, vector position, notnull array<int> paramArray)
623  {
624  int param1, param2, param3, param4, param5, param6;
625  GetParamsFromArray(paramArray, param1, param2, param3, param4, param5, param6);
626 
627  SendToUnlimitedEditorPlayersAndPlayer(playerID, notificationID, position, param1, param2, param3, param4, param5, param6);
628  }
629 
630  //------------------------------------------------------------------------------------------------
641  static bool SendToGroup(int groupID, ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
642  {
643  return SendToGroup(groupID, notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
644  }
645 
646  //------------------------------------------------------------------------------------------------
658  static bool SendToGroup(int groupID, ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
659  {
660  //~ Send from client to server to broadcast
661  if (!Replication.IsServer())
662  {
663  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerManager().GetPlayerController(SCR_PlayerController.GetLocalPlayerId()));
664  if (!playerController)
665  return false;
666 
667  SCR_NotificationsComponent notificationsComponent = SCR_NotificationsComponent.Cast(playerController.FindComponent(SCR_NotificationsComponent));
668  if (!notificationsComponent)
669  return false;
670 
671  array<int> paramArray = {};
672  CreateParamArray(paramArray, param1, param2, param3, param4, param5, param6);
673 
674  notificationsComponent.Rpc(notificationsComponent.Rpc_SendToGroup, groupID, notificationID, position, paramArray);
675  return true;
676  }
677 
678  SCR_NotificationData newNotificationData = SCR_NotificationData();
679  newNotificationData.SetParameters(ENotificationReceiver.PLAYER_GROUP, param1, param2, param3, param4, param5, param6);
680  newNotificationData.SetPosition(position);
681  return SendToGroupData(notificationID, newNotificationData, groupID);
682  }
683 
684  //------------------------------------------------------------------------------------------------
685  //~ Allows client to broadcast notification to all players within the given group
686  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
687  protected void Rpc_SendToGroup(int groupID, ENotification notificationID, vector position, notnull array<int> paramArray)
688  {
689  int param1, param2, param3, param4, param5, param6;
690  GetParamsFromArray(paramArray, param1, param2, param3, param4, param5, param6);
691 
692  SendToGroup(groupID, notificationID, position, param1, param2, param3, param4, param5, param6);
693  }
694 
695  //------------------------------------------------------------------------------------------------
696  //Set the actual data to players in the given group
697  protected static bool SendToGroupData(ENotification notificationID, SCR_NotificationData data, int groupID)
698  {
699  //--- Only server can broadcast messages
700  if (!Replication.IsServer())
701  return false;
702 
703  SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
704  if (!groupManager)
705  return false;
706 
707  SCR_AIGroup group = groupManager.FindGroup(groupID);
708  if (!group)
709  return false;
710 
711  array<int> players = group.GetPlayerIDs();
712 
713  if (players.IsEmpty())
714  return false;
715 
716  foreach (int playerID: players)
717  {
718  SendToPlayerData(playerID, notificationID, data);
719  }
720 
721  return true;
722  }
723 
724  //------------------------------------------------------------------------------------------------
734  static bool SendLocal(ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
735  {
736  return SendLocal(notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
737  }
738 
739  //------------------------------------------------------------------------------------------------
750  static bool SendLocal(ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
751  {
752  SCR_NotificationData newNotificationData = SCR_NotificationData();
753  newNotificationData.SetParameters(ENotificationReceiver.LOCAL_ONLY, param1, param2, param3, param4, param5, param6);
754  newNotificationData.SetPosition(position);
755  return SendLocalData(notificationID, newNotificationData);
756  }
757 
758  //------------------------------------------------------------------------------------------------
768  static bool SendLocalUnlimitedEditor(ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
769  {
770  return SendLocalUnlimitedEditor(notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
771  }
772 
773  //------------------------------------------------------------------------------------------------
784  static bool SendLocalUnlimitedEditor(ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
785  {
786  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
787  if (!editorManager || editorManager.IsLimited())
788  return false;
789 
790  SCR_NotificationData newNotificationData = SCR_NotificationData();
791  newNotificationData.SetParameters(ENotificationReceiver.LOCAL_GM_ONLY, param1, param2, param3, param4, param5, param6);
792  newNotificationData.SetPosition(position);
793  return SendLocalData(notificationID, newNotificationData);
794  }
795 
796  //------------------------------------------------------------------------------------------------
806  static bool SendLocalLimitedEditor(ENotification notificationID, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
807  {
808  return SendLocalLimitedEditor(notificationID, vector.Zero, param1, param2, param3, param4, param5, param6);
809  }
810 
811  //------------------------------------------------------------------------------------------------
822  static bool SendLocalLimitedEditor(ENotification notificationID, vector position, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
823  {
824  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
825  if (!editorManager || !editorManager.IsLimited())
826  return false;
827 
828  SCR_NotificationData newNotificationData = SCR_NotificationData();
829  newNotificationData.SetParameters(ENotificationReceiver.LOCAL_NON_GM_ONLY, param1, param2, param3, param4, param5, param6);
830  newNotificationData.SetPosition(position);
831  return SendLocalData(notificationID, newNotificationData);
832  }
833 
834  //------------------------------------------------------------------------------------------------
835  //Send actual notification data locally
836  protected static bool SendLocalData(ENotification notificationID, SCR_NotificationData data)
837  {
838  SCR_NotificationsComponent notificationsComponent = GetInstance();
839  if (!notificationsComponent)
840  return false;
841 
842  notificationsComponent.ReceiveSCR_NotificationData(notificationID, data);//position, target);
843  return true;
844  }
845 
846  //------------------------------------------------------------------------------------------------
847  //~ Create array of params
848  protected static void CreateParamArray(notnull out array<int> paramArray, int param1 = 0, int param2 = 0, int param3 = 0, int param4 = 0, int param5 = 0, int param6 = 0)
849  {
850  if (param1 != 0)
851  paramArray.Insert(param1);
852 
853  if (param2 != 0)
854  paramArray.Insert(param2);
855 
856  if (param3 != 0)
857  paramArray.Insert(param3);
858 
859  if (param4 != 0)
860  paramArray.Insert(param4);
861 
862  if (param5 != 0)
863  paramArray.Insert(param5);
864 
865  if (param6 != 0)
866  paramArray.Insert(param6);
867  }
868 
869  //------------------------------------------------------------------------------------------------
870  //~ Get all params from array of params
871  protected static void GetParamsFromArray(notnull array<int> paramArray, out int param1 = 0, out int param2 = 0, out int param3 = 0, out int param4 = 0, out int param5 = 0, out int param6 = 0)
872  {
873  int count = paramArray.Count();
874 
875  if (count == 1)
876  {
877  param1 = paramArray[0];
878  }
879  else if (count == 2)
880  {
881  param1 = paramArray[0];
882  param2 = paramArray[1];
883  }
884  else if (count == 3)
885  {
886  param1 = paramArray[0];
887  param2 = paramArray[1];
888  param3 = paramArray[2];
889  }
890  else if (count == 4)
891  {
892  param1 = paramArray[0];
893  param2 = paramArray[1];
894  param3 = paramArray[2];
895  param4 = paramArray[3];
896  }
897  else if (count == 5)
898  {
899  param1 = paramArray[0];
900  param2 = paramArray[1];
901  param3 = paramArray[2];
902  param4 = paramArray[3];
903  param5 = paramArray[4];
904  }
905  else if (count == 6)
906  {
907  param1 = paramArray[0];
908  param2 = paramArray[1];
909  param3 = paramArray[2];
910  param4 = paramArray[3];
911  param5 = paramArray[4];
912  param6 = paramArray[5];
913  }
914  }
915 
916  //------------------------------------------------------------------------------------------------
922  {
923  if (data)
925  else
926  Rpc(ReceiveNotification, id); //--- Don't send data when it's not needed (replication complains when null is received)
927 
928  return true;
929  }
930 
931  //------------------------------------------------------------------------------------------------
932  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
934  {
935  ReceiveSCR_NotificationData(id, null);
936  }
937 
938  //------------------------------------------------------------------------------------------------
939  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
941  {
942  SCR_NotificationData entry = data;
943  if (!entry)
944  entry = new SCR_NotificationData();
945 
946  //--- Set Meta data
947  entry.SetMeta(id, GetNotificationDisplayData(id));
948 
949  //--- Save to history
950  m_aHistory.InsertAt(entry, 0);
951  m_aHistory.Resize(Math.Min(m_aHistory.Count(), NOTIFICATION_HISTORY_LENGTH));
952 
953  //--- Trigger event to be captured by other systems
954  Event_OnNotification.Invoke(entry);
955  //entry.Log();
956 
957  vector position;
958  data.GetPosition(position);
959 
960  if (position != vector.Zero)
962 
963  //Start updating notification times if not yet done
966  }
967 
968  //------------------------------------------------------------------------------------------------
971  array<string> GetStickyNotifications()
972  {
973  SCR_NotificationsComponentClass notificationClass = SCR_NotificationsComponentClass.Cast(GetComponentData(GetOwner()));
974  if (!notificationClass)
975  return null;
976 
977  return notificationClass.GetStickyNotifications();
978  }
979 
980  //------------------------------------------------------------------------------------------------
983  array<ref SCR_NotificationDisplayColor> GetNotificationDisplayColor()
984  {
985  SCR_NotificationsComponentClass notificationClass = SCR_NotificationsComponentClass.Cast(GetComponentData(GetOwner()));
986  if (!notificationClass)
987  return null;
988 
989  return notificationClass.GetNotificationDisplayColor();
990  }
991 
992  //------------------------------------------------------------------------------------------------
994  {
995  SCR_NotificationsComponentClass notificationClass = SCR_NotificationsComponentClass.Cast(GetComponentData(GetOwner()));
996  if (!notificationClass)
997  return null;
998 
999  return notificationClass.GetNotificationDisplayData(notificationID);
1000  }
1001 
1002  //======================== PLAYER NAME HOTFIX ========================\\
1003 
1004  //------------------------------------------------------------------------------------------------
1008  string GetPlayerNameFromHistory(int playerID)
1009  {
1010  string playerName = string.Empty;
1011  m_mPlayerNameHistory.Find(playerID, playerName);
1012 
1013  return playerName;
1014  }
1015 
1016  //------------------------------------------------------------------------------------------------
1017  //~Hotfix to get player names when the player disconnected
1018  protected void AddPlayerNameToHistory(int playerID)
1019  {
1020  PlayerManager playerManager = GetGame().GetPlayerManager();
1021  if (!playerManager)
1022  return;
1023 
1024  m_mPlayerNameHistory.Set(playerID, playerManager.GetPlayerName(playerID));
1025  }
1026 
1027  //======================== START LISTENING TO UPDATE ========================\\
1028 
1029  //------------------------------------------------------------------------------------------------
1030  protected void UpdateNotificationData(bool updateNotificationData)
1031  {
1032  if (updateNotificationData == m_bIsUpdatingNotificationData)
1033  return;
1034 
1035  m_bIsUpdatingNotificationData = updateNotificationData;
1036 
1039  else
1041  }
1042 
1043  //------------------------------------------------------------------------------------------------
1045  {
1046  World world = GetOwner().GetWorld();
1047  NotificationsSystem notificationsSystem = NotificationsSystem.Cast(world.FindSystem(NotificationsSystem));
1048  if (!notificationsSystem)
1049  return;
1050 
1051  notificationsSystem.Register(this);
1052  }
1053 
1054  //------------------------------------------------------------------------------------------------
1056  {
1057  World world = GetOwner().GetWorld();
1058  NotificationsSystem notificationsSystem = NotificationsSystem.Cast(world.FindSystem(NotificationsSystem));
1059  if (!notificationsSystem)
1060  return;
1061 
1062  notificationsSystem.Unregister(this);
1063  }
1064 
1065  //------------------------------------------------------------------------------------------------
1068  void Update(float timeSlice)
1069  {
1070  int count = m_aHistory.Count();
1071 
1072  for(int i = 0; i < count; i++)
1073  {
1074  if (!m_aHistory[i])
1075  continue;
1076 
1077  //Update the time left and check if it needs to be deleted
1078  if (m_aHistory[i].UpdateNotificationData(timeSlice))
1079  {
1080  m_aHistory.RemoveOrdered(i);
1081  i--;
1082  count--;
1083  }
1084  }
1085 
1086  if (m_aHistory.IsEmpty())
1087  UpdateNotificationData(false);
1088  }
1089 
1090  //------------------------------------------------------------------------------------------------
1091  override void OnPostInit(IEntity owner)
1092  {
1093  PlayerController playerController = PlayerController.Cast(owner);
1094  if (!playerController)
1095  return;
1096 
1097  if (!m_aHistory.IsEmpty())
1098  UpdateNotificationData(true);
1099 
1100  //~Hotfix to remember player names even when the player left
1101  if (Replication.IsClient())
1102  {
1104  if (gameMode)
1105  gameMode.GetOnPlayerRegistered().Insert(AddPlayerNameToHistory);
1106 
1107  //~ Get a list of connected players as OnPostInit might be called after connected players were registered
1108  array<int> players = {};
1109 
1110  GetGame().GetPlayerManager().GetPlayers(players);
1111 
1112  foreach (int player : players)
1113  {
1114  AddPlayerNameToHistory(player);
1115  }
1116  }
1117  }
1118 
1119  //------------------------------------------------------------------------------------------------
1120  override void OnDelete(IEntity owner)
1121  {
1123 
1124  //~Hotfix to remember player names even when the player left
1125  if (Replication.IsClient())
1126  {
1128  if (gameMode)
1129  gameMode.GetOnPlayerRegistered().Remove(AddPlayerNameToHistory);
1130  }
1131 
1132  super.OnDelete(owner);
1133  }
1134 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_NotificationsComponentClass
Definition: SCR_NotificationsComponent.c:2
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_NotificationDisplayData
Definition: SCR_NotificationDisplayData.c:7
SCR_PlayerController
Definition: SCR_PlayerController.c:31
Rpc_SendToPlayer
protected void Rpc_SendToPlayer(int playerID, ENotification notificationID, vector position, notnull array< int > paramArray)
Definition: SCR_NotificationsComponent.c:311
ENotificationReceiver
ENotificationReceiver
Definition: ENotificationReceiver.c:4
ReceiveSCR_NotificationData
protected void ReceiveSCR_NotificationData(ENotification id, SCR_NotificationData data)
Definition: SCR_NotificationsComponent.c:940
DisconnectFromNotificationsSystem
protected void DisconnectFromNotificationsSystem()
Definition: SCR_NotificationsComponent.c:1055
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
GetPlayers
protected int GetPlayers(out notnull array< int > outPlayers)
Definition: SCR_DataCollectorComponent.c:233
GetLastNotificationLocation
bool GetLastNotificationLocation(out vector lastLocation)
Definition: SCR_NotificationsComponent.c:155
GetNotificationDisplayData
protected SCR_NotificationDisplayData GetNotificationDisplayData(ENotification notificationID)
Definition: SCR_NotificationsComponent.c:993
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_aHistory
SCR_NotificationsComponentClass m_aHistory
Framework for sending notifications to players.
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_NotificationsComponent.c:1120
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetNotificationDisplayColor
array< ref SCR_NotificationDisplayColor > GetNotificationDisplayColor()
Definition: SCR_NotificationsComponent.c:983
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
m_LastNotificationWithLocation
protected SCR_NotificationData m_LastNotificationWithLocation
Definition: SCR_NotificationsComponent.c:81
GetPlayerNameFromHistory
string GetPlayerNameFromHistory(int playerID)
Definition: SCR_NotificationsComponent.c:1008
ConnectToNotificationsSystem
protected void ConnectToNotificationsSystem()
Definition: SCR_NotificationsComponent.c:1044
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
ENotification
ENotification
Definition: ENotification.c:4
m_bIsUpdatingNotificationData
protected bool m_bIsUpdatingNotificationData
Definition: SCR_NotificationsComponent.c:82
Attribute
typedef Attribute
Post-process effect of scripted camera.
Rpc_SendToGroup
protected void Rpc_SendToGroup(int groupID, ENotification notificationID, vector position, notnull array< int > paramArray)
Definition: SCR_NotificationsComponent.c:687
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
Rpc_SendToUnlimitedEditorPlayers
protected void Rpc_SendToUnlimitedEditorPlayers(ENotification notificationID, vector position, notnull array< int > paramArray)
Definition: SCR_NotificationsComponent.c:525
GetStickyNotifications
array< string > GetStickyNotifications()
Definition: SCR_NotificationsComponent.c:971
OnPostInit
override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_NotificationsComponent.c:1091
SendToOwner
bool SendToOwner(ENotification id, SCR_NotificationData data=null)
Definition: SCR_NotificationsComponent.c:921
Rpc_SendToUnlimitedEditorPlayersAndPlayer
protected void Rpc_SendToUnlimitedEditorPlayersAndPlayer(int playerID, ENotification notificationID, vector position, notnull array< int > paramArray)
Definition: SCR_NotificationsComponent.c:622
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_mPlayerNameHistory
protected ref map< int, string > m_mPlayerNameHistory
Definition: SCR_NotificationsComponent.c:91
ReceiveNotification
protected void ReceiveNotification(ENotification id)
Definition: SCR_NotificationsComponent.c:933
SCR_BaseContainerTools
Definition: SCR_BaseContainerTools.c:3
Faction
Definition: Faction.c:12
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
SCR_NotificationData
Definition: SCR_NotificationData.c:6
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
AddPlayerNameToHistory
protected void AddPlayerNameToHistory(int playerID)
Definition: SCR_NotificationsComponent.c:1018
SCR_NotificationConfig
Definition: SCR_NotificationConfig.c:2
SCR_AIGroup
Definition: SCR_AIGroup.c:68
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
Rpc_SendToEveryone
protected void Rpc_SendToEveryone(ENotification notificationID, vector position, notnull array< int > paramArray)
Definition: SCR_NotificationsComponent.c:230
UpdateNotificationData
protected void UpdateNotificationData(bool updateNotificationData)
Definition: SCR_NotificationsComponent.c:1030
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
Update
void Update(float timeSlice)
Definition: SCR_NotificationsComponent.c:1068
GetHistoryEntry
bool GetHistoryEntry(int index, out SCR_NotificationData data=null)
Definition: SCR_NotificationsComponent.c:138
PlayerManager
Definition: PlayerManager.c:12
NotificationsSystem
TODO: When systems can be replicated, just move overything from SCR_NotificationsComponent.
Definition: NotificationsSystem.c:2
Rpc_SendToFaction
protected void Rpc_SendToFaction(int factionIndex, bool includeFriendlyFactions, ENotification notificationID, vector position, notnull array< int > paramArray)
Definition: SCR_NotificationsComponent.c:402
Event_OnNotification
protected ref ScriptInvoker Event_OnNotification
Definition: SCR_NotificationsComponent.c:79
SCR_Faction
Definition: SCR_Faction.c:6
GetOnNotification
ScriptInvoker GetOnNotification()
Definition: SCR_NotificationsComponent.c:96
GetHistoryOldToNew
int GetHistoryOldToNew(out notnull array< SCR_NotificationData > outHistory, int maxHistoryIndex=-1)
Definition: SCR_NotificationsComponent.c:120
GetHistoryNewToOld
int GetHistoryNewToOld(out notnull array< SCR_NotificationData > outHistory)
Definition: SCR_NotificationsComponent.c:105
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26