Upload CSpectatorGui basic code. Some reformat, refactor.

This commit is contained in:
a1batross 2016-03-16 20:44:51 +03:00
parent c02670e736
commit 4fbe104ea5
12 changed files with 439 additions and 159 deletions

View File

@ -25,7 +25,6 @@ from Valve. If you modify this file, you may extend this exception
to your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from your
version.
*/
#include "draw_util.h"
@ -35,23 +34,23 @@ version.
#include <string.h>
extern cvar_t *hud_textmode;
float DrawUtils :: color[3];
float DrawUtils::color[3];
int DrawUtils :: DrawHudString( int xpos, int ypos, int iMaxX, const char *str, int r, int g, int b, bool drawing )
int DrawUtils::DrawHudString( int xpos, int ypos, int iMaxX, const char *str, int r, int g, int b, bool drawing )
{
char *szIt = (char*)str;
char *szIt = (char *)str;
// draw the string until we hit the null character or a newline character
for ( ; *szIt != 0 && *szIt != '\n'; szIt++ )
{
int next = xpos + gHUD.m_scrinfo.charWidths[ (unsigned char)*szIt ]; // variable-width fonts look cool
int next = xpos + gHUD.GetCharWidth((unsigned char)*szIt); // variable-width fonts look cool
if ( next > iMaxX )
return xpos;
if( *szIt == '\\' && *(szIt+1) != '\n' && *(szIt+1) != 0)
if ( *szIt == '\\' && *( szIt + 1 ) != '\n' && *( szIt + 1 ) != 0 )
{
// an escape character
switch( *(++szIt) )
switch ( *( ++szIt ) )
{
case 'y':
UnpackRGB( r, g, b, RGB_YELLOWISH );
@ -64,7 +63,7 @@ int DrawUtils :: DrawHudString( int xpos, int ypos, int iMaxX, const char *str,
case 'R':
//if( drawing ) return xpos;
//return DrawHudStringReverse( iMaxX, ypos, first_xpos, szIt, r, g, b, true ); // set 'drawing' to true, to stop when '\R' is catched
xpos = iMaxX - gHUD.m_scrinfo.charWidths[ 'M' ] * 10;
xpos = iMaxX - gHUD.GetCharWidth('M') * 10;
++szIt;
}
}
@ -75,40 +74,39 @@ int DrawUtils :: DrawHudString( int xpos, int ypos, int iMaxX, const char *str,
return xpos;
}
int DrawUtils :: HudStringLen( char *szIt )
int DrawUtils::HudStringLen( char *szIt )
{
int l = 0;
// draw the string until we hit the null character or a newline character
// draw the string until we hit the null character or a newline character
for ( ; *szIt != 0 && *szIt != '\n'; szIt++ )
{
l += gHUD.m_scrinfo.charWidths[ (unsigned char)*szIt ]; // variable-width fonts look cool
l += gHUD.m_scrinfo.charWidths[(unsigned char)*szIt]; // variable-width fonts look cool
}
return l;
}
int DrawUtils :: DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int r, int g, int b )
int DrawUtils::DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int r, int g, int b )
{
char szString[32];
snprintf( szString, 32, "%d", iNumber );
return DrawHudStringReverse( xpos, ypos, iMinX, szString, r, g, b );
}
int DrawUtils :: DrawHudStringReverse( int xpos, int ypos, int iMinX, const char *szString, int r, int g, int b, bool drawing )
int DrawUtils::DrawHudStringReverse( int xpos, int ypos, int iMinX, const char *szString, int r, int g, int b, bool drawing )
{
// iterate throug the string in reverse
for ( signed int i = strlen(szString); i >= 0; i-- )
for ( signed int i = strlen( szString ); i >= 0; i-- )
{
int next = xpos - gHUD.m_scrinfo.charWidths[ (unsigned char)szString[i] ]; // variable-width fonts look cool
int next = xpos - gHUD.GetCharWidth((unsigned char)szString[i]); // variable-width fonts look cool
if ( next < iMinX )
return xpos;
xpos = next;
if( i > 1 && szString[i - 1] == '\\' )
if ( i > 1 && szString[i - 1] == '\\' )
{
// an escape character
switch( szString[i] )
switch ( szString[i] )
{
case 'y':
UnpackRGB( r, g, b, RGB_YELLOWISH );
@ -117,9 +115,9 @@ int DrawUtils :: DrawHudStringReverse( int xpos, int ypos, int iMinX, const char
r = g = b = 255;
break;
case 'R':
//if( drawing ) return xpos;
//else return DrawHudString( iMinX, ypos, first_xpos, &szString[i - 1], r, g, b, true ); // set 'drawing' to true, to stop when '\R' is catched
//xpos = iMinX + gHUD.m_scrinfo.charWidths['M'] * i ;
//if( drawing ) return xpos;
//else return DrawHudString( iMinX, ypos, first_xpos, &szString[i - 1], r, g, b, true ); // set 'drawing' to true, to stop when '\R' is catched
//xpos = iMinX + gHUD.m_scrinfo.charWidths['M'] * i ;
case 'd':
break;
}
@ -132,36 +130,36 @@ int DrawUtils :: DrawHudStringReverse( int xpos, int ypos, int iMinX, const char
return xpos;
}
int DrawUtils :: DrawHudNumber( int x, int y, int iFlags, int iNumber, int r, int g, int b)
int DrawUtils::DrawHudNumber( int x, int y, int iFlags, int iNumber, int r, int g, int b )
{
int iWidth = gHUD.GetSpriteRect(gHUD.m_HUD_number_0).right - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).left;
int iWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left;
int k;
if (iNumber > 0)
if ( iNumber > 0 )
{
// SPR_Draw 100's
if (iNumber >= 100)
if ( iNumber >= 100 )
{
k = iNumber/100;
SPR_Set(gHUD.GetSprite(gHUD.m_HUD_number_0 + k), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect(gHUD.m_HUD_number_0 + k));
k = iNumber / 100;
SPR_Set( gHUD.GetSprite( gHUD.m_HUD_number_0 + k ), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( gHUD.m_HUD_number_0 + k ) );
x += iWidth;
}
else if (iFlags & (DHN_3DIGITS))
else if ( iFlags & ( DHN_3DIGITS ) )
{
//SPR_DrawAdditive( 0, x, y, &rc );
x += iWidth;
}
// SPR_Draw 10's
if (iNumber >= 10)
if ( iNumber >= 10 )
{
k = (iNumber % 100)/10;
SPR_Set(gHUD.GetSprite(gHUD.m_HUD_number_0 + k), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect(gHUD.m_HUD_number_0 + k));
k = ( iNumber % 100 ) / 10;
SPR_Set( gHUD.GetSprite( gHUD.m_HUD_number_0 + k ), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( gHUD.m_HUD_number_0 + k ) );
x += iWidth;
}
else if (iFlags & (DHN_3DIGITS | DHN_2DIGITS))
else if ( iFlags & ( DHN_3DIGITS | DHN_2DIGITS ) )
{
//SPR_DrawAdditive( 0, x, y, &rc );
x += iWidth;
@ -169,22 +167,22 @@ int DrawUtils :: DrawHudNumber( int x, int y, int iFlags, int iNumber, int r, in
// SPR_Draw ones
k = iNumber % 10;
SPR_Set(gHUD.GetSprite(gHUD.m_HUD_number_0 + k), r, g, b );
SPR_DrawAdditive(0, x, y, &gHUD.GetSpriteRect(gHUD.m_HUD_number_0 + k));
SPR_Set( gHUD.GetSprite( gHUD.m_HUD_number_0 + k ), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( gHUD.m_HUD_number_0 + k ) );
x += iWidth;
}
else if (iFlags & DHN_DRAWZERO)
else if ( iFlags & DHN_DRAWZERO )
{
SPR_Set(gHUD.GetSprite(gHUD.m_HUD_number_0), r, g, b );
SPR_Set( gHUD.GetSprite( gHUD.m_HUD_number_0 ), r, g, b );
// SPR_Draw 100's
if (iFlags & (DHN_3DIGITS))
if ( iFlags & ( DHN_3DIGITS ) )
{
//SPR_DrawAdditive( 0, x, y, &rc );
x += iWidth;
}
if (iFlags & (DHN_3DIGITS | DHN_2DIGITS))
if ( iFlags & ( DHN_3DIGITS | DHN_2DIGITS ) )
{
//SPR_DrawAdditive( 0, x, y, &rc );
x += iWidth;
@ -192,53 +190,52 @@ int DrawUtils :: DrawHudNumber( int x, int y, int iFlags, int iNumber, int r, in
// SPR_Draw ones
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect(gHUD.m_HUD_number_0));
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ) );
x += iWidth;
}
return x;
}
int DrawUtils :: GetNumWidth( int iNumber, int iFlags )
int DrawUtils::GetNumWidth( int iNumber, int iFlags )
{
if (iFlags & (DHN_3DIGITS))
if ( iFlags & ( DHN_3DIGITS ) )
return 3;
if (iFlags & (DHN_2DIGITS))
if ( iFlags & ( DHN_2DIGITS ) )
return 2;
if (iNumber <= 0)
if ( iNumber <= 0 )
{
if (iFlags & (DHN_DRAWZERO))
if ( iFlags & ( DHN_DRAWZERO ) )
return 1;
else
return 0;
}
if (iNumber < 10)
if ( iNumber < 10 )
return 1;
if (iNumber < 100)
if ( iNumber < 100 )
return 2;
return 3;
}
void DrawUtils :: DrawRectangle(int x, int y, int wide, int tall , int r, int g, int b, int a, bool drawStroke)
void DrawUtils::DrawRectangle( int x, int y, int wide, int tall, int r, int g, int b, int a, bool drawStroke )
{
FillRGBABlend(x, y, wide, tall, r, g, b, a);
if(drawStroke)
FillRGBABlend( x, y, wide, tall, r, g, b, a );
if ( drawStroke )
{
// TODO: remove this hardcoded hardcore
FillRGBA( x+1, y, wide-1, 1, 255, 140, 0, 255 );
FillRGBA( x, y, 1, tall-1, 255, 140, 0, 255 );
FillRGBA( x+wide-1, y+1, 1, tall-1, 255, 140, 0, 255 );
FillRGBA( x, y+tall-1, wide-1, 1, 255, 140, 0, 255 );
FillRGBA( x + 1, y, wide - 1, 1, 255, 140, 0, 255 );
FillRGBA( x, y, 1, tall - 1, 255, 140, 0, 255 );
FillRGBA( x + wide - 1, y + 1, 1, tall - 1, 255, 140, 0, 255 );
FillRGBA( x, y + tall - 1, wide - 1, 1, 255, 140, 0, 255 );
}
}
int DrawUtils :: DrawHudNumber2( int x, int y, bool DrawZero, int iDigits, int iNumber, int r, int g, int b)
int DrawUtils::DrawHudNumber2( int x, int y, bool DrawZero, int iDigits, int iNumber, int r, int g, int b )
{
int iWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left;
x += ( iDigits - 1 ) * iWidth;
@ -252,24 +249,22 @@ int DrawUtils :: DrawHudNumber2( int x, int y, bool DrawZero, int iDigits, int i
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( gHUD.m_HUD_number_0 + k ) );
x -= iWidth;
iDigits--;
}
while( iNumber > 0 || ( iDigits > 0 && DrawZero ) );
} while ( iNumber > 0 || ( iDigits > 0 && DrawZero ) );
return ResX;
}
int DrawUtils :: DrawHudNumber2( int x, int y, int iNumber, int r, int g, int b)
int DrawUtils::DrawHudNumber2( int x, int y, int iNumber, int r, int g, int b )
{
int iWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left;
int iDigits = 0;
int temp = iNumber;
int temp = iNumber;
do
{
iDigits++;
temp /= 10;
}
while( temp > 0 );
} while ( temp > 0 );
x += ( iDigits - 1 ) * iWidth;
@ -281,55 +276,53 @@ int DrawUtils :: DrawHudNumber2( int x, int y, int iNumber, int r, int g, int b)
SPR_Set( gHUD.GetSprite( gHUD.m_HUD_number_0 + k ), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( gHUD.m_HUD_number_0 + k ) );
x -= iWidth;
}
while( iNumber > 0 );
} while ( iNumber > 0 );
return ResX;
}
int DrawUtils :: DrawConsoleString( int x, int y, const char *string )
int DrawUtils::DrawConsoleString( int x, int y, const char *string )
{
if( hud_textmode->value )
if ( hud_textmode->value )
{
int ret = DrawHudString( x, y, 9999, (char*)string, color[0] * 255, color[1] * 255, color[2] * 255);
int ret = DrawHudString( x, y, 9999, (char *)string, color[0] * 255, color[1] * 255, color[2] * 255 );
color[0] = color[1] = color[2] = 1.0f;
return ret;
}
else
return gEngfuncs.pfnDrawConsoleString( x, y, (char*) string );
return gEngfuncs.pfnDrawConsoleString( x, y, (char *)string );
}
void DrawUtils :: SetConsoleTextColor(float r, float g, float b)
void DrawUtils::SetConsoleTextColor( float r, float g, float b )
{
if( hud_textmode->value )
if ( hud_textmode->value )
color[0] = r, color[1] = g, color[2] = b;
else
gEngfuncs.pfnDrawSetTextColor( r, g, b );
}
void DrawUtils :: SetConsoleTextColor(unsigned char r, unsigned char g, unsigned char b)
void DrawUtils::SetConsoleTextColor( unsigned char r, unsigned char g, unsigned char b )
{
if( hud_textmode->value )
color[0] = r / 255.0f, color[1] = g / 255.0f, color[2] = b / 255.0f ;
if ( hud_textmode->value )
color[0] = r / 255.0f, color[1] = g / 255.0f, color[2] = b / 255.0f;
else
gEngfuncs.pfnDrawSetTextColor( r / 255.0f, g / 255.0f, b / 255.0f );
}
void DrawUtils :: ConsoleStringSize( const char *string, int *width, int *height )
void DrawUtils::ConsoleStringSize( const char *string, int *width, int *height )
{
if( hud_textmode->value )
*height = 13, *width = HudStringLen((char*)string);
if ( hud_textmode->value )
*height = 13, *width = HudStringLen( (char *)string );
else
gEngfuncs.pfnDrawConsoleStringLen( string, width, height );
}
int DrawUtils :: ConsoleStringLen( const char *string )
int DrawUtils::ConsoleStringLen( const char *string )
{
int _width, _height;
if( hud_textmode->value )
if ( hud_textmode->value )
{
return HudStringLen((char*)string);
return HudStringLen( (char *)string );
}
else
{
@ -338,7 +331,26 @@ int DrawUtils :: ConsoleStringLen( const char *string )
}
}
int DrawUtils :: TextMessageDrawChar(int x, int y, int number, int r, int g, int b)
int DrawUtils::TextMessageDrawChar( int x, int y, int number, int r, int g, int b )
{
return gEngfuncs.pfnDrawCharacter( x, y, number, r, g, b );
}
void DrawUtils::Draw2DQuad( float x1, float y1, float x2, float y2 )
{
gEngfuncs.pTriAPI->Begin( TRI_QUADS );
gEngfuncs.pTriAPI->TexCoord2f( 0, 0 );
gEngfuncs.pTriAPI->Vertex3f( x1, y1, 0 );
gEngfuncs.pTriAPI->TexCoord2f( 0, 1 );
gEngfuncs.pTriAPI->Vertex3f( x1, y2, 0 );
gEngfuncs.pTriAPI->TexCoord2f( 1, 1 );
gEngfuncs.pTriAPI->Vertex3f( x2, y2, 0 );
gEngfuncs.pTriAPI->TexCoord2f( 1, 0 );
gEngfuncs.pTriAPI->Vertex3f( x2, y1, 0 );
gEngfuncs.pTriAPI->End( );
}

