aboutsummaryrefslogtreecommitdiff
path: root/Northstar.Coop/scripts/vscripts/client/cl_respawnselect_sp.gnut
blob: eab80e98623b3eece4ec3c07225a4494e0819055 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
global function ShowRespawnSelect_SP
global function ClRespawnselect_SP_Init
global function DisableDeathBlur
global function DisplayRespawnPrompt

struct
{
	bool deathBlur = false // death blur will stay after respawn if we don't remove it
	bool canRespawn = false
	var respawnHintRui
} file


void function ClRespawnselect_SP_Init()
{
	Assert( !IsMultiplayer() )

	AddCallback_OnPlayerLifeStateChanged( Callback_PlayerLifestateChanged )
	file.respawnHintRui = RuiCreate( $"ui/respawn_hint.rpak", clGlobal.topoFullScreen, RUI_DRAW_HUD, RUI_SORT_SCREENFADE + 100 )
	RuiSetResolutionToScreenSize( file.respawnHintRui )

	// register these early so we don't end up registering multiple times and crashing later
	RegisterButtonPressedCallback( KEY_SPACE,		PlayerPressed_RespawnPilotSP )
    RegisterButtonPressedCallback( BUTTON_X,		PlayerPressed_RespawnPilotSP )
}

void function Callback_PlayerLifestateChanged( entity player, int oldLifeState, int newLifeState )
{
	if ( player.GetPlayerSettings() == "spectator" )
	{
		if ( !IsTestMap() )
		{
			ScreenFade( GetLocalViewPlayer(), 0, 0, 0, 255, 0.5, 1.0, FFADE_IN )
			//printt( "cl SCREENFADE: " + 0.5 + " " + 1.0 )
		}
		return
	}

	if ( oldLifeState == newLifeState )
		return

	if ( player != GetLocalViewPlayer() )
		return

	//if ( newLifeState == LIFE_DEAD )
	//	thread ShowRespawnSelect_SP()
}

void function DisableDeathBlur()
{
	file.deathBlur = false
}

void function ShowRespawnSelect_SP()
{
}

void function PlayerPressed_RespawnPilotSP( entity player )
{
	if ( file.canRespawn )
	{
		player.ClientCommand( "RespawnNowSP" )
		RuiSetBool( file.respawnHintRui, "isVisible", false )
		file.canRespawn = false
	}
}

void function DisplayRespawnPrompt()
{
	// move this out of here since otherwise the client will attempt to bind it multiple times which crashes
	//RegisterButtonPressedCallback( KEY_SPACE,		PlayerPressed_RespawnPilotSP )
	//RegisterButtonPressedCallback( BUTTON_X,		PlayerPressed_RespawnPilotSP )
	
	// delay this so it coincides with serverside respawn delay
	//RuiSetBool( file.respawnHintRui, "isVisible", true )
	
	print( "DisplayRespawnPrompt()" )
	if ( !AreAllPlayersDead() )
		thread WaitToDisplayRespawnPrompt()
	else
		thread LevelFailedEffect()
}

void function WaitToDisplayRespawnPrompt()
{
	print( "waittodisplayrespawnprompt()" )
	// display respawn ui
	RuiSetBool( file.respawnHintRui, "isVisible", true )

	entity player = GetLocalViewPlayer()
	RuiSetGameTime( file.respawnHintRui, "nextSpawnTime", expect float( player.nv.nextRespawnTime ) )
	
	// wait until we can respawn
	wait expect float( player.nv.nextRespawnTime ) - Time()
	
	// wait until server will allow a respawn to enable it
	file.canRespawn = true
}

void function LevelFailedEffect()
{
	print( "levelfailedeffect()")
	// display the fade that gets displayed in vanilla on death
	
	wait 1.5
	SetScreenBlur( 1.0, 1.0, EASING_LINEAR )

	wait 0.25
	ScreenFade( GetLocalViewPlayer(), 0, 0, 0, 255, 0.8, 5, FFADE_OUT )
}