Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
WorkshopItemActions.c
Go to the documentation of this file.
1 /*
2 Specific workshop item actions, inherited from base action class.
3 */
4 
5 //-----------------------------------------------------------------------------------------------
8 {
9  // Optionally it is possible to provide dependencies externally,
10  // In this case only these will be downloaded.
11  ref array<ref SCR_WorkshopItem> m_aProvidedDependencies;
12 
13  //-----------------------------------------------------------------------------------------------
15  void SCR_WorkshopItemActionDownloadDependenciesLatest(SCR_WorkshopItem wrapper, array<ref SCR_WorkshopItem> dependencies)
16  {
17  if (dependencies.Count() > 0)
18  {
19  // Copy the provided dependencies
20  m_aProvidedDependencies = new array<ref SCR_WorkshopItem>;
21  foreach (auto dep : dependencies)
22  m_aProvidedDependencies.Insert(dep);
23 
24  // Create actions for all dependencies
25  #ifdef WORKSHOP_DEBUG
26  _print("New() Creating actions:");
27  #endif
28  m_aActions.Clear();
29  foreach (SCR_WorkshopItem dep : m_aProvidedDependencies)
30  {
31  if (!dep.GetOffline() || dep.GetUpdateAvailable())
32  {
33  #ifdef WORKSHOP_DEBUG
34  _print(string.Format(" Dependency: %1 - Creating action", dep.GetName()));
35  #endif
36 
37  SCR_WorkshopItemAction action = dep.DownloadLatestVersion();
38  m_aActions.Insert(action);
39  }
40  else
41  {
42  #ifdef WORKSHOP_DEBUG
43  _print(string.Format(" Dependency: %1 - Download is not required.", dep.GetName()));
44  #endif
45  }
46  }
47  }
48  }
49 
50  //-----------------------------------------------------------------------------------------------
51  protected override bool OnActivate()
52  {
53  bool success = true;
54 
55  // Activate all created actions
56  foreach (auto action : m_aActions)
57  {
58  if (action.IsPaused())
59  success = success && action.Resume();
60  else if (action.IsInactive())
61  success = success && action.Activate();
62  }
63 
64  return success;
65  }
66 
67  //-----------------------------------------------------------------------------------------------
68  protected override bool OnReactivate()
69  {
70  return OnActivate();
71  }
72 
73  //-----------------------------------------------------------------------------------------------
74  protected override bool OnCancel()
75  {
76  CancelAll();
77  return true;
78  }
79 
80  //-----------------------------------------------------------------------------------------------
81  protected override bool OnPause()
82  {
83  PauseAll();
84  return true;
85  }
86 
87  //-----------------------------------------------------------------------------------------------
88  protected override bool OnResume()
89  {
90  ResumeAll();
91  return true;
92  }
93 
94  //-----------------------------------------------------------------------------------------------
95  override void Internal_Update(float timeSlice)
96  {
97  if (!m_Wrapper)
98  return;
99 
100  // Check if comms have failed
101  if (m_State != STATE_COMPLETED && m_State != STATE_FAILED)
102  {
103  if (m_Wrapper.GetRequestFailed())
104  this.Fail();
105  }
106 
107  // Unregister dependnecy actions which were canceled
108  array<SCR_WorkshopItemAction> removeActions = new array<SCR_WorkshopItemAction>;
109  foreach (SCR_WorkshopItemAction action : m_aActions)
110  {
111  if (action.IsCanceled() || action.IsPaused() || action.IsFailed()) // todo should paused actions be removed too?
112  removeActions.Insert(action);
113  }
114  UnregisterActions(removeActions);
115 
116  // Complete when all actions are completed
117  if (AllCompleted())
118  {
119  this.Complete();
120  }
121  }
122 };
123 
124 //-----------------------------------------------------------------------------------------------
127 {
128  ref SCR_WorkshopCallbackBase m_Callback;
129 
130  //-----------------------------------------------------------------------------------------------
131  protected bool OnActivateInternal();
132 
133  //-----------------------------------------------------------------------------------------------
134  protected override bool OnActivate()
135  {
137  m_Callback.m_OnTimeout.Insert(Callback_OnTimeout);
138  m_Callback.m_OnError.Insert(Callback_OnError);
139  m_Callback.m_OnSuccess.Insert(Callback_OnSuccess);
140 
141  bool success = OnActivateInternal();
142  return success;
143  }
144 
145 
146  //-----------------------------------------------------------------------------------------------
147  protected override bool OnReactivate()
148  {
149  return this.OnActivate();
150  }
151 
152  //-----------------------------------------------------------------------------------------------
153  protected void Callback_OnError()
154  {
155  Fail();
156  SCR_CommonDialogs.CreateRequestErrorDialog();
157  }
158 
159  //-----------------------------------------------------------------------------------------------
160  protected void Callback_OnTimeout()
161  {
162  Fail();
163  SCR_CommonDialogs.CreateTimeoutOkDialog();
164  }
165 
166  //-----------------------------------------------------------------------------------------------
167  protected void Callback_OnSuccess()
168  {
169  this.Complete();
170  }
171 };
172 
173 //-----------------------------------------------------------------------------------------------
176 {
177  protected EWorkshopReportType m_eReportType;
178  protected string m_sMessage;
179 
180  //-----------------------------------------------------------------------------------------------
181  void SCR_WorkshopItemActionReport(SCR_WorkshopItem wrapper, EWorkshopReportType eReport, string sMessage)
182  {
183  m_eReportType = eReport;
184  m_sMessage = sMessage;
185  }
186 
187 
188  //-----------------------------------------------------------------------------------------------
189  protected override bool OnActivateInternal()
190  {
191  return m_Wrapper.Internal_Report(m_eReportType, m_sMessage, m_Callback);
192  }
193 };
194 
195 
196 
197 //-----------------------------------------------------------------------------------------------
200 {
201  protected override bool OnActivateInternal()
202  {
203  return m_Wrapper.Internal_CancelReport(m_Callback);
204  }
205 };
206 
207 
208 //-----------------------------------------------------------------------------------------------
211 {
212  protected override bool OnActivateInternal()
213  {
214  return m_Wrapper.Internal_AddAuthorBlock(m_Callback);
215  }
216 };
217 
218 //-----------------------------------------------------------------------------------------------
221 {
222  protected override bool OnActivateInternal()
223  {
224  return m_Wrapper.Internal_RemoveAuthorBlock(m_Callback);
225  }
226 };
_print
void _print(string s)
Definition: SCR_ModularButtonComponent.c:665
SCR_WorkshopItemActionAddAuthorBlock
Action for blocking author.
Definition: WorkshopItemActions.c:210
m_aActions
ref SCR_SortedArray< SCR_BaseEditorAction > m_aActions
Definition: SCR_BaseActionsEditorComponent.c:8
SCR_CommonDialogs
Definition: CommonDialogs.c:5
m_Callback
protected ref CampaignCallback m_Callback
Definition: SCR_PlayerProfileManagerComponent.c:25
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
SCR_WorkshopItemActionDownloadDependenciesLatest
Action for downloading latest dependencies. Doesn't download this addon, but only downloads dependenc...
Definition: WorkshopItemActions.c:7
SCR_WorkshopItemActionCancelReport
Action for canceling report of an item.
Definition: WorkshopItemActions.c:199
SCR_WorkshopItemActionRemoveAuthorBlock
Action for removing author mod content blocking.
Definition: WorkshopItemActions.c:220
SCR_WorkshopItemActionReportBase
Action for reporting an item.
Definition: WorkshopItemActions.c:126
SCR_WorkshopCallbackBase
Definition: SCR_OnlineServiceWorkshop.c:101
SCR_WorkshopItemAction
Definition: SCR_WorkshopItemAction.c:16
m_State
private EEditableEntityState m_State
Definition: SCR_BaseEntitiesEditorUIEffect.c:3
SCR_WorkshopItemActionReport
Action for reporting an item.
Definition: WorkshopItemActions.c:175
SCR_WorkshopItemActionComposite
Composite action which includes multiple subactions.
Definition: SCR_WorkshopItemAction.c:408