12 protected bool m_bFocused;
13 protected bool m_bUpdatingContinuously;
22 protected SCR_EWorkshopTileErrorState m_eErrorState;
23 protected SCR_EWorkshopTileActionState m_eMainActionState;
25 protected const int CONTINUOUS_UPDATE_DELAY = 1000;
26 protected const string MAIN_ACTION_MESSAGE_DECORATION =
"[%1]";
29 override void HandlerAttached(Widget w)
31 super.HandlerAttached(w);
38 m_Widgets.m_EnableAddonButtonComponent.m_OnToggled.Insert(OnEnableButtonToggled);
39 m_Widgets.m_FavouriteButtonComponent0.m_OnToggled.Insert(OnFavouriteButtonToggled);
41 Widget backendImage =
m_wRoot.FindAnyWidget(
"m_BackendImage");
45 UpdateWarningOverlay();
46 m_Widgets.m_WarningOverlayComponent.GetOnWarningIconButtonClicked().Insert(OnWarningButtonClicked);
49 m_Widgets.m_MainActionButtonComponent0.m_OnClicked.Insert(OnMainActionButtonClicked);
54 downloadManager.m_OnNewDownload.Insert(OnAnyNewDownload);
55 downloadManager.m_OnDownloadFailed.Insert(OnAnyDownloadError);
56 downloadManager.m_OnDownloadCanceled.Insert(OnAnyDownloadCompleted);
57 downloadManager.m_OnDownloadComplete.Insert(OnAnyDownloadCompleted);
62 override void HandlerDeattached(Widget w)
69 downloadManager.m_OnNewDownload.Remove(OnAnyNewDownload);
70 downloadManager.m_OnDownloadFailed.Remove(OnAnyDownloadError);
71 downloadManager.m_OnDownloadCanceled.Remove(OnAnyDownloadCompleted);
72 downloadManager.m_OnDownloadComplete.Remove(OnAnyDownloadCompleted);
75 StopContinuousUpdate();
77 super.HandlerDeattached(w);
81 override bool OnFocus(Widget w,
int x,
int y)
86 UpdateFavouriteButton();
87 UpdateNamesScrolling();
93 return super.OnFocus(w, x, y);
97 override bool OnFocusLost(Widget w,
int x,
int y)
101 UpdateFavouriteButton();
102 UpdateNamesScrolling();
108 return super.OnFocusLost(w, x, y);
113 protected void UpdateStateFlags()
120 WorkshopItem item =
m_Item.GetWorkshopItem();
123 m_eRevisionAvailability = addonManager.ItemAvailability(item);
129 if (
m_Item.GetDownloadAction() ||
m_Item.GetDependencyCompositeAction())
130 m_eMainActionState = SCR_EWorkshopTileActionState.DOWNLOADING;
135 case EWorkshopItemProblem.UPDATE_AVAILABLE: m_eMainActionState = SCR_EWorkshopTileActionState.UPDATE;
break;
136 case EWorkshopItemProblem.DEPENDENCY_MISSING: m_eMainActionState = SCR_EWorkshopTileActionState.DEPENDENCIES_DOWNLOAD;
break;
137 case EWorkshopItemProblem.DEPENDENCY_OUTDATED: m_eMainActionState = SCR_EWorkshopTileActionState.DEPENDENCIES_UPDATE;
break;
138 case EWorkshopItemProblem.DEPENDENCY_DISABLED: m_eMainActionState = SCR_EWorkshopTileActionState.DEPENDENCIES_ENABLE;
break;
141 else if (!
m_Item.GetOffline())
142 m_eMainActionState = SCR_EWorkshopTileActionState.DOWNLOAD;
144 m_eMainActionState = SCR_EWorkshopTileActionState.DOWNLOADED;
147 if (
m_Item.GetRestricted())
148 m_eErrorState = SCR_EWorkshopTileErrorState.RESTRICTED;
150 m_eErrorState = SCR_EWorkshopTileErrorState.REVISION_AVAILABILITY_ISSUE;
152 m_eErrorState = SCR_EWorkshopTileErrorState.DEPENDENCIES_ISSUE;
154 m_eErrorState = SCR_EWorkshopTileErrorState.NONE;
158 protected void UpdateNames()
161 m_Widgets.m_wAddonAuthor.SetText(WidgetManager.Translate(
"#AR-Workshop_AddonAuthorPrefix",
m_Item.GetAuthorName()));
165 protected void UpdateNamesScrolling()
169 if (!
m_Widgets.m_FrameNameComponent.GetContentFit())
170 m_Widgets.m_FrameNameComponent.AnimationStart();
172 if (!
m_Widgets.m_FrameAuthorComponent.GetContentFit())
173 m_Widgets.m_FrameAuthorComponent.AnimationStart();
177 m_Widgets.m_FrameNameComponent.AnimationStop();
178 m_Widgets.m_FrameNameComponent.ResetPosition();
180 m_Widgets.m_FrameAuthorComponent.AnimationStop();
181 m_Widgets.m_FrameAuthorComponent.ResetPosition();
188 protected void UpdateRating()
190 m_Widgets.m_wRating.SetVisible(m_eErrorState != SCR_EWorkshopTileErrorState.RESTRICTED);
194 int rating = Math.Ceil(100 *
m_Item.GetAverageRating());
195 m_Widgets.m_RatingComponent1.SetTitle(WidgetManager.Translate(
"#AR-ValueUnit_Percentage", rating));
199 protected void UpdateImage()
201 if (!m_BackendImageComponent)
204 m_BackendImageComponent.SetWorkshopItemAndImage(
m_Item,
m_Item.GetThumbnail());
208 protected void UpdateDependencyCountWidgets()
213 bool offline =
m_Item.GetOffline();
219 m_Widgets.m_wDependent.SetVisible(nDependent > 0);
220 m_Widgets.m_wDependencies.SetVisible(nDependencies > 0);
222 m_Widgets.m_DependentComponent1.SetTitle(Math.ClampInt(nDependent, 0, 999).ToString());
223 m_Widgets.m_DependenciesComponent1.SetTitle(Math.ClampInt(nDependencies, 0, 999).ToString());
227 protected void UpdateDownloadProgressBar()
231 if (
m_Item && m_eMainActionState == SCR_EWorkshopTileActionState.DOWNLOADING)
232 progress = GetDownloadProgress();
234 m_Widgets.m_wDownloadProgressBar.SetCurrent(progress);
235 m_Widgets.m_wDownloadProgressBarOverlay.SetVisible(progress > 0);
240 protected float GetDownloadProgress()
246 protected void UpdateEnableButton()
248 m_Widgets.m_EnableAddonButtonComponent.SetVisible(
m_Item.GetOffline());
249 m_Widgets.m_EnableAddonButtonComponent.SetToggled(
m_Item.GetEnabled(),
false);
254 m_Widgets.m_EnableAddonButtonComponent.SetEnabled(m_eMainActionState != SCR_EWorkshopTileActionState.DOWNLOADING);
256 string enableButtonMode =
"no_problems";
257 if (m_eMainActionState == SCR_EWorkshopTileActionState.DEPENDENCIES_DOWNLOAD || m_eMainActionState == SCR_EWorkshopTileActionState.DEPENDENCIES_ENABLE)
258 enableButtonMode =
"problems";
260 m_Widgets.m_EnableAddonButtonComponent.SetEffectsWithAnyTagEnabled({
"all", enableButtonMode});
264 protected void UpdateFavouriteButton()
269 m_Widgets.m_FavouriteButtonComponent0.SetToggled(
m_Item.GetFavourite(),
false);
270 m_Widgets.m_FavouriteButtonComponent0.SetVisible((m_bFocused ||
m_Item.GetFavourite()) && m_eErrorState != SCR_EWorkshopTileErrorState.RESTRICTED);
274 protected void ShowBackendEnv()
276 string gameEnv =
GetGame().GetBackendApi().GetBackendEnv();
277 string modEnv =
m_Item.GetWorkshopItem().GetBackendEnv();
279 bool display = (modEnv !=
"local") && (modEnv !=
"ask") && (modEnv !=
"invalid");
280 bool envMatch = gameEnv == modEnv;
282 m_Widgets.m_wBackendSource.SetVisible(display && !envMatch);
286 m_Widgets.m_BackendSourceComponent1.SetTitle(modEnv);
295 protected void UpdateWarningOverlay()
298 if (!
m_Item || m_eErrorState == SCR_EWorkshopTileErrorState.NONE)
300 m_Widgets.m_WarningOverlayComponent.SetWarningVisible(
false);
302 if (m_BackendImageComponent)
303 m_BackendImageComponent.SetImageSaturation(
UIConstants.ENABLED_WIDGET_SATURATION);
309 m_Widgets.m_WarningOverlayComponent.SetWarningVisible(
true);
311 if (m_BackendImageComponent)
312 m_BackendImageComponent.SetImageSaturation(
UIConstants.DISABLED_WIDGET_SATURATION);
315 switch (m_eErrorState)
317 case SCR_EWorkshopTileErrorState.RESTRICTED:
319 m_Widgets.m_WarningOverlayComponent.SetWarning(
"#AR-Workshop_State_Restricted",
"reportedByMe");
323 case SCR_EWorkshopTileErrorState.DEPENDENCIES_ISSUE:
325 m_Widgets.m_WarningOverlayComponent.SetWarning(
"#AR-Workshop_State_MissingDependencies",
"dependencies");
329 case SCR_EWorkshopTileErrorState.REVISION_AVAILABILITY_ISSUE:
331 m_Widgets.m_WarningOverlayComponent.SetWarning(
341 protected void UpdateHeader()
346 m_Widgets.m_wMainActionButton.SetVisible(
347 (m_bFocused || (m_eMainActionState != SCR_EWorkshopTileActionState.DOWNLOAD)) &&
348 m_eMainActionState != SCR_EWorkshopTileActionState.DOWNLOADED &&
349 m_eErrorState != SCR_EWorkshopTileErrorState.RESTRICTED
352 if (!
m_Widgets.m_wMainActionButton.IsVisible())
366 switch (m_eMainActionState)
368 case SCR_EWorkshopTileActionState.DOWNLOAD:
370 iconColor.m_cDefault =
UIColors.IDLE_ACTIVE;
374 message =
string.Format(MAIN_ACTION_MESSAGE_DECORATION, message);
376 messageColor.m_cDefault =
UIColors.IDLE_ACTIVE;
380 case SCR_EWorkshopTileActionState.DOWNLOADING:
382 iconColor.m_cDefault =
UIColors.CONTRAST_COLOR;
383 icon =
"downloading";
385 string percentage = WidgetManager.Translate(
"#AR-ValueUnit_Percentage", Math.Round(100.0 * GetDownloadProgress()));
386 string label =
"#AR-DownloadManager_State_Downloading";
387 message = WidgetManager.Translate(
"%1 %2", label, percentage);
389 messageColor.m_cDefault =
UIColors.NEUTRAL_INFORMATION;
393 case SCR_EWorkshopTileActionState.UPDATE:
397 iconColor.m_cDefault =
UIColors.SLIGHT_WARNING;
398 messageColor.m_cDefault =
UIColors.IDLE_ACTIVE;
402 iconColor.m_cDefault =
UIColors.WARNING;
403 messageColor.m_cDefault =
UIColors.WARNING;
412 case SCR_EWorkshopTileActionState.DEPENDENCIES_UPDATE:
414 iconColor.m_cDefault =
UIColors.SLIGHT_WARNING;
417 messageColor.m_cDefault =
UIColors.IDLE_ACTIVE;
421 case SCR_EWorkshopTileActionState.DEPENDENCIES_DOWNLOAD:
423 iconColor.m_cDefault =
UIColors.SLIGHT_WARNING;
426 messageColor.m_cDefault =
UIColors.IDLE_ACTIVE;
430 case SCR_EWorkshopTileActionState.DEPENDENCIES_ENABLE:
432 iconColor.m_cDefault =
UIColors.SLIGHT_WARNING;
433 icon =
"repairCircle";
435 messageColor.m_cDefault =
UIColors.IDLE_ACTIVE;
440 m_Widgets.m_MainActionButtonComponent0.InvokeAllEnabledEffects(
false);
441 m_Widgets.m_MainActionButtonComponent1.SetImage(icon);
442 m_Widgets.m_wMainActionText.SetText(message);
446 protected void UpdateAllWidgets()
458 HandleDownloadChanges();
462 UpdateNamesScrolling();
466 UpdateEnableButton();
467 UpdateFavouriteButton();
468 UpdateDependencyCountWidgets();
472 protected void HandleDownloadChanges()
476 UpdateDownloadProgressBar();
477 UpdateWarningOverlay();
480 if (
m_Item && m_eMainActionState == SCR_EWorkshopTileActionState.DOWNLOADING)
481 StartContinuousUpdate();
483 StopContinuousUpdate();
487 protected void StartContinuousUpdate()
489 if (m_bUpdatingContinuously || !
m_Item)
492 GetGame().GetCallqueue().CallLater(ContinuousUpdate, CONTINUOUS_UPDATE_DELAY,
true);
494 m_bUpdatingContinuously =
true;
498 protected void StopContinuousUpdate()
500 if (m_bUpdatingContinuously)
501 GetGame().GetCallqueue().Remove(ContinuousUpdate);
503 m_bUpdatingContinuously =
false;
507 protected void ContinuousUpdate()
509 if (!
m_Item || m_eMainActionState != SCR_EWorkshopTileActionState.DOWNLOADING)
510 StopContinuousUpdate();
512 UpdateDownloadProgressBar();
517 protected void OnEnableButtonToggled(SCR_ModularButtonComponent comp)
523 protected void OnFavouriteButtonToggled(SCR_ModularButtonComponent comp,
bool toggled)
528 m_Item.SetFavourite(toggled);
538 protected void OnMainActionButtonClicked(SCR_ModularButtonComponent comp)
554 HandleDownloadChanges();
560 HandleDownloadChanges();
566 HandleDownloadChanges();
571 protected void OnTooltipShow(
SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset,
string tag)
573 if (!
m_Item || !tooltipWidget)
576 array<ref SCR_WorkshopItem> addons = {};
602 m_Item.m_OnChanged.Remove(OnWorkshopItemChange);
609 m_Item.m_OnChanged.Insert(OnWorkshopItemChange);
615 m_Widgets.m_EnableAddonButtonComponent.InvokeAllEnabledEffects(
true);
638 enum SCR_EWorkshopTileErrorState
647 enum SCR_EWorkshopTileActionState