Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ContentBrowser_ScenarioSubMenuBase.c
Go to the documentation of this file.
1 /*
2 Sub menu base for handlign scenario lines.
3 */
4 
6 {
7  protected ref array<SCR_ContentBrowser_ScenarioLineComponent> m_aScenarioLines = {};
8 
9  protected SCR_ContentBrowser_ScenarioLineComponent m_SelectedLine;
10  protected SCR_ContentBrowser_ScenarioLineComponent m_LastSelectedLine;
11 
12  protected MissionWorkshopItem m_SelectedScenario;
13  protected ref SCR_MissionHeader m_Header;
14 
15  protected SCR_ScenarioDetailsPanelComponent m_ScenarioDetailsPanel;
16 
17  // Line Actions
18  protected EInputDeviceType m_eLastInputType;
19  protected bool m_bWasLineSelected;
20  protected SCR_ContentBrowser_ScenarioLineComponent m_ClickedLine; // Cache last clicked line to trigger the correct dialog after the double click window
21 
22  protected SCR_MenuActionsComponent m_ActionsComponent;
23 
24  // Nav buttons
25  protected SCR_InputButtonComponent m_NavPlay;
26  protected SCR_InputButtonComponent m_NavContinue;
27  protected SCR_InputButtonComponent m_NavRestart;
28  protected SCR_InputButtonComponent m_NavHost;
29  protected SCR_InputButtonComponent m_NavFindServers;
30  protected SCR_InputButtonComponent m_NavFavorite;
31  protected ref array<SCR_InputButtonComponent> m_aRightFooterButtons = {};
32 
33  // Invokers
34  protected ref ScriptInvokerBool m_OnLineFavorite;
35 
36  protected bool m_bIsListeningForCommStatus;
37  protected WorkshopApi m_WorkshopApi;
38 
39  //------------------------------------------------------------------------------------------------
40  override void HandlerAttached(Widget w)
41  {
42  super.HandlerAttached(w);
43  InitWidgets();
44  }
45 
46  //------------------------------------------------------------------------------------------------
47  override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
48  {
49  super.OnTabCreate(menuRoot, buttonsLayout, index);
50 
51  // Listen for Actions
52  m_ActionsComponent = SCR_MenuActionsComponent.FindComponent(GetRootWidget());
53  if (m_ActionsComponent)
54  m_ActionsComponent.GetOnAction().Insert(OnActionTriggered);
55 
56  // Right footer buttons
57  // These are visible when using keyboard / gamepad and focusing a line
58  m_DynamicFooter.GetOnButtonActivated().Insert(OnInteractionButtonPressed);
59 
60  m_NavPlay = m_DynamicFooter.FindButton(SCR_ScenarioEntryHelper.BUTTON_PLAY);
61  m_NavContinue = m_DynamicFooter.FindButton(SCR_ScenarioEntryHelper.BUTTON_CONTINUE);
62  m_NavRestart = m_DynamicFooter.FindButton(SCR_ScenarioEntryHelper.BUTTON_RESTART);
63  m_NavHost = m_DynamicFooter.FindButton(SCR_ScenarioEntryHelper.BUTTON_HOST);
64  m_NavFindServers = m_DynamicFooter.FindButton(SCR_ScenarioEntryHelper.BUTTON_FIND_SERVERS);
65  m_NavFavorite = m_DynamicFooter.FindButton(SCR_ScenarioEntryHelper.BUTTON_FAVORITE);
66 
67  m_aRightFooterButtons = m_DynamicFooter.GetButtonsInFooter(SCR_EDynamicFooterButtonAlignment.RIGHT);
68 
69  UpdateNavigationButtons();
70 
71  // Backend
72  m_WorkshopApi = GetGame().GetBackendApi().GetWorkshop();
73 
74  InitWorkshopApi()
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  override void OnMenuUpdate(float tDelta)
79  {
80  super.OnMenuUpdate(tDelta);
81 
83  MissionWorkshopItem selectedMission = GetSelectedScenario();
84  if (selectedMission && m_SelectedScenario != selectedMission)
85  {
86  m_SelectedScenario = selectedMission;
87  m_Header = SCR_MissionHeader.Cast(MissionHeader.ReadMissionHeader(selectedMission.Id()));
88  }
89 
91  EInputDeviceType inputDeviceType = GetGame().GetInputManager().GetLastUsedInputDevice();
92  bool isLineSelected = GetSelectedLine();
93  bool shouldUpdateButtons = inputDeviceType != m_eLastInputType || isLineSelected != m_bWasLineSelected;
94 
95  if (shouldUpdateButtons)
96  UpdateNavigationButtons();
97 
98  m_eLastInputType = inputDeviceType;
99  m_bWasLineSelected = isLineSelected;
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  override void OnTabShow()
104  {
105  super.OnTabShow();
106 
107  SCR_ServicesStatusHelper.RefreshPing();
108 
109  if (!m_bIsListeningForCommStatus)
110  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Insert(OnCommStatusCheckFinished);
111 
112  m_bIsListeningForCommStatus = true;
113 
114  if (m_ActionsComponent)
115  m_ActionsComponent.ActivateActions();
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  override void OnTabHide()
120  {
121  super.OnTabHide();
122 
123  UpdateNavigationButtons(false);
124 
125  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusCheckFinished);
126  m_bIsListeningForCommStatus = false;
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  override void OnMenuFocusGained()
131  {
132  super.OnMenuFocusGained();
133 
134  SCR_ServicesStatusHelper.RefreshPing();
135 
136  UpdateNavigationButtons();
137 
138  if (m_bShown && m_ActionsComponent)
139  m_ActionsComponent.ActivateActions();
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  override void OnMenuShow()
144  {
145  super.OnMenuShow();
146 
147  if (m_bShown && m_ActionsComponent)
148  m_ActionsComponent.ActivateActions();
149  }
150 
151  // ---- EVENTS ----
152  //------------------------------------------------------------------------------------------------
153  protected void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
154  {
155  UpdateNavigationButtons();
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  protected void OnLineFocus(SCR_ScriptedWidgetComponent entry)
160  {
162 
163  m_SelectedLine = lineComp;
164  m_SelectedLine.m_OnClick.Insert(OnLineMouseClick);
165 
166  UpdateNavigationButtons();
167  UpdateSidePanel();
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  protected void OnLineFocusLost(SCR_ScriptedWidgetComponent entry)
172  {
173  m_LastSelectedLine = m_SelectedLine;
174  m_SelectedLine.m_OnClick.Remove(OnLineMouseClick);
175 
176  UpdateSidePanel();
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  protected void OnLineMouseClick(SCR_ScriptedWidgetComponent button)
181  {
182  m_ClickedLine = SCR_ContentBrowser_ScenarioLineComponent.Cast(button);
183  }
184 
185  //------------------------------------------------------------------------------------------------
186  protected void OnLineFavorite(SCR_ListMenuEntryComponent entry, bool favorite)
187  {
188  OnScenarioStateChanged(SCR_ContentBrowser_ScenarioLineComponent.Cast(entry));
189  }
190 
191  //------------------------------------------------------------------------------------------------
193  protected void OnScenarioStateChanged(SCR_ContentBrowser_ScenarioLineComponent comp)
194  {
195  UpdateSidePanel();
196  }
197 
198  // ---- INPUTS ----
199  // SWITCHES
200  //------------------------------------------------------------------------------------------------
201  protected void OnActionTriggered(string action, float multiplier)
202  {
204  if (GetGame().GetInputManager().GetLastUsedInputDevice() != EInputDeviceType.MOUSE)
205  return;
206 
207  MissionWorkshopItem scenario = GetSelectedScenario();
208  if (!SCR_ScenarioEntryHelper.IsReady(scenario) && action != SCR_ScenarioEntryHelper.ACTION_DOUBLE_CLICK)
209  return;
210 
211  switch (action)
212  {
213  case SCR_ScenarioEntryHelper.ACTION_DOUBLE_CLICK: OnLineClickInteraction(multiplier); break;
214  case SCR_ScenarioEntryHelper.ACTION_RESTART: Restart(scenario); break;
215  case SCR_ScenarioEntryHelper.ACTION_FIND_SERVERS: Join(scenario); break;
216  case SCR_ScenarioEntryHelper.ACTION_FAVORITE: OnFavouriteButton(); break;
217  case SCR_ScenarioEntryHelper.ACTION_HOST:
218  {
220  Host(scenario);
221  break;
222  }
223  }
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  protected void OnInteractionButtonPressed(string action)
228  {
229  SwitchOnButton(action, GetSelectedScenario());
230  }
231 
232  //------------------------------------------------------------------------------------------------
233  protected void OnConfirmationDialogButtonPressed(SCR_ScenarioConfirmationDialogUi dialog, string tag)
234  {
235  if (!dialog)
236  return;
237 
238  SwitchOnButton(tag, dialog.GetScenario());
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  protected void SwitchOnButton(string tag, MissionWorkshopItem scenario)
243  {
244  if (!SCR_ScenarioEntryHelper.IsReady(scenario))
245  return;
246 
247  switch (tag)
248  {
249  case SCR_ConfigurableDialogUi.BUTTON_CONFIRM: Play(scenario); break;
250  case SCR_ScenarioEntryHelper.BUTTON_PLAY: Play(scenario); break;
251  case SCR_ScenarioEntryHelper.BUTTON_CONTINUE: Continue(scenario); break;
252  case SCR_ScenarioEntryHelper.BUTTON_RESTART: Restart(scenario); break;
253  case SCR_ScenarioEntryHelper.BUTTON_FIND_SERVERS: Join(scenario); break;
254  case SCR_ScenarioEntryHelper.BUTTON_HOST: Host(scenario); break;
255  case SCR_ScenarioEntryHelper.BUTTON_FAVORITE: OnFavouriteButton(); break;
256  }
257  }
258 
259  // CLICKS
260  //------------------------------------------------------------------------------------------------
261  protected void OnLineClickInteraction(float multiplier)
262  {
264 
265  SCR_ContentBrowser_ScenarioLineComponent lineComp = m_ClickedLine;
266  if (!lineComp || !GetLineUnderCursor())
267  return;
268 
269  switch (Math.Floor(multiplier))
270  {
271  case 1: OnLineClick(lineComp); break;
272  case 2: OnLineDoubleClick(lineComp); break;
273  }
274 
275  m_ClickedLine = null;
276  }
277 
278  //------------------------------------------------------------------------------------------------
279  protected void OnLineClick(SCR_ContentBrowser_ScenarioLineComponent lineComp)
280  {
281  if (!lineComp)
282  return;
283 
285  MissionWorkshopItem scenario = lineComp.GetScenario();
286  if (!scenario)
287  return;
288 
290  if (GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
291  {
292  SCR_ScenarioConfirmationDialogUi scenarioConfirmationDialog = SCR_ScenarioDialogs.CreateScenarioConfirmationDialog(scenario, GetOnLineFavorite());
293  if (!scenarioConfirmationDialog)
294  {
295  OnPlayInteraction(scenario);
296  return;
297  }
298 
300  scenarioConfirmationDialog.m_OnButtonPressed.Insert(OnConfirmationDialogButtonPressed);
301  scenarioConfirmationDialog.GetOnFavorite().Insert(SetFavorite);
302  }
304  else
305  {
306  OnPlayInteraction(scenario);
307  }
308  }
309 
310  //------------------------------------------------------------------------------------------------
311  protected void OnLineDoubleClick(SCR_ContentBrowser_ScenarioLineComponent lineComp)
312  {
313  if (!lineComp)
314  return;
315 
316  OnPlayInteraction(lineComp.GetScenario());
317  }
318 
319  // BUTTONS
320  //------------------------------------------------------------------------------------------------
321  protected void OnFavouriteButton()
322  {
323  SetFavorite(GetSelectedScenario());
324  if (m_NavFavorite && GetSelectedLine())
325  m_NavFavorite.SetLabel(GetFavoriteLabel(GetSelectedScenario().IsFavorite()));
326  }
327 
328  // INTERACTIONS
329  //------------------------------------------------------------------------------------------------
330  protected void OnPlayInteraction(MissionWorkshopItem scenario)
331  {
332  if (!SCR_ScenarioEntryHelper.IsReady(scenario))
333  return;
334 
335  if (SCR_ScenarioEntryHelper.HasSave(scenario))
336  Continue(scenario);
337  else
338  Play(scenario);
339  }
340 
341  //------------------------------------------------------------------------------------------------
342  protected void Play(MissionWorkshopItem scenario)
343  {
344  if (!scenario)
345  return;
346 
347  SCR_WorkshopUiCommon.TryPlayScenario(scenario);
348  }
349 
350  //------------------------------------------------------------------------------------------------
351  protected void Continue(MissionWorkshopItem scenario)
352  {
353  if (!scenario)
354  return;
355 
356  if (m_Header && !m_Header.GetSaveFileName().IsEmpty())
357  GetGame().GetSaveManager().SetFileNameToLoad(m_Header);
358  else
359  GetGame().GetSaveManager().ResetFileNameToLoad();
360 
361  SCR_WorkshopUiCommon.TryPlayScenario(scenario);
362  }
363 
364  //------------------------------------------------------------------------------------------------
365  protected void Restart(MissionWorkshopItem scenario)
366  {
367  if (!scenario)
368  return;
369 
370  m_SelectedScenario = scenario;
371  m_Header = SCR_MissionHeader.Cast(MissionHeader.ReadMissionHeader(scenario.Id()));
372 
373  if (!SCR_ScenarioEntryHelper.HasSave(scenario))
374  return;
375 
376  SCR_ConfigurableDialogUi dialog = SCR_CommonDialogs.CreateDialog("scenario_restart");
377  dialog.m_OnConfirm.Insert(OnRestartConfirmed);
378  }
379 
380  //------------------------------------------------------------------------------------------------
381  protected void OnRestartConfirmed()
382  {
383  GetGame().GetSaveManager().ResetFileNameToLoad();
384  SCR_WorkshopUiCommon.TryPlayScenario(m_SelectedScenario);
385  }
386 
387  //------------------------------------------------------------------------------------------------
388  protected void Join(MissionWorkshopItem scenario)
389  {
390  SCR_EScenarioEntryErrorState state = SCR_ScenarioEntryHelper.GetErrorState(scenario);
391  if (!scenario || !SCR_ScenarioEntryHelper.IsMultiplayer(scenario) || SCR_ScenarioEntryHelper.IsInErrorState(state))
392  return;
393 
394  ServerBrowserMenuUI.OpenWithScenarioFilter(scenario);
395  }
396 
397  //------------------------------------------------------------------------------------------------
398  protected void Host(MissionWorkshopItem scenario)
399  {
400  SCR_EScenarioEntryErrorState state = SCR_ScenarioEntryHelper.GetErrorState(scenario);
401  if (!scenario || !SCR_ScenarioEntryHelper.IsMultiplayer(scenario) || SCR_ScenarioEntryHelper.IsInErrorState(state))
402  return;
403 
404  // Open server hosting dialog
405  ServerHostingUI dialog = SCR_CommonDialogs.CreateServerHostingDialog();
406 
407  if (dialog)
408  dialog.SelectScenario(scenario);
409  }
410 
411  //------------------------------------------------------------------------------------------------
412  protected void SetFavorite(MissionWorkshopItem scenario)
413  {
414  if (!scenario || !m_SelectedLine || m_SelectedLine.GetScenario() != scenario)
415  return;
416 
417  bool isFavorite = !scenario.IsFavorite();
418 
419  //Update the scenario
420  scenario.SetFavorite(isFavorite);
421 
422  //Update the widgets
423  m_SelectedLine.NotifyScenarioUpdate();
424 
425  //Delegate to update the dialog
426  if (m_OnLineFavorite)
427  m_OnLineFavorite.Invoke(isFavorite);
428  }
429 
430  // ---- HELPERS ----
431  // Create lines for scenarios
432  //------------------------------------------------------------------------------------------------
433  protected bool CreateLines(array<MissionWorkshopItem> scenarios, Widget parent)
434  {
435  foreach (MissionWorkshopItem scenario : scenarios)
436  {
437  Widget w = GetGame().GetWorkspace().CreateWidgets(SCR_ContentBrowser_ScenarioLineWidgets.s_sLayout, parent);
438  if (!w)
439  return false;
440 
442  if (!comp)
443  return false;
444 
445  comp.SetScenario(scenario);
446  m_aScenarioLines.Insert(comp);
447 
448  comp.GetOnFavorite().Insert(OnLineFavorite);
449  comp.GetOnMouseInteractionButtonClicked().Insert(OnInteractionButtonPressed);
450  comp.GetOnFocus().Insert(OnLineFocus);
451  comp.GetOnFocusLost().Insert(OnLineFocusLost);
452  }
453 
454  return true;
455  }
456 
457  //------------------------------------------------------------------------------------------------
458  protected void InitWidgets();
459 
460  //------------------------------------------------------------------------------------------------
461  // Inits workshop API according to current mode
462  protected void InitWorkshopApi()
463  {
464  // Scan offline items if needed
465  if (m_WorkshopApi.NeedScan())
466  m_WorkshopApi.ScanOfflineItems();
467  }
468 
469  //------------------------------------------------------------------------------------------------
470  protected void UpdateSidePanel()
471  {
472  SCR_ContentBrowser_ScenarioLineComponent lineComp = GetSelectedLine();
473  if (!lineComp)
474  return;
475 
476  MissionWorkshopItem scenario = lineComp.GetScenario();
477  if (scenario && m_ScenarioDetailsPanel)
478  m_ScenarioDetailsPanel.SetScenario(scenario);
479  }
480 
481  //------------------------------------------------------------------------------------------------
482  protected void UpdateNavigationButtons(bool visible = true)
483  {
484  MissionWorkshopItem scenario = GetSelectedScenario();
485  SCR_ScenarioEntryHelper.UpdateInputButtons(scenario, m_aRightFooterButtons, visible);
486 
487  if (m_NavFavorite)
488  {
489  m_NavFavorite.SetVisible(visible, false);
490  if (visible)
491  m_NavFavorite.SetLabel(GetFavoriteLabel(GetSelectedScenario().IsFavorite()));
492  }
493  }
494 
495  //------------------------------------------------------------------------------------------------
496  protected string GetFavoriteLabel(bool isFavorite)
497  {
498  if (isFavorite)
499  return UIConstants.FAVORITE_LABEL_REMOVE;
500  else
501  return UIConstants.FAVORITE_LABEL_ADD;
502  }
503 
504  //------------------------------------------------------------------------------------------------
505  protected SCR_ContentBrowser_ScenarioLineComponent GetSelectedLine()
506  {
507  // We are not over a line, use currently focused line
508  Widget wfocused = GetGame().GetWorkspace().GetFocusedWidget();
510  if (wfocused)
512 
513  EInputDeviceType inputDevice = GetGame().GetInputManager().GetLastUsedInputDevice();
514  bool isCursorOnInnerButton = m_SelectedLine && m_SelectedLine.IsInnerButtonInteraction();
515 
516  if (inputDevice == EInputDeviceType.MOUSE && (GetLineUnderCursor() || isCursorOnInnerButton))
517  return m_SelectedLine;
518  else
519  return comp;
520  }
521 
522  //------------------------------------------------------------------------------------------------
523  protected SCR_ContentBrowser_ScenarioLineComponent GetLineUnderCursor()
524  {
525  // Note that this returns null if the cursor is on a button nested inside the line main button
526 
527  Widget w = WidgetManager.GetWidgetUnderCursor();
528 
529  if (!w)
530  return null;
531 
533  }
534 
535  //------------------------------------------------------------------------------------------------
536  protected MissionWorkshopItem GetSelectedScenario()
537  {
538  SCR_ContentBrowser_ScenarioLineComponent comp = GetSelectedLine();
539 
540  if (!comp)
541  return null;
542 
543  return comp.GetScenario();
544  }
545 
546  // ---- PUBLIC ----
547  //------------------------------------------------------------------------------------------------
548  ScriptInvokerBool GetOnLineFavorite()
549  {
550  if (!m_OnLineFavorite)
551  m_OnLineFavorite = new ScriptInvokerBool();
552 
553  return m_OnLineFavorite;
554  }
555 }
m_bShown
protected bool m_bShown
Definition: SCR_InfoDisplay.c:61
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
SCR_ScenarioDetailsPanelComponent
Definition: SCR_ScenarioDetailsPanelComponent.c:6
m_WorkshopApi
protected WorkshopApi m_WorkshopApi
Definition: SCR_ContentBrowser_AddonsSubMenu.c:48
m_aRightFooterButtons
protected ref array< SCR_InputButtonComponent > m_aRightFooterButtons
Definition: SCR_ScenarioDialogs.c:37
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
MissionHeader
Definition: MissionHeader.c:32
SCR_CommonDialogs
Definition: CommonDialogs.c:5
SCR_SubMenuBase
Definition: SCR_SubMenuBase.c:6
IsPlatformGameConsole
bool IsPlatformGameConsole()
Definition: game.c:1393
SCR_ContentBrowser_ScenarioLineComponent
Definition: SCR_ContentBrowser_ScenarioLineComponent.c:4
SCR_EScenarioEntryErrorState
SCR_EScenarioEntryErrorState
Definition: SCR_ScenarioEntryHelper.c:419
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
ScriptInvokerBool
ScriptInvokerBase< ScriptInvokerBoolMethod > ScriptInvokerBool
Definition: SCR_ScriptInvokerHelper.c:41
SCR_ScenarioConfirmationDialogUi
void SCR_ScenarioConfirmationDialogUi(MissionWorkshopItem scenario, ScriptInvokerBool onFavoritesResponse=null)
Definition: SCR_ScenarioDialogs.c:50
SCR_ContentBrowser_ScenarioLineWidgets
Definition: SCR_ContentBrowser_ScenarioLineWidgets.c:4
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_ScenarioDialogs
Definition: SCR_ScenarioDialogs.c:9
SCR_ListMenuEntryComponent
Definition: SCR_ListMenuEntryComponent.c:9
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SCR_MenuActionsComponent
Definition: SCR_MenuActionsComponent.c:9
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
ServerBrowserMenuUI
Definition: ServerBrowserMenuUI.c:10
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
SCR_ContentBrowser_ScenarioSubMenuBase
Definition: SCR_ContentBrowser_ScenarioSubMenuBase.c:5