This repository was archived by the owner on Mar 1, 2021. It is now read-only.
forked from FWGS/xash3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.c
2093 lines (1754 loc) · 46 KB
/
console.c
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
/*
console.c - developer console
Copyright (C) 2007 Uncle Mike
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef XASH_DEDICATED
#include "common.h"
#include "client.h"
#include "keydefs.h"
#include "protocol.h" // get the protocol version
#include "gl_local.h"
#include "qfont.h"
#include "server.h" // Log_Printf( , ... )
convar_t *con_notifytime;
convar_t *scr_conspeed;
convar_t *con_fontsize;
convar_t *con_maxfrac;
convar_t *con_halffrac;
convar_t *con_charset;
convar_t *con_alpha;
convar_t *con_black;
convar_t *con_fontscale;
convar_t *con_fontnum;
convar_t *vgui_utf8;
rectf_t con_rect;
static int g_codepage = 0;
static qboolean g_utf8 = false;
#define CON_TIMES 5 // need for 4 lines
#define COLOR_DEFAULT '7'
#define CON_HISTORY 64
#define MAX_DBG_NOTIFY 128
#define CON_NUMFONTS 3 // maxfonts
#define CON_TEXTSIZE 131072 // 128 kb buffer
// console color typeing
rgba_t g_color_table[8] =
{
{ 0, 0, 0, 255}, // black
{255, 0, 0, 255}, // red
{ 0, 255, 0, 255}, // green
{255, 255, 0, 255}, // yellow
{ 0, 0, 255, 255}, // blue
{ 0, 255, 255, 255}, // cyan
{255, 0, 255, 255}, // magenta
{240, 180, 24, 255}, // default color (can be changed by user)
};
typedef struct
{
string szNotify;
float expire;
rgba_t color;
int key_dest;
} notify_t;
typedef struct
{
qboolean initialized;
short text[CON_TEXTSIZE];
int current; // line where next message will be printed
int display; // bottom of console displays this line
int x; // offset in current line for next print
int linewidth; // characters across screen
int totallines; // total lines in console scrollback
float displayFrac; // aproaches finalFrac at scr_conspeed
float finalFrac; // 0.0 to 1.0 lines of console to display
int vislines; // in scanlines
double times[CON_TIMES]; // host.realtime the line was generated for transparent notify lines
rgba_t color;
// console images
int background; // console background
// conchars
cl_font_t chars[CON_NUMFONTS];// fonts.wad/font1.fnt
cl_font_t *curFont, *lastUsedFont;
// console input
field_t input;
// chatfiled
field_t chat;
string chat_cmd; // can be overrieded by user
// console history
field_t historyLines[CON_HISTORY];
int historyLine; // the line being displayed from history buffer will be <= nextHistoryLine
int nextHistoryLine; // the last line in the history buffer, not masked
notify_t notify[MAX_DBG_NOTIFY]; // for Con_NXPrintf
qboolean draw_notify; // true if we have NXPrint message
} console_t;
static console_t con;
void Field_CharEvent( field_t *edit, int ch );
/*
================
Con_Clear_f
================
*/
void Con_Clear( void )
{
int i;
if( !con.initialized )
return;
for( i = 0; i < CON_TEXTSIZE; i++ )
con.text[i] = ( ColorIndex( COLOR_DEFAULT ) << 8 ) | ' ';
con.display = con.current; // go to end
}
/*
================
Con_SetColor_f
================
*/
void Con_SetColor_f( void )
{
vec3_t color;
switch( Cmd_Argc() )
{
case 1:
Msg( "\"con_color\" is %i %i %i\n", g_color_table[7][0], g_color_table[7][1], g_color_table[7][2] );
break;
case 2:
VectorSet( color, g_color_table[7][0], g_color_table[7][1], g_color_table[7][2] );
Q_atov( color, Cmd_Argv( 1 ), 3 );
Con_DefaultColor( color[0], color[1], color[2] );
break;
case 4:
VectorSet( color, Q_atof( Cmd_Argv( 1 )), Q_atof( Cmd_Argv( 2 )), Q_atof( Cmd_Argv( 3 )));
Con_DefaultColor( color[0], color[1], color[2] );
break;
default:
Msg( "Usage: con_color \"r g b\"\n" );
break;
}
}
/*
================
Con_ClearNotify
================
*/
void Con_ClearNotify( void )
{
int i;
for( i = 0; i < CON_TIMES; i++ )
con.times[i] = 0;
}
/*
================
Con_ClearField
================
*/
void Con_ClearField( field_t *edit )
{
Q_memset( edit->buffer, 0, MAX_STRING );
edit->cursor = 0;
edit->scroll = 0;
}
/*
================
Con_ClearTyping
================
*/
void Con_ClearTyping( void )
{
// int i;
Con_ClearField( &con.input );
con.input.widthInChars = con.linewidth;
Con_ClearAutoComplete();
}
/*
============
Con_StringLength
skipped color prefixes
============
*/
int Con_StringLength( const char *string )
{
int len;
const char *p;
if( !string ) return 0;
len = 0;
p = string;
while( *p )
{
if( IsColorString( p ))
{
p += 2;
continue;
}
len++;
p++;
}
return len;
}
/*
================
Con_MessageMode_f
================
*/
void Con_MessageMode_f( void )
{
if( Cmd_Argc() == 2 )
Q_strncpy( con.chat_cmd, Cmd_Argv( 1 ), sizeof( con.chat_cmd ));
else Q_strncpy( con.chat_cmd, "say", sizeof( con.chat_cmd ));
Key_SetKeyDest( key_message );
}
/*
================
Con_MessageMode2_f
================
*/
void Con_MessageMode2_f( void )
{
Q_strncpy( con.chat_cmd, "say_team", sizeof( con.chat_cmd ));
Key_SetKeyDest( key_message );
}
/*
================
Con_ToggleConsole_f
================
*/
void Con_ToggleConsole_f( void )
{
if( !host.developer ) return; // disabled
if( UI_CreditsActive( )) return; // disabled by final credits
// show console only in game or by special call from menu
if( cls.state != ca_active || cls.key_dest == key_menu )
return;
Con_ClearTyping();
Con_ClearNotify();
if( cls.key_dest == key_console )
{
if( Cvar_VariableInteger( "sv_background" ) || Cvar_VariableInteger( "cl_background" ))
UI_SetActiveMenu( true );
else UI_SetActiveMenu( false );
}
else
{
UI_SetActiveMenu( false );
Key_SetKeyDest( key_console );
}
}
/*
================
Con_CheckResize
If the line width has changed, reformat the buffer.
================
*/
void Con_CheckResize( void )
{
int i, j, width, numlines, numchars;
int oldwidth, oldtotallines;
short tbuf[CON_TEXTSIZE];
int charWidth = 8;
if( con.curFont && con.curFont->hFontTexture )
charWidth = con.curFont->charWidths['M'] - 1;
width = ( scr_width->integer / charWidth );
if( width == con.linewidth )
return;
if( !glw_state.initialized )
{
// video hasn't been initialized yet
con.linewidth = 80;
con.totallines = CON_TEXTSIZE / con.linewidth;
for( i = 0; i < CON_TEXTSIZE; i++ )
con.text[i] = ( ColorIndex( COLOR_DEFAULT ) << 8 ) | ' ';
}
else
{
oldwidth = con.linewidth;
con.linewidth = width;
oldtotallines = con.totallines;
con.totallines = CON_TEXTSIZE / con.linewidth;
numlines = oldtotallines;
if( con.totallines < numlines )
numlines = con.totallines;
numchars = oldwidth;
if( con.linewidth < numchars )
numchars = con.linewidth;
Q_memcpy( tbuf, con.text, CON_TEXTSIZE * sizeof( short ));
for( i = 0; i < CON_TEXTSIZE; i++ )
con.text[i] = ( ColorIndex( COLOR_DEFAULT ) << 8 ) | ' ';
for( i = 0; i < numlines; i++ )
{
for( j = 0; j < numchars; j++ )
{
con.text[(con.totallines - 1 - i) * con.linewidth + j] =
tbuf[((con.current - i + oldtotallines) % oldtotallines) * oldwidth + j + con.x];
}
}
Con_ClearNotify ();
}
con.current = con.totallines - 1;
con.display = con.current;
con.input.widthInChars = con.linewidth;
for( i = 0; i < CON_HISTORY; i++ )
con.historyLines[i].widthInChars = con.linewidth;
}
/*
================
Con_PageUp
================
*/
void Con_PageUp( int lines )
{
con.display -= abs( lines );
if( con.current - con.display >= con.totallines )
con.display = con.current - con.totallines + 1;
}
/*
================
Con_PageDown
================
*/
void Con_PageDown( int lines )
{
con.display += abs( lines );
if( con.display > con.current )
con.display = con.current;
}
/*
================
Con_Top
================
*/
void Con_Top( void )
{
con.display = con.totallines;
if( con.current - con.display >= con.totallines )
con.display = con.current - con.totallines + 1;
}
/*
================
Con_Bottom
================
*/
void Con_Bottom( void )
{
con.display = con.current;
}
/*
================
Con_Visible
================
*/
qboolean GAME_EXPORT Con_Visible( void )
{
return (con.displayFrac != 0.0f);
}
/*
================
Con_LoadConsoleFont
================
*/
static void Con_LoadConsoleFont( int fontNumber, cl_font_t *font )
{
int fontWidth;
const char *path = NULL;
byte *buffer;
fs_offset_t length;
qfont_t *src;
dword crc = 0;
ASSERT( font != NULL );
if( font->valid ) return; // already loaded
// replace default fonts.wad textures by current charset's font
if( !CRC32_File( &crc, "fonts.wad" ) || crc == 0x3c0a0029 )
{
const char *path2 = va("font%i_%s.fnt", fontNumber, Cvar_VariableString( "con_charset" ) );
if( FS_FileExists( path2, false ) )
path = path2;
}
if( !path )
path = va( "fonts.wad/font%i", fontNumber );
// loading conchars
font->hFontTexture = GL_LoadTexture( path, NULL, 0, TF_FONT|TF_NEAREST, NULL );
R_GetTextureParms( &fontWidth, NULL, font->hFontTexture );
if( fontWidth == 0 ) return;
// half-life font with variable chars witdh
buffer = FS_LoadFile( path, &length, false );
if( buffer && length >= ( fs_offset_t )sizeof( qfont_t ))
{
int i;
src = (qfont_t *)buffer;
font->charHeight = LittleLong(src->rowheight) * con_fontscale->value;
// build rectangles
for( i = 0; i < 256; i++ )
{
font->fontRc[i].left = LittleShort((word)src->fontinfo[i].startoffset) % fontWidth;
font->fontRc[i].right = font->fontRc[i].left + LittleShort(src->fontinfo[i].charwidth);
font->fontRc[i].top = LittleShort((word)src->fontinfo[i].startoffset) / fontWidth;
font->fontRc[i].bottom = font->fontRc[i].top + LittleLong(src->rowheight);
font->charWidths[i] = LittleShort(src->fontinfo[i].charwidth) * con_fontscale->value;
}
font->valid = true;
}
if( buffer ) Mem_Free( buffer );
}
/*
================
Con_LoadConchars
================
*/
static void Con_LoadConchars( void )
{
int i, fontSize;
// load all the console fonts
for( i = 0; i < 3; i++ )
Con_LoadConsoleFont( i, con.chars + i );
// select properly fontsize
if( con_fontnum->integer >= 0 && con_fontnum->integer <= 2)
fontSize = con_fontnum->integer;
else if( scr_width->integer <= 640 )
fontSize = 0;
else if( scr_width->integer >= 1280 )
fontSize = 2;
else fontSize = 1;
// sets the current font
con.lastUsedFont = con.curFont = &con.chars[fontSize];
}
// CP1251 table
int table_cp1251[64] = {
0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x007F, 0x2122, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457
};
/*
============================
Con_UtfProcessChar
Convert utf char to current font's single-byte encoding
============================
*/
int Con_UtfProcessCharForce( int in )
{
static int m = -1, k = 0; //multibyte state
static int uc = 0; //unicode char
if( !in )
{
m = -1;
k = 0;
uc = 0;
return 0;
}
// Get character length
if(m == -1)
{
uc = 0;
if( in >= 0xF8 )
return 0;
else if( in >= 0xF0 )
uc = in & 0x07, m = 3;
else if( in >= 0xE0 )
uc = in & 0x0F, m = 2;
else if( in >= 0xC0 )
uc = in & 0x1F, m = 1;
else if( in <= 0x7F)
return in; //ascii
// return 0 if we need more chars to decode one
k=0;
return 0;
}
// get more chars
else if( k <= m )
{
uc <<= 6;
uc += in & 0x3F;
k++;
}
if( in > 0xBF || m < 0 )
{
m = -1;
return 0;
}
if( k == m )
{
k = m = -1;
if( g_codepage == 1251 )
{
// cp1251 now
if( uc >= 0x0410 && uc <= 0x042F )
return uc - 0x410 + 0xC0;
if( uc >= 0x0430 && uc <= 0x044F )
return uc - 0x430 + 0xE0;
else
{
int i;
for( i = 0; i < 64; i++ )
if( table_cp1251[i] == uc )
return i + 0x80;
}
}
else if( g_codepage == 1252 )
{
if( uc < 255 )
return uc;
}
// not implemented yet
return '?';
}
return 0;
}
int GAME_EXPORT Con_UtfProcessChar( int in )
{
if( !g_utf8 )
return in;
else
return Con_UtfProcessCharForce( in );
}
/*
=================
Con_UtfMoveLeft
get position of previous printful char
=================
*/
int Con_UtfMoveLeft( char *str, int pos )
{
int i, k = 0;
// int j;
if( !g_utf8 )
return pos - 1;
Con_UtfProcessChar( 0 );
if(pos == 1) return 0;
for( i = 0; i < pos-1; i++ )
if( Con_UtfProcessChar( (unsigned char)str[i] ) )
k = i+1;
Con_UtfProcessChar( 0 );
return k;
}
/*
=================
Con_UtfMoveRight
get next of previous printful char
=================
*/
int Con_UtfMoveRight( char *str, int pos, int length )
{
int i;
if( !g_utf8 )
return pos + 1;
Con_UtfProcessChar( 0 );
for( i = pos; i <= length; i++ )
{
if( Con_UtfProcessChar( (unsigned char)str[i] ) )
return i+1;
}
Con_UtfProcessChar( 0 );
return pos+1;
}
int Con_DrawGenericChar( int x, int y, int number, rgba_t color )
{
int width, height;
float s1, t1, s2, t2;
int w, h;
wrect_t *rc;
number &= 255;
if( !con.curFont || !con.curFont->valid )
return 0;
number = Con_UtfProcessChar(number);
if( number < 32 )
return 0;
if( y < -con.curFont->charHeight )
return 0;
rc = &con.curFont->fontRc[number];
pglColor4ubv( color );
R_GetTextureParms( &w, &h, con.curFont->hFontTexture );
// calc rectangle
s1 = (float)rc->left / (float)w;
t1 = (float)rc->top / (float)h;
s2 = (float)rc->right / (float)w;
t2 = (float)rc->bottom / (float)h;
width = (rc->right - rc->left) * con_fontscale->value;
height = (rc->bottom - rc->top) * con_fontscale->value;
TextAdjustSize( &x, &y, &width, &height );
R_DrawStretchPic( x, y, width, height, s1, t1, s2, t2, con.curFont->hFontTexture );
pglColor4ub( 255, 255, 255, 255 ); // don't forget reset color
return con.curFont->charWidths[number];
}
void Con_SetFont( int fontNum )
{
fontNum = bound( 0, fontNum, 2 );
con.curFont = &con.chars[fontNum];
}
void Con_RestoreFont( void )
{
con.curFont = con.lastUsedFont;
}
int Con_DrawCharacter( int x, int y, int number, rgba_t color )
{
GL_SetRenderMode( kRenderTransTexture );
return Con_DrawGenericChar( x, y, number, color );
}
void Con_DrawCharacterLen( int number, int *width, int *height )
{
if( width && con.curFont ) *width = con.curFont->charWidths[number];
if( height && con.curFont ) *height = con.curFont->charHeight;
}
void Con_DrawStringLen( const char *pText, int *length, int *height )
{
int curLength = 0;
if( !con.curFont ) return;
if( height ) *height = con.curFont->charHeight;
if( !length ) return;
*length = 0;
while( *pText )
{
byte c = *pText;
if( *pText == '\n' ) //-V595
{
pText++;
curLength = 0;
}
// skip color strings they are not drawing
if( IsColorString( pText ))
{
pText += 2;
continue;
}
// Convert to unicode
c = Con_UtfProcessChar( c );
if( c )
curLength += con.curFont->charWidths[ c ];
pText++;
if( curLength > *length )
*length = curLength;
}
}
/*
==================
Con_DrawString
Draws a multi-colored string, optionally forcing
to a fixed color.
==================
*/
int Con_DrawGenericString( int x, int y, const char *string, rgba_t setColor, qboolean forceColor, int hideChar )
{
rgba_t color;
int drawLen = 0;
int numDraws = 0;
const char *s;
if( !con.curFont ) return 0; // no font set
Con_UtfProcessChar( 0 );
// draw the colored text
s = string;
*(uint *)color = *(uint *)setColor;
while ( s && *s )
{
if( *s == '\n' )
{
s++;
if( !*s ) break; // at end the string
drawLen = 0; // begin new row
y += con.curFont->charHeight;
}
if( IsColorString( s ))
{
if( !forceColor )
{
Q_memcpy( color, g_color_table[ColorIndex(*(s+1))], sizeof( color ));
color[3] = setColor[3];
}
s += 2;
numDraws++;
continue;
}
// hide char for overstrike mode
if( hideChar == numDraws )
drawLen += con.curFont->charWidths[*s];
else drawLen += Con_DrawCharacter( x + drawLen, y, *s, color );
numDraws++;
s++;
}
pglColor4ub( 255, 255, 255, 255 );
return drawLen;
}
int Con_DrawString( int x, int y, const char *string, rgba_t setColor )
{
return Con_DrawGenericString( x, y, string, setColor, false, -1 );
}
/*
================
Con_Init
================
*/
void Con_Init( void )
{
int i;
// must be init before startup video subsystem
scr_width = Cvar_Get( "width", "640", CVAR_RENDERINFO, "screen width" );
scr_height = Cvar_Get( "height", "480", CVAR_RENDERINFO, "screen height" );
scr_conspeed = Cvar_Get( "scr_conspeed", "600", 0, "console moving speed" );
con_notifytime = Cvar_Get( "con_notifytime", "3", 0, "notify time to live" );
con_fontsize = Cvar_Get( "con_fontsize", "1", CVAR_ARCHIVE, "chat or client font number (0, 1 or 2)" );
con_maxfrac = Cvar_Get( "con_maxfrac", DEFAULT_CON_MAXFRAC, CVAR_ARCHIVE, "console max height" );
con_halffrac = Cvar_Get( "con_halffrac", "0.5", CVAR_ARCHIVE, "console half height" );
con_charset = Cvar_Get( "con_charset", "cp1251", CVAR_ARCHIVE, "console font charset (only cp1251 supported now)" );
con_alpha = Cvar_Get( "con_alpha", "1.0", CVAR_ARCHIVE, "console alpha value" );
con_black = Cvar_Get( "con_black", "0", CVAR_ARCHIVE, "make console black like a nigga" );
con_fontscale = Cvar_Get( "con_fontscale", "1.0", CVAR_ARCHIVE, "scale font texture" );
con_fontnum = Cvar_Get( "con_fontnum", "-1", CVAR_ARCHIVE, "console font number (0, 1 or 2), -1 for autoselect" );
vgui_utf8 = Cvar_Get( "vgui_utf8", "0", CVAR_ARCHIVE, "enable utf-8 support for vgui text" );
Con_CheckResize();
Con_ClearField( &con.input );
con.input.widthInChars = con.linewidth;
Con_ClearField( &con.chat );
con.chat.widthInChars = con.linewidth;
for( i = 0; i < CON_HISTORY; i++ )
{
Con_ClearField( &con.historyLines[i] );
con.historyLines[i].widthInChars = con.linewidth;
}
Con_ClearAutoComplete();
Cmd_AddCommand( "toggleconsole", Con_ToggleConsole_f, "opens or closes the console" );
Cmd_AddCommand( "con_color", Con_SetColor_f, "set a custom console color" );
Cmd_AddCommand( "messagemode", Con_MessageMode_f, "enable message mode \"say\"" );
Cmd_AddCommand( "messagemode2", Con_MessageMode2_f, "enable message mode \"say_team\"" );
MsgDev( D_NOTE, "Console initialized.\n" );
con.initialized = true;
}
/*
===============
Con_Linefeed
===============
*/
void Con_Linefeed( void )
{
int i;
// mark time for transparent overlay
if( con.current >= 0 )
con.times[con.current % CON_TIMES] = host.realtime;
con.x = 0;
if( con.display == con.current )
con.display++;
con.current++;
for( i = 0; i < con.linewidth; i++ )
con.text[(con.current % con.totallines) * con.linewidth+i] = ( ColorIndex( COLOR_DEFAULT ) << 8 ) | ' ';
}
/*
================
Con_Print
Handles cursor positioning, line wrapping, etc
All console printing must go through this in order to be logged to disk
If no console is visible, the text will appear at the top of the game window
================
*/
void Con_Print( const char *txt )
{
int y, c, l, color;
// client not running
if( Host_IsDedicated() ) return;
if( !con.initialized ) return;
color = ColorIndex( COLOR_DEFAULT );
while(( c = *txt ) != 0 )
{
if( IsColorString( txt ))
{
color = ColorIndex( *( txt + 1 ));
txt += 2;
continue;
}
// count word length
for( l = 0; l < con.linewidth; l++ )
{
if( txt[l] <= ' ')
break;
}
// word wrap
// mittorn: Line already wrapped
//if( l != con.linewidth && ( con.x + l >= con.linewidth ))
// Con_Linefeed();
txt++;
switch( c )
{
case '\n':
Con_Linefeed();
break;
case '\r':
con.x = 0;
break;
default: // display character and advance
y = con.current % con.totallines;
con.text[y*con.linewidth+con.x] = (color << 8) | c;
con.x++;
if( con.x >= con.linewidth )
{
Con_Linefeed();
con.x = 0;
}
break;
}
}
}
/*
================
Con_NPrint
Draw a single debug line with specified height
================
*/
void GAME_EXPORT Con_NPrintf( int idx, char *fmt, ... )
{
va_list args;
if( idx < 0 || idx >= MAX_DBG_NOTIFY )
return;
Q_memset( con.notify[idx].szNotify, 0, MAX_STRING );
va_start( args, fmt );
Q_vsnprintf( con.notify[idx].szNotify, MAX_STRING, fmt, args );
va_end( args );
// reset values
con.notify[idx].key_dest = key_game;
con.notify[idx].expire = host.realtime + 4.0f;
MakeRGBA( con.notify[idx].color, 255, 255, 255, 255 );
con.draw_notify = true;
}
/*
================
Con_NXPrint
Draw a single debug line with specified height, color and time to live
================
*/
void GAME_EXPORT Con_NXPrintf( con_nprint_t *info, char *fmt, ... )
{
va_list args;
if( !info ) return;
if( info->index < 0 || info->index >= MAX_DBG_NOTIFY )
return;
Q_memset( con.notify[info->index].szNotify, 0, MAX_STRING );
va_start( args, fmt );
Q_vsnprintf( con.notify[info->index].szNotify, MAX_STRING, fmt, args );
va_end( args );
// setup values