]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
terrencehill's color codes patch. Please test thoroughly! Syntax: ^xF00 = red
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 25 Dec 2008 18:03:49 +0000 (18:03 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 25 Dec 2008 18:03:49 +0000 (18:03 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8602 d7cf8633-e32d-0410-b094-e92efae38249

common.c
console.c
draw.h
gl_draw.c
host_cmd.c
prvm_cmds.c
sv_main.c

index c9248464517a1642835cd06effb11b7af39b76c5..e0cffe48120f4790c34348817b8f509a3fd87321 100644 (file)
--- a/common.c
+++ b/common.c
@@ -1777,6 +1777,26 @@ COM_StringLengthNoColors(const char *s, size_t size_s, qboolean *valid)
                                ++s;
                                switch((s == end) ? 0 : *s)
                                {
+                                       case STRING_COLOR_RGB_DEFAULT:
+                                               if (s+1 != end && isxdigit(s[1]) &&
+                                                       s+2 != end && isxdigit(s[2]) &&
+                                                       s+3 != end && isxdigit(s[3]) )
+                                               {
+                                                       s+=3;
+                                                       break;
+                                               }
+                                               ++len; // STRING_COLOR_TAG
+                                               ++len; // STRING_COLOR_RGB_DEFAULT
+                                               break;
+                                       /*case 'a':
+                                               if ( s+1 != end && ( isxdigit(s[1]) || (s[1] == '+' || s[1] == '-') ) )
+                                               {
+                                                       s++;
+                                                       break;
+                                               }
+                                               ++len; // STRING_COLOR_TAG
+                                               ++len; // STRING_COLOR_RGB_DEFAULT
+                                               break;*/
                                        case 0: // ends with unfinished color code!
                                                ++len;
                                                if(valid)
@@ -1841,6 +1861,20 @@ COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out,
                                ++in;
                                switch((in == end) ? 0 : *in)
                                {
+                                       case STRING_COLOR_RGB_DEFAULT:
+                                               if (in+1 != end && isxdigit(in[1]) &&
+                                                       in+2 != end && isxdigit(in[2]) &&
+                                                       in+3 != end && isxdigit(in[3]) )
+                                               {
+                                                       in+=3;
+                                                       break;
+                                               }
+                                       /*case 'a':
+                                               if ( in+1 != end && ( isxdigit(in[1]) || (in[1] == '+' || in[1] == '-') ) )
+                                               {
+                                                       in++;
+                                                       break;
+                                               }*/
                                        case 0: // ends with unfinished color code!
                                                APPEND(STRING_COLOR_TAG);
                                                // finish the code by appending another caret when escaping
index fb75ba209b6af6cb1c3a7da0eff667880552fe41..be3c12c8a816a51817b72751be8a19e9318d9a6b 100644 (file)
--- a/console.c
+++ b/console.c
@@ -873,6 +873,69 @@ void Con_Rcon_AddChar(char c)
        --log_dest_buffer_appending;
 }
 
+/**
+ * Convert an RGB color to its nearest quake color.
+ * I'll cheat on this a bit by translating the colors to HSV first,
+ * S and V decide if it's black or white, otherwise, H will decide the
+ * actual color.
+ * @param _r Red (0-255)
+ * @param _g Green (0-255)
+ * @param _b Blue (0-255)
+ * @return A quake color character.
+ */
+static char Sys_Con_NearestColor(const unsigned char _r, const unsigned char _g, const unsigned char _b)
+{
+       float r = ((float)_r)/255.0;
+       float g = ((float)_g)/255.0;
+       float b = ((float)_b)/255.0;
+       float min = min(r, min(g, b));
+       float max = max(r, max(g, b));
+
+       int h; ///< Hue angle [0,360]
+       float s; ///< Saturation [0,1]
+       float v = max; ///< In HSV v == max [0,1]
+
+       if(max == min)
+               s = 0;
+       else
+               s = 1.0 - (min/max);
+
+       // Saturation threshold. We now say 0.2 is the minimum value for a color!
+       if(s < 0.2)
+       {
+               // If the value is less than half, return a black color code.
+               // Otherwise return a white one.
+               if(v < 0.5)
+                       return '0';
+               return '7';
+       }
+
+       // Let's get the hue angle to define some colors:
+       if(max == min)
+               h = 0;
+       else if(max == r)
+               h = (int)(60.0 * (g-b)/(max-min))%360;
+       else if(max == g)
+               h = (int)(60.0 * (b-r)/(max-min) + 120);
+       else if(max == b)
+               h = (int)(60.0 * (r-g)/(max-min) + 240);
+
+       if(h < 36) // *red* to orange
+               return '1';
+       else if(h < 80) // orange over *yellow* to evilish-bright-green
+               return '3';
+       else if(h < 150) // evilish-bright-green over *green* to ugly bright blue
+               return '2';
+       else if(h < 200) // ugly bright blue over *bright blue* to darkish blue
+               return '5';
+       else if(h < 270) // darkish blue over *dark blue* to cool purple
+               return '4';
+       else if(h < 330) // cool purple over *purple* to ugly swiny red
+               return '6';
+       else // ugly red to red closes the circly
+               return '1';
+}
+
 /*
 ================
 Con_Print
@@ -967,13 +1030,39 @@ void Con_Print(const char *msg)
                                        int lastcolor = 0;
                                        const char *in;
                                        char *out;
+                                       char color;
                                        for(in = line, out = printline; *in; ++in)
                                        {
                                                switch(*in)
                                                {
                                                        case STRING_COLOR_TAG:
-                                                               switch(in[1])
+                                                               if( in[1] == STRING_COLOR_RGB_DEFAULT && isxdigit(in[2]) && isxdigit(in[3]) && isxdigit(in[4]) )
+                                                               {
+                                                                       char r = tolower(in[2]);
+                                                                       char g = tolower(in[3]);
+                                                                       char b = tolower(in[4]);
+                                                                       // it's a hex digit already, so the else part needs no check --blub
+                                                                       if(isdigit(r)) r -= '0';
+                                                                       else r -= 87;
+                                                                       if(isdigit(g)) g -= '0';
+                                                                       else g -= 87;
+                                                                       if(isdigit(b)) b -= '0';
+                                                                       else b -= 87;
+                                                                       
+                                                                       color = Sys_Con_NearestColor(r * 17, g * 17, b * 17);
+                                                                       in += 3; // 3 only, the switch down there does the fourth
+                                                               }
+                                                               else
+                                                                       color = in[1];
+                                                               
+                                                               switch(color)
                                                                {
+                                                                       /*case 'a':
+                                                                               if ( isxdigit(in[2]) || in[2] == '+' || in[2] == '-' )
+                                                                               {
+                                                                                       in+=2;
+                                                                                       break;
+                                                                               }*/
                                                                        case STRING_COLOR_TAG:
                                                                                ++in;
                                                                                *out++ = STRING_COLOR_TAG;
@@ -1072,6 +1161,18 @@ void Con_Print(const char *msg)
                                                        case STRING_COLOR_TAG:
                                                                switch(in[1])
                                                                {
+                                                                       case STRING_COLOR_RGB_DEFAULT:
+                                                                               if ( isxdigit(in[2]) && isxdigit(in[3]) && isxdigit(in[4]) )
+                                                                               {
+                                                                                       in+=4;
+                                                                                       break;
+                                                                               }
+                                                                       /*case 'a':
+                                                                               if ( isxdigit(in[2]) || in[2] == '+' || in[2] == '-' )
+                                                                               {
+                                                                                       in+=2;
+                                                                                       break;
+                                                                               }*/
                                                                        case STRING_COLOR_TAG:
                                                                                ++in;
                                                                                *out++ = STRING_COLOR_TAG;
@@ -1436,7 +1537,7 @@ void Con_DrawNotify (void)
        if(numChatlines)
        {
                v = chatstart + numChatlines * con_chatsize.value;
-               Con_DrawNotifyRect(CON_MASK_CHAT, 0, con_chattime.value, 0, chatstart, vid_conwidth.value * con_chatwidth.value, v - chatstart, con_chatsize.value, 0.0, 1.0, "^3\014\014\014 "); // 015 is ·> character in conchars.tga
+               Con_DrawNotifyRect(CON_MASK_CHAT, 0, con_chattime.value, 0, chatstart, vid_conwidth.value * con_chatwidth.value, v - chatstart, con_chatsize.value, 0.0, 1.0, "^3\014\014\014 "); // 015 is Â·> character in conchars.tga
        }
 
        if (key_dest == key_message)
@@ -1804,11 +1905,10 @@ void Con_DisplayList(const char **list)
                Con_Print("\n\n");
 }
 
-/* Nicks_CompleteCountPossible
-
-   Count the number of possible nicks to complete
- */
-//qboolean COM_StringDecolorize(const char *in, size_t size_in, char *out, size_t size_out, qboolean escape_carets);
+/*
+       SanitizeString strips color tags from the string in
+       and writes the result on string out
+*/
 void SanitizeString(char *in, char *out)
 {
        while(*in)
@@ -1821,18 +1921,47 @@ void SanitizeString(char *in, char *out)
                                out[0] = STRING_COLOR_TAG;
                                out[1] = 0;
                                return;
-                       } else if(*in >= '0' && *in <= '9')
+                       }
+                       else if (*in >= '0' && *in <= '9') // ^[0-9] found
                        {
                                ++in;
-                               if(!*in) // end
+                               if(!*in)
                                {
                                        *out = 0;
                                        return;
-                               } else if (*in == STRING_COLOR_TAG)
+                               } else if (*in == STRING_COLOR_TAG) // ^[0-9]^ found, don't print ^[0-9]
                                        continue;
-                       } else if (*in != STRING_COLOR_TAG) {
-                               --in;
                        }
+                       else if (*in == STRING_COLOR_RGB_DEFAULT) // ^x found
+                       {
+                               if ( isxdigit(in[1]) && isxdigit(in[2]) && isxdigit(in[3]) )
+                               {
+                                       in+=4;
+                                       if (!*in)
+                                       {
+                                               *out = 0;
+                                               return;
+                                       } else if (*in == STRING_COLOR_TAG) // ^xrgb^ found, don't print ^xrgb
+                                               continue;
+                               }
+                               else in--;
+                       }
+                       /*else if (*in == 'a') // ^a found
+                       {
+                               if ( isxdigit(in[1]) || isxdigit(in[1]) == '+' || isxdigit(in[1]) == '-')
+                               {
+                                       in+=2;
+                                       if (!*in)
+                                       {
+                                               *out = 0;
+                                               return;
+                                       } else if (*in == STRING_COLOR_TAG) // ^ax^ found, don't print ^ax
+                                               continue;
+                               }
+                               else in = in--;
+                       }*/
+                       else if (*in != STRING_COLOR_TAG)
+                               --in;
                }
                *out = qfont_table[*(unsigned char*)in];
                ++in;
