Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 28.31 KB | None | 0 0
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. Copyright (C) 2000-2006 Tim Angus
  5.  
  6. This file is part of Tremfusion.
  7.  
  8. Tremfusion is free software; you can redistribute it
  9. and/or modify it under the terms of the GNU General Public License as
  10. published by the Free Software Foundation; either version 2 of the License,
  11. or (at your option) any later version.
  12.  
  13. Tremfusion is distributed in the hope that it will be
  14. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Tremfusion; if not, write to the Free Software
  20. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  21. ===========================================================================
  22. */
  23. // console.c
  24.  
  25. #include "client.h"
  26.  
  27.  
  28. int g_console_field_width = 78;
  29.  
  30.  
  31. #define NUM_CON_TIMES 4
  32.  
  33. #define     CON_TEXTSIZE    65536
  34. typedef struct {
  35.     qboolean    initialized;
  36.  
  37.     short   text[CON_TEXTSIZE];
  38.     int     current;        // line where next message will be printed
  39.     int     x;              // offset in current line for next print
  40.     int     display;        // bottom of console displays this line
  41.  
  42.     int     linewidth;      // characters across screen
  43.     int     totallines;     // total lines in console scrollback
  44.  
  45.     float   xadjust;        // for wide aspect screens
  46.  
  47.     float   displayFrac;    // aproaches finalFrac at scr_conspeed
  48.     float   finalFrac;      // 0.0 to 1.0 lines of console to display
  49.  
  50.     int     vislines;       // in scanlines
  51. } console_t;
  52.  
  53. extern  console_t   con;
  54.  
  55. console_t   con;
  56.  
  57. cvar_t      *cl_autoNamelog;
  58. cvar_t      *cl_translate;
  59. cvar_t      *cl_trName;
  60. cvar_t          *cl_mcolor;
  61.  
  62. cvar_t      *con_skipnotify;
  63.  
  64. cvar_t      *con_conspeed;
  65.  
  66. cvar_t      *scr_conUseOld;
  67.  
  68. // Color and alpha for console
  69. cvar_t      *scr_conUseShader;
  70.  
  71. cvar_t      *scr_conColorAlpha;
  72. cvar_t      *scr_conColorRed;
  73. cvar_t      *scr_conColorBlue;
  74. cvar_t      *scr_conColorGreen;
  75.  
  76. cvar_t      *scr_conHeight;
  77.  
  78. // Color and alpha for bar under console
  79. cvar_t      *scr_conBarSize;
  80.  
  81. cvar_t      *scr_conBarColorAlpha;
  82. cvar_t      *scr_conBarColorRed;
  83. cvar_t      *scr_conBarColorBlue;
  84. cvar_t      *scr_conBarColorGreen;
  85.  
  86.  
  87. #define DEFAULT_CONSOLE_WIDTH   78
  88.  
  89. /*
  90. ================
  91. Con_ToggleConsole_f
  92. ================
  93. */
  94. void Con_ToggleConsole_f (void) {
  95.     // Can't toggle the console when it's the only thing available
  96.     if ( cls.state == CA_DISCONNECTED && Key_GetCatcher( ) == KEYCATCH_CONSOLE ) {
  97.         return;
  98.     }
  99.  
  100.     if ( !cl_persistantConsole->integer )
  101.         Field_Clear( &g_consoleField );
  102.     g_consoleField.widthInChars = g_console_field_width;
  103.  
  104.     Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_CONSOLE );
  105. }
  106.  
  107. /*
  108. ================
  109. Con_Translate_f
  110. ================
  111. */
  112. void Con_Translate_f (void) {
  113.   char buffer[MAX_STRING_CHARS], cmd[MAX_STRING_CHARS];
  114.   FILE *fp;
  115.  
  116.  
  117.   if ( Cmd_Argc() < 4 )
  118.   {
  119.     Com_Printf("Wrong syntax\n");
  120.     return;
  121.   }
  122.  
  123.   Com_sprintf( cmd, sizeof( cmd ), "translate %s | iconv -f utf-8 -t us-ascii//TRANSLIT\n", Cmd_Args() );
  124. //   Com_Printf("%s", cmd);
  125.   fp = popen(cmd, "r");
  126.   fgets(buffer, MAX_STRING_CHARS, fp);
  127. //   Com_Printf( "%s", buffer);
  128.  
  129.   Com_sprintf( cmd, sizeof( cmd ), "say  \"%s\"\n", buffer );
  130.   pclose(fp);
  131.   CL_AddReliableCommand( cmd, qfalse );
  132.   return;
  133. }
  134.  
  135.  
  136.  
  137.  
  138. /*
  139. ================
  140. Con_MessageMode_f
  141. ================
  142. */
  143. void Con_MessageMode_f (void) {
  144.     chat_playerNum = -1;
  145.     chat_team = qfalse;
  146.     chat_admins = qfalse;
  147.     chat_clans = qfalse;
  148.     prompt.active = qfalse;
  149.     Field_Clear( &chatField );
  150.     chatField.widthInChars = 30;
  151.     Q_strncpyz( chatField.buffer, Cmd_Args( ), sizeof( chatField.buffer ) );
  152.     chatField.cursor = strlen( chatField.buffer );
  153.     Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
  154. }
  155.  
  156. /*
  157. ================
  158. Con_MessageMode2_f
  159. ================
  160. */
  161. void Con_MessageMode2_f (void) {
  162.     chat_playerNum = -1;
  163.     chat_team = qtrue;
  164.     chat_admins = qfalse;
  165.     chat_clans = qfalse;
  166.     prompt.active = qfalse;
  167.     Field_Clear( &chatField );
  168.     chatField.widthInChars = 25;
  169.     Q_strncpyz( chatField.buffer, Cmd_Args( ), sizeof( chatField.buffer ) );
  170.     chatField.cursor = strlen( chatField.buffer );
  171.     Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
  172. }
  173.  
  174. /*
  175. ================
  176. Con_MessageMode3_f
  177. ================
  178. */
  179. void Con_MessageMode3_f (void) {
  180.     chat_playerNum = VM_Call( cgvm, CG_CROSSHAIR_PLAYER );
  181.     if ( chat_playerNum < 0 || chat_playerNum >= MAX_CLIENTS ) {
  182.         chat_playerNum = -1;
  183.         return;
  184.     }
  185.     chat_team = qfalse;
  186.     chat_admins = qfalse;
  187.     chat_clans = qfalse;
  188.     prompt.active = qfalse;
  189.     Field_Clear( &chatField );
  190.     chatField.widthInChars = 30;
  191.     Q_strncpyz( chatField.buffer, Cmd_Args( ), sizeof( chatField.buffer ) );
  192.     chatField.cursor = strlen( chatField.buffer );
  193.     Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
  194. }
  195.  
  196. /*
  197. ================
  198. Con_MessageMode4_f
  199. ================
  200. */
  201. void Con_MessageMode4_f (void) {
  202.     chat_playerNum = VM_Call( cgvm, CG_LAST_ATTACKER );
  203.     if ( chat_playerNum < 0 || chat_playerNum >= MAX_CLIENTS ) {
  204.         chat_playerNum = -1;
  205.         return;
  206.     }
  207.     chat_team = qfalse;
  208.     chat_admins = qfalse;
  209.     chat_clans = qfalse;
  210.     prompt.active = qfalse;
  211.     Field_Clear( &chatField );
  212.     chatField.widthInChars = 30;
  213.     Q_strncpyz( chatField.buffer, Cmd_Args( ), sizeof( chatField.buffer ) );
  214.     chatField.cursor = strlen( chatField.buffer );
  215.     Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
  216. }
  217.  
  218. /*
  219. ================
  220. Con_MessageMode5_f
  221. ================
  222. */
  223. void Con_MessageMode5_f (void) {
  224.     chat_playerNum = -1;
  225.     chat_team = qfalse;
  226.     chat_admins = qtrue;
  227.     chat_clans = qfalse;
  228.     prompt.active = qfalse;
  229.     Field_Clear( &chatField );
  230.     chatField.widthInChars = 25;
  231.     Q_strncpyz( chatField.buffer, Cmd_Args( ), sizeof( chatField.buffer ) );
  232.     chatField.cursor = strlen( chatField.buffer );
  233.     Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
  234. }
  235.  
  236. /*
  237. ================
  238. Con_Prompt_f
  239. ================
  240. */
  241. void Con_Prompt_f (void) {
  242.     if (Cmd_Argc() < 3)
  243.     {
  244.         Com_Printf ("prompt <callback> [prompt]: Opens the chatbox, store the text in ui_sayBuffer and then vstr callback\n");
  245.         return;
  246.     }
  247.  
  248.     chat_playerNum = -1;
  249.     chat_team = qfalse;
  250.     chat_admins = qfalse;
  251.     chat_clans = qfalse;
  252.     prompt.active = qtrue;
  253.  
  254.     strcpy(prompt.callback, Cmd_Argv(1));
  255.  
  256.     // copy the rest of the command line
  257.     Q_strncpyz(prompt.question, Cmd_ArgsFrom(2), sizeof(prompt.question));
  258.    
  259.     Field_Clear( &chatField );
  260.     chatField.widthInChars = 34 - strlen(prompt.question);
  261.  
  262.     Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
  263. }
  264.  
  265. /*
  266. ================
  267. Con_MessageMode6_f
  268. ================
  269. */
  270. void Con_MessageMode6_f (void) {
  271.     chat_playerNum = -1;
  272.     chat_team = qfalse;
  273.     chat_admins = qfalse;
  274.     chat_clans = qtrue;
  275.     prompt.active = qfalse;
  276.     Field_Clear( &chatField );
  277.     Q_strncpyz( chatField.buffer, Cmd_Args( ), sizeof( chatField.buffer ) );
  278.     chatField.cursor = strlen( chatField.buffer );
  279.     Key_SetCatcher( Key_GetCatcher( ) ^ KEYCATCH_MESSAGE );
  280. }
  281.  
  282. /*
  283. ================
  284. Con_Clear_f
  285. ================
  286. */
  287. void Con_Clear_f (void) {
  288.     int     i;
  289.  
  290.     for ( i = 0 ; i < CON_TEXTSIZE ; i++ ) {
  291.         con.text[i] = (ColorIndex(COLOR_WHITE)<<8) | ' ';
  292.     }
  293.  
  294.     Con_Bottom();       // go to end
  295.  
  296.     CON_Clear_f();      // clear the tty too
  297. }
  298.  
  299.                        
  300. /*
  301. ================
  302. Con_Dump_f
  303.  
  304. Save the console contents out to a file
  305. ================
  306. */
  307. void Con_Dump_f (void)
  308. {
  309.     int     l, x, i;
  310.     short   *line;
  311.     fileHandle_t    f;
  312.     char    buffer[1024];
  313.  
  314.     if (Cmd_Argc() != 2)
  315.     {
  316.         Com_Printf ("usage: condump <filename>\n");
  317.         return;
  318.     }
  319.  
  320.     Com_Printf ("Dumped console text to %s.\n", Cmd_Argv(1) );
  321.  
  322.     f = FS_FOpenFileWrite( Cmd_Argv( 1 ) );
  323.     if (!f)
  324.     {
  325.         Com_Printf ("ERROR: couldn't open.\n");
  326.         return;
  327.     }
  328.  
  329.     // skip empty lines
  330.     for (l = con.current - con.totallines + 1 ; l <= con.current ; l++)
  331.     {
  332.         line = con.text + (l%con.totallines)*con.linewidth;
  333.         for (x=0 ; x<con.linewidth ; x++)
  334.             if ((line[x] & 0xff) != ' ')
  335.                 break;
  336.         if (x != con.linewidth)
  337.             break;
  338.     }
  339.  
  340.     // write the remaining lines
  341.     buffer[con.linewidth] = 0;
  342.     for ( ; l <= con.current ; l++)
  343.     {
  344.         line = con.text + (l%con.totallines)*con.linewidth;
  345.         for(i=0; i<con.linewidth; i++)
  346.             buffer[i] = line[i] & 0xff;
  347.         for (x=con.linewidth-1 ; x>=0 ; x--)
  348.         {
  349.             if (buffer[x] == ' ')
  350.                 buffer[x] = 0;
  351.             else
  352.                 break;
  353.         }
  354.         strcat( buffer, "\n" );
  355.         FS_Write(buffer, strlen(buffer), f);
  356.     }
  357.  
  358.     FS_FCloseFile( f );
  359. }
  360.  
  361. /*
  362. ================
  363. Con_Search_f
  364.  
  365. Scroll up to the first console line containing a string
  366. ================
  367. */
  368. void Con_Search_f (void)
  369. {
  370.     int     l, i, x;
  371.     short   *line;
  372.     char    buffer[MAXPRINTMSG];
  373.     int     direction;
  374.     int     c = Cmd_Argc();
  375.  
  376.     if (c < 2) {
  377.         Com_Printf ("usage: %s <string1> <string2> <...>\n", Cmd_Argv(0));
  378.         return;
  379.     }
  380.  
  381.     if (!Q_stricmp(Cmd_Argv(0), "searchDown")) {
  382.         direction = 1;
  383.     } else {
  384.         direction = -1;
  385.     }
  386.  
  387.     // check the lines
  388.     buffer[con.linewidth] = 0;
  389.     for (l = con.display - 1 + direction; l <= con.current && con.current - l < con.totallines; l += direction) {
  390.         line = con.text + (l%con.totallines)*con.linewidth;
  391.         for (i = 0; i < con.linewidth; i++)
  392.             buffer[i] = line[i] & 0xff;
  393.         for (x = con.linewidth - 1 ; x >= 0 ; x--) {
  394.             if (buffer[x] == ' ')
  395.                 buffer[x] = 0;
  396.             else
  397.                 break;
  398.         }
  399.         // Don't search commands
  400.         if (!Q_stricmpn(buffer, Q_CleanStr(va("%s", cl_consolePrompt->string)), Q_PrintStrlen(cl_consolePrompt->string)))
  401.             continue;
  402.         for (i = 1; i < c; i++) {
  403.             if (Q_stristr(buffer, Cmd_Argv(i))) {
  404.                 con.display = l + 1;
  405.                 if (con.display > con.current)
  406.                     con.display = con.current;
  407.                 return;
  408.             }
  409.         }
  410.     }
  411. }
  412.  
  413. /*
  414. ================
  415. Con_Grep_f
  416.  
  417. Find all console lines containing a string
  418. ================
  419. */
  420. void Con_Grep_f (void)
  421. {
  422.     int     l, x, i;
  423.     short   *line;
  424.     char    buffer[1024];
  425.     char    buffer2[1024];
  426.     char    printbuf[CON_TEXTSIZE];
  427.     char    *search;
  428.     char    lastcolor;
  429.  
  430.     if (Cmd_Argc() != 2)
  431.     {
  432.         Com_Printf ("usage: grep <string>\n");
  433.         return;
  434.     }
  435.  
  436.     // skip empty lines
  437.     for (l = con.current - con.totallines + 1 ; l <= con.current ; l++)
  438.     {
  439.         line = con.text + (l%con.totallines)*con.linewidth;
  440.         for (x=0 ; x<con.linewidth ; x++)
  441.             if ((line[x] & 0xff) != ' ')
  442.                 break;
  443.         if (x != con.linewidth)
  444.             break;
  445.     }
  446.  
  447.     // check the remaining lines
  448.     buffer[con.linewidth] = 0;
  449.     search = Cmd_Argv( 1 );
  450.     printbuf[0] = '\0';
  451.     lastcolor = 7;
  452.     for ( ; l <= con.current ; l++)
  453.     {
  454.         line = con.text + (l%con.totallines)*con.linewidth;
  455.         for(i=0,x=0; i<con.linewidth; i++)
  456.         {
  457.             if (line[i] >> 8 != lastcolor)
  458.             {
  459.                 lastcolor = line[i] >> 8;
  460.                 buffer[x++] = Q_COLOR_ESCAPE;
  461.                 buffer[x++] = lastcolor + '0';
  462.             }
  463.             buffer[x++] = line[i] & 0xff;
  464.         }
  465.         for (x=con.linewidth-1 ; x>=0 ; x--)
  466.         {
  467.             if (buffer[x] == ' ')
  468.                 buffer[x] = 0;
  469.             else
  470.                 break;
  471.         }
  472.         // Don't search commands
  473.         if (!Q_stricmpn(buffer, cl_consolePrompt->string, strlen(cl_consolePrompt->string)))
  474.             continue;
  475.         strcpy(buffer2, buffer);
  476.         Q_CleanStr(buffer2);
  477.         if (Q_stristr(buffer2, search))
  478.         {
  479.             strcat( printbuf, buffer );
  480.             strcat( printbuf, "\n" );
  481.         }
  482.     }
  483.     if ( printbuf[0] )
  484.         Com_Printf( "%s", printbuf );
  485. }
  486.  
  487. /*
  488. ================
  489. Con_ClearNotify
  490. ================
  491. */
  492. void Con_ClearNotify( void ) {
  493.     Cmd_TokenizeString( NULL );
  494.     CL_GameConsoleText( );
  495. }
  496.  
  497.                        
  498.  
  499. /*
  500. ================
  501. Con_CheckResize
  502.  
  503. If the line width has changed, reformat the buffer.
  504. ================
  505. */
  506. void Con_CheckResize (void)
  507. {
  508.     int     i, j, width, oldwidth, oldtotallines, numlines, numchars;
  509.     short   tbuf[CON_TEXTSIZE];
  510.  
  511.     if (cls.glconfig.vidWidth) {
  512.         if (scr_conUseOld->integer) {
  513.             width = cls.glconfig.vidWidth / SCR_ConsoleFontCharWidth('W');
  514.         } else {
  515.             width = (cls.glconfig.vidWidth - 30) / SCR_ConsoleFontCharWidth('W');
  516.         }
  517.         g_consoleField.widthInChars = width - Q_PrintStrlen(cl_consolePrompt->string) - 1;
  518.     } else {
  519.         width = 0;
  520.     }
  521.  
  522.     if (width == con.linewidth)
  523.         return;
  524.  
  525.     if (width < 1)          // video hasn't been initialized yet
  526.     {
  527.         width = DEFAULT_CONSOLE_WIDTH;
  528.         con.linewidth = width;
  529.         con.totallines = CON_TEXTSIZE / con.linewidth;
  530.         for(i=0; i<CON_TEXTSIZE; i++)
  531.  
  532.             con.text[i] = (ColorIndex(COLOR_WHITE)<<8) | ' ';
  533.     }
  534.     else
  535.     {
  536.         oldwidth = con.linewidth;
  537.         con.linewidth = width;
  538.         oldtotallines = con.totallines;
  539.         con.totallines = CON_TEXTSIZE / con.linewidth;
  540.         numlines = oldtotallines;
  541.  
  542.         if (con.totallines < numlines)
  543.             numlines = con.totallines;
  544.  
  545.         numchars = oldwidth;
  546.    
  547.         if (con.linewidth < numchars)
  548.             numchars = con.linewidth;
  549.  
  550.         Com_Memcpy (tbuf, con.text, CON_TEXTSIZE * sizeof(short));
  551.         for(i=0; i<CON_TEXTSIZE; i++)
  552.  
  553.             con.text[i] = (ColorIndex(COLOR_WHITE)<<8) | ' ';
  554.  
  555.  
  556.         for (i=0 ; i<numlines ; i++)
  557.         {
  558.             for (j=0 ; j<numchars ; j++)
  559.             {
  560.                 con.text[(con.totallines - 1 - i) * con.linewidth + j] =
  561.                         tbuf[((con.current - i + oldtotallines) %
  562.                               oldtotallines) * oldwidth + j];
  563.             }
  564.         }
  565.     }
  566.  
  567.     con.current = con.totallines - 1;
  568.     con.display = con.current;
  569. }
  570.  
  571. /*
  572. ==================
  573. Cmd_CompleteTxtName
  574. ==================
  575. */
  576. void Cmd_CompleteTxtName( char *args, int argNum ) {
  577.     if( argNum == 2 ) {
  578.         Field_CompleteFilename( "", "txt", qfalse );
  579.     }
  580. }
  581.  
  582.  
  583. /*
  584. ================
  585. Con_Init
  586. ================
  587. */
  588. void Con_Init (void) {
  589.     cl_autoNamelog = Cvar_Get ("cl_autoNamelog", "0", CVAR_ARCHIVE);
  590.     cl_translate = Cvar_Get ("cl_translate", "", CVAR_ARCHIVE);
  591.     cl_trName = Cvar_Get ("cl_trName", "", CVAR_ARCHIVE );
  592.     cl_mcolor = Cvar_Get ("cl_mcolor", "0", CVAR_ARCHIVE );
  593.     con_conspeed = Cvar_Get ("scr_conspeed", "3", 0);
  594.    
  595.     con_skipnotify = Cvar_Get ("con_skipnotify", "0", 0);
  596.    
  597.     scr_conUseOld = Cvar_Get ("scr_conUseOld", "0", CVAR_ARCHIVE|CVAR_LATCH);
  598.    
  599.     // Defines cvar for color and alpha for console/bar under console
  600.     scr_conUseShader = Cvar_Get ("scr_conUseShader", "0", CVAR_ARCHIVE);
  601.    
  602.     scr_conColorAlpha = Cvar_Get ("scr_conColorAlpha", "0.75", CVAR_ARCHIVE);
  603.     scr_conColorRed = Cvar_Get ("scr_conColorRed", "0", CVAR_ARCHIVE);
  604.     scr_conColorBlue = Cvar_Get ("scr_conColorBlue", "0.1", CVAR_ARCHIVE);
  605.     scr_conColorGreen = Cvar_Get ("scr_conColorGreen", "0", CVAR_ARCHIVE);
  606.  
  607.     scr_conHeight = Cvar_Get ("scr_conHeight", "50", CVAR_ARCHIVE);
  608.    
  609.     scr_conBarSize = Cvar_Get ("scr_conBarSize", "2", CVAR_ARCHIVE);
  610.    
  611.     scr_conBarColorAlpha = Cvar_Get ("scr_conBarColorAlpha", "1", CVAR_ARCHIVE);
  612.     scr_conBarColorRed = Cvar_Get ("scr_conBarColorRed", "1", CVAR_ARCHIVE);
  613.     scr_conBarColorBlue = Cvar_Get ("scr_conBarColorBlue", "0", CVAR_ARCHIVE);
  614.     scr_conBarColorGreen = Cvar_Get ("scr_conBarColorGreen", "0", CVAR_ARCHIVE);
  615.     // Done defining cvars for console colors
  616.    
  617.     Field_Clear( &g_consoleField );
  618.     g_consoleField.widthInChars = g_console_field_width;
  619.  
  620.     Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);
  621.     Cmd_AddCommand ("messagemode", Con_MessageMode_f);
  622.     Cmd_AddCommand ("messagemode2", Con_MessageMode2_f);
  623.     Cmd_AddCommand ("messagemode3", Con_MessageMode3_f);
  624.     Cmd_AddCommand ("messagemode4", Con_MessageMode4_f);
  625.     Cmd_AddCommand ("messagemode5", Con_MessageMode5_f);
  626.     Cmd_AddCommand ("messagemode6", Con_MessageMode6_f);
  627.     Cmd_AddCommand ("prompt", Con_Prompt_f);
  628.     Cmd_SetCommandCompletionFunc( "prompt", Cvar_CompleteCvarName );
  629.     Cmd_AddCommand ("clear", Con_Clear_f);
  630.     Cmd_AddCommand ("condump", Con_Dump_f);
  631.     Cmd_SetCommandCompletionFunc( "condump", Cmd_CompleteTxtName );
  632.     Cmd_AddCommand ("search", Con_Search_f);
  633.     Cmd_AddCommand ("searchDown", Con_Search_f);
  634.     Cmd_AddCommand ("grep", Con_Grep_f);
  635.     Cmd_AddCommand ("tr", Con_Translate_f);
  636. }
  637.  
  638.  
  639. /*
  640. ===============
  641. Con_Linefeed
  642. ===============
  643. */
  644. void Con_Linefeed (qboolean skipnotify)
  645. {
  646.     int     i;
  647.  
  648.     con.x = 0;
  649.     if (con.display == con.current)
  650.         con.display++;
  651.     con.current++;
  652.     for(i=0; i<con.linewidth; i++)
  653.         con.text[(con.current%con.totallines)*con.linewidth+i] = (ColorIndex(COLOR_WHITE)<<8) | ' ';
  654. }
  655.  
  656. /*
  657. ================
  658. CL_ConsolePrint
  659.  
  660. Handles cursor positioning, line wrapping, etc
  661. All console printing must go through this in order to be logged to disk
  662. If no console is visible, the text will appear at the top of the game window
  663. ================
  664. */
  665. void CL_ConsolePrint( char *txt ) {
  666.     int     y;
  667.     int     c, l;
  668.     int     color;
  669.     qboolean skipnotify = qfalse;       // NERVE - SMF
  670.     char NoColorMsg[MAXPRINTMSG];
  671.     static qboolean is_new_line = qtrue;
  672.    
  673.     CL_WriteClientChatLog( txt );
  674.    
  675. /* auto-namelog code */
  676.     if (( strstr(txt, "^7 connected\n") != NULL ) && !clc.demoplaying && cl_autoNamelog->integer)
  677.     {
  678.     char *p;
  679.     char text[MAX_SAY_TEXT];
  680.  
  681.     Q_strncpyz( text, txt, MAX_SAY_TEXT );
  682.     p = strstr(text, "^7 connected\n");
  683.     if (p)
  684.         {
  685.         char buf[MAX_SAY_TEXT];
  686.  
  687.         *p = '\0';
  688.  
  689.         Com_sprintf( buf, sizeof(buf), "!namelog %s", text );
  690.         CL_AddReliableCommand( buf, qfalse );
  691.         }
  692.     }
  693. /* end auto-namelog code */
  694.  
  695.     //Decolor Message
  696.     Q_strncpyz( NoColorMsg, txt, sizeof(NoColorMsg) );
  697.     Q_CleanStr( NoColorMsg );
  698.    
  699. /* Auto Translate code */
  700.    if ( ( ( strstr( NoColorMsg, "[H]") != NULL ) || ( strstr( NoColorMsg, "[S]") != NULL ) || ( strstr( NoColorMsg, "[A]") != NULL ) )
  701.      && cl_translate->string != NULL && (strstr( NoColorMsg, cl_trName->string ) != NULL ) )
  702.    {
  703.        char buffer[MAX_STRING_CHARS], cmd[MAX_STRING_CHARS];
  704.        char *q;
  705.        FILE *fp;
  706.    
  707.       if ( strstr( NoColorMsg, "[H]") != NULL )
  708.      q = strstr( NoColorMsg, "[H]");
  709.       else if ( strstr( NoColorMsg, "[A]") != NULL )
  710.      q = strstr( NoColorMsg, "[A]");
  711.       else if ( strstr( NoColorMsg, "[S]") != NULL )
  712.      q = strstr( NoColorMsg, "[S]");
  713.       if (q)
  714.       {
  715.     strncpy( q, "   ", 3);
  716.     Com_sprintf( cmd, sizeof( cmd ), "translate %s en %s | iconv -f utf-8 -t us-ascii//TRANSLIT\n", cl_translate->string, NoColorMsg );
  717. //    Com_Printf("%s", cmd);
  718.     fp = popen(cmd, "r");
  719.     fgets(buffer, MAX_STRING_CHARS, fp);
  720.     Com_Printf( "%s", buffer);
  721.  
  722. //      Com_Printf( "Translated:  \"%s\"\n", buffer );
  723.     pclose(fp);
  724.       }
  725.    }
  726.    
  727.  
  728.    
  729.     // TTimo - prefix for text that shows up in console but not in notify
  730.     // backported from RTCW
  731.     if ( !Q_strncmp( txt, "[skipnotify]", 12 ) ) {
  732.         skipnotify = qtrue;
  733.         txt += 12;
  734.     }
  735.    
  736.     // for some demos we don't want to ever show anything on the console
  737.     if ( cl_noprint && cl_noprint->integer ) {
  738.         return;
  739.     }
  740.    
  741.     if (!con.initialized) {
  742.         con.linewidth = -1;
  743.         Con_CheckResize ();
  744.         con.initialized = qtrue;
  745.     }
  746.  
  747.     if( !skipnotify && (!con_skipnotify || !con_skipnotify->integer) ) {
  748.         Cmd_SaveCmdContext( );
  749.  
  750.         // feed the text to cgame
  751.         if( is_new_line && ( com_timestamps && com_timestamps->integer ) )
  752.             Cmd_TokenizeString( txt + 16 );
  753.         else
  754.             Cmd_TokenizeString( txt );
  755.         CL_GameConsoleText( );
  756.  
  757.         Cmd_RestoreCmdContext( );
  758.     }
  759.  
  760.     color = ColorIndex(COLOR_WHITE);
  761.  
  762.     while ( (c = *txt) != 0 ) {
  763.         if ( Q_IsColorString( txt ) ) {
  764.             color = ColorIndex( *(txt+1) );
  765.             txt += 2;
  766.             continue;
  767.         }
  768.  
  769.         // count word length
  770.         for (l=0 ; l< con.linewidth ; l++) {
  771.             if ( txt[l] <= ' ' && txt[l] >= 0) {
  772.                 break;
  773.             }
  774.  
  775.         }
  776.  
  777.         // word wrap
  778.         if (l != con.linewidth && (con.x + l >= con.linewidth) ) {
  779.             Con_Linefeed(skipnotify);
  780.  
  781.         }
  782.  
  783.         txt++;
  784.  
  785.         switch (c)
  786.         {
  787.         case '\n':
  788.             Con_Linefeed (skipnotify);
  789.             break;
  790.         case '\r':
  791.             con.x = 0;
  792.             break;
  793.         default:    // display character and advance
  794.             y = con.current % con.totallines;
  795.             con.text[y*con.linewidth+con.x] = (color << 8) | (unsigned char)c;
  796.             con.x++;
  797.             if (con.x >= con.linewidth) {
  798.                 Con_Linefeed(skipnotify);
  799.                 con.x = 0;
  800.             }
  801.             break;
  802.         }
  803.     }
  804.     is_new_line = txt[strlen(txt) - 1] == '\n';
  805. }
  806.  
  807.  
  808. /*
  809. ==============================================================================
  810.  
  811. DRAWING
  812.  
  813. ==============================================================================
  814. */
  815.  
  816.  
  817. /*
  818. ================
  819. Con_DrawInput
  820.  
  821. Draw the editline after a ] prompt
  822. ================
  823. */
  824. void Con_DrawInput (void) {
  825.     int     y;
  826.     char    prompt[ MAX_STRING_CHARS ];
  827.     vec4_t  color;
  828.     qtime_t realtime;
  829.  
  830.     if ( cls.state != CA_DISCONNECTED && !(Key_GetCatcher( ) & KEYCATCH_CONSOLE ) ) {
  831.         return;
  832.     }
  833.  
  834.     Com_RealTime( &realtime );
  835.  
  836.     y = con.vislines - ( SCR_ConsoleFontCharHeight() * 2 ) + 2 ;
  837.  
  838.     Com_sprintf( prompt,  sizeof( prompt ), "^0[^3%02d%c%02d^0]^7 %s", realtime.tm_hour, (realtime.tm_sec & 1) ? ':' : ' ', realtime.tm_min, cl_consolePrompt->string );
  839.  
  840.     color[0] = 1.0f;
  841.     color[1] = 1.0f;
  842.     color[2] = 1.0f;
  843.     color[3] = (scr_conUseOld->integer ? 1.0f : con.displayFrac * 2.0f);
  844.  
  845.     SCR_DrawSmallStringExt( con.xadjust + cl_conXOffset->integer, y, prompt, color, qfalse, qfalse );
  846.  
  847.     Q_CleanStr( prompt );
  848.     Field_Draw( &g_consoleField, con.xadjust + cl_conXOffset->integer + SCR_ConsoleFontStringWidth(prompt, strlen(prompt)), y, qtrue, qtrue, color[3] );
  849. }
  850.  
  851. /*
  852. ================
  853. Con_DrawSolidConsole
  854.  
  855. Draws the console with the solid background
  856. ================
  857. */
  858. void Con_DrawSolidConsole( float frac ) {
  859.     int             i, x, y;
  860.     int             rows;
  861.     short           *text;
  862.     int             row;
  863.     int             lines;
  864. //  qhandle_t       conShader;
  865.     int             currentColor;
  866.     vec4_t          color;
  867.  
  868.     if (scr_conUseOld->integer) {
  869.         lines = cls.glconfig.vidHeight * frac;
  870.         if (lines <= 0)
  871.             return;
  872.  
  873.         if (lines > cls.glconfig.vidHeight )
  874.             lines = cls.glconfig.vidHeight;
  875.     } else {
  876.         lines = cls.glconfig.vidHeight * scr_conHeight->integer * 0.01 - 10;
  877.     }
  878.  
  879.     // on wide screens, we will center the text
  880.     if (!scr_conUseOld->integer) {
  881.         con.xadjust = 15;
  882.     }
  883.     SCR_AdjustFrom640( &con.xadjust, NULL, NULL, NULL );
  884.  
  885.     // draw the background
  886.     if (scr_conUseOld->integer) {
  887.         y = frac * SCREEN_HEIGHT;
  888.         if ( y < 1 ) {
  889.             y = 0;
  890.         }
  891.         else {
  892.          if( scr_conUseShader->integer )
  893.            {
  894.             SCR_DrawPic( 0, 0, SCREEN_WIDTH, y, cls.consoleShader );
  895.            }
  896.          else
  897.            {
  898.             // This will be overwrote, so ill just abuse it here, no need to define another array
  899.             color[0] = scr_conColorRed->value;
  900.             color[1] = scr_conColorGreen->value;
  901.             color[2] = scr_conColorBlue->value;
  902.             color[3] = scr_conColorAlpha->value;
  903.            
  904.             SCR_FillRect( 0, 0, SCREEN_WIDTH, y, color );
  905.            }
  906.         }
  907.  
  908.         color[0] = scr_conBarColorRed->value;
  909.         color[1] = scr_conBarColorGreen->value;
  910.         color[2] = scr_conBarColorBlue->value;
  911.         color[3] = scr_conBarColorAlpha->value;
  912.        
  913.         SCR_FillRect( 0, y, SCREEN_WIDTH, scr_conBarSize->value, color );
  914.     } else {
  915.         color[0] = scr_conColorRed->value;
  916.         color[1] = scr_conColorGreen->value;
  917.         color[2] = scr_conColorBlue->value;
  918.         color[3] = frac * 2 * scr_conColorAlpha->value;
  919.         SCR_FillRect(10, 10, 620, 460 * scr_conHeight->integer * 0.01, color);
  920.  
  921.         color[0] = scr_conBarColorRed->value;
  922.         color[1] = scr_conBarColorGreen->value;
  923.         color[2] = scr_conBarColorBlue->value;
  924.         color[3] = frac * 2 * scr_conBarColorAlpha->value;
  925.         SCR_FillRect(10, 10, 620, 1, color);    //top
  926.         SCR_FillRect(10, 460 * scr_conHeight->integer * 0.01 + 10, 621, 1, color);  //bottom
  927.         SCR_FillRect(10, 10, 1, 460 * scr_conHeight->integer * 0.01, color);    //left
  928.         SCR_FillRect(630, 10, 1, 460 * scr_conHeight->integer * 0.01, color);   //right
  929.     }
  930.  
  931.  
  932.     // draw the version number
  933.  
  934.     color[0] = 1.0f;
  935.     color[1] = 0.0f;
  936.     color[2] = 0.0f;
  937.     color[3] = (scr_conUseOld->integer ? 1.0f : frac * 2.0f);
  938.     re.SetColor( color );
  939.  
  940.     i = strlen( Q3_VERSION );
  941.     float totalwidth = SCR_ConsoleFontStringWidth( Q3_VERSION, i ) + cl_conXOffset->integer;
  942.     if (!scr_conUseOld->integer) {
  943.         totalwidth += 30;
  944.     }
  945.     float currentWidthLocation = 0;
  946.     for (x=0 ; x<i ; x++) {
  947.         SCR_DrawConsoleFontChar( cls.glconfig.vidWidth - totalwidth + currentWidthLocation, lines-SCR_ConsoleFontCharHeight(), Q3_VERSION[x] );
  948.         currentWidthLocation += SCR_ConsoleFontCharWidth( Q3_VERSION[x] );
  949.     }
  950.  
  951.  
  952.     // draw the text
  953.     con.vislines = lines;
  954.     rows = (lines)/SCR_ConsoleFontCharHeight() - 3;     // rows of text to draw
  955.     if (scr_conUseOld->integer)
  956.         rows++;
  957.  
  958.     y = lines - (SCR_ConsoleFontCharHeight()*3);
  959.  
  960.     // draw from the bottom up
  961.     if (con.display != con.current)
  962.     {
  963.         // draw arrows to show the buffer is backscrolled
  964.         color[0] = 1.0f;
  965.         color[1] = 0.0f;
  966.         color[2] = 0.0f;
  967.         color[3] = (scr_conUseOld->integer ? 1.0f : frac * 2.0f);
  968.         re.SetColor( color );
  969.         for (x=0 ; x<con.linewidth - (scr_conUseOld->integer ? 0 : 4); x+=4)
  970.             SCR_DrawConsoleFontChar( con.xadjust + (x+1)*SCR_ConsoleFontCharWidth('^'), y, '^' );
  971.         y -= SCR_ConsoleFontCharHeight();
  972.         rows--;
  973.     }
  974.    
  975.     row = con.display;
  976.  
  977.     if ( con.x == 0 ) {
  978.         row--;
  979.     }
  980.  
  981.     currentColor = 7;
  982.     color[0] = g_color_table[currentColor][0];
  983.     color[1] = g_color_table[currentColor][1];
  984.     color[2] = g_color_table[currentColor][2];
  985.     color[3] = (scr_conUseOld->integer ? 1.0f : frac * 2.0f);
  986.     re.SetColor( color );
  987.  
  988.     for (i=0 ; i<rows ; i++, y -= SCR_ConsoleFontCharHeight(), row--)
  989.     {
  990.         if (row < 0)
  991.             break;
  992.         if (con.current - row >= con.totallines) {
  993.             // past scrollback wrap point
  994.             continue;  
  995.         }
  996.  
  997.         text = con.text + (row % con.totallines)*con.linewidth;
  998.  
  999.         float currentWidthLocation = cl_conXOffset->integer;
  1000.         for (x=0 ; x<con.linewidth ; x++) {
  1001.             if ( ( (text[x]>>8)&7 ) != currentColor ) {
  1002.                 currentColor = (text[x]>>8)&7;
  1003.                 color[0] = g_color_table[currentColor][0];
  1004.                 color[1] = g_color_table[currentColor][1];
  1005.                 color[2] = g_color_table[currentColor][2];
  1006.                 color[3] = (scr_conUseOld->integer ? 1.0f : frac * 2.0f);
  1007.                 re.SetColor( color );
  1008.             }
  1009.            
  1010.             SCR_DrawConsoleFontChar(  con.xadjust + currentWidthLocation, y, text[x] & 0xff );
  1011.             currentWidthLocation += SCR_ConsoleFontCharWidth( text[x] & 0xff );
  1012.         }
  1013.     }
  1014.  
  1015.     // draw the input prompt, user text, and cursor if desired
  1016.     Con_DrawInput ();
  1017.  
  1018.     re.SetColor( NULL );
  1019. }
  1020.  
  1021.  
  1022.  
  1023. /*
  1024. ==================
  1025. Con_DrawConsole
  1026. ==================
  1027. */
  1028. void Con_DrawConsole( void ) {
  1029.     // check for console width changes from a vid mode change
  1030.     Con_CheckResize ();
  1031.  
  1032.     // if disconnected, render console full screen
  1033.     if ( cls.state == CA_DISCONNECTED ) {
  1034.         if ( !( Key_GetCatcher( ) & (KEYCATCH_UI | KEYCATCH_CGAME)) ) {
  1035.             Con_DrawSolidConsole( 1.0 );
  1036.             return;
  1037.         }
  1038.     }
  1039.  
  1040.     if ( con.displayFrac ) {
  1041.         Con_DrawSolidConsole( con.displayFrac );
  1042.     }
  1043.  
  1044.     if( Key_GetCatcher( ) & ( KEYCATCH_UI | KEYCATCH_CGAME ) )
  1045.         return;
  1046.  
  1047.     // draw the chat line
  1048.     if( Key_GetCatcher( ) & KEYCATCH_MESSAGE )
  1049.     {
  1050.         int skip;
  1051.  
  1052.         if( chat_team )
  1053.         {
  1054.             SCR_DrawBigString( 8, 232, "Team Say:", 1.0f, qfalse );
  1055.             skip = 11;
  1056.         }
  1057.         else if( chat_admins )
  1058.         {
  1059.             SCR_DrawBigString( 8, 232, "Admin Say:", 1.0f, qfalse );
  1060.             skip = 11;
  1061.         }
  1062.         else if (prompt.active)
  1063.         {
  1064.             SCR_DrawBigString( 8, 232, prompt.question, 1.0f, qfalse );
  1065.             skip = strlen(prompt.question) + 1;
  1066.         }
  1067.         else if( chat_clans )
  1068.         {
  1069.             SCR_DrawBigString( 8, 232, "Clan Say:", 1.0f, qfalse );
  1070.             skip = 11;
  1071.         }
  1072.         else
  1073.         {
  1074.             SCR_DrawBigString( 8, 232, "Say:", 1.0f, qfalse );
  1075.             skip = 5;
  1076.         }
  1077.  
  1078.         Field_BigDraw( &chatField, skip * BIGCHAR_WIDTH, 232, qtrue, qtrue );
  1079.     }
  1080. }
  1081.  
  1082. //================================================================
  1083.  
  1084. /*
  1085. ==================
  1086. Con_RunConsole
  1087.  
  1088. Scroll it up or down
  1089. ==================
  1090. */
  1091. void Con_RunConsole (void) {
  1092.     // decide on the destination height of the console
  1093.     if ( Key_GetCatcher( ) & KEYCATCH_CONSOLE )
  1094.         if (scr_conUseOld->integer) {
  1095.             con.finalFrac = MAX(0.10, 0.01 * scr_conHeight->integer);  // configured console percentage
  1096.         } else {
  1097.             con.finalFrac = 0.5;
  1098.         }
  1099.     else
  1100.         con.finalFrac = 0;              // none visible
  1101.    
  1102.     // scroll towards the destination height
  1103.     if (con.finalFrac < con.displayFrac)
  1104.     {
  1105.         con.displayFrac -= con_conspeed->value*cls.realFrametime*0.001;
  1106.         if (con.finalFrac > con.displayFrac)
  1107.             con.displayFrac = con.finalFrac;
  1108.  
  1109.     }
  1110.     else if (con.finalFrac > con.displayFrac)
  1111.     {
  1112.         con.displayFrac += con_conspeed->value*cls.realFrametime*0.001;
  1113.         if (con.finalFrac < con.displayFrac)
  1114.             con.displayFrac = con.finalFrac;
  1115.     }
  1116.  
  1117. }
  1118.  
  1119.  
  1120. void Con_PageUp( void ) {
  1121.     con.display -= 2;
  1122.     if ( con.current - con.display >= con.totallines ) {
  1123.         con.display = con.current - con.totallines + 1;
  1124.     }
  1125. }
  1126.  
  1127. void Con_PageDown( void ) {
  1128.     con.display += 2;
  1129.     if (con.display > con.current) {
  1130.         con.display = con.current;
  1131.     }
  1132. }
  1133.  
  1134. void Con_Top( void ) {
  1135.     con.display = con.totallines;
  1136.     if ( con.current - con.display >= con.totallines ) {
  1137.         con.display = con.current - con.totallines + 1;
  1138.     }
  1139. }
  1140.  
  1141. void Con_Bottom( void ) {
  1142.     con.display = con.current;
  1143. }
  1144.  
  1145.  
  1146. void Con_Close( void ) {
  1147.     if ( !com_cl_running->integer ) {
  1148.         return;
  1149.     }
  1150.     if ( !cl_persistantConsole->integer )
  1151.         Field_Clear( &g_consoleField );
  1152.     Key_SetCatcher( Key_GetCatcher( ) & ~KEYCATCH_CONSOLE );
  1153.     con.finalFrac = 0;              // none visible
  1154.     con.displayFrac = 0;
  1155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement