Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DownloadManager_AddonDownloadLine.c
Go to the documentation of this file.
1
4
5//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
6// Common problem in UI scripts: they do not inherit from the same parent. As a result there are a myriad duplicate methods and lines of code (eg. m_wRoot)
7
9{
10 // Icon setting
11 protected const string ICON_UP = "up";
12 protected const string ICON_DOWN = "down";
13
14 protected const Color ICON_COLOR_DOWNLOAD = UIColors.CONTRAST_COLOR;
15 protected const Color ICON_COLOR_UP = UIColors.CONFIRM;
16 protected const Color ICON_COLOR_DOWN = UIColors.WARNING;
17
18 protected const Color TEXT_SIZE_COLOR_DOWNLOAD = UIColors.CONTRAST_COLOR;
19 protected const Color TEXT_SIZE_COLOR_DOWNLOADED = UIColors.NEUTRAL_INFORMATION;
20 protected const Color TEXT_SIZE_COLOR_ERROR = UIColors.WARNING;
21
24 protected ref SCR_WorkshopItem m_Item;
25
26 [Attribute(UIConstants.ICONS_IMAGE_SET, UIWidgets.ResourcePickerThumbnail, "Imageset resource for icons", "imageset")]
28
30 protected bool m_bVersionChange = false;
31
32 protected Widget m_wRoot;
33
34 //------------------------------------------------------------------------------------------------
35 override void HandlerAttached(Widget w)
36 {
37 m_wRoot = w;
38
39 m_Widgets.Init(w);
40
41 m_Widgets.m_PauseResumeButtonComponent.m_OnClicked.Insert(OnPauseButton);
42 m_Widgets.m_CancelButtonComponent.m_OnClicked.Insert(OnCancelButton);
43 }
44
45 //---- REFACTOR NOTE END ----
46
47 //------------------------------------------------------------------------------------------------
48 override void HandlerDeattached(Widget w)
49 {
50 GetGame().GetCallqueue().Remove(Update);
51 }
52
53//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
54// Callqueue to perform continuous updates: this means a looping callqueue running for each one of these lines, and desyncronized updates (if other independent UIs display similar download progress visuals, they most likely rely on their own callqueues, so the progress bar/percentages will update at different times). This is a common issue in Workshop UI classes: they handle the same data but each one in their own sligtly different ways. Code was copy pasted all over the place, making the codebase extremely bloated and hard to mantain
55
56 //------------------------------------------------------------------------------------------------
60 {
61 m_Action = action;
62 Update();
63 GetGame().GetCallqueue().CallLater(Update, SCR_WorkshopUiCommon.CONTINUOUS_UPDATE_DELAY, true);
64 }
65
66
67 //------------------------------------------------------------------------------------------------
70 {
71 m_Action = action;
72 m_bHideButtons = true;
73
74 Update();
75 GetGame().GetCallqueue().CallLater(Update, SCR_WorkshopUiCommon.CONTINUOUS_UPDATE_DELAY, true);
76 }
77
78 //------------------------------------------------------------------------------------------------
81 {
82 m_Action = action;
83 m_bHideButtons = true;
84
85 if (m_Widgets && m_Widgets.m_AddonSizeIcon)
86 m_Widgets.m_AddonSizeIcon.SetVisible(false);
87
88 Update();
89 GetGame().GetCallqueue().CallLater(Update, SCR_WorkshopUiCommon.CONTINUOUS_UPDATE_DELAY, true);
90 }
91
92//---- REFACTOR NOTE END ----
93
94 //------------------------------------------------------------------------------------------------
96 void InitForServerBrowser(SCR_WorkshopItem item, Revision overrideTargetVersion = null, bool showVersionAndSize = true)
97 {
98 InitForWorkshopItem(item, overrideTargetVersion, showVersionAndSize);
99
100 Revision versionFrom = item.GetCurrentLocalRevision();
101 Revision versionTo = overrideTargetVersion;
102 if (!versionTo)
103 versionTo = item.GetLatestRevision();
104
105 if (!item.GetOffline()) //Missing
106 {
107 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOAD);
108 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_DOWNLOAD);
109 m_Widgets.m_AddonSizeIcon.LoadImageFromSet(0, m_IconImageSet, SCR_WorkshopUiCommon.ICON_DOWNLOAD);
110 }
111 else //Downloaded
112 {
113 if (versionFrom && !Revision.AreEqual(versionFrom, versionTo))
114 {
115 // Need version change
116 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOAD);
117 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_DOWNLOAD);
118 m_Widgets.m_AddonSizeIcon.LoadImageFromSet(0, m_IconImageSet, SCR_WorkshopUiCommon.ICON_UPDATE);
119 }
120 else
121 {
122 // Version match
123 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOADED);
124 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_UP);
125 m_Widgets.m_AddonSizeIcon.LoadImageFromSet(0, m_IconImageSet, UIConstants.ICON_CHECK);
126
127 // Display whole size
128 m_Widgets.m_AddonSizeText.SetText(SCR_ByteFormat.GetReadableSize(item.GetSizeBytes()));
129 }
130 }
131 }
132
133 //------------------------------------------------------------------------------------------------
135 void InitForWorkshopItem(SCR_WorkshopItem item, Revision versionTo = null, bool showVersionAndSize = true)
136 {
137 m_Item = item;
138
139 string addonName = item.GetName();
140 m_Widgets.m_AddonNameText.SetText(addonName);
141
142 if (!item.GetRestricted())
143 {
144 m_Widgets.m_RightWidgetGroup.SetVisible(showVersionAndSize);
145
146 if (showVersionAndSize)
147 {
148 Revision versionFrom = item.GetCurrentLocalRevision();
149 //Revision versionTo = overrideTargetVersion;
150 if (versionTo == null)
151 versionTo = item.GetLatestRevision();
152
153
154 float downloadSize = item.GetTargetRevisionPatchSize();
155
156 bool showVersionFrom = versionFrom && !Revision.AreEqual(versionFrom, versionTo);
157 m_Widgets.m_VersionFromText.SetVisible(showVersionFrom);
158 m_Widgets.m_VersionArrow.SetVisible(showVersionFrom);
159 if (showVersionFrom)
160 m_Widgets.m_VersionFromText.SetText(versionFrom.GetVersion());
161
162 if (versionTo)
163 m_Widgets.m_VersionToText.SetText(versionTo.GetVersion());
164
165 string sizeStr = SCR_ByteFormat.GetReadableSize(downloadSize);
166 m_Widgets.m_AddonSizeText.SetText(sizeStr);
167
168 // Display what action will be done icon
169 DisplayActionIcon(versionFrom, versionTo);
170
171 // Check version change
172 if (versionFrom && !Revision.AreEqual(versionFrom, versionTo))
173 m_bVersionChange = true;
174 }
175 }
176 else
177 {
178 // The addon is somehow restricted
179 m_Widgets.m_RightWidgetGroup.SetVisible(false);
180
181 string errorText = SCR_WorkshopUiCommon.GetRestrictedAddonStateText(item);
182 m_Widgets.m_ErrorText.SetVisible(true);
183 m_Widgets.m_ErrorText.SetText(errorText);
184 }
185 }
186
187 //------------------------------------------------------------------------------------------------
189 void DisplayError(string msg, bool positive = false)
190 {
191 m_Widgets.m_ErrorText.SetText(msg);
192 m_Widgets.m_ErrorText.SetColor(ICON_COLOR_DOWN);
193 m_Widgets.m_ErrorText.SetVisible(true);
194
195 // Green for positive
196 if (positive)
197 m_Widgets.m_ErrorText.SetColor(ICON_COLOR_UP);
198 }
199
200 //------------------------------------------------------------------------------------------------
202 {
203 return m_Item;
204 }
205
206 //------------------------------------------------------------------------------------------------
208 {
209 return m_wRoot;
210 }
211
212 //------------------------------------------------------------------------------------------------
217
218 //------------------------------------------------------------------------------------------------
219 protected void Update()
220 {
222 }
223
224 //------------------------------------------------------------------------------------------------
226 protected void UpdateAllWidgets()
227 {
228 if (!m_Action)
229 return;
230
231 // Name
232 m_Widgets.m_AddonNameText.SetText(m_Action.GetAddonName());
233
234 // Version from
235 Revision versionFrom = m_Action.GetStartRevision();
236
237 m_Widgets.m_VersionArrow.SetVisible(versionFrom != null);
238 m_Widgets.m_VersionFromText.SetVisible(versionFrom != null);
239
240 if (versionFrom)
241 m_Widgets.m_VersionFromText.SetText(versionFrom.GetVersion());
242
243 // Version to
244 Revision versionTo = m_Action.GetTargetRevision();
245 m_Widgets.m_VersionToText.SetVisible(versionTo != null);
246 if (versionTo)
247 m_Widgets.m_VersionToText.SetText(versionTo.GetVersion());
248
249 // Progress text
250 if (m_Action.IsCompleted() || m_Action.IsFailed() || m_Action.IsCanceled())
251 m_Widgets.m_ProgressText.SetText(string.Empty);
252 else
253 m_Widgets.m_ProgressText.SetText(UIConstants.FormatUnitPercentage(SCR_WorkshopUiCommon.GetDownloadProgressPercentage(m_Action.GetProgress())));
254
255 // Progress bar
256 if (m_Action.IsCompleted())
257 m_Widgets.m_ProgressBar.SetCurrent(1);
258 else if (m_Action.IsFailed() || m_Action.IsCanceled())
259 m_Widgets.m_ProgressBar.SetCurrent(0);
260 else
261 m_Widgets.m_ProgressBar.SetCurrent(m_Action.GetProgress());
262
263 // Download size
264 float downloadSize = m_Action.GetSizeBytes();
265 string sizeStr = SCR_ByteFormat.GetReadableSize(downloadSize);
266 m_Widgets.m_AddonSizeText.SetText(sizeStr);
267
268 if (m_Action.IsCompleted())
269 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOADED);
270 else if (m_Action.IsFailed() || m_Action.IsCanceled())
271 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_ERROR);
272 else
273 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOAD);
274
275 // Addon Size Icon
276 if (m_Action.IsCompleted())
277 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_UP);
278 else if (m_Action.IsFailed() || m_Action.IsCanceled())
279 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_DOWN);
280 else
281 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_DOWNLOAD);
282
283 // Buttons
284 if (m_bHideButtons)
285 {
286 m_Widgets.m_CancelButton.SetVisible(false);
287 m_Widgets.m_PauseResumeButton.SetVisible(false);
288 }
289 else
290 {
291 m_Widgets.m_PauseResumeButton.SetVisible(false);
292 m_Widgets.m_CancelButton.SetVisible(false);
293 if (!m_Action.IsCompleted() && !m_Action.IsFailed() && !m_Action.IsCanceled())
294 {
295 m_Widgets.m_PauseResumeButton.SetVisible(true);
296 m_Widgets.m_CancelButton.SetVisible(true);
297
298 string pauseButtonMode = "running";
299 if (m_Action.IsPaused() || m_Action.IsInactive())
300 pauseButtonMode = "paused";
301
302 m_Widgets.m_PauseResumeButtonComponent.SetEffectsWithAnyTagEnabled({"all", pauseButtonMode});
303 }
304 }
305
306 // Icons when the download is over
307 if (m_Action.IsCompleted())
308 {
309 m_Widgets.m_DownloadFailedImage.SetVisible(false);
310 m_Widgets.m_DownloadFinishedImage.SetVisible(true);
311 }
312 else if (m_Action.IsFailed() || m_Action.IsCanceled())
313 {
314 m_Widgets.m_DownloadFailedImage.SetVisible(true);
315 m_Widgets.m_DownloadFinishedImage.SetVisible(false);
316 }
317 else
318 {
319 m_Widgets.m_DownloadFailedImage.SetVisible(false);
320 m_Widgets.m_DownloadFinishedImage.SetVisible(false);
321 }
322 }
323
324 //------------------------------------------------------------------------------------------------
325 protected void OnPauseButton()
326 {
327 if (!m_Action)
328 return;
329
330 if (m_Action.IsPaused())
331 m_Action.Resume();
332 else if (m_Action.IsInactive())
333 m_Action.Activate();
334 else
335 m_Action.Pause();
336 }
337
338
339
340 //------------------------------------------------------------------------------------------------
341 protected void OnCancelButton()
342 {
343 if (!m_Action)
344 return;
345
346 m_Action.Cancel();
347 }
348
349 //------------------------------------------------------------------------------------------------
351 protected void DisplayActionIcon(Revision vFrom, Revision vTo)
352 {
353 ImageWidget wIcon = m_Widgets.m_AddonActionIcon;
354 if (!wIcon)
355 return;
356
357 // Defaul to download
358 string imageName = SCR_WorkshopUiCommon.ICON_DOWNLOAD;
360
361 // Is there current verion?
362 if (vFrom)
363 {
364 int result = vFrom.CompareTo(vTo);
365
366 if (result < 0)
367 {
368 imageName = ICON_UP;
369 color = ICON_COLOR_UP;
370 }
371 else if (result > 0)
372 {
373 imageName = ICON_DOWN;
374 color = ICON_COLOR_DOWN;
375 }
376 }
377
378 // Setup action icon widget
379 wIcon.LoadImageFromSet(0, m_IconImageSet, imageName);
380 wIcon.SetColor(color);
381 }
382};
ArmaReforgerScripted GetGame()
Definition game.c:1398
Definition Color.c:13
void InitForWorkshopItem(SCR_WorkshopItem item, Revision versionTo=null, bool showVersionAndSize=true)
Initializes the line in passive mode. It will just show basic information once.
void InitForDownloadAction(SCR_WorkshopItemActionDownload action)
void InitForServerBrowser(SCR_WorkshopItem item, Revision overrideTargetVersion=null, bool showVersionAndSize=true)
Initializes the line in non-interactive mode, shows basic data about a download.
void InitForCancelDownloadAction(SCR_WorkshopItemActionDownload action)
Initializes the line in non-interactive mode, shows basic data about a download which is already runn...
void InitForServerDownloadAction(SCR_WorkshopItemActionDownload action)
Initializes the line in non-interactive mode, shows basic data about a download relating to joining s...
void DisplayActionIcon(Revision vFrom, Revision vTo)
Display icon with action that need to done - download, update, downgrade.
void DisplayError(string msg, bool positive=false)
Display error massage, based on positivity message is green or red.
ref SCR_DownloadManager_AddonDownloadLineBaseWidgets m_Widgets
void UpdateAllWidgets()
Updates all widgets. Only relevant in the mode InitForDownloadAction.
Revision GetCurrentLocalRevision()
Returns the revision which we currently have on the local storage.
Revision GetLatestRevision()
bool GetOffline()
True when we have the item on our local storage.
float GetTargetRevisionPatchSize()
bool GetRestricted()
Returns true when item is restricted for any reason (blocked or reported).
static string GetRestrictedAddonStateText(SCR_WorkshopItem item)
Returns string such as "Banned" or "Reported" for a restricted item. Otherwise returns empty string.
static int GetDownloadProgressPercentage(float progress)
SCR_FieldOfViewSettings Attribute