Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WorkshopDownloadSequence.c
Go to the documentation of this file.
1
8
9//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
10// Data handling class tangled with UI. Furthermore, it complicates the already messy cross referencing going on with SCR_WorkshopItem and related classes
11
13{
14 protected static float LOADING_DELAY = 500;
15
16 protected ref SCR_WorkshopItem m_Item;
18
20
21 //------------------------------------------------------------------------------------------------
22 // Public
23 //------------------------------------------------------------------------------------------------
24
25 //------------------------------------------------------------------------------------------------
28 {
29 if (previous && previous.m_bWaitingResponse)
30 return previous;
31
32 SCR_WorkshopDownloadSequence sq = new SCR_WorkshopDownloadSequence(null, item, itemTargetRevision);
33
34 return sq;
35 }
36
37 //------------------------------------------------------------------------------------------------
38 protected void CreateLoadingOverlay()
39 {
40 // Skip if already loaded
42 return;
43
44 // Show only if we are still waiting for data
46 m_LoadingOverlay.m_OnCloseStarted.Insert(Cancel); // Cancel this when the loading overlay close is initiated by user
47 }
48
49 //------------------------------------------------------------------------------------------------
50 // Protected
51 //------------------------------------------------------------------------------------------------
52
53 //------------------------------------------------------------------------------------------------
55 override protected void AllPatchSizeLoaded()
56 {
57 // Setup callback and compute
59 callback.SetOnSuccess(OnItemPatchLoaded);
60 callback.SetOnError(OnItemPatchError);
61 m_aPatchSizeCallbacks.Insert(callback);
62
63 m_ItemTargetRevision.ComputePatchSize(callback);
64 }
65
66 //------------------------------------------------------------------------------------------------
68 protected void HandleError()
69 {
71 {
73 m_LoadingOverlay.CloseAnimated();
74
75 // Add action to downloads
78 action.Activate();
79
80 // Display fail dialog in next frame to display it after action is really failed
81 // TODO - improve logic and move to base
82 if (!SCR_DownloadManager_Dialog.Cast(SCR_ConfigurableDialogUi.GetCurrentDialog()))
83 {
84 GetGame().GetCallqueue().CallLater(SetupAddonFail, 0, false, action);
85 }
86 }
87
88 // Clear waiting
89 m_bWaitingResponse = false;
90 m_bFailed = true;
91 }
92
93 //------------------------------------------------------------------------------------------------
96 {
97 SCR_DownloadManager_Dialog.Create();
98 //action.ForceFail();
99 }
100
101 //------------------------------------------------------------------------------------------------
104 {
105 m_bWaitingResponse = false;
106
107 // Close the loading overlay
109 m_LoadingOverlay.CloseAnimated(false);
110
111 SCR_WorkshopDialogs.CreateDialog("error_addon_blocked");
112 }
113
114 //------------------------------------------------------------------------------------------------
116 protected void ShowConfirmationUI()
117 {
119 m_LoadingOverlay.CloseAnimated();
120
122 return;
123
124 // Setup main item
125 bool downloadMainItem = SCR_DownloadManager.IsLatestDownloadRequired(m_Item);
126
127 // Get dependencies
128 array<ref SCR_WorkshopItem> dependenciesToLoad = {};
130
131 // Show confirmation only if there are dependencies
132 if (!m_aDependencies.IsEmpty())
133 {
135 }
136 else
137 {
138 // Start download immediately
139 //SCR_DownloadManager.GetInstance().DownloadLatestWithDependencies(m_Item, downloadMainItem, dependenciesToLoad);
141
142 // Subscribe to items
144 return;
145
146 if (m_Item)
147 m_Item.SetSubscribed(true);
148
149 foreach (SCR_WorkshopItem dependency : dependenciesToLoad)
150 {
151 dependency.SetSubscribed(true);
152 }
153 }
154 }
155
156 //------------------------------------------------------------------------------------------------
157 // Callbacks
158 //------------------------------------------------------------------------------------------------
159
160 //------------------------------------------------------------------------------------------------
161 override protected void OnItemError(SCR_WorkshopItem item)
162 {
163 HandleError();
164
165 super.OnItemError(item);
166 }
167
168 //------------------------------------------------------------------------------------------------
170 override protected void OnAllDependenciesDetailsLoaded()
171 {
172 // Close the loading overlay
174 m_LoadingOverlay.CloseAnimated(false);
175
177
178 super.OnAllDependenciesDetailsLoaded();
179 }
180
181 //------------------------------------------------------------------------------------------------
182 protected void OnRestrictedDependenciesFound(SCR_DownloadSequence sequence, array<ref SCR_WorkshopItem> dependencies)
183 {
186 }
187
188 //------------------------------------------------------------------------------------------------
190 protected void OnItemDependenciesLoaded(notnull SCR_WorkshopItem item)
191 {
192 // Unsubscribe - this callback is not needed any more
193 m_Item.m_OnDependenciesLoaded.Remove(OnItemDependenciesLoaded);
194
195 m_aDependencies = m_Item.GetLatestDependencies();
196
197 // Resticted
198 if (item.GetRestricted())
199 {
201 return;
202 }
203
204 // No dependencies
205 if (m_aDependencies.IsEmpty())
206 {
208 return;
209 }
210
211 // Load
212 //OnAllDependenciesDetailsLoaded();
214 }
215
216 //------------------------------------------------------------------------------------------------
218 protected void OnItemGetAsset(SCR_WorkshopItem item)
219 {
220 if (!item.GetRequestFailed())
221 return;
222
223 GetGame().GetCallqueue().Remove(CreateLoadingOverlay);
225 m_LoadingOverlay.Close();
226
227 OnItemError(item);
228 }
229
230 //------------------------------------------------------------------------------------------------
233 protected void OnItemPatchLoaded()
234 {
235 // Size
236 float size;
237 m_ItemTargetRevision.GetPatchSize(size);
238 m_Item.SetTargetRevisionPatchSize(size);
239
240 // All ready
241 m_bWaitingResponse = false;
242
243 if (HasAllDetails())
244 {
245 if (m_OnReady)
246 m_OnReady.Invoke(this);
247
249 }
250 }
251
252 //------------------------------------------------------------------------------------------------
255 protected void OnItemPatchError()
256 {
257 HandleError();
258 }
259
260 //------------------------------------------------------------------------------------------------
261 // Construct
262 //------------------------------------------------------------------------------------------------
263
264 //------------------------------------------------------------------------------------------------
265 void SCR_WorkshopDownloadSequence(array<ref SCR_WorkshopItem> dependencies, SCR_WorkshopItem item, Revision itemTargetRevision)
266 {
267 // Setup
268 m_Item = item;
269 m_ItemTargetRevision = itemTargetRevision;
270 m_Item.SetItemTargetRevision(itemTargetRevision);
271
272 m_bWaitingResponse = true;
273
274 // Load
275 m_Item.m_OnDependenciesLoaded.Insert(OnItemDependenciesLoaded);
276
277 m_Item.m_OnGetAsset.Insert(OnItemGetAsset);
278 m_Item.m_OnError.Insert(OnItemError);
279 m_Item.m_OnTimeout.Insert(OnItemError);
280
281 m_Item.LoadDetails();
282
283 GetGame().GetCallqueue().CallLater(CreateLoadingOverlay, LOADING_DELAY);
284 }
285
286 //------------------------------------------------------------------------------------------------
288 {
289 #ifdef WORKSHOP_DEBUG
290 ContentBrowserUI._print(string.Format("SCR_WorkshopDownloadSequence: Delete for: %1", m_Item.GetName()));
291 #endif
292
294 m_LoadingOverlay.Close();
295
296 // Unsubscribe from item's events
297 m_Item.m_OnDependenciesLoaded.Remove(OnItemDependenciesLoaded);
298 }
299
300 //---- REFACTOR NOTE END ----
301};
ArmaReforgerScripted GetGame()
Definition game.c:1398
int size
void SCR_BackendCallbackWorkshopItem(SCR_WorkshopItem item)
static SCR_ConfigurableDialogUi GetCurrentDialog()
Dialog for confirming multiple downloads in workshop.
static SCR_DownloadConfirmationDialog CreateForAddonAndDependencies(notnull SCR_WorkshopItem mainItem, bool downloadMainItem, notnull array< ref SCR_WorkshopItem > dependencies, bool subscribeToAddons)
static void SelectAddonsForLatestDownload(array< ref SCR_WorkshopItem > arrayIn, array< ref SCR_WorkshopItem > arrayOut)
static bool IsLatestDownloadRequired(SCR_WorkshopItem item)
static SCR_DownloadManager GetInstance()
void AddDownloadManagerEntry(notnull SCR_WorkshopItem item, notnull SCR_WorkshopItemActionDownload action)
array< ref SCR_WorkshopItemActionDownload > DownloadItems(array< ref SCR_WorkshopItem > items)
ref array< ref SCR_WorkshopItem > m_aDependencies
ref array< ref SCR_BackendCallbackWorkshopItem > m_aPatchSizeCallbacks
ScriptInvokerBase< ScriptInvoker_DownloadSequenceDependencies > GetOnRestrictedDependency()
ref ScriptInvokerBase< ScriptInvoker_DownloadSequence > m_OnReady
void Cancel()
Cancels this download request.
bool HasAllDetails()
Returns true if all details were loaded successfully.
SCR_ReportedAddonsDialog ShowRestrictedDependenciesDialog()
static SCR_LoadingOverlayDialog Create(string text=string.Empty)
void OnAllDependenciesDetailsLoaded()
Called when finally all the details of all dependencies are loaded.
static SCR_WorkshopDownloadSequence Create(SCR_WorkshopItem item, Revision itemTargetRevision, SCR_WorkshopDownloadSequence previous)
Tries to create a new request if previous doesn't exist or finished. Otherwise returns the previous r...
void OnItemDependenciesLoaded(notnull SCR_WorkshopItem item)
Called from SCR_WorkshopItem.m_OnDependenciesLoaded.
void HandleError()
Unified behavior for error and timeout.
void SCR_WorkshopDownloadSequence(array< ref SCR_WorkshopItem > dependencies, SCR_WorkshopItem item, Revision itemTargetRevision)
void ShowRestrictedItemDialog()
Show main addon restricted dialog.
void OnItemGetAsset(SCR_WorkshopItem item)
Call when main item (addon) is loaded.
void SetupAddonFail(SCR_WorkshopItemActionDownload action)
Open download manager and set action to fail.
void OnRestrictedDependenciesFound(SCR_DownloadSequence sequence, array< ref SCR_WorkshopItem > dependencies)
void AllPatchSizeLoaded()
After all dependencies patch loaded start loading patch size for main item.
void OnItemError(SCR_WorkshopItem item)
void ShowConfirmationUI()
Show download confirm dialog base on main item size and dependencies.