@@ -1921,6 +2050,11 @@ int Nicks_strncasecmp(char *a, char *b, unsigned int a_len)
        return 0;
 }
 
+
+/* Nicks_CompleteCountPossible
+
+   Count the number of possible nicks to complete
+ */
 int Nicks_CompleteCountPossible(char *line, int pos, char *s, qboolean isCon)
 {
        char name[128];
@@ -1944,7 +2078,7 @@ int Nicks_CompleteCountPossible(char *line, int pos, char *s, qboolean isCon)
                        continue;
 
                SanitizeString(cl.scores[p].name, name);
-               //Con_Printf("Sanitized: %s^7 -> %s", cl.scores[p].name, name);
+               //Con_Printf(" ^2Sanitized: ^7%s -> %s", cl.scores[p].name, name);
 
                if(!name[0])
                        continue;
@@ -2176,11 +2310,16 @@ const char **Nicks_CompleteBuildList(int count)
        return buf;
 }
 
+/*
+       Nicks_AddLastColor
+       Restores the previous used color, after the autocompleted name.
+*/
 int Nicks_AddLastColor(char *buffer, int pos)
 {
        qboolean quote_added = false;
        int match;
-       char color = '7';
+       char color = STRING_COLOR_DEFAULT + '0';
+       char r = 0, g = 0, b = 0;
 
        if(con_nickcompletion_flags.integer & NICKS_ADD_QUOTE && buffer[Nicks_matchpos-1] == '\"')
        {
@@ -2195,16 +2334,58 @@ int Nicks_AddLastColor(char *buffer, int pos)
                // find last color
                for(match = Nicks_matchpos-1; match >= 0; --match)
                {
-                       if(buffer[match] == STRING_COLOR_TAG && buffer[match+1] >= '0' && buffer[match+1] <= '9')
+                       if(buffer[match] == STRING_COLOR_TAG)
                        {
-                               color = buffer[match+1];
-                               break;
+                               if( isdigit(buffer[match+1]) )
+                               {
+                                       color = buffer[match+1];
+                                       break;
+                               }
+                               else if(buffer[match+1] == STRING_COLOR_RGB_DEFAULT)
+                               {
+                                       if ( isxdigit(buffer[match+2]) && isxdigit(buffer[match+3]) && isxdigit(buffer[match+4]) )
+                                               r = buffer[match+2];
+                                               g = buffer[match+3];
+                                               b = buffer[match+4];
+                                               color = -1;
+                                               break;
+                               }
                        }
                }
-               if(!quote_added && buffer[pos-2] == STRING_COLOR_TAG && buffer[pos-1] >= '0' && buffer[pos-1] <= '9') // when thes use &4
-                       pos -= 2;
-               buffer[pos++] = STRING_COLOR_TAG;
-               buffer[pos++] = color;
+               if(!quote_added)
+               {
+                       if( buffer[pos-2] == STRING_COLOR_TAG && isdigit(buffer[pos-1]) ) // when thes use &4
+                       {
+                               pos -= 2;
+                       }
+                       else if( pos >= 5 && buffer[pos-5] == STRING_COLOR_TAG && buffer[pos-4] == STRING_COLOR_RGB_DEFAULT)
+                       {
+                               if ( isxdigit(buffer[pos-3]) && isxdigit(buffer[pos-2]) && isxdigit(buffer[pos-1]) )
+                               {
+                                       pos -= 5;
+                                       color = -1;
+                               }
+                       }
+               }
+               if (color == -1)
+               {
+                       buffer[pos++] = STRING_COLOR_TAG;
+                       buffer[pos++] = STRING_COLOR_RGB_DEFAULT;
+                       buffer[pos++] = r;
+                       buffer[pos++] = g;
+                       buffer[pos++] = b;
+               }
+               /*else if (color == -2)
+               {
+                       buffer[pos++] = STRING_COLOR_TAG;
+                       buffer[pos++] = 'a';
+                       buffer[pos++] = a;
+               }*/
+               else
+               {
+                       buffer[pos++] = STRING_COLOR_TAG;
+                       buffer[pos++] = color;
+               }
        }
        return pos;
 }
