]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
centering of notify lines in nexuiz now ignores color codes
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 27 May 2006 20:07:34 +0000 (20:07 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 27 May 2006 20:07:34 +0000 (20:07 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6395 d7cf8633-e32d-0410-b094-e92efae38249

console.c

index fee68c0ee22d0ab44cc2d7deb83811460942f6a9..23b6196472173aa261afd53971d72088430ed14a 100644 (file)
--- a/console.c
+++ b/console.c
@@ -774,10 +774,27 @@ void Con_DrawNotify (void)
                text = con_text + (i % con_totallines)*con_linewidth;
 
                if (gamemode == GAME_NEXUIZ) {
-                       int linewidth;
+                       int linewidth = 0;
+                       int chars = 0;
+                       int finalchars = 0;
+                       int j;
 
-                       for (linewidth = con_linewidth; linewidth && text[linewidth-1] == ' '; linewidth--);
-                       x = (vid_conwidth.integer - linewidth * con_textsize.value) * 0.5;
+                       // count up to the last non-whitespace, and ignore color codes
+                       for (j = 0;j < con_linewidth && text[j];j++)
+                       {
+                               if (text[j] == '^' && (text[j+1] >= '0' && text[j+1] <= '9'))
+                               {
+                                       j++;
+                                       continue;
+                               }
+                               chars++;
+                               if (text[j] == ' ')
+                                       continue;
+                               finalchars = chars;
+                               linewidth = j + 1;
+                       }
+                       // center the line using the calculated width
+                       x = (vid_conwidth.integer - finalchars * con_textsize.value) * 0.5;
                } else
                        x = 0;