Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ReportedAddonsDialog.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
4 {
5  /*
6  protected const ResourceName ADDON_LINE_INTERACTIVE_LAYOUT = "{0C4FAA01F4F56A90}UI/layouts/Menus/ContentBrowser/DownloadManager/DonwloadManager_AddonDownloadLineReport.layout";
7  protected const ResourceName AUTHOR_LINE = "{EF800FBBEA32B027}UI/layouts/Menus/Common/SimpleEntryInteractive.layout";
8  */
9 
10  protected const ResourceName LINE_LAYOUT = "{6D73127FB096229D}UI/layouts/Menus/ContentBrowser/DownloadManager/ReportedAddonEntry.layout";
11 
12  protected const ResourceName DIALOGS_CONFIG = "{ADEA32EB841E8629}Configs/ContentBrowser/ContentBrowserReportDialogs.conf";
13  protected const string AUTHOR_REPORT_TAG = "report_author";
14  protected const string AUTHOR_UNBLOCK_TAG = "unblock_author_simple";
15 
16  protected const string MSG_REPORTED = "#AR-Workshop_State_Reported";
17  protected const string MSG_BANNED = "#AR-Workshop_State_Banned";
18  protected const string MSG_AUTHOR = "#AR-Workshop_FilterCategory_Author";
19  protected const string STR_FIXED_REPORT = "#AR-Workshop_Dialog_Success";
20 
21  protected const string WIDGET_DETAIL = "TxtDetailType";
22  protected const string WIDGET_MESSAGE = "TxtDetailMessage";
23 
24  protected const string BUTTON_CANCEL_REPORT = "cancelReport";
25 
26  protected const int AUTHOR_MOD_LIMIT = 20;
27 
28  protected ref ScriptInvoker<SCR_ReportedAddonsDialog> Event_OnAllReportsCanceled;
29  protected bool m_bBlocked;
30 
31  // Widgets
32  protected TextWidget m_wTxtType;
33  protected TextWidget m_wTxtMessage;
34  protected SCR_InputButtonComponent m_NavCancelReport;
35  protected Widget m_wList;
36 
37  protected SCR_LoadingOverlayDialog m_LoadingOvelay;
38  protected ref SCR_CancelMyReportDialog m_DialogCancelReport;
39 
40  //protected SCR_WorkshopItem m_ItemFocused;
41  protected SCR_ModularButtonComponent m_LineFocused;
42 
43  //protected ref array<SCR_ModularButtonComponent> m_aButtons = new array<SCR_ModularButtonComponent>();
44 
45  protected ref map<SCR_ModularButtonComponent, SCR_WorkshopItem> m_mButtonsItems;
46  protected ref map<SCR_ModularButtonComponent, WorkshopAuthor> m_mButtonsAuthors;
47 
48  protected WorkshopAuthor m_LoadingAuthor;
49  protected ref SCR_BackendCallback m_ReportCallback = new SCR_BackendCallback();
50 
51  //------------------------------------------------------------------------------------------------
52  // Override API
53  //------------------------------------------------------------------------------------------------
54 
55  //------------------------------------------------------------------------------------------------
56  override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
57  {
58  m_mButtonsItems = new map<SCR_ModularButtonComponent, SCR_WorkshopItem>();
59  m_mButtonsAuthors = new map<SCR_ModularButtonComponent, WorkshopAuthor>();
60 
61  m_wList = VerticalLayoutWidget.Cast(GetRootWidget().FindAnyWidget("AddonList"));
62 
63  // Find widgets
64  m_wTxtType = TextWidget.Cast(GetRootWidget().FindAnyWidget(WIDGET_DETAIL));
65  m_wTxtMessage = TextWidget.Cast(GetRootWidget().FindAnyWidget(WIDGET_MESSAGE));
66 
67  SetupReports();
68 
69  FocusTopLine();
70 
71  SCR_InputButtonComponent button = FindButton(BUTTON_CANCEL_REPORT);
72  if (button)
73  {
74  button.m_OnActivated.Clear();
75  button.m_OnActivated.Insert(OnCancelReport);
76  }
77  }
78 
79  //------------------------------------------------------------------------------------------------
82  protected void SetupReports()
83  {
84  ref array<WorkshopAuthor> blockedAuthors = {};
85 
86  foreach (SCR_WorkshopItem item : m_aItems)
87  {
88  // Are there blocked/banned addons by serice?
89  if (item.GetBlocked())
90  {
91  CreateAddonEntry(item);
92  m_bBlocked = true;
93  continue;
94  }
95 
96  // Author blocks
97  if (item.GetModAuthorReportedByMe())
98  {
99  // Save reported author
100  WorkshopAuthor author = item.GetWorkshopItem().Author();
101 
102  if (!blockedAuthors.Contains(author))
103  {
104  // Add author entry
105  blockedAuthors.Insert(author);
106  CreateAuthorEntry(author);
107  }
108  }
109 
110  // Report by player
111  if (item.GetReportedByMe())
112  CreateAddonEntry(item);
113  }
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  protected override void OnConfirm()
118  {
119  OnCancelReportActived();
120  m_OnConfirm.Invoke(this);
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  // Protected API
125  //------------------------------------------------------------------------------------------------
126 
127  //------------------------------------------------------------------------------------------------
129  protected SCR_ModularButtonComponent CreateEntry(string name, string message)
130  {
131  Widget entry = GetGame().GetWorkspace().CreateWidgets(LINE_LAYOUT, m_wList);
132 
134  comp.SetMessages(name, message);
135 
136  // Find button comp
137  SCR_ModularButtonComponent button = SCR_ModularButtonComponent.Cast(entry.FindHandler(SCR_ModularButtonComponent));
138  if (!button)
139  return null;
140 
141  // Callback
142  button.m_OnFocus.Insert(OnAddonLineFocus);
143 
144  return button;
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  // Addon report
149  //------------------------------------------------------------------------------------------------
150 
151  //------------------------------------------------------------------------------------------------
153  protected void CreateAddonEntry(notnull SCR_WorkshopItem item)
154  {
155  // Msg
156  string msg = MSG_REPORTED;
157 
158  if (item.GetBlocked())
159  msg = MSG_BANNED;
160 
161  // Line
162  SCR_ModularButtonComponent button = CreateEntry(item.GetName(), msg);
163  m_mButtonsItems.Insert(button, item);
164 
165  // Callbacks
166  button.m_OnDoubleClicked.Insert(OnAddonEntrySelected);
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  protected void OnAddonEntrySelected(SCR_ModularButtonComponent button)
171  {
172  SCR_WorkshopItem item;
173  m_mButtonsItems.Find(button, item);
174 
175  if (!item)
176  Print("Item wasn't found or set!");
177 
178  // Load
179  item.m_OnMyReportLoaded.Insert(OnAddonReportLoadSuccess);
180  item.m_OnError.Insert(OnAddonReportLoadError);
181  item.m_OnTimeout.Insert(OnAddonReportLoadError);
182  item.LoadReport();
183 
184  // Show load UI
185  m_LoadingOvelay = SCR_LoadingOverlayDialog.Create();
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  protected void OnAddonReportLoadSuccess(SCR_WorkshopItem item)
190  {
191  // Cleanup
192  item.m_OnMyReportLoaded.Remove(OnAddonReportLoadSuccess);
193  item.m_OnError.Remove(OnAddonReportLoadError);
194  item.m_OnTimeout.Remove(OnAddonReportLoadError);
195 
196  m_LoadingOvelay.Close();
197 
198  // Setup dialog and callbacks
199  m_DialogCancelReport = new SCR_CancelMyReportDialog(item);
200 
201  if (m_DialogCancelReport)
202  {
203  m_DialogCancelReport.m_OnConfirm.Insert(OnCancelReportConfirm);
204  m_DialogCancelReport.m_OnClose.Insert(OnCancelReportDialog);
205  m_DialogCancelReport.m_OnClose.Insert(OnReportDialogClose);
206  }
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  protected void OnAddonReportLoadError(SCR_WorkshopItem item)
211  {
212  // Cleanup
213  item.m_OnMyReportLoaded.Remove(OnAddonReportLoadSuccess);
214  item.m_OnError.Remove(OnAddonReportLoadError);
215  item.m_OnTimeout.Remove(OnAddonReportLoadError);
216 
217  m_LoadingOvelay.Close();
218  }
219 
220  //------------------------------------------------------------------------------------------------
221  // Author report
222  //------------------------------------------------------------------------------------------------
223 
224  //------------------------------------------------------------------------------------------------
226  protected void CreateAuthorEntry(notnull WorkshopAuthor author)
227  {
228  SCR_ModularButtonComponent button = CreateEntry(author.Name(), MSG_AUTHOR);
229  m_mButtonsAuthors.Insert(button, author);
230 
231  // Callbacks
232  button.m_OnDoubleClicked.Insert(OnAuthorEntrySelected);
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  protected void OnAuthorEntrySelected(SCR_ModularButtonComponent button)
237  {
238  m_mButtonsAuthors.Find(button, m_LoadingAuthor);
239 
240  if (!m_LoadingAuthor)
241  Print("Author wasn't found or set!");
242 
243  // Request author addons - TODO: restore when fix is ready
244  /*
245  PageParams params = new PageParams();
246  params.limit = AUTHOR_MOD_LIMIT;
247  params.offset = 0;
248 
249  m_ReportCallback.GetEventOnResponse().Insert(OnAuthorReportLoadResponse);
250 
251  m_LoadingAuthor.RequestPage(m_ReportCallback, params, false);
252 
253  // Show load UI
254  m_LoadingOvelay = SCR_LoadingOverlayDialog.Create();
255  */
256 
257  // Show confirm list
258  AuthorBlockCancelDialog();
259  }
260 
261  //------------------------------------------------------------------------------------------------
262  protected void OnCancelReport()
263  {
264  if (m_mButtonsItems.Contains(m_LineFocused))
265  {
266  OnAddonEntrySelected(m_LineFocused);
267  }
268  else
269  {
270  OnAuthorEntrySelected(m_LineFocused);
271  }
272  }
273 
274  //------------------------------------------------------------------------------------------------
275  protected void AuthorBlockCancelDialog()
276  {
277  SCR_ConfigurableDialogUi dialog = SCR_ConfigurableDialogUi.CreateFromPreset(DIALOGS_CONFIG, AUTHOR_UNBLOCK_TAG);
278  dialog.SetMessage(WidgetManager.Translate(dialog.GetMessageStr(), m_LoadingAuthor.Name()));
279 
280  dialog.m_OnConfirm.Insert(OnConfirmRemoveAuthorBlock);
281  dialog.m_OnCancel.Insert(OnCancelRemoveAuthorReport);
282  dialog.m_OnClose.Insert(OnReportDialogClose);
283  }
284 
285  //------------------------------------------------------------------------------------------------
286  protected void OnAuthorReportLoadResponse(SCR_BackendCallback callback)
287  {
288  m_LoadingOvelay.Close();
289  callback.GetEventOnResponse().Remove(OnAuthorReportLoadResponse);
290 
291  if (callback.GetResponseType() == EBackendCallbackResponse.SUCCESS)
292  {
293  OpenAuthorModsDialog(m_LoadingAuthor);
294  }
295  }
296 
297  //------------------------------------------------------------------------------------------------
298  protected void OpenAuthorModsDialog(WorkshopAuthor author)
299  {
300  // Get items
301  array<WorkshopItem> items = {};
302  author.GetPageItems(items);
303 
304  //Set items list
305  array<ref SCR_WorkshopItem> scrItems;
306  SCR_AddonManager addonManager = SCR_AddonManager.GetInstance();
307 
308  foreach (WorkshopItem item : items)
309  {
310  SCR_WorkshopItem scrItem = addonManager.Register(item);
311  scrItems.Insert(scrItem);
312  }
313 
314  SCR_AddonListDialog dialog = SCR_AddonListDialog.CreateItemsList(scrItems, AUTHOR_REPORT_TAG, DIALOGS_CONFIG);
315 
316  // Set message
317  dialog.GetMessageWidget().SetTextFormat(
318  "#AR-Workshop_CancelAuthorReport" + "\n\n" + "#AR-Workshop_AffectedMods", m_LoadingAuthor.Name());
319 
320  // Callbacks
321  dialog.m_OnConfirm.Insert(OnConfirmRemoveAuthorBlock);
322  dialog.m_OnCancel.Insert(OnCancelRemoveAuthorReport);
323  dialog.m_OnClose.Insert(OnReportDialogClose);
324  }
325 
326  //------------------------------------------------------------------------------------------------
327  protected void OnConfirmRemoveAuthorBlock(SCR_ConfigurableDialogUi dialog)
328  {
329  m_ReportCallback.GetEventOnResponse().Insert(OnRemoveAuthorBlockResponse);
330 
331  m_LoadingAuthor.RemoveBlock(m_ReportCallback);
332 
333  OnCancelRemoveAuthorReport(dialog);
334  m_LoadingOvelay = SCR_LoadingOverlayDialog.Create();
335  }
336 
337  //------------------------------------------------------------------------------------------------
338  protected void OnRemoveAuthorBlockResponse(SCR_BackendCallback callback)
339  {
340  m_LoadingOvelay.Close();
341  callback.GetEventOnResponse().Remove(OnRemoveAuthorBlockResponse);
342 
343  if (callback.GetResponseType() == EBackendCallbackResponse.SUCCESS)
344  {
345  SCR_ModularButtonComponent button = m_mButtonsAuthors.GetKeyByValue(m_LoadingAuthor);
346  DisplayReportCancelSuccess(button);
347 
348  // Remove item
349  m_mButtonsAuthors.Remove(button);
350 
351  AllButtonsCanceled();
352  }
353  else
354  {
355  SCR_CommonDialogs.CreateRequestErrorDialog();
356  }
357  }
358 
359  //------------------------------------------------------------------------------------------------
361  protected void OnReportDialogClose(SCR_ConfigurableDialogUi dialog)
362  {
363  dialog.m_OnClose.Remove(OnReportDialogClose);
364  GetGame().GetCallqueue().CallLater(FocusTopLine);
365  }
366 
367  //------------------------------------------------------------------------------------------------
368  protected void DisplayReportCancelSuccess(notnull SCR_ModularButtonComponent button)
369  {
370  // Show success in ui
371  SCR_SimpleEntryComponent entry = SCR_SimpleEntryComponent.Cast(button.GetRootWidget().FindHandler(SCR_SimpleEntryComponent));
372 
373  if (entry)
374  {
375  entry.GetMessage().SetColor(Color.FromInt(UIColors.CONFIRM.PackToInt()));
376  entry.SetMessages(entry.GetLeftText(), STR_FIXED_REPORT);
377  }
378 
379  // Clearup button
380  button.m_OnFocus.Remove(OnAddonLineFocus);
381  button.m_OnDoubleClicked.Remove(OnAddonEntrySelected);
382  button.GetRootWidget().SetFlags(WidgetFlags.NOFOCUS);
383  }
384 
385  //------------------------------------------------------------------------------------------------
386  protected void AllButtonsCanceled()
387  {
388  if (m_mButtonsItems.IsEmpty() && m_mButtonsAuthors.IsEmpty())
389  {
390  Close();
391  InvokeOnAllReportsCanceled();
392  }
393  }
394 
395  //------------------------------------------------------------------------------------------------
396  protected void OnCancelRemoveAuthorReport(SCR_ConfigurableDialogUi dialog)
397  {
398  dialog.m_OnConfirm.Remove(OnConfirmRemoveAuthorBlock);
399  dialog.m_OnCancel.Remove(OnCancelRemoveAuthorReport);
400  }
401 
402  //------------------------------------------------------------------------------------------------
403  // Callbacks
404  //------------------------------------------------------------------------------------------------
405 
406  //------------------------------------------------------------------------------------------------
408  protected void OnAddonLineFocus(SCR_ModularButtonComponent button)
409  {
410  Widget w = button.GetRootWidget();
411  SCR_ModularButtonComponent line = SCR_ModularButtonComponent.Cast(w.FindHandler(SCR_ModularButtonComponent));
412 
413  if (line)
414  m_LineFocused = line;
415  }
416 
417  //------------------------------------------------------------------------------------------------
419  protected void OnCancelReportActived()
420  {
421  if (!m_LineFocused)
422  return;
423 
424  if (m_mButtonsAuthors.Contains(m_LineFocused))
425  {
426  OnAuthorEntrySelected(m_LineFocused);
427  return;
428  }
429 
430  OnAddonEntrySelected(m_LineFocused);
431  }
432 
433  //------------------------------------------------------------------------------------------------
434  protected void OnCancelReportConfirm(SCR_ConfigurableDialogUi dialog)
435  {
436  m_DialogCancelReport.GetWorkshopItemAction().m_OnCompleted.Insert(OnCancelReportSuccess);
437  m_DialogCancelReport.GetWorkshopItemAction().m_OnFailed.Insert(OnCancelReportFail);
438 
439  // Clear confirm
440  m_DialogCancelReport.m_OnConfirm.Remove(OnCancelReportConfirm);
441  }
442 
443  //------------------------------------------------------------------------------------------------
444  protected void OnCancelReportSuccess(SCR_WorkshopItemActionCancelReport action)
445  {
446  SCR_ModularButtonComponent button = m_mButtonsItems.GetKeyByValue(action.GetWorkshopItem());
447  DisplayReportCancelSuccess(button);
448 
449  // Remove item
450  m_mButtonsItems.Remove(button);
451 
452  AllButtonsCanceled();
453  }
454 
455  //------------------------------------------------------------------------------------------------
456  protected void OnCancelReportFail(SCR_WorkshopItemActionCancelReport action)
457  {
458  // Remove invoker actions
459  action.m_OnCompleted.Remove(OnCancelReportSuccess);
460  action.m_OnFailed.Remove(OnCancelReportFail);
461  }
462 
463  //------------------------------------------------------------------------------------------------
464  protected void OnCancelReportDialog(SCR_ConfigurableDialogUi dialog)
465  {
466  // Clear invokers
467  m_DialogCancelReport.m_OnConfirm.Remove(OnCancelReportConfirm);
468  m_DialogCancelReport.m_OnCancel.Remove(OnCancelReportDialog);
469  }
470 
471  //------------------------------------------------------------------------------------------------
472  protected void FocusTopLine()
473  {
474  // Addons
475  foreach (SCR_ModularButtonComponent button, SCR_WorkshopItem item : m_mButtonsItems)
476  {
477  if (button.GetRootWidget().IsFocusable())
478  {
479  GetGame().GetWorkspace().SetFocusedWidget(button.GetRootWidget());
480  return;
481  }
482  }
483 
484  // Authors
485  foreach (SCR_ModularButtonComponent button, WorkshopAuthor author : m_mButtonsAuthors)
486  {
487  if (button.GetRootWidget().IsFocusable())
488  {
489  GetGame().GetWorkspace().SetFocusedWidget(button.GetRootWidget());
490  return;
491  }
492  }
493  }
494 
495  //------------------------------------------------------------------------------------------------
496  // Invokers
497  //------------------------------------------------------------------------------------------------
498 
499  //------------------------------------------------------------------------------------------------
500  protected void InvokeOnAllReportsCanceled()
501  {
502  if (!Event_OnAllReportsCanceled)
503  Event_OnAllReportsCanceled = new ScriptInvoker();
504 
505  Event_OnAllReportsCanceled.Invoke(this);
506  }
507 
508  //------------------------------------------------------------------------------------------------
509  ScriptInvoker GetOnAllReportsCanceled()
510  {
511  if (!Event_OnAllReportsCanceled)
512  Event_OnAllReportsCanceled = new ScriptInvoker();
513 
514  return Event_OnAllReportsCanceled;
515  }
516 
517 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CommonDialogs
Definition: CommonDialogs.c:5
m_wList
protected Widget m_wList
Definition: SCR_DownloadManagerListComponent.c:12
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
WIDGET_MESSAGE
const protected string WIDGET_MESSAGE
Definition: SCR_ScriptedWidgetTooltip.c:30
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
SCR_SimpleEntryComponent
Definition: SCR_SimpleEntryComponent.c:6
SCR_BackendCallback
Scripted backend callback class unifying backend response.
Definition: SCR_BackendCallback.c:21
SCR_CancelMyReportDialog
Dialog which sends a request to delete user's report.
Definition: SCR_WorkshopUiCommon.c:973
SCR_WorkshopItemActionCancelReport
Action for canceling report of an item.
Definition: WorkshopItemActions.c:199
UIColors
Definition: Constants.c:16
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition: SCR_ConfigurableDialogUI.c:809
SCR_LoadingOverlayDialog
Definition: SCR_LoadingOverlayDialog.c:5
SCR_ReportedAddonsDialog
Show list of reported mods and provide option to cancel reports.
Definition: SCR_ReportedAddonsDialog.c:3
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SCR_AddonManager
Definition: SCR_AddonManager.c:72
EBackendCallbackResponse
EBackendCallbackResponse
Basic callback responses.
Definition: SCR_BackendCallback.c:12
callback
DownloadConfigCallback callback
SCR_AddonListDialog
Shows a list of addons and some text.
Definition: SCR_WorkshopUiCommon.c:820
FindButton
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
Definition: SCR_BrowserHoverTooltipComponent.c:116
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1