Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditorToggleUIComponent.c
Go to the documentation of this file.
1 
3 class SCR_EditorToggleUIComponent : ScriptedWidgetComponent
4 {
5  [Attribute()]
6  protected string m_sProgressWidgetName;
7 
8  [Attribute()]
9  protected string m_sInitLoadingWidgetName;
10 
11  [Attribute()]
12  protected string m_sLoadingWidgetName;
13 
14  [Attribute()]
15  protected string m_sBlurName;
16 
17  [Attribute()]
18  protected string m_sAutoInitName;
19 
20  [Attribute("0.4", desc: "When the actual charging starts. This should be after ping is evaluated. Thinging this value also means changing the process min of m_RadialProcessBar and the Ping input!")]
21  protected float m_fChargeThreshold;
22 
23  protected SCR_EditorManagerEntity m_EditorManager;
24  protected MenuManager m_MenuManager;
25  protected Widget m_Widget;
26  protected Widget m_Blur;
27  protected Widget m_AutoInit;
28  protected Widget m_ProgressWidget;
29  protected SCR_ImageRadialProgressBarUIComponent m_RadialProcessBar;
30  protected SCR_FadeUIComponent m_LoadingWidget;
31  protected SCR_FadeUIComponent m_InitLoadingWidget;
32 
33  //State
34  protected bool m_bCharging;
35 
36  //------------------------------------------------------------------------------------------------
37  protected void ChargeStart()
38  {
39  if (m_MenuManager.IsAnyDialogOpen())
40  return;
41 
42  m_bCharging = true;
43  m_Blur.SetVisible(true);
44 
45  if (m_Widget.IsVisible())
46  return;
47 
48  m_Widget.SetVisible(true);
49  m_RadialProcessBar.FadeImage(true);
50  m_ProgressWidget.SetVisible(true);
51  m_LoadingWidget.GetFadeWidget().SetVisible(false);
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  protected void ChargeFail()
56  {
57  m_bCharging = false;
58  m_Blur.SetVisible(false);
59 
60  if (m_RadialProcessBar.GetProgress() == m_RadialProcessBar.GetMaxProgress() || m_RadialProcessBar.GetProgress() <= m_RadialProcessBar.GetMinProgress())
61  return;
62 
63  m_RadialProcessBar.InstantProgressMaxMin(false);
64  m_Widget.SetVisible(false);
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  protected void WaitStart()
69  {
70  SCR_EditorModeEntity mode = m_EditorManager.GetCurrentModeEntity();
71  if (mode)
72  mode.GetInfo().SetIconTo(m_RadialProcessBar.GetFadeImage());
73 
74  if (!m_Widget.IsVisible())
75  {
76  m_AutoInit.SetVisible(m_EditorManager.IsAutoInit());
77  m_Blur.SetVisible(true);
78  m_Widget.SetVisible(true);
79  m_RadialProcessBar.InstantProgressMaxMin(false);
80  m_RadialProcessBar.FadeImage(true);
81  //m_InitLoadingWidget.FadeIn();
82  m_LoadingWidget.FadeIn();
83  }
84 
85  if (m_EditorManager.IsAutoInit())
86  m_InitLoadingWidget.FadeIn();
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  protected void WaitEnd()
91  {
92  m_RadialProcessBar.SetProgress(m_RadialProcessBar.GetMinProgress());
93 
94  if (m_AutoInit.IsVisible())
95  {
96  AnimateWidget.Opacity(m_AutoInit, 0, UIConstants.FADE_RATE_SUPER_SLOW);
97 
98  if (m_InitLoadingWidget)
99  m_InitLoadingWidget.FadeOut(true);
100  }
101 
102  m_Blur.SetVisible(false);
103  m_LoadingWidget.FadeOut(false);
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  protected void OnRadialProgressFadeDone(SCR_ImageRadialProgressBarUIComponent radial, bool isFadeIn)
108  {
109  if (!m_bCharging && !isFadeIn)
110  {
111  m_RadialProcessBar.InstantProgressMaxMin(false);
112  m_Widget.SetVisible(false);
113  }
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  protected void OnEditorToggleValue(float value, EActionTrigger reason)
118  {
119  if (m_MenuManager.IsAnyDialogOpen())
120  ChargeFail();
121 
122  if (value == 0)
123  {
124  //Charge has failed
125  if (m_bCharging)
126  ChargeFail();
127 
128  return;
129  }
130  //If cannot open editor
131  else if (!m_EditorManager || !m_EditorManager.CanToggle())
132  {
133  //Safty if rights where removed
134  if (m_bCharging)
135  ChargeFail();
136 
137  return;
138  }
139  //Visualize the charge only after ping input time window
140  else if (value < m_fChargeThreshold)
141  {
142  return;
143  }
144 
145  if (!m_bCharging)
146  ChargeStart();
147  else
148  m_RadialProcessBar.SetProgress(value);
149  }
150 
151  //------------------------------------------------------------------------------------------------
152  protected void OnEditorToggleDone()
153  {
154  //Editor failed to open, terminate
155  if (!m_EditorManager.IsInTransition())
156  ChargeFail();
157 
158  m_bCharging = false;
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  protected void OnRequest()
163  {
164  WaitStart();
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  protected void OnRequestEnd()
169  {
170  m_bCharging = false;
171  WaitEnd();
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  protected void OnAsyncLoad(float progress)
176  {
177  if (progress < 1)
178  WaitStart();
179  else
180  WaitEnd();
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  override void HandlerAttached(Widget w)
185  {
186  if (SCR_Global.IsEditMode())
187  return;
188 
190  if (!m_EditorManager)
191  return;
192 
193  InputManager inputManager = GetGame().GetInputManager();
194  if (!inputManager)
195  return;
196 
197  m_ProgressWidget = w.FindWidget(m_sProgressWidgetName);
198  if (!m_ProgressWidget)
199  {
200  Print(string.Format("ProgressBarWidget '%1' not found!", m_sProgressWidgetName), LogLevel.WARNING);
201  return;
202  }
203 
204  m_RadialProcessBar = SCR_ImageRadialProgressBarUIComponent.Cast(m_ProgressWidget.GetChildren().FindHandler(SCR_ImageRadialProgressBarUIComponent));
205  if (!m_RadialProcessBar)
206  return;
207 
208  m_RadialProcessBar.GetOnFadeDone().Insert(OnRadialProgressFadeDone);
209 
210  m_Blur = w.FindWidget(m_sBlurName);
211  m_AutoInit = w.FindWidget(m_sAutoInitName);
212  m_AutoInit.SetVisible(false);
213 
214  Widget loadingWidget = w.FindAnyWidget(m_sLoadingWidgetName);
215  m_LoadingWidget = SCR_FadeUIComponent.Cast(loadingWidget.FindHandler(SCR_FadeUIComponent));
216  m_LoadingWidget.GetFadeWidget().SetVisible(false);
217 
218  Widget initLoadingWidget = w.FindAnyWidget(m_sInitLoadingWidgetName);
219  m_InitLoadingWidget = SCR_FadeUIComponent.Cast(initLoadingWidget.FindHandler(SCR_FadeUIComponent));
220 
221  m_Widget = w;
222  m_Widget.SetVisible(false);
223 
224  m_EditorManager.GetOnRequest().Insert(OnRequest);
225  m_EditorManager.GetOnOpened().Insert(OnRequestEnd);
226  m_EditorManager.GetOnClosed().Insert(OnRequestEnd);
227  m_EditorManager.GetOnAsyncLoad().Insert(OnAsyncLoad);
228 
229  inputManager.AddActionListener("EditorToggle", EActionTrigger.VALUE, OnEditorToggleValue);
230  inputManager.AddActionListener("EditorToggle", EActionTrigger.UP, OnEditorToggleDone);
231 
232  m_MenuManager = GetGame().GetMenuManager();
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  override void HandlerDeattached(Widget w)
237  {
238  if (m_EditorManager)
239  {
240  m_EditorManager.GetOnRequest().Remove(OnRequest);
241  m_EditorManager.GetOnOpened().Remove(OnRequestEnd);
242  m_EditorManager.GetOnClosed().Remove(OnRequestEnd);
243  m_EditorManager.GetOnAsyncLoad().Remove(OnAsyncLoad);
244  }
245 
246  InputManager inputManager = GetGame().GetInputManager();
247  if (inputManager)
248  {
249  inputManager.RemoveActionListener("EditorToggle", EActionTrigger.VALUE, OnEditorToggleValue);
250  inputManager.RemoveActionListener("EditorToggle", EActionTrigger.UP, OnEditorToggleDone);
251 
252  }
253 
254  if (m_RadialProcessBar)
255  m_RadialProcessBar.GetOnFadeDone().Remove(OnRadialProgressFadeDone);
256  }
257 }
SCR_FadeUIComponent
Definition: SCR_FadeUIComponent.c:1
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ImageRadialProgressBarUIComponent
Definition: SCR_ImageRadialProgressBarUIComponent.c:1
SCR_EditorToggleUIComponent
Definition: SCR_EditorToggleUIComponent.c:3
m_EditorManager
protected SCR_EditorManagerEntity m_EditorManager
Definition: SCR_VotingEditor.c:5
SCR_Global
Definition: Functions.c:6
m_MenuManager
protected MenuManager m_MenuManager
Definition: SCR_InfoDisplayExtended.c:27
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26