View File

@ -77,9 +77,9 @@ int CHudMOTD :: Draw( float fTime )
// find the top of where the MOTD should be drawn, so the whole thing is centered in the screen
int ypos = (ScreenHeight - LINE_HEIGHT * m_iLines)/2; // shift it up slightly
char *ch = m_szMOTD;
int xpos = (ScreenWidth - gHUD.m_scrinfo.charWidths[ 'M' ] * m_iMaxLength) / 2;
int xpos = (ScreenWidth - gHUD.GetCharWidth( 'M' ) * m_iMaxLength) / 2;
if( xpos < 30 ) xpos = 30;
int xmax = xpos + gHUD.m_scrinfo.charWidths[ 'M' ] * m_iMaxLength;
int xmax = xpos + gHUD.GetCharWidth( 'M' ) * m_iMaxLength;
int height = LINE_HEIGHT * m_iLines;
int ypos_r=ypos;
if( height > ROW_RANGE_MAX )
@ -99,7 +99,7 @@ int CHudMOTD :: Draw( float fTime )
{
int line_length = 0; // count the length of the current line
for ( next_line = ch; *next_line != '\n' && *next_line != 0; next_line++ )
line_length += gHUD.m_scrinfo.charWidths[ (unsigned char)*next_line ];
line_length += gHUD.GetCharWidth( (unsigned char)*next_line );
char *top = next_line;
if ( *top == '\n' )
*top = 0;

View File

@ -95,7 +95,14 @@ int CHudDeathNotice :: Draw( float flTime )
//if ( !gHUD.m_iNoConsolePrint )
{
// Draw the death notice
y = YRES(DEATHNOTICE_TOP) + 2 + (20 * i); //!!!
if( !g_iUser1 )
{
y = YRES(DEATHNOTICE_TOP) + 2 + (20 * i); //!!!
}
else
{
y = ScreenHeight / 7 + 2 + (20 * i);
}
int id = (rgDeathNoticeList[i].iId == -1) ? m_HUD_d_skull : rgDeathNoticeList[i].iId;
x = ScreenWidth - DrawUtils::ConsoleStringLen(rgDeathNoticeList[i].szVictim) - (gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left);

View File

@ -153,6 +153,7 @@ void CHud :: Init( void )
// fullscreen overlays
m_SniperScope.Init();
m_NVG.Init();
m_SpectatorGui.Init();
// Game HUD things
m_Ammo.Init();
@ -360,6 +361,7 @@ void CHud :: VidInit( void )
m_ProgressBar.VidInit();
m_SniperScope.VidInit();
m_Radar.VidInit();
m_SpectatorGui.VidInit();
}
int CHud::MsgFunc_Logo(const char *pszName, int iSize, void *pbuf)

View File

@ -152,8 +152,10 @@ int CHud::MsgFunc_BombDrop(const char *pszName, int iSize, void *pbuf)
g_PlayerExtraInfo[33].playerclass = Flag;
if( Flag ) // bomb planted
{
m_SpectatorGui.m_bBombPlanted = 0;
m_Timer.m_iFlags = 0;
}
return 1;
}

View File

@ -198,7 +198,7 @@ void CHudMessage::MessageScanNextChar( void )
if ( m_parms.pMessage->effect == 1 && m_parms.charTime != 0 )
{
if ( m_parms.x >= 0 && m_parms.y >= 0 && (m_parms.x + gHUD.m_scrinfo.charWidths[ m_parms.text ]) <= ScreenWidth )
if ( m_parms.x >= 0 && m_parms.y >= 0 && (m_parms.x + gHUD.GetCharWidth( m_parms.text )) <= ScreenWidth )
DrawUtils::TextMessageDrawChar( m_parms.x, m_parms.y, m_parms.text, m_parms.pMessage->r2, m_parms.pMessage->g2, m_parms.pMessage->b2 );
}
}
@ -269,12 +269,12 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time )
width = 0;
}
else
width += gHUD.m_scrinfo.charWidths[(unsigned char)*pText];
width += gHUD.GetCharWidth((unsigned char)*pText);
pText++;
length++;
}
m_parms.length = length;
m_parms.totalHeight = (m_parms.lines * gHUD.m_scrinfo.iCharHeight);
m_parms.totalHeight = (m_parms.lines * gHUD.GetCharHeight());
m_parms.y = YPosition( pMessage->y, m_parms.totalHeight );
@ -292,7 +292,7 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time )
{
unsigned char c = *pText;
line[m_parms.lineLength] = c;
m_parms.width += gHUD.m_scrinfo.charWidths[c];
m_parms.width += gHUD.GetCharWidth(c);
m_parms.lineLength++;
pText++;
}
@ -304,7 +304,7 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time )
for ( j = 0; j < m_parms.lineLength; j++ )
{
m_parms.text = line[j];
int next = m_parms.x + gHUD.m_scrinfo.charWidths[ m_parms.text ];
int next = m_parms.x + gHUD.GetCharWidth( m_parms.text );
MessageScanNextChar();
if ( m_parms.x >= 0 && m_parms.y >= 0 && next <= ScreenWidth )
@ -312,7 +312,7 @@ void CHudMessage::MessageDrawScan( client_textmessage_t *pMessage, float time )
m_parms.x = next;
}
m_parms.y += gHUD.m_scrinfo.iCharHeight;
m_parms.y += gHUD.GetCharHeight();
}
}

