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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include <vgui/ISurface.h>
#include <vgui/ILocalize.h>
#include "tf_shareddefs.h"
#include "tf_overview.h"
#include "c_playerresource.h"
#include "c_tf_objective_resource.h"
#include "usermessages.h"
#include "coordsize.h"
#include "clientmode.h"
#include <vgui_controls/AnimationController.h>
#include "voice_status.h"
#include "spectatorgui.h"
#include "c_team_objectiveresource.h"
using namespace vgui;
void __MsgFunc_UpdateRadar( bf_read &msg )
{
if ( !g_pMapOverview )
return;
int iPlayerEntity = msg.ReadByte();
while ( iPlayerEntity > 0 )
{
int x = msg.ReadSBitLong( COORD_INTEGER_BITS-1 ) * 4;
int y = msg.ReadSBitLong( COORD_INTEGER_BITS-1 ) * 4;
int a = msg.ReadSBitLong( 9 );
Vector origin( x, y, 0 );
QAngle angles( 0, a, 0 );
g_pMapOverview->SetPlayerPositions( iPlayerEntity-1, origin, angles );
iPlayerEntity = msg.ReadByte(); // read index for next player
}
}
extern ConVar _overview_mode;
ConVar _cl_minimapzoom( "_cl_minimapzoom", "1", FCVAR_ARCHIVE );
ConVar _overview_mode( "_overview_mode", "1", FCVAR_ARCHIVE, "Overview mode - 0=off, 1=inset, 2=full\n", true, 0, true, 2 );
CTFMapOverview *GetTFOverview( void )
{
return dynamic_cast<CTFMapOverview *>( g_pMapOverview );
}
// overview_togglezoom rotates through 3 levels of zoom for the small map
//-----------------------------------------------------------------------
void ToggleZoom( void )
{
if ( !GetTFOverview() )
return;
GetTFOverview()->ToggleZoom();
}
static ConCommand overview_togglezoom( "overview_togglezoom", ToggleZoom );
// overview_largemap toggles showing the large map
//------------------------------------------------
void ShowLargeMap( void )
{
if ( !GetTFOverview() )
return;
GetTFOverview()->ShowLargeMap();
}
static ConCommand overview_showlargemap( "+overview_largemap", ShowLargeMap );
void HideLargeMap( void )
{
if ( !GetTFOverview() )
return;
GetTFOverview()->HideLargeMap();
}
static ConCommand overview_hidelargemap( "-overview_largemap", HideLargeMap );
//--------------------------------
// map border ?
// icon minimum zoom
// flag swipes
// chatting icon
// voice com icon
//---------------------------------
DECLARE_HUDELEMENT( CTFMapOverview );
ConVar tf_overview_voice_icon_size( "tf_overview_voice_icon_size", "64", FCVAR_ARCHIVE );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CTFMapOverview::CTFMapOverview( const char *pElementName ) : BaseClass( pElementName )
{
InitTeamColorsAndIcons();
m_flIconSize = 96.0f;
m_iLastMode = MAP_MODE_OFF;
m_bDisabled = false;
m_nMapTextureOverlayID = -1;
usermessages->HookMessage( "UpdateRadar", __MsgFunc_UpdateRadar );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::Update()
{
UpdateCapturePoints();
BaseClass::Update();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::VidInit( void )
{
BaseClass::VidInit();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::UpdateCapturePoints()
{
if ( !g_pObjectiveResource )
return;
Color colorGreen( 0,255,0,255 );
for( int i = 0 ; i < g_pObjectiveResource->GetNumControlPoints() ; i++ )
{
// check if CP is visible at all
if( !g_pObjectiveResource->IsCPVisible( i ) )
{
if ( m_CapturePoints[i] != 0 )
{
// remove capture point from map
RemoveObject( m_CapturePoints[i] );
m_CapturePoints[i] = 0;
}
continue;
}
// ok, show CP
int iOwningTeam = g_pObjectiveResource->GetOwningTeam(i);
int iCappingTeam = g_pObjectiveResource->GetCappingTeam(i);
int iOwningIcon = g_pObjectiveResource->GetIconForTeam( i, iOwningTeam );
if ( iOwningIcon <= 0 )
continue; // baah
const char *textureName = GetMaterialNameFromIndex( iOwningIcon );
int objID = m_CapturePoints[i];
if ( objID == 0 )
{
// add object if not already there
objID = m_CapturePoints[i] = AddObject( textureName, 0, -1 );
// objective positions never change (so far)
SetObjectPosition( objID, g_pObjectiveResource->GetCPPosition(i), vec3_angle );
AddObjectFlags( objID, MAP_OBJECT_ALIGN_TO_MAP );
}
SetObjectIcon( objID, textureName, 128.0 );
// draw cap percentage
if( iCappingTeam != TEAM_UNASSIGNED )
{
SetObjectStatus( objID, g_pObjectiveResource->GetCPCapPercentage(i), colorGreen );
}
else
{
SetObjectStatus( objID, -1, colorGreen ); // turn it off
}
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::InitTeamColorsAndIcons()
{
BaseClass::InitTeamColorsAndIcons();
m_TeamColors[TF_TEAM_RED] = COLOR_TF_RED;
m_TeamIcons[TF_TEAM_RED] = AddIconTexture( "sprites/minimap_icons/red_player" );
m_CameraIcons[TF_TEAM_RED] = AddIconTexture( "sprites/minimap_icons/red_camera" );
m_TeamColors[TF_TEAM_BLUE] = COLOR_TF_BLUE;
m_TeamIcons[TF_TEAM_BLUE] = AddIconTexture( "sprites/minimap_icons/blue_player" );
m_CameraIcons[TF_TEAM_BLUE] = AddIconTexture( "sprites/minimap_icons/blue_camera" );
Q_memset( m_flPlayerChatTime, 0, sizeof(m_flPlayerChatTime ) );
m_iVoiceIcon = AddIconTexture( "voice/icntlk_pl" );
m_iChatIcon = AddIconTexture( "sprites/minimap_icons/voiceIcon" );
Q_memset( m_CapturePoints, 0, sizeof(m_CapturePoints) );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::DrawCamera()
{
C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
if ( !localPlayer )
return;
int iTexture = m_CameraIcons[localPlayer->GetTeamNumber()];
if ( localPlayer->IsObserver() || iTexture <= 0 )
{
BaseClass::DrawCamera();
}
else
{
MapObject_t obj;
memset( &obj, 0, sizeof(MapObject_t) );
obj.icon = iTexture;
obj.position = localPlayer->GetAbsOrigin();
obj.size = m_flIconSize * 1.5;
obj.angle = localPlayer->EyeAngles();
obj.status = -1;
DrawIcon( &obj );
DrawVoiceIconForPlayer( localPlayer->entindex() - 1 );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::FireGameEvent( IGameEvent *event )
{
const char * type = event->GetName();
if ( Q_strcmp( type, "player_death" ) == 0 )
{
MapPlayer_t *player = GetPlayerByUserID( event->GetInt( "userid" ) );
if ( player && CanPlayerBeSeen( player ) )
{
// create skull icon for 3 seconds
int handle = AddObject( "sprites/minimap_icons/death", 0, 3 );
SetObjectText( handle, player->name, player->color );
SetObjectPosition( handle, player->position, player->angle );
}
}
else if ( Q_strcmp( type, "game_newmap" ) == 0 )
{
SetMode( _overview_mode.GetInt() );
}
BaseClass::FireGameEvent( event );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFMapOverview::CanPlayerBeSeen( MapPlayer_t *player )
{
// rules that define if you can see a player on the overview or not
C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
if ( !localPlayer || !player )
return false;
// don't draw ourselves
if ( localPlayer->entindex() == (player->index+1) )
return false;
// if local player is on spectator team, he can see everyone
if ( localPlayer->GetTeamNumber() <= TEAM_SPECTATOR )
return true;
// we never track unassigned or real spectators
if ( player->team <= TEAM_SPECTATOR )
return false;
// ingame and as dead player we can only see our own teammates
return ( localPlayer->GetTeamNumber() == player->team );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::ShowLargeMap( void )
{
if ( IsDisabled() )
{
return;
}
// remember old mode
m_iLastMode = GetMode();
// if we hit the toggle while full, set to disappear when we release
if ( m_iLastMode == MAP_MODE_FULL )
{
m_iLastMode = MAP_MODE_OFF;
}
SetMode( MAP_MODE_FULL );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::HideLargeMap( void )
{
if ( IsDisabled() )
{
return;
}
SetMode( m_iLastMode );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::ToggleZoom( void )
{
if ( IsDisabled() )
{
return;
}
if ( GetMode() != MAP_MODE_INSET )
return;
int iZoomLevel = ( _cl_minimapzoom.GetInt() + 1 ) % TF_MAP_ZOOM_LEVELS;
_cl_minimapzoom.SetValue( iZoomLevel );
switch( _cl_minimapzoom.GetInt() )
{
case 0:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel1" );
break;
case 1:
default:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel2" );
break;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::SetMode(int mode)
{
if ( IsDisabled() )
{
return;
}
m_flChangeSpeed = 0; // change size instantly
if ( mode == MAP_MODE_OFF )
{
ShowPanel( false );
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapOff" );
}
else if ( mode == MAP_MODE_INSET )
{
switch( _cl_minimapzoom.GetInt() )
{
case 0:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel1" );
break;
case 1:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel2" );
break;
case 2:
default:
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapZoomLevel3" );
break;
}
C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
if ( pPlayer )
SetFollowEntity( pPlayer->entindex() );
ShowPanel( true );
if ( m_nMode == MAP_MODE_FULL )
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "MapScaleToSmall" );
else
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SnapToSmall" );
}
else if ( mode == MAP_MODE_FULL )
{
SetFollowEntity( 0 );
ShowPanel( true );
if ( m_nMode == MAP_MODE_INSET )
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "ZoomToLarge" );
else
g_pClientMode->GetViewportAnimationController()->StartAnimationSequence( "SnapToLarge" );
}
// finally set mode
m_nMode = mode;
// save in a cvar for archive
_overview_mode.SetValue( m_nMode );
UpdateSizeAndPosition();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::UpdateSizeAndPosition()
{
// move back up if the spectator menu is not visible
if ( !g_pSpectatorGUI || ( !g_pSpectatorGUI->IsVisible() && GetMode() == MAP_MODE_INSET ) )
{
int x,y,w,h;
GetBounds( x,y,w,h );
y = YRES(5); // hax, align to top of the screen
SetBounds( x,y,w,h );
}
BaseClass::UpdateSizeAndPosition();
}
ConVar cl_voicetest( "cl_voicetest", "0", FCVAR_CHEAT );
ConVar cl_overview_chat_time( "cl_overview_chat_time", "2.0", FCVAR_ARCHIVE );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::PlayerChat( int index )
{
m_flPlayerChatTime[index-1] = gpGlobals->curtime + cl_overview_chat_time.GetFloat();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::DrawMapPlayers()
{
BaseClass::DrawMapPlayers();
C_BasePlayer *localPlayer = C_BasePlayer::GetLocalPlayer();
Assert( localPlayer );
int iLocalPlayer = localPlayer->entindex() - 1;
for ( int i = 0 ; i < MAX_PLAYERS ; i++ )
{
if ( i == iLocalPlayer )
continue;
MapPlayer_t *player = &m_Players[i];
if ( !CanPlayerBeSeen( player ) )
continue;
if ( player->health <= 0 ) // don't draw dead players / spectators
continue;
DrawVoiceIconForPlayer( i );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::DrawVoiceIconForPlayer( int playerIndex )
{
Assert( playerIndex >= 0 && playerIndex < MAX_PLAYERS );
MapPlayer_t *player = &m_Players[playerIndex];
// if they just sent a chat msg, or are using voice, or did a hand signal or voice command
// draw a chat icon
if ( cl_voicetest.GetInt() || GetClientVoiceMgr()->IsPlayerSpeaking( player->index+1 ) )
{
MapObject_t obj;
memset( &obj, 0, sizeof(MapObject_t) );
obj.icon = m_iVoiceIcon;
obj.position = player->position;
obj.size = tf_overview_voice_icon_size.GetFloat();
obj.status = -1;
DrawIcon( &obj );
}
else if ( m_flPlayerChatTime[player->index] > gpGlobals->curtime )
{
MapObject_t obj;
memset( &obj, 0, sizeof(MapObject_t) );
obj.icon = m_iChatIcon;
obj.position = player->position;
obj.size = tf_overview_voice_icon_size.GetFloat();
obj.status = -1;
DrawIcon( &obj );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFMapOverview::DrawIcon( MapObject_t *obj )
{
for ( int i = 0 ; i < MAX_CONTROL_POINTS ; i++ )
{
if ( obj->objectID == m_CapturePoints[i] && obj->objectID != 0 )
{
return DrawCapturePoint( i, obj );
}
}
return BaseClass::DrawIcon( obj );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::DrawQuad( Vector pos, int scale, float angle, int textureID, int alpha )
{
Vector offset;
offset.z = 0;
offset.x = -scale; offset.y = scale;
VectorYawRotate( offset, angle, offset );
Vector2D pos1 = WorldToMap( pos + offset );
offset.x = scale; offset.y = scale;
VectorYawRotate( offset, angle, offset );
Vector2D pos2 = WorldToMap( pos + offset );
offset.x = scale; offset.y = -scale;
VectorYawRotate( offset, angle, offset );
Vector2D pos3 = WorldToMap( pos + offset );
offset.x = -scale; offset.y = -scale;
VectorYawRotate( offset, angle, offset );
Vector2D pos4 = WorldToMap( pos + offset );
Vertex_t points[4] =
{
Vertex_t( MapToPanel ( pos1 ), Vector2D(0,0) ),
Vertex_t( MapToPanel ( pos2 ), Vector2D(1,0) ),
Vertex_t( MapToPanel ( pos3 ), Vector2D(1,1) ),
Vertex_t( MapToPanel ( pos4 ), Vector2D(0,1) )
};
surface()->DrawSetColor( 255, 255, 255, alpha );
surface()->DrawSetTexture( textureID );
surface()->DrawTexturedPolygon( 4, points );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFMapOverview::DrawCapturePoint( int iCP, MapObject_t *obj )
{
int textureID = obj->icon;
Vector pos = obj->position;
float scale = obj->size;
Vector2D pospanel = WorldToMap( pos );
pospanel = MapToPanel( pospanel );
if ( !IsInPanel( pospanel ) )
return false; // player is not within overview panel
// draw capture swipe
DrawQuad( pos, scale, 0, textureID, 255 );
int iCappingTeam = g_pObjectiveResource->GetCappingTeam( iCP );
if ( iCappingTeam != TEAM_UNASSIGNED )
{
int iCapperIcon = g_pObjectiveResource->GetCPCappingIcon( iCP );
const char *textureName = GetMaterialNameFromIndex( iCapperIcon );
float flCapPercent = g_pObjectiveResource->GetCPCapPercentage(iCP);
bool bSwipeLeft = ( iCappingTeam == TF_TEAM_RED ) ? true : false;
DrawHorizontalSwipe( pos, scale, AddIconTexture( textureName ), flCapPercent, bSwipeLeft );
}
// fixup for noone is capping, but someone is in the area
int iNumBlue = g_pObjectiveResource->GetNumPlayersInArea( iCP, TF_TEAM_BLUE );
int iNumRed = g_pObjectiveResource->GetNumPlayersInArea( iCP, TF_TEAM_RED );
int iOwningTeam = g_pObjectiveResource->GetOwningTeam( iCP );
if ( iCappingTeam == TEAM_UNASSIGNED )
{
if ( iNumBlue > 0 && iNumRed == 0 && iOwningTeam != TF_TEAM_BLUE )
{
iCappingTeam = TF_TEAM_BLUE;
}
else if ( iNumRed > 0 && iNumBlue == 0 && iOwningTeam != TF_TEAM_RED )
{
iCappingTeam = TF_TEAM_RED;
}
}
if ( iCappingTeam != TEAM_UNASSIGNED )
{
// Draw the number of cappers below the icon
int numPlayers = g_pObjectiveResource->GetNumPlayersInArea( iCP, iCappingTeam );
int requiredPlayers = g_pObjectiveResource->GetRequiredCappers( iCP, iCappingTeam );
if ( requiredPlayers > 1 )
{
numPlayers = MIN( numPlayers, requiredPlayers );
wchar_t wText[6];
_snwprintf( wText, sizeof(wText)/sizeof(wchar_t), L"%d", numPlayers );
int wide, tall;
surface()->GetTextSize( m_hIconFont, wText, wide, tall );
int x = pospanel.x-(wide/2);
int y = pospanel.y;
// match the offset that MapOverview uses
y += GetPixelOffset( scale ) + 4;
// draw black shadow text
surface()->DrawSetTextColor( 0, 0, 0, 255 );
surface()->DrawSetTextPos( x+1, y );
surface()->DrawPrintText( wText, wcslen(wText) );
// draw name in color
surface()->DrawSetTextColor( g_PR->GetTeamColor( iCappingTeam ) );
surface()->DrawSetTextPos( x, y );
surface()->DrawPrintText( wText, wcslen(wText) );
}
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::DrawHorizontalSwipe( Vector pos, int scale, int textureID, float flCapPercentage, bool bSwipeLeft )
{
float flIconSize = scale * 2;
float width = ( flIconSize * flCapPercentage );
float uv1 = 0.0f;
float uv2 = 1.0f;
Vector2D uv11( uv1, uv2 );
Vector2D uv21( flCapPercentage, uv2 );
Vector2D uv22( flCapPercentage, uv1 );
Vector2D uv12( uv1, uv1 );
// reversing the direction of the swipe effect
if ( bSwipeLeft )
{
uv11.x = uv2 - flCapPercentage;
uv21.x = uv2;
uv22.x = uv2;
uv12.x = uv2 - flCapPercentage;
}
float flXPos = pos.x - scale;
float flYPos = pos.y - scale;
Vector upperLeft( flXPos, flYPos, 0 );
Vector upperRight( flXPos + width, flYPos, 0 );
Vector lowerRight( flXPos + width, flYPos + flIconSize, 0 );
Vector lowerLeft ( flXPos, flYPos + flIconSize, 0 );
/// reversing the direction of the swipe effect
if ( bSwipeLeft )
{
upperLeft.x = flXPos + flIconSize - width;
upperRight.x = flXPos + flIconSize;
lowerRight.x = flXPos + flIconSize;
lowerLeft.x = flXPos + flIconSize - width;
}
vgui::Vertex_t vert[4];
Vector2D pos0 = WorldToMap( upperLeft );
vert[0].Init( MapToPanel( pos0 ), uv11 );
Vector2D pos3 = WorldToMap( lowerLeft );
vert[1].Init( MapToPanel( pos3 ), uv12 );
Vector2D pos2 = WorldToMap( lowerRight );
vert[2].Init( MapToPanel( pos2 ), uv22 );
Vector2D pos1 = WorldToMap( upperRight );
vert[3].Init( MapToPanel( pos1 ), uv21 );
surface()->DrawSetColor( 255, 255, 255, 255 );
surface()->DrawSetTexture( textureID );
surface()->DrawTexturedPolygon( 4, vert );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::SetMap( const char * levelname )
{
BaseClass::SetMap( levelname );
if ( m_nMapTextureID != -1 )
{
// we found a texture for this map
SetDisabled( false );
SetMode( m_nMode );
}
else
{
// we failed to load a map image
SetDisabled( true );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CTFMapOverview::ShouldDraw( void )
{
if ( IsDisabled() )
{
return false;
}
return BaseClass::ShouldDraw();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::Paint()
{
UpdateMapOverlayTexture();
UpdateSizeAndPosition();
UpdateFollowEntity();
UpdateObjects();
UpdatePlayers();
// UpdatePlayerTrails();
DrawMapTexture();
DrawMapOverlayTexture();
// DrawMapPlayerTrails();
DrawObjects();
DrawMapPlayers();
DrawCamera();
Panel::Paint();
}
extern ConVar overview_alpha;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::DrawMapOverlayTexture()
{
// now draw a box around the outside of this panel
int x0, y0, x1, y1;
int wide, tall;
GetSize( wide, tall );
x0 = 0; y0 = 0; x1 = wide - 2; y1 = tall - 2;
if ( m_nMapTextureOverlayID < 0 )
{
return;
}
Vertex_t points[4] =
{
Vertex_t( MapToPanel ( Vector2D(0,0) ), Vector2D(0,0) ),
Vertex_t( MapToPanel ( Vector2D(OVERVIEW_MAP_SIZE-1,0) ), Vector2D(1,0) ),
Vertex_t( MapToPanel ( Vector2D(OVERVIEW_MAP_SIZE-1,OVERVIEW_MAP_SIZE-1) ), Vector2D(1,1) ),
Vertex_t( MapToPanel ( Vector2D(0,OVERVIEW_MAP_SIZE-1) ), Vector2D(0,1) )
};
int alpha = 255.0f * overview_alpha.GetFloat(); clamp( alpha, 1, 255 );
surface()->DrawSetColor( 255,255,255, alpha );
surface()->DrawSetTexture( m_nMapTextureOverlayID );
surface()->DrawTexturedPolygon( 4, points );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CTFMapOverview::UpdateMapOverlayTexture()
{
/*
char tempfile[MAX_PATH];
Q_snprintf( tempfile, sizeof( tempfile ), "overviews/%s_%s_%s_%s", levelname, roundname, capname, teamname );
// TODO release old texture ?
m_nMapTextureOverlayID = surface()->CreateNewTextureID();
//if we have not uploaded yet, lets go ahead and do so
surface()->DrawSetTextureFile( m_nMapTextureOverlayID, tempfile, true, false );
int wide, tall;
surface()->DrawGetTextureSize( m_nMapTextureOverlayID, wide, tall );
if ( wide != tall )
{
DevMsg( 1, "Error! CTFMapOverview::UpdateMapOverlayTexture: map overlay image must be a square.\n" );
m_nMapTextureOverlayID = -1;
return;
}
*/
}
|