Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DownloadManagerListComponent.c
Go to the documentation of this file.
4
6{
7 [Attribute("m_AddonsList")]
8 protected string m_sList;
9
10 [Attribute("m_FallbackTextWrap")]
11 protected string m_sFallbackTextWrapWidget;
12
13 [Attribute()]
14 protected ref array<ref SCR_DownloadManagerListCategory> m_aCategories;
15
17 protected Widget m_wList;
19
24
25 protected ref array<ref SCR_DownloadManagerEntry> m_aAddonLines = {};
26
27 protected bool m_bAllPaused = false;
28
30
31 //------------------------------------------------------------------------------------------------
32 override void HandlerAttached(Widget w)
33 {
34 super.HandlerAttached(w);
35
36 m_ScrollLayout = ScrollLayoutWidget.Cast(w.FindAnyWidget("ScrollLayout"));
37 m_wList = w.FindAnyWidget(m_sList);
39 }
40
41 //------------------------------------------------------------------------------------------------
42 override void OnTabShow()
43 {
44 super.OnTabShow();
45
47
48 // Show fallback if list is empty
49 ShowFallbackText(m_wList.GetChildren() == null);
50
51 GetGame().GetCallqueue().Call(FocusFirstLine);
52 }
53
54 //------------------------------------------------------------------------------------------------
55 override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
56 {
57 super.OnTabCreate(menuRoot, buttonsLayout, index);
58
59 m_NavPauseResume = CreateNavigationButton("WorkshopPauseDownload", "#AR-Workshop_ButtonResume", true, false);
60 m_NavPauseResume.m_OnActivated.Insert(OnClickPauseResume);
61
62 m_NavCancel = CreateNavigationButton("WorkshopCancelDownload", "#AR-Keybind_Cancel", true, false);
63 m_NavCancel.m_OnActivated.Insert(OnClickCancel);
64
65 m_NavRetry = CreateNavigationButton("WorkshopPauseDownload", "#AR-Workshop_ButtonTryAgain", true, false);
66 m_NavRetry.m_OnActivated.Insert(OnClickRetry);
67
68 m_NavPauseResumeAll = CreateNavigationButton("WorkshopPauseAllDownloads", "#AR-DownloadManager_ButtonPauseAll", false);
69 m_NavPauseResumeAll.m_OnActivated.Insert(OnClickPauseResumeAll);
70 }
71
72 //------------------------------------------------------------------------------------------------
73 override void OnMenuFocusGained()
74 {
75 super.OnMenuFocusGained();
76
77 GetGame().GetCallqueue().Call(FocusFirstLine);
78 }
79
80 //------------------------------------------------------------------------------------------------
83 {
84 if (!m_wList || !entryPath)
85 {
86 Print("List widget or widgte resource wasn't set properly!", LogLevel.WARNING);
87 return null;
88 }
89
90 // Create new entry
91 Widget entry = GetGame().GetWorkspace().CreateWidgets(entryPath, m_wList);
92 LayoutSlot.SetHorizontalAlign(entry, LayoutHorizontalAlign.Stretch);
93
94 // Add addon line comp
96 btn.m_OnFocus.Insert(OnEntryFocus);
98
100 entryComp.InitForDownloadAction(action.GetWorkshopItem(), action);
101 m_aAddonLines.Insert(entryComp);
102
103 ShowFallbackText(false);
104
105 // Set category z order
107
108 for (int i = 0, count = m_aCategories.Count(); i < count; i++)
109 {
110 if (m_aCategories[i].m_iType == type)
111 {
112 entry.SetZOrder(m_aCategories[i].m_iZOrder);
113 return entry;
114 }
115 }
116
117 // No z order warning!
118 Print(string.Format("No Z order found for type: %1!", typename.EnumToString(EDownloadManagerActionState, type)), LogLevel.WARNING);
119
120 return entry;
121 }
122
123 //------------------------------------------------------------------------------------------------
126 {
127 if (entry.GetParent() != m_wList)
128 {
129 Print("Selected entry is not part of list!", LogLevel.WARNING);
130 return;
131 }
132
133 int categoryZOrder = -1;
134
135 // Find category
136 for (int i = 0, count = m_aCategories.Count(); i < count; i++)
137 {
138 if (m_aCategories[i].m_iType == type)
139 {
140 categoryZOrder = m_aCategories[i].m_iZOrder;
141 break;
142 }
143 }
144
145 // Move to category widget
146 if (categoryZOrder != -1)
147 entry.SetZOrder(categoryZOrder);
148 }
149
150 //------------------------------------------------------------------------------------------------
152 {
153 m_wList.RemoveChild(entry.GetRootWidget());
154 m_aAddonLines.RemoveItem(entry);
155 }
156
157 //------------------------------------------------------------------------------------------------
160 {
162 {
163 if (entry.GetDownloadAction() == action)
164 return entry;
165 }
166
167 return null;
168 }
169
170 //------------------------------------------------------------------------------------------------
173 {
174 for (int i = 0, count = m_aAddonLines.Count(); i < count; i++)
175 {
176 if (m_aAddonLines[i].GetItem() == item)
177 return m_aAddonLines[i];
178 }
179
180 return null;
181 }
182
183 //---------------------------------------------------------------------------------------------------
186 {
187 Widget focused = GetGame().GetWorkspace().GetFocusedWidget();
188 if (!focused)
189 return null;
190
191 return SCR_DownloadManagerEntry.Cast(focused.FindHandler(SCR_DownloadManagerEntry));
192 }
193
194 //------------------------------------------------------------------------------------------------
200
201 //------------------------------------------------------------------------------------------------
202 void ShowFallbackText(bool show)
203 {
205 m_wFallbackTextWrap.SetVisible(show);
206 }
207
208 //------------------------------------------------------------------------------------------------
211 {
212 return m_wList.GetChildren() != null;
213 }
214
215 //------------------------------------------------------------------------------------------------
216 // Callbacks
217 //------------------------------------------------------------------------------------------------
218 //------------------------------------------------------------------------------------------------
219 protected void OnEntryFocus()
220 {
222
223 // Setup change callback
224 m_FocusedEntry = entry;
225 m_FocusedEntry.GetOnUpdate().Insert(UpdateNavButtons);
226
228 }
229
230 //------------------------------------------------------------------------------------------------
231 protected void OnEntryFocusLost()
232 {
233 if (m_FocusedEntry)
234 m_FocusedEntry.GetOnUpdate().Remove(UpdateNavButtons);
235 }
236
237 //------------------------------------------------------------------------------------------------
239 {
240 // Setup button visibility
244
245 // Check current entry
246 if (!entry)
247 return;
248
249 bool pause, resume, cancel, retry;
250 entry.CanDoActions(pause, resume, cancel, retry);
251
252 // Pause and resume
254 m_NavPauseResume.SetEnabled(entry.GetPauseEnabled());
255
256 if (resume)
257 m_NavPauseResume.SetLabel("#AR-DownloadManager_ButtonResume");
258 else
259 m_NavPauseResume.SetLabel("#AR-DownloadManager_ButtonPause");
260
261 // Cancel
263
264 // Retry
266 }
267
268 //------------------------------------------------------------------------------------------------
269 protected void OnClickPauseResume()
270 {
272 if (!entry)
273 return;
274
275 if (entry.GetDownloadAction().IsPaused())
276 entry.OnClickResume();
277 else
278 entry.OnClickPause();
279 }
280
281 //------------------------------------------------------------------------------------------------
282 protected void OnClickCancel()
283 {
285 if (entry)
286 entry.OnClickCancel();
287 }
288
289 //------------------------------------------------------------------------------------------------
290 protected void OnClickRetry()
291 {
293 if (!entry)
294 return;
295
296 entry.OnClickRetry();
297 }
298
299 //------------------------------------------------------------------------------------------------
300 protected void OnClickPauseResumeAll()
301 {
302 for (int i = 0, count = m_aAddonLines.Count(); i < count; i++)
303 {
304 // Pause all
305 if (!m_bAllPaused)
306 {
307 if (!m_aAddonLines[i].GetDownloadAction().IsPaused())
308 m_aAddonLines[i].OnClickPause();
309
310 continue;
311 }
312
313 // Resume all
314 if (m_aAddonLines[i].GetDownloadAction().IsPaused())
315 m_aAddonLines[i].OnClickResume();
316 }
317
319
320 if (m_bAllPaused)
321 m_NavPauseResumeAll.SetLabel("#AR-DownloadManager_ButtonResumeAll");
322 else
323 m_NavPauseResumeAll.SetLabel("#AR-DownloadManager_ButtonPauseAll");
324
325 // Disable and enable later to prevent pause/resume request spamming
326 m_NavPauseResumeAll.SetEnabled(false);
327 GetGame().GetCallqueue().CallLater(EnablePauseResumeAll, SCR_DownloadManagerEntry.PAUSE_ENABLE_DELAY_MS);
328 }
329
330 //------------------------------------------------------------------------------------------------
331 protected void EnablePauseResumeAll()
332 {
333 m_NavPauseResumeAll.SetEnabled(true);
334 }
335
336 //------------------------------------------------------------------------------------------------
337 protected void FocusFirstLine()
338 {
339 if (m_aAddonLines.IsEmpty())
340 return;
341
342 GetGame().GetWorkspace().SetFocusedWidget(m_aAddonLines[0].GetRootWidget());
343
344 if (m_ScrollLayout)
345 m_ScrollLayout.SetSliderPos(0, 0);
346 }
347}
348
349//------------------------------------------------------------------------------------------------
350[BaseContainerProps(configRoot: true)]
351class SCR_DownloadManagerListCategory
353 // Using z order until it's possible to change widget parent
354 [Attribute()]
355 int m_iZOrder;
356
357 [Attribute("0", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EDownloadManagerActionState))]
359}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_WorkshopItem GetItem()
EDamageType type
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
EDownloadManagerActionState
Enum describing current state of downloading action.
Base class for any button, regardless its own content.
ref ScriptInvoker< Widget > m_OnFocusLost
ref ScriptInvoker< Widget > m_OnFocus
void OnClickRetry()
void InitForDownloadAction(SCR_WorkshopItem item, SCR_WorkshopItemActionDownload action)
void OnClickResume()
void CanDoActions(out bool canPause, out bool canResume, out bool canCancel, out bool canRetry)
Store which actions can be used for entry in current state.
void OnClickPause()
bool GetPauseEnabled()
static EDownloadManagerActionState DownloadActionState(SCR_WorkshopItemActionDownload action)
void OnClickCancel()
SCR_WorkshopItemActionDownload GetDownloadAction()
void RemoveEntry(notnull SCR_DownloadManagerEntry entry)
void ChangeEntryCategory(notnull Widget entry, EDownloadManagerActionState type)
Change widget in category based based on category type.
bool HasContent()
Return true if there are entries in list.
SCR_DownloadManagerEntry DownloadActionLine(notnull SCR_WorkshopItemActionDownload action)
Find line containing selected download action.
void UpdateNavButtons(SCR_DownloadManagerEntry entry)
SCR_DownloadManagerEntry FocusedEntry()
Return addon preset line component of currently focused widget if has any.
SCR_DownloadManagerEntry EntryWithItem(notnull SCR_WorkshopItem item)
Find line containing selected item.
ref array< ref SCR_DownloadManagerEntry > m_aAddonLines
Widget AddEntry(ResourceName entryPath, SCR_WorkshopItemActionDownload action)
Add new widget in category based based on category type.
ref array< ref SCR_DownloadManagerListCategory > m_aCategories
override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
SCR_InputButtonComponent CreateNavigationButton(string actionName, string label, bool rightFooter=false, bool show=true)
void SetNavigationButtonVisible(SCR_InputButtonComponent button, bool show, bool animate=false)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
LayoutHorizontalAlign