12 const int PAUSE_ENABLE_DELAY_MS = 1000;
13 protected const int PROCESSING_MESSAGE_UPDATE_DELAY = 2000;
16 protected const string PERCENTAGE =
"#AR-SupportStation_ActionFormat_Percentage";
17 protected const string STATE_DOWNLOADING =
"#AR-DownloadManager_State_Downloading";
18 protected const string STATE_PROCESSING =
"#AR-DownloadManager_State_Processing";
19 protected const string STATE_PAUSED =
"#AR-Workshop_ButtonPause";
20 protected const string STATE_CANCELED =
"#AR-Workshop_Canceled";
21 protected const string STATE_NO_CONNECTION =
"#AR-Workshop_WarningNoConnection";
22 protected const string STATE_DOWNLOAD_FAIL =
"#AR-Workshop_DownloadFail";
23 protected const string STATE_COMPLETED =
"#AR-Workshop_Details_Downloaded";
26 protected const string STATE_ICON_DOWNLOADING =
"downloading";
27 protected const string STATE_ICON_PROCESSING =
"update";
28 protected const string STATE_ICON_PAUSED =
"download-pause";
29 protected const string STATE_ICON_CANCELED =
"cancelCircle";
30 protected const string STATE_ICON_DOWNLOAD_FAIL =
"warning";
31 protected const string STATE_ICON_COMPLETED =
"okCircle";
34 protected ResourceName m_sIconImageset;
37 protected float m_fIconAnimationSpeed;
39 [
Attribute(defvalue:
SCR_Enum.GetDefault(EAnimationCurve.EASE_IN_OUT_SINE), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EAnimationCurve))]
40 protected EAnimationCurve m_eIconAnimationCurve;
43 protected bool m_bHideProgressBarOnComplete;
46 protected ref SCR_BackendImageComponent m_BackendImage;
51 protected bool m_bPauseEnabled =
true;
52 protected bool m_bShowButtons;
53 protected bool m_bDelayedProcessingDisplay;
56 protected WidgetAnimationImageRotation m_SpinnerAnimation;
58 protected ref ScriptInvokerBase<ScriptInvoker_DownloadManagerEntry> m_OnUpdate;
61 ScriptInvokerBase<ScriptInvoker_DownloadManagerEntry> GetOnUpdate()
64 m_OnUpdate =
new ScriptInvokerBase<ScriptInvoker_DownloadManagerEntry>();
74 override void HandlerAttached(Widget w)
76 super.HandlerAttached(w);
79 m_Widgets.m_PauseBtnComponent.m_OnClicked.Insert(OnClickPause);
80 m_Widgets.m_ResumeBtnComponent.m_OnClicked.Insert(OnClickResume);
81 m_Widgets.m_CancelBtnComponent.m_OnClicked.Insert(OnClickCancel);
82 m_Widgets.m_RetryBtnComponent.m_OnClicked.Insert(OnClickRetry);
84 m_Widgets.m_HorizontalButtons.SetVisible(
false);
91 m_Widgets.m_ProcessingSpinner.SetRotation(360);
101 override bool OnMouseEnter(Widget w,
int x,
int y)
103 m_bShowButtons =
true;
110 override bool OnMouseLeave(Widget w, Widget enterW,
int x,
int y)
112 m_bShowButtons =
false;
123 protected void SetupWidgets()
138 m_Widgets.m_NameText.SetText(m_Action.GetAddonName());
141 m_Widgets.m_VersionText.SetText(m_Action.GetTargetRevision().GetVersion());
146 protected void FallbackVisuals()
160 if (
m_Item.GetItemTargetRevision())
161 m_Widgets.m_VersionText.SetText(
m_Item.GetItemTargetRevision().GetVersion());
166 if (
m_Item.GetWorkshopItem() &&
m_Item.GetWorkshopItem().Thumbnail())
174 protected void UpdateProgressWidgets(
bool force =
false)
176 m_iState = DownloadActionState(m_Action);
182 if (m_bHideProgressBarOnComplete)
183 m_Widgets.m_Progress.SetVisible(runningOrFailed);
186 string addonSize =
SCR_ByteFormat.ContentDownloadFormat(m_Action.GetSizeBytes());
191 string downloadSize =
SCR_ByteFormat.ContentDownloadFormat(m_Action.GetSizeBytes() * m_Action.GetProgress());
193 m_Widgets.m_DownloadedText.SetText(
string.Format(
"%1/%2", downloadSize, addonSize));
194 m_Widgets.m_ProgressComponent.SetValue(m_Action.GetProgress());
198 m_Widgets.m_DownloadedText.SetText(addonSize);
200 if (m_Action.IsCompleted())
201 m_Widgets.m_ProgressComponent.SetValue(m_Action.GetProgress());
207 bool processing = m_Action.IsProcessing() && !(m_Action.IsPaused() || m_Action.IsFailed() || m_Action.IsCanceled());
208 if (!processing || force)
210 UpdateMessage(processing);
215 m_bDelayedProcessingDisplay =
true;
216 GetGame().GetCallqueue().CallLater(UpdateMessage, PROCESSING_MESSAGE_UPDATE_DELAY,
false, processing);
221 m_OnUpdate.Invoke(
this);
225 protected void UpdateMessage(
bool processing)
227 if (m_bDelayedProcessingDisplay)
229 GetGame().GetCallqueue().Remove(UpdateMessage);
230 m_bDelayedProcessingDisplay =
false;
236 StateMessage(msg, imgName, col);
238 m_Widgets.m_DownloadStateText.SetText(msg);
239 m_Widgets.m_DownloadIcon.LoadImageFromSet(0, m_sIconImageset, imgName);
240 m_Widgets.m_DownloadIconShadow.LoadImageFromSet(0, m_sIconImageset, imgName);
245 m_Widgets.m_DownloadStateText.SetColor(col);
246 m_Widgets.m_ProgressComponent.SetSliderColor(col);
247 m_Widgets.m_ProcessingSpinner.SetColor(col);
250 m_Widgets.m_ProcessingSpinner.SetVisible(processing);
251 m_Widgets.m_DownloadIcon.SetVisible(!processing);
252 m_Widgets.m_DownloadIconShadow.SetVisible(!processing);
256 protected void UpdateButtons()
258 m_Widgets.m_HorizontalButtons.SetVisible(m_bShowButtons);
263 bool pause, resume, cancel, retry;
264 CanDoActions(pause, resume, cancel, retry);
268 m_Widgets.m_ResumeBtn.SetVisible(resume);
269 m_Widgets.m_CancelBtn.SetVisible(cancel);
272 m_Widgets.m_PauseBtn.SetEnabled(m_Action.IsRunningAsyncSolved());
273 m_Widgets.m_ResumeBtn.SetEnabled(m_Action.IsPauseAsyncSolved());
278 protected void StateMessage(out
string message, out
string imageName, out Color color)
283 if (m_Action.IsActive() && !m_Action.IsCompleted() && !m_Action.IsPaused())
286 if (m_Action.IsProcessing())
288 progress = m_Action.GetProcessingProgress();
290 message = WidgetManager.Translate(PERCENTAGE, STATE_PROCESSING, Math.Round(progress * 100.0));
291 imageName = STATE_ICON_PROCESSING;
292 color = Color.FromInt(
UIColors.ONLINE.PackToInt());
297 progress = m_Action.GetProgress();
299 message = WidgetManager.Translate(PERCENTAGE,
STATE_DOWNLOADING, Math.Round(progress * 100.0));
300 imageName = STATE_ICON_DOWNLOADING;
301 color = Color.FromInt(
UIColors.CONTRAST_COLOR.PackToInt());
306 if (m_Action.IsPaused())
308 progress = m_Action.GetProgress();
310 message = WidgetManager.Translate(PERCENTAGE, STATE_PAUSED, Math.Round(progress * 100.0));
311 imageName = STATE_ICON_PAUSED;
312 color = Color.FromInt(
UIColors.CONTRAST_DEFAULT.PackToInt());
317 if (m_Action.IsCanceled())
319 message = STATE_CANCELED;
320 imageName = STATE_ICON_CANCELED;
321 color = Color.FromInt(
UIColors.WARNING.PackToInt());
326 if (m_Action.IsFailed())
328 FailReason(message, imageName);
329 color = Color.FromInt(
UIColors.WARNING.PackToInt());
334 if (m_Action.IsCompleted())
336 message = STATE_COMPLETED;
337 imageName = STATE_ICON_COMPLETED;
338 color = Color.FromInt(
UIColors.CONFIRM.PackToInt());
345 protected void FailReason(out
string message, out
string icon)
348 message = STATE_DOWNLOAD_FAIL;
349 icon = STATE_ICON_DOWNLOAD_FAIL;
354 message = STATE_NO_CONNECTION;
361 protected void AnimateIcon(WidgetAnimationBase animation)
369 m_Widgets.m_ProcessingSpinner.SetRotation(360);
380 protected void DisablePauserResume(SCR_ModularButtonComponent button)
382 m_bPauseEnabled =
false;
383 button.SetEnabled(
false);
385 GetGame().GetCallqueue().Remove(EnablePauserResume);
386 GetGame().GetCallqueue().CallLater(EnablePauserResume, PAUSE_ENABLE_DELAY_MS,
false, button);
389 m_OnUpdate.Invoke(
this);
393 protected void EnablePauserResume(SCR_ModularButtonComponent button)
395 m_bPauseEnabled =
true;
396 button.SetEnabled(
true);
399 m_OnUpdate.Invoke(
this);
405 UpdateProgressWidgets();
418 Print(
"Download manager entry state can't be update due to missing download action");
423 if (!action.IsCompleted() && !action.IsFailed() && !action.IsCanceled())
427 if (action.IsFailed() || action.IsCanceled())
431 if (action.IsCompleted() && !action.IsFailed() && !action.IsCanceled())
446 m_Action.m_OnChanged.Insert(OnActionChanged);
454 UpdateProgressWidgets(
true);
459 void CanDoActions(out
bool canPause, out
bool canResume, out
bool canCancel, out
bool canRetry)
473 if (m_Action.IsActive() && !m_Action.IsPaused())
476 UpdateProgressWidgets();
488 if (m_Action.IsPaused())
490 else if (m_Action.IsInactive())
493 UpdateProgressWidgets(
true);
505 UpdateProgressWidgets();
512 m_Action.RetryDownload();
515 UpdateProgressWidgets();
541 bool GetPauseEnabled()
543 return m_bPauseEnabled;