summaryrefslogtreecommitdiff
path: root/game/client/tf2/clientmode_tfnormal.cpp
blob: f766e4e47b36ae9b56c7582505899b30631116da (plain) (blame)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Normal HUD mode
//
// $Workfile:     $
// $Date:         $
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "hud_chat.h"
#include "clientmode_tfnormal.h"
#include "clientmode.h"
#include "hud.h"
#include "iinput.h"
#include "c_basetfplayer.h"
#include "hud_timer.h"
#include "usercmd.h"
#include "in_buttons.h"
#include "c_tf_playerclass.h"
#include "engine/IEngineSound.h"
#include <vgui/IInput.h>
#include <vgui/IPanel.h>
#include <vgui_controls/AnimationController.h>

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"


//-----------------------------------------------------------------------------
// Purpose: Instance the singleton and expose the interface to it.
// Output : IClientMode
//-----------------------------------------------------------------------------
IClientMode *GetClientModeNormal( void )
{
	static ClientModeTFNormal g_ClientModeNormal;
	return &g_ClientModeNormal;
}

ClientModeTFNormal::ClientModeTFNormal()
{
	m_pViewport = new Viewport();
	m_pViewport->Start( gameuifuncs, gameeventmanager );
}

ClientModeTFNormal::Viewport::Viewport()
{
	// use a custom scheme for the hud
	m_bHumanScheme = true;
	vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ClientSchemeHuman.res", "HudScheme");
	SetScheme(scheme);
}

void ClientModeTFNormal::Viewport::OnThink()
{
	BaseClass::OnThink();

	// See if scheme should change
	C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
	if(!pPlayer)
		return;
	int team = pPlayer->GetTeamNumber();
	if ( !team )
		return;

	bool human = ( team == TEAM_HUMANS ) ? true : false;
	if ( human != m_bHumanScheme )
	{
		ReloadScheme();
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void ClientModeTFNormal::Viewport::ReloadScheme()
{
	// See if scheme should change
	C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();

	if(!pPlayer)
		return;

	const char *schemeFile = NULL;

	int team = pPlayer->GetTeamNumber();
	if ( team )
	{
		m_bHumanScheme = ( team == TEAM_HUMANS ) ? true : false;

		if ( m_bHumanScheme )
		{
			schemeFile = "resource/ClientSchemeHuman.res";
		}
		else
		{
			schemeFile = "resource/ClientSchemeAlien.res";
		}
	}

//	BaseClass::ReloadScheme( schemeFile );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : vgui::Panel
//-----------------------------------------------------------------------------
vgui::Panel *ClientModeTFNormal::GetMinimapParent( void )
{
	return GetViewport();
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void ClientModeTFNormal::Update()
{
	BaseClass::Update();
	HudCommanderOverlayMgr()->Tick( );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : frametime - 
//			*cmd - 
//-----------------------------------------------------------------------------
void ClientModeTFNormal::CreateMove( float flInputSampleTime, CUserCmd *cmd )
{
	// Let the player override the view.
	C_BaseTFPlayer *pPlayer = C_BaseTFPlayer::GetLocalPlayer();
	if(!pPlayer)
		return;

	// Let the player at it
	pPlayer->CreateMove( flInputSampleTime, cmd );

	// Handle knockdowns
	if ( pPlayer->CheckKnockdownAngleOverride() )
	{
		QAngle ang;
		pPlayer->GetKnockdownAngles( ang );

		cmd->viewangles = ang;
		engine->SetViewAngles( ang );

		cmd->forwardmove = cmd->sidemove = cmd->upmove = 0;
		// Only keep score if it's down
		cmd->buttons &= ( IN_SCORE );
	}

	if ( pPlayer->GetPlayerClass() )
	{
		C_PlayerClass *pPlayerClass = pPlayer->GetPlayerClass();
		pPlayerClass->CreateMove( flInputSampleTime, cmd );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool ClientModeTFNormal::ShouldDrawViewModel( void )
{
	C_BaseTFPlayer *pPlayer = C_BaseTFPlayer::GetLocalPlayer();
	if(!pPlayer)
		return false;

	return pPlayer->ShouldDrawViewModel();
}