Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AddonDetailsPanelComponent.c
Go to the documentation of this file.
1 /*
2 Panel which shows state of addon.
3 
4 !!! This component relies on SCR_WorkshopUiCommon to be initialized to work correctly.
5 */
6 
8 {
9  protected const int MAX_ADDON_TYPE_IMAGES = 12; // Max amount of addon type images will be shown.
10 
11  protected ref SCR_AddonInfoWidgets m_InfoWidgets = new SCR_AddonInfoWidgets();
12  protected ref SCR_WorkshopItem m_Item;
13  protected SCR_WorkshopItemBackendImageComponent m_BackendImageComponent;
14 
15  //------------------------------------------------------------------------------------------------
16  override void HandlerAttached(Widget w)
17  {
18  super.HandlerAttached(w);
19 
20  m_InfoWidgets.Init(m_CommonWidgets.m_wAdditionalInfo.GetChildren());
21 
22  m_BackendImageComponent = SCR_WorkshopItemBackendImageComponent.Cast(m_CommonWidgets.m_wBackendImage.FindHandler(SCR_WorkshopItemBackendImageComponent));
23 
24  UpdateAllWidgets();
25  }
26 
27  //------------------------------------------------------------------------------------------------
30  protected void UpdateAllWidgets()
31  {
32  // Don't mess up widgets in workbench
33  if (SCR_Global.IsEditMode())
34  return;
35 
37 
38  if (!m_Item)
39  {
40  m_CommonWidgets.m_WarningOverlayComponent.SetWarningVisible(false);
41  m_CommonWidgets.m_wMainArea.SetVisible(false);
42  m_BackendImageComponent.SetWorkshopItemAndImage(null, null);
43  return;
44  }
45 
46  m_CommonWidgets.m_wMainArea.SetVisible(true);
47 
48  // Rating
49  int rating = Math.Ceil(m_Item.GetAverageRating() * 100.0);
50  m_InfoWidgets.m_wModRating.SetText(WidgetManager.Translate("#AR-ValueUnit_Percentage", rating));
51 
52  // Name, description, author name
53  m_CommonWidgets.m_wNameText.SetText(m_Item.GetName());
54  m_CommonWidgets.m_wAuthorNameText.SetText(m_Item.GetAuthorName());
55  m_CommonWidgets.m_wDescriptionText.SetText(m_Item.GetSummary());
56 
57  // Size
58  float sizef = m_Item.GetSizeBytes();
59  string sizeStr = SCR_ByteFormat.GetReadableSize(sizef);
60  m_InfoWidgets.m_wModSize.SetText(sizeStr);
61 
62  // Version
63  Revision revisionCurrent = m_Item.GetCurrentLocalRevision();
64  Revision revisionLatest = m_Item.GetLatestRevision();
65 
66  bool needsUpdate = revisionCurrent && revisionLatest && !Revision.AreEqual(revisionCurrent, revisionLatest);
67 
68  m_InfoWidgets.m_wVersionUpdateHorizontalLayout.SetVisible(needsUpdate);
69 
70  // Version text
71  if (needsUpdate || !m_Item.GetOffline())
72  m_InfoWidgets.m_wCurrentVersion.SetColor(UIColors.NEUTRAL_ACTIVE_STANDBY);
73  else
74  m_InfoWidgets.m_wCurrentVersion.SetColor(UIColors.CONFIRM);
75 
76  string revision;
77  if (m_Item.GetOffline() && revisionCurrent)
78  revision = revisionCurrent.GetVersion();
79  else if (revisionLatest)
80  revision = revisionLatest.GetVersion();
81 
82  m_InfoWidgets.m_wCurrentVersion.SetText(SCR_WorkshopUiCommon.FormatVersion(revision));
83 
84  if (revisionLatest)
85  m_InfoWidgets.m_wUpdateVersion.SetText(SCR_WorkshopUiCommon.FormatVersion(revisionLatest.GetVersion()));
86 
87  // Version Icon
88  if (!m_Item.GetOffline())
89  {
90  m_InfoWidgets.m_wCurrentVersionIcon.SetColor(UIColors.NEUTRAL_ACTIVE_STANDBY);
91  m_InfoWidgets.m_wCurrentVersionIcon.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, "download");
92  }
93  else if (needsUpdate)
94  {
95  m_InfoWidgets.m_wCurrentVersionIcon.SetColor(UIColors.SLIGHT_WARNING);
96  m_InfoWidgets.m_wCurrentVersionIcon.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, "update");
97  }
98  else
99  {
100  m_InfoWidgets.m_wCurrentVersionIcon.SetColor(UIColors.CONFIRM);
101  m_InfoWidgets.m_wCurrentVersionIcon.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, "check");
102  }
103 
104  // Time since last downloaded
105  int timeSinceDownload = m_Item.GetTimeSinceFirstDownload();
106  m_InfoWidgets.m_wLastDownloadedHorizontalLayout.SetVisible(timeSinceDownload >= 0);
107 
108  if (timeSinceDownload >= 0)
109  m_InfoWidgets.m_wLastDownloaded.SetText(SCR_FormatHelper.GetTimeSinceEventImprecise(timeSinceDownload));
110 
111  // Types
112  array<WorkshopTag> tagObjects = {}; // Get tag objects from workshop item
113  m_Item.GetWorkshopItem().GetTags(tagObjects);
114 
115  foreach (WorkshopTag tag : tagObjects)
116  {
117  string image = SCR_WorkshopUiCommon.GetTagImage(tag.Name());
118  if (!image.IsEmpty())
119  AddTypeDisplay(image, UIConstants.ICONS_IMAGE_SET, UIConstants.ICONS_GLOW_IMAGE_SET);
120  }
121 
122  // Image
123  m_BackendImageComponent.SetWorkshopItemAndImage(m_Item, m_Item.GetThumbnail());
124 
125  // Dependencies and dependent
126  array<ref SCR_WorkshopItem> dependentAddons = SCR_AddonManager.SelectItemsBasic(m_Item.GetDependentAddons(), EWorkshopItemQuery.OFFLINE);
127  array<ref SCR_WorkshopItem> dependencies = m_Item.GetLatestDependencies();
128 
129  m_InfoWidgets.m_wDependenciesHorizontalLayout.SetVisible(!dependencies.IsEmpty());
130  m_InfoWidgets.m_wDependentHorizontalLayout.SetVisible(!dependentAddons.IsEmpty());
131 
132  if (!dependencies.IsEmpty())
133  {
134  if (dependencies.Count() == 1)
135  m_InfoWidgets.m_wDependencies.SetText("#AR-Workshop_Details_ModDependencies_Short_One_LC");
136  else
137  m_InfoWidgets.m_wDependencies.SetTextFormat("#AR-Workshop_Details_ModDependencies_Short_LC", dependencies.Count());
138  }
139 
140  if (!dependentAddons.IsEmpty())
141  {
142  if (dependentAddons.Count() == 1)
143  m_InfoWidgets.m_wDependent.SetText("#AR-Workshop_Details_DependentMods_Short_One_LC");
144  else
145  m_InfoWidgets.m_wDependent.SetTextFormat("#AR-Workshop_Details_DependentMods_Short_LC", dependentAddons.Count());
146  }
147 
148  // Error message
149  WorkshopItem item = m_Item.GetWorkshopItem();
150  ERevisionAvailability revAvailability = SCR_AddonManager.ItemAvailability(item);
151  bool localModError = revAvailability != SCR_ERevisionAvailability.ERA_AVAILABLE && revAvailability != SCR_ERevisionAvailability.ERA_UNKNOWN_AVAILABILITY;
152  float saturation = UIConstants.ENABLED_WIDGET_SATURATION;
153 
154  m_CommonWidgets.m_WarningOverlayComponent.SetWarningVisible(m_Item.GetRestricted() || localModError);
155 
156  if (m_Item.GetRestricted())
157  m_CommonWidgets.m_WarningOverlayComponent.SetWarning("#AR-Workshop_Dialog_Error_ModIsBlocked", "reportedByMe");
158  else
159  m_CommonWidgets.m_WarningOverlayComponent.SetWarning(SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorMessageVerbose(item), SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorTexture(item));
160 
161  if (localModError)
162  saturation = UIConstants.DISABLED_WIDGET_SATURATION;
163 
164  m_BackendImageComponent.SetImageSaturation(saturation);
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  override void HandlerDeattached(Widget w)
169  {
170  super.HandlerDeattached(w);
171 
172  if (m_Item)
173  m_Item.m_OnChanged.Remove(Callback_OnChanged);
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  protected void Callback_OnChanged()
178  {
179  UpdateAllWidgets();
180  }
181 
182  // --- Public ----
183  //------------------------------------------------------------------------------------------------
184  void SetWorkshopItem(SCR_WorkshopItem item)
185  {
186  if (m_Item)
187  m_Item.m_OnChanged.Remove(Callback_OnChanged);
188 
189  m_Item = item;
190 
191  if (m_Item)
192  m_Item.m_OnChanged.Insert(Callback_OnChanged);
193 
194  UpdateAllWidgets();
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  SCR_WorkshopItem GetItem()
199  {
200  return m_Item;
201  }
202 }
SCR_ERevisionAvailability
SCR_ERevisionAvailability
Definition: SCR_AddonManager.c:1090
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
SCR_ContentDetailsPanelBase
Definition: SCR_ContentDetailsPanelBase.c:1
m_Item
NewsFeedItem m_Item
Definition: SCR_NewsSubMenu.c:2
SCR_AddonInfoWidgets
Definition: SCR_AddonInfoWidgets.c:3
UIConstants
Definition: Constants.c:130
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
SCR_AddonDetailsPanelComponent
Definition: SCR_AddonDetailsPanelComponent.c:7
ClearTypeDisplays
protected void ClearTypeDisplays()
Definition: SCR_ContentDetailsPanelBase.c:104
UIColors
Definition: Constants.c:16
SCR_ByteFormat
Definition: SCR_ByteFormat.c:5
SCR_WorkshopItemBackendImageComponent
Same as SCR_BackendImageComponent, but implements default image based on tag of Workshop Item.
Definition: SCR_WorkshopUiCommon.c:1094
SCR_Global
Definition: Functions.c:6
SCR_AddonManager
Definition: SCR_AddonManager.c:72
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
m_CommonWidgets
protected ref SCR_ContentDetailsPanelBaseWidgets m_CommonWidgets
Definition: SCR_ContentDetailsPanelBase.c:2
AddTypeDisplay
protected Widget AddTypeDisplay(string image, ResourceName imageset, ResourceName glowImageset)
Definition: SCR_ContentDetailsPanelBase.c:85
EWorkshopItemQuery
EWorkshopItemQuery
Definition: SCR_AddonManager.c:34