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
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "hud_basechat.h"
#include <vgui/IScheme.h>
#include <vgui/IVGui.h>
#include "iclientmode.h"
#include "hud_macros.h"
#include "engine/IEngineSound.h"
#include "text_message.h"
#include <vgui/ILocalize.h>
#include "vguicenterprint.h"
#include "vgui/KeyCode.h"
#include <KeyValues.h>
#include "ienginevgui.h"
#include "c_playerresource.h"
#include "ihudlcd.h"
#include "vgui/IInput.h"
#include "vgui/ILocalize.h"
#include "multiplay_gamerules.h"
#include "voice_status.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define CHAT_WIDTH_PERCENTAGE 0.6f
#ifndef _XBOX
ConVar hud_saytext_time( "hud_saytext_time", "12", 0 );
ConVar cl_showtextmsg( "cl_showtextmsg", "1", 0, "Enable/disable text messages printing on the screen." );
ConVar cl_chatfilters( "cl_chatfilters", "63", FCVAR_CLIENTDLL | FCVAR_ARCHIVE, "Stores the chat filter settings " );
ConVar cl_chatfilter_version( "cl_chatfilter_version", "0", FCVAR_CLIENTDLL | FCVAR_ARCHIVE | FCVAR_HIDDEN, "Stores the chat filter version" );
ConVar cl_mute_all_comms("cl_mute_all_comms", "1", FCVAR_ARCHIVE, "If 1, then all communications from a player will be blocked when that player is muted, including chat messages.");
const int kChatFilterVersion = 1;
Color g_ColorBlue( 153, 204, 255, 255 );
Color g_ColorRed( 255, 63, 63, 255 );
Color g_ColorGreen( 153, 255, 153, 255 );
Color g_ColorDarkGreen( 64, 255, 64, 255 );
Color g_ColorYellow( 255, 178, 0, 255 );
Color g_ColorGrey( 204, 204, 204, 255 );
// removes all color markup characters, so Msg can deal with the string properly
// returns a pointer to str
char* RemoveColorMarkup( char *str )
{
char *out = str;
for ( char *in = str; *in != 0; ++in )
{
if ( *in > 0 && *in < COLOR_MAX )
{
if ( *in == COLOR_HEXCODE || *in == COLOR_HEXCODE_ALPHA )
{
// skip the next six or eight characters
const int nSkip = ( *in == COLOR_HEXCODE ? 6 : 8 );
for ( int i = 0; i < nSkip && *in != 0; i++ )
{
++in;
}
// if we reached the end of the string first, then back up
if ( *in == 0 )
{
--in;
}
}
continue;
}
*out = *in;
++out;
}
*out = 0;
return str;
}
// converts all '\r' characters to '\n', so that the engine can deal with the properly
// returns a pointer to str
char* ConvertCRtoNL( char *str )
{
for ( char *ch = str; *ch != 0; ch++ )
if ( *ch == '\r' )
*ch = '\n';
return str;
}
// converts all '\r' characters to '\n', so that the engine can deal with the properly
// returns a pointer to str
wchar_t* ConvertCRtoNL( wchar_t *str )
{
for ( wchar_t *ch = str; *ch != 0; ch++ )
if ( *ch == L'\r' )
*ch = L'\n';
return str;
}
void StripEndNewlineFromString( char *str )
{
int s = strlen( str ) - 1;
if ( s >= 0 )
{
if ( str[s] == '\n' || str[s] == '\r' )
str[s] = 0;
}
}
void StripEndNewlineFromString( wchar_t *str )
{
int s = wcslen( str ) - 1;
if ( s >= 0 )
{
if ( str[s] == L'\n' || str[s] == L'\r' )
str[s] = 0;
}
}
//-----------------------------------------------------------------------------
// Purpose: Reads a string from the current message and checks if it is translatable
//-----------------------------------------------------------------------------
wchar_t* ReadLocalizedString( bf_read &msg, OUT_Z_BYTECAP(outSizeInBytes) wchar_t *pOut, int outSizeInBytes, bool bStripNewline, OUT_Z_CAP(originalSize) char *originalString, int originalSize )
{
char szString[2048];
szString[0] = 0;
msg.ReadString( szString, sizeof(szString) );
if ( originalString )
{
Q_strncpy( originalString, szString, originalSize );
}
const wchar_t *pBuf = g_pVGuiLocalize->Find( szString );
if ( pBuf )
{
V_wcsncpy( pOut, pBuf, outSizeInBytes );
}
else
{
g_pVGuiLocalize->ConvertANSIToUnicode( szString, pOut, outSizeInBytes );
}
if ( bStripNewline )
StripEndNewlineFromString( pOut );
return pOut;
}
//-----------------------------------------------------------------------------
// Purpose: Reads a string from the current message, converts it to unicode, and strips out color codes
//-----------------------------------------------------------------------------
wchar_t* ReadChatTextString( bf_read &msg, OUT_Z_BYTECAP(outSizeInBytes) wchar_t *pOut, int outSizeInBytes )
{
char szString[2048];
szString[0] = 0;
msg.ReadString( szString, sizeof(szString) );
g_pVGuiLocalize->ConvertANSIToUnicode( szString, pOut, outSizeInBytes );
StripEndNewlineFromString( pOut );
// converts color control characters into control characters for the normal color
for ( wchar_t *test = pOut; test && *test; ++test )
{
if ( *test && (*test < COLOR_MAX ) )
{
if ( *test == COLOR_HEXCODE || *test == COLOR_HEXCODE_ALPHA )
{
// mark the next seven or nine characters. one for the control character and six or eight for the code itself.
const int nSkip = ( *test == COLOR_HEXCODE ? 7 : 9 );
for ( int i = 0; i < nSkip && *test != 0; i++, test++ )
{
*test = COLOR_NORMAL;
}
// if we reached the end of the string first, then back up
if ( *test == 0 )
{
--test;
}
}
else
{
*test = COLOR_NORMAL;
}
}
}
return pOut;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *parent -
// *panelName -
//-----------------------------------------------------------------------------
CBaseHudChatLine::CBaseHudChatLine( vgui::Panel *parent, const char *panelName ) :
vgui::RichText( parent, panelName )
{
m_hFont = m_hFontMarlett = 0;
m_flExpireTime = 0.0f;
m_flStartTime = 0.0f;
m_iNameLength = 0;
m_text = NULL;
SetPaintBackgroundEnabled( true );
SetVerticalScrollbar( false );
}
CBaseHudChatLine::~CBaseHudChatLine()
{
if ( m_text )
{
delete[] m_text;
m_text = NULL;
}
}
void CBaseHudChatLine::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
m_hFont = pScheme->GetFont( "Default" );
#ifdef HL1_CLIENT_DLL
SetBgColor( Color( 0, 0, 0, 0 ) );
SetFgColor( Color( 0, 0, 0, 0 ) );
SetBorder( NULL );
#else
SetBgColor( Color( 0, 0, 0, 100 ) );
#endif
m_hFontMarlett = pScheme->GetFont( "Marlett" );
m_clrText = pScheme->GetColor( "FgColor", GetFgColor() );
SetFont( m_hFont );
}
void CBaseHudChatLine::PerformFadeout( void )
{
// Flash + Extra bright when new
float curtime = gpGlobals->curtime;
int lr = m_clrText[0];
int lg = m_clrText[1];
int lb = m_clrText[2];
if ( curtime >= m_flStartTime && curtime < m_flStartTime + CHATLINE_FLASH_TIME )
{
float frac1 = ( curtime - m_flStartTime ) / CHATLINE_FLASH_TIME;
float frac = frac1;
frac *= CHATLINE_NUM_FLASHES;
frac *= 2 * M_PI;
frac = cos( frac );
frac = clamp( frac, 0.0f, 1.0f );
frac *= (1.0f-frac1);
int r = lr, g = lg, b = lb;
r = r + ( 255 - r ) * frac;
g = g + ( 255 - g ) * frac;
b = b + ( 255 - b ) * frac;
// Draw a right facing triangle in red, faded out over time
int alpha = 63 + 192 * (1.0f - frac1 );
alpha = clamp( alpha, 0, 255 );
wchar_t wbuf[4096];
GetText(0, wbuf, sizeof(wbuf));
SetText( "" );
InsertColorChange( Color( r, g, b, 255 ) );
InsertString( wbuf );
}
else if ( curtime <= m_flExpireTime && curtime > m_flExpireTime - CHATLINE_FADE_TIME )
{
float frac = ( m_flExpireTime - curtime ) / CHATLINE_FADE_TIME;
int alpha = frac * 255;
alpha = clamp( alpha, 0, 255 );
wchar_t wbuf[4096];
GetText(0, wbuf, sizeof(wbuf));
SetText( "" );
InsertColorChange( Color( lr * frac, lg * frac, lb * frac, alpha ) );
InsertString( wbuf );
}
else
{
wchar_t wbuf[4096];
GetText(0, wbuf, sizeof(wbuf));
SetText( "" );
InsertColorChange( Color( lr, lg, lb, 255 ) );
InsertString( wbuf );
}
OnThink();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : time -
//-----------------------------------------------------------------------------
void CBaseHudChatLine::SetExpireTime( void )
{
m_flStartTime = gpGlobals->curtime;
m_flExpireTime = m_flStartTime + hud_saytext_time.GetFloat();
m_nCount = CBaseHudChat::m_nLineCounter++;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
int CBaseHudChatLine::GetCount( void )
{
return m_nCount;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CBaseHudChatLine::IsReadyToExpire( void )
{
// Engine disconnected, expire right away
if ( !engine->IsInGame() && !engine->IsConnected() )
return true;
if ( gpGlobals->curtime >= m_flExpireTime )
return true;
return false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : float
//-----------------------------------------------------------------------------
float CBaseHudChatLine::GetStartTime( void )
{
return m_flStartTime;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseHudChatLine::Expire( void )
{
SetVisible( false );
// Spit out label text now
// char text[ 256 ];
// GetText( text, 256 );
// Msg( "%s\n", text );
}
#endif // _XBOX
//-----------------------------------------------------------------------------
// Purpose: The prompt and text entry area for chat messages
//-----------------------------------------------------------------------------
#ifndef _XBOX
CBaseHudChatInputLine::CBaseHudChatInputLine( vgui::Panel *parent, char const *panelName ) :
vgui::Panel( parent, panelName )
{
SetMouseInputEnabled( false );
m_pPrompt = new vgui::Label( this, "ChatInputPrompt", L"Enter text:" );
m_pInput = new CBaseHudChatEntry( this, "ChatInput", parent );
m_pInput->SetMaximumCharCount( 127 );
}
void CBaseHudChatInputLine::ApplySchemeSettings(vgui::IScheme *pScheme)
{
BaseClass::ApplySchemeSettings(pScheme);
// FIXME: Outline
vgui::HFont hFont = pScheme->GetFont( "ChatFont" );
m_pPrompt->SetFont( hFont );
m_pInput->SetFont( hFont );
m_pInput->SetFgColor( pScheme->GetColor( "Chat.TypingText", pScheme->GetColor( "Panel.FgColor", Color( 255, 255, 255, 255 ) ) ) );
SetPaintBackgroundEnabled( true );
m_pPrompt->SetPaintBackgroundEnabled( true );
m_pPrompt->SetContentAlignment( vgui::Label::a_west );
m_pPrompt->SetTextInset( 2, 0 );
m_pInput->SetMouseInputEnabled( true );
#ifdef HL1_CLIENT_DLL
m_pInput->SetBgColor( Color( 255, 255, 255, 0 ) );
#endif
SetBgColor( Color( 0, 0, 0, 0) );
}
void CBaseHudChatInputLine::SetPrompt( const wchar_t *prompt )
{
Assert( m_pPrompt );
m_pPrompt->SetText( prompt );
InvalidateLayout();
}
void CBaseHudChatInputLine::ClearEntry( void )
{
Assert( m_pInput );
SetEntry( L"" );
}
void CBaseHudChatInputLine::SetEntry( const wchar_t *entry )
{
Assert( m_pInput );
Assert( entry );
m_pInput->SetText( entry );
}
void CBaseHudChatInputLine::GetMessageText( OUT_Z_BYTECAP(buffersizebytes) wchar_t *buffer, int buffersizebytes )
{
m_pInput->GetText( buffer, buffersizebytes);
}
void CBaseHudChatInputLine::PerformLayout()
{
BaseClass::PerformLayout();
int wide, tall;
GetSize( wide, tall );
int w,h;
m_pPrompt->GetContentSize( w, h);
m_pPrompt->SetBounds( 0, 0, w, tall );
m_pInput->SetBounds( w + 2, 0, wide - w - 2 , tall );
}
vgui::Panel *CBaseHudChatInputLine::GetInputPanel( void )
{
return m_pInput;
}
#endif //_XBOX
CHudChatFilterButton::CHudChatFilterButton( vgui::Panel *pParent, const char *pName, const char *pText ) :
BaseClass( pParent, pName, pText )
{
}
CHudChatFilterCheckButton::CHudChatFilterCheckButton( vgui::Panel *pParent, const char *pName, const char *pText, int iFlag ) :
BaseClass( pParent, pName, pText )
{
m_iFlag = iFlag;
}
CHudChatFilterPanel::CHudChatFilterPanel( vgui::Panel *pParent, const char *pName ) : BaseClass ( pParent, pName )
{
pParent->SetSize( 10, 10 ); // Quiet "parent not sized yet" spew
SetParent( pParent );
new CHudChatFilterCheckButton( this, "joinleave_button", "Sky is blue?", CHAT_FILTER_JOINLEAVE );
new CHudChatFilterCheckButton( this, "namechange_button", "Sky is blue?", CHAT_FILTER_NAMECHANGE );
new CHudChatFilterCheckButton( this, "publicchat_button", "Sky is blue?", CHAT_FILTER_PUBLICCHAT );
new CHudChatFilterCheckButton( this, "servermsg_button", "Sky is blue?", CHAT_FILTER_SERVERMSG );
new CHudChatFilterCheckButton( this, "teamchange_button", "Sky is blue?", CHAT_FILTER_TEAMCHANGE );
//=============================================================================
// HPE_BEGIN:
// [tj]Added a new filter checkbox for achievement announces.
// Also. Yes. Sky is blue.
//=============================================================================
new CHudChatFilterCheckButton( this, "achivement_button", "Sky is blue?", CHAT_FILTER_ACHIEVEMENT);
//=============================================================================
// HPE_END
//=============================================================================
}
void CHudChatFilterPanel::ApplySchemeSettings(vgui::IScheme *pScheme)
{
LoadControlSettings( "resource/UI/ChatFilters.res" );
BaseClass::ApplySchemeSettings( pScheme );
Color cColor = pScheme->GetColor( "DullWhite", GetBgColor() );
SetBgColor( Color ( cColor.r(), cColor.g(), cColor.b(), CHAT_HISTORY_ALPHA ) );
SetFgColor( pScheme->GetColor( "Blank", GetFgColor() ) );
}
void CHudChatFilterPanel::OnFilterButtonChecked( vgui::Panel *panel )
{
CHudChatFilterCheckButton *pButton = dynamic_cast < CHudChatFilterCheckButton * > ( panel );
if ( pButton && GetChatParent() && IsVisible() )
{
if ( pButton->IsSelected() )
{
GetChatParent()->SetFilterFlag( GetChatParent()->GetFilterFlags() | pButton->GetFilterFlag() );
}
else
{
GetChatParent()->SetFilterFlag( GetChatParent()->GetFilterFlags() & ~ pButton->GetFilterFlag() );
}
}
}
void CHudChatFilterPanel::SetVisible(bool state)
{
if ( state == true )
{
for (int i = 0; i < GetChildCount(); i++)
{
CHudChatFilterCheckButton *pButton = dynamic_cast < CHudChatFilterCheckButton * > ( GetChild(i) );
if ( pButton )
{
if ( cl_chatfilters.GetInt() & pButton->GetFilterFlag() )
{
pButton->SetSelected( true );
}
else
{
pButton->SetSelected( false );
}
}
}
}
BaseClass::SetVisible( state );
}
void CHudChatFilterButton::DoClick( void )
{
BaseClass::DoClick();
CBaseHudChat *pChat = dynamic_cast < CBaseHudChat * > (GetParent() );
if ( pChat )
{
pChat->GetChatInput()->RequestFocus();
if ( pChat->GetChatFilterPanel() )
{
if ( pChat->GetChatFilterPanel()->IsVisible() )
{
pChat->GetChatFilterPanel()->SetVisible( false );
}
else
{
pChat->GetChatFilterPanel()->SetVisible( true );
pChat->GetChatFilterPanel()->MakePopup();
pChat->GetChatFilterPanel()->SetMouseInputEnabled( true );
}
}
}
}
CHudChatHistory::CHudChatHistory( vgui::Panel *pParent, const char *panelName ) : BaseClass( pParent, "HudChatHistory" )
{
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ChatScheme.res", "ChatScheme");
SetScheme(scheme);
InsertFade( -1, -1 );
}
void CHudChatHistory::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings( pScheme );
SetFont( pScheme->GetFont( "ChatFont" ) );
SetAlpha( 255 );
}
int CBaseHudChat::m_nLineCounter = 1;
//-----------------------------------------------------------------------------
// Purpose: Text chat input/output hud element
//-----------------------------------------------------------------------------
CBaseHudChat::CBaseHudChat( const char *pElementName )
: CHudElement( pElementName ), BaseClass( NULL, "HudChat" )
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ChatScheme.res", "ChatScheme" );
SetScheme(scheme);
g_pVGuiLocalize->AddFile( "resource/chat_%language%.txt" );
m_nMessageMode = 0;
vgui::ivgui()->AddTickSignal( GetVPanel() );
// (We don't actually want input until they bring up the chat line).
MakePopup();
SetZPos( -30 );
SetHiddenBits( HIDEHUD_CHAT );
m_pFiltersButton = new CHudChatFilterButton( this, "ChatFiltersButton", "Filters" );
if ( m_pFiltersButton )
{
m_pFiltersButton->SetScheme( scheme );
m_pFiltersButton->SetVisible( true );
m_pFiltersButton->SetEnabled( true );
m_pFiltersButton->SetMouseInputEnabled( true );
m_pFiltersButton->SetKeyBoardInputEnabled( false );
}
m_pChatHistory = new CHudChatHistory( this, "HudChatHistory" );
CreateChatLines();
CreateChatInputLine();
GetChatFilterPanel();
m_iFilterFlags = cl_chatfilters.GetInt();
}
void CBaseHudChat::CreateChatInputLine( void )
{
#ifndef _XBOX
m_pChatInput = new CBaseHudChatInputLine( this, "ChatInputLine" );
m_pChatInput->SetVisible( false );
if ( GetChatHistory() )
{
GetChatHistory()->SetMaximumCharCount( 127 * 100 );
GetChatHistory()->SetVisible( true );
}
#endif
}
void CBaseHudChat::CreateChatLines( void )
{
#ifndef _XBOX
m_ChatLine = new CBaseHudChatLine( this, "ChatLine1" );
m_ChatLine->SetVisible( false );
#endif
}
#define BACKGROUND_BORDER_WIDTH 20
CHudChatFilterPanel *CBaseHudChat::GetChatFilterPanel( void )
{
if ( m_pFilterPanel == NULL )
{
m_pFilterPanel = new CHudChatFilterPanel( this, "HudChatFilterPanel" );
if ( m_pFilterPanel )
{
vgui::HScheme scheme = vgui::scheme()->LoadSchemeFromFileEx( enginevgui->GetPanel( PANEL_CLIENTDLL ), "resource/ChatScheme.res", "ChatScheme");
m_pFilterPanel->SetScheme( scheme );
m_pFilterPanel->InvalidateLayout( true, true );
m_pFilterPanel->SetMouseInputEnabled( true );
m_pFilterPanel->SetPaintBackgroundType( 2 );
m_pFilterPanel->SetPaintBorderEnabled( true );
m_pFilterPanel->SetVisible( false );
}
}
return m_pFilterPanel;
}
void CBaseHudChat::ApplySchemeSettings( vgui::IScheme *pScheme )
{
LoadControlSettings( "resource/UI/BaseChat.res" );
BaseClass::ApplySchemeSettings( pScheme );
SetPaintBackgroundType( 2 );
SetPaintBorderEnabled( true );
SetPaintBackgroundEnabled( true );
SetKeyBoardInputEnabled( false );
SetMouseInputEnabled( false );
m_nVisibleHeight = 0;
#ifdef HL1_CLIENT_DLL
SetBgColor( Color( 0, 0, 0, 0 ) );
SetFgColor( Color( 0, 0, 0, 0 ) );
#endif
Color cColor = pScheme->GetColor( "DullWhite", GetBgColor() );
SetBgColor( Color ( cColor.r(), cColor.g(), cColor.b(), CHAT_HISTORY_ALPHA ) );
GetChatHistory()->SetVerticalScrollbar( false );
}
void CBaseHudChat::Reset( void )
{
#ifndef HL1_CLIENT_DLL
m_nVisibleHeight = 0;
Clear();
#endif
}
#ifdef _XBOX
bool CBaseHudChat::ShouldDraw()
{
// never think, never draw
return false;
}
#endif
void CBaseHudChat::Paint( void )
{
#ifndef _XBOX
if ( m_nVisibleHeight == 0 )
return;
#endif
}
CHudChatHistory *CBaseHudChat::GetChatHistory( void )
{
return m_pChatHistory;
}
void CBaseHudChat::Init( void )
{
if ( IsXbox() )
return;
ListenForGameEvent( "hltv_chat" );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pszName -
// iSize -
// *pbuf -
//-----------------------------------------------------------------------------
void CBaseHudChat::MsgFunc_SayText( bf_read &msg )
{
char szString[256];
int client = msg.ReadByte();
msg.ReadString( szString, sizeof(szString) );
bool bWantsToChat = msg.ReadByte();
if ( bWantsToChat )
{
// print raw chat text
ChatPrintf( client, CHAT_FILTER_NONE, "%s", szString );
}
else
{
// try to lookup translated string
Printf( CHAT_FILTER_NONE, "%s", hudtextmessage->LookupString( szString ) );
}
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "HudChat.Message" );
Msg( "%s", szString );
}
int CBaseHudChat::GetFilterForString( const char *pString )
{
if ( !Q_stricmp( pString, "#HL_Name_Change" ) )
{
return CHAT_FILTER_NAMECHANGE;
}
return CHAT_FILTER_NONE;
}
//-----------------------------------------------------------------------------
// Purpose: Reads in a player's Chat text from the server
//-----------------------------------------------------------------------------
void CBaseHudChat::MsgFunc_SayText2( bf_read &msg )
{
// Got message during connection
if ( !g_PR )
return;
int client = msg.ReadByte();
bool bWantsToChat = msg.ReadByte();
wchar_t szBuf[6][256];
char untranslated_msg_text[256];
wchar_t *msg_text = ReadLocalizedString( msg, szBuf[0], sizeof( szBuf[0] ), false, untranslated_msg_text, sizeof( untranslated_msg_text ) );
// keep reading strings and using C format strings for subsituting the strings into the localised text string
ReadChatTextString ( msg, szBuf[1], sizeof( szBuf[1] ) ); // player name
ReadChatTextString ( msg, szBuf[2], sizeof( szBuf[2] ) ); // chat text
ReadLocalizedString( msg, szBuf[3], sizeof( szBuf[3] ), true );
ReadLocalizedString( msg, szBuf[4], sizeof( szBuf[4] ), true );
g_pVGuiLocalize->ConstructString( szBuf[5], sizeof( szBuf[5] ), msg_text, 4, szBuf[1], szBuf[2], szBuf[3], szBuf[4] );
char ansiString[512];
g_pVGuiLocalize->ConvertUnicodeToANSI( ConvertCRtoNL( szBuf[5] ), ansiString, sizeof( ansiString ) );
if ( bWantsToChat )
{
int iFilter = CHAT_FILTER_NONE;
if ( client > 0 && (g_PR->GetTeam( client ) != g_PR->GetTeam( GetLocalPlayerIndex() )) )
{
iFilter = CHAT_FILTER_PUBLICCHAT;
}
// print raw chat text
ChatPrintf( client, iFilter, "%s", ansiString );
Msg( "%s\n", RemoveColorMarkup(ansiString) );
CLocalPlayerFilter filter;
C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "HudChat.Message" );
}
else
{
// print raw chat text
ChatPrintf( client, GetFilterForString( untranslated_msg_text), "%s", ansiString );
}
}
//-----------------------------------------------------------------------------
// Message handler for text messages
// displays a string, looking them up from the titles.txt file, which can be localised
// parameters:
// byte: message direction ( HUD_PRINTCONSOLE, HUD_PRINTNOTIFY, HUD_PRINTCENTER, HUD_PRINTTALK )
// string: message
// optional parameters:
// string: message parameter 1
// string: message parameter 2
// string: message parameter 3
// string: message parameter 4
// any string that starts with the character '#' is a message name, and is used to look up the real message in titles.txt
// the next (optional) one to four strings are parameters for that string (which can also be message names if they begin with '#')
//-----------------------------------------------------------------------------
void CBaseHudChat::MsgFunc_TextMsg( bf_read &msg )
{
char szString[2048];
int msg_dest = msg.ReadByte();
wchar_t szBuf[5][256];
wchar_t outputBuf[256];
for ( int i=0; i<5; ++i )
{
msg.ReadString( szString, sizeof(szString) );
char *tmpStr = hudtextmessage->LookupString( szString, &msg_dest );
const wchar_t *pBuf = g_pVGuiLocalize->Find( tmpStr );
if ( pBuf )
{
// Copy pBuf into szBuf[i].
int nMaxChars = sizeof( szBuf[i] ) / sizeof( wchar_t );
wcsncpy( szBuf[i], pBuf, nMaxChars );
szBuf[i][nMaxChars-1] = 0;
}
else
{
if ( i )
{
StripEndNewlineFromString( tmpStr ); // these strings are meant for subsitution into the main strings, so cull the automatic end newlines
}
g_pVGuiLocalize->ConvertANSIToUnicode( tmpStr, szBuf[i], sizeof(szBuf[i]) );
}
}
if ( !cl_showtextmsg.GetInt() )
return;
int len;
switch ( msg_dest )
{
case HUD_PRINTCENTER:
g_pVGuiLocalize->ConstructString( outputBuf, sizeof(outputBuf), szBuf[0], 4, szBuf[1], szBuf[2], szBuf[3], szBuf[4] );
internalCenterPrint->Print( ConvertCRtoNL( outputBuf ) );
break;
case HUD_PRINTNOTIFY:
g_pVGuiLocalize->ConstructString( outputBuf, sizeof(outputBuf), szBuf[0], 4, szBuf[1], szBuf[2], szBuf[3], szBuf[4] );
g_pVGuiLocalize->ConvertUnicodeToANSI( outputBuf, szString, sizeof(szString) );
len = strlen( szString );
if ( len && szString[len-1] != '\n' && szString[len-1] != '\r' )
{
Q_strncat( szString, "\n", sizeof(szString), 1 );
}
Msg( "%s", ConvertCRtoNL( szString ) );
break;
case HUD_PRINTTALK:
g_pVGuiLocalize->ConstructString( outputBuf, sizeof(outputBuf), szBuf[0], 4, szBuf[1], szBuf[2], szBuf[3], szBuf[4] );
g_pVGuiLocalize->ConvertUnicodeToANSI( outputBuf, szString, sizeof(szString) );
len = strlen( szString );
if ( len && szString[len-1] != '\n' && szString[len-1] != '\r' )
{
Q_strncat( szString, "\n", sizeof(szString), 1 );
}
Printf( CHAT_FILTER_NONE, "%s", ConvertCRtoNL( szString ) );
Msg( "%s", ConvertCRtoNL( szString ) );
break;
case HUD_PRINTCONSOLE:
g_pVGuiLocalize->ConstructString( outputBuf, sizeof(outputBuf), szBuf[0], 4, szBuf[1], szBuf[2], szBuf[3], szBuf[4] );
g_pVGuiLocalize->ConvertUnicodeToANSI( outputBuf, szString, sizeof(szString) );
len = strlen( szString );
if ( len && szString[len-1] != '\n' && szString[len-1] != '\r' )
{
Q_strncat( szString, "\n", sizeof(szString), 1 );
}
Msg( "%s", ConvertCRtoNL( szString ) );
break;
}
}
void CBaseHudChat::MsgFunc_VoiceSubtitle( bf_read &msg )
{
// Got message during connection
if ( !g_PR )
return;
if ( !cl_showtextmsg.GetInt() )
return;
char szString[2048];
char szPrefix[64]; //(Voice)
wchar_t szBuf[128];
int client = msg.ReadByte();
int iMenu = msg.ReadByte();
int iItem = msg.ReadByte();
const char *pszSubtitle = "";
CGameRules *pGameRules = GameRules();
CMultiplayRules *pMultiRules = dynamic_cast< CMultiplayRules * >( pGameRules );
Assert( pMultiRules );
if ( pMultiRules )
{
pszSubtitle = pMultiRules->GetVoiceCommandSubtitle( iMenu, iItem );
}
SetVoiceSubtitleState( true );
const wchar_t *pBuf = g_pVGuiLocalize->Find( pszSubtitle );
if ( pBuf )
{
// Copy pBuf into szBuf[i].
int nMaxChars = sizeof( szBuf ) / sizeof( wchar_t );
wcsncpy( szBuf, pBuf, nMaxChars );
szBuf[nMaxChars-1] = 0;
}
else
{
g_pVGuiLocalize->ConvertANSIToUnicode( pszSubtitle, szBuf, sizeof(szBuf) );
}
int len;
g_pVGuiLocalize->ConvertUnicodeToANSI( szBuf, szString, sizeof(szString) );
len = strlen( szString );
if ( len && szString[len-1] != '\n' && szString[len-1] != '\r' )
{
Q_strncat( szString, "\n", sizeof(szString), 1 );
}
const wchar_t *pVoicePrefix = g_pVGuiLocalize->Find( "#Voice" );
g_pVGuiLocalize->ConvertUnicodeToANSI( pVoicePrefix, szPrefix, sizeof(szPrefix) );
ChatPrintf( client, CHAT_FILTER_NONE, "%c(%s) %s%c: %s", COLOR_PLAYERNAME, szPrefix, GetDisplayedSubtitlePlayerName( client ), COLOR_NORMAL, ConvertCRtoNL( szString ) );
SetVoiceSubtitleState( false );
}
const char *CBaseHudChat::GetDisplayedSubtitlePlayerName( int clientIndex )
{
return g_PR->GetPlayerName( clientIndex );
}
#ifndef _XBOX
static int __cdecl SortLines( void const *line1, void const *line2 )
{
CBaseHudChatLine *l1 = *( CBaseHudChatLine ** )line1;
CBaseHudChatLine *l2 = *( CBaseHudChatLine ** )line2;
// Invisible at bottom
if ( l1->IsVisible() && !l2->IsVisible() )
return -1;
else if ( !l1->IsVisible() && l2->IsVisible() )
return 1;
// Oldest start time at top
if ( l1->GetStartTime() < l2->GetStartTime() )
return -1;
else if ( l1->GetStartTime() > l2->GetStartTime() )
return 1;
// Otherwise, compare counter
if ( l1->GetCount() < l2->GetCount() )
return -1;
else if ( l1->GetCount() > l2->GetCount() )
return 1;
return 0;
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Allow inheriting classes to change this spacing behavior
//-----------------------------------------------------------------------------
int CBaseHudChat::GetChatInputOffset( void )
{
return m_iFontHeight;
}
//-----------------------------------------------------------------------------
// Purpose: Do respositioning here to avoid latency due to repositioning of vgui
// voice manager icon panel
//-----------------------------------------------------------------------------
void CBaseHudChat::OnTick( void )
{
#ifndef _XBOX
m_nVisibleHeight = 0;
CBaseHudChatLine *line = m_ChatLine;
if ( line )
{
vgui::HFont font = line->GetFont();
m_iFontHeight = vgui::surface()->GetFontTall( font ) + 2;
// Put input area at bottom
int iChatX, iChatY, iChatW, iChatH;
int iInputX, iInputY, iInputW, iInputH;
m_pChatInput->GetBounds( iInputX, iInputY, iInputW, iInputH );
GetBounds( iChatX, iChatY, iChatW, iChatH );
m_pChatInput->SetBounds( iInputX, iChatH - (m_iFontHeight * 1.75), iInputW, m_iFontHeight );
//Resize the History Panel so it fits more lines depending on the screen resolution.
int iChatHistoryX, iChatHistoryY, iChatHistoryW, iChatHistoryH;
GetChatHistory()->GetBounds( iChatHistoryX, iChatHistoryY, iChatHistoryW, iChatHistoryH );
iChatHistoryH = (iChatH - (m_iFontHeight * 2.25)) - iChatHistoryY;
GetChatHistory()->SetBounds( iChatHistoryX, iChatHistoryY, iChatHistoryW, iChatHistoryH );
}
FadeChatHistory();
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : width -
// *text -
// textlen -
// Output : int
//-----------------------------------------------------------------------------
int CBaseHudChat::ComputeBreakChar( int width, const char *text, int textlen )
{
#ifndef _XBOX
CBaseHudChatLine *line = m_ChatLine;
vgui::HFont font = line->GetFont();
int currentlen = 0;
int lastbreak = textlen;
for (int i = 0; i < textlen ; i++)
{
char ch = text[i];
if ( ch <= 32 )
{
lastbreak = i;
}
wchar_t wch[2];
g_pVGuiLocalize->ConvertANSIToUnicode( &ch, wch, sizeof( wch ) );
int a,b,c;
vgui::surface()->GetCharABCwide(font, wch[0], a, b, c);
currentlen += a + b + c;
if ( currentlen >= width )
{
// If we haven't found a whitespace char to break on before getting
// to the end, but it's still too long, break on the character just before
// this one
if ( lastbreak == textlen )
{
lastbreak = MAX( 0, i - 1 );
}
break;
}
}
if ( currentlen >= width )
{
return lastbreak;
}
return textlen;
#else
return 0;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *fmt -
// ... -
//-----------------------------------------------------------------------------
void CBaseHudChat::Printf( int iFilter, const char *fmt, ... )
{
va_list marker;
char msg[4096];
va_start(marker, fmt);
Q_vsnprintf(msg, sizeof( msg), fmt, marker);
va_end(marker);
ChatPrintf( 0, iFilter, "%s", msg );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseHudChat::StartMessageMode( int iMessageModeType )
{
#ifndef _XBOX
m_nMessageMode = iMessageModeType;
m_pChatInput->ClearEntry();
const wchar_t *pszPrompt = ( m_nMessageMode == MM_SAY ) ? g_pVGuiLocalize->Find( "#chat_say" ) : g_pVGuiLocalize->Find( "#chat_say_team" );
if ( pszPrompt )
{
m_pChatInput->SetPrompt( pszPrompt );
}
else
{
if ( m_nMessageMode == MM_SAY )
{
m_pChatInput->SetPrompt( L"Say :" );
}
else
{
m_pChatInput->SetPrompt( L"Say (TEAM) :" );
}
}
if ( GetChatHistory() )
{
GetChatHistory()->SetMouseInputEnabled( true );
GetChatHistory()->SetKeyBoardInputEnabled( false );
GetChatHistory()->SetVerticalScrollbar( true );
GetChatHistory()->ResetAllFades( true );
GetChatHistory()->SetPaintBorderEnabled( true );
GetChatHistory()->SetVisible( true );
}
vgui::SETUP_PANEL( this );
SetKeyBoardInputEnabled( true );
SetMouseInputEnabled( true );
m_pChatInput->SetVisible( true );
vgui::surface()->CalculateMouseVisible();
m_pChatInput->RequestFocus();
m_pChatInput->SetPaintBorderEnabled( true );
m_pChatInput->SetMouseInputEnabled( true );
//Place the mouse cursor near the text so people notice it.
int x, y, w, h;
GetChatHistory()->GetBounds( x, y, w, h );
vgui::input()->SetCursorPos( x + ( w/2), y + (h/2) );
m_flHistoryFadeTime = gpGlobals->curtime + CHAT_HISTORY_FADE_TIME;
m_pFilterPanel->SetVisible( false );
engine->ClientCmd_Unrestricted( "gameui_preventescapetoshow\n" );
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseHudChat::StopMessageMode( void )
{
#ifndef _XBOX
engine->ClientCmd_Unrestricted( "gameui_allowescapetoshow\n" );
SetKeyBoardInputEnabled( false );
SetMouseInputEnabled( false );
if ( GetChatHistory() )
{
GetChatHistory()->SetPaintBorderEnabled( false );
GetChatHistory()->GotoTextEnd();
GetChatHistory()->SetMouseInputEnabled( false );
GetChatHistory()->SetVerticalScrollbar( false );
GetChatHistory()->ResetAllFades( false, true, CHAT_HISTORY_FADE_TIME );
GetChatHistory()->SelectNoText();
}
//Clear the entry since we wont need it anymore.
m_pChatInput->ClearEntry();
//hide filter panel
m_pFilterPanel->SetVisible( false );
m_flHistoryFadeTime = gpGlobals->curtime + CHAT_HISTORY_FADE_TIME;
m_nMessageMode = MM_NONE;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseHudChat::OnChatEntrySend( void )
{
Send();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseHudChat::OnChatEntryStopMessageMode( void )
{
StopMessageMode();
}
void CBaseHudChat::FadeChatHistory( void )
{
float frac = ( m_flHistoryFadeTime - gpGlobals->curtime ) / CHAT_HISTORY_FADE_TIME;
int alpha = frac * CHAT_HISTORY_ALPHA;
alpha = clamp( alpha, 0, CHAT_HISTORY_ALPHA );
if ( alpha >= 0 )
{
if ( GetChatHistory() )
{
if ( IsMouseInputEnabled() )
{
SetAlpha( 255 );
GetChatHistory()->SetBgColor( Color( 0, 0, 0, CHAT_HISTORY_ALPHA - alpha ) );
m_pChatInput->GetPrompt()->SetAlpha( (CHAT_HISTORY_ALPHA*2) - alpha );
m_pChatInput->GetInputPanel()->SetAlpha( (CHAT_HISTORY_ALPHA*2) - alpha );
SetBgColor( Color( GetBgColor().r(), GetBgColor().g(), GetBgColor().b(), CHAT_HISTORY_ALPHA - alpha ) );
m_pFiltersButton->SetAlpha( (CHAT_HISTORY_ALPHA*2) - alpha );
}
else
{
GetChatHistory()->SetBgColor( Color( 0, 0, 0, alpha ) );
SetBgColor( Color( GetBgColor().r(), GetBgColor().g(), GetBgColor().b(), alpha ) );
m_pChatInput->GetPrompt()->SetAlpha( alpha );
m_pChatInput->GetInputPanel()->SetAlpha( alpha );
m_pFiltersButton->SetAlpha( alpha );
}
}
}
}
void CBaseHudChat::SetFilterFlag( int iFilter )
{
m_iFilterFlags = iFilter;
cl_chatfilters.SetValue( m_iFilterFlags );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
Color CBaseHudChat::GetTextColorForClient( TextColor colorNum, int clientIndex )
{
Color c;
switch ( colorNum )
{
case COLOR_CUSTOM:
c = m_ColorCustom;
break;
case COLOR_PLAYERNAME:
c = GetClientColor( clientIndex );
break;
case COLOR_LOCATION:
c = g_ColorDarkGreen;
break;
case COLOR_ACHIEVEMENT:
{
vgui::IScheme *pSourceScheme = vgui::scheme()->GetIScheme( vgui::scheme()->GetScheme( "SourceScheme" ) );
if ( pSourceScheme )
{
c = pSourceScheme->GetColor( "SteamLightGreen", GetBgColor() );
}
else
{
c = GetDefaultTextColor();
}
}
break;
default:
c = GetDefaultTextColor();
}
return Color( c[0], c[1], c[2], 255 );
}
//-----------------------------------------------------------------------------
void CBaseHudChat::SetCustomColor( const char *pszColorName )
{
vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( vgui::scheme()->GetScheme( "ClientScheme" ) );
SetCustomColor( pScheme->GetColor( pszColorName, Color(255,255,255,255) ) );
}
//-----------------------------------------------------------------------------
Color CBaseHudChat::GetDefaultTextColor( void )
{
return g_ColorYellow;
}
//-----------------------------------------------------------------------------
Color CBaseHudChat::GetClientColor( int clientIndex )
{
if ( clientIndex == 0 ) // console msg
{
return g_ColorGreen;
}
else if( g_PR )
{
return g_ColorGrey;
}
return g_ColorYellow;
}
//-----------------------------------------------------------------------------
// Purpose: Parses a line of text for color markup and inserts it via Colorize()
//-----------------------------------------------------------------------------
void CBaseHudChatLine::InsertAndColorizeText( wchar_t *buf, int clientIndex )
{
if ( m_text )
{
delete[] m_text;
m_text = NULL;
}
m_textRanges.RemoveAll();
m_text = CloneWString( buf );
CBaseHudChat *pChat = dynamic_cast<CBaseHudChat*>(GetParent() );
if ( pChat == NULL )
return;
wchar_t *txt = m_text;
int lineLen = wcslen( m_text );
Color colCustom;
if ( m_text[0] == COLOR_PLAYERNAME || m_text[0] == COLOR_LOCATION || m_text[0] == COLOR_NORMAL || m_text[0] == COLOR_ACHIEVEMENT || m_text[0] == COLOR_CUSTOM || m_text[0] == COLOR_HEXCODE || m_text[0] == COLOR_HEXCODE_ALPHA )
{
while ( txt && *txt )
{
TextRange range;
bool bFoundColorCode = false;
bool bDone = false;
int nBytesIn = txt - m_text;
switch ( *txt )
{
case COLOR_CUSTOM:
case COLOR_PLAYERNAME:
case COLOR_LOCATION:
case COLOR_ACHIEVEMENT:
case COLOR_NORMAL:
{
// save this start
range.start = nBytesIn + 1;
range.color = pChat->GetTextColorForClient( (TextColor)(*txt), clientIndex );
range.end = lineLen;
bFoundColorCode = true;
}
++txt;
break;
case COLOR_HEXCODE:
case COLOR_HEXCODE_ALPHA:
{
bool bReadAlpha = ( *txt == COLOR_HEXCODE_ALPHA );
const int nCodeBytes = ( bReadAlpha ? 8 : 6 );
range.start = nBytesIn + nCodeBytes + 1;
range.end = lineLen;
range.preserveAlpha = bReadAlpha;
++txt;
if ( range.end > range.start )
{
int r = V_nibble( txt[0] ) << 4 | V_nibble( txt[1] );
int g = V_nibble( txt[2] ) << 4 | V_nibble( txt[3] );
int b = V_nibble( txt[4] ) << 4 | V_nibble( txt[5] );
int a = 255;
if ( bReadAlpha )
{
a = V_nibble( txt[6] ) << 4 | V_nibble( txt[7] );
}
range.color = Color( r, g, b, a );
bFoundColorCode = true;
txt += nCodeBytes;
}
else
{
// Not enough characters remaining for a hex code. Skip the rest of the string.
bDone = true;
}
}
break;
default:
++txt;
}
if ( bDone )
{
break;
}
if ( bFoundColorCode )
{
int count = m_textRanges.Count();
if ( count )
{
m_textRanges[count-1].end = nBytesIn;
}
m_textRanges.AddToTail( range );
}
}
}
if ( !m_textRanges.Count() && m_iNameLength > 0 && m_text[0] == COLOR_USEOLDCOLORS )
{
TextRange range;
range.start = 0;
range.end = m_iNameStart;
range.color = pChat->GetTextColorForClient( COLOR_NORMAL, clientIndex );
m_textRanges.AddToTail( range );
range.start = m_iNameStart;
range.end = m_iNameStart + m_iNameLength;
range.color = pChat->GetTextColorForClient( COLOR_PLAYERNAME, clientIndex );
m_textRanges.AddToTail( range );
range.start = range.end;
range.end = wcslen( m_text );
range.color = pChat->GetTextColorForClient( COLOR_NORMAL, clientIndex );
m_textRanges.AddToTail( range );
}
if ( !m_textRanges.Count() )
{
TextRange range;
range.start = 0;
range.end = wcslen( m_text );
range.color = pChat->GetTextColorForClient( COLOR_NORMAL, clientIndex );
m_textRanges.AddToTail( range );
}
for ( int i=0; i<m_textRanges.Count(); ++i )
{
wchar_t * start = m_text + m_textRanges[i].start;
if ( *start > 0 && *start < COLOR_MAX )
{
Assert( *start != COLOR_HEXCODE && *start != COLOR_HEXCODE_ALPHA );
m_textRanges[i].start += 1;
}
}
Colorize();
}
//-----------------------------------------------------------------------------
// Purpose: Inserts colored text into the RichText control at the given alpha
//-----------------------------------------------------------------------------
void CBaseHudChatLine::Colorize( int alpha )
{
// clear out text
SetText( "" );
CBaseHudChat *pChat = dynamic_cast<CBaseHudChat*>(GetParent() );
if ( pChat && pChat->GetChatHistory() )
{
pChat->GetChatHistory()->InsertString( "\n" );
}
wchar_t wText[4096];
Color color;
for ( int i=0; i<m_textRanges.Count(); ++i )
{
wchar_t * start = m_text + m_textRanges[i].start;
int len = m_textRanges[i].end - m_textRanges[i].start + 1;
if ( len > 1 && len <= ARRAYSIZE( wText ) )
{
wcsncpy( wText, start, len );
wText[len-1] = 0;
color = m_textRanges[i].color;
if ( !m_textRanges[i].preserveAlpha )
{
color[3] = alpha;
}
InsertColorChange( color );
InsertString( wText );
CBaseHudChat *pChat = dynamic_cast<CBaseHudChat*>(GetParent() );
if ( pChat && pChat->GetChatHistory() )
{
pChat->GetChatHistory()->InsertColorChange( color );
pChat->GetChatHistory()->InsertString( wText );
pChat->GetChatHistory()->InsertFade( hud_saytext_time.GetFloat(), CHAT_HISTORY_IDLE_FADE_TIME );
if ( i == m_textRanges.Count()-1 )
{
pChat->GetChatHistory()->InsertFade( -1, -1 );
}
}
}
}
InvalidateLayout( true );
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : CBaseHudChatLine
//-----------------------------------------------------------------------------
CBaseHudChatLine *CBaseHudChat::FindUnusedChatLine( void )
{
#ifndef _XBOX
return m_ChatLine;
#else
return NULL;
#endif
}
void CBaseHudChat::Send( void )
{
#ifndef _XBOX
wchar_t szTextbuf[128];
m_pChatInput->GetMessageText( szTextbuf, sizeof( szTextbuf ) );
char ansi[128];
g_pVGuiLocalize->ConvertUnicodeToANSI( szTextbuf, ansi, sizeof( ansi ) );
int len = Q_strlen(ansi);
/*
This is a very long string that I am going to attempt to paste into the cs hud chat entry and we will see if it gets cropped or not.
*/
// remove the \n
if ( len > 0 &&
ansi[ len - 1 ] == '\n' )
{
ansi[ len - 1 ] = '\0';
}
if( len > 0 )
{
// Let the game rules at it
if ( GameRules() )
{
GameRules()->ModifySentChat( ansi, ARRAYSIZE(ansi) );
}
char szbuf[144]; // more than 128
Q_snprintf( szbuf, sizeof(szbuf), "%s \"%s\"", m_nMessageMode == MM_SAY ? "say" : "say_team", ansi );
engine->ClientCmd_Unrestricted(szbuf);
}
m_pChatInput->ClearEntry();
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : vgui::Panel
//-----------------------------------------------------------------------------
vgui::Panel *CBaseHudChat::GetInputPanel( void )
{
#ifndef _XBOX
return m_pChatInput->GetInputPanel();
#else
return NULL;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseHudChat::Clear( void )
{
#ifndef _XBOX
// Kill input prompt
StopMessageMode();
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *newmap -
//-----------------------------------------------------------------------------
void CBaseHudChat::LevelInit( const char *newmap )
{
Clear();
//=============================================================================
// HPE_BEGIN:
// [pfreese] initialize new chat filters to defaults. We do this because
// unused filter bits are zero, and we might want them on for new filters that
// are added.
//
// Also, we have to do this here instead of somewhere more sensible like the
// c'tor or Init() method, because cvars are currently loaded twice: once
// during initialization from the local file, and later (after HUD elements
// have been construction and initialized) from Steam Cloud remote storage.
//=============================================================================
switch ( cl_chatfilter_version.GetInt() )
{
case 0:
m_iFilterFlags |= CHAT_FILTER_ACHIEVEMENT;
// fall through
case kChatFilterVersion:
break;
}
if ( cl_chatfilter_version.GetInt() != kChatFilterVersion )
{
cl_chatfilters.SetValue( m_iFilterFlags );
cl_chatfilter_version.SetValue( kChatFilterVersion );
}
//=============================================================================
// HPE_END
//=============================================================================
}
void CBaseHudChat::LevelShutdown( void )
{
Clear();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *fmt -
// ... -
//-----------------------------------------------------------------------------
void CBaseHudChat::ChatPrintf( int iPlayerIndex, int iFilter, const char *fmt, ... )
{
va_list marker;
char msg[4096];
va_start(marker, fmt);
Q_vsnprintf(msg, sizeof( msg), fmt, marker);
va_end(marker);
// Strip any trailing '\n'
if ( strlen( msg ) > 0 && msg[ strlen( msg )-1 ] == '\n' )
{
msg[ strlen( msg ) - 1 ] = 0;
}
// Strip leading \n characters ( or notify/color signifiers ) for empty string check
char *pmsg = msg;
while ( *pmsg && ( *pmsg == '\n' || ( *pmsg > 0 && *pmsg < COLOR_MAX ) ) )
{
pmsg++;
}
if ( !*pmsg )
return;
// Now strip just newlines, since we want the color info for printing
pmsg = msg;
while ( *pmsg && ( *pmsg == '\n' ) )
{
pmsg++;
}
if ( !*pmsg )
return;
CBaseHudChatLine *line = (CBaseHudChatLine *)FindUnusedChatLine();
if ( !line )
{
line = (CBaseHudChatLine *)FindUnusedChatLine();
}
if ( !line )
{
return;
}
if ( iFilter != CHAT_FILTER_NONE )
{
if ( !(iFilter & GetFilterFlags() ) )
return;
}
// If a player is muted for voice, also mute them for text because jerks gonna jerk.
if ( cl_mute_all_comms.GetBool() && iPlayerIndex != 0 )
{
if ( GetClientVoiceMgr() && GetClientVoiceMgr()->IsPlayerBlocked( iPlayerIndex ) )
return;
}
if ( *pmsg < 32 )
{
hudlcd->AddChatLine( pmsg + 1 );
}
else
{
hudlcd->AddChatLine( pmsg );
}
line->SetText( "" );
int iNameStart = 0;
int iNameLength = 0;
player_info_t sPlayerInfo;
if ( iPlayerIndex == 0 )
{
Q_memset( &sPlayerInfo, 0, sizeof(player_info_t) );
Q_strncpy( sPlayerInfo.name, "Console", sizeof(sPlayerInfo.name) );
}
else
{
engine->GetPlayerInfo( iPlayerIndex, &sPlayerInfo );
}
int bufSize = (strlen( pmsg ) + 1 ) * sizeof(wchar_t);
wchar_t *wbuf = static_cast<wchar_t *>( _alloca( bufSize ) );
if ( wbuf )
{
Color clrNameColor = GetClientColor( iPlayerIndex );
line->SetExpireTime();
g_pVGuiLocalize->ConvertANSIToUnicode( pmsg, wbuf, bufSize);
// find the player's name in the unicode string, in case there is no color markup
const char *pName = sPlayerInfo.name;
if ( pName )
{
wchar_t wideName[MAX_PLAYER_NAME_LENGTH];
g_pVGuiLocalize->ConvertANSIToUnicode( pName, wideName, sizeof( wideName ) );
const wchar_t *nameInString = wcsstr( wbuf, wideName );
if ( nameInString )
{
iNameStart = (nameInString - wbuf);
iNameLength = wcslen( wideName );
}
}
line->SetVisible( false );
line->SetNameStart( iNameStart );
line->SetNameLength( iNameLength );
line->SetNameColor( clrNameColor );
line->InsertAndColorizeText( wbuf, iPlayerIndex );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CBaseHudChat::FireGameEvent( IGameEvent *event )
{
#ifndef _XBOX
const char *eventname = event->GetName();
if ( Q_strcmp( "hltv_chat", eventname ) == 0 )
{
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if ( !player )
return;
ChatPrintf( player->entindex(), CHAT_FILTER_NONE, "(SourceTV) %s", event->GetString( "text" ) );
}
#endif
}
|