Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DownloadManagerListComponent.c
Go to the documentation of this file.
1 
6 {
7  [Attribute("m_AddonsList")]
8  protected string m_sList;
9 
10  [Attribute("m_FallbackTextWrap")]
11  protected string m_sFallbackTextWrapWidget;
12 
14  protected ref array<ref SCR_DownloadManagerListCategory> m_aCategories;
15 
16  protected ScrollLayoutWidget m_ScrollLayout;
17  protected Widget m_wList;
18  protected Widget m_wFallbackTextWrap;
19 
20  protected SCR_InputButtonComponent m_NavPauseResume;
21  protected SCR_InputButtonComponent m_NavPauseResumeAll;
22  protected SCR_InputButtonComponent m_NavCancel;
23  protected SCR_InputButtonComponent m_NavRetry;
24 
25  protected ref array<ref SCR_DownloadManagerEntry> m_aAddonLines = {};
26 
27  protected bool m_bAllPaused = false;
28 
29  protected SCR_DownloadManagerEntry m_FocusedEntry;
30 
31  //------------------------------------------------------------------------------------------------
32  override void HandlerAttached(Widget w)
33  {
34  super.HandlerAttached(w);
35 
36  m_ScrollLayout = ScrollLayoutWidget.Cast(w);
37  m_wList = w.FindAnyWidget(m_sList);
38  m_wFallbackTextWrap = w.FindAnyWidget(m_sFallbackTextWrapWidget);
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  override void OnTabShow()
43  {
44  super.OnTabShow();
45 
46  UpdateNavButtons(m_FocusedEntry);
47 
48  // Show fallback if list is empty
49  ShowFallbackText(m_wList.GetChildren() == null);
50 
51  GetGame().GetWorkspace().SetFocusedWidget(null);
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  //------------------------------------------------------------------------------------------------
74  Widget AddEntry(ResourceName entryPath, SCR_WorkshopItemActionDownload action)
75  {
76  if (!m_wList || !entryPath)
77  {
78  Print("List widget or widgte resource wasn't set properly!", LogLevel.WARNING);
79  return null;
80  }
81 
82  // Create new entry
83  Widget entry = GetGame().GetWorkspace().CreateWidgets(entryPath, m_wList);
84  LayoutSlot.SetHorizontalAlign(entry, LayoutHorizontalAlign.Stretch);
85 
86  // Add addon line comp
88  btn.m_OnFocus.Insert(OnEntryFocus);
89  btn.m_OnFocusLost.Insert(OnEntryFocusLost);
90 
92  entryComp.InitForDownloadAction(action.GetWorkshopItem(), action);
93  m_aAddonLines.Insert(entryComp);
94 
95  ShowFallbackText(false);
96 
97  // Set category z order
98  EDownloadManagerActionState type = SCR_DownloadManagerEntry.DownloadActionState(action);
99 
100  for (int i = 0, count = m_aCategories.Count(); i < count; i++)
101  {
102  if (m_aCategories[i].m_iType == type)
103  {
104  entry.SetZOrder(m_aCategories[i].m_iZOrder);
105  return entry;
106  }
107  }
108 
109  // No z order warning!
110  Print(string.Format("No Z order found for type: %1!", typename.EnumToString(EDownloadManagerActionState, type)), LogLevel.WARNING);
111 
112  return entry;
113  }
114 
115  //------------------------------------------------------------------------------------------------
117  void ChangeEntryCategory(notnull Widget entry, EDownloadManagerActionState type)
118  {
119  if (entry.GetParent() != m_wList)
120  {
121  Print("Selected entry is not part of list!", LogLevel.WARNING);
122  return;
123  }
124 
125  int categoryZOrder = -1;
126 
127  // Find category
128  for (int i = 0, count = m_aCategories.Count(); i < count; i++)
129  {
130  if (m_aCategories[i].m_iType == type)
131  {
132  categoryZOrder = m_aCategories[i].m_iZOrder;
133  break;
134  }
135  }
136 
137  // Move to category widget
138  if (categoryZOrder != -1)
139  entry.SetZOrder(categoryZOrder);
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  void RemoveEntry(notnull SCR_DownloadManagerEntry entry)
144  {
145  m_wList.RemoveChild(entry.GetRootWidget());
146  m_aAddonLines.RemoveItem(entry);
147  }
148 
149  //------------------------------------------------------------------------------------------------
151  SCR_DownloadManagerEntry DownloadActionLine(notnull SCR_WorkshopItemActionDownload action)
152  {
153  for (int i = 0, count = m_aAddonLines.Count(); i < count; i++)
154  {
155  if (m_aAddonLines[i].GetDownloadAction() == action)
156  return m_aAddonLines[i];
157  }
158 
159  return null;
160  }
161 
162  //------------------------------------------------------------------------------------------------
164  SCR_DownloadManagerEntry EntryWithItem(notnull SCR_WorkshopItem item)
165  {
166  for (int i = 0, count = m_aAddonLines.Count(); i < count; i++)
167  {
168  if (m_aAddonLines[i].GetItem() == item)
169  return m_aAddonLines[i];
170  }
171 
172  return null;
173  }
174 
175  //---------------------------------------------------------------------------------------------------
177  SCR_DownloadManagerEntry FocusedEntry()
178  {
179  Widget focused = GetGame().GetWorkspace().GetFocusedWidget();
180  if (!focused)
181  return null;
182 
183  return SCR_DownloadManagerEntry.Cast(focused.FindHandler(SCR_DownloadManagerEntry));
184  }
185 
186  //------------------------------------------------------------------------------------------------
187  void ScrollTop()
188  {
189  if (m_ScrollLayout)
190  m_ScrollLayout.SetSliderPos(0, 0);
191  }
192 
193  //------------------------------------------------------------------------------------------------
194  void ShowPauseResumeAllButton(bool show)
195  {
196  if (m_NavPauseResumeAll)
197  SetNavigationButtonVisibile(m_NavPauseResumeAll, show);
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  void ShowFallbackText(bool show)
202  {
203  if (m_wFallbackTextWrap)
204  m_wFallbackTextWrap.SetVisible(show);
205  }
206 
207  //------------------------------------------------------------------------------------------------
209  bool HasContent()
210  {
211  return m_wList.GetChildren() != null;
212  }
213 
214  //------------------------------------------------------------------------------------------------
215  // Callbacks
216  //------------------------------------------------------------------------------------------------
217  //------------------------------------------------------------------------------------------------
218  protected void OnEntryFocus()
219  {
220  SCR_DownloadManagerEntry entry = FocusedEntry();
221 
222  // Setup change callback
223  m_FocusedEntry = entry;
224  m_FocusedEntry.GetOnUpdate().Insert(UpdateNavButtons);
225 
226  UpdateNavButtons(m_FocusedEntry);
227  }
228 
229  //------------------------------------------------------------------------------------------------
230  protected void OnEntryFocusLost()
231  {
232  if (m_FocusedEntry)
233  m_FocusedEntry.GetOnUpdate().Remove(UpdateNavButtons);
234  }
235 
236  //------------------------------------------------------------------------------------------------
237  protected void UpdateNavButtons(SCR_DownloadManagerEntry entry)
238  {
239  // Setup button visibility
240  SetNavigationButtonVisibile(m_NavPauseResume, entry != null);
241  SetNavigationButtonVisibile(m_NavCancel, entry != null);
242  SetNavigationButtonVisibile(m_NavRetry, entry != null);
243 
244  // Check current entry
245  if (!entry)
246  return;
247 
248  bool pause, resume, cancel, retry;
249  entry.CanDoActions(pause, resume, cancel, retry);
250 
251  // Pause and resume
252  SetNavigationButtonVisibile(m_NavPauseResume, pause || resume);
253  m_NavPauseResume.SetEnabled(entry.GetPauseEnabled());
254 
255  if (resume)
256  m_NavPauseResume.SetLabel("#AR-DownloadManager_ButtonResume");
257  else
258  m_NavPauseResume.SetLabel("#AR-DownloadManager_ButtonPause");
259 
260  // Cancel
261  SetNavigationButtonVisibile(m_NavCancel, cancel);
262 
263  // Retry
264  SetNavigationButtonVisibile(m_NavRetry, retry);
265  }
266 
267  //------------------------------------------------------------------------------------------------
268  protected void OnClickPauseResume()
269  {
270  SCR_DownloadManagerEntry entry = FocusedEntry();
271  if (!entry)
272  return;
273 
274  if (entry.GetDownloadAction().IsPaused())
275  entry.OnClickResume();
276  else
277  entry.OnClickPause();
278  }
279 
280  //------------------------------------------------------------------------------------------------
281  protected void OnClickCancel()
282  {
283  SCR_DownloadManagerEntry entry = FocusedEntry();
284  if (entry)
285  entry.OnClickCancel();
286  }
287 
288  //------------------------------------------------------------------------------------------------
289  protected void OnClickRetry()
290  {
291  SCR_DownloadManagerEntry entry = FocusedEntry();
292  if (!entry)
293  return;
294 
295  entry.OnClickRetry();
296  }
297 
298  //------------------------------------------------------------------------------------------------
299  protected void OnClickPauseResumeAll()
300  {
301  for (int i = 0, count = m_aAddonLines.Count(); i < count; i++)
302  {
303  // Pause all
304  if (!m_bAllPaused)
305  {
306  if (!m_aAddonLines[i].GetDownloadAction().IsPaused())
307  m_aAddonLines[i].OnClickPause();
308 
309  continue;
310  }
311 
312  // Resume all
313  if (m_aAddonLines[i].GetDownloadAction().IsPaused())
314  m_aAddonLines[i].OnClickResume();
315  }
316 
318 
319  if (m_bAllPaused)
320  m_NavPauseResumeAll.SetLabel("#AR-DownloadManager_ButtonResumeAll");
321  else
322  m_NavPauseResumeAll.SetLabel("#AR-DownloadManager_ButtonPauseAll");
323 
324  // Disable and enable later to prevent pause/resume request spamming
325  m_NavPauseResumeAll.SetEnabled(false);
326  GetGame().GetCallqueue().CallLater(EnablePauseResumeAll, SCR_DownloadManagerEntry.PAUSE_ENABLE_DELAY_MS);
327  }
328 
329  //------------------------------------------------------------------------------------------------
330  protected void EnablePauseResumeAll()
331  {
332  m_NavPauseResumeAll.SetEnabled(true);
333  }
334 }
335 
336 //------------------------------------------------------------------------------------------------
337 [BaseContainerProps(configRoot: true)]
338 class SCR_DownloadManagerListCategory
339 {
340  // Using z order until it's possible to change widget parent
341  [Attribute()]
342  int m_iZOrder;
343 
344  [Attribute("0", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EDownloadManagerActionState))]
346 }
BaseContainerProps
SCR_DownloadManagerListComponent SCR_SubMenuBase BaseContainerProps(configRoot:true)
Definition: SCR_DownloadManagerListComponent.c:337
m_ScrollLayout
protected ScrollLayoutWidget m_ScrollLayout
Definition: SCR_DownloadManagerListComponent.c:11
EDownloadManagerActionState
EDownloadManagerActionState
Enum describing current state of downloading action.
Definition: SCR_DownloadManager.c:846
SCR_DownloadManagerListComponent
Definition: SCR_DownloadManagerListComponent.c:5
m_NavCancel
protected SCR_InputButtonComponent m_NavCancel
Definition: SCR_DownloadManagerListComponent.c:17
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_WorkshopItemActionDownload
Definition: SCR_WorkshopItemActionDownload.c:9
m_NavRetry
protected SCR_InputButtonComponent m_NavRetry
Definition: SCR_DownloadManagerListComponent.c:18
m_aAddonLines
protected ref array< ref SCR_DownloadManagerEntry > m_aAddonLines
Definition: SCR_DownloadManagerListComponent.c:20
SCR_SubMenuBase
Definition: SCR_SubMenuBase.c:6
m_bAllPaused
protected bool m_bAllPaused
Definition: SCR_DownloadManagerListComponent.c:22
m_NavPauseResumeAll
protected SCR_InputButtonComponent m_NavPauseResumeAll
Definition: SCR_DownloadManagerListComponent.c:16
m_wList
protected Widget m_wList
Definition: SCR_DownloadManagerListComponent.c:12
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
SCR_DownloadManagerEntry
Definition: SCR_DownloadManagerEntry.c:10
m_FocusedEntry
protected SCR_DownloadManagerEntry m_FocusedEntry
Definition: SCR_DownloadManagerListComponent.c:24
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
m_NavPauseResume
protected SCR_InputButtonComponent m_NavPauseResume
Definition: SCR_DownloadManagerListComponent.c:15
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
GetItem
SCR_WorkshopItem GetItem()
Definition: SCR_AddonPatchSizeLoader.c:143
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
m_aCategories
protected ref array< ref SCR_DownloadManagerListCategory > m_aCategories
Definition: SCR_DownloadManagerListComponent.c:9
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
m_wFallbackTextWrap
protected Widget m_wFallbackTextWrap
Definition: SCR_DownloadManagerListComponent.c:13