Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DownloadManagerEntry.c
Go to the documentation of this file.
1
4
5//------------------------------------------------------------------------------------------------
8
9//------------------------------------------------------------------------------------------------
11{
12 const int PAUSE_ENABLE_DELAY_MS = 1000; // delay used to prevent spamming pause/resume request
13 protected const int PROCESSING_MESSAGE_UPDATE_DELAY = 2000; // delay to prevent message flickering when downloading switched to copying fragments
14
15 // State messages
16 protected const string PERCENTAGE = "#AR-SupportStation_ActionFormat_Percentage";
17
18 [Attribute(UIConstants.ICONS_IMAGE_SET, UIWidgets.ResourceNamePicker, desc: "Imageset for the icon", params: "imageset")]
20
21 [Attribute(UIConstants.PROCESSING_SPINNER_ANIMATION_SPEED.ToString())]
22 protected float m_fIconAnimationSpeed;
23
24 [Attribute(defvalue: SCR_Enum.GetDefault(EAnimationCurve.EASE_IN_OUT_SINE), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EAnimationCurve))]
26
27 [Attribute("0")]
29
32
34 protected ref SCR_WorkshopItem m_Item;
35
36 protected bool m_bPauseEnabled = true;
37 protected bool m_bShowButtons;
40
42
43 protected ref ScriptInvokerBase<ScriptInvoker_DownloadManagerEntry> m_OnUpdate;
44
45 //------------------------------------------------------------------------------------------------
46 ScriptInvokerBase<ScriptInvoker_DownloadManagerEntry> GetOnUpdate()
47 {
48 if (!m_OnUpdate)
49 m_OnUpdate = new ScriptInvokerBase<ScriptInvoker_DownloadManagerEntry>();
50
51 return m_OnUpdate;
52 }
53
54 //------------------------------------------------------------------------------------------------
55 // Override
56 //------------------------------------------------------------------------------------------------
57
58 //------------------------------------------------------------------------------------------------
59 override void HandlerAttached(Widget w)
60 {
61 super.HandlerAttached(w);
62 m_Widgets.Init(w);
63
64 m_Widgets.m_PauseBtnComponent.m_OnClicked.Insert(OnClickPause);
65 m_Widgets.m_ResumeBtnComponent.m_OnClicked.Insert(OnClickResume);
66 m_Widgets.m_CancelBtnComponent.m_OnClicked.Insert(OnClickCancel);
67 m_Widgets.m_RetryBtnComponent.m_OnClicked.Insert(OnClickRetry);
68
69 m_Widgets.m_HorizontalButtons.SetVisible(false);
70 m_Widgets.m_PauseBtn.SetVisible(false);
71 m_Widgets.m_ResumeBtn.SetVisible(false);
72 m_Widgets.m_CancelBtn.SetVisible(false);
73 m_Widgets.m_RetryBtn.SetVisible(false);
74
75 // Processing spinner animation
76 m_Widgets.m_ProcessingSpinner.SetRotation(360);
79 {
80 m_SpinnerAnimation.GetOnCycleCompleted().Insert(AnimateIcon);
82 }
83 }
84
85 //------------------------------------------------------------------------------------------------
86 override bool OnMouseEnter(Widget w, int x, int y)
87 {
88 m_bShowButtons = true;
90
91 return false;
92 }
93
94 //------------------------------------------------------------------------------------------------
95 override bool OnMouseLeave(Widget w, Widget enterW,int x, int y)
96 {
97 m_bShowButtons = false;
99
100 return false;
101 }
102
103 //------------------------------------------------------------------------------------------------
104 // Custom
105 //------------------------------------------------------------------------------------------------
106
107 //------------------------------------------------------------------------------------------------
108 protected void SetupWidgets()
109 {
110 if (!m_Action)
111 {
113 return;
114 }
115
116 // Image
117 if (m_Item && m_Item.GetWorkshopItem() && m_Item.GetWorkshopItem().Thumbnail())
118 m_BackendImage.SetImage(m_Item.GetWorkshopItem().Thumbnail());
119 else
120 m_BackendImage.SetImage(null);
121
122 // Name
123 m_Widgets.m_NameText.SetText(m_Action.GetAddonName());
124
125 // Versions
126 m_Widgets.m_VersionText.SetText(m_Action.GetTargetRevision().GetVersion());
127 }
128
129//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
130// Unlocalized fallback visuals
131
132 //------------------------------------------------------------------------------------------------
133 // Display placeholder values if action failed to be loaded
134 protected void FallbackVisuals()
135 {
136 if (!m_Item)
137 {
138 m_Widgets.m_NameText.SetText("...");
139 m_Widgets.m_VersionText.SetText("...");
140 m_BackendImage.SetImage(null);
141
142 return;
143 }
144
145 m_Widgets.m_NameText.SetText(m_Item.GetName());
146
147 // Versions
148 if (m_Item.GetItemTargetRevision())
149 m_Widgets.m_VersionText.SetText(m_Item.GetItemTargetRevision().GetVersion());
150 else
151 m_Widgets.m_VersionText.SetText("...");
152
153 // Image
154 if (m_Item.GetWorkshopItem() && m_Item.GetWorkshopItem().Thumbnail())
155 m_BackendImage.SetImage(m_Item.GetWorkshopItem().Thumbnail());
156 else
157 m_BackendImage.SetImage(null);
158 }
159
160//---- REFACTOR NOTE END ----
161
162 //------------------------------------------------------------------------------------------------
164 protected void UpdateProgressWidgets(bool force = false)
165 {
167
168 // Progress bar
169 bool running = (m_iState == EDownloadManagerActionState.RUNNING);
170 bool runningOrFailed = running || m_iState == EDownloadManagerActionState.FAILED;
171
173 m_Widgets.m_Progress.SetVisible(runningOrFailed);
174
175 // Download size
176 string addonSize = SCR_ByteFormat.ContentDownloadFormat(m_Action.GetSizeBytes());
177
178 if (runningOrFailed)
179 {
180 // Show progress
181 string downloadSize = SCR_ByteFormat.ContentDownloadFormat(m_Action.GetSizeBytes() * m_Action.GetProgress());
182
183 m_Widgets.m_DownloadedText.SetText(string.Format("%1/%2", downloadSize, addonSize));
184 m_Widgets.m_ProgressComponent.SetValue(m_Action.GetProgress());
185 }
186 else
187 {
188 m_Widgets.m_DownloadedText.SetText(addonSize);
189
190 if (m_Action.IsCompleted())
191 m_Widgets.m_ProgressComponent.SetValue(m_Action.GetProgress());
192 }
193
194 // Update buttons
196
197 bool processing = m_Action.IsProcessing() && !(m_Action.IsPaused() || m_Action.IsFailed() || m_Action.IsCanceled());
198 if (!processing || force)
199 {
200 UpdateMessage(processing);
201 }
202 // Delay to avoid flickering
203 else
204 {
206 GetGame().GetCallqueue().CallLater(UpdateMessage, PROCESSING_MESSAGE_UPDATE_DELAY, false, processing);
207 }
208
209 // Invoke
210 if (m_OnUpdate)
211 m_OnUpdate.Invoke(this);
212 }
213
214 //------------------------------------------------------------------------------------------------
215 protected void UpdateMessage(bool processing)
216 {
218 {
219 GetGame().GetCallqueue().Remove(UpdateMessage);
221 }
222
223 // Show message
224 string msg, imgName;
225 Color col;
226 StateMessage(msg, imgName, col);
227
228 m_Widgets.m_DownloadStateText.SetText(msg);
229 m_Widgets.m_DownloadIcon.LoadImageFromSet(0, m_sIconImageset, imgName);
230 m_Widgets.m_DownloadIconShadow.LoadImageFromSet(0, m_sIconImageset, imgName);
231
232 if (col)
233 {
234 m_Widgets.m_DownloadIcon.SetColor(col);
235 m_Widgets.m_DownloadStateText.SetColor(col);
236 m_Widgets.m_ProgressComponent.SetSliderColor(col);
237 m_Widgets.m_ProcessingSpinner.SetColor(col);
238 }
239
240 m_Widgets.m_ProcessingSpinner.SetVisible(processing);
241 m_Widgets.m_DownloadIcon.SetVisible(!processing);
242 m_Widgets.m_DownloadIconShadow.SetVisible(!processing);
243 }
244
245 //------------------------------------------------------------------------------------------------
246 protected void UpdateButtons()
247 {
248 m_Widgets.m_HorizontalButtons.SetVisible(m_bShowButtons);
249
250 if (!m_bShowButtons)
251 return;
252
253 bool pause, resume, cancel, retry;
254 CanDoActions(pause, resume, cancel, retry);
255
256 // Buttons
257 m_Widgets.m_PauseBtn.SetVisible(pause);
258 m_Widgets.m_ResumeBtn.SetVisible(resume);
259 m_Widgets.m_CancelBtn.SetVisible(cancel);
260 m_Widgets.m_RetryBtn.SetVisible(retry);
261
262 m_Widgets.m_PauseBtn.SetEnabled(m_Action.IsRunningAsyncSolved());
263 m_Widgets.m_ResumeBtn.SetEnabled(m_Action.IsPauseAsyncSolved());
264 }
265
266 //------------------------------------------------------------------------------------------------
268 protected void StateMessage(out string message, out string imageName, out Color color)
269 {
270 float progress;
271
272 // Downloading
273 if (m_Action.IsActive() && !m_Action.IsCompleted() && !m_Action.IsPaused())
274 {
275 // Copying fragments
276 if (m_Action.IsProcessing())
277 {
278 progress = m_Action.GetProcessingProgress();
279
280 message = WidgetManager.Translate(PERCENTAGE, SCR_WorkshopUiCommon.DOWNLOAD_STATE_PROCESSING, SCR_WorkshopUiCommon.GetDownloadProgressPercentage(progress));
281 imageName = SCR_WorkshopUiCommon.DOWNLOAD_STATE_ICON_PROCESSING;
282 color = Color.FromInt(UIColors.ONLINE.PackToInt());
283 return;
284 }
285
286 // Download running
287 progress = m_Action.GetProgress();
288
289 message = WidgetManager.Translate(PERCENTAGE, SCR_WorkshopUiCommon.DOWNLOAD_STATE_DOWNLOADING, SCR_WorkshopUiCommon.GetDownloadProgressPercentage(progress));
290 imageName = SCR_WorkshopUiCommon.DOWNLOAD_STATE_ICON_DOWNLOADING;
291 color = Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt());
292 return;
293 }
294
295 // Paused
296 if (m_Action.IsPaused())
297 {
298 progress = m_Action.GetProgress();
299
300 message = WidgetManager.Translate(PERCENTAGE, SCR_WorkshopUiCommon.DOWNLOAD_STATE_PAUSED, SCR_WorkshopUiCommon.GetDownloadProgressPercentage(progress));
301 imageName = SCR_WorkshopUiCommon.DOWNLOAD_STATE_ICON_PAUSED;
302 color = Color.FromInt(UIColors.CONTRAST_DEFAULT.PackToInt());
303 return;
304 }
305
306 // Canceled
307 if (m_Action.IsCanceled())
308 {
309 message = SCR_WorkshopUiCommon.DOWNLOAD_STATE_CANCELED;
310 imageName = UIConstants.ICON_CANCEL;
311 color = Color.FromInt(UIColors.WARNING.PackToInt());
312 return;
313 }
314
315 // Failed
316 if (m_Action.IsFailed())
317 {
318 FailReason(message, imageName);
319 color = Color.FromInt(UIColors.WARNING.PackToInt());
320 return;
321 }
322
323 // Success
324 if (m_Action.IsCompleted())
325 {
326 message = SCR_WorkshopUiCommon.DOWNLOAD_STATE_COMPLETED;
327 imageName = UIConstants.ICON_OK;
328 color = Color.FromInt(UIColors.CONFIRM.PackToInt());
329 return;
330 }
331 }
332
333 //------------------------------------------------------------------------------------------------
335 protected void FailReason(out string message, out string icon)
336 {
337 // Addon specific fail
338 message = SCR_WorkshopUiCommon.DOWNLOAD_STATE_DOWNLOAD_FAIL;
339 icon = UIConstants.ICON_WARNING;
340
341 // Communication with server failed
343 {
344 message = SCR_ConnectionUICommon.MESSAGE_VERBOSE_DISCONNECTION;
345 icon = SCR_ConnectionUICommon.ICON_SERVICES_ISSUES;
346 }
347 }
348
349 //------------------------------------------------------------------------------------------------
351 protected void AnimateIcon(WidgetAnimationBase animation)
352 {
354 {
355 m_SpinnerAnimation.GetOnCycleCompleted().Remove(AnimateIcon);
356 m_SpinnerAnimation.Stop();
357 }
358
359 m_Widgets.m_ProcessingSpinner.SetRotation(360);
362 {
363 m_SpinnerAnimation.SetRepeat(true);
365 m_SpinnerAnimation.GetOnCycleCompleted().Insert(AnimateIcon);
366 }
367 }
368
369 //------------------------------------------------------------------------------------------------
370 protected void DisablePauserResume(SCR_ModularButtonComponent button)
371 {
372 m_bPauseEnabled = false;
373 button.SetEnabled(false);
374 // Enable pause button later to prevent request spamming
375 GetGame().GetCallqueue().Remove(EnablePauserResume);
376 GetGame().GetCallqueue().CallLater(EnablePauserResume, PAUSE_ENABLE_DELAY_MS, false, button);
377
378 if (m_OnUpdate)
379 m_OnUpdate.Invoke(this);
380 }
381
382 //------------------------------------------------------------------------------------------------
383 protected void EnablePauserResume(SCR_ModularButtonComponent button)
384 {
385 m_bPauseEnabled = true;
386 button.SetEnabled(true);
387
388 if (m_OnUpdate)
389 m_OnUpdate.Invoke(this);
390 }
391
392 //------------------------------------------------------------------------------------------------
394 {
396 }
397
398 //------------------------------------------------------------------------------------------------
399 // Public
400 //------------------------------------------------------------------------------------------------
401 //------------------------------------------------------------------------------------------------
405 {
406 if (!action)
407 {
408 Print("Download manager entry state can't be update due to missing download action");
409 return EDownloadManagerActionState.INACTIVE;
410 }
411
412 // Running
413 if (!action.IsCompleted() && !action.IsFailed() && !action.IsCanceled())
414 return EDownloadManagerActionState.RUNNING;
415
416 // Failed
417 if (action.IsFailed() || action.IsCanceled())
418 return EDownloadManagerActionState.FAILED;
419
420 // Downloaded
421 if (action.IsCompleted() && !action.IsFailed() && !action.IsCanceled())
422 return EDownloadManagerActionState.DOWNLOADED;
423
424 // No state
425 return EDownloadManagerActionState.INACTIVE;
426 }
427
428 //------------------------------------------------------------------------------------------------
432 {
433 m_Item = item;
434 m_Action = action;
435
436 m_Action.m_OnChanged.Insert(OnActionChanged);
437
439
440 // Setup static
441 SetupWidgets();
442
443 if (m_Action)
445 }
446
447 //------------------------------------------------------------------------------------------------
449 void CanDoActions(out bool canPause, out bool canResume, out bool canCancel, out bool canRetry)
450 {
451 canPause = m_iState == EDownloadManagerActionState.RUNNING && !m_Action.IsPaused();
452 canResume = m_iState == EDownloadManagerActionState.RUNNING && m_Action.IsPaused();
453 canCancel = m_iState == EDownloadManagerActionState.RUNNING;
454 canRetry = m_iState == EDownloadManagerActionState.FAILED;
455 }
456
457 //------------------------------------------------------------------------------------------------
459 {
460 if (!m_Action)
461 return;
462
463 if (m_Action.IsActive() && !m_Action.IsPaused())
464 m_Action.Pause();
465
467
468 // Set disabled
469 //DisablePauserResume(m_Widgets.m_ResumeBtnComponent);
470 }
471
472 //------------------------------------------------------------------------------------------------
474 {
475 if (!m_Action)
476 return;
477
478 if (m_Action.IsPaused())
479 m_Action.Resume();
480 else if (m_Action.IsInactive())
481 m_Action.Activate();
482
484
485 // Set disabled
486 //DisablePauserResume(m_Widgets.m_PauseBtnComponent);
487 }
488
489 //------------------------------------------------------------------------------------------------
491 {
492 if (m_Action)
493 m_Action.Cancel();
494
496 }
497
498 //------------------------------------------------------------------------------------------------
500 {
501 if (m_Action)
502 m_Action.RetryDownload();
503
504 if (m_wRoot)
506 }
507
508 //------------------------------------------------------------------------------------------------
509 // Get set
510 //------------------------------------------------------------------------------------------------
511
512 //------------------------------------------------------------------------------------------------
514 {
515 return m_Item;
516 }
517
518 //------------------------------------------------------------------------------------------------
523
524 //------------------------------------------------------------------------------------------------
529
530 //------------------------------------------------------------------------------------------------
532 {
533 return m_bPauseEnabled;
534 }
535}
ArmaReforgerScripted GetGame()
Definition game.c:1398
EDownloadManagerActionState
Enum describing current state of downloading action.
void UpdateProgressWidgets()
func ScriptInvoker_DownloadManagerEntry
void UpdateMessage()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void WidgetAnimationBase(Widget w, float speed)
EAnimationCurve
static WidgetAnimationImageRotation Rotation(Widget widget, float targetValue, float speed)
Definition Color.c:13
bool m_bShowButtons
void OnClickRetry()
EAnimationCurve m_eIconAnimationCurve
const int PROCESSING_MESSAGE_UPDATE_DELAY
void FailReason(out string message, out string icon)
Return message with details why entry wasn't downloaded.
void InitForDownloadAction(SCR_WorkshopItem item, SCR_WorkshopItemActionDownload action)
ref ScriptInvokerBase< ScriptInvoker_DownloadManagerEntry > m_OnUpdate
const string PERCENTAGE
void UpdateProgressWidgets(bool force=false)
Update all text displaying progress.
ref SCR_WorkshopItemActionDownload m_Action
ScriptInvokerBase< ScriptInvoker_DownloadManagerEntry > GetOnUpdate()
void OnClickResume()
void CanDoActions(out bool canPause, out bool canResume, out bool canCancel, out bool canRetry)
Store which actions can be used for entry in current state.
bool m_bHideProgressBarOnComplete
void DisablePauserResume(SCR_ModularButtonComponent button)
ResourceName m_sIconImageset
void SetupWidgets()
float m_fIconAnimationSpeed
void UpdateButtons()
override void HandlerAttached(Widget w)
void UpdateMessage(bool processing)
override bool OnMouseEnter(Widget w, int x, int y)
ref SCR_DownloadManagerEntryWidgets m_Widgets
void OnClickPause()
SCR_WorkshopItem GetItem()
ref SCR_BackendImageComponent m_BackendImage
bool GetPauseEnabled()
void FallbackVisuals()
bool m_bPauseEnabled
void StateMessage(out string message, out string imageName, out Color color)
Setup state message variables.
void OnActionChanged(SCR_WorkshopItemAction action)
static EDownloadManagerActionState DownloadActionState(SCR_WorkshopItemActionDownload action)
EDownloadManagerActionState GetState()
bool m_bDelayedProcessingDisplay
void OnClickCancel()
ref SCR_WorkshopItem m_Item
WidgetAnimationImageRotation m_SpinnerAnimation
SCR_WorkshopItemActionDownload GetDownloadAction()
void AnimateIcon(WidgetAnimationBase animation)
Return message with details why entry wasn't downloaded.
EDownloadManagerActionState m_iState
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void EnablePauserResume(SCR_ModularButtonComponent button)
static int GetDownloadProgressPercentage(float progress)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
SCR_FieldOfViewSettings Attribute