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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================
#include "vgui_baseui_interface.h"
#include "vgui/IVGui.h"
#include "vgui_controls/Frame.h"
#include "vgui_controls/Label.h"
#include "vgui_controls/AnimationController.h"
#include "vgui/ILocalize.h"
#include "mathlib/mathlib.h"
#include "inputsystem/ButtonCode.h"
#include "vgui_askconnectpanel.h"
#include "keys.h"
#include "cl_pluginhelpers.h"
using namespace vgui;
class CAskConnectPanel : public EditablePanel
{
DECLARE_CLASS_SIMPLE( CAskConnectPanel, vgui::EditablePanel );
public:
CAskConnectPanel( VPANEL parent );
~CAskConnectPanel();
void GetHostName( char *pOut, int maxOutBytes );
void SetHostName( const char *pHostName );
void StartSlideAnimation( float flDuration );
void UpdateCurrentPosition();
void Hide();
virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
virtual void ApplySettings(KeyValues *inResourceData);
virtual void OnTick();
public:
static CAskConnectPanel *s_pAskConnectPanel;
private:
char m_HostName[256];
Color m_bgColor;
int m_OriginalWidth; // Don't get less than this wide.
double m_flAnimationEndTime; // -1 if not playing
Label *m_pInfoLabel;
Label *m_pHostNameLabel;
int m_HostNameLabelRightSidePadding; // Grow the whole panel to make sure there's this much padding on the right of the hostname label.
Label *m_pAcceptLabel;
AnimationController *m_pAnimationController;
};
CAskConnectPanel *CAskConnectPanel::s_pAskConnectPanel = NULL;
CAskConnectPanel::CAskConnectPanel( VPANEL parent )
: BaseClass( NULL, "AskConnectPanel" ), m_bgColor( 0, 0, 0, 192 )
{
SetParent( parent );
Assert( s_pAskConnectPanel == NULL );
s_pAskConnectPanel = this;
m_flAnimationEndTime = -1;
SetKeyBoardInputEnabled( false );
SetMouseInputEnabled( false );
SetVisible( false );
m_pHostNameLabel = new Label( this, "HostNameLabel", "" );
m_pAcceptLabel = new Label( this, "AcceptLabel", "" );
m_pInfoLabel = new Label( this, "InfoLabel", "" );
m_HostName[0] = 0;
vgui::ivgui()->AddTickSignal( GetVPanel() );
SetAutoDelete( true );
m_pAnimationController = new vgui::AnimationController( NULL );
m_pAnimationController->SetParent( parent );
m_pAnimationController->SetScriptFile( parent, "scripts/plugin_animations.txt" );
m_pAnimationController->SetProportional( false );
LoadControlSettings( "resource\\askconnectpanel.res" );
InvalidateLayout( true );
m_OriginalWidth = GetWide();
int x, y, wide, tall;
m_pHostNameLabel->GetBounds( x, y, wide, tall );
m_HostNameLabelRightSidePadding = GetWide() - (x+wide);
}
CAskConnectPanel::~CAskConnectPanel()
{
s_pAskConnectPanel = NULL;
}
void CAskConnectPanel::GetHostName( char *pOut, int maxOutBytes )
{
V_strncpy( pOut, m_HostName, maxOutBytes );
}
void CAskConnectPanel::SetHostName( const char *pHostName )
{
V_strncpy( m_HostName, pHostName, sizeof( m_HostName ) );
m_pHostNameLabel->SetText( pHostName );
// Update our width.
int x, y, wide, tall;
m_pHostNameLabel->SizeToContents();
m_pHostNameLabel->GetBounds( x, y, wide, tall );
int x2, y2, wide2, tall2;
wchar_t wcMessage[512];
g_pVGuiLocalize->ConstructString_safe( wcMessage, g_pVGuiLocalize->Find("#Valve_ServerOfferingToConnect"), 0 );
m_pInfoLabel->SetText( wcMessage );
m_pInfoLabel->SizeToContents();
m_pInfoLabel->GetBounds( x2, y2, wide2, tall2 );
int desiredWidth = max(x+wide,x2+wide2) + m_HostNameLabelRightSidePadding;
if ( desiredWidth < m_OriginalWidth )
desiredWidth = m_OriginalWidth;
SetWide( desiredWidth );
}
void CAskConnectPanel::ApplySettings(KeyValues *inResourceData)
{
BaseClass::ApplySettings(inResourceData);
const char *pStr = inResourceData->GetString( "BgColor", NULL );
if ( pStr )
{
int r = 0, g = 0, b = 0, a = 0;
if ( sscanf( pStr, "%d %d %d %d", &r, &g, &b, &a ) == 4 )
{
m_bgColor = Color( r, g, b, a );
SetBgColor( m_bgColor );
}
}
}
void CAskConnectPanel::StartSlideAnimation( float flDuration )
{
m_flAnimationEndTime = Plat_FloatTime() + flDuration;
// Figure out what key they have bound...
const char *pKeyName = Key_NameForBinding( "askconnect_accept" );
if ( pKeyName )
{
wchar_t wcKeyName[64], wcMessage[512];
g_pVGuiLocalize->ConvertANSIToUnicode( pKeyName, wcKeyName, sizeof( wcKeyName ) );
g_pVGuiLocalize->ConstructString_safe( wcMessage, g_pVGuiLocalize->Find("#Valve_PressKeyToAccept"), 1, wcKeyName );
m_pAcceptLabel->SetText( wcMessage );
}
else
{
m_pAcceptLabel->SetText( "#Valve_BindKeyToAccept" );
}
m_pAnimationController->StartAnimationSequence( "AskConnectShow" );
SetVisible( true );
InvalidateLayout();
UpdateCurrentPosition();
}
void CAskConnectPanel::Hide()
{
m_flAnimationEndTime = -1;
SetVisible( false );
}
void CAskConnectPanel::OnTick()
{
// Do the hide animation?
if ( m_flAnimationEndTime != -1 )
{
if ( Plat_FloatTime() > m_flAnimationEndTime )
{
m_flAnimationEndTime = -1;
m_pAnimationController->StartAnimationSequence( "AskConnectHide" );
}
}
m_pAnimationController->UpdateAnimations( Sys_FloatTime() );
// Make sure vgui doesn't call Paint() on us after we're hidden.
if ( GetAlpha() == 0 )
SetVisible( false );
if ( IsVisible() )
{
UpdateCurrentPosition();
}
BaseClass::OnTick();
}
void CAskConnectPanel::UpdateCurrentPosition()
{
int x=0, y=0, wide=0, tall=0;
if ( g_PluginManager )
g_PluginManager->GetHudMessagePosition( x, y, wide, tall );
SetPos( x, y+tall );
}
void CAskConnectPanel::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetBgColor( m_bgColor );
SetPaintBackgroundType( 2 );
}
void SetupDefaultAskConnectAcceptKey()
{
// If they don't have a binding for askconnect_accept, set one up.
if ( !Key_NameForBinding( "askconnect_accept" ) )
{
// .. but only if they don't already have something setup for F3.
if ( !Key_BindingForKey( KEY_F3 ) )
{
Key_SetBinding( KEY_F3, "askconnect_accept" );
}
}
}
vgui::Panel* CreateAskConnectPanel( VPANEL parent )
{
return new CAskConnectPanel( parent );
}
void ShowAskConnectPanel( const char *pHostName, float flDuration )
{
const int cubHostName = V_strlen( pHostName );
if ( cubHostName <= 0 )
return;
// Hostname is not allowed to contain semicolon, whitespace, or control characters
for ( int i = 0; i < cubHostName; i++ )
{
if ( pHostName[i] == ';' || V_isspace( pHostName[i] ) || pHostName[i] < 0x20 )
{
return;
}
}
CAskConnectPanel *pPanel = CAskConnectPanel::s_pAskConnectPanel;
if ( pPanel )
{
pPanel->SetHostName( pHostName );
pPanel->StartSlideAnimation( flDuration );
pPanel->MoveToFront();
}
}
void HideAskConnectPanel()
{
CAskConnectPanel *pPanel = CAskConnectPanel::s_pAskConnectPanel;
if ( pPanel )
pPanel->Hide();
}
bool IsAskConnectPanelActive( char *pHostName, int maxHostNameBytes )
{
CAskConnectPanel *pPanel = CAskConnectPanel::s_pAskConnectPanel;
if ( pPanel && pPanel->IsVisible() && pPanel->GetAlpha() > 0 )
{
pPanel->GetHostName( pHostName, maxHostNameBytes );
return true;
}
else
{
return false;
}
}
|