@@ -2223,7 +2404,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 - 4) ) // space for color and space and \0
+               if( len < (size - 7) ) // space for color (^[0-9] or ^xrgb) and space and \0
                        len = Nicks_AddLastColor(buffer, Nicks_matchpos+len);
                buffer[len++] = ' ';
                buffer[len] = 0;
diff --git a/draw.h b/draw.h
index 88b3d5a11f1e8f5c850cb4f854f875b54d107fb0..259ed9b05f6f856b672824e8f15c44ac5683c1be 100644 (file)
--- a/draw.h
+++ b/draw.h
@@ -110,6 +110,10 @@ extern dp_font_t dp_fonts[MAX_FONTS];
 #define STRING_COLOR_TAG                       '^'
 #define STRING_COLOR_DEFAULT           7
 #define STRING_COLOR_DEFAULT_STR       "^7"
+#define STRING_COLOR_RGB_DEFAULT 'x'
+#define STRING_COLOR_RGB_DEFAULT_STR "^xfff"
+//#define STRING_COLOR_ALPHA_DEFAULT 'a'
+//#define STRING_COLOR_ALPHA_DEFAULT_STR "^af"
 
 // all of these functions will set r_defdef.draw2dstage if not in 2D rendering mode (and of course prepare for 2D rendering in that case)
 
