Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_NotificationsLogUIComponent.c
Go to the documentation of this file.
1 
7 {
8  [Attribute("0", desc: "If false notifications can never be clicked on and do not have any key hints or teleport icons. This is used if the notifications are part of a menu")]
9  protected bool m_bHasNotificationInput;
10 
11  [Attribute("5", desc: "How many notifications will be displayed (not counting sticky notifications that do not effect the normal notifications) Can never be higher then SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH")]
12  protected int m_iMaxNotifications;
13 
14  [Attribute("15", desc: "Notification display time in seconds. This can be diffrent for each notification log. Can never be higher then SCR_NotificationsComponent.NOTIFICATION_DELETE_TIME")]
15  protected float m_fNotificationDisplayTime;
16 
17  [Attribute("NotificationHolder")]
18  protected string m_sNotificationHolderName;
19 
20  [Attribute("PriorityNotificationHolder")]
21  protected string m_sPriorityNotificationHolderName;
22 
23  [Attribute("2", desc: "Size of priority Notification (Default: Priority Notification has the size of 2 normal Notifications")]
24  protected int m_iPriorityNotificationSize;
25 
26  [Attribute("VerticalLayout0")]
27  protected string m_sNotificationHolderParent;
28 
29  [Attribute("{8ADB878F8DD9BD53}UI/layouts/HUD/Notifications/Notifications_Message.layout")]
30  protected ResourceName m_sNotificationEntityPrefab;
31 
32  [Attribute("{8904986114C6F944}UI/layouts/HUD/Notifications/Notifications_Message_Split.layout")]
33  protected ResourceName m_sSplitNotificationEntityPrefab;
34 
35  protected SCR_NotificationsComponent m_NotificationsManager;
36  protected SCR_EditorManagerEntity m_EditorManagerEntity;
37  protected SCR_FadeUIComponent m_FadeUiComponent;
38  protected VerticalLayoutWidget m_wNotificationHolder;
39  protected VerticalLayoutWidget m_wPriorityNotificationHolder;
40  protected VerticalLayoutWidget m_wNotificationHolderParent;
41  protected ref SCR_NotificationMessageUIComponent m_PrevOverFlowNotification;
42 
43  protected Widget m_wRoot;
44  protected int m_iCurrentMaxNotifications;
45  protected int m_iCurrentPriorityNotifications;
46 
47  //InputType
48  protected bool m_bIsUsingMouseAndKeyboard = true;
49 
50  protected ref ScriptInvoker m_OnNewMessageHasPosition = new ScriptInvoker();
51  protected ref ScriptInvoker m_OnInputDeviceChanged = new ScriptInvoker();
52 
53  protected ref array<ref SCR_NotificationMessageUIComponent> m_aNotificationMessages = {};
54  protected ref array<ref SCR_NotificationMessageUIComponent> m_aPriorityNotificationMessages = {};
55  //Notification Color Data Map
56  protected ref map<ENotificationColor, SCR_NotificationDisplayColor> m_NotificationDisplayColorMap = new map<ENotificationColor, SCR_NotificationDisplayColor>();
57 
58  //------------------------------------------------------------------------------------------------
59  protected bool OnNotification(SCR_NotificationData data)
60  {
61  if (!data || SCR_StringHelper.IsEmptyOrWhiteSpace(data.GetText()))
62  return false;
63 
64  //Check how much display time is left for this particular Notification log
65  float displayTimeLeft = m_fNotificationDisplayTime - (SCR_NotificationsComponent.NOTIFICATION_DELETE_TIME - data.GetNotificationTimeLeft());
66 
67  if (displayTimeLeft <= 0)
68  return false;
69 
70  vector position;
71  data.GetPosition(position);
72 
73  if (position != vector.Zero)
75 
76  Widget newNotification;
77  SCR_NotificationDisplayData displayData = data.GetDisplayData();
78  if (!displayData)
79  return false;
80 
81  SCR_UINotificationInfo uiInfo = displayData.GetNotificationUIInfo();
82  if (!uiInfo)
83  return false;
84 
86  WorkspaceWidget workspaceWidget = GetGame().GetWorkspace();
87  //Spawn priority / normal or split notification
88  if (displayData.GetPriority())
89  newNotification = workspaceWidget.CreateWidgets(m_sNotificationEntityPrefab, m_wPriorityNotificationHolder);
90  else if (!splituiInfo)
91  newNotification = workspaceWidget.CreateWidgets(m_sNotificationEntityPrefab, m_wNotificationHolder);
92  else
93  newNotification = workspaceWidget.CreateWidgets(m_sSplitNotificationEntityPrefab, m_wNotificationHolder);
94 
95  if (!newNotification)
96  return false;
97 
99  if (!notificationMessage)
100  newNotification.RemoveFromHierarchy();
101 
102  if (displayData.GetPriority())
103  {
104  m_aPriorityNotificationMessages.InsertAt(notificationMessage, 0);
105  OnPriorityNotificationChange(true);
106  }
107  else
108  {
109  m_aNotificationMessages.InsertAt(notificationMessage, 0);
110  }
111 
112  notificationMessage.GetOnDeleted().Insert(OnNotificationDeleted);
113 
114  notificationMessage.Init(data, this, displayTimeLeft * 1000);
115 
116  //Check if max notification amount is reached then delete latest
117  if (m_aNotificationMessages.Count() > m_iCurrentMaxNotifications)
118  RemoveOldestNotification();
119 
120  return true;
121  }
122 
123  //------------------------------------------------------------------------------------------------
126  ScriptInvoker GetOnNewMessageHasPosition()
127  {
129  }
130 
131  //------------------------------------------------------------------------------------------------
134  ScriptInvoker GetOnInputDeviceChanged()
135  {
136  return m_OnInputDeviceChanged;
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  protected void OnNotificationDeleted(SCR_NotificationMessageUIComponent notificationMessage)
141  {
142  int index = m_aNotificationMessages.Find(notificationMessage);
143 
144  if (index >= 0)
145  m_aNotificationMessages.RemoveOrdered(index);
146 
147  int priorityIndex = m_aPriorityNotificationMessages.Find(notificationMessage);
148  if (priorityIndex >= 0)
149  {
150  OnPriorityNotificationChange(false);
151  m_aPriorityNotificationMessages.RemoveOrdered(priorityIndex);
152  }
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  protected void RemoveOldestNotification()
157  {
158  if (m_aNotificationMessages.IsEmpty())
159  return;
160 
161  int index = m_aNotificationMessages.Count() -1;
162 
163  //Make sure there is never more then 1 notification that was removed by overflow
164  if (m_PrevOverFlowNotification)
165  m_PrevOverFlowNotification.DeleteNotification();
166 
168  m_aNotificationMessages[index].ForceRemoveNotification();
169 
170  //Can be that notification is already removed
171  if (index < m_aNotificationMessages.Count())
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  protected void OnInputDeviceIsGamepad(bool isGamepad)
177  {
178  m_bIsUsingMouseAndKeyboard = !isGamepad;
179  m_OnInputDeviceChanged.Invoke(m_bIsUsingMouseAndKeyboard);
180  }
181 
182  //------------------------------------------------------------------------------------------------
185  bool GetIsUsingMouseAndKeyboard()
186  {
188  }
189 
190  //------------------------------------------------------------------------------------------------
192  SCR_EditorManagerEntity GetEditorManager()
193  {
194  return m_EditorManagerEntity;
195  }
196 
197  //------------------------------------------------------------------------------------------------
199  SCR_NotificationsComponent GetNotificationManager()
200  {
201  return m_NotificationsManager;
202  }
203 
204  //------------------------------------------------------------------------------------------------
206  Color GetNotificationWidgetColor(ENotificationColor notificationColor)
207  {
208  if (m_NotificationDisplayColorMap.Contains(notificationColor))
209  {
210  return m_NotificationDisplayColorMap.Get(notificationColor).GetWidgetColor();
211  }
212  else
213  {
214  Print("Notification color '" + typename.EnumToString(ENotificationColor, notificationColor) + "' has no color assigned to it in 'SCR_NotificationsLogComponent'", LogLevel.WARNING);
215  return m_NotificationDisplayColorMap.Get(ENotificationColor.NEUTRAL).GetWidgetColor();
216  }
217  }
218 
219  //------------------------------------------------------------------------------------------------
221  Color GetNotificationTextColor(ENotificationColor notificationColor)
222  {
223  if (m_NotificationDisplayColorMap.Contains(notificationColor))
224  {
225  return Color.FromInt(m_NotificationDisplayColorMap.Get(notificationColor).GetTextColor().PackToInt());
226  }
227  else
228  {
229  Print("Notification color '" + typename.EnumToString(ENotificationColor, notificationColor) + "' has no color assigned to it in 'SCR_NotificationsLogComponent'", LogLevel.WARNING);
230  return Color.FromInt(m_NotificationDisplayColorMap.Get(ENotificationColor.NEUTRAL).GetTextColor().PackToInt());
231  }
232  }
233 
234  //------------------------------------------------------------------------------------------------
236  bool HasNotificationInput()
237  {
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  protected void GenerateNotificationColorMap()
243  {
244  array<ref SCR_NotificationDisplayColor> m_aNotificationDisplayColor = m_NotificationsManager.GetNotificationDisplayColor();
245 
246  for (int i = 0, count = m_aNotificationDisplayColor.Count(); i < count; i++)
247  {
248  if (!m_NotificationDisplayColorMap.Contains(m_aNotificationDisplayColor[i].m_NotificationColor))
249  m_NotificationDisplayColorMap.Set(m_aNotificationDisplayColor[i].m_NotificationColor, m_aNotificationDisplayColor[i]);
250  else
251  Print("Notification Color in 'SCR_NotificationsLogComponent' has duplicate notification color key: '" + typename.EnumToString(ENotificationColor, m_aNotificationDisplayColor[i].m_NotificationColor) + "'. There should only be one of each key!", LogLevel.WARNING);
252  }
253  }
254 
255  //------------------------------------------------------------------------------------------------
256  //On each sticky notification active make sure to shrink the list and grow it again once they are inactive.
257  //This is only called by the sticky notification if it affects the list size
258  protected void OnStickyNotificationChanged(bool newActive)
259  {
260  if (newActive)
261  {
264 
265  RemoveOldestNotification();
266  }
267  else
268  {
270  }
271  }
272 
273  //------------------------------------------------------------------------------------------------
274  protected void OnPriorityNotificationChange(bool newActive)
275  {
276  if (newActive)
277  {
279  Math.Clamp(m_iCurrentMaxNotifications, 0, m_iMaxNotifications);
280 
281  RemoveOldestNotification();
282  }
283  else
284  {
286  }
287  }
288 
289  //------------------------------------------------------------------------------------------------
290  override void HandlerAttachedScripted(Widget w)
291  {
292  if(!w)
293  return;
294 
295  m_wRoot = w;
297 
298  if (m_iMaxNotifications > SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH)
299  {
300  Print("Max display Notification in notification log is higher than total notification history in notification component and thus are set the same", LogLevel.ERROR);
301  m_iMaxNotifications = SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH;
302  }
303 
305 
306  m_NotificationsManager = SCR_NotificationsComponent.GetInstance();
307  if (!m_NotificationsManager)
308  {
309  Print("SCR_NotificationsLogDisplay requires SCR_NotificationsComponent on PlayerController!", LogLevel.WARNING);
310  m_wRoot.SetVisible(false);
311  return;
312  }
313 
314  m_wPriorityNotificationHolder = VerticalLayoutWidget.Cast(m_wRoot.FindAnyWidget(m_sPriorityNotificationHolderName));
315  m_wNotificationHolder = VerticalLayoutWidget.Cast(m_wRoot.FindAnyWidget(m_sNotificationHolderName));
316  m_wNotificationHolderParent = VerticalLayoutWidget.Cast(m_wRoot.FindAnyWidget(m_sNotificationHolderParent));
317  if (!m_wNotificationHolder || !m_wNotificationHolderParent)
318  return;
319 
320  m_wNotificationHolder.SetFillOrigin(VerticalFillOrigin.TOP);
321  FrameSlot.SetAlignment(m_wNotificationHolderParent, 1, 1);
322  //Set anchor left & top
323  FrameSlot.SetAnchorMin(m_wNotificationHolderParent, 1, 1);
324  //Set anchor right & bottom
325  FrameSlot.SetAnchorMax(m_wNotificationHolderParent, 1, 1);
326 
327  if (m_fNotificationDisplayTime > SCR_NotificationsComponent.NOTIFICATION_DELETE_TIME)
328  {
329  Print("Notification display time in notification log is higher than delete time in notification component and thus are set the same time", LogLevel.ERROR);
330  m_fNotificationDisplayTime = SCR_NotificationsComponent.NOTIFICATION_DELETE_TIME;
331  }
332 
333  //Fade logics.
334  m_NotificationsManager.GetOnNotification().Insert(OnNotification);
335 
336  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
337 
338  EInputDeviceType inputDevice = GetGame().GetInputManager().GetLastUsedInputDevice();
339  m_bIsUsingMouseAndKeyboard = (inputDevice == EInputDeviceType.KEYBOARD || inputDevice == EInputDeviceType.MOUSE);
341 
342  //Generate Color map data
343  GenerateNotificationColorMap();
344 
345  Widget stickyNotificationWidget;
346  SCR_StickyNotificationUIComponent stickyNotificationComponent;
347 
348  foreach (string notificationWidget : m_NotificationsManager.GetStickyNotifications())
349  {
350  stickyNotificationWidget = w.FindAnyWidget(notificationWidget);
351  if (!stickyNotificationWidget)
352  {
353  Print("NotificationsLog could not find stickNotification: " + notificationWidget, LogLevel.NORMAL);
354  continue;
355  }
356 
357  stickyNotificationComponent = SCR_StickyNotificationUIComponent.Cast(stickyNotificationWidget.FindHandler(SCR_StickyNotificationUIComponent));
358  if (!stickyNotificationComponent)
359  {
360  Print("NotificationsLog could not find SCR_StickyNotificationUIComponent on: " + notificationWidget, LogLevel.NORMAL);
361  continue;
362  }
363 
364  //Init the sticky notification
365  stickyNotificationComponent.OnInit(this);
366 
367  if (!stickyNotificationComponent.InfluenceNotificationListSize())
368  continue;
369 
370  stickyNotificationComponent.GetOnStickyActiveChanged().Insert(OnStickyNotificationChanged);
371 
372  if (stickyNotificationComponent.isStickyActive())
373  OnStickyNotificationChanged(true);
374  }
375 
376  array<SCR_NotificationData> notificationHistory = {};
377  int count = m_NotificationsManager.GetHistoryOldToNew(notificationHistory, m_iCurrentMaxNotifications);
378 
379  //Add the notifications from old to new to set the order in UI correctly
380  for (int i = 0; i < count; i++)
381  {
382  OnNotification(notificationHistory[i]);
383  }
384  }
385 
386  //------------------------------------------------------------------------------------------------
387  override void HandlerDeattached(Widget w)
388  {
389  super.HandlerDeattached(w);
390 
391  if (!m_NotificationsManager)
392  return;
393 
394  m_NotificationsManager.GetOnNotification().Remove(OnNotification);
395  GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
396  }
397 
398  //------------------------------------------------------------------------------------------------
400  void OnSlotResize(int maxNotifications)
401  {
402  m_iMaxNotifications = maxNotifications;
403  if (m_iMaxNotifications > SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH)
404  {
405  Print("Max display Notification in notification log is higher than total notification history in notification component and thus are set the same", LogLevel.ERROR);
406  m_iMaxNotifications = SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH;
407  }
408 
410 
411  Math.Clamp(m_iCurrentMaxNotifications, 0, m_iMaxNotifications);
412 
413  if (m_aNotificationMessages.Count() > m_iCurrentMaxNotifications)
414  RemoveOldestNotification();
415  }
416 
417  //------------------------------------------------------------------------------------------------
420  void ChangeInsertOrder(bool fromTop)
421  {
422  if(!m_wNotificationHolder)
423  return;
424 
425  if (fromTop)
426  {
427  m_wNotificationHolder.SetFillOrigin(VerticalFillOrigin.BOTTOM);
428  FrameSlot.SetAlignment(m_wNotificationHolderParent, 1, 0);
429  //Set anchor left & top
430  FrameSlot.SetAnchorMin(m_wNotificationHolderParent, 1, 0);
431  //Set anchor right & bottom
432  FrameSlot.SetAnchorMax(m_wNotificationHolderParent, 1, 0);
433  }
434  else
435  {
436  m_wNotificationHolder.SetFillOrigin(VerticalFillOrigin.TOP);
437  FrameSlot.SetAlignment(m_wNotificationHolderParent, 1, 1);
438  //Set anchor left & top
439  FrameSlot.SetAnchorMin(m_wNotificationHolderParent, 1, 1);
440  //Set anchor right & bottom
441  FrameSlot.SetAnchorMax(m_wNotificationHolderParent, 1, 1);
442  }
443  }
444 }
445 
448 class SCR_NotificationDisplayColor
449 {
450  [Attribute("0", UIWidgets.ComboBox, "Color Enum", "", ParamEnumArray.FromEnum(ENotificationColor))]
451  ENotificationColor m_NotificationColor;
452 
453  [Attribute(defvalue: "255,255,255,255", desc: "Color of images within the notification message")]
454  protected ref Color m_cWidgetNotificationColor;
455 
456  [Attribute(defvalue: "255,255,255,255", desc: "Color of message text. Only relevant with Split notifications")]
457  protected ref Color m_TextNotificationColor;
458 
459  //------------------------------------------------------------------------------------------------
461  Color GetWidgetColor()
462  {
463  return Color.FromInt(m_cWidgetNotificationColor.PackToInt());
464  }
465 
466  //------------------------------------------------------------------------------------------------
468  Color GetTextColor()
469  {
470  return Color.FromInt(m_TextNotificationColor.PackToInt());
471  }
472 }
SCR_NotificationMessageUIComponent
Definition: SCR_NotificationMessageUIComponent.c:1
SCR_NotificationDisplayData
Definition: SCR_NotificationDisplayData.c:7
SCR_BaseContainerCustomTitleEnum
SCR_NotificationsLogComponent MenuRootSubComponent SCR_BaseContainerCustomTitleEnum(ENotificationColor, "m_NotificationColor")
Definition: SCR_NotificationsLogUIComponent.c:447
SCR_FadeUIComponent
Definition: SCR_FadeUIComponent.c:1
MenuRootSubComponent
Definition: MenuRootSubComponent.c:5
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_SplitNotificationUIInfo
Definition: SCR_SplitNotificationUIInfo.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_StringHelper
Definition: SCR_StringHelper.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_NotificationsLogComponent
Definition: SCR_NotificationsLogUIComponent.c:6
m_iPriorityNotificationSize
protected int m_iPriorityNotificationSize
Definition: SCR_NotificationsLogUIComponent.c:18
m_OnInputDeviceChanged
protected ref ScriptInvoker m_OnInputDeviceChanged
Definition: SCR_NotificationsLogUIComponent.c:45
m_NotificationsManager
protected SCR_NotificationsComponent m_NotificationsManager
Definition: SCR_NotificationsLogUIComponent.c:29
m_wPriorityNotificationHolder
protected VerticalLayoutWidget m_wPriorityNotificationHolder
Definition: SCR_NotificationsLogUIComponent.c:33
m_wNotificationHolder
protected VerticalLayoutWidget m_wNotificationHolder
Definition: SCR_NotificationsLogUIComponent.c:32
m_EditorManagerEntity
protected SCR_EditorManagerEntity m_EditorManagerEntity
Definition: SCR_NotificationsLogUIComponent.c:30
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_wNotificationHolderParent
protected VerticalLayoutWidget m_wNotificationHolderParent
Definition: SCR_NotificationsLogUIComponent.c:34
m_aNotificationMessages
protected ref array< ref SCR_NotificationMessageUIComponent > m_aNotificationMessages
Definition: SCR_NotificationsLogUIComponent.c:47
m_iCurrentMaxNotifications
protected int m_iCurrentMaxNotifications
Definition: SCR_NotificationsLogUIComponent.c:38
m_aPriorityNotificationMessages
protected ref array< ref SCR_NotificationMessageUIComponent > m_aPriorityNotificationMessages
Definition: SCR_NotificationsLogUIComponent.c:48
m_NotificationDisplayColorMap
protected ref map< ENotificationColor, SCR_NotificationDisplayColor > m_NotificationDisplayColorMap
Definition: SCR_NotificationsLogUIComponent.c:50
m_FadeUiComponent
protected SCR_FadeUIComponent m_FadeUiComponent
Definition: SCR_NotificationsLogUIComponent.c:31
m_bIsUsingMouseAndKeyboard
protected bool m_bIsUsingMouseAndKeyboard
Definition: SCR_NotificationsLogUIComponent.c:42
SCR_NotificationData
Definition: SCR_NotificationData.c:6
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
m_PrevOverFlowNotification
protected ref SCR_NotificationMessageUIComponent m_PrevOverFlowNotification
Definition: SCR_NotificationsLogUIComponent.c:35
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
ENotificationColor
ENotificationColor
Definition: ENotificationColor.c:4
m_iMaxNotifications
protected int m_iMaxNotifications
Definition: SCR_NotificationsLogUIComponent.c:6
m_OnNewMessageHasPosition
protected ref ScriptInvoker m_OnNewMessageHasPosition
Definition: SCR_NotificationsLogUIComponent.c:44
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
SCR_StickyNotificationUIComponent
Definition: SCR_StickyNotificationUIComponent.c:1
m_bHasNotificationInput
protected bool m_bHasNotificationInput
Definition: SCR_NotificationsLogUIComponent.c:3
m_fNotificationDisplayTime
protected float m_fNotificationDisplayTime
Definition: SCR_NotificationsLogUIComponent.c:9
SCR_UINotificationInfo
UIInfo used by the Notifications system.
Definition: SCR_NotificationUIInfo.c:3
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
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26