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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================
#include "cbase.h"
#include "hud.h"
#include "hudelement.h"
#include "c_tf_player.h"
#include "iclientmode.h"
#include <vgui/ILocalize.h>
#include <vgui/ISurface.h>
#include <vgui/IVGui.h>
#include "c_baseobject.h"
#include "inputsystem/iinputsystem.h"
#include "tf_hud_menu_eureka_teleport.h"
// NVNT haptics for buildings
#include "haptics/haptic_utils.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
// Set to 1 to simulate xbox-style menu interaction
extern ConVar tf_build_menu_controller_mode;
DECLARE_HUDELEMENT_DEPTH( CHudEurekaEffectTeleportMenu, 41 ); // in front of engy building status
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHudEurekaEffectTeleportMenu::CHudEurekaEffectTeleportMenu( const char *pElementName )
: CHudElement( pElementName )
, BaseClass( NULL, "HudEurekaEffectTeleportMenu" )
, m_bWantsToTeleport( false )
, m_eSelectedTeleportTarget( EUREKA_TELEPORT_HOME )
, m_eCurrentBuildMenuLayout( BUILDMENU_DEFAULT )
{
Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetHiddenBits( HIDEHUD_MISCSTATUS );
vgui::ivgui()->AddTickSignal( GetVPanel() );
for( int i=0; i < EUREKA_NUM_TARGETS; ++i )
{
m_pAvilableTargets[ i ] = new EditablePanel( this, VarArgs( "available_target_%d", i+1 ) );
m_pUnavailableTargets[ i ] = new EditablePanel( this, VarArgs( "unavailable_target_%d", i+1 ) );
}
RegisterForRenderGroup( "mid" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudEurekaEffectTeleportMenu::ApplySchemeSettings( IScheme *pScheme )
{
const char *pszCustomDir = NULL;
switch( m_eCurrentBuildMenuLayout )
{
case BUILDMENU_PIPBOY:
pszCustomDir = "resource/UI/build_menu/pipboy";
break;
default:
case BUILDMENU_DEFAULT:
if ( ::input->IsSteamControllerActive() )
{
pszCustomDir = "resource/UI/build_menu_sc";
}
else
{
pszCustomDir = "resource/UI/build_menu";
}
break;
}
LoadControlSettings( VarArgs( "%s/HudMenuEurekaEffect.res", pszCustomDir) );
m_pAvilableTargets[ EUREKA_TELEPORT_HOME ]->LoadControlSettings( VarArgs( "%s/eureka_target_home_avail.res", pszCustomDir ) );
m_pAvilableTargets[ EUREKA_TELEPORT_TELEPORTER_EXIT ]->LoadControlSettings( VarArgs( "%s/eureka_target_tele_exit_avail.res", pszCustomDir ) );
m_pUnavailableTargets[ EUREKA_TELEPORT_HOME ]->LoadControlSettings( VarArgs( "%s/eureka_target_home_unavail.res", pszCustomDir ) );
m_pUnavailableTargets[ EUREKA_TELEPORT_TELEPORTER_EXIT ]->LoadControlSettings( VarArgs( "%s/eureka_target_tele_exit_unavail.res", pszCustomDir ) );
BaseClass::ApplySchemeSettings( pScheme );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CHudEurekaEffectTeleportMenu::ShouldDraw( void )
{
if ( !CanTeleport() )
{
m_bWantsToTeleport = false;
return false;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudEurekaEffectTeleportMenu::SetVisible( bool bState )
{
if ( bState == true )
{
// close the weapon selection menu
engine->ClientCmd( "cancelselect" );
// See if our layout needs to change, due to equipped items
buildmenulayouts_t eDesired = CHudMenuEngyBuild::CalcCustomBuildMenuLayout();
if ( eDesired != m_eCurrentBuildMenuLayout )
{
m_eCurrentBuildMenuLayout = eDesired;
InvalidateLayout( true, true );
}
const char* key = engine->Key_LookupBinding( "lastinv" );
if ( !key )
{
key = "< not bound >";
}
SetDialogVariable( "lastinv", key );
// Set selection to the first available building that we can build
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalPlayer )
return;
m_eSelectedTeleportTarget = EUREKA_TELEPORT_HOME;
SetSelectedItem( m_eSelectedTeleportTarget );
HideLowerPriorityHudElementsInGroup( "mid" );
}
else
{
UnhideLowerPriorityHudElementsInGroup( "mid" );
}
BaseClass::SetVisible( bState );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CHudEurekaEffectTeleportMenu::CanTeleport() const
{
if ( !m_bWantsToTeleport )
return false;
CTFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pPlayer )
return false;
CTFWeaponBase *pWpn = pPlayer->GetActiveTFWeapon();
if ( !pWpn )
return false;
// Don't show the menu for first person spectator
if ( pPlayer != pWpn->GetOwner() )
return false;
if ( !const_cast<CHudEurekaEffectTeleportMenu*>(this)->CHudElement::ShouldDraw() )
return false;
return ( pWpn->GetWeaponID() == TF_WEAPON_WRENCH );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudEurekaEffectTeleportMenu::SendTeleportMessage( eEurekaTeleportTargets eTeleportTarget )
{
// They've made their selection. Setting this to false will close this panel.
m_bWantsToTeleport = false;
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalPlayer )
return;
// We do code elsewhere that set the available targets panel visible if they're available.
// If it's not visible, it's not available.
// Can not use while karting
if ( !m_pAvilableTargets[ eTeleportTarget ]->IsVisible() || pLocalPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
{
pLocalPlayer->EmitSound( "Player.DenyWeaponSelection" );
return;
}
char szCmd[128];
Q_snprintf( szCmd, sizeof(szCmd), "eureka_teleport %d", (int)eTeleportTarget );
engine->ClientCmd( szCmd );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CHudEurekaEffectTeleportMenu::HudElementKeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBinding )
{
if ( !ShouldDraw() )
{
return 1;
}
if ( !down )
{
return 1;
}
bool bConsoleController = ( IsConsole() || ( keynum >= JOYSTICK_FIRST && !IsSteamControllerCode(keynum)) );
if ( bConsoleController )
{
int nNewSelection = m_eSelectedTeleportTarget;
switch( keynum )
{
case KEY_XBUTTON_UP:
// jump to last
nNewSelection = EUREKA_LAST_TARGET;
break;
case KEY_XBUTTON_DOWN:
// jump to first
nNewSelection = EUREKA_FIRST_TARGET;
break;
case KEY_XBUTTON_RIGHT:
// move selection to the right
nNewSelection++;
if ( nNewSelection > EUREKA_LAST_TARGET )
nNewSelection = EUREKA_FIRST_TARGET;
break;
case KEY_XBUTTON_LEFT:
// move selection to the left
nNewSelection--;
if ( nNewSelection <= 0 )
nNewSelection = EUREKA_LAST_TARGET;
break;
case KEY_XBUTTON_A:
case KEY_XBUTTON_RTRIGGER:
case KEY_XBUTTON_Y:
case KEY_XBUTTON_LTRIGGER:
// build selected item
SendTeleportMessage( (eEurekaTeleportTargets)nNewSelection );
return 0;
case KEY_XBUTTON_B:
// cancel, close the menu
engine->ExecuteClientCmd( "lastinv" );
return 0;
default:
return 1; // key not handled
}
SetSelectedItem( (eEurekaTeleportTargets)nNewSelection );
return 0;
}
else
{
int iSlot = 0;
// convert slot1, slot2 etc to 1,2,3,4
if( pszCurrentBinding && ( !Q_strncmp( pszCurrentBinding, "slot", NUM_ENGY_BUILDINGS ) && Q_strlen(pszCurrentBinding) > NUM_ENGY_BUILDINGS ) )
{
const char *pszNum = pszCurrentBinding+NUM_ENGY_BUILDINGS;
iSlot = atoi(pszNum);
// slot10 cancels
if ( iSlot == 10 )
{
engine->ExecuteClientCmd( "lastinv" );
return 0;
}
// allow slot1 - slot4
if ( iSlot < 1 || iSlot > EUREKA_NUM_TARGETS )
return 1;
}
else
{
switch( keynum )
{
case KEY_1:
iSlot = 1;
break;
case KEY_2:
iSlot = 2;
break;
case KEY_3:
case KEY_4:
case KEY_5:
case KEY_6:
case KEY_7:
case KEY_8:
case KEY_9:
// Eat these keys
return 0;
case KEY_0:
case KEY_XBUTTON_B:
case STEAMCONTROLLER_B:
// cancel, close the menu
engine->ExecuteClientCmd( "lastinv" );
return 0;
case STEAMCONTROLLER_DPAD_LEFT:
SendTeleportMessage( EUREKA_TELEPORT_HOME );
return 0;
case STEAMCONTROLLER_DPAD_RIGHT:
SendTeleportMessage( EUREKA_TELEPORT_TELEPORTER_EXIT );
return 0;
default:
return 1; // key not handled
}
}
if ( iSlot > 0 )
{
SendTeleportMessage( (eEurekaTeleportTargets)(iSlot-1) );
return 0;
}
}
return 1; // key not handled
}
void CHudEurekaEffectTeleportMenu::WantsToTeleport()
{
m_bWantsToTeleport = true;
InvalidateLayout( true, true );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudEurekaEffectTeleportMenu::SetSelectedItem( eEurekaTeleportTargets eSelectedTeleportTarget )
{
if ( m_eSelectedTeleportTarget != eSelectedTeleportTarget )
{
m_eSelectedTeleportTarget = eSelectedTeleportTarget;
// move the selection item to the new position
if ( m_pActiveSelection )
{
// move the selection background
int x, y;
m_pAvilableTargets[m_eSelectedTeleportTarget]->GetPos( x, y );
x -= XRES(4);
y -= XRES(4);
m_pActiveSelection->SetPos( x, y );
UpdateHintLabels();
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudEurekaEffectTeleportMenu::OnTick( void )
{
if ( !IsVisible() )
return;
C_TFPlayer *pLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalPlayer )
return;
m_pAvilableTargets[ EUREKA_TELEPORT_HOME ]->SetVisible( true );
m_pUnavailableTargets[ EUREKA_TELEPORT_HOME ]->SetVisible( false );
const C_BaseObject *pObj = pLocalPlayer->GetObjectOfType( OBJ_TELEPORTER, MODE_TELEPORTER_EXIT );
bool bTeleAvailable = pObj
&& !pObj->IsBuilding()
&& !pObj->IsPlacing()
&& !pObj->IsUpgrading()
&& !pObj->IsCarried();
m_pAvilableTargets[ EUREKA_TELEPORT_TELEPORTER_EXIT ]->SetVisible( bTeleAvailable );
m_pUnavailableTargets[ EUREKA_TELEPORT_TELEPORTER_EXIT ]->SetVisible( !bTeleAvailable );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudEurekaEffectTeleportMenu::UpdateHintLabels( void )
{
}
|