Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GMMenu.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_GMMenuEntry : Managed
3 {
4  bool m_bIsFeatured;
5  bool m_bIsRecent;
6  bool m_bIsRecommended;
7  ref MissionWorkshopItem m_Header;
9  Widget m_wRoot;
10 
11  void SCR_GMMenuEntry(MissionWorkshopItem h, bool featured, bool recent, bool recommended)
12  {
13  m_Header = h;
14  m_bIsFeatured = featured;
15  m_bIsRecent = recent;
16  m_bIsRecommended = recommended;
17  }
18 
19  void SetTile(SCR_GMMenuTileComponent tile, Widget widget)
20  {
21  m_Tile = tile;
22  m_wRoot = widget;
23  }
24 }
25 
26 //------------------------------------------------------------------------------------------------
27 class SCR_GMMenu : ChimeraMenuBase
28 {
29  protected ResourceName m_sLayout = "{02155A85F2DC521F}UI/layouts/Menus/GMMenu/GMMenuTile.layout";
30  protected ResourceName m_sConfig = "{CA59D3A983A1BBAB}Configs/GMMenu/GMMenuEntries.conf";
32  protected WorkshopApi m_WorkshopAPI;
34  protected Widget m_wRoot;
35  protected ref array<ref SCR_GMMenuEntry> m_aEntries = {};
36 
37  const int THRESHOLD_RECENTLY_PLAYED = 60 * 60 * 24 * 7;
38 
39  //------------------------------------------------------------------------------------------------
40  override void OnMenuOpen()
41  {
42  super.OnMenuOpen();
44  m_Gallery = SCR_GalleryComponent.GetGalleryComponent("Gallery", m_wRoot);
45  m_WorkshopAPI = GetGame().GetBackendApi().GetWorkshop();
46 
47  SCR_InputButtonComponent back = SCR_InputButtonComponent.GetInputButtonComponent("Back", m_wRoot);
48  if (back)
49  back.m_OnActivated.Insert(OnBack);
50 
53 
54  if (m_aEntries.Count() > 0)
55  m_Gallery.SetFocusedItem(0, true);
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  protected override void OnMenuFocusGained()
60  {
61  if (m_CurrentTile)
62  GetGame().GetWorkspace().SetFocusedWidget(m_CurrentTile.GetRootWidget(), true);
63 
64  super.OnMenuFocusGained();
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  protected void PrepareHeaders()
69  {
70  Resource resource = BaseContainerTools.LoadContainer(m_sConfig);
71  if (!resource)
72  return;
73 
74  BaseContainer cont = resource.GetResource().ToBaseContainer();
75  if (!cont)
76  return;
77 
78  array<ResourceName> missions = {};
79  cont.Get("m_aGameMasterScenarios", missions);
80 
81  if (!missions)
82  return;
83 
84  foreach (ResourceName str : missions)
85  {
86  MissionWorkshopItem item = GetMission(str);
87  if (!item || !IsUnique(item, m_aEntries))
88  continue;
89 
90  m_aEntries.Insert(new SCR_GMMenuEntry(item, false, false, false));
91  }
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  MissionWorkshopItem GetMission(ResourceName rsc)
96  {
97  return m_WorkshopAPI.GetInGameScenario(rsc);
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  protected bool IsUnique(MissionWorkshopItem item, array<ref SCR_GMMenuEntry> entries)
102  {
103  if (!item)
104  return false;
105 
106  foreach (SCR_GMMenuEntry entry : entries)
107  {
108  if (!entry || !entry.m_Header)
109  continue;
110 
111  if (item == entry.m_Header)
112  return false;
113  }
114 
115  return true;
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  protected void PrepareWidgets()
120  {
121  foreach (SCR_GMMenuEntry entry : m_aEntries)
122  {
123  Widget w = GetGame().GetWorkspace().CreateWidgets(m_sLayout, m_wRoot);
124  if (!w)
125  continue;
126 
128  if (!tile)
129  continue;
130 
131  entry.SetTile(tile, tile.m_wRoot);
132  tile.m_OnPlay.Insert(OnPlay);
133  tile.m_OnContinue.Insert(OnContinue);
134  tile.m_OnRestart.Insert(OnRestart);
135  tile.m_OnFindServer.Insert(OnFindServer);
136  tile.m_OnFocused.Insert(OnTileFocused);
137  tile.ShowMission(entry.m_Header, entry.m_bIsFeatured, entry.m_bIsRecent, entry.m_bIsRecommended);
138 
139  m_Gallery.AddItem(w);
140  }
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  protected void OnBack()
145  {
146  Close();
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void OnPlay(SCR_GMMenuTileComponent tile)
151  {
152  GetGame().GetSaveManager().ResetFileNameToLoad();
153  TryPlayScenario(tile.m_Item);
154 
155  SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.EditorSelectionMenu);
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  protected void OnContinue(SCR_GMMenuTileComponent tile)
160  {
161  SCR_MissionHeader header = tile.m_Header;
162  if (header && !header.GetSaveFileName().IsEmpty())
163  GetGame().GetSaveManager().SetFileNameToLoad(header);
164  else
165  GetGame().GetSaveManager().ResetFileNameToLoad();
166 
167  TryPlayScenario(tile.m_Item);
168 
169  SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.EditorSelectionMenu);
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  protected void OnRestart(SCR_GMMenuTileComponent tile)
174  {
175  m_CurrentTile = tile;
176 
177  SCR_ConfigurableDialogUi dialog = SCR_CommonDialogs.CreateDialog("scenario_restart");
178  dialog.m_OnConfirm.Insert(OnRestartConfirmed);
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  protected void OnRestartConfirmed()
183  {
184  GetGame().GetSaveManager().ResetFileNameToLoad();
185  SCR_WorkshopUiCommon.TryPlayScenario(m_CurrentTile.m_Item);
186 
187  SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.EditorSelectionMenu);
188  }
189 
190  //------------------------------------------------------------------------------------------------
192  {
193  m_CurrentTile = tile;
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  void TryPlayScenario(MissionWorkshopItem scenario)
198  {
199  if (!scenario)
200  return;
201 
202  SCR_WorkshopUiCommon.TryPlayScenario(scenario);
203  }
204 
205  //------------------------------------------------------------------------------------------------
206  protected void PlayCurrentScenario()
207  {
209  }
210 
211  //------------------------------------------------------------------------------------------------
212  protected void FindCurrentScenarioServers()
213  {
214  MissionWorkshopItem scenario = GetGame().GetBackendApi().GetWorkshop().GetInGameScenario(m_CurrentTile.m_Header.GetHeaderResourceName());
215  if (!scenario)
216  return;
217 
218  ServerBrowserMenuUI.OpenWithScenarioFilter(scenario);
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  protected void OnPlayMission()
223  {
224  // If possible, load the save
225  if (!m_CurrentTile || !m_CurrentTile.m_Header)
226  return;
227 
228  GetGame().GetSaveManager().SetFileNameToLoad(m_CurrentTile.m_Header);
230  }
231 
232  //------------------------------------------------------------------------------------------------
234  {
236  }
237 }
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
m_Tile
SCR_NewsTileComponent m_Tile
Definition: SCR_NewsSubMenu.c:3
FindCurrentScenarioServers
protected void FindCurrentScenarioServers()
Definition: SCR_GMMenu.c:212
OnPlayMission
protected void OnPlayMission()
Definition: SCR_GMMenu.c:222
m_wRoot
protected Widget m_wRoot
Definition: SCR_GMMenu.c:34
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_GMMenuEntry
Definition: SCR_GMMenu.c:2
PrepareWidgets
protected void PrepareWidgets()
Definition: SCR_GMMenu.c:119
OnRestartConfirmed
protected void OnRestartConfirmed()
Definition: SCR_GMMenu.c:182
OnFindServer
protected void OnFindServer(SCR_GMMenuTileComponent tile)
Definition: SCR_GMMenu.c:233
OnMenuOpen
override void OnMenuOpen()
Definition: SCR_GMMenu.c:40
OnMenuFocusGained
protected override void OnMenuFocusGained()
Definition: SCR_GMMenu.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CommonDialogs
Definition: CommonDialogs.c:5
THRESHOLD_RECENTLY_PLAYED
const int THRESHOLD_RECENTLY_PLAYED
Definition: SCR_GMMenu.c:37
m_Gallery
protected SCR_GalleryComponent m_Gallery
Definition: SCR_GMMenu.c:31
OnRestart
protected void OnRestart(SCR_GMMenuTileComponent tile)
Definition: SCR_GMMenu.c:173
OnPlay
protected void OnPlay(SCR_GMMenuTileComponent tile)
Definition: SCR_GMMenu.c:150
m_sConfig
protected ResourceName m_sConfig
Definition: SCR_GMMenu.c:30
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
OnTileFocused
protected void OnTileFocused(SCR_GMMenuTileComponent tile)
Definition: SCR_GMMenu.c:191
GetMission
MissionWorkshopItem GetMission(ResourceName rsc)
Definition: SCR_GMMenu.c:95
m_aEntries
protected ref array< ref SCR_GMMenuEntry > m_aEntries
Definition: SCR_GMMenu.c:35
m_sLayout
SCR_GMMenuEntry m_sLayout
SCR_GMMenuTileComponent
Definition: SCR_GMMenuTileComponent.c:1
OnBack
protected void OnBack()
Definition: SCR_GMMenu.c:144
IsUnique
protected bool IsUnique(MissionWorkshopItem item, array< ref SCR_GMMenuEntry > entries)
Definition: SCR_GMMenu.c:101
m_CurrentTile
protected SCR_GMMenuTileComponent m_CurrentTile
Definition: SCR_GMMenu.c:33
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
OnContinue
protected void OnContinue(SCR_GMMenuTileComponent tile)
Definition: SCR_GMMenu.c:159
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
PlayCurrentScenario
protected void PlayCurrentScenario()
Definition: SCR_GMMenu.c:206
TryPlayScenario
void TryPlayScenario(MissionWorkshopItem scenario)
Definition: SCR_GMMenu.c:197
PrepareHeaders
protected void PrepareHeaders()
Definition: SCR_GMMenu.c:68
m_WorkshopAPI
protected WorkshopApi m_WorkshopAPI
Definition: SCR_GMMenu.c:32
ServerBrowserMenuUI
Definition: ServerBrowserMenuUI.c:10
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1