View File

@ -293,27 +293,22 @@ int CHudScoreboard :: DrawTeams( float list_slot )
int r, g, b;
char teamName[64];
if( !stricmp(team_info->name, "TERRORIST"))
GetTeamColor( r, g, b, team_info->teamnumber );
switch( team_info->teamnumber )
{
GetTeamColor( r, g, b, TEAM_TERRORIST );
case TEAM_TERRORIST:
snprintf(teamName, sizeof(teamName), "Terrorists - %i players", team_info->players);
DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), team_info->frags, r, g, b );
}
else if( !stricmp( team_info->name, "CT") )
{
GetTeamColor( r, g, b, TEAM_CT );
break;
case TEAM_CT:
snprintf(teamName, sizeof(teamName), "Counter-Terrorists - %i players", team_info->players);
DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), team_info->frags, r, g, b );
}
else if( !stricmp( team_info->name, "SPECTATOR" ) )
{
GetTeamColor( r, g, b, TEAM_SPECTATOR );
break;
case TEAM_SPECTATOR:
case TEAM_UNASSIGNED:
strncpy( teamName, "Spectators", sizeof(teamName) );
}
else
{
GetTeamColor( r, g, b, TEAM_UNASSIGNED );
strncpy( teamName, team_info->name, sizeof(teamName) );
break;
}
DrawUtils::DrawHudString( NAME_POS_START(), ypos, NAME_POS_END(), teamName, r, g, b );
@ -376,14 +371,12 @@ int CHudScoreboard :: DrawPlayers( float list_slot, int nameoffset, const char *
if ( ypos > yend ) // don't draw to close to the lower border
break;
int r, g, b;
r = g = b = 255;
int r = 255, g = 255, b = 255;
float *colors = GetClientColor( best_player );
r *= colors[0];
g *= colors[1];
b *= colors[2];
if(pl_info->thisplayer) // hey, it's me!
{
FillRGBABlend( xstart, ypos, xend - xstart, ROW_GAP, 255, 255, 255, 15 );
@ -394,11 +387,11 @@ int CHudScoreboard :: DrawPlayers( float list_slot, int nameoffset, const char *
// draw bomb( if player have the bomb )
if( g_PlayerExtraInfo[best_player].dead )
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "Dead", r, g, b );
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "Dead", r, g, b );
else if( g_PlayerExtraInfo[best_player].has_c4 )
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "Bomb", r, g, b );
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "Bomb", r, g, b );
else if( g_PlayerExtraInfo[best_player].vip )
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "VIP", r, g, b );
DrawUtils::DrawHudString( ATTRIB_POS_START(), ypos, ATTRIB_POS_END(), "VIP", r, g, b );
// draw kills (right to left)
DrawUtils::DrawHudNumberString( KILLS_POS_END(), ypos, KILLS_POS_START(), g_PlayerExtraInfo[best_player].frags, r, g, b );
@ -464,16 +457,28 @@ int CHudScoreboard :: MsgFunc_TeamInfo( const char *pszName, int iSize, void *pb
{
BEGIN_READ( pbuf, iSize );
short cl = READ_BYTE();
int teamNumber = 0;
if ( cl > 0 && cl <= MAX_PLAYERS )
{ // set the players team
{
// set the players team
char teamName[MAX_TEAM_NAME];
strncpy( teamName, READ_STRING(), MAX_TEAM_NAME );
if( !strcmp(teamName, "UNASSIGNED") )
if( !stricmp( teamName, "TERRORIST") )
teamNumber = TEAM_TERRORIST;
else if( !stricmp( teamName, "CT") )
teamNumber = TEAM_CT;
else if( !stricmp( teamName, "SPECTATOR" ) || !stricmp( teamName, "UNASSIGNED" ) )
{
teamNumber = TEAM_SPECTATOR;
strncpy( teamName, "SPECTATOR", MAX_TEAM_NAME );
}
// just in case
else teamNumber = TEAM_UNASSIGNED;
strncpy( g_PlayerExtraInfo[cl].teamname, teamName, MAX_TEAM_NAME );
g_PlayerExtraInfo[cl].teamnumber = teamNumber;
}
// rebuild the list of teams
@ -520,6 +525,7 @@ int CHudScoreboard :: MsgFunc_TeamInfo( const char *pszName, int iSize, void *pb
m_iNumTeams = max( j, m_iNumTeams );
strncpy( g_TeamInfo[j].name, g_PlayerExtraInfo[i].teamname, MAX_TEAM_NAME );
g_TeamInfo[j].teamnumber = g_PlayerExtraInfo[i].teamnumber;
g_TeamInfo[j].players = 0;
}

View File

@ -1,6 +1,31 @@
/*
hud_overlays.cpp - HUD Overlays
Copyright (C) 2015 a1batross
Copyright (C) 2015-2016 a1batross
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
In addition, as a special exception, the author gives permission to
link the code of this program with the Half-Life Game Engine ("HL
Engine") and Modified Game Libraries ("MODs") developed by Valve,
L.L.C ("Valve"). You must obey the GNU General Public License in all
respects for all of the code used other than the HL Engine and MODs
from Valve. If you modify this file, you may extend this exception
to your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from your
version.
*/
#include "hud.h"
@ -8,21 +33,6 @@ Copyright (C) 2015 a1batross
#include "r_efx.h"
#include "cl_util.h"
void Quad(float x1, float y1, float x2, float y2)
{
gEngfuncs.pTriAPI->TexCoord2f(0,0);
gEngfuncs.pTriAPI->Vertex3f(x1, y1, 0);
gEngfuncs.pTriAPI->TexCoord2f(0,1);
gEngfuncs.pTriAPI->Vertex3f(x1, y2, 0);
gEngfuncs.pTriAPI->TexCoord2f(1,1);
gEngfuncs.pTriAPI->Vertex3f(x2, y2, 0);
gEngfuncs.pTriAPI->TexCoord2f(1,0);
gEngfuncs.pTriAPI->Vertex3f(x2, y1, 0);
}
int CHudSniperScope::Init()
{
@ -43,7 +53,6 @@ int CHudSniperScope::VidInit()
m_iScopeArc[1] = gRenderAPI.GL_LoadTexture("sprites/scope_arc_ne.tga", NULL, 0, TF_NEAREST |TF_NOPICMIP|TF_NOMIPMAP|TF_CLAMP);
m_iScopeArc[2] = gRenderAPI.GL_LoadTexture("sprites/scope_arc.tga", NULL, 0, TF_NEAREST |TF_NOPICMIP|TF_NOMIPMAP|TF_CLAMP);
m_iScopeArc[3] = gRenderAPI.GL_LoadTexture("sprites/scope_arc_sw.tga", NULL, 0, TF_NEAREST |TF_NOPICMIP|TF_NOMIPMAP|TF_CLAMP);
blackTex = gRenderAPI.GL_FindTexture("*black");
left = (TrueWidth - TrueHeight)/2;
right = left + TrueHeight;
centerx = TrueWidth/2;
@ -61,33 +70,19 @@ int CHudSniperScope::Draw(float flTime)
gEngfuncs.pTriAPI->CullFace(TRI_NONE);
gRenderAPI.GL_Bind(0, m_iScopeArc[0]);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
Quad(left, 0, centerx, centery);
gEngfuncs.pTriAPI->End();
DrawUtils::Draw2DQuad(left, 0, centerx, centery);
gRenderAPI.GL_Bind(0, m_iScopeArc[1]);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
Quad(centerx, 0, right, centery);
gEngfuncs.pTriAPI->End();
DrawUtils::Draw2DQuad(centerx, 0, right, centery);
gRenderAPI.GL_Bind(0, m_iScopeArc[2]);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
Quad(centerx, centery, right, TrueHeight);
gEngfuncs.pTriAPI->End();
DrawUtils::Draw2DQuad(centerx, centery, right, TrueHeight);
gRenderAPI.GL_Bind(0, m_iScopeArc[3]);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
Quad(left, centery, centerx, TrueHeight);
gEngfuncs.pTriAPI->End();
DrawUtils::Draw2DQuad(left, centery, centerx, TrueHeight);
gRenderAPI.GL_Bind(0, blackTex);
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
Quad(0, 0, left + 1.0f / TrueWidth, TrueHeight);
gEngfuncs.pTriAPI->End();
gEngfuncs.pTriAPI->Begin(TRI_QUADS);
Quad(right - 1.0f / TrueWidth, 0, TrueWidth, TrueHeight);
gEngfuncs.pTriAPI->End();
FillRGBABlend( 0, 0, (ScreenWidth - ScreenHeight) / 2 + 2, ScreenHeight, 0, 0, 0, 255 );
FillRGBABlend( (ScreenWidth - ScreenHeight) / 2 - 2 + ScreenHeight, 0, (ScreenWidth - ScreenHeight) / 2 + 2, ScreenHeight, 0, 0, 0, 255 );
FillRGBABlend(0, ScreenHeight/2, ScreenWidth/2 - 20, 1, 0, 0, 0, 255);
FillRGBABlend(ScreenWidth/2 + 20, ScreenHeight/2, ScreenWidth , 1, 0, 0, 0, 255);

View File

@ -1,4 +1,209 @@
/*
spectator_gui.cpp - HUD Overlays
Copyright (C) 2015 a1batross
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
In addition, as a special exception, the author gives permission to
link the code of this program with the Half-Life Game Engine ("HL
Engine") and Modified Game Libraries ("MODs") developed by Valve,
L.L.C ("Valve"). You must obey the GNU General Public License in all
respects for all of the code used other than the HL Engine and MODs
from Valve. If you modify this file, you may extend this exception
to your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from your
version.
*/
#include <string.h>
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#define DIVIDER_XPOS (ScreenWidth * 0.85)
#define DIVIDER_GAP (15)
#define BAR_HEIGHT (ScreenHeight / 7)
DECLARE_MESSAGE( m_SpectatorGui, SpecHealth );
DECLARE_MESSAGE( m_SpectatorGui, SpecHealth2 );
int CHudSpectatorGui::Init()
{
HOOK_MESSAGE( SpecHealth );
HOOK_MESSAGE( SpecHealth2 );
gHUD.AddHudElem(this);
m_iFlags = HUD_ACTIVE;
return 1;
}
int CHudSpectatorGui::VidInit()
{
if( g_iXash )
{
m_hTimerTexture = gRenderAPI.GL_LoadTexture("gfx/vgui/timer.tga", NULL, 0, TF_NEAREST |TF_NOPICMIP|TF_NOMIPMAP|TF_CLAMP );
}
else
{
m_hTimerTexture = 0;
}
return 1;
}
int CHudSpectatorGui::Draw( float flTime )
{
if( !g_iUser1 )
return 1;
// check for scoreboard. We will don't draw it, because screen space econodmy
if( gHUD.m_Scoreboard.m_bForceDraw || !(!gHUD.m_Scoreboard.m_bShowscoresHeld && gHUD.m_Health.m_iHealth > 0 && !gHUD.m_iIntermission ))
return 1;
int r, g, b;
r = 255; g = 140; b = 0;
// at first, draw these silly black bars
DrawUtils::DrawRectangle(0, 0, ScreenWidth, BAR_HEIGHT, 0, 0, 0, 153, false);
DrawUtils::DrawRectangle(0, BAR_HEIGHT * 6, ScreenWidth, BAR_HEIGHT, 0, 0, 0, 153, false);
// divider
FillRGBABlend( ScreenWidth * 0.85, BAR_HEIGHT * 0.25, 1, BAR_HEIGHT * 0.5, r, g, b, 255 );
// function name says it
CalcAllNeededData( );
// draw counter-terrorist and terrorist remaining and time3
DrawUtils::DrawHudString( DIVIDER_XPOS + DIVIDER_GAP, BAR_HEIGHT * 0.25, ScreenWidth, label.m_szMap, r, g, b );
if( m_hTimerTexture )
{
gRenderAPI.GL_Bind( 0, m_hTimerTexture );
DrawUtils::Draw2DQuad( TrueWidth * 0.85 + DIVIDER_GAP, TrueHeight / 14,
TrueWidth * 0.85 + DIVIDER_GAP + gHUD.GetCharHeight(), TrueHeight / 14 + gHUD.GetCharHeight() );
}
DrawUtils::DrawHudString( DIVIDER_XPOS + DIVIDER_GAP * 2 + gHUD.GetCharWidth('M'), BAR_HEIGHT * 0.5, ScreenWidth, label.m_szTimer, r, g, b);
// CTs, Ts labels
DrawUtils::DrawHudString( ScreenWidth * 0.7, BAR_HEIGHT * 0.25, ScreenWidth * 0.8, "Counter-Terrorists:", r, g, b );
DrawUtils::DrawHudString( ScreenWidth * 0.7, BAR_HEIGHT * 0.5, ScreenWidth * 0.8, "Terrorists:", r, g, b );
// CTs, Ts count
DrawUtils::DrawHudNumberString( DIVIDER_XPOS - DIVIDER_GAP, BAR_HEIGHT * 0.25, ScreenWidth * 0.8, label.m_iCounterTerrorists, r, g, b );
DrawUtils::DrawHudNumberString( DIVIDER_XPOS - DIVIDER_GAP, BAR_HEIGHT * 0.5, ScreenWidth * 0.8, label.m_iTerrorists, r, g, b );
if( g_iUser2 > 0 && g_iUser2 < MAX_PLAYERS )
{
cl_entity_t *pEnt = gEngfuncs.GetEntityByIndex( g_iUser2 );
if( pEnt && pEnt->player )
{
hud_player_info_t *pInfo = g_PlayerInfoList + pEnt->index;
GetPlayerInfo( pEnt->index, pInfo );
if( pInfo->name )
{
char szNameAndHealth[64];
snprintf( szNameAndHealth, 64, "%s (%i)", pInfo->name, g_PlayerExtraInfo[pEnt->index].health );
int iLen = DrawUtils::HudStringLen( szNameAndHealth );
GetTeamColor( r, g, b, g_PlayerExtraInfo[ pEnt->index ].teamnumber );
DrawUtils::DrawHudString( ScreenWidth * 0.5 - iLen * 0.5, BAR_HEIGHT * 13 / 2, ScreenWidth, szNameAndHealth, r, g, b );
}
}
}
return 1;
}
void CHudSpectatorGui::CalcAllNeededData( )
{
// mapname
static char szMapNameStripped[55];
const char *szMapName = gEngfuncs.pfnGetLevelName(); // "maps/%s.bsp"
strncpy( szMapNameStripped, szMapName + 5, sizeof( szMapNameStripped ) );
szMapNameStripped[strlen(szMapNameStripped) - 4] = '\0';
snprintf( label.m_szMap, sizeof( label.m_szMap ), "Map: %s", szMapNameStripped );
// team
label.m_iTerrorists = 0;
label.m_iCounterTerrorists = 0;
for( int i = 0; i < MAX_TEAMS; i++ )
{
if( !stricmp( g_TeamInfo[i].name, "CT") )
label.m_iCounterTerrorists = g_TeamInfo[i].players;
else if( !stricmp( g_TeamInfo[i].name, "TERRORIST") )
label.m_iTerrorists = g_TeamInfo[i].players;
if( label.m_iTerrorists && label.m_iCounterTerrorists )
break;
}
// timer
// time must be positive
if( m_bBombPlanted )
{
label.m_szTimer[0] = '\0';
}
else
{
int iMinutes = max( 0, (int)( gHUD.m_Timer.m_iTime + gHUD.m_Timer.m_fStartTime - gHUD.m_flTime ) / 60);
int iSeconds = max( 0, (int)( gHUD.m_Timer.m_iTime + gHUD.m_Timer.m_fStartTime - gHUD.m_flTime ) - (iMinutes * 60));
sprintf( label.m_szTimer, "%i:%i", iMinutes, iSeconds );
}
}
void CHudSpectatorGui::InitHUDData()
{
m_bBombPlanted = false;
}
void CHudSpectatorGui::Think()
{
}
void CHudSpectatorGui::Reset()
{
m_bBombPlanted = false;
}
int CHudSpectatorGui::MsgFunc_SpecHealth(const char *pszName, int iSize, void *buf)
{
BEGIN_READ( buf, iSize );
int health = READ_BYTE();
g_PlayerExtraInfo[g_iUser2].health = health;
m_iPlayerLastPointedAt = g_iUser2;
return 1;
}
int CHudSpectatorGui::MsgFunc_SpecHealth2(const char *pszName, int iSize, void *buf)
{
BEGIN_READ( buf, iSize );
int health = READ_BYTE();
int client = READ_BYTE();
g_PlayerExtraInfo[client].health = health;
m_iPlayerLastPointedAt = g_iUser2;
return 1;
}

View File

@ -161,8 +161,8 @@ int CHudProgressBar::Draw( float flTime )
DrawUtils::UnpackRGB( r, g, b, RGB_YELLOWISH );
DrawUtils::DrawHudString( ScreenWidth / 4, ScreenHeight / 2, ScreenWidth, (char*)m_szLocalizedHeader, r, g, b );
DrawUtils::DrawRectangle( ScreenWidth/ 4, ScreenHeight / 2 + gHUD.m_scrinfo.iCharHeight, ScreenWidth/2, ScreenHeight/30 );
FillRGBA( ScreenWidth/4+2, ScreenHeight/2 + gHUD.m_scrinfo.iCharHeight + 2, m_fPercent * (ScreenWidth/2-4), ScreenHeight/30-4, 255, 140, 0, 255 );
DrawUtils::DrawRectangle( ScreenWidth/ 4, ScreenHeight / 2 + gHUD.GetCharHeight(), ScreenWidth/2, ScreenHeight/30 );
FillRGBA( ScreenWidth/4+2, ScreenHeight/2 + gHUD.GetCharHeight() + 2, m_fPercent * (ScreenWidth/2-4), ScreenHeight/30-4, 255, 140, 0, 255 );
return 1;
}

View File

@ -85,6 +85,9 @@ public:
g = (int)(g * x);
b = (int)(b * x);
}
static void Draw2DQuad( float x1, float y1, float x2, float y2 );
private:
// console string color
static float color[3];

View File

@ -299,6 +299,7 @@ protected:
class CHudScoreboard: public CHudBase
{
friend class CHudSpectatorGui;
public:
int Init( void );
void InitHUDData( void );
@ -401,7 +402,7 @@ struct team_info_t
int already_drawn;
int scores_overriden;
int sumping;
//int teamnumber; not used
int teamnumber;
};
struct hostage_info_t
@ -713,6 +714,7 @@ private:
//
class CHudTimer: public CHudBase
{
friend class CHudSpectatorGui;
public:
int Init( void );
int VidInit( void );
@ -771,10 +773,12 @@ public:
private:
float left, right, centerx, centery;
int m_iScopeArc[4];
int blackTex;
};
//
//-----------------------------------------------------
//
class CHudNVG: public CHudBase
{
public:
@ -795,6 +799,40 @@ private:
//-----------------------------------------------------
//
class CHudSpectatorGui: public CHudBase
{
public:
int Init();
int VidInit();
int Draw( float flTime );
void InitHUDData();
void Think();
void Reset();
CHudMsgFunc( SpecHealth );
CHudMsgFunc( SpecHealth2 );
void CalcAllNeededData( );
bool m_bBombPlanted;
int m_iPlayerLastPointedAt;
private:
// szMapName is 64 bytes only. Removing "maps/" and ".bsp" gived me this result
class Labels
{
public:
short m_iTerrorists;
short m_iCounterTerrorists;
char m_szTimer[64];
char m_szMap[64];
} label;
int m_hTimerTexture;
};
//
//-----------------------------------------------------
//
class CHud
@ -815,6 +853,15 @@ public:
wrect_t& GetSpriteRect( int index );
int GetSpriteIndex( const char *SpriteName ); // gets a sprite index, for use in the m_rghSprites[] array
inline short GetCharWidth ( unsigned char ch )
{
return m_scrinfo.charWidths[ ch ];
}
inline int GetCharHeight( )
{
return m_scrinfo.iCharHeight;
}
HSPRITE m_hsprCursor;
float m_flTime; // the current client time
@ -858,6 +905,7 @@ public:
CHudSniperScope m_SniperScope;
CHudNVG m_NVG;
CHudRadar m_Radar;
CHudSpectatorGui m_SpectatorGui;