blob: c7569e05be3f0bd7872232dbbe92f8c1e2c666f2 (
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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
//
// BonusProgress.cpp
//
// implementation of CHudBonusProgress class
//
#include "cbase.h"
#include "hud.h"
#include "hud_macros.h"
#include "view.h"
#include "iclientmode.h"
#include <KeyValues.h>
#include <vgui/ISurface.h>
#include <vgui/ISystem.h>
#include <vgui_controls/AnimationController.h>
#include <vgui/ILocalize.h>
using namespace vgui;
#include "hudelement.h"
#include "hud_numericdisplay.h"
#include "convar.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define INIT_BONUS_PROGRESS -1
//-----------------------------------------------------------------------------
// Purpose: BonusProgress panel
//-----------------------------------------------------------------------------
class CHudBonusProgress : public CHudElement, public CHudNumericDisplay
{
DECLARE_CLASS_SIMPLE( CHudBonusProgress, CHudNumericDisplay );
public:
CHudBonusProgress( const char *pElementName );
virtual void Init( void );
virtual void VidInit( void );
virtual void Reset( void );
virtual void OnThink();
private:
void SetChallengeLabel( void );
private:
// old variables
int m_iBonusProgress;
int m_iLastChallenge;
};
DECLARE_HUDELEMENT( CHudBonusProgress );
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudBonusProgress::CHudBonusProgress( const char *pElementName ) : CHudElement( pElementName ), CHudNumericDisplay(NULL, "HudBonusProgress")
{
SetHiddenBits( HIDEHUD_BONUS_PROGRESS );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBonusProgress::Init()
{
Reset();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBonusProgress::Reset()
{
m_iBonusProgress = INIT_BONUS_PROGRESS;
C_BasePlayer *local = C_BasePlayer::GetLocalPlayer();
if ( local )
m_iLastChallenge = local->GetBonusChallenge();
SetChallengeLabel();
SetDisplayValue(m_iBonusProgress);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBonusProgress::VidInit()
{
Reset();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudBonusProgress::OnThink()
{
C_GameRules *pGameRules = GameRules();
if ( !pGameRules )
{
// Not ready to init!
return;
}
int newBonusProgress = 0;
int iBonusChallenge = 0;
C_BasePlayer *local = C_BasePlayer::GetLocalPlayer();
if ( !local )
{
// Not ready to init!
return;
}
// Never below zero
newBonusProgress = MAX( local->GetBonusProgress(), 0 );
iBonusChallenge = local->GetBonusChallenge();
// Only update the fade if we've changed bonusProgress
if ( newBonusProgress == m_iBonusProgress && m_iLastChallenge == iBonusChallenge )
{
return;
}
m_iBonusProgress = newBonusProgress;
if ( m_iLastChallenge != iBonusChallenge )
{
m_iLastChallenge = iBonusChallenge;
SetChallengeLabel();
}
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence("BonusProgressFlash");
if ( pGameRules->IsBonusChallengeTimeBased() )
{
SetIsTime( true );
SetIndent( false );
}
else
{
SetIsTime( false );
SetIndent( true );
}
SetDisplayValue(m_iBonusProgress);
}
void CHudBonusProgress::SetChallengeLabel( void )
{
// Blank for no challenge
if ( m_iLastChallenge == 0 )
{
SetLabelText(L"");
return;
}
char szBonusTextName[] = "#Valve_Hud_BONUS_PROGRESS00";
int iStringLength = Q_strlen( szBonusTextName );
szBonusTextName[ iStringLength - 2 ] = ( m_iLastChallenge / 10 ) + '0';
szBonusTextName[ iStringLength - 1 ] = ( m_iLastChallenge % 10 ) + '0';
wchar_t *tempString = g_pVGuiLocalize->Find(szBonusTextName);
if (tempString)
{
SetLabelText(tempString);
return;
}
// Couldn't find a special string for this challenge
tempString = g_pVGuiLocalize->Find("#Valve_Hud_BONUS_PROGRESS");
if (tempString)
{
SetLabelText(tempString);
return;
}
// Couldn't find any localizable string
SetLabelText(L"BONUS");
}
|