2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-22 01:47:45 +01:00
hlsdk-xash3d/cl_dll/ammo_secondary.cpp

160 lines
4.1 KiB
C++
Raw Normal View History

2016-06-04 15:24:23 +02:00
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
//
// ammo_secondary.cpp
//
// implementation of CHudAmmoSecondary class
//
#include "hud.h"
#include "cl_util.h"
#include <string.h>
#include <stdio.h>
#include "parsemsg.h"
DECLARE_MESSAGE( m_AmmoSecondary, SecAmmoVal )
DECLARE_MESSAGE( m_AmmoSecondary, SecAmmoIcon )
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
int CHudAmmoSecondary::Init( void )
2016-06-04 15:24:23 +02:00
{
HOOK_MESSAGE( SecAmmoVal );
HOOK_MESSAGE( SecAmmoIcon );
gHUD.AddHudElem(this);
m_HUD_ammoicon = 0;
2016-08-02 15:36:48 +02:00
for( int i = 0; i < MAX_SEC_AMMO_VALUES; i++ )
2016-06-04 15:24:23 +02:00
m_iAmmoAmounts[i] = -1; // -1 means don't draw this value
Reset();
return 1;
}
2016-07-03 15:39:55 +02:00
void CHudAmmoSecondary::Reset( void )
2016-06-04 15:24:23 +02:00
{
m_fFade = 0;
}
2016-07-03 15:39:55 +02:00
int CHudAmmoSecondary::VidInit( void )
2016-06-04 15:24:23 +02:00
{
return 1;
}
2016-07-03 15:39:55 +02:00
int CHudAmmoSecondary::Draw( float flTime )
2016-06-04 15:24:23 +02:00
{
2016-08-02 15:36:48 +02:00
if( ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_WEAPONS | HIDEHUD_ALL ) ) )
2016-06-04 15:24:23 +02:00
return 1;
// draw secondary ammo icons above normal ammo readout
int a, x, y, r, g, b, AmmoWidth;
UnpackRGB( r, g, b, RGB_YELLOWISH );
2019-08-11 23:25:50 +02:00
a = (int)Q_max( MIN_ALPHA, m_fFade );
2016-07-03 15:39:55 +02:00
if( m_fFade > 0 )
2019-10-13 14:12:41 +02:00
m_fFade -= ( (float)gHUD.m_flTimeDelta * 20.0f ); // slowly lower alpha to fade out icons
2016-06-04 15:24:23 +02:00
ScaleColors( r, g, b, a );
2016-07-03 15:39:55 +02:00
AmmoWidth = gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).right - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).left;
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
y = ScreenHeight - ( gHUD.m_iFontHeight * 4 ); // this is one font height higher than the weapon ammo values
2016-06-04 15:24:23 +02:00
x = ScreenWidth - AmmoWidth;
2016-07-03 15:39:55 +02:00
if( m_HUD_ammoicon )
2016-06-04 15:24:23 +02:00
{
// Draw the ammo icon
2016-07-03 15:39:55 +02:00
x -= ( gHUD.GetSpriteRect( m_HUD_ammoicon ).right - gHUD.GetSpriteRect( m_HUD_ammoicon ).left );
y -= ( gHUD.GetSpriteRect( m_HUD_ammoicon ).top - gHUD.GetSpriteRect( m_HUD_ammoicon ).bottom );
2016-06-04 15:24:23 +02:00
2016-07-03 15:39:55 +02:00
SPR_Set( gHUD.GetSprite( m_HUD_ammoicon ), r, g, b );
SPR_DrawAdditive( 0, x, y, &gHUD.GetSpriteRect( m_HUD_ammoicon ) );
2016-06-04 15:24:23 +02:00
}
else
2016-07-03 15:39:55 +02:00
{
// move the cursor by the '0' char instead, since we don't have an icon to work with
2016-06-04 15:24:23 +02:00
x -= AmmoWidth;
2016-07-03 15:39:55 +02:00
y -= ( gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).top - gHUD.GetSpriteRect( gHUD.m_HUD_number_0 ).bottom );
2016-06-04 15:24:23 +02:00
}
// draw the ammo counts, in reverse order, from right to left
2016-07-03 15:39:55 +02:00
for( int i = MAX_SEC_AMMO_VALUES-1; i >= 0; i-- )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
if( m_iAmmoAmounts[i] < 0 )
2016-06-04 15:24:23 +02:00
continue; // negative ammo amounts imply that they shouldn't be drawn
// half a char gap between the ammo number and the previous pic
2016-07-03 15:39:55 +02:00
x -= ( AmmoWidth / 2 );
2016-06-04 15:24:23 +02:00
// draw the number, right-aligned
2016-07-03 15:39:55 +02:00
x -= ( gHUD.GetNumWidth( m_iAmmoAmounts[i], DHN_DRAWZERO ) * AmmoWidth );
2016-06-04 15:24:23 +02:00
gHUD.DrawHudNumber( x, y, DHN_DRAWZERO, m_iAmmoAmounts[i], r, g, b );
2016-07-03 15:39:55 +02:00
if( i != 0 )
2016-06-04 15:24:23 +02:00
{
// draw the divider bar
2016-07-03 15:39:55 +02:00
x -= ( AmmoWidth / 2 );
FillRGBA( x, y, ( AmmoWidth/10 ), gHUD.m_iFontHeight, r, g, b, a );
2016-06-04 15:24:23 +02:00
}
}
return 1;
}
// Message handler for Secondary Ammo Value
// accepts one value:
// string: sprite name
2016-07-03 15:39:55 +02:00
int CHudAmmoSecondary::MsgFunc_SecAmmoIcon( const char *pszName, int iSize, void *pbuf )
2016-06-04 15:24:23 +02:00
{
BEGIN_READ( pbuf, iSize );
m_HUD_ammoicon = gHUD.GetSpriteIndex( READ_STRING() );
return 1;
}
// Message handler for Secondary Ammo Icon
// Sets an ammo value
// takes two values:
// byte: ammo index
// byte: ammo value
2016-07-03 15:39:55 +02:00
int CHudAmmoSecondary::MsgFunc_SecAmmoVal( const char *pszName, int iSize, void *pbuf )
2016-06-04 15:24:23 +02:00
{
BEGIN_READ( pbuf, iSize );
int index = READ_BYTE();
2016-07-03 15:39:55 +02:00
if( index < 0 || index >= MAX_SEC_AMMO_VALUES )
2016-06-04 15:24:23 +02:00
return 1;
m_iAmmoAmounts[index] = READ_BYTE();
m_iFlags |= HUD_ACTIVE;
// check to see if there is anything left to draw
int count = 0;
2016-07-03 15:39:55 +02:00
for( int i = 0; i < MAX_SEC_AMMO_VALUES; i++ )
2016-06-04 15:24:23 +02:00
{
2019-08-11 23:25:50 +02:00
count += Q_max( 0, m_iAmmoAmounts[i] );
2016-06-04 15:24:23 +02:00
}
2016-07-03 15:39:55 +02:00
if( count == 0 )
{
// the ammo fields are all empty, so turn off this hud area
2016-06-04 15:24:23 +02:00
m_iFlags &= ~HUD_ACTIVE;
return 1;
}
// make the icons light up
m_fFade = 200.0f;
return 1;
}