]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - console.c
Remove Con_Warnf and Errorf. Use macros to change color and identify the message
[xonotic/darkplaces.git] / console.c
index 7748769c9a087b1b9db377bbecb5f4a89dd4f911..5bbf112cf1f9b03dda66377204fa0543b1cec4db 100644 (file)
--- a/console.c
+++ b/console.c
@@ -57,7 +57,9 @@ cvar_t con_textsize = {CVAR_CLIENT | CVAR_SAVE, "con_textsize","8", "console tex
 cvar_t con_notifysize = {CVAR_CLIENT | CVAR_SAVE, "con_notifysize","8", "notify text size in virtual 2D pixels"};
 cvar_t con_chatsize = {CVAR_CLIENT | CVAR_SAVE, "con_chatsize","8", "chat text size in virtual 2D pixels (if con_chat is enabled)"};
 cvar_t con_chatsound = {CVAR_CLIENT | CVAR_SAVE, "con_chatsound","1", "enables chat sound to play on message"};
-
+cvar_t con_chatsound_file = {CVAR_CLIENT, "con_chatsound_file","sound/misc/talk.wav", "The sound to play for chat messages"};
+cvar_t con_chatsound_team_file = {CVAR_CLIENT, "con_chatsound_team_file","sound/misc/talk2.wav", "The sound to play for team chat messages"};
+cvar_t con_chatsound_team_mask = {CVAR_CLIENT, "con_chatsound_team_mask","40","Magic ASCII code that denotes a team chat message"};
 
 cvar_t sys_specialcharactertranslation = {CVAR_CLIENT | CVAR_SERVER, "sys_specialcharactertranslation", "1", "terminal console conchars to ASCII translation (set to 0 if your conchars.tga is for an 8bit character set or if you want raw output)"};
 #ifdef WIN32
@@ -807,7 +809,7 @@ static void Con_ConDump_f(cmd_state_t *cmd)
        file = FS_OpenRealFile(Cmd_Argv(cmd, 1), "w", false);
        if (!file)
        {
-               Con_Errorf("condump: unable to write file \"%s\"\n", Cmd_Argv(cmd, 1));
+               Con_Printf(CON_ERROR "condump: unable to write file \"%s\"\n", Cmd_Argv(cmd, 1));
                return;
        }
        if (con_mutex) Thread_LockMutex(con_mutex);
@@ -884,6 +886,9 @@ void Con_Init (void)
        Cvar_RegisterVariable (&con_notifytime);
        Cvar_RegisterVariable (&con_textsize);
        Cvar_RegisterVariable (&con_chatsound);
+       Cvar_RegisterVariable (&con_chatsound_file);
+       Cvar_RegisterVariable (&con_chatsound_team_file);
+       Cvar_RegisterVariable (&con_chatsound_team_mask);
 
        // --blub
        Cvar_RegisterVariable (&con_nickcompletion);
@@ -905,6 +910,9 @@ void Con_Init (void)
        Cmd_AddCommand(CMD_SHARED, "condump", Con_ConDump_f, "output console history to a file (see also log_file)");
 
        con_initialized = true;
+       // initialize console window (only used by sys_win.c)
+       Sys_InitConsole();
+       
        Con_DPrint("Console initialized.\n");
 }
 
@@ -1156,28 +1164,17 @@ void Con_MaskPrint(int additionalmask, const char *msg)
                                {
                                        if (con_chatsound.value)
                                        {
-                                               if(IS_NEXUIZ_DERIVED(gamemode))
-                                               {
-                                                       if(msg[1] == '\r' && cl.foundtalk2wav)
-                                                               S_LocalSound ("sound/misc/talk2.wav");
-                                                       else
-                                                               S_LocalSound ("sound/misc/talk.wav");
-                                               }
+                                               if(msg[1] == con_chatsound_team_mask.integer && cl.foundteamchatsound)
+                                                       S_LocalSound (con_chatsound_team_file.string);
                                                else
-                                               {
-                                                       if (msg[1] == '(' && cl.foundtalk2wav)
-                                                               S_LocalSound ("sound/misc/talk2.wav");
-                                                       else
-                                                               S_LocalSound ("sound/misc/talk.wav");
-                                               }
+                                                       S_LocalSound (con_chatsound_file.string);
                                        }
                                }
-                               
                                // Send to chatbox for say/tell (1) and messages (3)
                                // 3 is just so that a message can be sent to the chatbox without a sound.
                                if (*msg == 1 || *msg == 3)
                                        mask = CON_MASK_CHAT;
-                               
+
                                line[index++] = STRING_COLOR_TAG;
                                line[index++] = '3';
                                msg++;
@@ -1455,61 +1452,6 @@ void Con_Printf(const char *fmt, ...)
        Con_MaskPrint(CON_MASK_PRINT, msg);
 }
 
