From f98227d6f343e27796a77b9c72748aa4120eabd0 Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 19 Jul 2008 00:50:20 +0000 Subject: [PATCH] Better line wrapping for multiplayer chat messages git-svn-id: https://svn.eduke32.com/eduke32@867 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/build/src/osd.c | 11 +++++ polymer/eduke32/source/game.c | 68 +++++++++++++++++++------------ polymer/eduke32/source/menus.c | 4 +- polymer/eduke32/source/osdfuncs.c | 6 +-- polymer/eduke32/source/osdfuncs.h | 2 + 5 files changed, 59 insertions(+), 32 deletions(-) diff --git a/polymer/build/src/osd.c b/polymer/build/src/osd.c index 55aac2298..3879854c6 100644 --- a/polymer/build/src/osd.c +++ b/polymer/build/src/osd.c @@ -119,6 +119,11 @@ const char *stripcolorcodes(const char *t) t++; continue; } + if (*t == '^' && (Btoupper(*(t+1)) == 'S'||Btoupper(*(t+1)) == 'O')) + { + t += 2; + continue; + } colstrip[i] = *t; i++,t++; } @@ -1340,6 +1345,12 @@ void OSD_Printf(const char *fmt, ...) if (isdigit(*(++chp))) s = *chp; } + else if (*chp == '^' && Btoupper(*(chp+1)) == 'O') + { + chp++; + p = osdtextpal; + s = osdtextshade; + } else if (*chp == '\r') osdpos=0; else if (*chp == '\n') { diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index e7b03b822..f169dc867 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -151,6 +151,9 @@ static char recbuf[180]; extern void computergetinput(int snum, input *syn); +#define USERQUOTE_LEFTOFFSET 5 +#define USERQUOTE_RIGHTOFFSET 14 + enum { T_EOF = -2, @@ -275,8 +278,6 @@ void setgamepalette(player_struct *player, char *pal, int set) player->palette = pal; } -#define TEXTWRAPLEN (scale(39,ud.config.ScreenWidth,320)) - int gametext_z(int small, int starttile, int x,int y,const char *t,int s,int p,int orientation,int x1, int y1, int x2, int y2, int z) { int ac,newx,oldx=x; @@ -342,7 +343,7 @@ int gametext_z(int small, int starttile, int x,int y,const char *t,int s,int p,i } if (*t == 32) { - x+=8*z/65536; + x+=5*z/65536; t++; continue; } @@ -356,13 +357,42 @@ int gametext_z(int small, int starttile, int x,int y,const char *t,int s,int p,i if ((*t >= '0' && *t <= '9')) x += 8*z/65536; else x += tilesizx[ac]*z/65536;//(tilesizx[ac]>>small); - if (t-oldt >= (signed)TEXTWRAPLEN-!small) oldt = (char *)t, x = oldx, y+=8*z/65536; + if (x > (ud.config.ScreenWidth - 14)) oldt = (char *)t, x = oldx, y+=8*z/65536; t++; } return (x); } +int gametextlen(int x,const char *t) +{ + int ac; + + if (t == NULL) + return -1; + + while (*t) + { + if (*t == 32) + { + x+=5; + t++; + continue; + } + else ac = *t - '!' + STARTALPHANUM; + + if (ac < STARTALPHANUM || ac > (STARTALPHANUM + 93)) + break; + + if ((*t >= '0' && *t <= '9')) + x += 8; + else x += tilesizx[ac]; + t++; + } + + return (x); +} + inline int gametext(int x,int y,const char *t,int s,int dabits) { return(gametext_z(0,STARTALPHANUM, x,y,t,s,0,dabits,0, 0, xdim-1, ydim-1, 65536)); @@ -2404,10 +2434,10 @@ static void operatefta(void) { if (user_quote_time[i] <= 0) break; k = user_quote_time[i]; - l = Bstrlen(user_quote[i]); - while (l > TEXTWRAPLEN) + l = gametextlen(USERQUOTE_LEFTOFFSET,stripcolorcodes(user_quote[i])); + while (l > (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET)) { - l -= TEXTWRAPLEN; + l -= (ud.config.ScreenWidth-USERQUOTE_RIGHTOFFSET); j -= 8; } if (k > 4) @@ -2446,18 +2476,6 @@ static void operatefta(void) if (g_player[screenpeek].ps->ftq == 115 || g_player[screenpeek].ps->ftq == 116 || g_player[screenpeek].ps->ftq == 117) { k = quotebot-8-4; - /* for(i=0;i TEXTWRAPLEN) - { - l -= TEXTWRAPLEN; - k -= 8; - } - } - k -= 4; */ } j = g_player[screenpeek].ps->fta; @@ -2676,10 +2694,10 @@ static int strget_(int small,int x,int y,char *t,int dalen,int c) } c = 4-(sintable[(totalclock<<4)&2047]>>11); - i = Bstrlen(t); - while (i > TEXTWRAPLEN-!small) + i = gametextlen(USERQUOTE_LEFTOFFSET,stripcolorcodes(t)); + while (i > (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET)) { - i -= TEXTWRAPLEN-!small; + i -= (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET); y += 8; } @@ -2754,10 +2772,10 @@ static void typemode(void) } adduserquote(recbuf); quotebot += 8; - l = Bstrlen(recbuf); - while (l > TEXTWRAPLEN) + l = gametextlen(USERQUOTE_LEFTOFFSET,stripcolorcodes(recbuf)); + while (l > (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET)) { - l -= TEXTWRAPLEN; + l -= (ud.config.ScreenWidth - USERQUOTE_RIGHTOFFSET); quotebot += 8; } quotebotgoal = quotebot; diff --git a/polymer/eduke32/source/menus.c b/polymer/eduke32/source/menus.c index c9dd5d1a0..ef658858d 100644 --- a/polymer/eduke32/source/menus.c +++ b/polymer/eduke32/source/menus.c @@ -2734,7 +2734,7 @@ cheat_for_port_credits: "Parental lock", "-", "Game messages", - "HUD weapon", + "HUD weapon display", "FPS counter", "-", "Automatic voting", @@ -2812,7 +2812,7 @@ cheat_for_port_credits: } modval(0,2,(int *)&ud.drawweapon,1,probey==io); { - char *s[] = { "Off", "On", "Icon" }; + char *s[] = { "Disabled", "Normal", "Item" }; gametextpal(d,yy, s[ud.drawweapon], MENUHIGHLIGHT(io), 0); break; } diff --git a/polymer/eduke32/source/osdfuncs.c b/polymer/eduke32/source/osdfuncs.c index 5dfeb9206..89efa7a0b 100644 --- a/polymer/eduke32/source/osdfuncs.c +++ b/polymer/eduke32/source/osdfuncs.c @@ -1,6 +1,7 @@ #include "duke3d.h" #include "build.h" #include "namesdyn.h" +#include "osdfuncs.h" void GAME_drawosdchar(int x, int y, char ch, int shade, int pal) { @@ -13,16 +14,11 @@ void GAME_drawosdchar(int x, int y, char ch, int shade, int pal) rotatesprite(((x<<3)+x)<<16, (y<<3)<<16, 65536l, 0, ac, shade, pal, 8|16, 0, 0, xdim-1, ydim-1); } -#define OSDCHAR_WIDTH 8 - void GAME_drawosdstr(int x, int y, char *ch, int len, int shade, int pal) { short ac; char *ptr = OSD_GetTextPtr(); - UNREFERENCED_PARAMETER(shade); - UNREFERENCED_PARAMETER(pal); - for (x = (x<<3)+x; len>0; len--, ch++, x++) { if (*ch == 32) diff --git a/polymer/eduke32/source/osdfuncs.h b/polymer/eduke32/source/osdfuncs.h index 9a2b53811..2255c7a4f 100644 --- a/polymer/eduke32/source/osdfuncs.h +++ b/polymer/eduke32/source/osdfuncs.h @@ -5,3 +5,5 @@ int GAME_getcolumnwidth(int w); int GAME_getrowheight(int w); void GAME_clearbackground(int c, int r); void GAME_onshowosd(int shown); + +#define OSDCHAR_WIDTH 8 \ No newline at end of file