blob: 76f1162762a725955b15671ceffea1cc2af7241b (
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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "cbase.h"
#include "hud.h"
#include "hud_macros.h"
#include "c_tf_player.h"
#include "c_tf_team.h"
#include "c_tf_playerresource.h"
#include "iclientmode.h"
#include "ienginevgui.h"
#include "tf_gamerules.h"
#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include <vgui/IVGui.h>
#include <vgui_controls/EditablePanel.h>
#include "c_tf_playerresource.h"
#include "tf_hud_arena_player_count.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
DECLARE_HUDELEMENT( CHudArenaPlayerCount );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHudArenaPlayerCount::CHudArenaPlayerCount( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudArenaPlayerCount" )
{
Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
vgui::SETUP_PANEL( this );
vgui::ivgui()->AddTickSignal( GetVPanel(), 100 );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudArenaPlayerCount::ApplySchemeSettings( IScheme *pScheme )
{
// load control settings...
LoadControlSettings( "resource/UI/HudArenaPlayerCount.res" );
BaseClass::ApplySchemeSettings( pScheme );
m_pBlueTeam = dynamic_cast<EditablePanel *>( FindChildByName( "blueteam" ) );
if ( m_pBlueTeam )
{
m_pBlueTeam->SetDialogVariable( "blue_alive", "0" );
}
m_pRedTeam = dynamic_cast<EditablePanel *>( FindChildByName( "redteam" ) );
if ( m_pRedTeam )
{
m_pRedTeam->SetDialogVariable( "red_alive", "0" );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CHudArenaPlayerCount::ShouldDraw( void )
{
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalTFPlayer )
return false;
if ( pLocalTFPlayer->GetObserverMode() == OBS_MODE_FREEZECAM )
return false;
if ( TFGameRules() && TFGameRules()->IsInArenaMode() && TFGameRules()->IsInWaitingForPlayers() == false )
{
if ( TFGameRules()->State_Get() != GR_STATE_PREROUND )
{
return CHudElement::ShouldDraw();
}
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudArenaPlayerCount::UpdateCounts( void )
{
// update the team sections in the scoreboard
for ( int teamIndex = TF_TEAM_RED; teamIndex <= TF_TEAM_BLUE; teamIndex++ )
{
EditablePanel *pPanel = NULL;
// choose dialog variables to set depending on team
const char *pDialogVar = NULL;
switch ( teamIndex )
{
case TF_TEAM_RED:
pDialogVar = "red_alive";
pPanel = m_pRedTeam;
break;
case TF_TEAM_BLUE:
pDialogVar = "blue_alive";
pPanel = m_pBlueTeam;
break;
default:
Assert( false );
break;
}
if ( pPanel )
{
// update # of living players on each team
wchar_t wNumPlayers[6];
int nCount = g_TF_PR ? g_TF_PR->GetNumPlayersForTeam( teamIndex, true ) : 0;
_snwprintf( wNumPlayers, ARRAYSIZE( wNumPlayers ), L"%i", nCount );
pPanel->SetDialogVariable( pDialogVar, wNumPlayers );
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudArenaPlayerCount::OnTick( void )
{
if ( !ShouldDraw() )
return;
UpdateCounts();
}
|