lfnetwork.com mark read register faq members calendar

Thread: SNIPPET :: Weapon HUD
Thread Tools Display Modes
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Old 12-15-2009, 08:06 AM   #1
-=*Raz0r*=-
Rookie
 
-=*Raz0r*=-'s Avatar
 
Join Date: Oct 2006
Location: Australia
Posts: 243
SNIPPET :: Weapon HUD

Here's some code I'm somewhat proud of - still needs some work, customise it how you want.

OLD
Show spoiler



Updated

Code:
#define DRAW_PIC( x, y, w, h, shader, colour )	\
{												\
	trap_R_SetColor( colour );					\
		CG_DrawPic( x, y, w, h, shader );		\
	trap_R_SetColor( NULL );					\
}

static void DrawWeapons( void )
{
	int		weaponsAllowed		= cg.predictedPlayerState.stats[STAT_WEAPONS];	//	Bit-mask of the weapons are we given
	int		currentWeapon		= cg.weaponSelect;								//	Which weapon do we currently have selected?
	int		i					= 0;											//	iterate
	float	y					= 96.0f;										//	y co-ordinate of current weapon icon (iterated)
	float	wpX[WP_NUM_WEAPONS];												//	Store the x coordinate of each weapon icon
	float	wpY[WP_NUM_WEAPONS];												//	Store the y coordinate of each weapon icon
	vec4_t	colour				= { 1.0f, 1.0f, 1.0f, 1.0f };					//	Colour of the icons (Greyscaling and whatnot)

	
	for ( i=1; i<=LAST_USEABLE_WEAPON; i++ )
	{//Set the coordinates (Preparation)
		if ( weaponsAllowed & ( 1 << i ) )
		{//Only get weapons we actually own
			wpY[i]	= y;
			y		+= ICON_SIZE-12.0f;

			if ( i == currentWeapon )
			{//The weapon we have selected shall be nudged to the right
				wpX[i]	= 36.0f;
			}
			else if ( !am_weaponData[i].ammoPerShot || cg.predictedPlayerState.ammo[am_weaponData[i].ammoIndex] )
			{//This weapon doesn't use ammo, or we have ammo. Regular position.
				wpX[i]	= 24.0f;
			}
			else
			{//We can't use this weapon. Nudge it to the left.
				//wpX[i]	= 8.0f;
				wpX[i]	= 24.0f;
			}
		}
	}

	for ( i=1; i<=LAST_USEABLE_WEAPON; i++ )
	{//Render the valid weapons' icons
		if ( weaponsAllowed & ( 1 << i ) )
		{
			if ( i == currentWeapon )
			{//The weapon we have selected shall be highlighted
				CG_DrawPic( wpX[i], wpY[i], ICON_SIZE, ICON_SIZE, cgs.media.weaponIcons[i] );
			}
			else if ( !am_weaponData[i].ammoPerShot || cg.predictedPlayerState.ammo[am_weaponData[i].ammoIndex] )
			{//This weapon either doesn't use ammo, or we have ammo for it. It's valid.
				MAKERGB( colour, 0.5f, 0.5f, 0.5f );
				DRAW_PIC( wpX[i], wpY[i], ICON_SIZE, ICON_SIZE, cgs.media.weaponIcons[i], colour );
			}
			else
			{//We don't have ammo for this weapon, it's invalid. We can't select this, so dim it.
				MAKERGBA( colour, 0.2f, 0.2f, 0.2f, 0.75f );
				DRAW_PIC( wpX[i], wpY[i], ICON_SIZE, ICON_SIZE, cgs.media.weaponIcons_NA[i], colour );
			}
		}
	}
}
You'll have to adapt the ammo and weaponData part for your own mod (Mine is altered from baseJKA)

-Notes-
It could probably do with some static memory, but I didn't want to mess too much with that.
It should be called from CG_Draw2D (My HUD code is totally restructured, so I can't really say where the most suitable place is)


Last edited by -=*Raz0r*=-; 09-29-2012 at 02:19 AM.
-=*Raz0r*=- is offline   you may: quote & reply,
Post a new thread. Add a reply to this thread. Indicate all threads in this forum as read. Subscribe to this forum. RSS feed: this forum RSS feed: all forums
Go Back   LucasForums > Network > JediKnight Series > Editing Central > JA Coding > SNIPPET :: Weapon HUD

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:23 AM.

LFNetwork, LLC ©2002-2011 - All rights reserved.
Powered by vBulletin®
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.