summaryrefslogtreecommitdiff
path: root/game/client/tf2/playeroverlayhealth.cpp
blob: 0ae023e3ef33d8bbe7a20929001b52f8becd951c (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $Workfile:     $
// $Date:         $
//
//-----------------------------------------------------------------------------
// $Log: $
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "playeroverlayhealth.h"
#include "playeroverlay.h"
#include "CommanderOverlay.h"
#include "hud_commander_statuspanel.h"
//-----------------------------------------------------------------------------
// Purpose: 
// Output : 
//-----------------------------------------------------------------------------
CHudPlayerOverlayHealth::CHudPlayerOverlayHealth( CHudPlayerOverlay *baseOverlay )
: BaseClass( NULL, "CHudPlayerOverlayHealth" )
{
	m_pBaseOverlay = baseOverlay;

	SetHealth( 0 );

	SetPaintBackgroundEnabled( false );
	// Send mouse inputs (but not cursorenter/exit for now) up to parent
	SetReflectMouse( true );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Output : 
//-----------------------------------------------------------------------------
CHudPlayerOverlayHealth::~CHudPlayerOverlayHealth( void )
{
}

//-----------------------------------------------------------------------------
// Parse values from the file
//-----------------------------------------------------------------------------

bool CHudPlayerOverlayHealth::Init( KeyValues* pInitData )
{
	if (!pInitData)
		return false;

	if (!ParseRGBA(pInitData, "fgcolor", m_fgColor ))
		return false;

	if (!ParseRGBA(pInitData, "bgcolor", m_bgColor ))
		return false;

	int x, y, w, h;
	if (!ParseRect(pInitData, "position", x, y, w, h ))
		return false;
	SetPos( x, y );
	SetSize( w, h );

	return true;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : health - 
//-----------------------------------------------------------------------------

void CHudPlayerOverlayHealth::SetHealth( float health )
{
	m_Health = health;
}


//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHudPlayerOverlayHealth::Paint( void )
{
	int w, h;

	GetSize( w, h );
	
	m_pBaseOverlay->SetColorLevel( this, m_fgColor, m_bgColor );

	// Use a color related to health value....
	vgui::surface()->DrawSetColor( 0, 255, 0, 255 * m_pBaseOverlay->GetAlphaFrac() );

	int drawwidth;

	float frac = m_Health;
	frac = MIN( 1.0, m_Health );
	frac = MAX( 0.0, m_Health );

	drawwidth = frac * w;

	vgui::surface()->DrawFilledRect( 0, 0, drawwidth, h/2 );

	// This is the hurt part
	if (w != drawwidth)
	{
		vgui::surface()->DrawSetColor( 255, 64, 64, 255 * m_pBaseOverlay->GetAlphaFrac() );
		vgui::surface()->DrawFilledRect( drawwidth, 0, w, h/2 );
	}
}

void CHudPlayerOverlayHealth::OnCursorEntered()
{
	if ( m_pBaseOverlay->GetMouseOverText() )
	{
		StatusPrint( TYPE_HINT, "%s", m_pBaseOverlay->GetMouseOverText() );
	}
}

void CHudPlayerOverlayHealth::OnCursorExited()
{
	if ( m_pBaseOverlay->GetMouseOverText() )
	{
		StatusClear();
	}
}