Skip to content

Commit

Permalink
Improved console timestamps, Added con_notifyname
Browse files Browse the repository at this point in the history
Setting con_notifyname to your name will highlight timestamps cyan if the name you set it to is mentioned to chat. If you have a short nickname like mine ("et"), you may want to set it to something like "@et" and tell every1 to say that if they want to contact you.
If con_notifyname is set, the icon will flash if minimized or the window will flash if unfocused. (Only supported on Windows for now)
Console now has proper indentation for all messages
Repeated timestamps are replaced with "::::::::"
Chat msgs have white timestamps instead of Grey
User inputted commands have green timestamps
Improved R_PrintLongString so that words aren't cut off
  • Loading branch information
eternalcodes committed Apr 5, 2016
1 parent b6865a9 commit 0f338f0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 18 deletions.
48 changes: 35 additions & 13 deletions codemp/client/cl_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cvar_t *con_conspeed;
cvar_t *con_notifytime;
cvar_t *con_opacity; // background alpha multiplier
cvar_t *con_autoclear;
cvar_t *con_notifyname;

#define DEFAULT_CONSOLE_WIDTH 78

Expand Down Expand Up @@ -507,6 +508,7 @@ void Con_Init (void) {

con_opacity = Cvar_Get ("con_opacity", "1.0", CVAR_ARCHIVE, "Opacity of console background");
con_autoclear = Cvar_Get ("con_autoclear", "1", CVAR_ARCHIVE, "Automatically clear console input on close");
con_notifyname = Cvar_Get("con_notifyname", "0", CVAR_ARCHIVE, "Notifies you when name is mentioned");

Field_Clear( &g_consoleField );
g_consoleField.widthInChars = g_console_field_width;
Expand Down Expand Up @@ -551,6 +553,7 @@ Con_Linefeed
static void Con_Linefeed (qboolean skipnotify)
{
int i;
char design[] = "::::::::";

// mark time for transparent overlay
if (con.current >= 0)
Expand All @@ -561,11 +564,14 @@ static void Con_Linefeed (qboolean skipnotify)
con.times[con.current % NUM_CON_TIMES] = cls.realtime;
}

con.x = 0;
con.x = 9;
if (con.display == con.current)
con.display++;
con.current++;
for(i=0; i<con.linewidth; i++)
for (i = 0; i < 9; i++) {
con.text[(con.current%con.totallines)*con.linewidth + i] = (ColorIndex(COLOR_GREY) << 8) | design[i];
}
for(i=9; i<con.linewidth; i++)
con.text[(con.current%con.totallines)*con.linewidth+i] = (ColorIndex(COLOR_WHITE)<<8) | ' ';
}

