Esempio n. 1
0
void CHUDQuickInfo::Paint()
{
	//BB: KILL THIS CRAP!
	return;

	C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
	if ( player == NULL )
		return;

	C_BaseCombatWeapon *pWeapon = GetActiveWeapon();
	if ( pWeapon == NULL )
		return;

	float fX, fY;
	bool bBehindCamera = false;
	CHudCrosshair::GetDrawPosition( &fX, &fY, &bBehindCamera );

	// if the crosshair is behind the camera, don't draw it
	if( bBehindCamera )
		return;

	int		xCenter	= (int)fX;
	int		yCenter = (int)fY - m_icon_lb->Height() / 2;

	float	scalar  = 138.0f/255.0f;
	
	// Check our health for a warning
	int	health	= player->GetHealth();
	if ( health != m_lastHealth )
	{
		UpdateEventTime();
		m_lastHealth = health;

		if ( health <= HEALTH_WARNING_THRESHOLD )
		{
			if ( m_warnHealth == false )
			{
				m_healthFade = 255;
				m_warnHealth = true;
				
				CLocalPlayerFilter filter;
				C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "HUDQuickInfo.LowHealth" );
			}
		}
		else
		{
			m_warnHealth = false;
		}
	}

	// Check our ammo for a warning
	int	ammo = pWeapon->Clip1();
	if ( ammo != m_lastAmmo )
	{
		UpdateEventTime();
		m_lastAmmo	= ammo;

		// Find how far through the current clip we are
		float ammoPerc = (float) ammo / (float) pWeapon->GetMaxClip1();

		// Warn if we're below a certain percentage of our clip's size
		if (( pWeapon->GetMaxClip1() > 1 ) && ( ammoPerc <= ( 1.0f - CLIP_PERC_THRESHOLD )))
		{
			if ( m_warnAmmo == false )
			{
				m_ammoFade = 255;
				m_warnAmmo = true;

				CLocalPlayerFilter filter;
				C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "HUDQuickInfo.LowAmmo" );
			}
		}
		else
		{
			m_warnAmmo = false;
		}
	}

	Color clrNormal = gHUD.m_clrNormal;
	clrNormal[3] = 255 * scalar;
	m_icon_c->DrawSelf( xCenter, yCenter, clrNormal );

	if( IsX360() )
	{
		// Because the fixed reticle draws on half-texels, this rather unsightly hack really helps
		// center the appearance of the quickinfo on 360 displays.
		xCenter += 1;
	}

	if ( !hud_quickinfo.GetInt() )
		return;

	int	sinScale = (int)( fabs(sin(gpGlobals->curtime*8.0f)) * 128.0f );

	// Update our health
	if ( m_healthFade > 0.0f )
	{
		DrawWarning( xCenter - (m_icon_lb->Width() * 2), yCenter, m_icon_lb, m_healthFade );
	}
	else
	{
		float healthPerc = (float) health / 100.0f;
		healthPerc = clamp( healthPerc, 0.0f, 1.0f );

		Color healthColor = m_warnHealth ? gHUD.m_clrCaution : gHUD.m_clrNormal;
		
		if ( m_warnHealth )
		{
			healthColor[3] = 255 * sinScale;
		}
		else
		{
			healthColor[3] = 255 * scalar;
		}
		
		gHUD.DrawIconProgressBar( xCenter - (m_icon_lb->Width() * 2), yCenter, m_icon_lb, m_icon_lbe, ( 1.0f - healthPerc ), healthColor, CHud::HUDPB_VERTICAL );
	}

	// Update our ammo
	if ( m_ammoFade > 0.0f )
	{
		DrawWarning( xCenter + m_icon_rb->Width(), yCenter, m_icon_rb, m_ammoFade );
	}
	else
	{
		float ammoPerc;

		if ( pWeapon->GetMaxClip1() <= 0 )
		{
			ammoPerc = 0.0f;
		}
		else
		{
			ammoPerc = 1.0f - ( (float) ammo / (float) pWeapon->GetMaxClip1() );
			ammoPerc = clamp( ammoPerc, 0.0f, 1.0f );
		}

		Color ammoColor = m_warnAmmo ? gHUD.m_clrCaution : gHUD.m_clrNormal;
		
		if ( m_warnAmmo )
		{
			ammoColor[3] = 255 * sinScale;
		}
		else
		{
			ammoColor[3] = 255 * scalar;
		}
		
		gHUD.DrawIconProgressBar( xCenter + m_icon_rb->Width(), yCenter, m_icon_rb, m_icon_rbe, ammoPerc, ammoColor, CHud::HUDPB_VERTICAL );
	}
}
void CHUDQuickInfo::Paint()
{
	CHudTexture	*icon_c		= gHUD.GetIcon( "crosshair" );
	CHudTexture	*icon_rb	= gHUD.GetIcon( "crosshair_right" );
	CHudTexture	*icon_lb	= gHUD.GetIcon( "crosshair_left" );

	if ( !icon_c || !icon_rb || !icon_lb )
		return;

	int		xCenter	= ( ScreenWidth() / 2 ) - icon_c->Width() / 2;
	int		yCenter = ( ScreenHeight() / 2 ) - icon_c->Height() / 2;
	int		scalar;
	
	C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();

	if ( player == NULL )
		return;

	C_BaseCombatWeapon *pWeapon = GetActiveWeapon();

	if ( pWeapon == NULL )
		return;

	//Get our values
	int	health	= player->GetHealth();
	int	ammo	= pWeapon->Clip1();

	if ( m_fDamageFade > 0.0f )
	{
		m_fDamageFade -= (gpGlobals->frametime * 200.0f);
	}

	//Check our health for a warning
	if ( health != m_lastHealth )
	{
		if ( health < m_lastHealth )
		{
			m_fDamageFade = QINFO_FADE_TIME;
		}

		m_fFade			= QINFO_FADE_TIME;
		m_lastHealth	= health;

		if ( health <= HEALTH_WARNING_THRESHOLD )
		{
			if ( m_warnHealth == false )
			{
				m_healthFade = 255;
				m_warnHealth = true;
				
				CLocalPlayerFilter filter;
				C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "HUDQuickInfo.LowHealth" );
			}
		}
		else
		{
			m_warnHealth = false;
		}
	}

	// Check our ammo for a warning
	if ( ammo != m_lastAmmo )
	{
		m_fFade		= QINFO_FADE_TIME;
		m_lastAmmo	= ammo;

		if ( ( (float) ammo / (float) pWeapon->GetMaxClip1() ) <= ( 1.0f - CLIP_PERC_THRESHOLD ) )
		{
			if ( m_warnAmmo == false )
			{
				m_ammoFade = 255;
				m_warnAmmo = true;

				CLocalPlayerFilter filter;
				C_BaseEntity::EmitSound( filter, SOUND_FROM_LOCAL_PLAYER, "HUDQuickInfo.LowAmmo" );
			}
		}
		else
		{
			m_warnAmmo = false;
		}
	}

	//Get our crosshair intensity
	if ( m_fFade > 0.0f )
	{
		m_fFade  -= (gpGlobals->frametime * 50.0f);

		if ( m_fFade  < 128.0f )
		{
			scalar = (int) max( 16, (m_fFade) );
		}
		else
		{
			scalar = 128;
		}
	}
	else
	{
		scalar = 16;
	}

	if ( player->IsInAVehicle() )
	{
		scalar = 48;
	}

	Color clrNormal = gHUD.m_clrNormal;
	clrNormal[3] = 255 * scalar;
	icon_c->DrawSelf( xCenter, yCenter, clrNormal );

	int	sinScale = (int)( fabs(sin(gpGlobals->curtime*8.0f)) * 128.0f );

	//Update our health
	if ( m_healthFade > 0.0f )
	{
		DrawWarning( xCenter - 10, yCenter-5, icon_lb, m_healthFade );
	}
	else
	{
		float	healthPerc = (float) health / 100.0f;

		Color healthColor = m_warnHealth ? gHUD.m_clrCaution : gHUD.m_clrNormal;
		
		if ( m_warnHealth )
		{
			healthColor[3] = 255 * sinScale;
		}
		else
		{
			healthColor[3] = 255 * scalar;
		}
		
		gHUD.DrawIconProgressBar( xCenter - 10, yCenter-5, icon_lb, ( 1.0f - healthPerc ), healthColor, CHud::HUDPB_VERTICAL );
	}

	//Update our ammo
	if ( m_ammoFade > 0.0f )
	{
		DrawWarning( xCenter + icon_rb->Width() - 6, yCenter-5, icon_rb, m_ammoFade );
	}
	else
	{
		float ammoPerc = 1.0f - ( (float) ammo / (float) pWeapon->GetMaxClip1() );

		Color ammoColor = m_warnAmmo ? gHUD.m_clrCaution : gHUD.m_clrNormal;
		
		if ( m_warnAmmo )
		{
			ammoColor[3] = 255 * sinScale;
		}
		else
		{
			ammoColor[3] = 255 * scalar;
		}
		
		gHUD.DrawIconProgressBar( xCenter + icon_rb->Width() - 6, yCenter-5, icon_rb, ammoPerc, ammoColor, CHud::HUDPB_VERTICAL );
	}
}