index 9d3d47b531deb7b14b87d4b978717657f6f6223f..b64760fdb8cb99bee303f857b09381ca76f3cb52 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -922,7 +922,15 @@ static void DrawQ_GetTextColor(float color[4], int colorindex, float r, float g,
 {
        float C = r_textcontrast.value;
        float B = r_textbrightness.value;
-       Vector4Copy(string_colors[colorindex], color);
+       if (colorindex & 0x10000) // that bit means RGB color
+       {
+               color[0] = ((colorindex >> 12) & 0xf) / 15.0;
+               color[1] = ((colorindex >> 8) & 0xf) / 15.0;
+               color[2] = ((colorindex >> 4) & 0xf) / 15.0;
+               color[3] = (colorindex & 0xf) / 15.0;
+       }
+       else
+               Vector4Copy(string_colors[colorindex], color);
        Vector4Set(color, (color[0] * C + B) * r, (color[1] * C + B) * g, (color[2] * C + B) * b, color[3] * a);
        if (shadow)
        {
@@ -936,6 +944,8 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
        int num, colorindex = STRING_COLOR_DEFAULT;
        size_t i;
        float x = 0;
+       char ch;
+       int current_alpha, tempcolorindex;
 
        if (*maxlen < 1)
                *maxlen = 1<<30;
@@ -947,6 +957,8 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
 
        maxwidth /= fnt->scale;
 
+       current_alpha = 0xf;
+
        for (i = 0;i < *maxlen && text[i];i++)
        {
                if (text[i] == ' ')
@@ -958,16 +970,69 @@ float DrawQ_TextWidth_Font_UntilWidth_TrackColors(const char *text, size_t *maxl
                }
                if (text[i] == STRING_COLOR_TAG && !ignorecolorcodes && i + 1 < *maxlen)
                {
-                       if (text[i+1] == STRING_COLOR_TAG)
+                       ch = text[++i];
+            if (ch <= '9' && ch >= '0') // ^[0-9] found
                        {
-                               i++;
+                               colorindex = ch - '0';
+                continue;
+                       }
+                       else if (ch == STRING_COLOR_RGB_DEFAULT && i + 3 < *maxlen ) // ^x found
+                       {
+                               // building colorindex...
+                               ch = tolower(text[i+1]);
+                               tempcolorindex = 0x10000; // binary: 1,0000,0000,0000,0000
+                               if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 12;
+                               else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 12;
+                               else tempcolorindex = 0;
+                               if (tempcolorindex)
+                               {
+                                       ch = tolower(text[i+2]);
+                                       if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 8;
+                                       else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 8;
+                                       else tempcolorindex = 0;
+                                       if (tempcolorindex)
+                                       {
+                                               ch = tolower(text[i+3]);
+                                               if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 4;
+                                               else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 4;
+                                               else tempcolorindex = 0;
+                                               if (tempcolorindex)
+                                               {
+                                                       colorindex = tempcolorindex | current_alpha;
+                                                       // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
+                                                       i+=3;
+                                                       continue;
+                                               }
+                                       }
+                               }
                        }
-                       else if (text[i+1] >= '0' && text[i+1] <= '9')
+                       /*else if (ch == 'a' && i + 1 < *maxlen) // ^a found
                        {
-                               colorindex = text[i+1] - '0';
+                               if (colorindex > 9)
+                               {
+                                       ch = tolower(text[i+1]);
+                                       if (ch <= '9' && ch >= '0') current_alpha = (ch - '0');
+                                       else if (ch >= 'a' && ch <= 'f') current_alpha = (ch - 87);
+                                       else if (ch == '+' && colorindex > 9)
+                                       {
+                                               current_alpha = colorindex & 0xf;
+                                               if (current_alpha < 0xf)
+                                                       current_alpha++;
+                                       }
+                                       else if (ch == '-' && colorindex > 9)
+                                       {
+                                               current_alpha = colorindex & 0xf;
+                                               if (current_alpha > 0)
+                                                       current_alpha--;
+                                       }
+                                       colorindex = ((colorindex >> 4 ) << 4) + current_alpha;
+                               }
                                i++;
                                continue;
-                       }
+                       }*/
+                       else if (ch == STRING_COLOR_TAG) // ^^ found, ignore the first ^ and go to print the second
+                               i++;
+                       i--;
                }
                num = (unsigned char) text[i];
                if(x + fnt->width_of[num] > maxwidth)
@@ -994,6 +1059,8 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
        float vertex3f[QUADELEMENTS_MAXQUADS*4*3];
        float texcoord2f[QUADELEMENTS_MAXQUADS*4*2];
        float color4f[QUADELEMENTS_MAXQUADS*4*4];
+       char ch;
+       int current_alpha, tempcolorindex;
 
        int tw, th;
        tw = R_TextureWidth(fnt->tex);
@@ -1035,6 +1102,7 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
                        x += r_textshadow.value;
                        y += r_textshadow.value;
                }
+               current_alpha = 0xf;
                for (i = 0;i < maxlen && text[i];i++)
                {
                        if (text[i] == ' ')
@@ -1044,17 +1112,74 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
                        }
                        if (text[i] == STRING_COLOR_TAG && !ignorecolorcodes && i + 1 < maxlen)
                        {
-                               if (text[i+1] == STRING_COLOR_TAG)
+                               ch = text[++i];
+                               if (ch <= '9' && ch >= '0') // ^[0-9] found
                                {
-                                       i++;
+                                       colorindex = ch - '0';
+                                       DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow);
+                                       continue;
                                }
-                               else if (text[i+1] >= '0' && text[i+1] <= '9')
+                               else if (ch == STRING_COLOR_RGB_DEFAULT && i+3 < maxlen ) // ^x found
                                {
-                                       colorindex = text[i+1] - '0';
-                                       DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow);
+                                       // building colorindex...
+                                       ch = tolower(text[i+1]);
+                                       tempcolorindex = 0x10000; // binary: 1,0000,0000,0000,0000
+                                       if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 12;
+                                       else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 12;
+                                       else tempcolorindex = 0;
+                                       if (tempcolorindex)
+                                       {
+                                               ch = tolower(text[i+2]);
+                                               if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 8;
+                                               else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 8;
+                                               else tempcolorindex = 0;
+                                               if (tempcolorindex)
+                                               {
+                                                       ch = tolower(text[i+3]);
+                                                       if (ch <= '9' && ch >= '0') tempcolorindex |= (ch - '0') << 4;
+                                                       else if (ch >= 'a' && ch <= 'f') tempcolorindex |= (ch - 87) << 4;
+                                                       else tempcolorindex = 0;
+                                                       if (tempcolorindex)
+                                                       {
+                                                               colorindex = tempcolorindex | current_alpha;
+                                                               // ...done! now colorindex has rgba codes (1,rrrr,gggg,bbbb,aaaa)
+                                                               //Con_Printf("^1colorindex:^7 %x\n", colorindex);
+                                                               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow);
+                                                               i+=3;
+                                                               continue;
+                                                       }
+                                               }
+                                       }
+                               }
+                               /*else if (ch == 'a' && i+1 < maxlen ) // ^a found
+                               {
+                                       if (colorindex > 9) // colorindex is a RGB color
+                                       {
+                                               ch = tolower(text[i+1]);
+                                               if (ch <= '9' && ch >= '0') current_alpha = (ch - '0');
+                                               else if (ch >= 'a' && ch <= 'f') current_alpha = (ch - 87);
+                                               else if (ch == '+' && colorindex > 9)
+                                               {
+                                                       current_alpha = colorindex & 0xf;
+                                                       if (current_alpha < 0xf)
+                                                               current_alpha++;
+                                               }
+                                               else if (ch == '-' && colorindex > 9)
+                                               {
+                                                       current_alpha = colorindex & 0xf;
+                                                       if (current_alpha > 0)
+                                                               current_alpha--;
+                                               }
+                                               colorindex = ((colorindex >> 4 ) << 4) + current_alpha;
+                                               //Con_Printf("^1colorindex:^7 %x\n", colorindex);
+                                               DrawQ_GetTextColor(color, colorindex, basered, basegreen, baseblue, basealpha, shadow);
+                                       }
                                        i++;
                                        continue;
-                               }
+                               }*/
+                               else if (ch == STRING_COLOR_TAG)
+                                       i++;
+                               i--;
                        }
                        num = (unsigned char) text[i];
                        thisw = fnt->width_of[num];
