Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DownloadConfirmationDialog.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  protected const ResourceName DOWNLOAD_LINE_LAYOUT = "{BB5AEDDA3C4134FD}UI/layouts/Menus/ContentBrowser/DownloadManager/DownloadManager_AddonDownloadLineConfirmation.layout";
6  protected ref SCR_WorkshopItem m_Item;
7  protected bool m_bDownloadMainItem;
8  protected ref array<ref SCR_WorkshopItem> m_aDependencies;
9  protected ref array<ref Revision> m_aDependencyVersions; // Array with specific versions of dependencies
10  protected bool m_bSubscribeToAddons; // When true, if user confirms the download, addons will be subscribed
12  protected ref array<ref SCR_WorkshopItemAction> m_aCreatedActions = {}; // Actions which were created when the user confirmed the action
13 
14  protected ref SCR_AddonPatchSizeLoader m_Loader = new SCR_AddonPatchSizeLoader();
15 
16  protected ref ScriptInvoker m_OnDownloadConfirmed; // (SCR_DownloadConfirmationDialog dlg)
17 
18  //------------------------------------------------------------------------------------------------
23  static SCR_DownloadConfirmationDialog CreateForAddonAndDependencies(notnull SCR_WorkshopItem mainItem, bool downloadMainItem, notnull array<ref SCR_WorkshopItem> dependencies, bool subscribeToAddons)
24  {
26 
27  dlg.m_bSubscribeToAddons = subscribeToAddons;
28  dlg.m_Item = mainItem;
29  dlg.m_bDownloadMainItem = downloadMainItem;
30  dlg.m_aDependencies = new array<ref SCR_WorkshopItem>;
31  foreach (auto i : dependencies)
32  dlg.m_aDependencies.Insert(i);
33 
34  SCR_ConfigurableDialogUi.CreateFromPreset(SCR_WorkshopUiCommon.DIALOGS_CONFIG, "download_confirmation", dlg);
35 
36  dlg.SetStyleDownloadAddonsWithDependencies();
37 
38  return dlg;
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  protected static void SetupDownloadDialogAddons(notnull out SCR_DownloadConfirmationDialog dialog, notnull array<ref Tuple2<SCR_WorkshopItem, ref Revision>> addonsAndVersions, bool subscribeToAddons)
43  {
44  dialog.m_bDownloadMainItem = false;
45  dialog.m_bSubscribeToAddons = subscribeToAddons;
46  dialog.m_aDependencies = new array<ref SCR_WorkshopItem>;
47  dialog.m_aDependencyVersions = new array<ref Revision>;
48 
49  foreach (Tuple2<SCR_WorkshopItem, ref Revision> i : addonsAndVersions)
50  {
51  dialog.m_aDependencies.Insert(i.param1);
52  dialog.m_aDependencyVersions.Insert(i.param2);
53  }
54  }
55 
56  //------------------------------------------------------------------------------------------------
58  static SCR_DownloadConfirmationDialog CreateForAddons(notnull array<ref Tuple2<SCR_WorkshopItem, ref Revision>> addonsAndVersions, bool subscribeToAddons)
59  {
61 
62  SetupDownloadDialogAddons(dlg, addonsAndVersions, subscribeToAddons);
63 
64  SCR_ConfigurableDialogUi.CreateFromPreset(SCR_WorkshopUiCommon.DIALOGS_CONFIG, "download_confirmation", dlg);
65 
66  dlg.SetStyleDownloadAddons();
67 
68  return dlg;
69  }
70 
71  //------------------------------------------------------------------------------------------------
72  override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
73  {
74  m_Widgets.Init(GetContentLayoutRoot(GetRootWidget()));
75 
76  // Update line of the main addon
77  m_Widgets.m_MainAddonSection.SetVisible(m_bDownloadMainItem);
78  if (m_Item != null && m_bDownloadMainItem)
79  {
80  m_Widgets.m_MainAddonLineComponent0.InitForWorkshopItem(m_Item);
81  }
82 
83  // Load patch size
84  OnAllPatchSizeLoaded(m_Loader, true);
85 
86  // Buttons
87  SCR_InputButtonComponent confirmButton = FindButton("confirm");
88  SCR_InputButtonComponent confirmAlternativeButton = FindButton("confirm2");
89 
90  if (confirmAlternativeButton)
91  confirmAlternativeButton.m_OnActivated.Insert(OnConfirmAlternative);
92 
93  if (m_aDependencies.IsEmpty())
94  {
95  // When we are downloading only one addon, 'download all' button becomes 'download'
96  if (confirmAlternativeButton)
97  confirmAlternativeButton.SetVisible(false);
98 
99  confirmButton.SetLabel("#AR-Workshop_Dialog_ConfirmDownload_ButtonDownload");
100  }
101  else if (!m_bDownloadMainItem)
102  {
103  // When we are not downloading the main addon, 'download one' button is hidden
104  if (confirmAlternativeButton)
105  confirmAlternativeButton.SetVisible(false);
106  }
107 
108  // Hide other optional text
109  m_Widgets.m_OtherAddonsMessage.SetVisible(false);
110  }
111 
112  //------------------------------------------------------------------------------------------------
113  protected void LoadAddonPatchSizes()
114  {
115  array<ref SCR_WorkshopItem> versionDifferences = SCR_AddonManager.SelectItemsAnd(
117  EWorkshopItemQuery.NOT_OFFLINE | EWorkshopItemQuery.NOT_LOCAL_VERSION_MATCH_DEPENDENCY);
118 
119  // Skip if there are no version differences
120  if (versionDifferences.IsEmpty())
121  {
122  OnAllPatchSizeLoaded(m_Loader, true);
123  return;
124  }
125 
126  // Setup loading
127  m_Loader.ClearItems();
128 
129  foreach (SCR_WorkshopItem item : versionDifferences)
130  {
131  Revision rev = item.GetDependency().GetRevision();
132  item.SetItemTargetRevision(rev);
133  m_Loader.InsertItem(item);
134  }
135 
136  m_Loader.GetOnAllPatchSizeLoaded().Insert(OnAllPatchSizeLoaded);
137  m_Loader.LoadPatchSizes();
138 
139  // Show loading overlay
140  m_Widgets.m_LoadingOverlayComponent.SetShown(true);
141  m_Widgets.m_AddonContentVertical.SetVisible(false);
142  }
143 
144  //------------------------------------------------------------------------------------------------
145  protected void OnAllPatchSizeLoaded(SCR_AddonPatchSizeLoader loader, bool allLoaded)
146  {
147  CreateAddonList();
148 
149  loader.GetOnAllPatchSizeLoaded().Remove(OnAllPatchSizeLoaded);
150 
151  // Hide loading overlay
152  m_Widgets.m_LoadingOverlayComponent.SetShown(false);
153  m_Widgets.m_AddonContentVertical.SetVisible(true);
154 
155  // Total download size - only visible if we have any dependencies
156  m_Widgets.m_SummarySection.SetVisible(!m_aDependencies.IsEmpty());
157  if (!m_aDependencies.IsEmpty())
158  {
159  float totalSize = SCR_DownloadManager.GetTotalSizeBytes(m_aDependencies, m_Item);
160  string totalSizeStr = SCR_ByteFormat.GetReadableSize(totalSize);
161  m_Widgets.m_TotalAddonSizeText.SetText(totalSizeStr);
162  }
163  }
164 
165  //------------------------------------------------------------------------------------------------
167  protected void CreateAddonWidget(notnull SCR_WorkshopItem dep, Widget listRoot)
168  {
169  Widget w = GetGame().GetWorkspace().CreateWidgets(DOWNLOAD_LINE_LAYOUT, listRoot);
171 
172  // Setup addon revision
173  Dependency dependency = dep.GetDependency();
174 
175  Revision revision = null;
176  if (dependency)
177  revision = dependency.GetRevision();
178 
179  //Revision revision = dep.GetDependency().GetRevision();
180  comp.InitForWorkshopItem(dep, revision);
181  }
182 
183  //------------------------------------------------------------------------------------------------
184  protected void CreateAddonList()
185  {
186  // Create lines for other addons
187  m_Widgets.m_OtherAddonsSection.SetVisible(!m_aDependencies.IsEmpty());
188  if (!m_aDependencies.IsEmpty())
189  {
190  // Not downloaded - not avaiable offline
191  array<ref SCR_WorkshopItem> missingAddons = SCR_AddonManager.SelectItemsBasic(m_aDependencies, EWorkshopItemQuery.NOT_OFFLINE);
192 
193  foreach (SCR_WorkshopItem missing : missingAddons)
194  {
195  CreateAddonWidget(missing, m_Widgets.m_OtherAddonsList);
196  }
197 
198  // Version difference
199  array<ref SCR_WorkshopItem> versionDifferences = SCR_AddonManager.SelectItemsAnd(
201  EWorkshopItemQuery.NOT_LOCAL_VERSION_MATCH_DEPENDENCY | EWorkshopItemQuery.OFFLINE);
202 
203  int vDifCount = versionDifferences.Count();
204  bool hasDifference = vDifCount > 0;
205 
206  // Display version difference widgets
207  m_Widgets.m_UpdateAddonsList.SetVisible(hasDifference);
208  m_Widgets.m_UpdateAddonsMessage.SetVisible(hasDifference);
209  m_Widgets.m_UpdateSpacer.SetVisible(hasDifference && missingAddons.IsEmpty());
210 
211  if (hasDifference)
212  {
213  // Create woidgets
214  foreach (SCR_WorkshopItem addon : versionDifferences)
215  {
216  CreateAddonWidget(addon, m_Widgets.m_UpdateAddonsList);
217  }
218 
219  // Version change text
220  m_Widgets.m_UpdateAddonsMessage.SetTextFormat("#AR-Workshop_Dialog_ConfirmDownload_VersionDifferences", vDifCount);
221  }
222  }
223  }
224 
227  //------------------------------------------------------------------------------------------------
229  void SetStyleDownloadAddonsWithDependencies()
230  {
231  if (!m_aDependencies.IsEmpty())
232  {
233  m_Widgets.m_OtherAddonsMessage.SetVisible(true);
234  m_Widgets.m_OtherAddonsMessage.SetTextFormat(
235  "#AR-Workshop_Dialog_ConfirmDownload_DependenciesWillBeDownloaded",
236  m_aDependencies.Count());
237  }
238  }
239 
240  //------------------------------------------------------------------------------------------------
242  void SetStyleDownloadAddons()
243  {
244  m_Widgets.m_OtherAddonsMessage.SetVisible(false);
245  }
246 
247  //------------------------------------------------------------------------------------------------
248  override void OnConfirm()
249  {
250  if (m_Item)
251  {
252  // If main item is provided, we (maybe) start downloading this item and its dependencies.
253  m_aCreatedActions = SCR_DownloadManager.GetInstance().DownloadLatestWithDependencies(m_Item, m_bDownloadMainItem, m_aDependencies);
254  }
255  else if (m_aDependencies != null)
256  {
257  // If main item was not provided, all the downloads are started separately.
258  for (int i = 0; i < m_aDependencies.Count(); i++)
259  {
261  if (dep.IsDownloadRunning())
262  continue;
263 
264  Revision targetVersion;
265  if (m_aDependencyVersions != null)
266  targetVersion = m_aDependencyVersions[i];
267 
269 
270  if (targetVersion) //why? it's never true
271  action = dep.Download(targetVersion);
272  else
273  action = dep.DownloadLatestVersion();
274 
275  if (action)
276  {
277  action.Activate();
278  m_aCreatedActions.Insert(action);
279  }
280  }
281  }
282 
283  // Subscription behavior
284  if (m_bSubscribeToAddons)
285  {
286  if (m_Item)
287  m_Item.SetSubscribed(true);
288 
289  foreach (SCR_WorkshopItem dependency : m_aDependencies)
290  {
291  dependency.SetSubscribed(true);
292  }
293  }
294 
295  super.OnConfirm();
296  }
297 
298  //------------------------------------------------------------------------------------------------
300  void OnConfirmAlternative()
301  {
302  m_aDependencies.Clear(); // Don't download any dependencies
303 
304  if (!m_Item)
305  return;
306 
307  m_aCreatedActions = SCR_DownloadManager.GetInstance().DownloadLatestWithDependencies(m_Item, true, m_aDependencies);
308 
309  if (m_bSubscribeToAddons)
310  {
311  if (m_Item)
312  m_Item.SetSubscribed(true);
313  }
314 
315  super.OnConfirm();
316  }
317 
318  //------------------------------------------------------------------------------------------------
320  array<ref SCR_WorkshopItemAction> GetActions()
321  {
322  array<ref SCR_WorkshopItemAction> a = {};
323 
324  foreach (SCR_WorkshopItemAction action : m_aCreatedActions)
325  {
326  a.Insert(action);
327  }
328 
329  return a;
330  }
331 }
SCR_AddonPatchSizeLoader
Definition: SCR_AddonPatchSizeLoader.c:9
DOWNLOAD_LINE_LAYOUT
const protected ResourceName DOWNLOAD_LINE_LAYOUT
Definition: SCR_WorkshopUiCommon.c:684
m_Item
NewsFeedItem m_Item
Definition: SCR_NewsSubMenu.c:2
SCR_DownloadConfirmationDialog
Dialog for confirming multiple downloads in workshop.
Definition: SCR_DownloadConfirmationDialog.c:3
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
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
m_aDependencies
protected ref array< ref SCR_WorkshopItem > m_aDependencies
Definition: SCR_ModDetailsSuperMenuComponent.c:10
SCR_ByteFormat
Definition: SCR_ByteFormat.c:5
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition: SCR_ConfigurableDialogUI.c:809
SCR_WorkshopItemAction
Definition: SCR_WorkshopItemAction.c:16
SCR_DownloadConfirmationDialogContentWidgets
Definition: SCR_DownloadConfirmationDialogContentWidgets.c:4
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SCR_AddonManager
Definition: SCR_AddonManager.c:72
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
SCR_DownloadManager
Definition: SCR_DownloadManager.c:20
FindButton
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
Definition: SCR_BrowserHoverTooltipComponent.c:116
SCR_DownloadManager_AddonDownloadLine
Definition: SCR_DownloadManager_AddonDownloadLine.c:5
EWorkshopItemQuery
EWorkshopItemQuery
Definition: SCR_AddonManager.c:34
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1