Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_NotificationsLogUIComponent.c
Go to the documentation of this file.
2
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;
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;
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")]
17 [Attribute("NotificationHolder")]
18 protected string m_sNotificationHolderName;
20 [Attribute("PriorityNotificationHolder")]
23 [Attribute("2", desc: "Size of priority Notification (Default: Priority Notification has the size of 2 normal Notifications")]
26 [Attribute("VerticalLayout0")]
29 [Attribute("{8ADB878F8DD9BD53}UI/layouts/HUD/Notifications/Notifications_Message.layout")]
32 [Attribute("{8904986114C6F944}UI/layouts/HUD/Notifications/Notifications_Message_Split.layout")]
35 protected SCR_NotificationsComponent m_NotificationsManager;
42 protected FactionManager m_FactionManager;
43
45
46 protected Widget m_wRoot;
50
51 //InputType
52 protected bool m_bIsUsingMouseAndKeyboard = true;
53
54 protected string m_sCachedLanguage;
55
58
59 protected ref array<ref SCR_NotificationMessageUIComponent> m_aNotificationMessages = {};
60 protected ref array<ref SCR_NotificationMessageUIComponent> m_aPriorityNotificationMessages = {};
61 //Notification Color Data Map
63
64 //------------------------------------------------------------------------------------------------
66 {
68 return false;
69
70 //Check how much display time is left for this particular Notification log
71 float displayTimeLeft = m_fNotificationDisplayTime - (SCR_NotificationsComponent.NOTIFICATION_DELETE_TIME - data.GetNotificationTimeLeft());
72
73 if (displayTimeLeft <= 0)
74 return false;
75
77 data.GetPosition(position);
78
79 if (position != vector.Zero)
81
82 Widget newNotification;
83 SCR_NotificationDisplayData displayData = data.GetDisplayData();
84 if (!displayData)
85 return false;
86
87 SCR_UINotificationInfo uiInfo = displayData.GetNotificationUIInfo();
88 if (!uiInfo)
89 return false;
90
92 WorkspaceWidget workspaceWidget = GetGame().GetWorkspace();
93 //Spawn priority / normal or split notification
94 if (displayData.GetPriority())
95 newNotification = workspaceWidget.CreateWidgets(m_sNotificationEntityPrefab, m_wPriorityNotificationHolder);
96 else if (!splituiInfo)
97 newNotification = workspaceWidget.CreateWidgets(m_sNotificationEntityPrefab, m_wNotificationHolder);
98 else
99 newNotification = workspaceWidget.CreateWidgets(m_sSplitNotificationEntityPrefab, m_wNotificationHolder);
100
101 if (!newNotification)
102 return false;
103
105 if (!notificationMessage)
106 newNotification.RemoveFromHierarchy();
107
108 if (displayData.GetPriority())
109 {
110 m_aPriorityNotificationMessages.InsertAt(notificationMessage, 0);
112 }
113 else
114 {
115 m_aNotificationMessages.InsertAt(notificationMessage, 0);
116 }
117
118 notificationMessage.GetOnDeleted().Insert(OnNotificationDeleted);
119
120 notificationMessage.Init(data, this, displayTimeLeft * 1000);
121
122 //Check if max notification amount is reached then delete latest
125
126 return true;
127 }
128
129 //------------------------------------------------------------------------------------------------
136
137 //------------------------------------------------------------------------------------------------
138 //! Get script invoker if input device changed
139 //! \return ScriptInvoker m_OnInputDeviceChanged
144
145 //------------------------------------------------------------------------------------------------
147 {
148 int index = m_aNotificationMessages.Find(notificationMessage);
149
150 if (index >= 0)
151 m_aNotificationMessages.RemoveOrdered(index);
152
153 int priorityIndex = m_aPriorityNotificationMessages.Find(notificationMessage);
154 if (priorityIndex >= 0)
155 {
157 m_aPriorityNotificationMessages.RemoveOrdered(priorityIndex);
158 }
159 }
160
161 //------------------------------------------------------------------------------------------------
163 {
164 // Delete every notification one by one until we are below the max notifications
166 {
167 int index = m_aNotificationMessages.Count() -1;
168
169 //Make sure there is never more then 1 notification that was removed by overflow
171 m_PrevOverFlowNotification.DeleteNotification();
172
174 m_aNotificationMessages[index].ForceRemoveNotification();
175
176 //Can be that notification is already removed
177 if (index < m_aNotificationMessages.Count())
179 }
180 }
181
182 //------------------------------------------------------------------------------------------------
185 {
187 {
188 if (msg)
189 msg.UpdateText();
190 }
191
193 {
194 if (priorityMsg)
195 priorityMsg.UpdateText();
196 }
197 }
198
199 //------------------------------------------------------------------------------------------------
200 protected void OnInputDeviceIsGamepad(bool isGamepad)
205
206 //------------------------------------------------------------------------------------------------
208 //! \return true if using mouse and keyboard, false otherwise
213
214 //------------------------------------------------------------------------------------------------
215 //! \return EditorManagerEntity reference
220
221 //------------------------------------------------------------------------------------------------
222 //! \return NotificationsManager reference
223 SCR_NotificationsComponent GetNotificationManager()
224 {
226 }
227
228 //------------------------------------------------------------------------------------------------
231 {
232 //~ Get faction color if color enum is less than 0
233 if (notificationColor < 0)
234 {
235 if (!m_FactionManager)
236 {
237 notificationColor = ENotificationColor.NEUTRAL;
238 Print("SCR_NotificationsLogComponent: Could not find the FactionManager so faction color for notification could not be set", LogLevel.WARNING);
239 }
240
241 Faction faction = m_FactionManager.GetFactionByIndex((notificationColor * -1) - 1);
242 if (!faction)
243 {
244 notificationColor = ENotificationColor.NEUTRAL;
245 Print("SCR_NotificationsLogComponent: Could not find the faction index: '" + (notificationColor * -1) + "' so faction color for notification could not be set", LogLevel.WARNING);
246 }
247 else
248 {
249 SCR_Faction scrFaction = SCR_Faction.Cast(faction);
250 if (scrFaction)
251 return scrFaction.GetNotificationFactionColor();
252 else
253 return faction.GetFactionColor();
254 }
255 }
256
257 if (m_NotificationDisplayColorMap.Contains(notificationColor))
258 {
259 return m_NotificationDisplayColorMap.Get(notificationColor).GetWidgetColor();
260 }
261 else
263 Print("Notification color '" + typename.EnumToString(ENotificationColor, notificationColor) + "' has no color assigned to it in 'SCR_NotificationsLogComponent'", LogLevel.WARNING);
264 return m_NotificationDisplayColorMap.Get(ENotificationColor.NEUTRAL).GetWidgetColor();
265 }
266 }
267
268 //------------------------------------------------------------------------------------------------
271 {
272 //~ Get faction color if color enum is less than 0
273 if (notificationColor < 0)
274 {
275 if (!m_FactionManager)
276 {
277 notificationColor = ENotificationColor.NEUTRAL;
278 Print("SCR_NotificationsLogComponent: Could not find the FactionManager so faction color for notification could not be set", LogLevel.WARNING);
279 }
280
281 Faction faction = m_FactionManager.GetFactionByIndex((notificationColor * -1) - 1);
282 if (!faction)
283 {
284 notificationColor = ENotificationColor.NEUTRAL;
285 Print("SCR_NotificationsLogComponent: Could not find the faction index: '" + (notificationColor * -1) + "' so faction color for notification could not be set", LogLevel.WARNING);
286 }
287 else
288 {
289 SCR_Faction scrFaction = SCR_Faction.Cast(faction);
290 if (scrFaction)
291 return scrFaction.GetNotificationTextFactionColor();
292 else
293 return faction.GetFactionColor();
294 }
295 }
296
297 if (m_NotificationDisplayColorMap.Contains(notificationColor))
298 {
299 return Color.FromInt(m_NotificationDisplayColorMap.Get(notificationColor).GetTextColor().PackToInt());
300 }
301 else
303 Print("Notification color '" + typename.EnumToString(ENotificationColor, notificationColor) + "' has no color assigned to it in 'SCR_NotificationsLogComponent'", LogLevel.WARNING);
304 return Color.FromInt(m_NotificationDisplayColorMap.Get(ENotificationColor.NEUTRAL).GetTextColor().PackToInt());
305 }
306 }
307
308 //------------------------------------------------------------------------------------------------
311 {
313 }
314
315 //------------------------------------------------------------------------------------------------
317 {
318 array<ref SCR_NotificationDisplayColor> m_aNotificationDisplayColor = m_NotificationsManager.GetNotificationDisplayColor();
319
320 for (int i = 0, count = m_aNotificationDisplayColor.Count(); i < count; i++)
321 {
322 if (!m_NotificationDisplayColorMap.Contains(m_aNotificationDisplayColor[i].m_NotificationColor))
323 m_NotificationDisplayColorMap.Set(m_aNotificationDisplayColor[i].m_NotificationColor, m_aNotificationDisplayColor[i]);
324 else
325 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);
326 }
327 }
328
329 //------------------------------------------------------------------------------------------------
330 //On each sticky notification active make sure to shrink the list and grow it again once they are inactive.
331 //This is only called by the sticky notification if it affects the list size
332 protected void OnStickyNotificationChanged(bool newActive)
333 {
334 if (newActive)
335 {
338
340
343 }
344 else
349 }
350 }
351
352 //------------------------------------------------------------------------------------------------
353 protected void OnPriorityNotificationChange(bool newActive)
354 {
355 if (newActive)
356 {
359
362 }
363 else
364 {
367 }
368 }
369
370 //------------------------------------------------------------------------------------------------
371 protected void OnSettingsChanged()
372 {
374 if (!hudManager)
375 return;
376
377 BaseContainer interfaceSettings = GetGame().GetGameUserSettings().GetModule(hudManager.GetInterfaceSettingsClass());
378 if (!interfaceSettings)
379 return;
380
381 bool state;
382 interfaceSettings.Get("m_bShowNotifications", state);
383 m_wRoot.SetVisible(state);
384
385 // check if language is really changed
386 string newLanguage;
387 WidgetManager.GetLanguage(newLanguage);
388 if (newLanguage.IsEmpty() || newLanguage == m_sCachedLanguage)
389 return;
390
391 m_sCachedLanguage = newLanguage;
392
394 }
395
396 //------------------------------------------------------------------------------------------------
398 {
399 if(!w)
400 return;
401
402 m_wRoot = w;
404
405 if (m_iMaxNotifications > SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH)
406 {
407 Print("Max display Notification in notification log is higher than total notification history in notification component and thus are set the same", LogLevel.ERROR);
408 m_iMaxNotifications = SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH;
409 }
410
412
413 m_NotificationsManager = SCR_NotificationsComponent.GetInstance();
415 {
416 Print("SCR_NotificationsLogDisplay requires SCR_NotificationsComponent on PlayerController!", LogLevel.WARNING);
417 m_wRoot.SetVisible(false);
418 return;
419 }
420
421 // Since Notifications still work as component inside Editor, we need to apply the same logic as to the InfoDisplay here.
423 if (hudManager)
424 {
425 BaseContainer interfaceSettings = GetGame().GetGameUserSettings().GetModule(hudManager.GetInterfaceSettingsClass());
426 if (interfaceSettings)
427 {
428 bool state;
429 interfaceSettings.Get("m_bShowNotifications", state);
430 m_wRoot.SetVisible(state);
431
432 GetGame().OnUserSettingsChangedInvoker().Insert(OnSettingsChanged);
433 WidgetManager.GetLanguage(m_sCachedLanguage);
434 }
435 }
436
441 return;
442
443 m_wNotificationHolder.SetFillOrigin(VerticalFillOrigin.TOP);
444 FrameSlot.SetAlignment(m_wNotificationHolderParent, 1, 1);
445 //Set anchor left & top
446 FrameSlot.SetAnchorMin(m_wNotificationHolderParent, 1, 1);
447 //Set anchor right & bottom
448 FrameSlot.SetAnchorMax(m_wNotificationHolderParent, 1, 1);
449
450 if (m_fNotificationDisplayTime > SCR_NotificationsComponent.NOTIFICATION_DELETE_TIME)
451 {
452 Print("Notification display time in notification log is higher than delete time in notification component and thus are set the same time", LogLevel.ERROR);
453 m_fNotificationDisplayTime = SCR_NotificationsComponent.NOTIFICATION_DELETE_TIME;
454 }
455
456 //Fade logics.
457 m_NotificationsManager.GetOnNotification().Insert(OnNotification);
458
459 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
460
461 EInputDeviceType inputDevice = GetGame().GetInputManager().GetLastUsedInputDevice();
462 m_bIsUsingMouseAndKeyboard = (inputDevice == EInputDeviceType.KEYBOARD || inputDevice == EInputDeviceType.MOUSE);
464 m_FactionManager = GetGame().GetFactionManager();
465
466 //Generate Color map data
468
469 Widget stickyNotificationWidget;
470 SCR_StickyNotificationUIComponent stickyNotificationComponent;
471
472 foreach (string notificationWidget : m_NotificationsManager.GetStickyNotifications())
473 {
474 stickyNotificationWidget = w.FindAnyWidget(notificationWidget);
475 if (!stickyNotificationWidget)
476 {
477 Print("NotificationsLog could not find stickNotification: " + notificationWidget, LogLevel.NORMAL);
478 continue;
479 }
480
481 stickyNotificationComponent = SCR_StickyNotificationUIComponent.Cast(stickyNotificationWidget.FindHandler(SCR_StickyNotificationUIComponent));
482 if (!stickyNotificationComponent)
483 {
484 Print("NotificationsLog could not find SCR_StickyNotificationUIComponent on: " + notificationWidget, LogLevel.NORMAL);
485 continue;
486 }
487
488 //Init the sticky notification
489 stickyNotificationComponent.OnInit(this);
490
491 stickyNotificationComponent.GetOnStickyActiveChanged().Insert(OnStickyNotificationChanged);
492
493 if (stickyNotificationComponent.isStickyActive())
495 }
496
497 array<SCR_NotificationData> notificationHistory = {};
498 int count = m_NotificationsManager.GetHistoryOldToNew(notificationHistory, m_iCurrentMaxNotifications);
499
500 //Add the notifications from old to new to set the order in UI correctly
501 for (int i = 0; i < count; i++)
502 {
503 OnNotification(notificationHistory[i]);
504 }
505
506 m_SaveWarning = SCR_SaveWarningComponent.Cast(m_wRoot.FindAnyWidget("SaveWarning").FindHandler(SCR_SaveWarningComponent));
507 EventProvider.ConnectEvent(GetGame().GetSaveGameManager().OnBusyStateChanged, ShowSavingWarning);
508 }
509
510 //------------------------------------------------------------------------------------------------
511 override void HandlerDeattached(Widget w)
512 {
513 super.HandlerDeattached(w);
514
515 GetGame().OnUserSettingsChangedInvoker().Remove(OnSettingsChanged);
516
518 return;
519
520 m_NotificationsManager.GetOnNotification().Remove(OnNotification);
521 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
522
523 EventProvider.DisconnectEvent(GetGame().GetSaveGameManager().OnBusyStateChanged, ShowSavingWarning);
524 }
525
526 //------------------------------------------------------------------------------------------------
528 void OnSlotResize(int maxNotifications)
529 {
530 m_iMaxNotifications = maxNotifications;
531 if (m_iMaxNotifications > SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH)
532 {
533 Print("Max display Notification in notification log is higher than total notification history in notification component and thus are set the same", LogLevel.ERROR);
534 m_iMaxNotifications = SCR_NotificationsComponent.NOTIFICATION_HISTORY_LENGTH;
535 }
536
537 // Max amount of Notifications that can be shown are determined by the normal Max Notifications - amount of Priority Notifications - amount of Sticky Notifications
539
544 }
545
546 //------------------------------------------------------------------------------------------------
549 void ChangeInsertOrder(bool fromTop)
550 {
552 return;
553
554 if (fromTop)
555 {
556 m_wNotificationHolder.SetFillOrigin(VerticalFillOrigin.BOTTOM);
557 FrameSlot.SetAlignment(m_wNotificationHolderParent, 1, 0);
558 //Set anchor left & top
559 FrameSlot.SetAnchorMin(m_wNotificationHolderParent, 1, 0);
560 //Set anchor right & bottom
561 FrameSlot.SetAnchorMax(m_wNotificationHolderParent, 1, 0);
562 }
563 else
564 {
565 m_wNotificationHolder.SetFillOrigin(VerticalFillOrigin.TOP);
566 FrameSlot.SetAlignment(m_wNotificationHolderParent, 1, 1);
567 //Set anchor left & top
568 FrameSlot.SetAnchorMin(m_wNotificationHolderParent, 1, 1);
569 //Set anchor right & bottom
570 FrameSlot.SetAnchorMax(m_wNotificationHolderParent, 1, 1);
571 }
572 }
573
574 //------------------------------------------------------------------------------------------------
575 protected void UpdateSpinner()
576 {
577 m_SaveWarning.UpdateSpinner(GetGame().GetWorld().GetTimeSlice());
578 }
579
580 //------------------------------------------------------------------------------------------------
582 protected void ShowSavingWarning(bool state)
583 {
584 m_SaveWarning.ShowWarning(state);
585
586 if (state)
587 GetGame().GetCallqueue().CallLater(UpdateSpinner, 1.0, true);
588 else
589 GetGame().GetCallqueue().Remove(UpdateSpinner);
590 }
591}
592
595class SCR_NotificationDisplayColor
596{
597 [Attribute("0", UIWidgets.ComboBox, "Color Enum", "", ParamEnumArray.FromEnum(ENotificationColor))]
598 ENotificationColor m_NotificationColor;
599
600 [Attribute(defvalue: "1 1 1 1", desc: "Color of images within the notification message")]
601 protected ref Color m_cWidgetNotificationColor;
602
603 [Attribute(defvalue: "1 1 1 1", desc: "Color of message text. Only relevant with Split notifications")]
604 protected ref Color m_TextNotificationColor;
605
606 //------------------------------------------------------------------------------------------------
608 Color GetWidgetColor()
609 {
610 return Color.FromInt(m_cWidgetNotificationColor.PackToInt());
611 }
612
613 //------------------------------------------------------------------------------------------------
615 Color GetTextColor()
616 {
617 return Color.FromInt(m_TextNotificationColor.PackToInt());
618 }
619}
ENotificationColor
ArmaReforgerScripted GetGame()
Definition game.c:1398
void OnInputDeviceIsGamepad(bool isGamepad)
vector position
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
Get all prefabs that have the spawner data
bool OnNotification(SCR_NotificationData data)
SCR_NotificationsComponent m_NotificationsManager
void ShowSavingWarning(bool state)
bool m_bIsUsingMouseAndKeyboard
int m_iCurrentStickyNotifications
ref array< ref SCR_NotificationMessageUIComponent > m_aPriorityNotificationMessages
ref array< ref SCR_NotificationMessageUIComponent > m_aNotificationMessages
ref map< ENotificationColor, SCR_NotificationDisplayColor > m_NotificationDisplayColorMap
int m_iPriorityNotificationSize
SCR_NotificationsLogComponent MenuRootSubComponent SCR_BaseContainerCustomTitleEnum(ENotificationColor, "m_NotificationColor")
ref ScriptInvoker m_OnInputDeviceChanged
VerticalLayoutWidget m_wNotificationHolderParent
SCR_NotificationsLogComponent MenuRootSubComponent BaseContainerProps()
Class that saves the color data for specific ENotificationColor enums for the notification system.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Color.c:13
Class for broadcasting events to registered receivers.
static proto bool DisconnectEvent(func eventSender, func eventReceiver)
Definition Math.c:13
Marks a method in a class as a valid event receiver callback.
Color GetNotificationTextFactionColor()
Color GetNotificationFactionColor()
static SCR_HUDManagerComponent GetHUDManager()
SCR_UINotificationInfo GetNotificationUIInfo()
void Init(SCR_NotificationData data, SCR_NotificationsLogComponent notificationLog, float fadeDelay)
bool OnNotification(SCR_NotificationData data)
SCR_NotificationsComponent m_NotificationsManager
ref SCR_NotificationMessageUIComponent m_PrevOverFlowNotification
void OnNotificationDeleted(SCR_NotificationMessageUIComponent notificationMessage)
ref map< ENotificationColor, SCR_NotificationDisplayColor > m_NotificationDisplayColorMap
SCR_NotificationsComponent GetNotificationManager()
ref array< ref SCR_NotificationMessageUIComponent > m_aPriorityNotificationMessages
void UpdateNotificationTexts()
Update notification texts.
ref array< ref SCR_NotificationMessageUIComponent > m_aNotificationMessages
Color GetNotificationTextColor(ENotificationColor notificationColor)
Color GetNotificationWidgetColor(ENotificationColor notificationColor)
void OnInit(SCR_NotificationsLogComponent notificationLog)
static bool IsEmptyOrWhiteSpace(string input)
UIInfo used by the Notifications system.
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
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134