-=*Raz0r*=- Posted December 15, 2009 Share Posted December 15, 2009 Here's some code I'm somewhat proud of - still needs some work, customise it how you want. OLD Show spoiler (hidden content - requires Javascript to show) #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]; // Which weapons are we given? int weaponsAvailable = 0; // Which of these do we have ammo for? int currentWeapon = cg.weaponSelect; // Which weapon do we have currently selected int i = 0; // iterate float y = 96.0f; // y co-ordinate of current weapon icon float wpX[WP_NUM_WEAPONS]; float wpY[WP_NUM_WEAPONS]; vec4_t colour = { 1.0f, 1.0f, 1.0f, 1.0f }; // Colour of the icons (Greyscaling and whatnot) //Set the coordinates for ( i=1; i<WP_NUM_WEAPONS; i++ ) { if ( weaponsAllowed & ( 1 << i ) ) { wpY[i] = y; y += ICON_SIZE-12.0f; wpX[i] = (i==currentWeapon) ? 32.0f : 24.0f ; } } #if 0 //TODO: Find out which weapons we have ammo for (So we can highlight them) for ( i=1; i<WP_NUM_WEAPONS; i++ ) { if ( ( weaponsAllowed & ( 1 << i ) ) && cg.predictedPlayerState.ammo[i] ) weaponsAvailable |= ( 1 << i ); } #else //Every weapon we own for ( i=1; i<WP_NUM_WEAPONS; i++ ) { if ( weaponsAllowed & ( 1 << i ) ) weaponsAvailable |= ( 1 << i ); } #endif //Every weapon we have ammo for (highlight them) for ( i=1; i<WP_NUM_WEAPONS; i++ ) { if ( weaponsAvailable & ( 1 << i ) ) { if ( i == currentWeapon ) CG_DrawPic( wpX[i], wpY[i], ICON_SIZE, ICON_SIZE, cgs.media.weaponIcons[i] ); else { MAKERGB( colour, 0.75f, 0.75f, 0.75f ); DRAW_PIC( wpX[i], wpY[i], ICON_SIZE, ICON_SIZE, cgs.media.weaponIcons_NA[i], colour ); } } } } Updated #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) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.