Skip to content

Commit

Permalink
Update menu.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Elinsrc committed Apr 18, 2024
1 parent 081a245 commit d1776ec
Showing 1 changed file with 110 additions and 18 deletions.
128 changes: 110 additions & 18 deletions cl_dll/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,74 @@ int CHudMenu::VidInit( void )
return 1;
}

int CHudMenu::Draw( float flTime )
/*=================================
ParseEscapeToken
Interprets the given escape token (backslash followed by a letter). The
first character of the token must be a backslash. The second character
specifies the operation to perform:
\w : White text (this is the default)
\d : Dim (gray) text
\y : Yellow text
\r : Red text
\R : Right-align (just for the remainder of the current line)
=================================*/

static int menu_r, menu_g, menu_b, menu_x, menu_ralign;

static inline const char* ParseEscapeToken( const char* token )
{
int i;
if ( *token != '\\' )
return token;

token++;

switch ( *token )
{
case '\0':
return token;

case 'w':
menu_r = 255;
menu_g = 255;
menu_b = 255;
break;

case 'd':
menu_r = 100;
menu_g = 100;
menu_b = 100;
break;

case 'y':
menu_r = 255;
menu_g = 210;
menu_b = 64;
break;

case 'r':
menu_r = 210;
menu_g = 24;
menu_b = 0;
break;

case 'R':
menu_x = ScreenWidth/2;
menu_ralign = TRUE;
break;
}

return ++token;
}

int CHudMenu::Draw( float flTime )
{
// check for if menu is set to disappear
if( m_flShutoffTime > 0 )
if ( m_flShutoffTime > 0 )
{
if( m_flShutoffTime <= gHUD.m_flTime )
{
// times up, shutoff
if ( m_flShutoffTime <= gHUD.m_flTime )
{ // times up, shutoff
m_fMenuDisplayed = 0;
m_iFlags &= ~HUD_ACTIVE;
return 1;
Expand All @@ -88,28 +146,62 @@ int CHudMenu::Draw( float flTime )
#endif

// draw the menu, along the left-hand side of the screen

// count the number of newlines
int nlc = 0;
for( i = 0; i < MAX_MENU_STRING && g_szMenuString[i] != '\0'; i++ )
int i;
for ( i = 0; i < MAX_MENU_STRING && g_szMenuString[i] != '\0'; i++ )
{
if( g_szMenuString[i] == '\n' )
if ( g_szMenuString[i] == '\n' )
nlc++;
}

// center it
int y = ( ScreenHeight / 2 ) - ( ( nlc / 2 ) * 12 ) - 40; // make sure it is above the say text
int x = 20;
int y = (ScreenHeight/2) - ((nlc/2)*12) - 40; // make sure it is above the say text

i = 0;
while( i < MAX_MENU_STRING && g_szMenuString[i] != '\0' )
menu_r = 255;
menu_g = 255;
menu_b = 255;
menu_x = 20;
menu_ralign = FALSE;

const char* sptr = g_szMenuString;

while ( *sptr != '\0' )
{
gHUD.DrawHudString( x, y, 320, g_szMenuString + i, 255, 255, 255 );
y += 12;
if ( *sptr == '\\' )
{
sptr = ParseEscapeToken( sptr );
}
else if ( *sptr == '\n' )
{
menu_ralign = FALSE;
menu_x = 20;
y += (12);

sptr++;
}
else
{
char menubuf[ 80 ];
const char *ptr = sptr;
while ( *sptr != '\0' && *sptr != '\n' && *sptr != '\\')
{
sptr++;
}
strncpy( menubuf, ptr, Q_min( ( sptr - ptr), (int)sizeof( menubuf ) ));
menubuf[ Q_min( ( sptr - ptr), (int)(sizeof( menubuf )-1) ) ] = '\0';

while( i < MAX_MENU_STRING && g_szMenuString[i] != '\0' && g_szMenuString[i] != '\n' )
i++;
if( g_szMenuString[i] == '\n' )
i++;
if ( menu_ralign )
{
// IMPORTANT: Right-to-left rendered text does not parse escape tokens!
menu_x = gHUD.DrawHudStringReverse( menu_x, y, 0, menubuf, menu_r, menu_g, menu_b );
}
else
{
menu_x = gHUD.DrawHudString( menu_x, y, 320, menubuf, menu_r, menu_g, menu_b );
}
}
}

return 1;
Expand Down

0 comments on commit d1776ec

Please sign in to comment.