diff options
author | Andrey Nazarov <skuller@skuller.net> | 2013-01-15 16:15:12 +0400 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2013-01-15 16:15:12 +0400 |
commit | d4fbc09c2d1c2cffaf217fb468c883550d648102 (patch) | |
tree | 0721ed4b0d36ce44ec5a95573bf2af598eedad7c | |
parent | c2fe5f4d6ccbdb8b2e99285ee0fe303233f93fbe (diff) |
Re-introduce chat HUD.
-rw-r--r-- | doc/client.txt | 24 | ||||
-rw-r--r-- | src/client/client.h | 3 | ||||
-rw-r--r-- | src/client/main.c | 4 | ||||
-rw-r--r-- | src/client/parse.c | 2 | ||||
-rw-r--r-- | src/client/screen.c | 115 |
5 files changed, 142 insertions, 6 deletions
diff --git a/doc/client.txt b/doc/client.txt index e796810..0f19c96 100644 --- a/doc/client.txt +++ b/doc/client.txt @@ -395,6 +395,30 @@ scr_lag_max:: Specifies ping graph scale by defining the maximum value that can be displayed. Default value is 200. +scr_chathud:: + Toggles drawing of the last chat lines on the screen. Default value is 0. + - 0 — do not draw chat lines + - 1 — draw chat lines in normal color + - 2 — draw chat lines in alternative color + +scr_chathud_lines:: + Specifies number of the last chat lines drawn on the screen. Default value + is 4. Maximum value is 32. + +scr_chathud_time:: + Specifies visibility time of each chat line, counted in seconds. Default + value is 0 (lines never fade out). + +scr_chathud_x:: + Absolute value of this cvar specifies horizontal placement of the chat HUD, + counted in pixels from the screen edge. Negative values align graph to the right + edge of the screen instead of the left edge. Default value is 8. + +scr_chathud_y:: + Absolute value of this cvar specifies vertical placement of the chat HUD, + counted in pixels from the screen edge. Negative values align graph to the bottom + edge of the screen intead of the top edge. Default value is -64. + ch_health:: Enables dynamic crosshair coloring based on the health statistic seen in the player's HUD. Default value is 0 (use static color). diff --git a/src/client/client.h b/src/client/client.h index 0194c09..91e0e08 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -923,6 +923,9 @@ float SCR_FadeAlpha(unsigned startTime, unsigned visTime, unsigned fadeTime); int SCR_DrawStringEx(int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font); void SCR_DrawStringMulti(int x, int y, int flags, size_t maxlen, const char *s, qhandle_t font); +void SCR_ClearChatHUD_f(void); +void SCR_AddToChatHUD(const char *text); + #ifdef _DEBUG void CL_AddNetgraph(void); #endif diff --git a/src/client/main.c b/src/client/main.c index eb99ed9..e4cc914 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -732,7 +732,9 @@ void CL_Disconnect(error_type_t type) return; } - SCR_EndLoadingPlaque(); // get rid of loading plaque + SCR_EndLoadingPlaque(); // get rid of loading plaque + + SCR_ClearChatHUD_f(); // clear chat HUD on server change if (cls.state > ca_disconnected && !cls.demo.playback) { EXEC_TRIGGER(cl_disconnectcmd); diff --git a/src/client/parse.c b/src/client/parse.c index 96f7369..c8888ce 100644 --- a/src/client/parse.c +++ b/src/client/parse.c @@ -972,9 +972,7 @@ static void CL_ParsePrint(void) Con_SkipNotify(qfalse); -#if USE_CHATHUD SCR_AddToChatHUD(s); -#endif // silence MVD spectator chat if (cl.serverstate == ss_broadcast && !strncmp(s, "[MVD] ", 6)) diff --git a/src/client/screen.c b/src/client/screen.c index caa1e8e..eee6dde 100644 --- a/src/client/screen.c +++ b/src/client/screen.c @@ -71,6 +71,12 @@ static cvar_t *scr_scale; static cvar_t *scr_crosshair; +static cvar_t *scr_chathud; +static cvar_t *scr_chathud_lines; +static cvar_t *scr_chathud_time; +static cvar_t *scr_chathud_x; +static cvar_t *scr_chathud_y; + static cvar_t *ch_health; static cvar_t *ch_red; static cvar_t *ch_green; @@ -835,6 +841,103 @@ static void SCR_DrawObjects(void) /* =============================================================================== +CHAT HUD + +=============================================================================== +*/ + +#define MAX_CHAT_TEXT 150 +#define MAX_CHAT_LINES 32 +#define CHAT_LINE_MASK (MAX_CHAT_LINES - 1) + +typedef struct { + char text[MAX_CHAT_TEXT]; + unsigned time; +} chatline_t; + +static chatline_t scr_chatlines[MAX_CHAT_LINES]; +static unsigned scr_chathead; + +void SCR_ClearChatHUD_f(void) +{ + memset(scr_chatlines, 0, sizeof(scr_chatlines)); + scr_chathead = 0; +} + +void SCR_AddToChatHUD(const char *text) +{ + chatline_t *line; + char *p; + + line = &scr_chatlines[scr_chathead++ & CHAT_LINE_MASK]; + Q_strlcpy(line->text, text, sizeof(line->text)); + line->time = cls.realtime; + + p = strrchr(line->text, '\n'); + if (p) + *p = 0; +} + +static void SCR_DrawChatHUD(void) +{ + int x, y, flags, step; + unsigned i, lines, time; + float alpha; + chatline_t *line; + + if (scr_chathud->integer == 0) + return; + + x = scr_chathud_x->integer; + y = scr_chathud_y->integer; + + if (scr_chathud->integer == 2) + flags = UI_ALTCOLOR; + else + flags = 0; + + if (x < 0) { + x += scr.hud_width + 1; + flags |= UI_RIGHT; + } else { + flags |= UI_LEFT; + } + + if (y < 0) { + y += scr.hud_height - CHAR_HEIGHT + 1; + step = -CHAR_HEIGHT; + } else { + step = CHAR_HEIGHT; + } + + lines = scr_chathud_lines->integer; + if (lines > scr_chathead) + lines = scr_chathead; + + time = scr_chathud_time->value * 1000; + + for (i = 0; i < lines; i++) { + line = &scr_chatlines[(scr_chathead - i - 1) & CHAT_LINE_MASK]; + + if (time) { + alpha = SCR_FadeAlpha(line->time, time, 1000); + if (!alpha) + break; + + R_SetAlpha(alpha * scr_alpha->value); + SCR_DrawString(x, y, flags, line->text); + R_SetAlpha(scr_alpha->value); + } else { + SCR_DrawString(x, y, flags, line->text); + } + + y += step; + } +} + +/* +=============================================================================== + DEBUG STUFF =============================================================================== @@ -1195,6 +1298,7 @@ static const cmdreg_t scr_cmds[] = { { "sky", SCR_Sky_f }, { "draw", SCR_Draw_f, SCR_Draw_c }, { "undraw", SCR_UnDraw_f, SCR_UnDraw_c }, + { "clearchathud", SCR_ClearChatHUD_f }, { NULL } }; @@ -1223,6 +1327,12 @@ void SCR_Init(void) scr_crosshair = Cvar_Get("crosshair", "0", CVAR_ARCHIVE); scr_crosshair->changed = scr_crosshair_changed; + scr_chathud = Cvar_Get("scr_chathud", "0", 0); + scr_chathud_lines = Cvar_Get("scr_chathud_lines", "4", 0); + scr_chathud_time = Cvar_Get("scr_chathud_time", "0", 0); + scr_chathud_x = Cvar_Get("scr_chathud_x", "8", 0); + scr_chathud_y = Cvar_Get("scr_chathud_y", "-64", 0); + ch_health = Cvar_Get("ch_health", "0", 0); ch_health->changed = scr_crosshair_changed; ch_red = Cvar_Get("ch_red", "1", 0); @@ -1306,9 +1416,6 @@ void SCR_EndLoadingPlaque(void) } cls.disable_screen = 0; Con_ClearNotify_f(); -#if USE_CHATHUD - SCR_ClearChatHUD_f(); -#endif } // Clear any parts of the tiled background that were drawn on last frame @@ -1891,6 +1998,8 @@ static void SCR_Draw2D(void) SCR_DrawObjects(); + SCR_DrawChatHUD(); + SCR_DrawTurtle(); SCR_DrawPause(); |