Skip to content

Commit

Permalink
Separate subtitles prints, removed shadow, added subtitle size cvar
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfetplayer committed Jun 9, 2024
1 parent 43dd63c commit 178cbaf
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 13 deletions.
90 changes: 78 additions & 12 deletions code/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1810,29 +1810,29 @@ void CG_SubtitlePrint( const char *str, int y, int charWidth ) {
return;
}

// Copy the translated string to cg.centerPrint
Q_strncpyz(cg.centerPrint, translated, sizeof(cg.centerPrint));
// Copy the translated string to cg.subtitlePrint
Q_strncpyz(cg.subtitlePrint, translated, sizeof(cg.subtitlePrint));



cg.centerPrintY = y;
cg.centerPrintCharWidth = charWidth;
cg.subtitlePrintY = y;
cg.subtitlePrintCharWidth = charWidth;

// count the number of lines for centering
cg.centerPrintLines = 1;
s = cg.centerPrint;
cg.subtitlePrintLines = 1;
s = cg.subtitlePrint;
while ( *s ) {
if ( *s == '\n' ) {
cg.centerPrintLines++;
cg.subtitlePrintLines++;
}
if ( !Q_strncmp( s, "\\n", 1 ) ) {
cg.centerPrintLines++;
cg.subtitlePrintLines++;
s++;
}
s++;
}
// Calculate the number of characters in the message
len = CG_DrawStrlen(cg.centerPrint);
len = CG_DrawStrlen(cg.subtitlePrint);
// Calculate the display time based on an average reading speed of 17 characters per second
int displayTime = (len / 17.0) * 1000; // Convert to milliseconds

Expand All @@ -1843,7 +1843,7 @@ void CG_SubtitlePrint( const char *str, int y, int charWidth ) {
}

// Set the time at which the message should disappear
cg.centerPrintTime = cg.time + displayTime;
cg.subtitlePrintTime = cg.time + displayTime;
}

/*
Expand Down Expand Up @@ -1872,7 +1872,7 @@ static void CG_DrawCenterString( void ) {

trap_R_SetColor( color );

start = cg.centerPrint;
start = cg.subtitlePrint;

y = cg.centerPrintY - cg.centerPrintLines * BIGCHAR_HEIGHT / 2;

Expand Down Expand Up @@ -1911,6 +1911,71 @@ static void CG_DrawCenterString( void ) {
trap_R_SetColor( NULL );
}

/*
===================
CG_DrawSubtitleString
===================
*/
static void CG_DrawSubtitleString( void ) {
char *start;
int l;
int x, y, w;
float *color;

if ( !cg.subtitlePrintTime ) {
return;
}

color = CG_FadeColor( cg.subtitlePrintTime, 1000 * cg_centertime.value );
if ( !color ) {
return;
}

if ( cg_fixedAspect.integer ) {
CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);
}

trap_R_SetColor( color );

start = cg.subtitlePrint;

y = cg.subtitlePrintY - cg.subtitlePrintLines * BIGCHAR_HEIGHT / 2;

while ( 1 ) {
char linebuffer[1024];

for ( l = 0; l < 50; l++ ) {
if ( !start[l] || start[l] == '\n' || !Q_strncmp( &start[l], "\\n", 1 ) ) {
break;
}
linebuffer[l] = start[l];
}
linebuffer[l] = 0;

w = cg.subtitlePrintCharWidth * CG_DrawStrlen( linebuffer );

x = ( SCREEN_WIDTH - w ) / 2;

CG_DrawStringExt( x, y, linebuffer, color, qfalse, qfalse, cg.subtitlePrintCharWidth, (int)( cg.subtitlePrintCharWidth * 1.5 ), 0 );

y += cg.subtitlePrintCharWidth * 2;

while ( *start && ( *start != '\n' ) ) {
if ( !Q_strncmp( start, "\\n", 1 ) ) {
start++;
break;
}
start++;
}
if ( !*start ) {
break;
}
start++;
}

trap_R_SetColor( NULL );
}



/*
Expand Down Expand Up @@ -2953,6 +3018,7 @@ CG_DrawIntermission
static void CG_DrawIntermission( void ) {

CG_DrawCenterString();
CG_DrawSubtitleString();
return;

//cg.scoreFadeTime = cg.time;
Expand Down Expand Up @@ -3700,7 +3766,7 @@ if ( !cg_oldWolfUI.integer ) {
// don't draw center string if scoreboard is up
if ( !CG_DrawScoreboard() ) {
CG_DrawCenterString();

CG_DrawSubtitleString();
CG_DrawObjectiveInfo(); // NERVE - SMF
}

Expand Down
7 changes: 7 additions & 0 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,12 @@ typedef struct {
char centerPrint[1024];
int centerPrintLines;

int subtitlePrintTime;
int subtitlePrintCharWidth;
int subtitlePrintY;
char subtitlePrint[1024];
int subtitlePrintLines;

// fade in/out
int fadeTime;
float fadeRate;
Expand Down Expand Up @@ -1721,6 +1727,7 @@ extern vmCvar_t cg_crosshairHealth;
extern vmCvar_t cg_drawStatus;
extern vmCvar_t cg_draw2D;
extern vmCvar_t cg_drawSubtitles;
extern vmCvar_t cg_subtitleSize;
extern vmCvar_t cg_drawFrags;
extern vmCvar_t cg_animSpeed;
extern vmCvar_t cg_debugAnim;
Expand Down
2 changes: 2 additions & 0 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ vmCvar_t cg_crosshairY;
vmCvar_t cg_crosshairHealth;
vmCvar_t cg_draw2D;
vmCvar_t cg_drawSubtitles;
vmCvar_t cg_subtitleSize;
vmCvar_t cg_drawFrags;
vmCvar_t cg_teamChatsOnly;
vmCvar_t cg_drawStatus;
Expand Down Expand Up @@ -346,6 +347,7 @@ cvarTable_t cvarTable[] = {
{ &cg_gibs, "cg_gibs", "1", CVAR_ARCHIVE },
{ &cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE },
{ &cg_drawSubtitles, "cg_drawSubtitles", "0", CVAR_ARCHIVE},
{ &cg_subtitleSize, "cg_subtitleSize", "7", CVAR_ARCHIVE},
{ &cg_drawSpreadScale, "cg_drawSpreadScale", "1", CVAR_ARCHIVE },
{ &cg_drawFrags, "cg_drawFrags", "1", CVAR_ARCHIVE },
{ &cg_drawStatus, "cg_drawStatus", "1", CVAR_ARCHIVE },
Expand Down
1 change: 1 addition & 0 deletions code/cgame/cg_playerstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ void CG_Respawn( void ) {
cg.pmext.bAutoReload = ( cg_autoReload.integer > 0 ); // autoreload

cg.centerPrintTime = 0; //----(SA) reset centerprint counter so previous messages don't re-appear
cg.subtitlePrintTime = 0; //----(SA) reset centerprint counter so previous messages don't re-appear
cg.cursorHintIcon = 0;
cg.cursorHintTime = 0;
cg.yougotmailTime = 0;
Expand Down
3 changes: 2 additions & 1 deletion code/cgame/cg_servercmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ static void CG_MapRestart( void ) {
memset( &cg.lastWeapSelInBank[0], 0, MAX_WEAP_BANKS * sizeof( int ) ); // clear weapon bank selections

cg.centerPrintTime = 0; // reset centerprint counter so previous messages don't re-appear
cg.subtitlePrintTime = 0; // reset subtitleprint counter so previous messages don't re-appear
cg.itemPickupTime = 0; // reset item pickup counter so previous messages don't re-appear
cg.cursorHintFade = 0; // reset cursor hint timer
cg.yougotmailTime = 0; // reset
Expand Down Expand Up @@ -812,7 +813,7 @@ static void CG_ServerCommand( void ) {

if ( !strcmp( cmd, "cpst" )) { // dynamite print (what a hack :(
if (cg_drawSubtitles.value != 0) {
CG_SubtitlePrint( CG_Argv( 1 ), SCREEN_HEIGHT - ( SCREEN_HEIGHT * 0.25 ), 7 );
CG_SubtitlePrint( CG_Argv( 1 ), SCREEN_HEIGHT - ( SCREEN_HEIGHT * 0.25 ), cg_subtitleSize.integer );
}
return;
}
Expand Down

0 comments on commit 178cbaf

Please sign in to comment.