-/*
-================
-Con_Warn
-================
-*/
-void Con_Warn(const char *msg)
-{
-       Con_Printf("^3%s",msg);
-}
-
-/*
-================
-Con_Warnf
-================
-*/
-void Con_Warnf(const char *fmt, ...)
-{
-       va_list argptr;
-       char msg[MAX_INPUTLINE];
-
-       va_start(argptr,fmt);
-       dpvsnprintf(msg,sizeof(msg),fmt,argptr);
-       va_end(argptr);
-
-       Con_Printf("^3%s",msg);
-}
-
-/*
-================
-Con_Error
-================
-*/
-void Con_Error(const char *msg)
-{
-       Con_Printf("^1%s",msg);
-}
-
-/*
-================
-Con_Errorf
-================
-*/
-void Con_Errorf(const char *fmt, ...)
-{
-       va_list argptr;
-       char msg[MAX_INPUTLINE];
-
-       va_start(argptr,fmt);
-       dpvsnprintf(msg,sizeof(msg),fmt,argptr);
-       va_end(argptr);
-
-       Con_Printf("^1%s",msg);
-
-}
-
 /*
 ================
 Con_DPrint
@@ -1624,7 +1566,7 @@ static void Con_DrawInput (void)
        DrawQ_String(x, con_vislines - con_textsize.value*2, text, y + 3, con_textsize.value, con_textsize.value, 1.0, 1.0, 1.0, 1.0, 0, NULL, false, FONT_CONSOLE );
 
        // draw a cursor on top of this
-       if ((int)(realtime*con_cursorspeed) & 1)                // cursor is visible
+       if ((int)(host.realtime*con_cursorspeed) & 1)           // cursor is visible
        {
                if (!utf8_enable.integer)
                {
@@ -1878,7 +1820,7 @@ void Con_DrawNotify (void)
                int colorindex = -1;
                const char *cursor;
                char charbuf16[16];
-               cursor = u8_encodech(0xE00A + ((int)(realtime * con_cursorspeed)&1), NULL, charbuf16);
+               cursor = u8_encodech(0xE00A + ((int)(host.realtime * con_cursorspeed)&1), NULL, charbuf16);
 
                // LadyHavoc: speedup, and other improvements
                if (chat_mode < 0)
@@ -2032,7 +1974,7 @@ void Con_DrawConsole (int lines)
                if (sx != 0 || sy != 0)
                        conbackflags &= CACHEPICFLAG_NOCLAMP;
                conbackpic = scr_conbrightness.value >= 0.01f ? Draw_CachePic_Flags("gfx/conback", conbackflags) : NULL;
-               sx *= realtime; sy *= realtime;
+               sx *= host.realtime; sy *= host.realtime;
                sx -= floor(sx); sy -= floor(sy);
                if (Draw_IsPicLoaded(conbackpic))
                        DrawQ_SuperPic(0, lines - vid_conheight.integer, conbackpic, vid_conwidth.integer, vid_conheight.integer,
@@ -2049,7 +1991,7 @@ void Con_DrawConsole (int lines)
                sx = scr_conscroll2_x.value;
                sy = scr_conscroll2_y.value;
                conbackpic = Draw_CachePic_Flags("gfx/conback2", (sx != 0 || sy != 0) ? CACHEPICFLAG_NOCLAMP : 0);
-               sx *= realtime; sy *= realtime;
+               sx *= host.realtime; sy *= host.realtime;
                sx -= floor(sx); sy -= floor(sy);
                if(Draw_IsPicLoaded(conbackpic))
                        DrawQ_SuperPic(0, lines - vid_conheight.integer, conbackpic, vid_conwidth.integer, vid_conheight.integer,
@@ -2064,7 +2006,7 @@ void Con_DrawConsole (int lines)
                sx = scr_conscroll3_x.value;
                sy = scr_conscroll3_y.value;
                conbackpic = Draw_CachePic_Flags("gfx/conback3", (sx != 0 || sy != 0) ? CACHEPICFLAG_NOCLAMP : 0);
-               sx *= realtime; sy *= realtime;
+               sx *= host.realtime; sy *= host.realtime;
                sx -= floor(sx); sy -= floor(sy);
                if(Draw_IsPicLoaded(conbackpic))
                        DrawQ_SuperPic(0, lines - vid_conheight.integer, conbackpic, vid_conwidth.integer, vid_conheight.integer,
@@ -2430,7 +2372,7 @@ static int Nicks_strncasecmp(char *a, char *b, unsigned int a_len)
  */
 static int Nicks_CompleteCountPossible(char *line, int pos, char *s, qboolean isCon)
 {
-       char name[128];
+       char name[MAX_SCOREBOARDNAME];
        int i, p;
        int match;
        int spos;
@@ -2761,7 +2703,7 @@ int Nicks_CompleteChatLine(char *buffer, size_t size, unsigned int pos)
                msg = Nicks_list[0];
                len = min(size - Nicks_matchpos - 3, strlen(msg));
                memcpy(&buffer[Nicks_matchpos], msg, len);
-               if( len < (size - 7) ) // space for color (^[0-9] or ^xrgb) and space and \0
+               if(len < size - 7) // space for color code (^[0-9] or ^xrgb), space and \0
                        len = (int)Nicks_AddLastColor(buffer, Nicks_matchpos+(int)len);
                buffer[len++] = ' ';
                buffer[len] = 0;
@@ -3075,7 +3017,7 @@ done:
 
                                memcpy(&key_line[key_linepos] , Nicks_list[0], cmd_len);
                                key_linepos += cmd_len;
-                               if(key_linepos < (int)(sizeof(key_line)-4)) // space for ^, X and space and \0
+                               if(key_linepos < (int)(sizeof(key_line) - 7)) // space for color code (^[0-9] or ^xrgb), space and \0
                                        key_linepos = Nicks_AddLastColor(key_line, key_linepos);
                        }
                        key_line[key_linepos++] = ' ';