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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: HUD Target ID element
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "tf_hud_target_id.h"
#include "c_tf_playerresource.h"
#include "iclientmode.h"
#include "vgui/ILocalize.h"
#include "c_baseobject.h"
#include "c_team.h"
#include "tf_gamerules.h"
#include "tf_hud_statpanel.h"
#if defined( REPLAY_ENABLED )
#include "replay/iclientreplaycontext.h"
#include "replay/ireplaymoviemanager.h"
#include "replay/ienginereplay.h"
#endif // REPLAY_ENABLED
#include "tf_weapon_bonesaw.h"
#include "sourcevr/isourcevirtualreality.h"
#include "tf_revive.h"
#include "tf_logic_robot_destruction.h"
#include "entity_capture_flag.h"
#include "vgui_avatarimage.h"
#include "VGuiMatSurface/IMatSystemSurface.h"
#include "renderparm.h"
#include "tf_dropped_weapon.h"
#include "econ/econ_item_description.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
extern ConVar cl_hud_minmode;
DECLARE_HUDELEMENT( CMainTargetID );
DECLARE_HUDELEMENT( CSpectatorTargetID );
DECLARE_HUDELEMENT( CSecondaryTargetID );
using namespace vgui;
enum
{
SPECTATOR_TARGET_ID_NORMAL = 0,
SPECTATOR_TARGET_ID_BOTTOM_LEFT,
SPECTATOR_TARGET_ID_BOTTOM_CENTER,
SPECTATOR_TARGET_ID_BOTTOM_RIGHT,
};
void SpectatorTargetLocationCallback( IConVar *var, const char *oldString, float oldFloat )
{
CSpectatorTargetID *pSpecTargetID = (CSpectatorTargetID *)GET_HUDELEMENT( CSpectatorTargetID );
if ( pSpecTargetID )
{
pSpecTargetID->InvalidateLayout();
}
}
ConVar tf_spectator_target_location( "tf_spectator_target_location", "0", FCVAR_ARCHIVE, "Determines the location of the spectator targetID panel.", true, 0, true, 3, SpectatorTargetLocationCallback );
ConVar tf_hud_target_id_disable_floating_health( "tf_hud_target_id_disable_floating_health", "0", FCVAR_ARCHIVE, "Set to disable floating health bar" );
ConVar tf_hud_target_id_alpha( "tf_hud_target_id_alpha", "100", FCVAR_ARCHIVE, "Alpha value of target id background, default 100" );
ConVar tf_hud_target_id_offset( "tf_hud_target_id_offset", "0", FCVAR_ARCHIVE, "RES file Y offset for target id" );
ConVar tf_hud_target_id_show_avatars( "tf_hud_target_id_show_avatars", "2", FCVAR_ARCHIVE, "Display Steam avatars on TargetID when using floating health icons. 1 = everyone, 2 = friends only." );
#ifdef STAGING_ONLY
ConVar tf_bountymode_showhealth( "tf_bountymode_showhealth", "0", FCVAR_ARCHIVE, "Show floating health icon over enemy players. 1 = show health, 2 = show health and level", true, 0, true, 2 );
#endif // STAGING_ONLY
bool ShouldHealthBarBeVisible( CBaseEntity *pTarget, CTFPlayer *pLocalPlayer )
{
if ( !pTarget || !pLocalPlayer )
return false;
if ( tf_hud_target_id_disable_floating_health.GetBool() )
return false;
if ( pTarget->IsHealthBarVisible() )
return true;
if ( !pTarget->IsPlayer() )
return false;
if ( pLocalPlayer->IsPlayerClass( TF_CLASS_SPY ) )
return true;
if ( pLocalPlayer->InSameTeam( pTarget ) )
return true;
if ( pLocalPlayer->InSameDisguisedTeam( pTarget ) )
return true;
int iSeeEnemyHealth = 0;
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pLocalPlayer, iSeeEnemyHealth, see_enemy_health )
if ( iSeeEnemyHealth )
return true;
return false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTargetID::CTargetID( const char *pElementName ) :
CHudElement( pElementName ), BaseClass( NULL, pElementName )
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
m_hFont = g_hFontTrebuchet24;
m_flLastChangeTime = 0;
m_iLastEntIndex = 0;
m_nOriginalY = 0;
m_bArenaPanelVisible = false;
SetHiddenBits( HIDEHUD_MISCSTATUS );
m_pTargetNameLabel = NULL;
m_pTargetDataLabel = NULL;
m_pBGPanel = NULL;
m_pMoveableIcon = NULL;
m_pMoveableSymbolIcon = NULL;
m_pMoveableIconBG = NULL;
m_pMoveableKeyLabel = NULL;
m_pTargetHealth = new CTFSpectatorGUIHealth( this, "SpectatorGUIHealth" );
m_pTargetAmmoIcon = NULL;
m_pTargetKillStreakIcon = NULL;
m_bLayoutOnUpdate = false;
m_pFloatingHealthIcon = NULL;
m_iLastScannedEntIndex = 0;
m_pAvatarImage = NULL;
RegisterForRenderGroup( "mid" );
RegisterForRenderGroup( "commentary" );
m_iRenderPriority = 5;
ListenForGameEvent( "show_class_layout" );
RegisterForRenderGroup( "arena_target_id" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTargetID::LevelShutdown( void )
{
if ( m_pFloatingHealthIcon )
{
m_pFloatingHealthIcon->MarkForDeletion();
m_pFloatingHealthIcon = NULL;
}
}
//-----------------------------------------------------------------------------
// Purpose: Setup
//-----------------------------------------------------------------------------
void CTargetID::Reset( void )
{
m_pTargetHealth->Reset();
vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
if ( pScheme )
{
m_LabelColorDefault = pScheme->GetColor( "Label.TextColor", Color( 255, 255, 255, 255 ) );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTargetID::FireGameEvent( IGameEvent * event )
{
const char *eventName = event->GetName();
if ( FStrEq( "show_class_layout", eventName ) )
{
if ( TFGameRules() && TFGameRules()->IsInArenaMode() && GetLocalPlayerTeam() > LAST_SHARED_TEAM )
{
m_bArenaPanelVisible = event->GetBool( "show", false );
}
else
{
m_bArenaPanelVisible = false;
}
InvalidateLayout( true );
}
}
//-----------------------------------------------------------------------------
bool CTargetID::DrawHealthIcon()
{
C_BaseEntity *pEnt = cl_entitylist->GetEnt( GetTargetIndex() );
if ( pEnt && pEnt->IsBaseObject() )
return true;
if ( tf_hud_target_id_disable_floating_health.GetBool() )
return true;
return false;
}
//-----------------------------------------------------------------------------
// Purpose: Find out which player to pull an avatar image from. pTFPlayer is the player under the crosshair.
//-----------------------------------------------------------------------------
C_TFPlayer *CTargetID::GetTargetForSteamAvatar( C_TFPlayer *pTFPlayer )
{
if ( !tf_hud_target_id_show_avatars.GetBool() )
return NULL;
if ( !pTFPlayer || ( g_TF_PR && g_TF_PR->IsFakePlayer( pTFPlayer->entindex() ) ) )
return NULL;
C_TFPlayer *pTFLocalPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pTFLocalPlayer )
return NULL;
// Health icon inside the panel (too busy - figure this out later)
if ( DrawHealthIcon() )
return NULL;
// Save room when healing or being healed
if ( pTFLocalPlayer->IsPlayerClass( TF_CLASS_MEDIC ) && pTFLocalPlayer->MedicGetHealTarget() == pTFPlayer )
return NULL;
C_TFPlayer *pTFHealer = NULL;
float flHealerChargeLevel = -1.f;
pTFLocalPlayer->GetHealer( &pTFHealer, &flHealerChargeLevel );
if ( pTFHealer && pTFHealer->entindex() == m_iTargetEntIndex )
return NULL;
if ( pTFPlayer->IsPlayerClass( TF_CLASS_SPY ) && pTFPlayer->m_Shared.InCond( TF_COND_DISGUISED ) )
{
C_TFPlayer *pDisguiseTarget = ToTFPlayer( pTFPlayer->m_Shared.GetDisguiseTarget() );
if ( pDisguiseTarget && ( pTFLocalPlayer->InSameTeam( pDisguiseTarget ) || pDisguiseTarget == pTFLocalPlayer ) )
{
// Bots don't (currently) have avatars.
if ( pDisguiseTarget->IsBot() )
return NULL;
if ( tf_hud_target_id_show_avatars.GetInt() == 2 && !pTFLocalPlayer->IsPlayerOnSteamFriendsList( pDisguiseTarget ) )
return NULL;
return pDisguiseTarget;
}
}
if ( pTFLocalPlayer->IsPlayerOnSteamFriendsList( pTFPlayer ) )
return pTFPlayer;
if ( tf_hud_target_id_show_avatars.GetInt() == 1 )
return pTFPlayer;
return NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTargetID::ApplySchemeSettings( vgui::IScheme *scheme )
{
LoadControlSettings( "resource/UI/TargetID.res" );
BaseClass::ApplySchemeSettings( scheme );
m_pTargetNameLabel = dynamic_cast<Label *>(FindChildByName("TargetNameLabel"));
m_pTargetDataLabel = dynamic_cast<Label *>(FindChildByName("TargetDataLabel"));
m_pBGPanel = dynamic_cast<CTFImagePanel *> ( FindChildByName("TargetIDBG") );
m_pMoveableSubPanel = dynamic_cast<vgui::EditablePanel *> ( FindChildByName("MoveableSubPanel") );
if ( m_pMoveableSubPanel )
{
m_pMoveableIcon = dynamic_cast<CIconPanel *> ( m_pMoveableSubPanel->FindChildByName("MoveableIcon") );
m_pMoveableSymbolIcon = dynamic_cast<vgui::ImagePanel *> ( m_pMoveableSubPanel->FindChildByName("MoveableSymbolIcon") );
m_pMoveableIconBG = dynamic_cast<CIconPanel *> ( m_pMoveableSubPanel->FindChildByName("MoveableIconBG") );
m_pMoveableKeyLabel = dynamic_cast<Label *>( m_pMoveableSubPanel->FindChildByName("MoveableKeyLabel") );
}
m_hFont = scheme->GetFont( "TargetID", true );
m_pTargetAmmoIcon = dynamic_cast<vgui::ImagePanel *>( FindChildByName( "AmmoIcon" ) );
m_pTargetKillStreakIcon = dynamic_cast<vgui::ImagePanel *>( FindChildByName( "KillStreakIcon" ) );
m_pAvatarImage = dynamic_cast< CAvatarImagePanel* >( FindChildByName( "AvatarImage" ) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTargetID::ApplySettings( KeyValues *inResourceData )
{
BaseClass::ApplySettings( inResourceData );
m_iRenderPriority = inResourceData->GetInt( "priority" );
int x;
GetPos( x, m_nOriginalY );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTargetID::GetRenderGroupPriority( void )
{
return m_iRenderPriority;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTargetID::UpdateFloatingHealthIconVisibility( bool bVisible )
{
if ( m_pFloatingHealthIcon && ( m_pFloatingHealthIcon->IsVisible() != bVisible ) )
{
m_pFloatingHealthIcon->SetVisible( bVisible );
}
}
//-----------------------------------------------------------------------------
// Purpose: clear out string etc between levels
//-----------------------------------------------------------------------------
void CTargetID::VidInit()
{
CHudElement::VidInit();
m_flLastChangeTime = 0;
m_iLastEntIndex = 0;
}
bool CTargetID::IsValidIDTarget( int nEntIndex, float flOldTargetRetainFOV, float &flNewTargetRetainFOV )
{
bool bReturn = false;
flNewTargetRetainFOV = 0.0f;
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalTFPlayer )
return false;
#ifdef STAGING_ONLY
if ( pLocalTFPlayer->m_Shared.InCond( TF_COND_STEALTHED_PHASE ) )
return false;
#endif // STAGING_ONLY
if ( nEntIndex )
{
C_BaseEntity *pEnt = cl_entitylist->GetEnt( nEntIndex );
if ( pEnt )
{
Vector vDiff = pEnt->EyePosition() - pLocalTFPlayer->EyePosition();
float flDist;
flDist = VectorNormalize( vDiff );
if ( flOldTargetRetainFOV != 0.0f )
{
// It has a FOV that maintains previous targets
Vector vForward;
pLocalTFPlayer->EyeVectors( &vForward );
float fAngle = 1.0f - vDiff.Dot( vForward );
fAngle = RemapVal( fAngle, 0.0f, 1.0f, 0.0f, 90.0f );
if ( fAngle > flOldTargetRetainFOV )
{
return false;
}
}
C_TFPlayer *pPlayer = ToTFPlayer( pEnt );
int iHideEnemyHealth = 0;
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pLocalTFPlayer, iHideEnemyHealth, hide_enemy_health );
bool bInSameTeam = pLocalTFPlayer->InSameDisguisedTeam( pEnt );
bool bSpy = pLocalTFPlayer->IsPlayerClass( TF_CLASS_SPY ) && iHideEnemyHealth == 0;
if ( TFGameRules() && TFGameRules()->IsMannVsMachineMode() )
{
// We don't want to show health bars to the spy in MVM because it's distracting
bSpy = false;
// Are we disguised as the enemy?
if ( pLocalTFPlayer->m_Shared.InCond( TF_COND_DISGUISED ) && pLocalTFPlayer->m_Shared.GetDisguiseTeam() != pLocalTFPlayer->GetTeamNumber() )
{
// Get the target's apparent team
int iTheirApparentTeam = pEnt->GetTeamNumber();
if ( pPlayer && pPlayer->m_Shared.InCond( TF_COND_DISGUISED ) )
{
iTheirApparentTeam = pPlayer->m_Shared.GetDisguiseTeam();
}
// Are we disguised as they appear?
if ( pLocalTFPlayer->m_Shared.GetDisguiseTeam() == iTheirApparentTeam )
{
// Don't show the health
bInSameTeam = false;
}
}
}
bool bSpectator = pLocalTFPlayer->GetTeamNumber() == TEAM_SPECTATOR;
int iSeeEnemyHealth = 0;
bool bStealthed = false;
bool bHealthBarVisible = ShouldHealthBarBeVisible( pEnt, pLocalTFPlayer );
bool bShow = bHealthBarVisible;
if ( pPlayer )
{
if ( pPlayer->m_Shared.IsStealthed() )
{
bStealthed = true;
bHealthBarVisible = false;
bShow = false;
}
if ( !bStealthed )
{
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pLocalTFPlayer, iSeeEnemyHealth, see_enemy_health );
}
bool bMaintainInFOV = !pLocalTFPlayer->InSameTeam( pEnt );
if ( bHealthBarVisible )
{
bool bEnemyPlayer = pPlayer->GetTeamNumber() != pLocalTFPlayer->GetTeamNumber();
bool bEnemyMiniBoss = pPlayer->IsMiniBoss() && bEnemyPlayer;
bShow = bEnemyMiniBoss;
#ifdef STAGING_ONLY
bShow |= TFGameRules() && TFGameRules()->IsBountyMode() && tf_bountymode_showhealth.GetInt() && bEnemyPlayer;
#endif // STAGING_ONLY
if ( bShow )
{
bMaintainInFOV = false;
// Minibosses keep the health indicator up within a small FOV until a different valid target is selected
// The FOV needs to grow exponentially when a target is getting near
if ( bEnemyMiniBoss )
{
bMaintainInFOV = true;
}
}
}
if ( bMaintainInFOV )
{
const float flMaxDist = 800.0f;
float fInterp = RemapVal( flMaxDist - MIN( flDist, flMaxDist ), 0.0f, flMaxDist, 0.0f, 1.0f );
fInterp *= fInterp;
flNewTargetRetainFOV = fInterp * 13.0f + 0.75f;
}
bReturn = ( bSpectator || pLocalTFPlayer->InSameTeam( pEnt ) || ( ( bInSameTeam || bSpy || iSeeEnemyHealth ) && !bStealthed ) );
}
if ( bShow || bHealthBarVisible )
{
// See if we're re-targeting our previous
if ( m_pFloatingHealthIcon )
{
if ( m_pFloatingHealthIcon->GetEntity() && m_pFloatingHealthIcon->GetEntity() == pEnt )
{
UpdateFloatingHealthIconVisibility( true );
}
else
{
// New target - clear previous
m_pFloatingHealthIcon->MarkForDeletion();
m_pFloatingHealthIcon = NULL;
}
}
//Recreate the floating health icon if there isn't one, we're not a spectator, and
// we're not a spy or this was a robot from Robot Destruction-Mode
if ( !m_pFloatingHealthIcon && !bSpectator && ( !bSpy || bHealthBarVisible ) && !DrawHealthIcon() )
{
m_pFloatingHealthIcon = CFloatingHealthIcon::AddFloatingHealthIcon( pEnt );
}
}
else if ( pEnt->IsBaseObject() && ( bInSameTeam || bSpy ) )
{
bReturn = true;
}
else if ( pEnt->IsVisibleToTargetID() )
{
bReturn = true;
}
else
{
UpdateFloatingHealthIconVisibility( false );
}
}
}
return bReturn;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTargetID::ShouldDraw( void )
{
if ( !CHudElement::ShouldDraw() )
{
UpdateFloatingHealthIconVisibility( false );
return false;
}
if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
{
UpdateFloatingHealthIconVisibility( false );
return false;
}
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalTFPlayer )
{
UpdateFloatingHealthIconVisibility( false );
return false;
}
if ( pLocalTFPlayer->IsTaunting() )
{
UpdateFloatingHealthIconVisibility( false );
return false;
}
// Get our target's ent index
m_iTargetEntIndex = CalculateTargetIndex(pLocalTFPlayer);
if ( !m_iTargetEntIndex )
{
if ( m_flTargetRetainFOV == 0.0f )
{
// Check to see if we should clear our ID
if ( m_flLastChangeTime && ( gpGlobals->curtime > m_flLastChangeTime ) )
{
m_flLastChangeTime = 0;
m_iLastEntIndex = 0;
}
else
{
// Keep re-using the old one
m_iTargetEntIndex = m_iLastEntIndex;
}
}
// If we're showing a floating health icon, and no longer have a target,
// hide it and see if it's the same entity next time
UpdateFloatingHealthIconVisibility( false );
}
else
{
m_flLastChangeTime = gpGlobals->curtime;
if ( m_iTargetEntIndex != m_iLastScannedEntIndex )
{
// If we switched to another, valid target for a floating health icon, recreate it on the next pass
if ( m_pFloatingHealthIcon )
{
m_pFloatingHealthIcon->MarkForDeletion();
m_pFloatingHealthIcon = NULL;
}
m_iLastScannedEntIndex = m_iTargetEntIndex;
}
}
float flTargetRetainFOV = 0.0f;
bool bReturn = IsValidIDTarget( m_iTargetEntIndex, 0.0f, flTargetRetainFOV );
if ( !bReturn )
{
m_iLastEntIndex = 0;
}
else
{
if ( !IsVisible() || (m_iTargetEntIndex != m_iLastEntIndex) )
{
m_iLastEntIndex = m_iTargetEntIndex;
m_bLayoutOnUpdate = true;
m_flTargetRetainFOV = flTargetRetainFOV;
if ( m_pAvatarImage )
{
m_pAvatarImage->SetVisible( false );
}
}
UpdateID();
}
return bReturn;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTargetID::PerformLayout( void )
{
int iXIndent = XRES(5);
int iXPostdent = XRES(10);
int iWidth = iXIndent + iXPostdent;
if ( DrawHealthIcon() )
{
iWidth += m_pTargetHealth->GetWide();
}
if ( m_pAvatarImage && m_pAvatarImage->IsVisible() )
{
iWidth += m_pAvatarImage->GetWide() + XRES( 2 );
}
int iTextW, iTextH;
int iDataW, iDataH;
if ( m_pTargetNameLabel && m_pTargetDataLabel )
{
m_pTargetNameLabel->GetContentSize( iTextW, iTextH );
m_pTargetDataLabel->GetContentSize( iDataW, iDataH );
iWidth += MAX(iTextW,iDataW);
if ( m_pBGPanel )
{
m_pBGPanel->SetSize( iWidth, GetTall() );
}
int x1 = 0, y1 = 0;
int x2 = 0, y2 = 0;
int x3 = 0, y3 = 0;
m_pTargetNameLabel->GetPos( x1, y1 );
m_pTargetDataLabel->GetPos( x2, y2 );
if ( m_pTargetKillStreakIcon )
{
m_pTargetKillStreakIcon->GetPos( x3, y3 );
}
int iWideExtra = 0;
if ( DrawHealthIcon() )
{
iWideExtra += m_pTargetHealth->GetWide();
}
if ( m_pAvatarImage && m_pAvatarImage->IsVisible() )
{
iWideExtra += m_pAvatarImage->GetWide() + XRES( 4 );
}
int nBuffer = ( m_pAvatarImage && m_pAvatarImage->IsVisible() ) ? 6 : 8;
m_pTargetNameLabel->SetPos( XRES( nBuffer ) + iWideExtra, y1 );
m_pTargetDataLabel->SetPos( XRES( nBuffer ) + iWideExtra, y2 );
if ( m_pTargetKillStreakIcon )
{
int nKSBuffer = ( cl_hud_minmode.GetBool() ) ? 6 : 9;
m_pTargetKillStreakIcon->SetPos( XRES( nKSBuffer ) + iWideExtra, y3 );
}
}
// Put the moveable icon to the right hand of our panel
if ( m_pMoveableSubPanel && m_pMoveableSubPanel->IsVisible() )
{
if ( m_pMoveableKeyLabel && m_pMoveableIcon && m_pMoveableSymbolIcon && m_pMoveableIconBG )
{
m_pMoveableKeyLabel->SizeToContents();
int iIndent = XRES(4);
int iMoveWide = MAX( XRES(16) + m_pMoveableKeyLabel->GetWide() + iIndent, (m_pMoveableIcon->GetWide()) + iIndent + XRES(8) );
m_pMoveableKeyLabel->SetWide( iMoveWide );
m_pMoveableSubPanel->SetSize( iMoveWide, GetTall() );
m_pMoveableSubPanel->SetPos( iWidth - iIndent, 0 );
int x,y;
m_pMoveableKeyLabel->GetPos( x, y );
m_pMoveableSymbolIcon->SetPos( (iMoveWide - m_pMoveableSymbolIcon->GetWide()) * 0.5, y - m_pMoveableSymbolIcon->GetTall() );
m_pMoveableSymbolIcon->GetPos( x, y );
m_pMoveableIcon->SetPos( (iMoveWide - m_pMoveableIcon->GetWide()) * 0.5, y - m_pMoveableIcon->GetTall() );
m_pMoveableIconBG->SetSize( m_pMoveableSubPanel->GetWide(), m_pMoveableSubPanel->GetTall() );
}
}
if ( m_pMoveableSubPanel && m_pMoveableSubPanel->IsVisible() )
{
// Now add our extra width to the total size
iWidth += m_pMoveableSubPanel->GetWide();
}
SetSize( iWidth, GetTall() );
int nOffset = m_bArenaPanelVisible ? YRES (120) : 0; // HACK: move the targetID up a bit so it won't overlap the panel
if( UseVR() )
{
SetPos( ScreenWidth() - iWidth - m_iXOffset, m_nOriginalY - nOffset + YRES( tf_hud_target_id_offset.GetInt() ) );
}
else
{
SetPos( (ScreenWidth() - iWidth) * 0.5, m_nOriginalY - nOffset + YRES( tf_hud_target_id_offset.GetInt() ) );
}
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CTargetID::CalculateTargetIndex( C_TFPlayer *pLocalTFPlayer )
{
int iIndex = pLocalTFPlayer->GetIDTarget();
// If our target entity is already in our secondary ID, don't show it in primary.
CSecondaryTargetID *pSecondaryID = GET_HUDELEMENT( CSecondaryTargetID );
if ( pSecondaryID && pSecondaryID != this && pSecondaryID->GetTargetIndex() == iIndex )
{
iIndex = 0;
}
return iIndex;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTargetID::UpdateID( void )
{
wchar_t sIDString[ MAX_ID_STRING ] = L"";
wchar_t sDataString[ MAX_ID_STRING ] = L"";
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalTFPlayer )
return;
// Default the labels' colors
Color colorName = m_LabelColorDefault;
Color colorData = m_LabelColorDefault;
// Get our target's ent index
// Is this an entindex sent by the server?
if ( m_iTargetEntIndex )
{
C_BaseEntity *pEnt = cl_entitylist->GetEnt( m_iTargetEntIndex );
if ( !pEnt )
return;
bool bShowHealth = false;
float flHealth = 0;
float flMaxHealth = 1;
int iMaxBuffedHealth = 0;
int iTargetTeam = pEnt->GetTeamNumber();
const char *pszActionCommand = NULL;
const char *pszActionIcon = NULL;
m_pTargetHealth->SetBuilding( false );
m_pTargetHealth->SetLevel( -1 );
// Some entities we always want to check, cause the text may change
// even while we're looking at it
// Is it a player?
if ( IsPlayerIndex( m_iTargetEntIndex ) )
{
const char *printFormatString = NULL;
wchar_t wszPlayerName[ MAX_PLAYER_NAME_LENGTH ];
bool bDisguisedTarget = false;
bool bDisguisedEnemy = false;
C_TFPlayer *pPlayer = static_cast<C_TFPlayer*>( pEnt );
if ( !pPlayer )
return;
C_TFPlayer *pDisguiseTarget = NULL;
g_pVGuiLocalize->ConvertANSIToUnicode( pPlayer->GetPlayerName(), wszPlayerName, sizeof(wszPlayerName) );
// determine if the target is a disguised spy (either friendly or enemy)
if ( pPlayer->m_Shared.InCond( TF_COND_DISGUISED ) && // they're disguised
//!pPlayer->m_Shared.InCond( TF_COND_DISGUISING ) && // they're not in the process of disguising
!pPlayer->m_Shared.IsStealthed() ) // they're not cloaked
{
bDisguisedTarget = true;
pDisguiseTarget = ToTFPlayer( pPlayer->m_Shared.GetDisguiseTarget() );
if ( pLocalTFPlayer->InSameTeam( pEnt ) == false )
{
iTargetTeam = pPlayer->m_Shared.GetDisguiseTeam();
}
}
if ( bDisguisedTarget )
{
// is the target a disguised enemy spy?
if ( pPlayer->IsEnemyPlayer() )
{
if ( pDisguiseTarget )
{
bDisguisedEnemy = true;
// change the player name
g_pVGuiLocalize->ConvertANSIToUnicode( pDisguiseTarget->GetPlayerName(), wszPlayerName, sizeof(wszPlayerName) );
// change the team / team color
}
}
}
bool bInSameTeam = pLocalTFPlayer->InSameDisguisedTeam( pEnt );
bool bSpy = pLocalTFPlayer->IsPlayerClass( TF_CLASS_SPY );
bool bMedic = pLocalTFPlayer->IsPlayerClass( TF_CLASS_MEDIC );
bool bHeavy = pLocalTFPlayer->IsPlayerClass( TF_CLASS_HEAVYWEAPONS );
// See if the player wants to fill in the data string
bool bIsAmmoData = false;
bool bIsKillStreakData = false;
pPlayer->GetTargetIDDataString( bDisguisedTarget, sDataString, sizeof(sDataString), bIsAmmoData, bIsKillStreakData );
if ( pLocalTFPlayer->GetTeamNumber() == TEAM_SPECTATOR || bInSameTeam || bSpy || bDisguisedEnemy || bMedic || bHeavy )
{
printFormatString = "#TF_playerid_sameteam";
bShowHealth = true;
}
else if ( pLocalTFPlayer->m_Shared.GetState() == TF_STATE_DYING )
{
// We're looking at an enemy who killed us.
printFormatString = "#TF_playerid_diffteam";
bShowHealth = true;
}
if ( bShowHealth )
{
if ( g_TF_PR )
{
if ( bDisguisedEnemy )
{
flHealth = (float)pPlayer->m_Shared.GetDisguiseHealth();
flMaxHealth = (float)pPlayer->m_Shared.GetDisguiseMaxHealth();
iMaxBuffedHealth = pPlayer->m_Shared.GetDisguiseMaxBuffedHealth();
}
else
{
flHealth = (float)pPlayer->GetHealth();
flMaxHealth = g_TF_PR->GetMaxHealth( m_iTargetEntIndex );
iMaxBuffedHealth = pPlayer->m_Shared.GetMaxBuffedHealth();
}
}
else
{
bShowHealth = false;
}
}
if ( printFormatString )
{
const wchar_t *pszPrepend = GetPrepend();
if ( !pszPrepend || !pszPrepend[0] )
{
pszPrepend = L"";
}
g_pVGuiLocalize->ConstructString_safe( sIDString, g_pVGuiLocalize->Find(printFormatString), 2, pszPrepend, wszPlayerName );
}
// Show target's clip state to attached medics
bool bShowClipInfo = bIsAmmoData &&
sDataString[0] &&
ToTFPlayer( pLocalTFPlayer->MedicGetHealTarget() ) == pPlayer;
if ( m_pTargetAmmoIcon && m_pTargetAmmoIcon->IsVisible() != bShowClipInfo )
{
m_pTargetAmmoIcon->SetVisible( bShowClipInfo );
}
bool bShowKillStreak = bIsKillStreakData && sDataString[0];
if ( m_pTargetKillStreakIcon && m_pTargetKillStreakIcon->IsVisible() != bShowKillStreak )
{
m_pTargetKillStreakIcon->SetVisible( bShowKillStreak );
}
}
else
{
// see if it is an object
if ( pEnt->IsBaseObject() )
{
C_BaseObject *pObj = assert_cast<C_BaseObject *>( pEnt );
pObj->GetTargetIDString( sIDString, sizeof(sIDString), false );
pObj->GetTargetIDDataString( sDataString, sizeof(sDataString) );
bShowHealth = true;
flHealth = pObj->GetHealth();
flMaxHealth = pObj->GetMaxHealth();
m_pTargetHealth->SetBuilding( true );
if ( m_pTargetKillStreakIcon )
{
m_pTargetKillStreakIcon->SetVisible( false );
}
// Switch the icon to the right object
if ( pObj->GetBuilder() == pLocalTFPlayer )
{
int iObj = pObj->GetType();
if ( iObj >= OBJ_DISPENSER && iObj <= OBJ_SENTRYGUN )
{
if ( pLocalTFPlayer->CanPickupBuilding(pObj) )
{
pszActionCommand = "+attack2";
}
switch ( iObj )
{
default:
case OBJ_DISPENSER:
pszActionIcon = "obj_status_dispenser";
break;
case OBJ_TELEPORTER:
{
pszActionIcon = (pObj->GetObjectMode() == MODE_TELEPORTER_ENTRANCE) ? "obj_status_tele_entrance" : "obj_status_tele_exit";
}
break;
case OBJ_SENTRYGUN:
{
int iLevel = pObj->GetUpgradeLevel();
if ( iLevel == 3 )
{
pszActionIcon = "obj_status_sentrygun_3";
}
else
{
pszActionIcon = (iLevel == 2) ? "obj_status_sentrygun_2" : "obj_status_sentrygun_1";
}
}
break;
}
}
}
}
// Generic
else if ( pEnt->IsVisibleToTargetID() )
{
CCaptureFlag *pFlag = dynamic_cast< CCaptureFlag * >( pEnt );
if ( pFlag && pFlag->GetPointValue() > 0 )
{
bShowHealth = false;
g_pVGuiLocalize->ConvertANSIToUnicode( CFmtStr("%d Points", pFlag->GetPointValue() ), sIDString, sizeof(sIDString) );
}
else
{
CTFDroppedWeapon *pDroppedWeapon = dynamic_cast< CTFDroppedWeapon * >( pEnt );
if ( pDroppedWeapon )
{
CEconItemView* pDroppedEconItem = pDroppedWeapon->GetItem();
if ( pLocalTFPlayer->GetDroppedWeaponInRange() != NULL )
{
pszActionIcon = "obj_weapon_pickup";
pszActionCommand = "+use_action_slot_item";
}
if ( FStrEq( pDroppedEconItem->GetStaticData()->GetItemClass(), "tf_weapon_medigun" ) )
{
wchar_t wszChargeLevel[10];
_snwprintf( wszChargeLevel, ARRAYSIZE( wszChargeLevel ) - 1, L"%.0f", pDroppedWeapon->GetChargeLevel() * 100 );
wszChargeLevel[ARRAYSIZE( wszChargeLevel ) - 1] = '\0';
g_pVGuiLocalize->ConstructString_safe( sIDString, L"%s1 (%s2%)", 2, CEconItemLocalizedFullNameGenerator( GLocalizationProvider(), pDroppedEconItem->GetItemDefinition(), pDroppedEconItem->GetItemQuality() ).GetFullName(), wszChargeLevel );
}
else
{
g_pVGuiLocalize->ConstructString_safe( sIDString, L"%s1", 1, CEconItemLocalizedFullNameGenerator( GLocalizationProvider(), pDroppedEconItem->GetItemDefinition(), pDroppedEconItem->GetItemQuality() ).GetFullName() );
}
locchar_t wszPlayerName [128];
CBasePlayer *pOwner = GetPlayerByAccountID( pDroppedEconItem->GetAccountID() );
// Bots will not work here, so don't fill this out.
if ( pOwner )
{
g_pVGuiLocalize->ConvertANSIToUnicode( pOwner->GetPlayerName(), wszPlayerName, sizeof(wszPlayerName) );
g_pVGuiLocalize->ConstructString_safe( sDataString, g_pVGuiLocalize->Find( "#TF_WhoDropped" ), 1, wszPlayerName );
// Get the rarity color
vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( GetScheme() );
if ( pScheme )
{
const char* pszColorName = GetItemSchema()->GetRarityColor( pDroppedEconItem->GetItemDefinition()->GetRarity() );
pszColorName = pszColorName ? pszColorName : "TanLight";
colorName = pScheme->GetColor( pszColorName, Color( 255, 255, 255, 255 ) );
}
}
}
else if ( pLocalTFPlayer->InSameTeam( pEnt ) )
{
bShowHealth = true;
flHealth = pEnt->GetHealth();
flMaxHealth = pEnt->GetMaxHealth();
iMaxBuffedHealth = pEnt->GetMaxHealth();
// Display respawn timer on revive markers by hacking bountymode's player level display
if ( !pEnt->IsPlayer() )
{
CTFReviveMarker *pMarker = dynamic_cast< CTFReviveMarker* >( pEnt );
if ( pMarker && pMarker->GetOwner() )
{
float flRespawn = TFGameRules()->GetNextRespawnWave( pMarker->GetTeamNumber(), pMarker->GetOwner() ) - gpGlobals->curtime;
m_pTargetHealth->SetLevel( (int)flRespawn );
g_pVGuiLocalize->ConvertANSIToUnicode( pMarker->GetOwner()->GetPlayerName(), sIDString, sizeof(sIDString) );
}
}
}
}
}
}
// Setup health icon
if ( !pEnt->IsAlive() && ( pEnt->IsPlayer() || pEnt->IsBaseObject() ) )
{
flHealth = 0; // fixup for health being 1 when dead
}
m_pTargetHealth->SetHealth( flHealth, flMaxHealth, iMaxBuffedHealth );
m_pTargetHealth->SetVisible( DrawHealthIcon() );
if ( m_pMoveableSubPanel )
{
bool bShowActionKey = pszActionCommand != NULL;
if ( m_pMoveableSubPanel->IsVisible() != bShowActionKey )
{
m_pMoveableSubPanel->SetVisible( bShowActionKey );
m_bLayoutOnUpdate = true;
}
if ( m_pMoveableSubPanel->IsVisible() )
{
const char *pBoundKey = engine->Key_LookupBinding( pszActionCommand );
m_pMoveableSubPanel->SetDialogVariable( "movekey", pBoundKey );
}
if ( m_pMoveableIcon )
{
if ( pszActionIcon )
{
m_pMoveableIcon->SetIcon( pszActionIcon );
}
m_pMoveableIcon->SetVisible( pszActionIcon != NULL );
}
}
if ( m_pAvatarImage && pEnt->IsPlayer() )
{
C_BasePlayer *pTFTarget = GetTargetForSteamAvatar( ToTFPlayer( pEnt ) );
bool bShowAvatar = ( pTFTarget ) ? true : false;
if ( m_pAvatarImage->IsVisible() != bShowAvatar )
{
m_pAvatarImage->SetVisible( bShowAvatar );
if ( bShowAvatar )
{
m_pAvatarImage->SetPlayer( pTFTarget );
m_pAvatarImage->SetShouldDrawFriendIcon( false );
m_pAvatarImage->SetAlpha( tf_hud_target_id_alpha.GetInt() );
}
}
}
if ( m_pTargetNameLabel && m_pTargetDataLabel )
{
int iNameW, iDataW, iIgnored;
m_pTargetNameLabel->GetContentSize( iNameW, iIgnored );
m_pTargetDataLabel->GetContentSize( iDataW, iIgnored );
// Target name
if ( sIDString[0] )
{
sIDString[ ARRAYSIZE(sIDString)-1 ] = '\0';
m_pTargetNameLabel->SetVisible(true);
m_pTargetNameLabel->SetFgColor( colorName );
// TODO: Support if( hud_centerid.GetInt() == 0 )
SetDialogVariable( "targetname", sIDString );
}
else
{
m_pTargetNameLabel->SetVisible(false);
m_pTargetNameLabel->SetText("");
}
// Extra target data
if ( sDataString[0] )
{
sDataString[ ARRAYSIZE(sDataString)-1 ] = '\0';
m_pTargetDataLabel->SetVisible(true);
m_pTargetDataLabel->SetFgColor( colorData );
SetDialogVariable( "targetdata", sDataString );
}
else
{
m_pTargetDataLabel->SetVisible(false);
m_pTargetDataLabel->SetText("");
}
int iPostNameW, iPostDataW;
m_pTargetNameLabel->GetContentSize( iPostNameW, iIgnored );
m_pTargetDataLabel->GetContentSize( iPostDataW, iIgnored );
if ( m_pBGPanel )
{
m_pBGPanel->SetBGTeam( iTargetTeam );
m_pBGPanel->UpdateBGImage();
m_pBGPanel->SetAlpha( tf_hud_target_id_alpha.GetInt() );
}
if ( m_bLayoutOnUpdate || (iPostDataW != iDataW) || (iPostNameW != iNameW) )
{
InvalidateLayout( true );
m_bLayoutOnUpdate = false;
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CSecondaryTargetID::CSecondaryTargetID( const char *pElementName ) : CTargetID( pElementName )
{
m_wszPrepend[0] = '\0';
RegisterForRenderGroup( "mid" );
m_bWasHidingLowerElements = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CSecondaryTargetID::ShouldDraw( void )
{
bool bDraw = BaseClass::ShouldDraw();
if ( bDraw )
{
if ( !m_bWasHidingLowerElements )
{
HideLowerPriorityHudElementsInGroup( "mid" );
m_bWasHidingLowerElements = true;
}
}
else
{
if ( m_bWasHidingLowerElements )
{
UnhideLowerPriorityHudElementsInGroup( "mid" );
m_bWasHidingLowerElements = false;
}
}
return bDraw;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CSecondaryTargetID::CalculateTargetIndex( C_TFPlayer *pLocalTFPlayer )
{
// If we're a medic & we're healing someone, target him.
CBaseEntity *pHealTarget = pLocalTFPlayer->MedicGetHealTarget();
if ( pHealTarget )
{
if ( pHealTarget->entindex() != m_iTargetEntIndex )
{
g_pVGuiLocalize->ConstructString_safe( m_wszPrepend, g_pVGuiLocalize->Find("#TF_playerid_healtarget" ), 0 );
}
return pHealTarget->entindex();
}
// If we have a healer, target him.
C_TFPlayer *pHealer;
float flHealerChargeLevel;
pLocalTFPlayer->GetHealer( &pHealer, &flHealerChargeLevel );
if ( pHealer )
{
if ( pHealer->entindex() != m_iTargetEntIndex )
{
g_pVGuiLocalize->ConstructString_safe( m_wszPrepend, g_pVGuiLocalize->Find("#TF_playerid_healer" ), 0 );
}
return pHealer->entindex();
}
if ( m_iTargetEntIndex )
{
m_wszPrepend[0] = '\0';
}
return 0;
}
// Separately declared versions of the hud element for alive and dead so they
// can have different positions
bool CMainTargetID::ShouldDraw( void )
{
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalTFPlayer )
return false;
if ( pLocalTFPlayer->GetObserverMode() > OBS_MODE_NONE )
return false;
return BaseClass::ShouldDraw();
}
bool CSpectatorTargetID::ShouldDraw( void )
{
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalTFPlayer )
return false;
if ( pLocalTFPlayer->GetObserverMode() <= OBS_MODE_NONE ||
pLocalTFPlayer->GetObserverMode() == OBS_MODE_FREEZECAM )
return false;
if ( pLocalTFPlayer->m_bIsCoaching )
{
return false;
}
// Hide panel for freeze-cam screenshot?
extern bool IsTakingAFreezecamScreenshot();
extern ConVar hud_freezecamhide;
if ( IsTakingAFreezecamScreenshot() && hud_freezecamhide.GetBool() )
return false;
#if defined( REPLAY_ENABLED )
if ( g_pEngineClientReplay->IsPlayingReplayDemo() )
return false;
#endif
return BaseClass::ShouldDraw();
}
int CSpectatorTargetID::CalculateTargetIndex( C_TFPlayer *pLocalTFPlayer )
{
int iIndex = BaseClass::CalculateTargetIndex( pLocalTFPlayer );
#if defined( REPLAY_ENABLED )
// Don't execute this if we're watching a replay
if ( ( !g_pEngineClientReplay || !g_pEngineClientReplay->IsPlayingReplayDemo() ) && pLocalTFPlayer->GetObserverMode() == OBS_MODE_IN_EYE && pLocalTFPlayer->GetObserverTarget() )
#else
if ( pLocalTFPlayer->GetObserverMode() == OBS_MODE_IN_EYE && pLocalTFPlayer->GetObserverTarget() )
#endif
{
iIndex = pLocalTFPlayer->GetObserverTarget()->entindex();
}
return iIndex;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CSpectatorTargetID::ApplySchemeSettings( vgui::IScheme *scheme )
{
BaseClass::ApplySchemeSettings( scheme );
if ( m_pBGPanel )
{
m_pBGPanel->SetVisible( false );
}
m_pBGPanel_Spec_Blue = FindChildByName("TargetIDBG_Spec_Blue");
m_pBGPanel_Spec_Red = FindChildByName("TargetIDBG_Spec_Red");
if ( m_pBGPanel_Spec_Blue )
{
m_pBGPanel_Spec_Blue->SetVisible( true );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CSpectatorTargetID::PerformLayout( void )
{
int iXIndent = XRES(5);
int iXPostdent = XRES(10);
int iWidth = m_pTargetHealth->GetWide() + iXIndent + iXPostdent;
int iTextW, iTextH;
int iDataW, iDataH;
if ( m_pTargetNameLabel && m_pTargetDataLabel )
{
m_pTargetNameLabel->GetContentSize( iTextW, iTextH );
m_pTargetDataLabel->GetContentSize( iDataW, iDataH );
iWidth += MAX(iTextW,iDataW);
SetSize( iWidth, GetTall() );
int nOffset = m_bArenaPanelVisible ? YRES (120) : 0; // HACK: move the targetID up a bit so it won't overlap the panel
int x1 = 0, y1 = 0;
int x2 = 0, y2 = 0;
int x3 = 0, y3 = 0;
m_pTargetNameLabel->GetPos( x1, y1 );
m_pTargetDataLabel->GetPos( x2, y2 );
if ( m_pTargetKillStreakIcon )
{
m_pTargetKillStreakIcon->GetPos( x3, y3 );
}
// Shift Labels
{
int nBuffer = ( m_pAvatarImage && m_pAvatarImage->IsVisible() ) ? 6 : 8;
m_pTargetNameLabel->SetPos( XRES( nBuffer ) + m_pTargetHealth->GetWide(), y1 );
m_pTargetDataLabel->SetPos( XRES( nBuffer ) + m_pTargetHealth->GetWide(), y2 );
if ( m_pTargetKillStreakIcon )
{
m_pTargetKillStreakIcon->SetPos( XRES( 10 ) + m_pTargetHealth->GetWide(), y3 );
}
}
if ( tf_spectator_target_location.GetInt() == SPECTATOR_TARGET_ID_NORMAL )
{
SetPos( (ScreenWidth() - iWidth) * 0.5, m_nOriginalY - nOffset );
}
else
{
int iBottomBarHeight = 0;
if ( g_pSpectatorGUI && g_pSpectatorGUI->IsVisible() )
{
iBottomBarHeight = g_pSpectatorGUI->GetBottomBarHeight();
}
int iYPos = ScreenHeight() - GetTall() - iBottomBarHeight - m_iYOffset;
if ( tf_spectator_target_location.GetInt() == SPECTATOR_TARGET_ID_BOTTOM_LEFT )
{
SetPos( m_iXOffset, iYPos );
}
else if ( tf_spectator_target_location.GetInt() == SPECTATOR_TARGET_ID_BOTTOM_CENTER )
{
SetPos( (ScreenWidth() - iWidth) * 0.5, iYPos );
}
else if ( tf_spectator_target_location.GetInt() == SPECTATOR_TARGET_ID_BOTTOM_RIGHT )
{
SetPos( ScreenWidth() - iWidth - m_iXOffset, iYPos );
}
}
if ( m_pBGPanel_Spec_Blue )
{
m_pBGPanel_Spec_Blue->SetSize( iWidth, GetTall() );
}
if ( m_pBGPanel_Spec_Red )
{
m_pBGPanel_Spec_Red->SetSize( iWidth, GetTall() );
}
if ( m_pBGPanel_Spec_Blue && m_pBGPanel_Spec_Red )
{
if ( m_iTargetEntIndex )
{
C_BaseEntity *pEnt = cl_entitylist->GetEnt( m_iTargetEntIndex );
if ( pEnt )
{
bool bRed = ( pEnt->GetTeamNumber() == TF_TEAM_RED );
m_pBGPanel_Spec_Blue->SetVisible( !bRed );
m_pBGPanel_Spec_Red->SetVisible( bRed );
m_pBGPanel_Spec_Blue->SetAlpha( tf_hud_target_id_alpha.GetInt() );
m_pBGPanel_Spec_Red->SetAlpha( tf_hud_target_id_alpha.GetInt() );
}
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CFloatingHealthIcon::CFloatingHealthIcon( vgui::Panel *parent, const char *name ) : EditablePanel( parent, name )
{
m_flPrevHealth = -1.f;
m_nPrevLevel = 0;
SetVisible( false );
SetBounds( 0, 0, 128, 128 );
vgui::ivgui()->AddTickSignal( GetVPanel(), 50 );
OnTick();
m_pTargetHealth = new CTFSpectatorGUIHealth( this, "SpectatorGUIHealth" );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CFloatingHealthIcon::Reset( void )
{
m_pTargetHealth->Reset();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CFloatingHealthIcon::SetEntity( C_BaseEntity *pEntity )
{
m_hEntity = pEntity;
if ( !m_pTargetHealth )
return;
m_pTargetHealth->SetAllowAnimations( false );
m_pTargetHealth->HideHealthBonusImage();
bool bBuilding = false;
if ( m_hEntity->IsPlayer() )
{
C_TFPlayer *pPlayer = ToTFPlayer( m_hEntity );
bBuilding = ( pPlayer && pPlayer->IsMiniBoss() ) ? true : false;
}
m_pTargetHealth->SetBuilding( bBuilding );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CFloatingHealthIcon* CFloatingHealthIcon::AddFloatingHealthIcon( C_BaseEntity *pEntity )
{
CFloatingHealthIcon *pHealthIcon = new CFloatingHealthIcon( g_pClientMode->GetViewport(), "HealthIcon" );
vgui::SETUP_PANEL( pHealthIcon );
pHealthIcon->SetEntity( pEntity );
return pHealthIcon;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CFloatingHealthIcon::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
LoadControlSettings( "resource/UI/HealthIconPanel.res" );
SetVisible( false );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CFloatingHealthIcon::OnTick( void )
{
if ( !m_pTargetHealth )
return;
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !ShouldHealthBarBeVisible( m_hEntity, pLocalTFPlayer ) )
{
SetVisible( false );
return;
}
C_TFPlayer *pTargetPlayer = ToTFPlayer( m_hEntity );
if ( pTargetPlayer && pTargetPlayer->m_Shared.IsStealthed() )
{
SetVisible( false );
return;
}
// Defaults for all entities
float flHealth = m_hEntity->GetHealth();
float flMaxHealth = m_hEntity->GetMaxHealth();
float iMaxBuffedHealth = m_hEntity->GetMaxHealth();
if ( pTargetPlayer && pTargetPlayer->m_Shared.InCond( TF_COND_DISGUISED ) && pTargetPlayer->IsEnemyPlayer() )
{
flHealth = (float)pTargetPlayer->m_Shared.GetDisguiseHealth();
flMaxHealth = (float)pTargetPlayer->m_Shared.GetDisguiseMaxHealth();
iMaxBuffedHealth = pTargetPlayer->m_Shared.GetDisguiseMaxBuffedHealth();
}
if ( flHealth != m_flPrevHealth )
{
m_pTargetHealth->SetHealth( flHealth, flMaxHealth, iMaxBuffedHealth );
m_flPrevHealth = flHealth;
}
#ifdef STAGING_ONLY
if ( TFGameRules() && TFGameRules()->IsBountyMode() && tf_bountymode_showhealth.GetInt() == 2 )
{
if ( m_hEntity->IsPlayer() )
{
if ( !pTargetPlayer || pTargetPlayer->IsMiniBoss() )
return;
int nPlayerLevel = pTargetPlayer->GetExperienceLevel();
if ( nPlayerLevel != m_nPrevLevel )
{
m_pTargetHealth->SetLevel( nPlayerLevel );
m_nPrevLevel = nPlayerLevel;
}
}
}
#endif // STAGING_ONLY
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
ConVar tf_healthicon_height_offset( "tf_healthicon_height_offset", "10", FCVAR_ARCHIVE, "Offset of the health icon away from the top of the target." );
void CFloatingHealthIcon::Paint( void )
{
if ( !CalculatePosition() )
return;
BaseClass::Paint();
}
//-----------------------------------------------------------------------------
bool CFloatingHealthIcon::CalculatePosition( )
{
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalTFPlayer )
return false;
if ( !m_hEntity || m_hEntity->IsDormant() )
{
return false;
}
Vector vecTarget = m_hEntity->GetAbsOrigin();
// Reposition based on our target's position
Vector vecDistance = vecTarget - pLocalTFPlayer->GetAbsOrigin();
vecTarget.z += VEC_HULL_MAX_SCALED( m_hEntity->GetBaseAnimating() ).z + tf_healthicon_height_offset.GetInt() + m_hEntity->GetHealthBarHeightOffset();
int iX, iY;
GetVectorInHudSpace( vecTarget, iX, iY ); // TODO: GetVectorInHudSpace or GetVectorInScreenSpace?
SetPos( iX - ( GetWide() / 2 ), iY - GetTall() );
return true;
}
//-----------------------------------------------------------------------------
void CFloatingHealthIcon::SetVisible( bool state )
{
if ( state )
{
CalculatePosition();
}
BaseClass::SetVisible( state );
}
//-----------------------------------------------------------------------------
bool CFloatingHealthIcon::IsVisible( void )
{
if ( !m_pTargetHealth )
return false;
C_TFPlayer *pLocalTFPlayer = C_TFPlayer::GetLocalTFPlayer();
if ( !pLocalTFPlayer )
return false;
//if ( pLocalTFPlayer->GetObserverMode() == OBS_MODE_FREEZECAM )
if ( pLocalTFPlayer->GetObserverMode() > OBS_MODE_NONE )
return false;
if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
return false;
return BaseClass::IsVisible();
}
|