8class SCR_RespawnSystemComponent : RespawnSystemComponent
11 protected ref SCR_SpawnLogic m_SpawnLogic;
14 protected bool m_bEnableRespawn;
16 [
Attribute(
"1",
desc:
"Handles visibility of the Respawn button in Pause menu.",
category:
"Respawn System")]
17 protected bool m_bEnablePauseMenuRespawn;
19 [
Attribute(
"{A1CE9D1EC16DA9BE}UI/layouts/Menus/MainMenu/SplashScreen.layout",
desc:
"Optional: Layout shown during world load completion and respawn menu opening or automatically completing.",
category:
"Respawn System")]
22 [
Attribute(
"{A39BE59EB6F41125}Configs/Respawn/SpawnPointRequestResultInfoConfig.conf",
desc:
"Holds a config of all reasons why a specific spawnpoint can be disabled",
category:
"Respawn System")]
23 protected ResourceName m_sSpawnPointRequestResultInfoHolder;
28 private static SCR_RespawnSystemComponent s_Instance = null;
41 protected bool m_bAudioMuted;
42 protected Widget m_wLoadingPlaceholder;
52 if (!m_SpawnPointRequestResultInfoHolder)
55 return m_SpawnPointRequestResultInfoHolder.GetFirstValidRequestResultInfo(requestComponent, response,
data);
60 static SCR_RespawnSystemComponent GetInstance()
64 BaseGameMode pGameMode =
GetGame().GetGameMode();
66 s_Instance = SCR_RespawnSystemComponent.Cast(pGameMode.FindComponent(SCR_RespawnSystemComponent));
81 static MenuBase OpenRespawnMenu()
83 MenuManager pMenuManager =
GetGame().GetMenuManager();
92 static void CloseRespawnMenu()
94 MenuManager pMenuManager =
GetGame().GetMenuManager();
106 void ServerSetEnableRespawn(
bool enableSpawning)
108 if (enableSpawning == m_bEnableRespawn || !Replication.IsServer())
111 SetEnableRespawnBroadcast(enableSpawning);
112 Rpc(SetEnableRespawnBroadcast, enableSpawning);
119 protected void SetEnableRespawnBroadcast(
bool enableSpawning)
121 m_bEnableRespawn = enableSpawning;
122 if (Event_OnRespawnEnabledChanged)
123 Event_OnRespawnEnabledChanged.Invoke(m_bEnableRespawn);
128 bool IsRespawnEnabled()
130 return m_bEnableRespawn;
135 bool IsPauseMenuRespawnEnabled()
137 return m_bEnablePauseMenuRespawn;
142 bool IsFactionChangeAllowed()
151 if (!Event_OnRespawnEnabledChanged)
154 return Event_OnRespawnEnabledChanged;
169 #ifdef _ENABLE_RESPAWN_LOGS
170 Print(
string.Format(
"%1::CanRequestSpawn_S(playerId: %2, handler: %2, data: %3)",
Type().
ToString(),
171 requestComponent.GetPlayerId(),
176 if (!m_bEnableRespawn)
182 return m_pGameMode.CanPlayerSpawn_S(requestComponent, handlerComponent,
data, result);
199 return m_pGameMode.PreparePlayerEntity_S(requestComponent, handlerComponent,
data, entity);
212 void OnPlayerEntityChange_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent,
IEntity previousEntity,
IEntity newEntity, SCR_SpawnData
data)
214 EmitPlayerEntityChange_S(requestComponent.GetPlayerId(), previousEntity, newEntity)
218 void EmitPlayerEntityChange_S(
int playerId,
IEntity previousEntity,
IEntity newEntity)
220 m_pGameMode.OnPlayerEntityChanged_S(playerId, previousEntity, newEntity);
221 m_SpawnLogic.OnPlayerEntityChanged_S(playerId, previousEntity, newEntity);
243 m_pGameMode.OnPlayerSpawnFinalize_S(requestComponent, handlerComponent,
data, entity);
244 m_SpawnLogic.OnPlayerSpawned_S(requestComponent.GetPlayerId(), entity);
249 void OnPlayerRegistered_S(
int playerId)
251 m_SpawnLogic.OnPlayerRegistered_S(playerId);
256 void OnPlayerAuditSuccess_S(
int playerId)
265 void OnPlayerDisconnected_S(
int playerId, KickCauseCode cause,
int timeout)
267 m_SpawnLogic.OnPlayerDisconnected_S(playerId, cause, timeout);
275 void OnPlayerKilled_S(
int playerId,
IEntity playerEntity,
IEntity killerEntity, notnull Instigator killer)
277 m_SpawnLogic.OnPlayerKilled_S(playerId, playerEntity, killerEntity, killer);
282 void OnPlayerDeleted_S(
int playerId)
284 const bool isDisconnect = !
GetGame().GetPlayerManager().IsPlayerConnected(playerId);
285 m_SpawnLogic.OnPlayerDeleted_S(playerId, isDisconnect);
291 void OnPlayerEntityCleanup_S(notnull
IEntity playerEntity)
293 m_SpawnLogic.OnPlayerEntityCleanup_S(playerEntity);
298 SCR_SpawnLogic GetSpawnLogic()
306 m_SpawnPointRequestResultInfoHolder = SCR_ConfigHelperT<SCR_SpawnPointRequestResultInfoConfig>.GetConfigObject(m_sSpawnPointRequestResultInfoHolder);
307 if (!m_SpawnPointRequestResultInfoHolder)
308 Print(
"'SCR_RespawnSystemComponent' has no valid m_SpawnPointRequestResultInfoHolder! This means the disabled reason cannot be disabled spawn point!",
LogLevel.ERROR);
312 Print(
"SCR_RespawnSystemComponent has to be attached to a SCR_BaseGameMode (or inherited) entity!",
LogLevel.ERROR);
316 Print(
"SCR_RespawnSystemComponent is missing SCR_SpawnLogic!",
LogLevel.ERROR);
320 m_SpawnLogic.OnInit(
this);
326 string text =
string.Format(
"No %1 found in the world, %2 might not work as intended!",
335 string text =
string.Format(
"No %1 found in the world, %2 might not work as intended!",
340 if (!System.IsConsoleApp())
341 CreateLoadingPlaceholder();
346 protected override event bool OnRplSave(ScriptBitWriter w)
348 w.WriteBool(m_bEnableRespawn);
350 return super.OnRplSave(w);
354 protected override event bool OnRplLoad(ScriptBitReader r)
357 r.ReadBool(enableRespawn);
359 SetEnableRespawnBroadcast(enableRespawn);
361 return super.OnRplLoad(r);
365 protected void CreateLoadingPlaceholder()
367 if (!UsesLoadingPlaceholder())
370 m_wLoadingPlaceholder =
GetGame().GetWorkspace().CreateWidgets(m_sLoadingLayout);
371 if (!m_wLoadingPlaceholder)
374 AudioSystem.Pause(1 << AudioSystem.SFX);
375 m_bAudioMuted =
true;
377 const Widget spinner = m_wLoadingPlaceholder.FindAnyWidget(
"Spinner");
379 m_LoadingSpinner = SCR_LoadingSpinner.Cast(spinner.FindHandler(SCR_LoadingSpinner));
383 bool UsesLoadingPlaceholder()
385 return !m_sLoadingLayout.IsEmpty();
389 void UpdateLoadingPlaceholder(
float dt)
391 if (!m_wLoadingPlaceholder)
394 const bool placeHolderVisible = !
GetGame().IsPlayingCinematic();
395 m_wLoadingPlaceholder.SetVisible(placeHolderVisible);
397 if (placeHolderVisible && !m_bAudioMuted)
399 AudioSystem.Pause(1 << AudioSystem.SFX);
400 m_bAudioMuted =
true;
402 else if (!placeHolderVisible && m_bAudioMuted)
404 AudioSystem.Resume(1 << AudioSystem.SFX);
405 m_bAudioMuted =
false;
413 void DestroyLoadingPlaceholder()
417 AudioSystem.Resume(1 << AudioSystem.SFX);
418 m_bAudioMuted =
false;
421 if (!m_wLoadingPlaceholder)
424 m_wLoadingPlaceholder.RemoveFromHierarchy();
425 m_wLoadingPlaceholder = null;
431 void ~SCR_RespawnSystemComponent()
433 DestroyLoadingPlaceholder();