@@ -1067,14 +1192,14 @@ float DrawQ_String_Font(float startx, float starty, const char *text, size_t max
                        ac[ 4] = color[0];ac[ 5] = color[1];ac[ 6] = color[2];ac[ 7] = color[3];
                        ac[ 8] = color[0];ac[ 9] = color[1];ac[10] = color[2];ac[11] = color[3];
                        ac[12] = color[0];ac[13] = color[1];ac[14] = color[2];ac[15] = color[3];
-                       at[ 0] = s  ;at[ 1] = t  ;
-                       at[ 2] = s+u;at[ 3] = t  ;
-                       at[ 4] = s+u;at[ 5] = t+v;
-                       at[ 6] = s  ;at[ 7] = t+v;
-                       av[ 0] = x  ;av[ 1] = y  ;av[ 2] = 10;
-                       av[ 3] = x+w*thisw;av[ 4] = y  ;av[ 5] = 10;
-                       av[ 6] = x+w*thisw;av[ 7] = y+h;av[ 8] = 10;
-                       av[ 9] = x  ;av[10] = y+h;av[11] = 10;
+                       at[ 0] = s              ; at[ 1] = t    ;
+                       at[ 2] = s+u    ; at[ 3] = t    ;
+                       at[ 4] = s+u    ; at[ 5] = t+v  ;
+                       at[ 6] = s              ; at[ 7] = t+v  ;
+                       av[ 0] = x                      ; av[ 1] = y    ; av[ 2] = 10;
+                       av[ 3] = x+w*thisw      ; av[ 4] = y    ; av[ 5] = 10;
+                       av[ 6] = x+w*thisw      ; av[ 7] = y+h  ; av[ 8] = 10;
+                       av[ 9] = x                      ; av[10] = y+h  ; av[11] = 10;
                        ac += 16;
                        at += 8;
                        av += 12;
@@ -1111,18 +1236,19 @@ float DrawQ_String(float startx, float starty, const char *text, size_t maxlen,
        return DrawQ_String_Font(startx, starty, text, maxlen, w, h, basered, basegreen, baseblue, basealpha, flags, outcolor, ignorecolorcodes, &dp_fonts[0]);
 }
 
-float DrawQ_TextWidth_Font_UntilWidth(const char *text, size_t *maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxWidth)
+float DrawQ_TextWidth_Font(const char *text, size_t maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt)
 {
-       return DrawQ_TextWidth_Font_UntilWidth_TrackColors(text, maxlen, NULL, ignorecolorcodes, fnt, maxWidth);
+       return DrawQ_TextWidth_Font_UntilWidth(text, &maxlen, ignorecolorcodes, fnt, 1000000000);
 }
 
-float DrawQ_TextWidth_Font(const char *text, size_t maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt)
+float DrawQ_TextWidth_Font_UntilWidth(const char *text, size_t *maxlen, qboolean ignorecolorcodes, const dp_font_t *fnt, float maxWidth)
 {
-       return DrawQ_TextWidth_Font_UntilWidth(text, &maxlen, ignorecolorcodes, fnt, 1000000000);
+       return DrawQ_TextWidth_Font_UntilWidth_TrackColors(text, maxlen, NULL, ignorecolorcodes, fnt, maxWidth);
 }
 
 #if 0
 // not used
+// no ^xrgb management
 static int DrawQ_BuildColoredText(char *output2c, size_t maxoutchars, const char *text, int maxreadchars, qboolean ignorecolorcodes, int *outcolor)
 {
        int color, numchars = 0;
index b5a4047b2bbc17e69a295a97dfc0de4ea636f09a..4436ae5b4f0a52e2566741164fa98a438b52d2f4 100644 (file)
@@ -1035,7 +1035,7 @@ void Host_Name_f (void)
        if (strcmp(host_client->old_name, host_client->name))
        {
                if (host_client->spawned)
-                       SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
+                       SV_BroadcastPrintf("%s ^7changed name to %s\n", host_client->old_name, host_client->name);
                strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
                // send notification to all clients
                MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
index ccd5b0a02eaa4a16ebab1e1d1af61deaf0ead895..924f6880061936d81fdaee7a4d8fabfdfd15ddda 100644 (file)
@@ -1957,9 +1957,7 @@ void VM_strdecolorize(void)
        // Prepare Strings
        VM_SAFEPARMCOUNT(1,VM_strdecolorize);
        szString = PRVM_G_STRING(OFS_PARM0);
-
        COM_StringDecolorize(szString, 0, szNewString, sizeof(szNewString), TRUE);
-
        PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(szNewString);
 }
 
@@ -4409,50 +4407,18 @@ void VM_changepitch (void)
        PRVM_EDICTFIELDVALUE(ent, prog->fieldoffsets.angles)->vector[0] = ANGLEMOD (current + move);
 }
 
-// TODO: adapt all static function names to use a single naming convention... [12/3/2007 Black]
-static int Is_Text_Color (char c, char t)
-{
-       int a = 0;
-       char c2 = c - (c & 128);
-       char t2 = t - (t & 128);
-
-       if(c != STRING_COLOR_TAG && c2 != STRING_COLOR_TAG)             return 0;
-       if(t >= '0' && t <= '9')                a = 1;
-       if(t2 >= '0' && t2 <= '9')              a = 1;
-/*     if(t >= 'A' && t <= 'Z')                a = 2;
-       if(t2 >= 'A' && t2 <= 'Z')              a = 2;
-
-       if(a == 1 && scr_colortext.integer > 0)
-               return 1;
-       if(a == 2 && scr_multifonts.integer > 0)
-               return 2;
-*/
-       return a;
-}
 
 void VM_uncolorstring (void)
 {
-       const char      *in;
-       char            out[VM_STRINGTEMP_LENGTH];
-       int                     k = 0, i = 0;
+       char szNewString[VM_STRINGTEMP_LENGTH];
+       const char *szString;
 
+       // Prepare Strings
        VM_SAFEPARMCOUNT(1, VM_uncolorstring);
-       in = PRVM_G_STRING(OFS_PARM0);
-       VM_CheckEmptyString (in);
-
-       while (in[k])
-       {
-               if(in[k+1])
-               if(Is_Text_Color(in[k], in[k+1]) == 1/* || (in[k] == '&' && in[k+1] == 'r')*/)
-               {
-                       k += 2;
-                       continue;
-               }
-               out[i] = in[k];
-               ++k;
-               ++i;
-       }
-       PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(out);
+       szString = PRVM_G_STRING(OFS_PARM0);
+       COM_StringDecolorize(szString, 0, szNewString, sizeof(szNewString), TRUE);
+       PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(szNewString);
+       
 }
 
 // #221 float(string str, string sub[, float startpos]) strstrofs (FTE_STRINGS)
index 57d350e0277055263eed05d01298343de5255aa0..22237bba1400d357e6561fd36c8447aff5a1145d 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -1998,7 +1998,7 @@ static void SV_UpdateToReliableMessages (void)
                if (strcmp(host_client->old_name, host_client->name))
                {
                        if (host_client->spawned)
-                               SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
+                               SV_BroadcastPrintf("%s ^7changed name to %s\n", host_client->old_name, host_client->name);
                        strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
                        // send notification to all clients
                        MSG_WriteByte (&sv.reliable_datagram, svc_updatename);