Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_StartScenarioDialog.c
Go to the documentation of this file.
1 /*
2 Dialog with confirmation for starting a scenario
3 */
5 {
7  protected MissionWorkshopItem m_Scenario;
8 
9  //------------------------------------------------------------------------------------------------
10  static SCR_StartScenarioDialog CreateForScenario(MissionWorkshopItem scenario)
11  {
12  SCR_StartScenarioDialog dlg = SCR_StartScenarioDialog.Cast(GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.StartScenarioDialog, DialogPriority.CRITICAL));
13  dlg.Init(scenario);
14  return dlg;
15  }
16 
17 
18 
19  // ----------------------------------- Protected and private -------------------------------------
20 
21 
22 
23  //------------------------------------------------------------------------------------------------
24  protected void Init(MissionWorkshopItem scenario)
25  {
26  m_Scenario = scenario;
27  SCR_MissionHeader header = SCR_MissionHeader.Cast(scenario.GetHeader());
28 
29  // Name
30  if (header)
31  widgets.m_ScenarioNameText.SetText(header.m_sName);
32  else if (m_Scenario)
33  widgets.m_ScenarioNameText.SetText(scenario.Name());
34 
35  // Image
36  if (header)
37  {
38  string image = header.m_sIcon;
39  if (!image.IsEmpty())
40  {
41  widgets.m_ScenarioImage.LoadImageTexture(0, image, false, true);
42  }
43  else
44  widgets.m_ScenarioImage.SetVisible(false);
45  }
46  else
47  widgets.m_ScenarioImage.SetVisible(false);
48 
49 
50  // Hide host button for SP scenario
51  if (header)
52  {
53  if (!header.IsMultiplayer())
54  {
55  widgets.m_HostButton.SetVisible(false);
56  widgets.m_HostButton.SetEnabled(false);
57  }
58  }
59  }
60 
61 
62 
63  //------------------------------------------------------------------------------------------------
64  override void OnMenuOpen()
65  {
66  super.OnMenuOpen();
67  widgets.Init(GetRootWidget());
68  widgets.m_PlayButtonComponent.m_OnActivated.Insert(OnPlay);
69  widgets.m_HostButtonComponent.m_OnActivated.Insert(OnHost);
70  widgets.m_JoinButtonComponent.m_OnActivated.Insert(OnJoin);
71  }
72 
73 
74  //------------------------------------------------------------------------------------------------
75  void OnJoin()
76  {
77  if (!m_Scenario)
78  return;
79 
80  ServerBrowserMenuUI menu = ServerBrowserMenuUI.Cast(GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.ServerBrowserMenu, 0, true, true));
81  }
82 
83 
84  //------------------------------------------------------------------------------------------------
85  void OnPlay()
86  {
87  if (!m_Scenario)
88  return;
89 
90  m_Scenario.Play();
91  }
92 
93 
94  //------------------------------------------------------------------------------------------------
95  void OnHost()
96  {
97  if (!m_Scenario)
98  return;
99 
100  ref DSConfig config = new DSConfig;
101  ref DSGameConfig game = new DSGameConfig;
102  config.game = game;
103  game.scenarioId = m_Scenario.Id();
104  game.maxPlayers = m_Scenario.GetPlayerCount();
105  game.name = m_Scenario.Name() + " - " + System.GetMachineName();
106  WorkshopItem hostedMod = m_Scenario.GetOwner();
107  if (hostedMod)
108  game.hostedScenarioModId = hostedMod.Id();
109 
110  ref array<WorkshopItem> offlineMods = new array<WorkshopItem>;
111  ref array<ref DSMod> modIds = new array<ref DSMod>;
112  GetGame().GetBackendApi().GetWorkshop().GetOfflineItems(offlineMods);
113  foreach(auto mod : offlineMods)
114  {
115  ref DSMod modData = new DSMod;
116  modData.modId = mod.Id();
117  modData.name = mod.Name();
118  modData.version = mod.GetActiveRevision().GetVersion();
119  modIds.Insert(modData);
120  }
121  config.game.mods = modIds;
122  m_Scenario.Host(config);
123  }
124 
125 
126  //------------------------------------------------------------------------------------------------
127  override protected void OnConfirm()
128  {
129  // Do nothing, confirm button is disabled
130  }
131 
132 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
DialogUI
Definition: DialogUI.c:1
SCR_StartScenarioDialogWidgets
Definition: SCR_StartScenarioDialogWidgets.c:4
SCR_StartScenarioDialog
Definition: SCR_StartScenarioDialog.c:4
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
ServerBrowserMenuUI
Definition: ServerBrowserMenuUI.c:10
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
m_Scenario
SCR_ExitGameWhileDownloadingDialog m_Scenario