Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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
15
16 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
17 // Old script invoker. Auto
18
19 protected ref ScriptInvoker m_OnDownloadConfirmed; // (SCR_DownloadConfirmationDialog dlg)
20
21 //------------------------------------------------------------------------------------------------
26 static SCR_DownloadConfirmationDialog CreateForAddonAndDependencies(notnull SCR_WorkshopItem mainItem, bool downloadMainItem, notnull array<ref SCR_WorkshopItem> dependencies, bool subscribeToAddons)
27 {
29
30 dlg.m_bSubscribeToAddons = subscribeToAddons;
31 dlg.m_Item = mainItem;
32 dlg.m_bDownloadMainItem = downloadMainItem;
33 dlg.m_aDependencies = new array<ref SCR_WorkshopItem>;
34 foreach (auto i : dependencies)
35 dlg.m_aDependencies.Insert(i);
36
37 SCR_ConfigurableDialogUi.CreateFromPreset(SCR_WorkshopDialogs.DIALOGS_CONFIG, "download_confirmation", dlg);
38
40
41 return dlg;
42 }
43
44 //---- REFACTOR NOTE END ----
45
46 //------------------------------------------------------------------------------------------------
47 protected static void SetupDownloadDialogAddons(notnull out SCR_DownloadConfirmationDialog dialog, notnull array<ref Tuple2<SCR_WorkshopItem, ref Revision>> addonsAndVersions, bool subscribeToAddons)
48 {
49 dialog.m_bDownloadMainItem = false;
50 dialog.m_bSubscribeToAddons = subscribeToAddons;
51 dialog.m_aDependencies = new array<ref SCR_WorkshopItem>;
52 dialog.m_aDependencyVersions = new array<ref Revision>;
53
54 foreach (Tuple2<SCR_WorkshopItem, ref Revision> i : addonsAndVersions)
55 {
56 dialog.m_aDependencies.Insert(i.param1);
57 dialog.m_aDependencyVersions.Insert(i.param2);
58 }
59 }
60
61 //------------------------------------------------------------------------------------------------
63 static SCR_DownloadConfirmationDialog CreateForAddons(notnull array<ref Tuple2<SCR_WorkshopItem, ref Revision>> addonsAndVersions, bool subscribeToAddons)
64 {
66
67 SetupDownloadDialogAddons(dlg, addonsAndVersions, subscribeToAddons);
68
69 SCR_ConfigurableDialogUi.CreateFromPreset(SCR_WorkshopDialogs.DIALOGS_CONFIG, "download_confirmation", dlg);
70
72
73 return dlg;
74 }
75
76 //------------------------------------------------------------------------------------------------
78 {
80
81 // Update line of the main addon
82 m_Widgets.m_MainAddonSection.SetVisible(m_bDownloadMainItem);
83 if (m_Item != null && m_bDownloadMainItem)
84 {
85 m_Widgets.m_MainAddonLineComponent0.InitForWorkshopItem(m_Item);
86 }
87
88 // Load patch size
90
91//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
92// Overreliance on strings, weird naming
93
94 // Buttons
95 SCR_InputButtonComponent confirmButton = FindButton("confirm");
96 SCR_InputButtonComponent confirmAlternativeButton = FindButton("confirm2");
97
98//---- REFACTOR NOTE END ----
99
100 if (confirmAlternativeButton)
101 confirmAlternativeButton.m_OnActivated.Insert(OnConfirmAlternative);
102
103 if (m_aDependencies.IsEmpty())
104 {
105 // When we are downloading only one addon, 'download all' button becomes 'download'
106 if (confirmAlternativeButton)
107 confirmAlternativeButton.SetVisible(false);
108
109//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
110// Hardcoded string
111
112 confirmButton.SetLabel("#AR-Workshop_Dialog_ConfirmDownload_ButtonDownload");
113
114//---- REFACTOR NOTE END ----
115
116 }
117 else if (!m_bDownloadMainItem)
118 {
119 // When we are not downloading the main addon, 'download one' button is hidden
120 if (confirmAlternativeButton)
121 confirmAlternativeButton.SetVisible(false);
122 }
123
124 // Hide other optional text
125 m_Widgets.m_OtherAddonsMessage.SetVisible(false);
126 }
127
128 //------------------------------------------------------------------------------------------------
129 protected void LoadAddonPatchSizes()
130 {
131 array<ref SCR_WorkshopItem> versionDifferences = SCR_AddonManager.SelectItemsAnd(
133 EWorkshopItemQuery.NOT_OFFLINE | EWorkshopItemQuery.NOT_LOCAL_VERSION_MATCH_DEPENDENCY);
134
135 // Skip if there are no version differences
136 if (versionDifferences.IsEmpty())
137 {
139 return;
140 }
141
142 // Setup loading
143 m_Loader.ClearItems();
144
145 foreach (SCR_WorkshopItem item : versionDifferences)
146 {
147 Revision rev = item.GetDependency().GetRevision();
148 item.SetItemTargetRevision(rev);
149 m_Loader.InsertItem(item);
150 }
151
152 m_Loader.GetOnAllPatchSizeLoaded().Insert(OnAllPatchSizeLoaded);
153 m_Loader.LoadPatchSizes();
154
155 // Show loading overlay
156 m_Widgets.m_LoadingOverlayComponent.SetShown(true);
157 m_Widgets.m_AddonContentVertical.SetVisible(false);
158 }
159
160 //------------------------------------------------------------------------------------------------
161 protected void OnAllPatchSizeLoaded(SCR_AddonPatchSizeLoader loader, bool allLoaded)
162 {
164
166
167 // Hide loading overlay
168 m_Widgets.m_LoadingOverlayComponent.SetShown(false);
169 m_Widgets.m_AddonContentVertical.SetVisible(true);
170
171 // Total download size - only visible if we have any dependencies
172 m_Widgets.m_SummarySection.SetVisible(!m_aDependencies.IsEmpty());
173 if (!m_aDependencies.IsEmpty())
174 {
176 string totalSizeStr = SCR_ByteFormat.GetReadableSize(totalSize);
177 m_Widgets.m_TotalAddonSizeText.SetText(totalSizeStr);
178 }
179 }
180
181 //------------------------------------------------------------------------------------------------
183 protected void CreateAddonWidget(notnull SCR_WorkshopItem dep, Widget listRoot)
184 {
185 Widget w = GetGame().GetWorkspace().CreateWidgets(DOWNLOAD_LINE_LAYOUT, listRoot);
187
188 // Setup addon revision
189 Dependency dependency = dep.GetDependency();
190
191 Revision revision = null;
192 if (dependency)
193 revision = dependency.GetRevision();
194
195 //Revision revision = dep.GetDependency().GetRevision();
196 comp.InitForWorkshopItem(dep, revision);
197 }
198
199 //------------------------------------------------------------------------------------------------
200 protected void CreateAddonList()
201 {
202 // Create lines for other addons
203 m_Widgets.m_OtherAddonsSection.SetVisible(!m_aDependencies.IsEmpty());
204 if (!m_aDependencies.IsEmpty())
205 {
206 // Not downloaded - not avaiable offline
207 array<ref SCR_WorkshopItem> missingAddons = SCR_AddonManager.SelectItemsBasic(m_aDependencies, EWorkshopItemQuery.NOT_OFFLINE);
208
209 foreach (SCR_WorkshopItem missing : missingAddons)
210 {
211 CreateAddonWidget(missing, m_Widgets.m_OtherAddonsList);
212 }
213
214 // Version difference
215 array<ref SCR_WorkshopItem> versionDifferences = SCR_AddonManager.SelectItemsAnd(
217 EWorkshopItemQuery.NOT_LOCAL_VERSION_MATCH_DEPENDENCY | EWorkshopItemQuery.OFFLINE);
218
219 int vDifCount = versionDifferences.Count();
220 bool hasDifference = vDifCount > 0;
221
222 // Display version difference widgets
223 m_Widgets.m_UpdateAddonsList.SetVisible(hasDifference);
224 m_Widgets.m_UpdateAddonsMessage.SetVisible(hasDifference);
225
226 if (hasDifference)
227 {
228 // Create woidgets
229 foreach (SCR_WorkshopItem addon : versionDifferences)
230 {
231 CreateAddonWidget(addon, m_Widgets.m_UpdateAddonsList);
232 }
233
234 // Version change text
235 m_Widgets.m_UpdateAddonsMessage.SetTextFormat("#AR-Workshop_Dialog_ConfirmDownload_VersionDifferences", vDifCount);
236 }
237 }
238 }
239
242 //------------------------------------------------------------------------------------------------
245 {
246 if (!m_aDependencies.IsEmpty())
247 {
248 m_Widgets.m_OtherAddonsMessage.SetVisible(true);
249 m_Widgets.m_OtherAddonsMessage.SetTextFormat(
250 "#AR-Workshop_Dialog_ConfirmDownload_DependenciesWillBeDownloaded",
251 m_aDependencies.Count());
252 }
253 }
254
255 //------------------------------------------------------------------------------------------------
258 {
259 m_Widgets.m_OtherAddonsMessage.SetVisible(false);
260 }
261
262 //------------------------------------------------------------------------------------------------
263 override void OnConfirm()
264 {
265 if (m_Item)
266 {
267 // If main item is provided, we (maybe) start downloading this item and its dependencies.
269 }
270 else if (m_aDependencies)
271 {
272 // If main item was not provided, all the downloads are started separately.
273 foreach (int i, SCR_WorkshopItem dep : m_aDependencies)
274 {
275 if (dep.IsDownloadRunning())
276 continue;
277
278 Revision targetVersion;
279 if (m_aDependencyVersions != null)
280 targetVersion = m_aDependencyVersions[i];
281
283
284 if (targetVersion) //why? it's never true
285 action = dep.Download(targetVersion);
286 else
287 action = dep.DownloadLatestVersion();
288
289 if (action)
290 {
291 action.Activate();
292 m_aCreatedActions.Insert(action);
293 }
294 }
295 }
296
297 // Subscription behavior
299 {
300 if (m_Item)
301 m_Item.SetSubscribed(true);
302
303 foreach (SCR_WorkshopItem dependency : m_aDependencies)
304 {
305 dependency.SetSubscribed(true);
306 }
307 }
308
309 super.OnConfirm();
310 }
311
312 //------------------------------------------------------------------------------------------------
315 {
316 m_aDependencies.Clear(); // Don't download any dependencies
317
318 if (!m_Item)
319 return;
320
322
324 {
325 if (m_Item)
326 m_Item.SetSubscribed(true);
327 }
328
329 super.OnConfirm();
330 }
331
332 //------------------------------------------------------------------------------------------------
334 array<ref SCR_WorkshopItemAction> GetActions()
335 {
336 array<ref SCR_WorkshopItemAction> a = {};
337
339 {
340 a.Insert(action);
341 }
342
343 return a;
344 }
345}
ArmaReforgerScripted GetGame()
Definition game.c:1398
EWorkshopItemQuery
static array< ref SCR_WorkshopItem > SelectItemsBasic(array< ref SCR_WorkshopItem > items, EWorkshopItemQuery query)
static array< ref SCR_WorkshopItem > SelectItemsAnd(array< ref SCR_WorkshopItem > items, EWorkshopItemQuery query)
ScriptInvokerBase< ScriptInvoker_AddonPatchSizeLoad > GetOnAllPatchSizeLoaded()
static SCR_ConfigurableDialogUi CreateFromPreset(ResourceName presetsResourceName, string tag, SCR_ConfigurableDialogUi customDialogObj=null)
Creates a dialog from preset.
Widget GetContentLayoutRoot()
Returns the root of the content layout.
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
Dialog for confirming multiple downloads in workshop.
ref array< ref SCR_WorkshopItemAction > m_aCreatedActions
ref array< ref Revision > m_aDependencyVersions
static void SetupDownloadDialogAddons(notnull out SCR_DownloadConfirmationDialog dialog, notnull array< ref Tuple2< SCR_WorkshopItem, ref Revision > > addonsAndVersions, bool subscribeToAddons)
void CreateAddonWidget(notnull SCR_WorkshopItem dep, Widget listRoot)
Create and setup addon widget text and verions.
array< ref SCR_WorkshopItemAction > GetActions()
Returns the internal array with created download actions.
static SCR_DownloadConfirmationDialog CreateForAddonAndDependencies(notnull SCR_WorkshopItem mainItem, bool downloadMainItem, notnull array< ref SCR_WorkshopItem > dependencies, bool subscribeToAddons)
static SCR_DownloadConfirmationDialog CreateForAddons(notnull array< ref Tuple2< SCR_WorkshopItem, ref Revision > > addonsAndVersions, bool subscribeToAddons)
Download addons with specific versions.
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
void SetStyleDownloadAddons()
Hides all explanation text.
void SetStyleDownloadAddonsWithDependencies()
Sets text: "%1 dependencies will be downloaded:" over the dependencies list.
void OnAllPatchSizeLoaded(SCR_AddonPatchSizeLoader loader, bool allLoaded)
void OnConfirmAlternative()
This is only valid when we can download the main addon.
ref SCR_DownloadConfirmationDialogContentWidgets m_Widgets
ref array< ref SCR_WorkshopItem > m_aDependencies
void InitForWorkshopItem(SCR_WorkshopItem item, Revision versionTo=null, bool showVersionAndSize=true)
Initializes the line in passive mode. It will just show basic information once.
static float GetTotalSizeBytes(array< ref SCR_WorkshopItem > arrayIn, SCR_WorkshopItem extraItem=null)
static SCR_DownloadManager GetInstance()
array< ref SCR_WorkshopItemAction > DownloadLatestWithDependencies(notnull SCR_WorkshopItem mainItem, bool downloadMainItem, array< ref SCR_WorkshopItem > dependencies)
void SetLabel(string label)
PUBLIC API\.
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134