Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WorkshopAddonBarComponent.c
Go to the documentation of this file.
2{
4
5 [Attribute("20", UIWidgets.EditBox, desc: "After how many character should be display preset name cut")]
6 protected int m_iPresetNameCap;
7
9
12
13 protected const int UPDATE_DELAY = 250;
14
15 //------------------------------------------------------------------------------------------------
16 override void HandlerAttached(Widget w)
17 {
18 super.HandlerAttached(w);
19
20 if (!GetGame().InPlayMode())
21 return;
22
23 m_Widgets.Init(w);
24
26 if (!mgr)
27 return;
28
31
33
35
36 m_Widgets.m_PresetsButtonComponent.GetButton().m_OnClicked.Insert(SCR_CommonDialogs.CreateModPresetsDialog);
37 m_Widgets.m_UpdateButtonComponent.GetButton().m_OnClicked.Insert(OnUpdateButtonClicked);
38
40 GetGame().GetCallqueue().CallLater(HandleUpdatesButton, UPDATE_DELAY, true);
41
43 }
44
45 //------------------------------------------------------------------------------------------------
46 override void HandlerDeattached(Widget w)
47 {
48 super.HandlerDeattached(w);
49
51
52 if (mgr)
54
56 m_LoadingOverlay.Close();
57
58 GetGame().GetCallqueue().Remove(HandleUpdatesButton);
59
61 }
62
63 //------------------------------------------------------------------------------------------------
64 protected void OnMenuShow(ChimeraMenuBase menu)
65 {
68 }
69
70 //------------------------------------------------------------------------------------------------
72 {
74 }
75
76 //------------------------------------------------------------------------------------------------
78 protected void OnUsedPresetChanged(string name)
79 {
80 // Cap
81 if (!name.IsEmpty() && name.Length() > m_iPresetNameCap)
82 name = name.Substring(0, m_iPresetNameCap) + "...";
83
84 m_Widgets.m_PresetsButtonComponent.SetLabelText(name);
85 }
86
87 //------------------------------------------------------------------------------------------------
88 protected void UpdateAllWidgets()
89 {
91
92 if (!mgr)
93 return;
94
95 // Mod count text
97 m_Widgets.m_PresetsButtonComponent.SetCountText(nAddonsEnabled.ToString());
98 }
99
100 //------------------------------------------------------------------------------------------------
101 protected void OnUpdateButtonClicked()
102 {
104 array<ref SCR_WorkshopItem> addonsOutdated = SCR_AddonManager.SelectItemsBasic(mgr.GetOfflineAddons(), EWorkshopItemQuery.UPDATE_AVAILABLE);
105
106 // Load patch sizes for latest revision
108
109 foreach (SCR_WorkshopItem item : addonsOutdated)
110 {
111 Revision rev = item.GetLatestRevision();
112 item.SetItemTargetRevision(rev);
113 m_Loader.InsertItem(item);
114 }
115
117
118 m_Loader.GetOnAllPatchSizeLoaded().Insert(OnUpdatePatchSizeLoaded);
119 m_Loader.LoadPatchSizes();
120 }
121
122 //------------------------------------------------------------------------------------------------
123 protected void OnUpdatePatchSizeLoaded(SCR_AddonPatchSizeLoader loader, bool allLoaded)
124 {
125 // Cleanup
126 m_Loader.GetOnAllPatchSizeLoaded().Remove(OnUpdatePatchSizeLoaded);
128 m_LoadingOverlay.Close();
129
131 array<ref SCR_WorkshopItem> addonsOutdated = SCR_AddonManager.SelectItemsBasic(mgr.GetOfflineAddons(), EWorkshopItemQuery.UPDATE_AVAILABLE);
132
133 // Open download confirmation dialog
134 array<ref Tuple2<SCR_WorkshopItem, ref Revision>> addonsAndVersions = {};
135 foreach (SCR_WorkshopItem item : addonsOutdated)
136 {
137 addonsAndVersions.Insert(new Tuple2<SCR_WorkshopItem, ref Revision>(item, item.GetLatestRevision()));
138
139 }
140
141 SCR_AddonUpdateConfirmationDialog dialog = SCR_AddonUpdateConfirmationDialog.CreateForUpdates(addonsAndVersions, false);
142 if (dialog)
143 dialog.m_OnClose.Insert(OnAddonUpdateDialogClose);
144 }
145
146 //------------------------------------------------------------------------------------------------
151
152 //------------------------------------------------------------------------------------------------
153 protected void HandleUpdatesButton()
154 {
156 {
157 m_Widgets.m_UpdateButtonComponent.SetVisible(false);
158 return;
159 }
160
162 array<ref SCR_WorkshopItem> addonsOutdated = {};
163
164 if (mgr)
165 addonsOutdated = SCR_AddonManager.SelectItemsBasic(mgr.GetOfflineAddons(), EWorkshopItemQuery.UPDATE_AVAILABLE);
166
167 int nOutdated;
168
169 foreach (SCR_WorkshopItem item : addonsOutdated)
170 {
171 if (!item.IsDownloadRunning())
172 nOutdated++;
173 }
174
175 m_Widgets.m_UpdateButtonComponent.SetVisible(nOutdated > 0);
176
177 if (nOutdated > 0)
178 m_Widgets.m_UpdateButtonComponent.SetCountText(nOutdated.ToString());
179 }
180
181 //------------------------------------------------------------------------------------------------
182 protected void DisplayFailDialog()
183 {
184 // Check if dialog is not already opened
185 if (m_FailDialog)
186 return;
187
188 array<ref Tuple2<SCR_WorkshopItem, ref Revision>> failed = {};
189 array<ref SCR_WorkshopItemActionDownload> failedActions = SCR_DownloadManager.GetInstance().GetFailedDownloads();
190
191 foreach (SCR_WorkshopItemActionDownload action : failedActions)
192 {
193 SCR_WorkshopItem item = action.m_Wrapper;
194 Revision version = item.GetDependency().GetRevision();
195
196 failed.Insert(new Tuple2<SCR_WorkshopItem, ref Revision>>(item, version));
197 }
198
199 // Setup dialog
200 SCR_DownloadFailDialog dialog = SCR_DownloadFailDialog.CreateFailedAddonsDialog(failed, false);
201 if (!dialog)
202 return;
203
204 m_FailDialog = dialog;
205 m_FailDialog.m_OnConfirm.Insert(Callback_OnFailDialogConfirm);
206 }
207
208 //------------------------------------------------------------------------------------------------
210 {
211 // Clear dialog
212 m_FailDialog.m_OnConfirm.Clear();
213 m_FailDialog.Close();
214 m_FailDialog = null;
216 }
217}
ArmaReforgerScripted GetGame()
Definition game.c:1398
EWorkshopItemQuery
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Constant variables used in various menus.
static ChimeraMenuBase GetOwnerMenu(Widget w)
Returns parent menu of a widget.
array< ref SCR_WorkshopItem > GetOfflineAddons()
Returns array with all offline addons.
static array< ref SCR_WorkshopItem > SelectItemsBasic(array< ref SCR_WorkshopItem > items, EWorkshopItemQuery query)
static int CountItemsAnd(array< ref SCR_WorkshopItem > items, EWorkshopItemQuery query, bool returnOnFirstMatch=false)
Counts items which match query. All flags must match.
SCR_WorkshopAddonManagerPresetStorage GetPresetStorage()
ref ScriptInvoker m_OnAddonsEnabledChanged
static SCR_AddonManager GetInstance()
array< ref SCR_WorkshopItemActionDownload > GetFailedDownloads()
static SCR_DownloadManager GetInstance()
static SCR_LoadingOverlayDialog Create(string text=string.Empty)
static bool IsInTopMenu(notnull Widget componentRoot)
NB: This will return false if the widget is in a DIALOG on top of the MENU!!!
static ScriptInvokerMenu GetOnMenuOpen()
ref SCR_WorkshopAddonBarWidgets m_Widgets
void Callback_OnFailDialogConfirm(SCR_ConfigurableDialogUi dialog)
void OnUsedPresetChanged(string name)
Show actual preset name on preset name change.
void OnAddonUpdateDialogClose(SCR_ConfigurableDialogUi dialog)
static SCR_ConfigurableDialogUi m_FailDialog
void OnUpdatePatchSizeLoaded(SCR_AddonPatchSizeLoader loader, bool allLoaded)
Dependency GetDependency()
SCR_FieldOfViewSettings Attribute