summaryrefslogtreecommitdiff
path: root/game/client/cstrike/VGUI/cstriketeammenu.cpp
blob: 4b3908813b1dd7725c5e5352a652800f4571b82e (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#include "cbase.h"
#include "cstriketeammenu.h"
#include "backgroundpanel.h"
#include <convar.h>
#include "hud.h" // for gEngfuncs
#include "c_cs_player.h"
#include "cs_gamerules.h"

using namespace vgui;

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CCSTeamMenu::CCSTeamMenu(IViewPort *pViewPort) : CTeamMenu(pViewPort)
{
	CreateBackground( this );
	m_backgroundLayoutFinished = false;
}

//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CCSTeamMenu::~CCSTeamMenu()
{
}

void CCSTeamMenu::ShowPanel(bool bShow)
{
	if ( bShow )
	{
		engine->CheckPoint( "TeamMenu" );
	}

	BaseClass::ShowPanel( bShow );
}

//-----------------------------------------------------------------------------
// Purpose: called to update the menu with new information
//-----------------------------------------------------------------------------
void CCSTeamMenu::Update( void )
{
	BaseClass::Update();

	const ConVar *allowspecs =  cvar->FindVar( "mp_allowspectators" );

	C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
	
	if ( !pPlayer || !CSGameRules() )
		return;

	if ( allowspecs && allowspecs->GetBool() )
	{
		// if we're not already a CT or T...or the freeze time isn't over yet...or we're dead
		if ( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED || 
			CSGameRules()->IsFreezePeriod() || 
			( pPlayer && pPlayer->IsPlayerDead() ) )
		{
			SetVisibleButton("specbutton", true);
		}
		else
		{
			SetVisibleButton("specbutton", false);
		}
	}
	else
	{
		SetVisibleButton("specbutton", false );
	}

	m_bVIPMap = false;

	char mapName[MAX_MAP_NAME];

	Q_FileBase( engine->GetLevelName(), mapName, sizeof(mapName) );

	if ( !Q_strncmp( mapName, "maps/as_", 8 ) )
	{
		m_bVIPMap = true;
	}
		
	// if this isn't a VIP map or we're a spectator/terrorist, then disable the VIP button
	if ( !CSGameRules()->IsVIPMap() || ( pPlayer->GetTeamNumber() != TEAM_CT ) )
	{
		SetVisibleButton("vipbutton", false);
	}
	else // this must be a VIP map and we must already be a CT
	{
		SetVisibleButton("vipbutton", true);
	}

	if( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED ) // we aren't on a team yet
	{
		SetVisibleButton("CancelButton", false); 
	}
	else
	{
		SetVisibleButton("CancelButton", true); 
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CCSTeamMenu::SetVisible(bool state)
{
	BaseClass::SetVisible(state);

	if ( state )
	{
		Button *pAutoButton = dynamic_cast< Button* >( FindChildByName( "autobutton" ) );
		if ( pAutoButton )
		{
			pAutoButton->RequestFocus();
			pAutoButton->SetArmed( true );
		}
	}
}

//-----------------------------------------------------------------------------
// Purpose: When a team button is pressed it triggers this function to 
//			cause the player to join a team
//-----------------------------------------------------------------------------
void CCSTeamMenu::OnCommand( const char *command )
{
	if ( Q_stricmp( command, "vguicancel" ) )
	{
		engine->ClientCmd( command );
	}
	
	
	BaseClass::OnCommand(command);

	gViewPortInterface->ShowBackGround( false );
	OnClose();
}


void CCSTeamMenu::OnKeyCodePressed( vgui::KeyCode code )
{
	if ( code == KEY_ENTER )
	{
		Button *pAutoButton = dynamic_cast< Button* >( FindChildByName( "autobutton" ) );
		if ( pAutoButton )
		{
			pAutoButton->DoClick();
		}
	}
	else
	{
		BaseClass::OnKeyCodePressed( code );
	}
}

//-----------------------------------------------------------------------------
// Purpose: Sets the visibility of a button by name
//-----------------------------------------------------------------------------
void CCSTeamMenu::SetVisibleButton(const char *textEntryName, bool state)
{
	Button *entry = dynamic_cast<Button *>(FindChildByName(textEntryName));
	if (entry)
	{
		entry->SetVisible(state);
	}
}

//-----------------------------------------------------------------------------
// Purpose: The CS background is painted by image panels, so we should do nothing
//-----------------------------------------------------------------------------
void CCSTeamMenu::PaintBackground()
{
}

//-----------------------------------------------------------------------------
// Purpose: Scale / center the window
//-----------------------------------------------------------------------------
void CCSTeamMenu::PerformLayout()
{
	BaseClass::PerformLayout();

	// stretch the window to fullscreen
	if ( !m_backgroundLayoutFinished )
		LayoutBackgroundPanel( this );
	m_backgroundLayoutFinished = true;
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CCSTeamMenu::ApplySchemeSettings( vgui::IScheme *pScheme )
{
	BaseClass::ApplySchemeSettings( pScheme );
	ApplyBackgroundSchemeSettings( this, pScheme );
}