Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayerDeployMenuHandlerComponent.c
Go to the documentation of this file.
3 typedef ScriptInvokerBase<OnDeployMenuOpenDelegate> OnDeployMenuOpenInvoker;
4 
7 typedef ScriptInvokerBase<OnDeployMenuCloseDelegate> OnDeployMenuCloseInvoker;
8 
9 class SCR_PlayerDeployMenuHandlerComponentClass : ScriptComponentClass
10 {
11 }
12 
14 class SCR_PlayerDeployMenuHandlerComponent : ScriptComponent
15 {
19  private bool m_bReady = false;
20  private bool m_bFirstOpen = true;
21  private bool m_bWelcomeOpened;
22  private bool m_bWelcomeClosed;
23 
24  private static ref OnDeployMenuCloseInvoker s_OnMenuClose;
25 
28 
29  //------------------------------------------------------------------------------------------------
30  protected override void OnPostInit(IEntity owner)
31  {
32  super.OnPostInit(owner);
33 
34  SCR_RespawnSystemComponent rsc = SCR_RespawnSystemComponent.GetInstance();
35  if (!GetGame().InPlayMode() || (rsc && !rsc.CanOpenDeployMenu()))
36  return;
37 
38  World world = GetOwner().GetWorld();
39  m_DeployMenuSystem = DeployMenuSystem.Cast(world.FindSystem(DeployMenuSystem));
40  m_DeployMenuSystem.Register(this);
41 
43  if (!m_RespawnComponent)
44  {
45  Print(string.Format("%1 could not find %2!",
46  Type().ToString(), SCR_RespawnComponent),
47  LogLevel.ERROR);
48  }
49 
51  if (!m_PlayerController)
52  {
53  Print(string.Format("%1 is not attached in %2 hierarchy! (%1 should be a child of %3!)",
54  Type().ToString(), SCR_PlayerController, SCR_RespawnComponent),
55  LogLevel.ERROR);
56  }
57 
59 
60  m_RespawnComponent.GetOnRespawnReadyInvoker_O().Insert(OnRespawnReady);
61  m_RespawnComponent.GetOnRespawnResponseInvoker_O().Insert(SetNotReady);
62  m_SpawnLogic = SCR_MenuSpawnLogic.Cast(rsc.GetSpawnLogic());
63 
64  SCR_ReconnectSynchronizationComponent reconnectComp = SCR_ReconnectSynchronizationComponent.Cast(owner.FindComponent(SCR_ReconnectSynchronizationComponent));
65  if (reconnectComp)
66  reconnectComp.GetOnPlayerReconnect().Insert(OnPlayerReconnect);
67 
68  SCR_WelcomeScreenComponent welcomeScreenComp = SCR_WelcomeScreenComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_WelcomeScreenComponent));
69  if (!welcomeScreenComp)
71  }
72 
73  //------------------------------------------------------------------------------------------------
76  void Update(float timeSlice)
77  {
78 #ifdef ENABLE_DIAG
79  if (SCR_RespawnComponent.Diag_IsCLISpawnEnabled())
80  return;
81 #endif
83  {
84  if (!IsWelcomeScreenOpen())
85  GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.WelcomeScreenMenu);
86 
87  return;
88 
89  }
90  else if (IsWelcomeScreenOpen())
91  {
93  return;
94  }
95 
96  if (CanOpenMenu())
97  {
98  if (HasPlayableFaction() && !SCR_RoleSelectionMenu.GetRoleSelectionMenu())
99  {
100  if (!SCR_DeployMenuMain.GetDeployMenu())
101  {
102  SCR_RoleSelectionMenu.CloseRoleSelectionMenu();
103  SCR_DeployMenuMain.OpenDeployMenu();
104  }
105  }
106  else
107  {
108  if (!SCR_RoleSelectionMenu.GetRoleSelectionMenu())
109  {
110  SCR_DeployMenuMain.CloseDeployMenu();
111  SCR_RoleSelectionMenu.OpenRoleSelectionMenu();
112  }
113 
114  m_bFirstOpen = false;
115  }
116  }
117  else if (IsMenuOpen())
118  {
119  CloseMenu();
120  }
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  protected bool IsMenuOpen()
125  {
126  return SCR_DeployMenuMain.GetDeployMenu() || SCR_RoleSelectionMenu.GetRoleSelectionMenu();
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  protected bool IsWelcomeScreenOpen()
131  {
132  return GetGame().GetMenuManager().FindMenuByPreset(ChimeraMenuPreset.WelcomeScreenMenu);
133  }
134 
135  //------------------------------------------------------------------------------------------------
136  protected void CloseWelcomeScreen()
137  {
138  GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.WelcomeScreenMenu);
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  protected void CloseMenu()
143  {
144  if (m_PlayerController.GetPlayerId() != GetGame().GetPlayerController().GetPlayerId())
145  return;
146 
147  GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.WelcomeScreenMenu);
148  GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.RespawnSuperMenu);
149  GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.RoleSelectionDialog);
150 
151  if (s_OnMenuClose)
152  s_OnMenuClose.Invoke();
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  protected bool HasPlayableFaction()
157  {
158  if (!m_PlyFactionAffil)
159  return false;
160 
161  SCR_Faction faction = SCR_Faction.Cast(m_PlyFactionAffil.GetAffiliatedFaction());
162 
163  return (faction && faction.IsPlayable());
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  protected bool CanOpenMenu()
168  {
169  if (!m_bWelcomeClosed)
170  return false;
171 
172  bool hasEntity = (m_PlayerController.IsPossessing() || m_PlayerController.GetControlledEntity());
173  bool hasDeadEntity = false;
174  ChimeraCharacter character = ChimeraCharacter.Cast(m_PlayerController.GetControlledEntity());
175  if (character)
176  hasDeadEntity = character.GetCharacterController().IsDead();
177 
178  bool canOpen = (
179  !SCR_EditorManagerEntity.IsOpenedInstance() &&
180  (!hasEntity || hasDeadEntity) &&
181  (SCR_BaseGameMode.Cast(GetGame().GetGameMode()).GetState() != SCR_EGameModeState.POSTGAME)
182  );
183 
184  return canOpen;
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  protected bool CanOpenWelcomeScreen()
189  {
190  bool hasEntity = (m_PlayerController.IsPossessing() || m_PlayerController.GetControlledEntity());
191 
192  if (m_bWelcomeClosed || hasEntity)
193  return false;
194 
195  bool hasDeadEntity = false;
196  ChimeraCharacter character = ChimeraCharacter.Cast(m_PlayerController.GetControlledEntity());
197  if (character)
198  hasDeadEntity = character.GetCharacterController().IsDead();
199 
200  bool canOpen = (
201  !SCR_EditorManagerEntity.IsOpenedInstance() &&
202  (!hasEntity || hasDeadEntity) &&
203  (SCR_BaseGameMode.Cast(GetGame().GetGameMode()).GetState() != SCR_EGameModeState.POSTGAME)
204  );
205 
206  return canOpen;
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  protected void OnRespawnReady()
211  {
212  if (m_bFirstOpen)
213  {
214  SetReady();
215  return;
216  }
217 
218  // Delay to next frame as current character deleted replication could by applied later than the respawn system RPC this event is raised from.
219  GetGame().GetCallqueue().Call(SetReadyDelayed);
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  protected void SetReadyDelayed()
224  {
225  IEntity controlledEntity = m_PlayerController.GetControlledEntity();
226  if (!controlledEntity || controlledEntity.IsDeleted())
227  {
228  SetReady();
229  return;
230  }
231 
232  float delay = SCR_RespawnSystemComponent.GetInstance().GetDeployMenuOpenDelay_ms();
233  GetGame().GetCallqueue().CallLater(SetReady, delay, false);
234  }
235 
236  //------------------------------------------------------------------------------------------------
237  protected void SetReady()
238  {
239  if (m_SpawnLogic)
240  m_SpawnLogic.DestroyLoadingPlaceholder();
241  m_DeployMenuSystem.SetReady(true);
242  }
243 
244  //------------------------------------------------------------------------------------------------
246  {
247  m_bWelcomeClosed = true;
248  }
249 
250  //------------------------------------------------------------------------------------------------
251  protected void OnPlayerReconnect(int state)
252  {
253  if (m_SpawnLogic)
254  m_SpawnLogic.DestroyLoadingPlaceholder();
255  m_bFirstOpen = false;
257  }
258 
259  //------------------------------------------------------------------------------------------------
260  protected void SetNotReady(SCR_SpawnRequestComponent requestComponent, SCR_ESpawnResult response)
261  {
262  if (response == SCR_ESpawnResult.OK)
263  {
264  SCR_DeployMenuMain.CloseDeployMenu();
265  SCR_RoleSelectionMenu.CloseRoleSelectionMenu();
268  m_DeployMenuSystem.SetReady(false);
269  m_bFirstOpen = false;
270  }
271  }
272 
273  //------------------------------------------------------------------------------------------------
278  {
279  return m_SpawnLogic.UpdateLoadingPlaceholder(dt);
280  }
281 
282  //------------------------------------------------------------------------------------------------
285  static OnDeployMenuCloseInvoker SGetOnMenuClosed()
286  {
287  if (!s_OnMenuClose)
288  s_OnMenuClose = new OnDeployMenuCloseInvoker();
289 
290  return s_OnMenuClose;
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  override protected void OnDelete(IEntity owner)
295  {
296  if (s_OnMenuClose)
297  delete s_OnMenuClose;
298 
299  if (m_DeployMenuSystem)
300  m_DeployMenuSystem.Unregister(this);
301 
302  super.OnDelete(owner);
303  }
304 
305  //------------------------------------------------------------------------------------------------
308  {
309  return m_PlayerController;
310  }
311 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
GetState
EEditableEntityState GetState()
Definition: SCR_BaseEntitiesEditorUIEffect.c:7
SetReady
protected void SetReady()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:237
SCR_RespawnComponent
void SCR_RespawnComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_RespawnComponent.c:576
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SCR_ESpawnResult
SCR_ESpawnResult
Definition: SCR_ESpawnResult.c:8
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
HasPlayableFaction
protected bool HasPlayableFaction()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:156
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
IsMenuOpen
protected bool IsMenuOpen()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:124
DeployMenuSystem
Definition: DeployMenuSystem.c:1
OnDelete
override protected void OnDelete(IEntity owner)
Definition: SCR_PlayerDeployMenuHandlerComponent.c:294
IsWelcomeScreenOpen
protected bool IsWelcomeScreenOpen()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:130
m_bWelcomeOpened
private bool m_bWelcomeOpened
Definition: SCR_PlayerDeployMenuHandlerComponent.c:21
OnDeployMenuCloseDelegate
func OnDeployMenuCloseDelegate
Definition: SCR_PlayerDeployMenuHandlerComponent.c:6
func
func
Definition: SCR_AIThreatSystem.c:5
GetPlayerController
SCR_PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
OnRespawnReady
protected void OnRespawnReady()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:210
m_PlayerController
private SCR_PlayerController m_PlayerController
Definition: SCR_PlayerDeployMenuHandlerComponent.c:17
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
UpdateLoadingPlaceholder
bool UpdateLoadingPlaceholder(float dt)
Definition: SCR_PlayerDeployMenuHandlerComponent.c:277
m_bFirstOpen
private bool m_bFirstOpen
Definition: SCR_PlayerDeployMenuHandlerComponent.c:20
SCR_PlayerDeployMenuHandlerComponentClass
Definition: SCR_PlayerDeployMenuHandlerComponent.c:9
m_RespawnComponent
SCR_PlayerDeployMenuHandlerComponentClass m_RespawnComponent
Component responsible for deploy menu management.
SetNotReady
protected void SetNotReady(SCR_SpawnRequestComponent requestComponent, SCR_ESpawnResult response)
Definition: SCR_PlayerDeployMenuHandlerComponent.c:260
SCR_RoleSelectionMenu
Role selection menu for setting up player faction, group and loadout.
Definition: SCR_RoleSelectionMenu.c:2
SetWelcomeClosed
void SetWelcomeClosed()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:245
SetReadyDelayed
protected void SetReadyDelayed()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:223
OnPostInit
protected override void OnPostInit(IEntity owner)
Editable Mine.
Definition: SCR_PlayerDeployMenuHandlerComponent.c:30
CloseWelcomeScreen
protected void CloseWelcomeScreen()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:136
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
CanOpenWelcomeScreen
protected bool CanOpenWelcomeScreen()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:188
OnDeployMenuCloseInvoker
ScriptInvokerBase< OnDeployMenuCloseDelegate > OnDeployMenuCloseInvoker
Definition: SCR_PlayerDeployMenuHandlerComponent.c:7
SCR_PlayerFactionAffiliationComponent
Definition: SCR_PlayerFactionAffiliationComponent.c:16
Update
void Update(float timeSlice)
Definition: SCR_PlayerDeployMenuHandlerComponent.c:76
OnPlayerReconnect
protected void OnPlayerReconnect(int state)
Definition: SCR_PlayerDeployMenuHandlerComponent.c:251
OnDeployMenuOpenInvoker
ScriptInvokerBase< OnDeployMenuOpenDelegate > OnDeployMenuOpenInvoker
Definition: SCR_PlayerDeployMenuHandlerComponent.c:3
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
OnDeployMenuOpenDelegate
func OnDeployMenuOpenDelegate
Definition: SCR_PlayerDeployMenuHandlerComponent.c:2
m_bWelcomeClosed
private bool m_bWelcomeClosed
Definition: SCR_PlayerDeployMenuHandlerComponent.c:22
m_PlyFactionAffil
private SCR_PlayerFactionAffiliationComponent m_PlyFactionAffil
Definition: SCR_PlayerDeployMenuHandlerComponent.c:18
CanOpenMenu
protected bool CanOpenMenu()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:167
SCR_MenuSpawnLogic
Definition: SCR_MenuSpawnLogic.c:2
m_SpawnLogic
private SCR_MenuSpawnLogic m_SpawnLogic
Definition: SCR_PlayerDeployMenuHandlerComponent.c:27
m_DeployMenuSystem
private DeployMenuSystem m_DeployMenuSystem
Definition: SCR_PlayerDeployMenuHandlerComponent.c:26
SCR_EGameModeState
SCR_EGameModeState
Definition: SCR_EGameModeState.c:4
CloseMenu
protected void CloseMenu()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:142
SCR_Faction
Definition: SCR_Faction.c:6
GetPlayerId
proto external int GetPlayerId()
Definition: SCR_SpawnRequestComponent.c:39
m_bReady
private bool m_bReady
Definition: SCR_PlayerDeployMenuHandlerComponent.c:19
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26