Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_StickyNotificationUIComponent.c
Go to the documentation of this file.
1 class SCR_StickyNotificationUIComponent : ScriptedWidgetComponent
2 {
3  [Attribute("StickyNotificationMessage")]
4  protected string m_sTextName;
5 
6  [Attribute("OptionalMessageLayout")]
7  protected string m_sOptionalMessageLayoutName;
8 
9  //Reference
10  protected SCR_NotificationsLogComponent m_NotificationsLog;
11  protected Widget m_Root;
12  protected SCR_FadeUIComponent m_FadeUIComponent;
13 
14  [Attribute("1", desc: "Wether or not the notification message list shrinks if a new stick notification is added (and increases again on deactivate). Do not change in runtime unless you are certain the notification log knows this notification is not active!")]
15  protected bool m_bInfluenceNotificationListSize;
16 
17  protected bool m_bStickyNotificationActive = false;
18 
19  protected TextWidget m_Text;
20  protected Widget m_OptionalMessageLayout;
21 
22  protected ref ScriptInvoker Event_OnStickyActiveChanged = new ScriptInvoker();
23 
24  protected void SetStickyActive(bool newActive, bool fade = true)
25  {
26  if (newActive == m_bStickyNotificationActive)
27  {
28  //Still set visiblity
29  if (!fade)
30  SetVisible(newActive);
31 
32  return;
33  }
34 
35  m_bStickyNotificationActive = newActive;
36 
37  Event_OnStickyActiveChanged.Invoke(m_bStickyNotificationActive);
38 
39  if (fade)
40  Fade(newActive);
41  else
42  SetVisible(newActive);
43  }
44 
45  //------------------------------------------------------------------------------------------------
49  bool isStickyActive()
50  {
51  return m_bStickyNotificationActive;
52  }
53 
54  //------------------------------------------------------------------------------------------------
58  bool InfluenceNotificationListSize()
59  {
60  return m_bInfluenceNotificationListSize;
61  }
62 
63  //------------------------------------------------------------------------------------------------
67  ScriptInvoker GetOnStickyActiveChanged()
68  {
69  return Event_OnStickyActiveChanged;
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  protected void SetVisible(bool visible)
74  {
75  if (visible)
76  m_Root.SetOpacity(1);
77  else
78  m_Root.SetOpacity(0);
79 
80  m_Root.SetVisible(visible);
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  protected void Fade(bool fadeIn)
85  {
86  if (fadeIn)
87  {
88  if (!m_FadeUIComponent.IsFadingIn())
89  m_FadeUIComponent.FadeIn(false);
90  }
91  else
92  {
93  if (!m_Root.IsVisible() || !m_FadeUIComponent.IsFadingOut())
94  m_FadeUIComponent.FadeOut(false);
95  }
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  protected void OnButton()
100  {
101  }
102 
103  //------------------------------------------------------------------------------------------------
105  void OnInit(SCR_NotificationsLogComponent notificationLog)
106  {
107  if (SCR_Global.IsEditMode() || !m_Root)
108  return;
109 
110  m_NotificationsLog = notificationLog;
111 
112  //Disable clicking on the UI
113  if (!m_NotificationsLog.HasNotificationInput())
114  {
115  m_Root.SetEnabled(false);
116  return;
117  }
118 
119  SCR_EditorManagerEntity editorManager = notificationLog.GetEditorManager();
120  if (!editorManager)
121  return;
122 
123  m_Root.SetEnabled(editorManager.IsOpened());
124  editorManager.GetOnOpened().Insert(EditorOpened);
125  editorManager.GetOnClosed().Insert(EditorClosed);
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  protected void OnDestroy()
130  {
131  }
132 
133  //------------------------------------------------------------------------------------------------
134  protected void EditorOpened()
135  {
136  if (m_Root)
137  m_Root.SetEnabled(true);
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  protected void EditorClosed()
142  {
143  if (m_Root)
144  m_Root.SetEnabled(false);
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  override void HandlerAttached(Widget w)
149  {
150  if (SCR_Global.IsEditMode())
151  return;
152 
153  m_Root = w;
154  m_FadeUIComponent = SCR_FadeUIComponent.Cast(w.FindHandler(SCR_FadeUIComponent));
155  if (!m_FadeUIComponent)
156  Print("SCR_NotificationVotingInProgressUIComponent could not find SCR_FadeUIComponent! Make sure this component comes after the SCR_FadeUIComponent!", LogLevel.ERROR);
157 
158  m_Text = TextWidget.Cast(w.FindAnyWidget(m_sTextName));
159  if (!m_Text)
160  Print("SCR_NotificationVotingInProgressUIComponent could not find m_Text!", LogLevel.ERROR);
161 
162  m_OptionalMessageLayout = w.FindAnyWidget(m_sOptionalMessageLayoutName);
163 
164  ScriptInvoker onPressed = ButtonActionComponent.GetOnAction(w);
165  if (onPressed)
166  onPressed.Insert(OnButton);
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  override void HandlerDeattached(Widget w)
171  {
172  OnDestroy();
173 
174  if (m_NotificationsLog)
175  {
176  SCR_EditorManagerEntity editorManager = m_NotificationsLog.GetEditorManager();
177  if (editorManager)
178  {
179  editorManager.GetOnOpened().Remove(EditorOpened);
180  editorManager.GetOnClosed().Remove(EditorClosed);
181  }
182  }
183  }
184 }
m_Root
SCR_ServerHostingModSubMenu m_Root
SCR_FadeUIComponent
Definition: SCR_FadeUIComponent.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_NotificationsLogComponent
Definition: SCR_NotificationsLogUIComponent.c:6
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_Global
Definition: Functions.c:6
SCR_StickyNotificationUIComponent
Definition: SCR_StickyNotificationUIComponent.c:1
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26