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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "c_vguiscreen.h"
#include <vgui/IVGui.h>
#include <vgui_controls/Controls.h>
#include <vgui_controls/Label.h>
#include "clientmode_hlnormal.h"
#include "tier1/utllinkedlist.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Amount of time before breen teleports away
//-----------------------------------------------------------------------------
class C_InfoTeleporterCountdown : public C_BaseEntity
{
public:
DECLARE_CLASS( C_InfoTeleporterCountdown, C_BaseEntity );
DECLARE_CLIENTCLASS();
public:
C_InfoTeleporterCountdown();
~C_InfoTeleporterCountdown();
virtual bool ShouldDraw() { return false; }
private:
bool m_bCountdownStarted;
bool m_bDisabled;
float m_flStartTime;
float m_flTimeRemaining;
friend class CTeleportCountdownScreen;
};
//-----------------------------------------------------------------------------
// Global list of teleporters
//-----------------------------------------------------------------------------
CUtlFixedLinkedList<C_InfoTeleporterCountdown *> g_InfoTeleporterCountdownList;
//-----------------------------------------------------------------------------
// Networking
//-----------------------------------------------------------------------------
IMPLEMENT_CLIENTCLASS_DT( C_InfoTeleporterCountdown, DT_InfoTeleporterCountdown, CInfoTeleporterCountdown )
RecvPropInt( RECVINFO( m_bCountdownStarted ) ),
RecvPropInt( RECVINFO( m_bDisabled ) ),
RecvPropTime( RECVINFO( m_flStartTime ) ),
RecvPropFloat( RECVINFO( m_flTimeRemaining ) ),
END_RECV_TABLE()
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
C_InfoTeleporterCountdown::C_InfoTeleporterCountdown()
{
g_InfoTeleporterCountdownList.AddToTail( this );
}
C_InfoTeleporterCountdown::~C_InfoTeleporterCountdown()
{
g_InfoTeleporterCountdownList.FindAndRemove( this );
}
//-----------------------------------------------------------------------------
//
// In-game vgui panel which shows the teleporter countdown
//
//-----------------------------------------------------------------------------
class CTeleportCountdownScreen : public CVGuiScreenPanel
{
DECLARE_CLASS( CTeleportCountdownScreen, CVGuiScreenPanel );
public:
CTeleportCountdownScreen( vgui::Panel *parent, const char *panelName );
virtual bool Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData );
virtual void OnTick();
private:
vgui::Label *m_pTimeRemainingTitleLabel;
vgui::Label *m_pTimeRemainingLabel;
vgui::Label *m_pMalfunctionLabel;
};
//-----------------------------------------------------------------------------
// Standard VGUI panel for objects
//-----------------------------------------------------------------------------
DECLARE_VGUI_SCREEN_FACTORY( CTeleportCountdownScreen, "teleport_countdown_screen" );
//-----------------------------------------------------------------------------
// Constructor:
//-----------------------------------------------------------------------------
CTeleportCountdownScreen::CTeleportCountdownScreen( vgui::Panel *parent, const char *panelName )
: BaseClass( parent, panelName, g_hVGuiCombineScheme )
{
}
//-----------------------------------------------------------------------------
// Initialization
//-----------------------------------------------------------------------------
bool CTeleportCountdownScreen::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
{
// Load all of the controls in
if ( !BaseClass::Init(pKeyValues, pInitData) )
return false;
// Make sure we get ticked...
vgui::ivgui()->AddTickSignal( GetVPanel() );
// Grab ahold of certain well-known controls
// NOTE: it is valid for these controls to not exist!
m_pTimeRemainingTitleLabel = dynamic_cast<vgui::Label*>(FindChildByName( "TimeRemainingTitle" ));
m_pTimeRemainingLabel = dynamic_cast<vgui::Label*>(FindChildByName( "TimeRemaining" ));
m_pMalfunctionLabel = dynamic_cast<vgui::Label*>( FindChildByName( "MalfunctionLabel" ) );
return true;
}
//-----------------------------------------------------------------------------
// Frame-based update
//-----------------------------------------------------------------------------
void CTeleportCountdownScreen::OnTick()
{
BaseClass::OnTick();
// Find the active info teleporter countdown
C_InfoTeleporterCountdown *pActiveCountdown = NULL;
for ( int i = g_InfoTeleporterCountdownList.Head(); i != g_InfoTeleporterCountdownList.InvalidIndex();
i = g_InfoTeleporterCountdownList.Next(i) )
{
if ( g_InfoTeleporterCountdownList[i]->m_bCountdownStarted )
{
pActiveCountdown = g_InfoTeleporterCountdownList[i];
break;
}
}
if ( !GetEntity() || !pActiveCountdown )
{
m_pTimeRemainingTitleLabel->SetVisible( false );
m_pTimeRemainingLabel->SetVisible( false );
m_pMalfunctionLabel->SetVisible( false );
return;
}
// Make the appropriate labels visible
bool bMalfunction = pActiveCountdown->m_bDisabled;
m_pTimeRemainingTitleLabel->SetVisible( !bMalfunction );
m_pTimeRemainingLabel->SetVisible( !bMalfunction );
// This will make it flash
m_pMalfunctionLabel->SetVisible( bMalfunction && (((int)(gpGlobals->curtime) & 0x1) == 0x1) );
// Update the time remaining
if ( !bMalfunction )
{
char buf[32];
if (m_pTimeRemainingLabel)
{
float dt = gpGlobals->curtime - pActiveCountdown->m_flStartTime;
if ( dt < 0.0f )
{
dt = 0.0f;
}
int nTimeRemaining = (int)(pActiveCountdown->m_flTimeRemaining - dt + 0.5f);
if ( nTimeRemaining < 0 )
{
nTimeRemaining = 0;
}
Q_snprintf( buf, sizeof( buf ), "%d", nTimeRemaining );
m_pTimeRemainingLabel->SetText( buf );
}
}
}
|