Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ContentBrowser_ScenarioSubMenuBase.c
Go to the documentation of this file.
1/*
2Sub menu base for handlign scenario lines.
3*/
4
6{
7 ref array<MissionWorkshopItem> m_aScenarios;
8 Widget m_wListRoot;
9}
10
11class SCR_ContentBrowser_ScenarioSubMenuBase : SCR_SubMenuBase
12{
13 [Attribute("{FEFDB7917AB8310F}UI/layouts/Menus/ContentBrowser/ScenariosMenu/ContentBrowser_ScenarioLine.layout", UIWidgets.ResourceNamePicker, ".layout for the scenario lines", params: "layout")]
14 protected ResourceName m_sLinesLayout;
15
16 protected ref array<SCR_ContentBrowser_ScenarioLineComponent> m_aScenarioLines = {};
17
20
23
26
27 // Line Actions
28 protected EInputDeviceType m_eLastInputType;
29 protected bool m_bWasLineSelected;
30 protected SCR_ContentBrowser_ScenarioLineComponent m_ClickedLine; // Cache last clicked line to trigger the correct dialog after the double click window
31
33
34 // Nav buttons
36 protected ref array<SCR_InputButtonComponent> m_aRightFooterButtons = {};
37
38 // Invokers
40
43
44 //------------------------------------------------------------------------------------------------
45 override void HandlerAttached(Widget w)
46 {
47 super.HandlerAttached(w);
49 }
50
51 //------------------------------------------------------------------------------------------------
52 override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
53 {
54 super.OnTabCreate(menuRoot, buttonsLayout, index);
55
56 // Listen for Actions
59 m_ActionsComponent.GetOnAction().Insert(OnActionTriggered);
60
61 // Right footer buttons
62 // These are visible when using keyboard / gamepad and focusing a line
63 m_DynamicFooter.GetOnButtonActivated().Insert(OnInteractionButtonPressed);
64
65 m_NavFavorite = m_DynamicFooter.FindButton(SCR_ScenarioUICommon.BUTTON_FAVORITE);
66 m_aRightFooterButtons = m_DynamicFooter.GetButtonsInFooter(SCR_EDynamicFooterButtonAlignment.RIGHT);
67
69
70 // Backend
71 m_WorkshopApi = GetGame().GetBackendApi().GetWorkshop();
72
74 }
75
76 //------------------------------------------------------------------------------------------------
77 override void OnMenuUpdate(float tDelta)
78 {
79 super.OnMenuUpdate(tDelta);
80
82 MissionWorkshopItem selectedMission = GetSelectedScenario();
83 if (selectedMission && m_SelectedScenario != selectedMission)
84 {
85 m_SelectedScenario = selectedMission;
86 m_Header = SCR_MissionHeader.Cast(MissionHeader.ReadMissionHeader(selectedMission.Id()));
87 }
88
90 EInputDeviceType inputDeviceType = GetGame().GetInputManager().GetLastUsedInputDevice();
91 bool isLineSelected = GetSelectedLine();
92 bool shouldUpdateButtons = inputDeviceType != m_eLastInputType || isLineSelected != m_bWasLineSelected;
93
94 if (shouldUpdateButtons)
96
97 m_eLastInputType = inputDeviceType;
98 m_bWasLineSelected = isLineSelected;
99 }
100
101 //------------------------------------------------------------------------------------------------
102 override void OnTabShow()
103 {
104 super.OnTabShow();
105
107
110
112
114 m_ActionsComponent.ActivateActions();
115 }
116
117 //------------------------------------------------------------------------------------------------
118 override void OnTabHide()
119 {
120 super.OnTabHide();
121
123
126 }
127
128 //------------------------------------------------------------------------------------------------
129 override void OnMenuFocusGained()
130 {
131 super.OnMenuFocusGained();
132
134
136
138 m_ActionsComponent.ActivateActions();
139 }
140
141 //------------------------------------------------------------------------------------------------
142 override void OnMenuShow()
143 {
144 super.OnMenuShow();
145
147 m_ActionsComponent.ActivateActions();
148 }
149
150 // ---- EVENTS ----
151 //------------------------------------------------------------------------------------------------
152 protected void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
153 {
155 }
156
157 //------------------------------------------------------------------------------------------------
168
169 //------------------------------------------------------------------------------------------------
171 {
173 m_SelectedLine.m_OnClick.Remove(OnLineMouseClick);
174
176 }
177
178 //------------------------------------------------------------------------------------------------
180
181 //------------------------------------------------------------------------------------------------
186
187 //------------------------------------------------------------------------------------------------
192
193 //------------------------------------------------------------------------------------------------
199
200 // ---- INPUTS ----
201 // SWITCHES
202 //------------------------------------------------------------------------------------------------
203 protected void OnActionTriggered(string action, float multiplier)
204 {
206 if (GetGame().GetInputManager().GetLastUsedInputDevice() != EInputDeviceType.MOUSE)
207 return;
208
210
211 switch (action)
212 {
213 case UIConstants.MENU_ACTION_DOUBLE_CLICK: OnLineClickInteraction(multiplier); break;
214 case SCR_ScenarioUICommon.ACTION_RESTART: Restart(scenario); break;
215 case SCR_ScenarioUICommon.ACTION_FIND_SERVERS: Join(scenario); break;
216 case UIConstants.MENU_ACTION_FAVORITE: OnFavouriteButton(); break;
217 case SCR_ScenarioUICommon.ACTION_HOST:
218 {
220 Host(scenario);
221 break;
222 }
223 }
224 }
225
226 //------------------------------------------------------------------------------------------------
227 protected void OnInteractionButtonPressed(string action)
228 {
230 }
231
232 //------------------------------------------------------------------------------------------------
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 switch (tag)
245 {
246 case SCR_ConfigurableDialogUi.BUTTON_CONFIRM: Play(scenario); break;
247 case SCR_ScenarioUICommon.BUTTON_PLAY: Play(scenario); break;
248 case SCR_ScenarioUICommon.BUTTON_CONTINUE: Continue(scenario); break;
249 case SCR_ScenarioUICommon.BUTTON_RESTART: Restart(scenario); break;
250 case SCR_ScenarioUICommon.BUTTON_FIND_SERVERS: Join(scenario); break;
251 case SCR_ScenarioUICommon.BUTTON_HOST: Host(scenario); break;
252 case SCR_ScenarioUICommon.BUTTON_FAVORITE: OnFavouriteButton(); break;
253 }
254 }
255
256 // CLICKS
257 //------------------------------------------------------------------------------------------------
258 protected void OnLineClickInteraction(float multiplier)
259 {
261
263 if (!lineComp || !GetLineUnderCursor())
264 return;
265
266 switch (Math.Floor(multiplier))
267 {
268 case 1: OnLineClick(lineComp); break;
269 case 2: OnLineDoubleClick(lineComp); break;
270 }
271
272 m_ClickedLine = null;
273 }
274
275 //------------------------------------------------------------------------------------------------
277 {
278 if (!lineComp)
279 return;
280
282 MissionWorkshopItem scenario = lineComp.GetScenario();
283 if (!scenario)
284 return;
285
287 if (GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
288 {
289 SCR_ScenarioConfirmationDialogUi scenarioConfirmationDialog;
290
291 // Save details dialog
293
294 if (saveLineComp)
295 {
296 // zzz Issue is that this call just create plain SCR_ConfigurableDialog
298 scenarioConfirmationDialog = saveDialog;
299
300 if (saveDialog)
301 saveDialog.SetSave(saveLineComp.GetSave());
302 }
303
304 // Scenario confirm dialog
305 if (!scenarioConfirmationDialog)
306 scenarioConfirmationDialog = SCR_ScenarioDialogs.CreateScenarioConfirmationDialog(scenario, GetOnLineFavorite());
307
308 if (!scenarioConfirmationDialog)
309 {
310 OnPlayInteraction(scenario);
311 return;
312 }
313
315 scenarioConfirmationDialog.m_OnButtonPressed.Insert(OnConfirmationDialogButtonPressed);
316 scenarioConfirmationDialog.GetOnFavorite().Insert(SetFavorite);
317 }
319 else
320 {
321 OnPlayInteraction(scenario);
322 }
323 }
324
325 //------------------------------------------------------------------------------------------------
327 {
328 if (!lineComp)
329 return;
330
331 OnPlayInteraction(lineComp.GetScenario());
332 }
333
334 // BUTTONS
335 //------------------------------------------------------------------------------------------------
336 protected void OnFavouriteButton()
337 {
340 m_NavFavorite.SetLabel(UIConstants.GetFavoriteLabel(GetSelectedScenario().IsFavorite()));
341 }
342
343 // INTERACTIONS
344 //------------------------------------------------------------------------------------------------
345 protected void OnPlayInteraction(MissionWorkshopItem scenario)
346 {
347 Continue(scenario);
348 }
349
350 //------------------------------------------------------------------------------------------------
351 protected bool Play(MissionWorkshopItem scenario)
352 {
353 if (!SCR_ScenarioUICommon.CanPlay(scenario))
354 return false;
355
356 SCR_ScenarioUICommon.TryPlayScenario(scenario);
357 return true;
358 }
359
360 //------------------------------------------------------------------------------------------------
361 protected bool Continue(MissionWorkshopItem scenario)
362 {
363 if (!SCR_ScenarioUICommon.CanPlay(scenario))
364 return false;
365
366 SCR_ScenarioUICommon.LoadSave(scenario, m_Header, ChimeraMenuPreset.ScenarioMenu);
367 return true;
368 }
369
370 //------------------------------------------------------------------------------------------------
371 protected void Restart(MissionWorkshopItem scenario)
372 {
373 if (!scenario || !SCR_ScenarioUICommon.CanPlay(scenario))
374 return;
375
376 m_SelectedScenario = scenario;
377 m_Header = SCR_MissionHeader.Cast(MissionHeader.ReadMissionHeader(scenario.Id()));
378
379 SCR_ConfigurableDialogUi dialog = SCR_CommonDialogs.CreateDialog(SCR_ScenarioUICommon.DIALOG_RESTART);
380 dialog.m_OnConfirm.Insert(OnRestartConfirmed);
381 }
382
383 //------------------------------------------------------------------------------------------------
388
389 //------------------------------------------------------------------------------------------------
390 protected void Join(MissionWorkshopItem scenario)
391 {
392 if (!scenario || !SCR_ScenarioUICommon.CanJoin(scenario))
393 return;
394
396 }
397
398 //------------------------------------------------------------------------------------------------
399 protected void Host(MissionWorkshopItem scenario)
400 {
401 if (!scenario || !SCR_ScenarioUICommon.CanHost(scenario))
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(true);
424
425 //Delegate to update the dialog
427 m_OnLineFavorite.Invoke(isFavorite);
428 }
429
430 //------------------------------------------------------------------------------------------------
431 protected void CreateLines(array<MissionWorkshopItem> scenarios, Widget parent)
432 {
433 foreach (MissionWorkshopItem scenario : scenarios)
434 {
435 CreateLine(m_sLinesLayout, parent, scenario)
436 }
437 }
438
439 //------------------------------------------------------------------------------------------------
441 {
442 Widget w = GetGame().GetWorkspace().CreateWidgets(layout, parent);
443 if (!w)
444 return null;
445
447 if (!comp)
448 return null;
449
450 comp.SetScenario(scenario);
451 m_aScenarioLines.Insert(comp);
452
453 comp.GetOnFavorite().Insert(OnLineFavorite);
454 comp.GetOnMouseInteractionButtonClicked().Insert(OnInteractionButtonPressed);
455 comp.GetOnFocus().Insert(OnLineFocus);
456 comp.GetOnFocusLost().Insert(OnLineFocusLost);
457 comp.GetOnMouseEnter().Insert(OnLineMouseEnter);
458
459 return w;
460 }
461
462 //------------------------------------------------------------------------------------------------
463 protected void OnScenariosLoadFailed();
464
465 //------------------------------------------------------------------------------------------------
466 protected void InitWidgets();
467
468 //------------------------------------------------------------------------------------------------
469 // Inits workshop API according to current mode
470 protected void InitWorkshopApi()
471 {
472 // Scan offline items if needed
473 if (m_WorkshopApi.NeedAddonsScan())
474 m_WorkshopApi.ScanOfflineItems();
475 }
476
477 //------------------------------------------------------------------------------------------------
478 protected void UpdateSidePanel()
479 {
481 if (!lineComp)
482 return;
483
484 // Display panel
486 bool isSave = saveLineComp != null;
487
489 m_AddonDetailsPanel.GetRootWidget().SetVisible(isSave);
490
492 m_ScenarioDetailsPanel.GetRootWidget().SetVisible(!isSave);
493
494 // Fill from save
495 if (isSave)
496 {
498 m_AddonDetailsPanel.SetWorkshopItem(saveLineComp.GetSaveScrWorkshopItem());
499
500 return;
501 }
502
503 // Fill scenario
504 MissionWorkshopItem scenario = lineComp.GetScenario();
505 if (scenario && m_ScenarioDetailsPanel)
506 m_ScenarioDetailsPanel.SetScenario(scenario);
507 }
508
509 //------------------------------------------------------------------------------------------------
510 protected void UpdateNavigationButtons(bool visible = true)
511 {
514
515 if (m_NavFavorite)
516 {
517 m_NavFavorite.SetVisible(visible, false);
518 if (visible)
519 m_NavFavorite.SetLabel(UIConstants.GetFavoriteLabel(GetSelectedScenario().IsFavorite()));
520 }
521 }
522
523 //------------------------------------------------------------------------------------------------
525 {
526 // We are not over a line, use currently focused line
527 Widget wfocused = GetGame().GetWorkspace().GetFocusedWidget();
529 if (wfocused)
531
532 EInputDeviceType inputDevice = GetGame().GetInputManager().GetLastUsedInputDevice();
533 bool isCursorOnInnerButton = m_SelectedLine && m_SelectedLine.IsInnerButtonInteraction();
534
535 if (inputDevice == EInputDeviceType.MOUSE && (GetLineUnderCursor() || isCursorOnInnerButton))
536 return m_SelectedLine;
537 else
538 return comp;
539 }
540
541 //------------------------------------------------------------------------------------------------
543 {
544 // Note that this returns null if the cursor is on a button nested inside the line main button
545
546 Widget w = WidgetManager.GetWidgetUnderCursor();
547
548 if (!w)
549 return null;
550
552 }
553
554 //------------------------------------------------------------------------------------------------
556 {
558
559 if (!comp)
560 return null;
561
562 return comp.GetScenario();
563 }
564
565 // ---- PUBLIC ----
566 //------------------------------------------------------------------------------------------------
574}
ChimeraMenuPreset
Menu presets.
bool IsPlatformGameConsole()
Definition game.c:1357
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
WorkshopApi m_WorkshopApi
void UpdateNavigationButtons()
override void OnScenarioStateChanged(SCR_ContentBrowser_ScenarioLineComponent comp)
Called from scenario line component when scenario state changes.
override bool Continue(MissionWorkshopItem scenario)
override void OnRestartConfirmed()
override void OnScenariosLoadFailed()
ref array< SCR_ContentBrowser_ScenarioLineComponent > m_aScenarioLines
SCR_ContentBrowser_ScenarioLineComponent m_ClickedLine
void OnLineDoubleClick(SCR_ContentBrowser_ScenarioLineComponent lineComp)
SCR_ContentBrowser_ScenarioLineComponent m_SelectedLine
SCR_ContentBrowser_ScenarioLineComponent GetSelectedLine()
void OnLineClick(SCR_ContentBrowser_ScenarioLineComponent lineComp)
SCR_MenuActionsComponent m_ActionsComponent
void Restart(MissionWorkshopItem scenario)
SCR_AddonDetailsPanelComponent m_AddonDetailsPanel
SCR_ContentBrowser_ScenarioLineComponent m_LastSelectedLine
SCR_ScenarioDetailsPanelComponent m_ScenarioDetailsPanel
SCR_ContentBrowser_ScenarioLineComponent GetLineUnderCursor()
ref SCR_MissionHeader m_Header
EInputDeviceType m_eLastInputType
void OnLineFavorite(SCR_BrowserListMenuEntryComponent entry, bool favorite)
ref ScriptInvokerBool m_OnLineFavorite
void SetFavorite(MissionWorkshopItem scenario)
void SwitchOnButton(string tag, MissionWorkshopItem scenario)
void OnLineFocus(SCR_ScriptedWidgetComponent entry)
void OnPlayInteraction(MissionWorkshopItem scenario)
ScriptInvokerBool GetOnLineFavorite()
SCR_InputButtonComponent m_NavFavorite
MissionWorkshopItem GetSelectedScenario()
void OnActionTriggered(string action, float multiplier)
void OnInteractionButtonPressed(string action)
void OnLineFocusLost(SCR_ScriptedWidgetComponent entry)
void OnLineClickInteraction(float multiplier)
void OnConfirmationDialogButtonPressed(SCR_ScenarioConfirmationDialogUi dialog, string tag)
void Host(MissionWorkshopItem scenario)
void OnLineMouseClick(SCR_ScriptedWidgetComponent button)
MissionWorkshopItem m_SelectedScenario
void Join(MissionWorkshopItem scenario)
void OnMenuUpdate(float tDelta)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void OnMenuFocusGained()
UI layouts Menus CleanSweep CleanSweepAreaSelection layout
bool m_bShown
void CreateLine(notnull Widget rootW, bool drawStart=false)
Widget GetRootWidget()
override void OnTabHide()
override void OnTabShow()
override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
override void OnMenuShow()
void SCR_ScenarioConfirmationDialogUi(MissionWorkshopItem scenario, ScriptInvokerBool onFavoritesResponse=null)
ref array< SCR_InputButtonComponent > m_aRightFooterButtons
ScriptInvokerBase< ScriptInvokerBoolMethod > ScriptInvokerBool
override void HandlerAttached(Widget w)
void CreateLines(Widget w)
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition Math.c:13
static SCR_ContentBrowser_ScenarioLineComponent FindComponent(Widget w)
void SetSave(WorldSaveItem save)
PUBLIC.
static SCR_MenuActionsComponent FindComponent(Widget w)
static SCR_GMSaveDialog CreateSaveDetailsnDialog(MissionWorkshopItem scenario, ScriptInvokerBool onFavoritesResponse=null)
static SCR_ScenarioConfirmationDialogUi CreateScenarioConfirmationDialog(MissionWorkshopItem scenario, ScriptInvokerBool onFavoritesResponse=null)
static bool RestartScenario(MissionWorkshopItem scenario)
static void UpdateInputButtons(MissionWorkshopItem mission, array< SCR_InputButtonComponent > buttons, bool visible=true)
static bool CanJoin(MissionWorkshopItem mission)
static bool CanHost(MissionWorkshopItem mission)
static bool CanPlay(MissionWorkshopItem mission)
static ScriptInvokerCommStatus GetOnCommStatusCheckFinished()
static void TryOpenServerBrowserWithScenarioFilter(MissionWorkshopItem mission)
Workshop Api instance.
Definition WorkshopApi.c:14
bool Play()
Start playing the animation. Call 'Prepare' first if you need to change the setup of a component!
SCR_FieldOfViewSettings Attribute