summaryrefslogtreecommitdiff
path: root/src/cgame
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2015-04-04 12:33:20 +0200
committerPaweł Redman <pawel.redman@gmail.com>2015-04-04 12:33:20 +0200
commiteb30895efbad7f5f1ca5d943dbe87ebcd3502fa3 (patch)
tree45979666162f6a1177320d7c28ecf452746c7ad1 /src/cgame
parentf3008f9819d57b671a424a0097f50c93926af74e (diff)
Improve numbers_alt, make health bars' colors change depending on the health, make health bars not appear on entities with 100% health.
Diffstat (limited to 'src/cgame')
-rw-r--r--src/cgame/cg_draw.c54
-rw-r--r--src/cgame/cg_local.h2
-rw-r--r--src/cgame/cg_main.c5
3 files changed, 36 insertions, 25 deletions
diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c
index 2c6645f..92e64b5 100644
--- a/src/cgame/cg_draw.c
+++ b/src/cgame/cg_draw.c
@@ -3888,7 +3888,7 @@ static void CG_DrawNumber( float x, float y, float h, char *str )
char *p;
len = strlen( str );
- w = h * cgDC.aspectScale * 0.5f;
+ w = h * cgDC.aspectScale * 0.75f;
y -= h / 2;
x -= len * w / 2;
@@ -3897,10 +3897,14 @@ static void CG_DrawNumber( float x, float y, float h, char *str )
{
if( *p >= '0' && *p <= '9' )
index = *p - '0';
- else
+ else if( *p == '.' )
index = 10;
-
- CG_DrawPic( x, y, w, h, cgs.media.numberShadersAlt[ index ] );
+ else
+ index = 11;
+
+ if( *p != ' ' )
+ CG_DrawPic( x, y, w, h, cgs.media.numberShadersAlt[ index ] );
+
x += w;
}
}
@@ -3984,7 +3988,7 @@ typedef struct
static int CompareHealthBars( const healthBar_t *a, const healthBar_t *b )
{
- return a->dist < b->dist;
+ return ( a->dist < b->dist ? 1 : -1 );
}
static void CG_DrawHealthBars( void )
@@ -4047,44 +4051,50 @@ static void CG_DrawHealthBars( void )
qsort( bars, bare - bars, sizeof( healthBar_t ),
(int(*)(const void*,const void*))CompareHealthBars );
-/*
- TODO: figure out why qsort fails for more than 5 bars
-
- for( i = 0; i < bare - bars - 1; i++ )
- if( CompareHealthBars( bars + i, bars + i + 1 ) )
- {
- Com_Printf( "qsort is retarded\n" );
- break;
- }
-*/
-
for( bar = bars; bar < bare; bar++ )
{
- float x, y, w, h, hf;
+ float x, y, w, h, hf, cf;
char buffer[ 64 ];
vec4_t color;
+ if( bar->value >= bar->max )
+ continue;
+
if( !CG_WorldToScreen( bar->origin, &x, &y ) )
continue;
hf = (float)bar->value / bar->max;
h = cg_healthBarSize.value / bar->dist;
- w = 4 * h * cgDC.aspectScale;
+ w = 6 * h * cgDC.aspectScale;
- Com_sprintf( buffer, sizeof( buffer ), "%d", bar->value );
+ Com_sprintf( buffer, sizeof( buffer ), "%d/%d", bar->value, bar->max );
color[ 3 ] = cg_healthBarAlpha.value;
- VectorSet( color, 0.1, 0.7, 0.1 );
+ if( hf <= 1.0f && hf > 0.5f )
+ {
+ cf = ( hf - 0.5f ) / 0.5f;
+ VectorSet( color, 1 - cf, 1.0f, 0.0f );
+ }
+ else
+ {
+ cf = hf / 0.5f;
+ VectorSet( color, 1.0f, cf, 0.0f );
+ }
+
+ VectorScale( color, 0.5f, color );
+
trap_R_SetColor( color );
CG_DrawPic( x - w/2, y - h/2, w * hf, h, cgs.media.whiteShader );
- VectorSet( color, 0.7, 0.1, 0.1 );
+
+
+ VectorSet( color, 0.1, 0.1, 0.1 );
trap_R_SetColor( color );
CG_DrawPic( x - w/2 + w * hf, y - h/2, w * ( 1 - hf ), h, cgs.media.whiteShader );
- VectorSet( color, 0, 0, 0 );
+ VectorSet( color, 1, 1, 1 );
trap_R_SetColor( color );
CG_DrawNumber( x, y, h, buffer );
}
diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h
index 83cac63..2d2598c 100644
--- a/src/cgame/cg_local.h
+++ b/src/cgame/cg_local.h
@@ -1198,7 +1198,7 @@ typedef struct
qhandle_t teamOverlayShader;
qhandle_t numberShaders[ 11 ];
- qhandle_t numberShadersAlt[ 11 ];
+ qhandle_t numberShadersAlt[ 12 ];
qhandle_t shadowMarkShader;
qhandle_t wakeMarkShader;
diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c
index 0fdb028..9e51258 100644
--- a/src/cgame/cg_main.c
+++ b/src/cgame/cg_main.c
@@ -781,7 +781,7 @@ static void CG_RegisterGraphics( void )
"gfx/2d/numbers/nine_32b",
"gfx/2d/numbers/minus_32b",
};
- static char *sb_nums_alt[ 11 ] =
+ static char *sb_nums_alt[ 12 ] =
{
"gfx/2d/numbers_alt/0",
"gfx/2d/numbers_alt/1",
@@ -794,6 +794,7 @@ static void CG_RegisterGraphics( void )
"gfx/2d/numbers_alt/8",
"gfx/2d/numbers_alt/9",
"gfx/2d/numbers_alt/minus",
+ "gfx/2d/numbers_alt/slash",
};
static char *buildWeaponTimerPieShaders[ 8 ] =
{
@@ -817,7 +818,7 @@ static void CG_RegisterGraphics( void )
for( i = 0; i < 11; i++ )
cgs.media.numberShaders[ i ] = trap_R_RegisterShader( sb_nums[ i ] );
- for( i = 0; i < 11; i++ )
+ for( i = 0; i < 12; i++ )
cgs.media.numberShadersAlt[ i ] = trap_R_RegisterShader( sb_nums_alt[ i ] );
cgs.media.viewBloodShader = trap_R_RegisterShader( "gfx/damage/fullscreen_painblend" );