summaryrefslogtreecommitdiff
path: root/game/client/dod/dod_hud_playerstatuspanel.cpp
blob: 541986940abc63071e00d24616365d46567f82c7 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "cbase.h"
#include "hudelement.h"
#include <vgui_controls/EditablePanel.h>
#include <vgui_controls/ImagePanel.h>
#include <vgui/ISurface.h>
#include "c_dod_player.h"
#include "clientmode_dod.h"

#include "dodcornercutpanel.h"

#include "c_dod_objective_resource.h"
#include "c_dod_playerresource.h"

#include "dod_hud_playerstatus_ammo.h"
#include "dod_hud_playerstatus_health.h"
#include "dod_hud_playerstatus_weapon.h"
#include "dod_hud_playerstatus_stamina.h"
#include "dod_hud_playerstatus_mgheat.h"
#include "dod_hud_playerstatus_fireselect.h"
#include "dod_hud_playerstatus_tnt.h"

class CDoDHudPlayerStatusPanel : public CHudElement, public vgui::EditablePanel
{
public:
	DECLARE_CLASS_SIMPLE( CDoDHudPlayerStatusPanel, vgui::EditablePanel );

	CDoDHudPlayerStatusPanel( const char *pElementName );

	virtual void Init();
	virtual void OnThink();
	virtual void PerformLayout();
	virtual void ApplySchemeSettings( IScheme *pScheme );

private:

	CDoDCutEditablePanel	*m_pMainBar;
	ImagePanel				*m_pAlliesIcon;
	ImagePanel				*m_pAxisIcon;
	CDoDHudAmmo				*m_pAmmoStatus;
	CDoDHudHealth			*m_pHealthStatus;	
	CDoDHudCurrentWeapon	*m_pCurrentWeapon;
	CDoDHudStamina			*m_pStamina;
	CDoDHudMGHeat			*m_pMGHeat;
	CDoDHudFireSelect		*m_pFireSelect;
	CDoDHudTNT				*m_pTNT;
};

DECLARE_HUDELEMENT( CDoDHudPlayerStatusPanel );

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CDoDHudPlayerStatusPanel::CDoDHudPlayerStatusPanel( const char *pElementName ) : CHudElement( pElementName ), BaseClass( NULL, "HudPlayerStatusPanel" ) 
{
	SetParent( g_pClientMode->GetViewport() );

	m_pMainBar = new CDoDCutEditablePanel( this, "PlayerStatusMainBackground" );
	m_pAlliesIcon = new ImagePanel( this, "PlayerStatusAlliesIcon" );
	m_pAxisIcon = new ImagePanel( this, "PlayerStatusAxisIcon" );
	m_pAmmoStatus = new CDoDHudAmmo( this, "PlayerStatusAmmo" );
	m_pCurrentWeapon = new CDoDHudCurrentWeapon( this, "PlayerStatusCurrentWeapon" );
	m_pHealthStatus = new CDoDHudHealth( this, "PlayerStatusHealth" );
	m_pStamina = new CDoDHudStamina( this, "PlayerStatusStamina" );
	m_pMGHeat = new CDoDHudMGHeat( this, "PlayerStatusMGHeat" );
	m_pFireSelect = new CDoDHudFireSelect( this, "PlayerStatusFireSelect" );
	m_pTNT = new CDoDHudTNT( this, "PlayerStatusTNT" );
}

void CDoDHudPlayerStatusPanel::ApplySchemeSettings( IScheme *pScheme )
{
	// load control settings...
	LoadControlSettings( "resource/UI/HudPlayerStatusPanel.res" );

	BaseClass::ApplySchemeSettings( pScheme );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDHudPlayerStatusPanel::Init()
{
	if ( m_pMainBar )
	{
		m_pMainBar->SetVisible( true );
	}

	if ( m_pStamina )
	{
		m_pStamina->SetVisible( true );	
	}

	if ( m_pAlliesIcon )
	{
		m_pAlliesIcon->SetVisible( false );
	}

	if ( m_pAxisIcon )
	{
		m_pAxisIcon->SetVisible( false );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDHudPlayerStatusPanel::PerformLayout()
{
	BaseClass::PerformLayout();

	int x, y, w, t;
	GetBounds( x, y, w, t );

	if ( w != ScreenWidth() )
	{
		// doing this because of the 16:9 and 16:10 resolutions (VGUI doesn't scale properly for them)
		SetBounds( x, y, ScreenWidth(), t ); 
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CDoDHudPlayerStatusPanel::OnThink()
{
	BaseClass::OnThink();

	C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();

	if ( pPlayer )
	{
		// turn off the panel and children if the player is dead
		if ( !pPlayer->IsAlive() )
		{
			if ( IsVisible() )
			{
				SetVisible( false );
			}
			return;
		}
		else
		{
			if ( !IsVisible() )
			{
				SetVisible( true );
			}
		}

		// set our team icon
		int nTeam = pPlayer->GetTeamNumber();

		switch( nTeam )
		{
		case TEAM_AXIS:
			if ( m_pAlliesIcon && m_pAlliesIcon->IsVisible() )
			{
				m_pAlliesIcon->SetVisible( false );
			}
			if ( m_pAxisIcon && !m_pAxisIcon->IsVisible() )
			{
				m_pAxisIcon->SetVisible( true );
			}
			break;
		case TEAM_ALLIES:
		default:
			if ( m_pAlliesIcon && !m_pAlliesIcon->IsVisible() )
			{
				m_pAlliesIcon->SetVisible( true );
			}
			if ( m_pAxisIcon && m_pAxisIcon->IsVisible() )
			{
				m_pAxisIcon->SetVisible( false );
			}
			break;
		}
	}
}