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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "hud.h"
#include "hudelement.h"
#include "hud_macros.h"
#include "iclientmode.h"
#include "hl1_c_player.h"
#include <vgui/ISurface.h>
#include <vgui_controls/Panel.h>
#define MIN_ALPHA 100
class CHudFlashlight : public CHudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHudFlashlight, vgui::Panel );
public:
CHudFlashlight( const char *pElementName );
private:
void Paint( void );
void ApplySchemeSettings(vgui::IScheme *pScheme);
private:
CHudTexture *icon_flash_empty;
CHudTexture *icon_flash_full;
CHudTexture *icon_flash_beam;
Color m_clrReddish;
};
DECLARE_HUDELEMENT( CHudFlashlight );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudFlashlight::CHudFlashlight( const char *pElementName ) : CHudElement( pElementName ), BaseClass(NULL, "HudFlashlight")
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_HEALTH | HIDEHUD_PLAYERDEAD | HIDEHUD_NEEDSUIT );
}
void CHudFlashlight::Paint( void )
{
int r, g, b, a, nUnused;
int x, y;
bool bIsOn;
Color clrFlash;
C_HL1_Player *pPlayer = ToHL1Player( C_HL1_Player::GetLocalPlayer() );
if ( !pPlayer )
return;
if ( !icon_flash_empty )
{
icon_flash_empty = gHUD.GetIcon( "flash_empty" );
}
if ( !icon_flash_full )
{
icon_flash_full = gHUD.GetIcon( "flash_full" );
}
if ( !icon_flash_beam )
{
icon_flash_beam = gHUD.GetIcon( "flash_beam" );
}
if ( !icon_flash_empty || !icon_flash_full || !icon_flash_beam )
{
return;
}
bIsOn = pPlayer->IsEffectActive( EF_DIMLIGHT );
if ( bIsOn )
a = 225;
else
a = MIN_ALPHA;
if ( pPlayer->m_nFlashBattery < 20 )
{
m_clrReddish.GetColor( r, g, b, nUnused );
}
else
{
(gHUD.m_clrYellowish).GetColor( r, g, b, nUnused );
}
clrFlash.SetColor( r, g, b, a );
y = icon_flash_empty->Height() / 2;
x = GetWide() - ( icon_flash_empty->Width() * 1.5 );
// Draw the flashlight casing
icon_flash_empty->DrawSelf( x, y, clrFlash );
if ( bIsOn )
{ // draw the flashlight beam
x = GetWide() - icon_flash_empty->Width() / 2;
icon_flash_beam->DrawSelf( x, y, clrFlash );
}
// draw the flashlight energy level
x = GetWide() - ( icon_flash_empty->Width() * 1.5 );
int nOffset = icon_flash_empty->Width() * ( 1.0 - ( (float)pPlayer->m_nFlashBattery / 100.0 ) );
if ( nOffset < icon_flash_empty->Width() )
{
icon_flash_full->DrawSelfCropped( x + nOffset, y, nOffset, 0, icon_flash_full->Width() - nOffset, icon_flash_full->Height(), clrFlash );
}
}
void CHudFlashlight::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
SetPaintBackgroundEnabled(false);
m_clrReddish = pScheme->GetColor( "Reddish", Color( 255, 16, 16, 255 ) );
}
|