Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WorkshopDownloadSequence.c
Go to the documentation of this file.
1 
10 {
11  protected static float LOADING_DELAY = 500;
12 
13  protected ref SCR_WorkshopItem m_Item;
14  protected ref Revision m_ItemTargetRevision;
15 
16  protected SCR_LoadingOverlayDialog m_LoadingOverlay;
17 
18  protected ref ScriptInvoker<> m_OnDownloadConfirmDisplayed = new ScriptInvoker<>();
19 
20  //------------------------------------------------------------------------------------------------
21  ScriptInvoker GetOnDownloadConfirmDisplayed()
22  {
23  return m_OnDownloadConfirmDisplayed;
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  // Public
28  //------------------------------------------------------------------------------------------------
29 
30  //------------------------------------------------------------------------------------------------
32  static SCR_WorkshopDownloadSequence Create(SCR_WorkshopItem item, Revision itemTargetRevision, SCR_WorkshopDownloadSequence previous)
33  {
34  if (previous && previous.m_bWaitingResponse)
35  return previous;
36 
37  SCR_WorkshopDownloadSequence sq = new SCR_WorkshopDownloadSequence(null, item, itemTargetRevision);
38 
39  return sq;
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  protected void CreateLoadingOverlay()
44  {
45  // Skip if already loaded
46  if (!m_bWaitingResponse)
47  return;
48 
49  // Show only if we are still waiting for data
51  m_LoadingOverlay.m_OnCloseStarted.Insert(Cancel); // Cancel this when the loading overlay close is initiated by user
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  // Protected
56  //------------------------------------------------------------------------------------------------
57 
58  //------------------------------------------------------------------------------------------------
60  override protected void AllPatchSizeLoaded()
61  {
62  // Setup callback and compute
64  callback.GetEventOnResponse().Insert(OnItemPatchLoaded);
65  m_aPatchSizeCallbacks.Insert(callback);
66 
67  m_ItemTargetRevision.ComputePatchSize(callback);
68  }
69 
70  //------------------------------------------------------------------------------------------------
72  protected void HandleError()
73  {
74  if (m_bWaitingResponse || !m_bFailed)
75  {
76  if (m_LoadingOverlay)
77  m_LoadingOverlay.CloseAnimated();
78 
79  // Add action to downloads
80  SCR_WorkshopItemActionDownload action = new SCR_WorkshopItemActionDownload(m_Item, latestVersion: true);
81  SCR_DownloadManager.GetInstance().AddDownloadManagerEntry(m_Item, action);
82  action.Activate();
83 
84  // Display fail dialog in next frame to display it after action is really failed
85  // TODO - improve logic and move to base
86  if (!SCR_DownloadManager_Dialog.Cast(SCR_ConfigurableDialogUi.GetCurrentDialog()))
87  {
88  GetGame().GetCallqueue().CallLater(SetupAddonFail, 0, false, action);
89  }
90  }
91 
92  // Clear waiting
93  m_bWaitingResponse = false;
94  m_bFailed = true;
95  }
96 
97  //------------------------------------------------------------------------------------------------
99  protected void SetupAddonFail(SCR_WorkshopItemActionDownload action)
100  {
102  //action.ForceFail();
103  }
104 
105  //------------------------------------------------------------------------------------------------
107  protected void ShowRestrictedItemDialog()
108  {
109  m_bWaitingResponse = false;
110 
111  // Close the loading overlay
112  if (m_LoadingOverlay)
113  m_LoadingOverlay.CloseAnimated(false);
114 
115  SCR_WorkshopUiCommon.CreateDialog("error_addon_blocked");
116  }
117 
118  //------------------------------------------------------------------------------------------------
120  protected void ShowConfirmationUI()
121  {
122  if (m_LoadingOverlay)
123  m_LoadingOverlay.CloseAnimated();
124 
125  if (m_bRestrictedAddons)
126  return;
127 
128  // Setup main item
129  bool downloadMainItem = SCR_DownloadManager.IsLatestDownloadRequired(m_Item);
130 
131  // Get dependencies
132  array<ref SCR_WorkshopItem> dependenciesToLoad = {};
133  SCR_DownloadManager.SelectAddonsForLatestDownload(m_aDependencies, dependenciesToLoad);
134 
135  // Show confirmation only if there are dependencies
136  if (!m_aDependencies.IsEmpty())
137  {
138  SCR_DownloadConfirmationDialog confirmDialog = SCR_DownloadConfirmationDialog.CreateForAddonAndDependencies(m_Item, downloadMainItem, dependenciesToLoad, m_bSubscribeToAddons);
139 
140  if (m_OnDownloadConfirmDisplayed)
141  m_OnDownloadConfirmDisplayed.Invoke(this, confirmDialog);
142  }
143  else
144  {
145  // Start download immediately
146  //SCR_DownloadManager.GetInstance().DownloadLatestWithDependencies(m_Item, downloadMainItem, dependenciesToLoad);
147  SCR_DownloadManager.GetInstance().DownloadItems({m_Item});
148 
149  // Subscribe to items
150  if (!m_bSubscribeToAddons)
151  return;
152 
153  if (m_Item)
154  m_Item.SetSubscribed(true);
155 
156  foreach (SCR_WorkshopItem dependency : dependenciesToLoad)
157  {
158  dependency.SetSubscribed(true);
159  }
160  }
161  }
162 
163  //------------------------------------------------------------------------------------------------
164  // Callbacks
165  //------------------------------------------------------------------------------------------------
166 
167  //------------------------------------------------------------------------------------------------
168  override protected void OnItemError(SCR_WorkshopItem item)
169  {
170  HandleError();
171 
172  super.OnItemError(item);
173  }
174 
175  //------------------------------------------------------------------------------------------------
177  override protected void OnAllDependenciesDetailsLoaded()
178  {
179  // Close the loading overlay
180  if (m_LoadingOverlay)
181  m_LoadingOverlay.CloseAnimated(false);
182 
183  GetOnRestrictedDependency().Insert(OnRestrictedDependenciesFound);
184 
185  super.OnAllDependenciesDetailsLoaded();
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  protected void OnRestrictedDependenciesFound(SCR_DownloadSequence sequence, array<ref SCR_WorkshopItem> dependencies)
190  {
191  ShowRestrictedDependenciesDialog();
192  GetOnRestrictedDependency().Remove(OnRestrictedDependenciesFound);
193  }
194 
195  //------------------------------------------------------------------------------------------------
197  protected void OnItemDependenciesLoaded(notnull SCR_WorkshopItem item)
198  {
199  // Unsubscribe - this callback is not needed any more
200  m_Item.m_OnDependenciesLoaded.Remove(OnItemDependenciesLoaded);
201 
202  m_aDependencies = m_Item.GetLatestDependencies();
203 
204  // Resticted
205  if (item.GetRestricted())
206  {
207  ShowRestrictedItemDialog();
208  return;
209  }
210 
211  // No dependencies
212  if (m_aDependencies.IsEmpty())
213  {
214  OnAllDependenciesDetailsLoaded();
215  return;
216  }
217 
218  // Load
219  //OnAllDependenciesDetailsLoaded();
220  LoadDependenciesDetails();
221  }
222 
223  //------------------------------------------------------------------------------------------------
225  protected void OnItemGetAsset(SCR_WorkshopItem item)
226  {
227  if (!item.GetRequestFailed())
228  return;
229 
230  GetGame().GetCallqueue().Remove(CreateLoadingOverlay);
231  if (m_LoadingOverlay)
232  m_LoadingOverlay.Close();
233 
234  OnItemError(item);
235  }
236 
237  //------------------------------------------------------------------------------------------------
240  protected void OnItemPatchLoaded(SCR_BackendCallback callback = null)
241  {
242  // Error handling
243  if (callback && callback.GetResponseType() == EBackendCallbackResponse.ERROR)
244  {
245  HandleError();
246  return;
247  }
248 
249  // Size
250  float size;
251  m_ItemTargetRevision.GetPatchSize(size);
252  m_Item.SetTargetRevisionPatchSize(size);
253 
254  // All ready
255  m_bWaitingResponse = false;
256 
257  if (HasAllDetails())
258  {
259  if (m_OnReady)
260  m_OnReady.Invoke(this);
261 
262  ShowConfirmationUI();
263  }
264  }
265 
266  //------------------------------------------------------------------------------------------------
267  // Construct
268  //------------------------------------------------------------------------------------------------
269 
270  //------------------------------------------------------------------------------------------------
271  void SCR_WorkshopDownloadSequence(array<ref SCR_WorkshopItem> dependencies, SCR_WorkshopItem item, Revision itemTargetRevision)
272  {
273  // Setup
274  m_Item = item;
275  m_ItemTargetRevision = itemTargetRevision;
276  m_Item.SetItemTargetRevision(itemTargetRevision);
277 
278  m_bWaitingResponse = true;
279 
280  // Load
281  m_Item.m_OnDependenciesLoaded.Insert(OnItemDependenciesLoaded);
282 
283  m_Item.m_OnGetAsset.Insert(OnItemGetAsset);
284  m_Item.m_OnError.Insert(OnItemError);
285  m_Item.m_OnTimeout.Insert(OnItemError);
286 
287  m_Item.LoadDetails();
288 
289  GetGame().GetCallqueue().CallLater(CreateLoadingOverlay, LOADING_DELAY);
290  }
291 
292  //------------------------------------------------------------------------------------------------
294  {
295  #ifdef WORKSHOP_DEBUG
296  ContentBrowserUI._print(string.Format("SCR_WorkshopDownloadSequence: Delete for: %1", m_Item.GetName()));
297  #endif
298 
299  if (m_LoadingOverlay)
300  m_LoadingOverlay.Close();
301 
302  // Unsubscribe from item's events
303  m_Item.m_OnDependenciesLoaded.Remove(OnItemDependenciesLoaded);
304  }
305 };
SCR_DownloadSequence
Definition: SCR_DownloadSequence.c:19
SCR_WorkshopDownloadSequence
Definition: SCR_WorkshopDownloadSequence.c:9
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_BackendCallbackWorkshopItem
void SCR_BackendCallbackWorkshopItem(SCR_WorkshopItem item)
Definition: SCR_AddonPatchSizeLoader.c:149
SCR_WorkshopItemActionDownload
Definition: SCR_WorkshopItemActionDownload.c:9
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
SCR_BackendCallback
Scripted backend callback class unifying backend response.
Definition: SCR_BackendCallback.c:21
m_LoadingOverlay
protected SCR_LoadingOverlay m_LoadingOverlay
Definition: SCR_BackendImageComponent.c:250
m_aDependencies
protected ref array< ref SCR_WorkshopItem > m_aDependencies
Definition: SCR_ModDetailsSuperMenuComponent.c:10
SCR_LoadingOverlayDialog
Definition: SCR_LoadingOverlayDialog.c:5
SCR_DownloadManager_Dialog
void SCR_DownloadManager_Dialog()
Definition: SCR_DownloadManager_Dialog.c:491
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
EBackendCallbackResponse
EBackendCallbackResponse
Basic callback responses.
Definition: SCR_BackendCallback.c:12
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
callback
DownloadConfigCallback callback
SCR_DownloadManager
Definition: SCR_DownloadManager.c:20