Expand All @@ -578,12 +584,15 @@ All console printing must go through this in order to be logged to disk
If no console is visible, the text will appear at the top of the game window
================
*/
static qtime_t lastTime;
void CL_ConsolePrint( const char *txt) {
int y;
int c, l;
int color;
int color, stampColor;
qboolean skipnotify = qfalse; // NERVE - SMF
int prev; // NERVE - SMF
char txtt[MAXPRINTMSG];
qtime_t now;

// TTimo - prefix for text that shows up in console but not in notify
// backported from RTCW
Expand All @@ -593,28 +602,41 @@ void CL_ConsolePrint( const char *txt) {
}
if ( txt[0] == '*' ) {
char *txtc;

skipnotify = qtrue;
txt += 1;

txtc = va("%s", txt);
Q_StripColor(txtc);
CL_LogPrintf(cls.log.chat, va("%s", txtc));
}

if (con.x == 0) {
char txtt[MAXPRINTMSG];
qtime_t now;
Com_RealTime(&now);
Com_sprintf(txtt, sizeof(txtt), "^9%02d:%02d:%02d ^7%s", now.tm_hour, now.tm_min, now.tm_sec, txt);
txt = va("%s", txtt);
if (con_notifyname->string != "0" && Q_stristr(Q_strrchr(txtc, ':'), con_notifyname->string)) {
stampColor = COLOR_CYAN;
#ifdef _WIN32
con_alert = qtrue;
#endif
}
else stampColor = COLOR_WHITE;
}
else if (txt[0] == ']') stampColor = COLOR_GREEN;
else stampColor = COLOR_GREY;
stampColor -= '0';

// for some demos we don't want to ever show anything on the console
if ( cl_noprint && cl_noprint->integer ) {
return;
}

Com_RealTime(&now);
if (lastTime.tm_hour != now.tm_hour || lastTime.tm_min != now.tm_min || lastTime.tm_sec != now.tm_sec) {
lastTime.tm_hour = now.tm_hour, lastTime.tm_min = now.tm_min, lastTime.tm_sec = now.tm_sec;
Com_sprintf(txtt, sizeof(txtt), "^%i%02d:%02d:%02d ^7%s", stampColor, now.tm_hour, now.tm_min, now.tm_sec, txt);
txt = va("%s", txtt);
}
else {
txt = va("^%i%s ^7%s", stampColor, "::::::::", txt);
}

if (!con.initialized) {
con.color[0] =
con.color[1] =
Expand Down Expand Up @@ -644,7 +666,6 @@ void CL_ConsolePrint( const char *txt) {
// word wrap
if (l != con.linewidth && (con.x + l >= con.linewidth) ) {
Con_Linefeed(skipnotify);

}

txt++;
Expand All @@ -655,7 +676,7 @@ void CL_ConsolePrint( const char *txt) {
Con_Linefeed (skipnotify);
break;
case '\r':
con.x = 0;
con.x = 9;
break;
default: // display character and advance
y = con.current % con.totallines;
Expand All @@ -668,6 +689,7 @@ void CL_ConsolePrint( const char *txt) {
}
}

con.x = 0;

// mark time for transparent overlay

Expand Down
3 changes: 3 additions & 0 deletions codemp/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,9 @@ void Con_SetFrac(const float conFrac);
void Con_Copy(void);
void Con_CopyLink(void);

#ifdef _WIN32
extern qboolean con_alert;
#endif

//
// cl_scrn.c
Expand Down
12 changes: 8 additions & 4 deletions codemp/rd-vanilla/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,16 +1350,20 @@ Workaround for ri->Printf's 1024 characters buffer limit.
*/
void R_PrintLongString(const char *string) {
char buffer[1024];
const char *p;
const char *p, *s;
int size = strlen(string);
int bufferSize;

p = string;
while(size > 0)
{
Q_strncpyz(buffer, p, sizeof (buffer) );
s = p + 1023;
while (*s > ' ') s--;
bufferSize = s - p;
Q_strncpyz(buffer, p, bufferSize);
ri->Printf( PRINT_ALL, "%s", buffer );
p += 1023;
size -= 1023;
p = s + 1;
size -= bufferSize;
}
}

Expand Down
9 changes: 9 additions & 0 deletions shared/sdl/sdl_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,12 @@ static void IN_ProcessEvents( void )

if( !SDL_WasInit( SDL_INIT_VIDEO ) )
return;
#ifdef _WIN32
if (com_unfocused->integer == 1 && con_alert == qtrue) {
GLimp_Alert();
con_alert = qfalse;
}
#endif

while( SDL_PollEvent( &e ) )
{
Expand Down Expand Up @@ -888,6 +894,9 @@ static void IN_ProcessEvents( void )
Cvar_SetValue( "com_unfocused", 1 );
SNDDMA_Activate( qfalse );
cl_unfocusedTime = cls.realtime;
#ifdef _WIN32
con_alert = qfalse;
#endif
break;
}

Expand Down
18 changes: 17 additions & 1 deletion shared/sdl/sdl_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ void GLimp_Minimize(void)
SDL_MinimizeWindow( screen );
}

#ifdef _WIN32
qboolean con_alert;
static FLASHWINFO fi;
void GLimp_Alert(void) {
FlashWindowEx(&fi);
}
#endif

void WIN_Present( window_t *window )
{
if ( window->api == GRAPHICS_API_OPENGL )
Expand Down Expand Up @@ -778,15 +786,23 @@ window_t WIN_Init( const windowDesc_t *windowDesc, glconfig_t *glConfig )

window.api = windowDesc->api;

#if defined(_WIN32)
#ifdef _WIN32
SDL_SysWMinfo info;
SDL_VERSION(&info.version);

con_alert = qfalse;

if ( SDL_GetWindowWMInfo(screen, &info) )
{
switch(info.subsystem) {
case SDL_SYSWM_WINDOWS:
window.handle = info.info.win.window;

fi.cbSize = sizeof(FLASHWINFO);
fi.hwnd = info.info.win.window;
fi.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
fi.uCount = 0;
fi.dwTimeout = 0;
break;

default:
Expand Down
3 changes: 3 additions & 0 deletions shared/sys/sys_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ qboolean Sys_GetPacket( netadr_t *net_from, msg_t *net_message );
char *Sys_ConsoleInput( void );
void Sys_QueEvent( int time, sysEventType_t type, int value, int value2, int ptrLength, void *ptr );
void Sys_SigHandler( int signal );
#ifdef _WIN32
extern void GLimp_Alert(void);
#endif
#ifndef _WIN32
void Sys_AnsiColorPrint( const char *msg );
#endif
Expand Down

0 comments on commit 0f338f0

Please sign in to comment.