Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RoomModsManager.c
Go to the documentation of this file.
1 // Mods callback
2 //------------------------------------------------------------------------------------------------
4 {
5  protected Room m_Room;
6 
7  //-----------------------------------------------------------------------------------------------
8  Room GetRoom()
9  {
10  return m_Room;
11  }
12 
13  //-----------------------------------------------------------------------------------------------
14  void SCR_BackendCallbackRoomMods(Room room)
15  {
16  m_Room = room;
17  }
18 };
19 
20 //-----------------------------------------------------------------------------------------------
21 void ScriptInvoker_RoomModsDependencies(Room room, array<ref SCR_WorkshopItem> dependencies);
23 
24 //------------------------------------------------------------------------------------------------
28 {
29  protected Room m_Room;
30  protected Dependency m_ScenarioDependency;
31 
32  protected ref SCR_DownloadSequence m_DownloadSequence;
33 
34  protected bool m_bModsMatching = false;
35  protected bool m_bBlockedMods;
36  protected ref array<ref SCR_WorkshopItem> m_aCollidingDependencies = {};
37 
38  // Arrays
39  protected ref array<ref SCR_WorkshopItem> m_aRoomItemsScripted = {};
40 
41  protected ref array<ref SCR_WorkshopItem> m_aItemsUpdated = {};
42  protected ref array<ref SCR_WorkshopItem> m_aItemsToUpdate = {};
43 
44  // Callbacks
45  protected ref SCR_BackendCallbackRoomMods m_ModsCallback;
46  protected ref SCR_OnlineServiceBackendCallbacks m_ScenarioCallback = new SCR_OnlineServiceBackendCallbacks();
47 
48  protected ref array<ref SCR_OnlineServiceBackendCallbacks> m_aModsCallbacks = {};
49 
50 
51  //------------------------------------------------------------------------------------------------
52  // Invokers
53  //------------------------------------------------------------------------------------------------
54 
55  protected ref ScriptInvoker m_OnGetAllDependencies = new ScriptInvoker();
56 
57  protected ref ScriptInvoker m_OnGetScenario = new ScriptInvoker();
58 
59  protected ref ScriptInvokerRoom m_OnModsFail;
60  protected ref ScriptInvokerBase<ScriptInvoker_RoomModsDependencies> m_OnDependenciesLoadingPrevented;
61 
62  //------------------------------------------------------------------------------------------------
63  ScriptInvoker GetOnGetAllDependencies()
64  {
65  return m_OnGetAllDependencies;
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  ScriptInvoker GetOnGetScenario()
70  {
71  return m_OnGetScenario;
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  ScriptInvokerRoom GetOnModsFail()
76  {
77  if (!m_OnModsFail)
78  m_OnModsFail = new ScriptInvokerRoom();
79 
80  return m_OnModsFail;
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  ScriptInvokerBase<ScriptInvoker_RoomModsDependencies> GetOnDependenciesLoadingPrevented()
85  {
86  if (!m_OnDependenciesLoadingPrevented)
87  m_OnDependenciesLoadingPrevented = new ScriptInvokerBase<ScriptInvoker_RoomModsDependencies>();
88 
89  return m_OnDependenciesLoadingPrevented;
90  }
91 
92  //------------------------------------------------------------------------------------------------
93  // Public
94  //------------------------------------------------------------------------------------------------
95 
96  //------------------------------------------------------------------------------------------------
97  void Clear()
98  {
99  // Default for loading mods
100 
101  m_bModsMatching = false;
102  m_bBlockedMods = false;
103  m_aCollidingDependencies.Clear();
104  m_aRoomItemsScripted.Clear();
105  m_aItemsUpdated.Clear();
106  m_aItemsToUpdate.Clear();
107  m_ModsCallback = null;
108  m_ScenarioCallback = new SCR_OnlineServiceBackendCallbacks();
109  m_aModsCallbacks.Clear();
110  m_DownloadSequence = null;
111  m_ScenarioDependency = null;
112  m_Room = null;
113  }
114 
115  //------------------------------------------------------------------------------------------------
118  void ReceiveRoomMods(notnull Room room)
119  {
120  if (room != m_Room)
121  m_Room = room;
122 
123  array<Dependency> deps = {};
124  m_Room.GetItems(deps);
125 
126  m_bBlockedMods = false;
127  m_aCollidingDependencies.Clear();
128 
129  // Load full list
130  m_ModsCallback = new SCR_BackendCallbackRoomMods(room);
131  m_ModsCallback.GetEventOnResponse().Insert(OnRoomCallbackResponse);
132  m_Room.LoadDownloadList(m_ModsCallback);
133  }
134 
135  //------------------------------------------------------------------------------------------------
136  // Try to receive scenario data without looking for mods
137  void ReceiveRoomScenario(notnull Room room)
138  {
139  if (room != m_Room)
140  {
141  Debug.Error("Received data for non active room");
142  return;
143  }
144  OnScenarioModLoaded();
145  }
146 
147 
148  //------------------------------------------------------------------------------------------------
150  protected void OnLoadingModsFail(Room room)
151  {
152  // Don't notify fail if failed is not for current
153  if (room != m_Room)
154  return;
155 
156  if (m_OnModsFail)
157  m_OnModsFail.Invoke(m_Room);
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  // Protected
162  //------------------------------------------------------------------------------------------------
163 
164  //------------------------------------------------------------------------------------------------
168  protected void UpdatedDependencies(notnull array<ref SCR_WorkshopItem> items)
169  {
170  m_aItemsUpdated.Clear();
171  m_aItemsToUpdate.Clear();
172 
173  m_aItemsUpdated = SCR_AddonManager.SelectItemsBasic(items, EWorkshopItemQuery.LOCAL_VERSION_MATCH_DEPENDENCY);
174  m_aItemsToUpdate = SCR_AddonManager.SelectItemsBasic(items, EWorkshopItemQuery.NOT_LOCAL_VERSION_MATCH_DEPENDENCY);
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  protected void AllItemsLoaded()
179  {
180  if (!m_Room)
181  return;
182 
183  UpdatedDependencies(m_aRoomItemsScripted);
184 
185  // Pass list of updated & outdated mods
186  if (m_OnGetAllDependencies)
187  {
188  m_OnGetAllDependencies.Invoke();
189 
190  m_bModsMatching = (m_aItemsToUpdate.IsEmpty());
191  }
192 
193  ReceiveRoomScenario(m_Room);
194  }
195 
196  //------------------------------------------------------------------------------------------------
198  protected void LoadScenario()
199  {
200  m_ScenarioCallback.m_OnItem.Clear();
201 
202  if (!m_Room)
203  return;
204 
205  m_ScenarioDependency = m_Room.HostScenarioMod();
206  OnScenarioDetails();
207  }
208 
209  //------------------------------------------------------------------------------------------------
211  SCR_ReportedAddonsDialog DisplayRestrictedAddonsList()
212  {
213  /*
214  if (m_DownloadSequence && m_DownloadSequence.GetRestrictedAddons())
215  return m_DownloadSequence.ShowRestrictedDependenciesDialog();
216  */
217 
218  array<ref SCR_WorkshopItem> restrictedDependencies = SCR_AddonManager.SelectItemsBasic(m_aRoomItemsScripted, EWorkshopItemQuery.RESTRICTED);
219  SCR_AddonListDialog addonsDialog = SCR_AddonListDialog.CreateRestrictedAddonsJoinServer(restrictedDependencies);
220 
221  // Handle cancel reports done
222  SCR_ReportedAddonsDialog reportedDialog = SCR_ReportedAddonsDialog.Cast(addonsDialog);
223  if (reportedDialog)
224  reportedDialog.GetOnAllReportsCanceled().Insert(OnAllReportsCanceled);
225 
226  return reportedDialog;
227 
228  // All can be downloaded
229  return null;
230  }
231 
232  //------------------------------------------------------------------------------------------------
234  protected void OnAllReportsCanceled(SCR_ReportedAddonsDialog dialog)
235  {
236  dialog.GetOnAllReportsCanceled().Remove(OnAllReportsCanceled);
237 
238  m_DownloadSequence.OnAllReportsCanceled(dialog);
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  // Callbacks
243  //------------------------------------------------------------------------------------------------
244 
245  //------------------------------------------------------------------------------------------------
247  protected void OnScenarioModLoaded()
248  {
249  // Remove callback action
250  m_ScenarioCallback.m_OnItem.Remove(OnScenarioModLoaded);
251  LoadScenario();
252  }
253 
254  //------------------------------------------------------------------------------------------------
256  protected void OnScenarioDetails()
257  {
258  m_ScenarioCallback.m_OnScenarios.Remove(OnScenarioDetails);
259  m_OnGetScenario.Invoke(m_ScenarioDependency);
260  }
261 
262  //------------------------------------------------------------------------------------------------
263  protected void OnRoomCallbackResponse(SCR_BackendCallbackRoomMods callback)
264  {
265  if (callback.GetResponseType() == EBackendCallbackResponse.SUCCESS)
266  {
267  // Load list success
268  OnRoomFullList();
269  }
270  else
271  {
272  // Fail/timeout
273  OnLoadingModsFail(callback.GetRoom());
274  }
275 
276  callback.GetEventOnResponse().Remove(OnRoomCallbackResponse);
277  }
278 
279  //------------------------------------------------------------------------------------------------
281  protected void OnRoomFullList()
282  {
283  if (!m_Room)
284  {
285  OnLoadingModsFail(null);
286  return;
287  }
288 
289  if (!m_Room.IsAuthorized())
290  {
291  OnLoadingModsFail(m_Room);
292  return;
293  }
294 
295  array<Dependency> deps = new array<Dependency>;
296  m_Room.GetItems(deps);
297 
298  array<Dependency> depsItems = new array<Dependency>;
299 
300  // Clearup
301  m_aRoomItemsScripted.Clear();
302 
303  // Skip loadig of content if none
304  if (deps.IsEmpty())
305  {
306  AllItemsLoaded();
307  return;
308  }
309 
310  SCR_AddonManager mngr = SCR_AddonManager.GetInstance();
311 
312  // Loaded dependencies as items
313  foreach (Dependency dep : deps)
314  {
315  //ref SCR_WorkshopItem item = SCR_WorkshopItem.Internal_CreateFromDependency(dep);
316  SCR_WorkshopItem item = mngr.Register(dep);
317  item.SetItemTargetRevision(dep.GetRevision());
318  m_aRoomItemsScripted.Insert(item);
319  }
320 
321  // Clear previous download sequence reactions
322  if (m_DownloadSequence)
323  {
324  m_DownloadSequence.GetOnReady().Remove(OnDownloadSequenceReady);
325  m_DownloadSequence.GetOnError().Remove(OnDownloadSequenceError);
326  }
327 
328  // Setup new download sequence
329  InitDownloadSequence();
330  }
331 
332  //------------------------------------------------------------------------------------------------
333  protected void InitDownloadSequence()
334  {
335  m_DownloadSequence = SCR_DownloadSequence.Create(m_aRoomItemsScripted, null, true);
336  m_DownloadSequence.GetOnReady().Insert(OnDownloadSequenceReady);
337  m_DownloadSequence.GetOnDependenciesLoadingPrevented().Insert(OnDependenciesLoadingPrevented);
338  m_DownloadSequence.GetOnError().Insert(OnDownloadSequenceError);
339  m_DownloadSequence.GetOnRestrictedDependency().Insert(OnDownloadSequenceRestrictedAddons);
340 
341  m_DownloadSequence.Init();
342  }
343 
344  //------------------------------------------------------------------------------------------------
345  protected void OnDownloadSequenceReady(SCR_DownloadSequence sequence)
346  {
347  AllItemsLoaded();
348 
349  // Cleanup
350  sequence.GetOnReady().Remove(OnDownloadSequenceReady);
351  sequence.GetOnDependenciesLoadingPrevented().Remove(OnDependenciesLoadingPrevented);
352  sequence.GetOnError().Remove(OnDownloadSequenceError);
353  sequence.GetOnRestrictedDependency().Remove(OnDownloadSequenceRestrictedAddons);
354  }
355 
356  //------------------------------------------------------------------------------------------------
359  protected void OnDependenciesLoadingPrevented(SCR_DownloadSequence sequence, array<ref SCR_WorkshopItem> dependencies)
360  {
361  m_aCollidingDependencies = dependencies;
362 
363  if (m_OnDependenciesLoadingPrevented)
364  m_OnDependenciesLoadingPrevented.Invoke(m_Room, dependencies);
365 
366  // Cleanup
367  sequence.GetOnDependenciesLoadingPrevented().Remove(OnDependenciesLoadingPrevented);
368  }
369 
370  //------------------------------------------------------------------------------------------------
371  array<ref SCR_WorkshopItem> GetCollidingDependencies()
372  {
373  array<ref SCR_WorkshopItem> dependencies = {};
374 
375  foreach (SCR_WorkshopItem item : m_aCollidingDependencies)
376  {
377  dependencies.Insert(item);
378  }
379 
380  return dependencies;
381  }
382 
383  //------------------------------------------------------------------------------------------------
384  protected void OnCancelDownloadConfirm(SCR_ConfigurableDialogUi dialog)
385  {
386  SCR_DownloadManager.GetInstance().EndAllDownloads();
387  }
388 
389  //------------------------------------------------------------------------------------------------
390  protected void OnCancelDownloadDialogClose(SCR_ConfigurableDialogUi dialog)
391  {
392  InitDownloadSequence();
393 
394  dialog.m_OnConfirm.Remove(OnCancelDownloadConfirm);
395  dialog.m_OnClose.Remove(OnCancelDownloadDialogClose);
396  }
397 
398  //------------------------------------------------------------------------------------------------
399  protected void OnDownloadSequenceError(SCR_DownloadSequence sequence)
400  {
401  // Cleanup
402  sequence.GetOnReady().Remove(OnDownloadSequenceReady);
403  sequence.GetOnDependenciesLoadingPrevented().Remove(OnDependenciesLoadingPrevented);
404  sequence.GetOnError().Remove(OnDownloadSequenceError);
405  sequence.GetOnRestrictedDependency().Remove(OnDownloadSequenceRestrictedAddons);
406  if (m_OnModsFail)
407  m_OnModsFail.Invoke(m_Room);
408  }
409 
410  //------------------------------------------------------------------------------------------------
411  protected void OnDownloadSequenceRestrictedAddons(SCR_DownloadSequence sequence, array<ref SCR_WorkshopItem> items)
412  {
413  m_bBlockedMods = m_DownloadSequence.GetBlockedAddons();
414  }
415 
416  //------------------------------------------------------------------------------------------------
417  // Get set
418  //------------------------------------------------------------------------------------------------
419  //------------------------------------------------------------------------------------------------
420  string GetModListSizeString(array<ref SCR_WorkshopItem> items)
421  {
422  float size = GetModsSize(items);
423 
424  if (size <= 0)
425  return string.Empty;
426 
427  // Size string
428  string str = SCR_ByteFormat.GetReadableSize(size);
429 
430  return str;
431  }
432 
433  //------------------------------------------------------------------------------------------------
434  float GetModsSize(array<ref SCR_WorkshopItem> items)
435  {
436  return SCR_ModHandlerLib.GetModListSize(items);
437  }
438 
439  //------------------------------------------------------------------------------------------------
441  string GetModListPatchSizeString(array<ref SCR_WorkshopItem> items)
442  {
443  float size = GetModListPatchSize(items);
444 
445  if (size <= 0)
446  return string.Empty;
447 
448  // Size string
449  return SCR_ByteFormat.GetReadableSize(size);
450  }
451 
452  //------------------------------------------------------------------------------------------------
453  float GetModListPatchSize(array<ref SCR_WorkshopItem> items)
454  {
455  float size;
456  for (int i = 0, count = items.Count(); i < count; i++)
457  {
458  size += items[i].GetTargetRevisionPatchSize();
459  }
460 
461  return size;
462  }
463 
464  //------------------------------------------------------------------------------------------------
465  bool HasBlockedMods()
466  {
467  return m_bBlockedMods;
468  }
469 
470  //------------------------------------------------------------------------------------------------
471  array<ref SCR_WorkshopItem> GetRoomItemsScripted()
472  {
473  return m_aRoomItemsScripted;
474  }
475 
476  //------------------------------------------------------------------------------------------------
477  array<ref SCR_WorkshopItem> GetRoomItemsUpdated()
478  {
479  return m_aItemsUpdated;
480  }
481 
482  //------------------------------------------------------------------------------------------------
483  array<ref SCR_WorkshopItem> GetRoomItemsToUpdate()
484  {
485  array<ref SCR_WorkshopItem> items = {};
486 
487  foreach (SCR_WorkshopItem item : m_aItemsToUpdate)
488  {
489  items.Insert(item);
490  }
491 
492  return items;
493  }
494 
495  //------------------------------------------------------------------------------------------------
496  void SetRoom(Room room)
497  {
498  m_Room = room;
499  }
500 
501  //------------------------------------------------------------------------------------------------
502  bool GetModsMatching()
503  {
504  return m_bModsMatching;
505  }
506 };
SCR_OnlineServiceBackendCallbacks
Definition: SCR_OnlineServiceWorkshop.c:16
SCR_ModHandlerLib
Definition: SCR_ModsHandlerLib.c:7
SCR_DownloadSequence
Definition: SCR_DownloadSequence.c:19
ScriptInvoker_RoomModsDependencies
func ScriptInvoker_RoomModsDependencies
Definition: SCR_RoomModsManager.c:22
SCR_BackendCallbackRoomMods
Definition: SCR_RoomModsManager.c:3
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
SCR_BackendCallback
Scripted backend callback class unifying backend response.
Definition: SCR_BackendCallback.c:21
SCR_ByteFormat
Definition: SCR_ByteFormat.c:5
SCR_ReportedAddonsDialog
Show list of reported mods and provide option to cancel reports.
Definition: SCR_ReportedAddonsDialog.c:3
SCR_RoomModsManager
Definition: SCR_RoomModsManager.c:27
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SCR_AddonManager
Definition: SCR_AddonManager.c:72
EBackendCallbackResponse
EBackendCallbackResponse
Basic callback responses.
Definition: SCR_BackendCallback.c:12
m_Room
protected Room m_Room
Definition: ServerBrowserMenuCallbacks.c:2
callback
DownloadConfigCallback callback
SCR_AddonListDialog
Shows a list of addons and some text.
Definition: SCR_WorkshopUiCommon.c:820
SCR_DownloadManager
Definition: SCR_DownloadManager.c:20
EWorkshopItemQuery
EWorkshopItemQuery
Definition: SCR_AddonManager.c:34
ScriptInvokerRoom
ScriptInvokerBase< ScriptInvokerRoomMethod > ScriptInvokerRoom
Definition: ServerBrowserMenuUI.c:8