8 protected const string ICONICON_DOWNLOAD =
"download";
9 protected const string ICON_UP =
"up";
10 protected const string ICON_DOWN =
"down";
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;
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;
20 protected const string ICON_SIZE_DOWNLOAD =
"download";
21 protected const string ICON_SIZE_UPDATE =
"update";
22 protected const string ICON_SIZE_DOWNLOADED =
"check";
28 [
Attribute(
"{3262679C50EF4F01}UI/Textures/Icons/icons_wrapperUI.imageset", UIWidgets.ResourcePickerThumbnail,
"Imageset resource for icons",
"imageset")]
29 protected ResourceName m_IconImageSet;
32 protected bool m_bVersionChange =
false;
34 protected Widget m_wRoot;
37 override void HandlerAttached(Widget w)
43 m_Widgets.m_PauseResumeButtonComponent.m_OnClicked.Insert(OnPauseButton);
44 m_Widgets.m_CancelButtonComponent.m_OnClicked.Insert(OnCancelButton);
49 override void HandlerDeattached(Widget w)
51 GetGame().GetCallqueue().Remove(Update);
62 GetGame().GetCallqueue().CallLater(Update, 20,
true);
71 m_bHideButtons =
true;
74 GetGame().GetCallqueue().CallLater(Update, 20,
true);
82 m_bHideButtons =
true;
85 m_Widgets.m_AddonSizeIcon.SetVisible(
false);
88 GetGame().GetCallqueue().CallLater(Update, 20,
true);
94 void InitForServerBrowser(
SCR_WorkshopItem item, Revision overrideTargetVersion =
null,
bool showVersionAndSize =
true)
96 InitForWorkshopItem(item, overrideTargetVersion, showVersionAndSize);
98 Revision versionFrom = item.GetCurrentLocalRevision();
99 Revision versionTo = overrideTargetVersion;
101 versionTo = item.GetLatestRevision();
103 if (!item.GetOffline())
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);
111 if (versionFrom && !Revision.AreEqual(versionFrom, versionTo))
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);
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);
133 void InitForWorkshopItem(
SCR_WorkshopItem item, Revision versionTo =
null,
bool showVersionAndSize =
true)
137 string addonName = item.GetName();
138 m_Widgets.m_AddonNameText.SetText(addonName);
140 if (!item.GetRestricted())
142 m_Widgets.m_RightWidgetGroup.SetVisible(showVersionAndSize);
144 if (showVersionAndSize)
146 Revision versionFrom = item.GetCurrentLocalRevision();
148 if (versionTo ==
null)
149 versionTo = item.GetLatestRevision();
152 float downloadSize = item.GetTargetRevisionPatchSize();
154 bool showVersionFrom = versionFrom && !Revision.AreEqual(versionFrom, versionTo);
155 m_Widgets.m_VersionFromText.SetVisible(showVersionFrom);
156 m_Widgets.m_VersionArrow.SetVisible(showVersionFrom);
158 m_Widgets.m_VersionFromText.SetText(versionFrom.GetVersion());
161 m_Widgets.m_VersionToText.SetText(versionTo.GetVersion());
164 m_Widgets.m_AddonSizeText.SetText(sizeStr);
167 DisplayActionIcon(versionFrom, versionTo);
170 if (versionFrom && !Revision.AreEqual(versionFrom, versionTo))
171 m_bVersionChange =
true;
177 m_Widgets.m_RightWidgetGroup.SetVisible(
false);
181 m_Widgets.m_ErrorText.SetText(errorText);
187 void DisplayError(
string msg,
bool positive =
false)
190 m_Widgets.m_ErrorText.SetColor(ICON_COLOR_DOWN);
195 m_Widgets.m_ErrorText.SetColor(ICON_COLOR_UP);
205 Widget GetRootWidget()
217 protected void Update()
224 protected void UpdateAllWidgets()
230 m_Widgets.m_AddonNameText.SetText(m_Action.GetAddonName());
233 Revision versionFrom = m_Action.GetStartRevision();
235 m_Widgets.m_VersionArrow.SetVisible(versionFrom !=
null);
236 m_Widgets.m_VersionFromText.SetVisible(versionFrom !=
null);
239 m_Widgets.m_VersionFromText.SetText(versionFrom.GetVersion());
242 Revision versionTo = m_Action.GetTargetRevision();
243 m_Widgets.m_VersionToText.SetVisible(versionTo !=
null);
245 m_Widgets.m_VersionToText.SetText(versionTo.GetVersion());
248 if (m_Action.IsCompleted() || m_Action.IsFailed() || m_Action.IsCanceled())
250 m_Widgets.m_ProgressText.SetText(
string.Empty);
254 float progress = m_Action.GetProgress();
255 string progressStr =
string.Format(
"%1%%", Math.Round(progress * 100.0));
256 m_Widgets.m_ProgressText.SetText(progressStr);
260 if (m_Action.IsCompleted())
262 else if (m_Action.IsFailed() || m_Action.IsCanceled())
265 m_Widgets.m_ProgressBar.SetCurrent(m_Action.GetProgress());
268 float downloadSize = m_Action.GetSizeBytes();
270 m_Widgets.m_AddonSizeText.SetText(sizeStr);
272 if (m_Action.IsCompleted())
274 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOADED);
276 else if (m_Action.IsFailed() || m_Action.IsCanceled())
278 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_ERROR);
282 m_Widgets.m_AddonSizeText.SetColor(TEXT_SIZE_COLOR_DOWNLOAD);
286 if (m_Action.IsCompleted())
288 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_UP);
290 else if (m_Action.IsFailed() || m_Action.IsCanceled())
292 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLOR_DOWN);
296 m_Widgets.m_AddonSizeIcon.SetColor(ICON_COLORICON_DOWNLOAD);
302 m_Widgets.m_CancelButton.SetVisible(
false);
303 m_Widgets.m_PauseResumeButton.SetVisible(
false);
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())
311 m_Widgets.m_PauseResumeButton.SetVisible(
true);
312 m_Widgets.m_CancelButton.SetVisible(
true);
314 string pauseButtonMode =
"running";
315 if (m_Action.IsPaused() || m_Action.IsInactive())
316 pauseButtonMode =
"paused";
318 m_Widgets.m_PauseResumeButtonComponent.SetEffectsWithAnyTagEnabled({
"all", pauseButtonMode});
323 if (m_Action.IsCompleted())
325 m_Widgets.m_DownloadFailedImage.SetVisible(
false);
326 m_Widgets.m_DownloadFinishedImage.SetVisible(
true);
328 else if (m_Action.IsFailed() || m_Action.IsCanceled())
330 m_Widgets.m_DownloadFailedImage.SetVisible(
true);
331 m_Widgets.m_DownloadFinishedImage.SetVisible(
false);
335 m_Widgets.m_DownloadFailedImage.SetVisible(
false);
336 m_Widgets.m_DownloadFinishedImage.SetVisible(
false);
343 protected void OnPauseButton()
348 if (m_Action.IsPaused())
350 else if (m_Action.IsInactive())
359 protected void OnCancelButton()
369 protected void DisplayActionIcon(Revision vFrom, Revision vTo)
371 ImageWidget wIcon =
m_Widgets.m_AddonActionIcon;
376 string imageName = ICONICON_DOWNLOAD;
377 Color color = ICON_COLORICON_DOWNLOAD;
382 int result = vFrom.CompareTo(vTo);
387 color = ICON_COLOR_UP;
391 imageName = ICON_DOWN;
392 color = ICON_COLOR_DOWN;
397 wIcon.LoadImageFromSet(0, m_IconImageSet, imageName);
398 wIcon.SetColor(color);