Skip to content

Commit

Permalink
cgame: add cg_weaponBar
Browse files Browse the repository at this point in the history
1 - top left, 2 - bottom center
  • Loading branch information
yumirak committed Mar 8, 2024
1 parent 05f6b24 commit 6b5665d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 38 deletions.
1 change: 0 additions & 1 deletion code/cgame/cg_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ CG_DrawStatusBar
================
*/
#ifndef MISSIONPACK
#define STATUSBAR_HEIGHT 60
static void CG_DrawStatusBar( void ) {
int color;
centity_t *cent;
Expand Down
5 changes: 4 additions & 1 deletion code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#define DEFAULT_REDTEAM_NAME "Stroggs"
#define DEFAULT_BLUETEAM_NAME "Pagans"

#define STATUSBAR_HEIGHT 60

#define NUM_REWARD_VARIATIONS 3

#define ICON_SCALE_DISTANCE 200.0
Expand Down Expand Up @@ -736,6 +738,7 @@ typedef struct {
qhandle_t connectionShader;

qhandle_t selectShader;
qhandle_t weaplit;
qhandle_t viewBloodShader;
qhandle_t tracerShader;
qhandle_t crosshairShader[NUM_CROSSHAIRS];
Expand Down Expand Up @@ -1344,7 +1347,7 @@ extern vmCvar_t cg_drawPowerupAvailableAlpha;
extern vmCvar_t cg_drawPowerupAvailableFadeStart;
extern vmCvar_t cg_drawPowerupAvailableFadeEnd;
//

extern vmCvar_t cg_drawWeaponBar;
//
// cg_main.c
//
Expand Down
5 changes: 5 additions & 0 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ vmCvar_t cg_drawPowerupAvailableOffset;
vmCvar_t cg_drawPowerupAvailableAlpha;
vmCvar_t cg_drawPowerupAvailableFadeStart;
vmCvar_t cg_drawPowerupAvailableFadeEnd;
//
vmCvar_t cg_drawWeaponBar;

typedef struct {
vmCvar_t *vmCvar;
Expand Down Expand Up @@ -454,6 +456,8 @@ static cvarTable_t cvarTable[] = {
{ &cg_drawPowerupAvailableAlpha,"cg_drawPowerupAvailableAlpha", "1.0", CVAR_ARCHIVE },
{ &cg_drawPowerupAvailableFadeStart,"cg_drawPowerupAvailableFadeStart", "705.0", CVAR_ARCHIVE },
{ &cg_drawPowerupAvailableFadeEnd, "cg_drawPowerupAvailableFadeEnd", "520.0", CVAR_ARCHIVE },
//
{ &cg_drawWeaponBar, "cg_weaponBar", "1", CVAR_ARCHIVE },
// { &cg_pmove_fixed, "cg_pmove_fixed", "0", CVAR_USERINFO | CVAR_ARCHIVE }
};

Expand Down Expand Up @@ -1053,6 +1057,7 @@ static void CG_RegisterGraphics( void ) {

cgs.media.tracerShader = trap_R_RegisterShader( "gfx/misc/tracer" );
cgs.media.selectShader = trap_R_RegisterShader( "gfx/2d/select" );
cgs.media.weaplit = trap_R_RegisterShader("ui/assets/hud/weaplit2");

for ( i = 0 ; i < NUM_CROSSHAIRS ; i++ )
cgs.media.crosshairShader[i] = trap_R_RegisterShaderNoMip( va("gfx/2d/crosshair%d", i) );
Expand Down
72 changes: 36 additions & 36 deletions code/cgame/cg_weapons.c
Original file line number Diff line number Diff line change
Expand Up @@ -1458,77 +1458,77 @@ WEAPON SELECTION
CG_DrawWeaponSelect
===================
*/
#define AMMO_ICON_SIZE 16
void CG_DrawWeaponSelect( void ) {
int i;
int bits;
int count;
int x, y, w;
char *name;
float *color;
int x, y;
int dx, dy;
int weaponSelect;
char buf[4];

// don't display if dead
if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 ) {
if ( cg.predictedPlayerState.stats[STAT_HEALTH] <= 0 || !cg_drawWeaponBar.integer ) {
return;
}

color = CG_FadeColor( cg.weaponSelectTime, WEAPON_SELECT_TIME );
if ( !color ) {
return;
}
trap_R_SetColor( color );

// showing weapon select clears pickup item display, but not the blend blob
cg.itemPickupTime = 0;
weaponSelect = cg_drawWeaponBar.integer ;

// count the number of weapons owned
bits = cg.snap->ps.stats[ STAT_WEAPONS ];
count = 0;
for ( i = 1 ; i < MAX_WEAPONS ; i++ ) {
for ( i = WP_MACHINEGUN ; i < MAX_WEAPONS ; i++ ) {
if ( bits & ( 1 << i ) ) {
count++;
}
}

x = 320 - count * 20;
y = cgs.screenYmax + 1 - 100; // - STATUSBAR_HEIGHT - 40
switch(weaponSelect)
{
case 2: // horizontal
x = 320 - count * 28;
y = cgs.screenYmax - STATUSBAR_HEIGHT - 40;
dx = 56;
dy = 0;
break;
default: // vertical left
x = cgs.screenXmin + 6;
y = 100; //240 - count * 10; // centered
dx = 0;
dy = 20;
break;
}

for ( i = 1 ; i < MAX_WEAPONS ; i++ ) {
for ( i = WP_MACHINEGUN ; i < MAX_WEAPONS ; i++ ) {
if ( !( bits & ( 1 << i ) ) ) {
continue;
}

CG_RegisterWeapon( i );

// draw weapon icon
CG_DrawPic( x, y, 32, 32, cg_weapons[i].weaponIcon );

// draw selection marker
if ( i == cg.weaponSelect ) {
CG_DrawPic( x-4, y-4, 40, 40, cgs.media.selectShader );
CG_DrawPic( x - 2, y - 2, (AMMO_ICON_SIZE*3) + 8, AMMO_ICON_SIZE+4, cgs.media.weaplit);
}

// draw weapon icon
CG_DrawPic( x, y, AMMO_ICON_SIZE, AMMO_ICON_SIZE, cg_weapons[i].weaponIcon );

// no ammo cross on top
if ( !cg.snap->ps.ammo[ i ] ) {
CG_DrawPic( x, y, 32, 32, cgs.media.noammoShader );
}
if ( weaponSelect > 0 && cg.snap->ps.ammo[ i ] > -1 ) {

x += 40;
}
if ( !cg.snap->ps.ammo[ i ] )
CG_DrawPic( x, y, AMMO_ICON_SIZE, AMMO_ICON_SIZE, cgs.media.noammoShader );

// draw the selected name
if ( cg_weapons[ cg.weaponSelect ].item ) {
name = cg_weapons[ cg.weaponSelect ].item->pickup_name;
if ( name ) {
w = CG_DrawStrlen( name, UI_BIGFONT);// * BIGCHAR_WIDTH;
x = ( SCREEN_WIDTH - w ) / 2;
CG_DrawBigStringColor(x, y - 22, name, color);
// ammo counter
Com_sprintf( buf, sizeof(buf),"%i", cg.snap->ps.ammo[ i ] );
CG_DrawString( x + AMMO_ICON_SIZE + 2, y-1, buf, UI_BIGFONT, NULL);
}
x += dx;
y += dy;
}

trap_R_SetColor( NULL );
}


/*
===============
CG_WeaponSelectable
Expand Down

0 comments on commit 6b5665d

Please sign in to comment.