Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlayerDeployMenuHandlerComponent.c
Go to the documentation of this file.
3typedef ScriptInvokerBase<OnDeployMenuOpenDelegate> OnDeployMenuOpenInvoker;
4
7typedef ScriptInvokerBase<OnDeployMenuCloseDelegate> OnDeployMenuCloseInvoker;
8
12
14class SCR_PlayerDeployMenuHandlerComponent : ScriptComponent
15{
18 private SCR_PlayerFactionAffiliationComponent m_PlyFactionAffil;
19 private bool m_bReady = true;
20 private bool m_bWelcomeOpened;
21 private bool m_bWelcomeClosed;
22 protected RplId m_iLastUsedSpawnPoint = RplId.Invalid();
23
24 private static ref OnDeployMenuCloseInvoker s_OnMenuClose;
25
26 private DeployMenuSystem m_DeployMenuSystem;
27 private SCR_MenuSpawnLogic m_SpawnLogic;
28 private SCR_RespawnSystemComponent m_RespawnSystem;
29
30 //------------------------------------------------------------------------------------------------
31 protected override void OnPostInit(IEntity owner)
32 {
33 super.OnPostInit(owner);
34
35 if (!GetGame().InPlayMode())
36 return;
37
38 m_RespawnSystem = SCR_RespawnSystemComponent.GetInstance();
39 if (m_RespawnSystem)
40 m_SpawnLogic = SCR_MenuSpawnLogic.Cast(m_RespawnSystem.GetSpawnLogic());
41
42 if (!m_SpawnLogic)
43 return;
44
45 World world = GetOwner().GetWorld();
46 m_DeployMenuSystem = DeployMenuSystem.Cast(world.FindSystem(DeployMenuSystem));
47 m_DeployMenuSystem.Register(this);
48
51 {
52 Print(string.Format("%1 could not find %2!",
54 LogLevel.ERROR);
55 }
56
59 {
60 Print(string.Format("%1 is not attached in %2 hierarchy! (%1 should be a child of %3!)",
62 LogLevel.ERROR);
63 }
64
66
67 m_RespawnComponent.GetOnRespawnReadyInvoker_O().Insert(OnRespawnReady);
68 m_RespawnComponent.GetOnRespawnResponseInvoker_O().Insert(SetNotReady);
69
70 SCR_ReconnectSynchronizationComponent reconnectComp = SCR_ReconnectSynchronizationComponent.Cast(owner.FindComponent(SCR_ReconnectSynchronizationComponent));
71 if (reconnectComp)
72 reconnectComp.GetOnPlayerReconnect().Insert(OnPlayerReconnect);
73
74 SCR_WelcomeScreenComponent welcomeScreenComp = SCR_WelcomeScreenComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_WelcomeScreenComponent));
75 if (!welcomeScreenComp)
77 }
78
79 //------------------------------------------------------------------------------------------------
82 void Update(float timeSlice)
83 {
84#ifdef ENABLE_DIAG
85 if (SCR_RespawnComponent.Diag_IsCLISpawnEnabled())
86 return;
87#endif
88 if (!m_bReady)
89 return;
90
92 {
94 GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.WelcomeScreenMenu);
95
96 return;
97
98 }
99 else if (IsWelcomeScreenOpen())
100 {
102 return;
103 }
104
105 if (CanOpenMenu())
106 {
108 {
109 if (!SCR_DeployMenuMain.GetDeployMenu())
110 {
112 SCR_DeployMenuMain.OpenDeployMenu();
113 }
114 }
116 {
117 SCR_DeployMenuMain.CloseDeployMenu();
119 }
120 }
121 else if (IsMenuOpen())
122 {
123 CloseMenu();
124 }
125 }
126
127 //------------------------------------------------------------------------------------------------
128 protected bool IsMenuOpen()
129 {
130 return SCR_DeployMenuMain.GetDeployMenu() || SCR_RoleSelectionMenu.GetRoleSelectionMenu();
131 }
132
133 //------------------------------------------------------------------------------------------------
134 protected bool IsWelcomeScreenOpen()
135 {
136 return GetGame().GetMenuManager().FindMenuByPreset(ChimeraMenuPreset.WelcomeScreenMenu);
137 }
138
139 //------------------------------------------------------------------------------------------------
140 protected void CloseWelcomeScreen()
141 {
142 GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.WelcomeScreenMenu);
143 }
144
145 //------------------------------------------------------------------------------------------------
146 protected void CloseMenu()
147 {
149 return;
150
151 GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.WelcomeScreenMenu);
152 GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.RespawnSuperMenu);
153 GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.RoleSelectionDialog);
154
155 if (s_OnMenuClose)
156 s_OnMenuClose.Invoke();
157 }
158
159 //------------------------------------------------------------------------------------------------
160 protected bool HasPlayableFaction()
161 {
162 if (!m_PlyFactionAffil)
163 return false;
164
165 SCR_Faction faction = SCR_Faction.Cast(m_PlyFactionAffil.GetAffiliatedFaction());
166
167 return (faction && faction.IsPlayable());
168 }
169
170 //------------------------------------------------------------------------------------------------
171 protected bool CanOpenMenu()
172 {
173 if (!m_bWelcomeClosed)
174 return false;
175
176 bool hasEntity = (m_PlayerController.IsPossessing() || m_PlayerController.GetControlledEntity());
177 bool hasDeadEntity = false;
178 ChimeraCharacter character = ChimeraCharacter.Cast(m_PlayerController.GetControlledEntity());
179 if (character)
180 hasDeadEntity = character.GetCharacterController().IsDead();
181
182 bool canOpen = (
183 !SCR_EditorManagerEntity.IsOpenedInstance() &&
184 (!hasEntity || hasDeadEntity) &&
186 );
187
188 return canOpen;
189 }
190
191 //------------------------------------------------------------------------------------------------
192 protected bool CanOpenWelcomeScreen()
193 {
194 bool hasEntity = (m_PlayerController.IsPossessing() || m_PlayerController.GetControlledEntity());
195
196 if (m_bWelcomeClosed || hasEntity)
197 return false;
198
199 bool hasDeadEntity = false;
200 ChimeraCharacter character = ChimeraCharacter.Cast(m_PlayerController.GetControlledEntity());
201 if (character)
202 hasDeadEntity = character.GetCharacterController().IsDead();
203
204 bool canOpen = (
205 !SCR_EditorManagerEntity.IsOpenedInstance() &&
206 (!hasEntity || hasDeadEntity) &&
208 );
209
210 return canOpen;
211 }
212
213 //------------------------------------------------------------------------------------------------
214 protected void OnRespawnReady()
215 {
216 if (m_SpawnLogic && m_SpawnLogic.GetWaitForSpawnPoints())
217 {
219 return;
220 }
221
222 // Delay to next frame as current character deleted replication could by applied later than the respawn system RPC this event is raised from.
223 GetGame().GetCallqueue().Call(SetReadyDelayed);
224 }
225
226 //------------------------------------------------------------------------------------------------
227 protected void SetReadyDelayed()
228 {
229 IEntity controlledEntity = m_PlayerController.GetControlledEntity();
230 if (!controlledEntity || controlledEntity.IsDeleted())
231 {
232 SetReady();
233 return;
234 }
235
236 const float delay = m_SpawnLogic.GetDeployMenuOpenDelay() * 1000.0;
237 GetGame().GetCallqueue().CallLater(SetReady, delay, false);
238 }
239
240 //------------------------------------------------------------------------------------------------
241 protected void SetReady()
242 {
243 if (!m_bReady)
244 return;
245
246 if (m_RespawnSystem)
247 m_RespawnSystem.DestroyLoadingPlaceholder();
248
249 m_DeployMenuSystem.SetReady(true);
250 }
251
252 //------------------------------------------------------------------------------------------------
254 {
255 m_bWelcomeClosed = true;
256 }
257
258 //------------------------------------------------------------------------------------------------
259 protected void OnPlayerReconnect()
260 {
262 }
263
264 //------------------------------------------------------------------------------------------------
265 protected void SetNotReady(SCR_SpawnRequestComponent requestComponent, SCR_ESpawnResult response)
266 {
267 if (response == SCR_ESpawnResult.OK)
268 {
269 SCR_DeployMenuMain.CloseDeployMenu();
271
274
275 m_DeployMenuSystem.SetReady(false);
276 }
277 }
278
279 //------------------------------------------------------------------------------------------------
282 static OnDeployMenuCloseInvoker SGetOnMenuClosed()
283 {
284 if (!s_OnMenuClose)
285 s_OnMenuClose = new OnDeployMenuCloseInvoker();
286
287 return s_OnMenuClose;
288 }
289
290 //------------------------------------------------------------------------------------------------
291 override protected void OnDelete(IEntity owner)
292 {
293 if (s_OnMenuClose)
294 delete s_OnMenuClose;
295
296 if (m_DeployMenuSystem)
297 m_DeployMenuSystem.Unregister(this);
298
299 if (m_RespawnSystem)
300 m_RespawnSystem.DestroyLoadingPlaceholder();
301
302 super.OnDelete(owner);
303 }
304
305 //------------------------------------------------------------------------------------------------
311
312 //------------------------------------------------------------------------------------------------
317
318 //------------------------------------------------------------------------------------------------
324
325 //------------------------------------------------------------------------------------------------
327 {
328 if (!m_PlyFactionAffil)
329 return;
330
331 const FactionKey factionKey = m_PlyFactionAffil.GetAffiliatedFactionKey();
332 if (factionKey.IsEmpty())
333 {
334 m_PlyFactionAffil.GetOnPlayerFactionChangedInvoker().Insert(OnPlayerFactionAssigned);
335 return; // We must wait until we have a faction assigned
336 }
337
338 CheckSpawnsOrWait(factionKey);
339 }
340
341 //------------------------------------------------------------------------------------------------
343 {
344 if (!current)
345 return;
346
347 m_PlyFactionAffil.GetOnPlayerFactionChangedInvoker().Remove(OnPlayerFactionAssigned);
348 CheckSpawnsOrWait(current.GetFactionKey());
349 }
350
351 //------------------------------------------------------------------------------------------------
352 protected void CheckSpawnsOrWait(const FactionKey factionKey)
353 {
354 if (SCR_SpawnPoint.GetSpawnPointCountForFaction(factionKey) > 0)
355 {
356 m_bReady = true;
357 GetGame().GetCallqueue().Call(SetReadyDelayed);
358 return;
359 }
360
361 // Wait for more to be added
362 SCR_SpawnPoint.Event_SpawnPointAdded.Insert(OnPlayerSpawnPointAdded);
363 }
364
365 //------------------------------------------------------------------------------------------------
367 {
368 if (sp.GetFactionKey() != m_PlyFactionAffil.GetAffiliatedFactionKey())
369 return;
370
371 SCR_SpawnPoint.Event_SpawnPointAdded.Remove(OnPlayerSpawnPointAdded);
372
373 m_bReady = true;
374 GetGame().GetCallqueue().Call(SetReadyDelayed);
375 }
376}
AddonBuildInfoTool id
ChimeraMenuPreset
Menu presets.
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
SCR_EGameModeState
SCR_ESpawnResult
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
SCR_FastTravelComponentClass m_PlayerController
SCR_PlayerDeployMenuHandlerComponentClass m_RespawnComponent
Component responsible for deploy menu management.
void OnPlayerSpawnPointAdded(SCR_SpawnPoint sp)
void SetNotReady(SCR_SpawnRequestComponent requestComponent, SCR_ESpawnResult response)
void OnPlayerFactionAssigned(SCR_PlayerFactionAffiliationComponent component, Faction previous, Faction current)
ScriptInvokerBase< OnDeployMenuOpenDelegate > OnDeployMenuOpenInvoker
void SetLastUsedSpawnPointId(RplId id)
void CheckSpawnsOrWait(const FactionKey factionKey)
ScriptInvokerBase< OnDeployMenuCloseDelegate > OnDeployMenuCloseInvoker
void SCR_RespawnComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
int Type
void Register(notnull SCR_PlayerDeployMenuHandlerComponent handler)
proto external GenericComponent FindComponent(typename typeName)
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
proto external bool IsDeleted()
Replication item identifier.
Definition RplId.c:14
bool IsPlayable()
Role selection menu for setting up player faction, group and loadout.
static void CloseRoleSelectionMenu()
Close role selection menu.
static SCR_RoleSelectionMenu GetRoleSelectionMenu()
static SCR_RoleSelectionMenu OpenRoleSelectionMenu()
Spawn point entity defines positions on which players can possibly spawn.
string GetFactionKey()
proto external GenericEntity GetOwner()
Get owner entity.
Definition World.c:16
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto external PlayerController GetPlayerController()
proto external EParticleEffectState GetState()
proto external int GetPlayerId()
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.