Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_NotificationMessageUIComponent.c
Go to the documentation of this file.
1 class SCR_NotificationMessageUIComponent: ScriptedWidgetComponent
2 {
3  [Attribute()]
4  protected string m_sIcon;
5 
6  [Attribute(desc: "Widgets that are colored by the Notification Color")]
7  protected ref array<string> m_aColoredWidgets;
8 
9  [Attribute(desc: "Notifications widgets that are hidden if notification is GM only. These widgets should be shown by default")]
10  protected ref array<string> m_aNonGameMasterWidgets;
11 
12  [Attribute(desc: "Notifications widgets that are shown if notification is GM only. These widgets should be hidden by default")]
13  protected ref array<string> m_aGameMasterOnlyWidgets;
14 
15  [Attribute()]
16  protected string m_sNotificationText;
17 
18  [Attribute("GoToIndicator")]
19  protected string m_sGoToIndicator;
20 
21  [Attribute("GoToControlHint")]
22  protected string m_sGoToControlHint;
23 
24  [Attribute("GotoIndicatorsHolder")]
25  protected string m_sGoToIndicatorsHolder;
26 
27  //Reference
28  protected Widget m_wRoot;
29  protected SCR_NotificationsLogComponent m_NotificationsLog;
30  protected ref SCR_NotificationData m_Data;
31  protected Widget m_GoToControlHint;
32  protected Widget m_GoToIndicator;
33  protected Widget m_GoToIndicatorsHolder;
34 
35  protected ref ScriptInvoker Event_OnDeleted = new ScriptInvoker();
36 
37  //State
38  protected bool m_bIsListeningToDoneFade;
39  protected bool m_bHasPosition;
40  protected bool m_bShowTeleportControlHint;
41 
42  //Animation speed and update
43  protected static const float ANIMATION_DONE_UPDATE_SPEED = 100;
44  protected static const float FORCE_DELETE_FADE_SPEED = 3;
45  protected static const float AUTO_FADE_SPEED = 1;
46  protected static const float FADE_IN_SPEED = 2;
47 
48  //------------------------------------------------------------------------------------------------
53  void Init(SCR_NotificationData data, SCR_NotificationsLogComponent notificationLog, float fadeDelay)
54  {
55  if (!m_wRoot)
56  return;
57 
58  m_Data = data;
59  if (!m_Data)
60  return;
61 
62  SCR_NotificationsComponent notificationManager = notificationLog.GetNotificationManager();
63  SCR_NotificationDisplayData displayData = data.GetDisplayData();
64  SCR_EditorManagerEntity editorManager = notificationLog.GetEditorManager();
65 
66  m_NotificationsLog = notificationLog;
67 
68  TextWidget notificationText = TextWidget.Cast(m_wRoot.FindAnyWidget(m_sNotificationText));
69  if (!notificationText)
70  return;
71 
72  string notificationMessage = data.GetText();
73  string param1, param2, param3, param4, param5, param6;
74 
75  if (notificationMessage != string.Empty)
76  data.GetNotificationTextEntries(param1, param2, param3, param4, param5, param6);
77  else
78  notificationMessage = typename.EnumToString(ENotification, data.GetID());
79 
80  if (!displayData.MergeParam1With2())
81  {
82  notificationText.SetTextFormat(notificationMessage, param1, param2, param3, param4, param5, param6);
83  }
84  else
85  {
86  string mergeParams = WidgetManager.Translate(param2, param1);
87  notificationText.SetTextFormat(notificationMessage, param1, mergeParams, param3, param4, param5, param6);
88  }
89 
91  ENotificationColor notificationColorEnum;
92  displayData.GetDisplayVisualizationData(data, uiInfo, notificationColorEnum);
93 
94  if (uiInfo)
95  {
96  ImageWidget icon = ImageWidget.Cast(m_wRoot.FindAnyWidget(m_sIcon));
97  if (icon)
98  {
99  if (uiInfo.HasIcon())
100  uiInfo.SetIconTo(icon);
101  else
102  icon.SetVisible(false);
103  }
104 
105  SetWidgetColor(m_NotificationsLog.GetNotificationWidgetColor(notificationColorEnum));
106  }
107 
108  //Show Gm only visuals and hide non game master visuals
109  if (data.GetNotificationReceiverType() == ENotificationReceiver.GM_ONLY || data.GetNotificationReceiverType() == ENotificationReceiver.LOCAL_GM_ONLY || data.GetNotificationReceiverType() == ENotificationReceiver.GM_OR_AFFECTED_PLAYER_ONLY)
110  {
111  Widget elementWidget;
112 
113  foreach (string element: m_aNonGameMasterWidgets)
114  {
115  elementWidget = m_wRoot.FindAnyWidget(element);
116 
117  if (elementWidget)
118  elementWidget.SetVisible(false);
119  }
120 
121  foreach (string element: m_aGameMasterOnlyWidgets)
122  {
123  elementWidget = m_wRoot.FindAnyWidget(element);
124 
125  if (elementWidget)
126  elementWidget.SetVisible(true);
127  }
128  }
129 
130  //Set text color
131  SCR_ColoredTextNotificationUIInfo coloredTextNotificationUIInfo = SCR_ColoredTextNotificationUIInfo.Cast(uiInfo);
132  if (coloredTextNotificationUIInfo)
133  {
134  Color textColor = notificationLog.GetNotificationTextColor(displayData.GetTextColor(data));
135  textColor.SetA(notificationText.GetColor().A());
136  notificationText.SetColor(textColor);
137  }
138 
139  //Get position
140  vector position;
141  if (m_NotificationsLog.HasNotificationInput() && displayData.GetPosition(data, position))
142  {
143  m_NotificationsLog.GetEditorManager().GetOnOpened().Insert(EditorOpened);
144  m_NotificationsLog.GetEditorManager().GetOnClosed().Insert(EditorClosed);
145  m_NotificationsLog.GetEditorManager().GetOnLimitedChange().Insert(OnLimitedChanged);
146 
147  m_bHasPosition = true;
148  m_bShowTeleportControlHint = true;
149 
150  //notificationManager.GetOnNotification().Insert(OnNotification);
151  m_NotificationsLog.GetOnNewMessageHasPosition().Insert(OnNewNotificationHasPosition);
152  m_NotificationsLog.GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
153 
154  if (!editorManager.IsOpened())
155  EditorClosed();
156  else
157  EditorOpened();
158  }
159  else
160  {
161  //Disable teleport button
162  m_wRoot.SetEnabled(false);
163  }
164 
165  GetGame().GetCallqueue().CallLater(AutoFadeDelay, fadeDelay);
166 
167  m_wRoot.SetOpacity(0);
168  AnimateWidget.Opacity(m_wRoot, 1, FADE_IN_SPEED);
169  }
170 
171  //======================== SET COLOR ========================\\
172 
173  //------------------------------------------------------------------------------------------------
174  protected void SetWidgetColor(Color notificationColor)
175  {
176  if (!m_aColoredWidgets || m_aColoredWidgets.IsEmpty())
177  return;
178 
179  Color color;
180 
181  foreach (string widgetName: m_aColoredWidgets)
182  {
183  Widget widget = m_wRoot.FindAnyWidget(widgetName);
184  if (widget)
185  {
186  color = Color.FromInt(notificationColor.PackToInt());
187  color.SetA(widget.GetColor().A());
188  widget.SetColor(notificationColor);
189  }
190  }
191  }
192 
193  //Removed for now but can be used for mods.
194 // protected void OnNotification(SCR_NotificationData data)
195 // {
196 //
197 // }
198 
199  //Quickly fades out notification and deletes it. Called when max notification count is reached
200  //------------------------------------------------------------------------------------------------
202  void ForceRemoveNotification()
203  {
204  FadeDelete(FORCE_DELETE_FADE_SPEED);
205  }
206 
207  //------------------------------------------------------------------------------------------------
210  ScriptInvoker GetOnDeleted()
211  {
212  return Event_OnDeleted;
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  protected void OnNewNotificationHasPosition()
217  {
218  if (!m_GoToControlHint || !m_GoToIndicator || !m_GoToIndicatorsHolder)
219  return;
220 
221  if (!m_bShowTeleportControlHint)
222  return;
223 
224  m_bShowTeleportControlHint = false;
225 
226  if (!m_NotificationsLog.GetEditorManager().IsOpened())
227  return;
228 
229  bool isLimited = m_NotificationsLog.GetEditorManager().IsLimited();
230 
231  //Keyboard and mouse
232  if (!isLimited && m_NotificationsLog.GetIsUsingMouseAndKeyboard())
233  {
234  m_GoToControlHint.SetVisible(false);
235  m_GoToIndicator.SetVisible(true);
236  m_GoToIndicatorsHolder.SetVisible(true);
237  }
238  //Using gamepad
239  else
240  {
241  m_GoToIndicatorsHolder.SetVisible(false);
242  }
243  }
244 
245  //------------------------------------------------------------------------------------------------
246  protected void EditorOpened()
247  {
248  bool limited = m_NotificationsLog.GetEditorManager().IsLimited();
249 
250  if (!m_bShowTeleportControlHint)
251  {
252  if (m_GoToIndicator && m_GoToIndicatorsHolder)
253  {
254  m_GoToIndicator.SetVisible(m_NotificationsLog.GetIsUsingMouseAndKeyboard() && !limited);
255  m_GoToIndicatorsHolder.SetVisible(m_NotificationsLog.GetIsUsingMouseAndKeyboard() && !limited);
256  }
257 
258  }
259  else
260  {
261  if (m_GoToControlHint && m_GoToIndicatorsHolder)
262  {
263  m_GoToControlHint.SetVisible(!limited);
264  m_GoToIndicatorsHolder.SetVisible(!limited);
265  }
266 
267  }
268 
269  if (m_wRoot)
270  m_wRoot.SetEnabled(!limited);
271  }
272 
273  //------------------------------------------------------------------------------------------------
274  protected void EditorClosed()
275  {
276  if (m_GoToControlHint)
277  m_GoToIndicatorsHolder.SetVisible(false);
278 
279  if (m_wRoot)
280  m_wRoot.SetEnabled(false);
281  }
282 
283  //------------------------------------------------------------------------------------------------
284  protected void OnLimitedChanged(bool limited)
285  {
286  EditorOpened();
287  }
288 
289  //------------------------------------------------------------------------------------------------
290  protected void OnInputDeviceChanged(bool isUsingMouseAndKeyboard)
291  {
292  bool limited = m_NotificationsLog.GetEditorManager().IsLimited();
293 
294  if (!m_bHasPosition || !m_NotificationsLog.GetEditorManager().IsOpened() || limited)
295  return;
296 
297  if (m_GoToIndicator)
298  m_GoToIndicator.SetVisible(isUsingMouseAndKeyboard && !m_bShowTeleportControlHint);
299 
300  if (m_GoToIndicatorsHolder)
301  m_GoToIndicatorsHolder.SetVisible(isUsingMouseAndKeyboard || m_bShowTeleportControlHint)
302  }
303 
304  //------------------------------------------------------------------------------------------------
305  protected void TeleportToLocation()
306  {
307  if (!m_NotificationsLog.HasNotificationInput() || !m_Data)
308  return;
309 
310  bool limited = m_NotificationsLog.GetEditorManager().IsLimited();
311  if (limited)
312  return;
313 
314  vector position;
315  if (m_Data.GetDisplayData().GetPosition(m_Data, position))
316  {
317  SCR_ManualCamera camera = SCR_CameraEditorComponent.GetCameraInstance();
318  if (!camera)
319  return;
320 
322  if (!cursorManualCameraComponent)
323  return;
324 
325  cursorManualCameraComponent.TeleportCamera(position);
326  }
327  }
328 
329  //------------------------------------------------------------------------------------------------
330  protected void FadeDelete(float fadeSpeed)
331  {
332  AnimateWidget.Opacity(m_wRoot, 0, fadeSpeed);
333 
334  if (!m_bIsListeningToDoneFade)
335  {
336  m_bIsListeningToDoneFade = true;
337  GetGame().GetCallqueue().CallLater(AnimationDoneListenerUpdate, ANIMATION_DONE_UPDATE_SPEED, true);
338  }
339  }
340 
341  //------------------------------------------------------------------------------------------------
342  protected void AnimationDoneListenerUpdate()
343  {
344  if (!AnimateWidget.IsAnimating(m_wRoot))
345  DeleteNotification();
346  }
347 
348  //------------------------------------------------------------------------------------------------
350  void DeleteNotification()
351  {
352  if (m_wRoot)
353  m_wRoot.RemoveFromHierarchy();
354  }
355 
356  //------------------------------------------------------------------------------------------------
357  protected void AutoFadeDelay()
358  {
359  if (m_bIsListeningToDoneFade)
360  return;
361 
362  FadeDelete(AUTO_FADE_SPEED);
363  }
364 
365  //------------------------------------------------------------------------------------------------
366  override void HandlerAttached(Widget w)
367  {
368  if (SCR_Global.IsEditMode())
369  return;
370 
371  m_wRoot = w;
372 
373  m_GoToIndicator = w.FindAnyWidget(m_sGoToIndicator);
374  m_GoToControlHint = w.FindAnyWidget(m_sGoToControlHint);
375 
376  m_GoToIndicatorsHolder = m_wRoot.FindAnyWidget(m_sGoToIndicatorsHolder);
377  if (m_GoToIndicatorsHolder)
378  m_GoToIndicatorsHolder.SetVisible(false);
379 
380  ScriptInvoker teleportButton = ButtonActionComponent.GetOnAction(m_wRoot, false);
381  if (teleportButton)
382  teleportButton.Insert(TeleportToLocation);
383  }
384 
385  //------------------------------------------------------------------------------------------------
386  override void HandlerDeattached(Widget w)
387  {
388  if (SCR_Global.IsEditMode())
389  return;
390 
391  Event_OnDeleted.Invoke(this);
392 
393  if (!m_Data)
394  return;
395 
396  if (m_bHasPosition && m_NotificationsLog && m_NotificationsLog.GetEditorManager())
397  {
398  m_NotificationsLog.GetEditorManager().GetOnOpened().Remove(EditorOpened);
399  m_NotificationsLog.GetEditorManager().GetOnClosed().Remove(EditorClosed);
400  m_NotificationsLog.GetEditorManager().GetOnLimitedChange().Remove(OnLimitedChanged);
401  m_NotificationsLog.GetOnNewMessageHasPosition().Remove(OnNewNotificationHasPosition);
402  //m_NotificationsLog.GetNotificationManager().GetOnNotification().Remove(OnNotification);
403  m_NotificationsLog.GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
404  }
405 
406  if (m_bIsListeningToDoneFade)
407  GetGame().GetCallqueue().Remove(AnimationDoneListenerUpdate);
408  }
409 
410  //------------------------------------------------------------------------------------------------
412  SCR_NotificationData GetData()
413  {
414  return m_Data;
415  }
416 }
SCR_NotificationMessageUIComponent
Definition: SCR_NotificationMessageUIComponent.c:1
SCR_NotificationDisplayData
Definition: SCR_NotificationDisplayData.c:7
SCR_ManualCamera
Definition: SCR_ManualCamera.c:16
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
ENotificationReceiver
ENotificationReceiver
Definition: ENotificationReceiver.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CameraEditorComponent
Definition: SCR_CameraEditorComponent.c:13
SCR_ColoredTextNotificationUIInfo
Definition: SCR_ColoredTextNotificationUIInfo.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_NotificationsLogComponent
Definition: SCR_NotificationsLogUIComponent.c:6
ENotification
ENotification
Definition: ENotification.c:4
Attribute
typedef Attribute
Post-process effect of scripted camera.
ButtonActionComponent
Component to execute action when the button or its shortcut is pressed.
Definition: ButtonActionComponent.c:2
SCR_NotificationData
Definition: SCR_NotificationData.c:6
SCR_Global
Definition: Functions.c:6
SCR_TeleportToCursorManualCameraComponent
Teleport the camera to the cursor's world position.
Definition: SCR_TeleportToCursorManualCameraComponent.c:5
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
ENotificationColor
ENotificationColor
Definition: ENotificationColor.c:4
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
m_sIcon
protected string m_sIcon
Definition: SCR_InventoryHitZonePointUI.c:373
SCR_UINotificationInfo
UIInfo used by the Notifications system.
Definition: SCR_NotificationUIInfo.c:3
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26