Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DownloadManager_AddonDownloadLine.c
Go to the documentation of this file.
1 
5 class SCR_DownloadManager_AddonDownloadLine : ScriptedWidgetComponent
6 {
7  // Icon setting
8  protected const string ICONICON_DOWNLOAD = "download";
9  protected const string ICON_UP = "up";
10  protected const string ICON_DOWN = "down";
11 
12  protected const Color ICON_COLORICON_DOWNLOAD = UIColors.CONTRAST_COLOR;
13  protected const Color ICON_COLOR_UP = UIColors.CONFIRM;
14  protected const Color ICON_COLOR_DOWN = UIColors.WARNING;
15 
16  protected const Color TEXT_SIZE_COLOR_DOWNLOAD = UIColors.CONTRAST_COLOR;
17  protected const Color TEXT_SIZE_COLOR_DOWNLOADED = Color.White;
18  protected const Color TEXT_SIZE_COLOR_ERROR = UIColors.WARNING;
19 
20  protected const string ICON_SIZE_DOWNLOAD = "download";
21  protected const string ICON_SIZE_UPDATE = "update";
22  protected const string ICON_SIZE_DOWNLOADED = "check";
23 
25  protected ref SCR_WorkshopItemActionDownload m_Action;
26  protected ref SCR_WorkshopItem m_Item;
27 
28  [Attribute("{3262679C50EF4F01}UI/Textures/Icons/icons_wrapperUI.imageset", UIWidgets.ResourcePickerThumbnail, "Imageset resource for icons", "imageset")]
29  protected ResourceName m_IconImageSet;
30 
31  bool m_bHideButtons;
32  protected bool m_bVersionChange = false;
33 
34  protected Widget m_wRoot;
35 
36  //------------------------------------------------------------------------------------------------
37  override void HandlerAttached(Widget w)
38  {
39  m_wRoot = w;
40 
41  m_Widgets.Init(w);
42 
43  m_Widgets.m_PauseResumeButtonComponent.m_OnClicked.Insert(OnPauseButton);
44  m_Widgets.m_CancelButtonComponent.m_OnClicked.Insert(OnCancelButton);
45  }
46 
47 
48  //------------------------------------------------------------------------------------------------
49  override void HandlerDeattached(Widget w)
50  {
51  GetGame().GetCallqueue().Remove(Update);
52  }
53 
54 
55  //------------------------------------------------------------------------------------------------
58  void InitForDownloadAction(SCR_WorkshopItemActionDownload action)
59  {
60  m_Action = action;
61  Update();
62  GetGame().GetCallqueue().CallLater(Update, 20, true);
63  }
64 
65 
66  //------------------------------------------------------------------------------------------------
68  void InitForCancelDownloadAction(SCR_WorkshopItemActionDownload action)
69  {
70  m_Action = action;
71  m_bHideButtons = true;
72 
73  Update();
74  GetGame().GetCallqueue().CallLater(Update, 20, true);
75  }
76 
77  //------------------------------------------------------------------------------------------------
79  void InitForServerDownloadAction(SCR_WorkshopItemActionDownload action)
80  {
81  m_Action = action;
82  m_bHideButtons = true;
83 
84  if (m_Widgets && m_Widgets.m_AddonSizeIcon)
85  m_Widgets.m_AddonSizeIcon.SetVisible(false);
86 
87  Update();
88  GetGame().GetCallqueue().CallLater(Update, 20, true);
89  }
90 
91 
92  //------------------------------------------------------------------------------------------------
94  void InitForServerBrowser(SCR_WorkshopItem item, Revision overrideTargetVersion = null, bool showVersionAndSize = true)
95  {
96  InitForWorkshopItem(item, overrideTargetVersion, showVersionAndSize);
97 
98  Revision versionFrom = item.GetCurrentLocalRevision();
99  Revision versionTo = overrideTargetVersion;
100  if (!versionTo)
101  versionTo = item.GetLatestRevision();
102 
103  if (!item.GetOffline()) //Missing
104  {
105  m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOAD);
106  m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLORICON_DOWNLOAD);
107  m_Widgets.m_AddonSizeIcon.LoadImageFromSet(0, m_IconImageSet, ICON_SIZE_DOWNLOAD);
108  }
109  else //Downloaded
110  {
111  if (versionFrom && !Revision.AreEqual(versionFrom, versionTo))
112  {
113  // Need version change
114  m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOAD);
115  m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLORICON_DOWNLOAD);
116  m_Widgets.m_AddonSizeIcon.LoadImageFromSet(0, m_IconImageSet, ICON_SIZE_UPDATE);
117  }
118  else
119  {
120  // Version match
121  m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOADED);
122  m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_UP);
123  m_Widgets.m_AddonSizeIcon.LoadImageFromSet(0, m_IconImageSet, ICON_SIZE_DOWNLOADED);
124 
125  // Display whole size
126  m_Widgets.m_AddonSizeText.SetText(SCR_ByteFormat.GetReadableSize(item.GetSizeBytes()));
127  }
128  }
129  }
130 
131  //------------------------------------------------------------------------------------------------
133  void InitForWorkshopItem(SCR_WorkshopItem item, Revision versionTo = null, bool showVersionAndSize = true)
134  {
135  m_Item = item;
136 
137  string addonName = item.GetName();
138  m_Widgets.m_AddonNameText.SetText(addonName);
139 
140  if (!item.GetRestricted())
141  {
142  m_Widgets.m_RightWidgetGroup.SetVisible(showVersionAndSize);
143 
144  if (showVersionAndSize)
145  {
146  Revision versionFrom = item.GetCurrentLocalRevision();
147  //Revision versionTo = overrideTargetVersion;
148  if (versionTo == null)
149  versionTo = item.GetLatestRevision();
150 
151 
152  float downloadSize = item.GetTargetRevisionPatchSize();
153 
154  bool showVersionFrom = versionFrom && !Revision.AreEqual(versionFrom, versionTo);
155  m_Widgets.m_VersionFromText.SetVisible(showVersionFrom);
156  m_Widgets.m_VersionArrow.SetVisible(showVersionFrom);
157  if (showVersionFrom)
158  m_Widgets.m_VersionFromText.SetText(versionFrom.GetVersion());
159 
160  if (versionTo)
161  m_Widgets.m_VersionToText.SetText(versionTo.GetVersion());
162 
163  string sizeStr = SCR_ByteFormat.GetReadableSize(downloadSize);
164  m_Widgets.m_AddonSizeText.SetText(sizeStr);
165 
166  // Display what action will be done icon
167  DisplayActionIcon(versionFrom, versionTo);
168 
169  // Check version change
170  if (versionFrom && !Revision.AreEqual(versionFrom, versionTo))
171  m_bVersionChange = true;
172  }
173  }
174  else
175  {
176  // The addon is somehow restricted
177  m_Widgets.m_RightWidgetGroup.SetVisible(false);
178 
179  string errorText = SCR_WorkshopUiCommon.GetRestrictedAddonStateText(item);
180  m_Widgets.m_ErrorText.SetVisible(true);
181  m_Widgets.m_ErrorText.SetText(errorText);
182  }
183  }
184 
185  //------------------------------------------------------------------------------------------------
187  void DisplayError(string msg, bool positive = false)
188  {
189  m_Widgets.m_ErrorText.SetText(msg);
190  m_Widgets.m_ErrorText.SetColor(ICON_COLOR_DOWN);
191  m_Widgets.m_ErrorText.SetVisible(true);
192 
193  // Green for positive
194  if (positive)
195  m_Widgets.m_ErrorText.SetColor(ICON_COLOR_UP);
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  SCR_WorkshopItem GetItem()
200  {
201  return m_Item;
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  Widget GetRootWidget()
206  {
207  return m_wRoot;
208  }
209 
210  //------------------------------------------------------------------------------------------------
211  SCR_WorkshopItemActionDownload GetDownloadAction()
212  {
213  return m_Action;
214  }
215 
216  //------------------------------------------------------------------------------------------------
217  protected void Update()
218  {
219  UpdateAllWidgets();
220  }
221 
222  //------------------------------------------------------------------------------------------------
224  protected void UpdateAllWidgets()
225  {
226  if (!m_Action)
227  return;
228 
229  // Name
230  m_Widgets.m_AddonNameText.SetText(m_Action.GetAddonName());
231 
232  // Version from
233  Revision versionFrom = m_Action.GetStartRevision();
234 
235  m_Widgets.m_VersionArrow.SetVisible(versionFrom != null);
236  m_Widgets.m_VersionFromText.SetVisible(versionFrom != null);
237 
238  if (versionFrom)
239  m_Widgets.m_VersionFromText.SetText(versionFrom.GetVersion());
240 
241  // Version to
242  Revision versionTo = m_Action.GetTargetRevision();
243  m_Widgets.m_VersionToText.SetVisible(versionTo != null);
244  if (versionTo)
245  m_Widgets.m_VersionToText.SetText(versionTo.GetVersion());
246 
247  // Progress text
248  if (m_Action.IsCompleted() || m_Action.IsFailed() || m_Action.IsCanceled())
249  {
250  m_Widgets.m_ProgressText.SetText(string.Empty);
251  }
252  else
253  {
254  float progress = m_Action.GetProgress();
255  string progressStr = string.Format("%1%%", Math.Round(progress * 100.0));
256  m_Widgets.m_ProgressText.SetText(progressStr);
257  }
258 
259  // Progress bar
260  if (m_Action.IsCompleted())
261  m_Widgets.m_ProgressBar.SetCurrent(1);
262  else if (m_Action.IsFailed() || m_Action.IsCanceled())
263  m_Widgets.m_ProgressBar.SetCurrent(0);
264  else
265  m_Widgets.m_ProgressBar.SetCurrent(m_Action.GetProgress());
266 
267  // Download size
268  float downloadSize = m_Action.GetSizeBytes();
269  string sizeStr = SCR_ByteFormat.GetReadableSize(downloadSize);
270  m_Widgets.m_AddonSizeText.SetText(sizeStr);
271 
272  if (m_Action.IsCompleted())
273  {
274  m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOADED);
275  }
276  else if (m_Action.IsFailed() || m_Action.IsCanceled())
277  {
278  m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_ERROR);
279  }
280  else
281  {
282  m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOAD);
283  }
284 
285  // Addon Size Icon
286  if (m_Action.IsCompleted())
287  {
288  m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_UP);
289  }
290  else if (m_Action.IsFailed() || m_Action.IsCanceled())
291  {
292  m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_DOWN);
293  }
294  else
295  {
296  m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLORICON_DOWNLOAD);
297  }
298 
299  // Buttons
300  if (m_bHideButtons)
301  {
302  m_Widgets.m_CancelButton.SetVisible(false);
303  m_Widgets.m_PauseResumeButton.SetVisible(false);
304  }
305  else
306  {
307  m_Widgets.m_PauseResumeButton.SetVisible(false);
308  m_Widgets.m_CancelButton.SetVisible(false);
309  if (!m_Action.IsCompleted() && !m_Action.IsFailed() && !m_Action.IsCanceled())
310  {
311  m_Widgets.m_PauseResumeButton.SetVisible(true);
312  m_Widgets.m_CancelButton.SetVisible(true);
313 
314  string pauseButtonMode = "running";
315  if (m_Action.IsPaused() || m_Action.IsInactive())
316  pauseButtonMode = "paused";
317 
318  m_Widgets.m_PauseResumeButtonComponent.SetEffectsWithAnyTagEnabled({"all", pauseButtonMode});
319  }
320  }
321 
322  // Icons when the download is over
323  if (m_Action.IsCompleted())
324  {
325  m_Widgets.m_DownloadFailedImage.SetVisible(false);
326  m_Widgets.m_DownloadFinishedImage.SetVisible(true);
327  }
328  else if (m_Action.IsFailed() || m_Action.IsCanceled())
329  {
330  m_Widgets.m_DownloadFailedImage.SetVisible(true);
331  m_Widgets.m_DownloadFinishedImage.SetVisible(false);
332  }
333  else
334  {
335  m_Widgets.m_DownloadFailedImage.SetVisible(false);
336  m_Widgets.m_DownloadFinishedImage.SetVisible(false);
337  }
338  }
339 
340 
341 
342  //------------------------------------------------------------------------------------------------
343  protected void OnPauseButton()
344  {
345  if (!m_Action)
346  return;
347 
348  if (m_Action.IsPaused())
349  m_Action.Resume();
350  else if (m_Action.IsInactive())
351  m_Action.Activate();
352  else
353  m_Action.Pause();
354  }
355 
356 
357 
358  //------------------------------------------------------------------------------------------------
359  protected void OnCancelButton()
360  {
361  if (!m_Action)
362  return;
363 
364  m_Action.Cancel();
365  }
366 
367  //------------------------------------------------------------------------------------------------
369  protected void DisplayActionIcon(Revision vFrom, Revision vTo)
370  {
371  ImageWidget wIcon = m_Widgets.m_AddonActionIcon;
372  if (!wIcon)
373  return;
374 
375  // Defaul to download
376  string imageName = ICONICON_DOWNLOAD;
377  Color color = ICON_COLORICON_DOWNLOAD;
378 
379  // Is there current verion?
380  if (vFrom)
381  {
382  int result = vFrom.CompareTo(vTo);
383 
384  if (result < 0)
385  {
386  imageName = ICON_UP;
387  color = ICON_COLOR_UP;
388  }
389  else if (result > 0)
390  {
391  imageName = ICON_DOWN;
392  color = ICON_COLOR_DOWN;
393  }
394  }
395 
396  // Setup action icon widget
397  wIcon.LoadImageFromSet(0, m_IconImageSet, imageName);
398  wIcon.SetColor(color);
399  }
400 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
m_Item
NewsFeedItem m_Item
Definition: SCR_NewsSubMenu.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_WorkshopItemActionDownload
Definition: SCR_WorkshopItemActionDownload.c:9
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
SCR_DownloadManager_AddonDownloadLineBaseWidgets
Definition: SCR_DownloadManager_AddonDownloadLineBaseWidgets.c:4
Attribute
typedef Attribute
Post-process effect of scripted camera.
UIColors
Definition: Constants.c:16
SCR_ByteFormat
Definition: SCR_ByteFormat.c:5
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
SCR_DownloadManager_AddonDownloadLine
Definition: SCR_DownloadManager_AddonDownloadLine.c:5