Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

164 lines
3.4 KiB

9 years ago
/***
*
* 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.
*
****/
//
// flashlight.cpp
//
// implementation of CHudFlashlight class
//
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include <string.h>
#include <stdio.h>
9 years ago
DECLARE_MESSAGE( m_Flash, FlashBat )
DECLARE_MESSAGE( m_Flash, Flashlight )
9 years ago
#define BAT_NAME "sprites/%d_Flashlight.spr"
9 years ago
int CHudFlashlight::Init( void )
9 years ago
{
m_fFade = 0;
m_fOn = 0;
9 years ago
HOOK_MESSAGE( Flashlight );
HOOK_MESSAGE( FlashBat );
9 years ago
m_iFlags |= HUD_ACTIVE;
9 years ago
gHUD.AddHudElem( this );
9 years ago
return 1;
}
9 years ago
9 years ago
void CHudFlashlight::Reset( void )
9 years ago
{
m_fFade = 0;
m_fOn = 0;
m_iBat = 100;
m_flBat = 1.0f;
9 years ago
}
9 years ago
int CHudFlashlight::VidInit( void )
9 years ago
{
int HUD_flash_empty = gHUD.GetSpriteIndex( "flash_empty" );
int HUD_flash_full = gHUD.GetSpriteIndex( "flash_full" );
int HUD_flash_beam = gHUD.GetSpriteIndex( "flash_beam" );
9 years ago
m_hSprite1 = gHUD.GetSprite( HUD_flash_empty );
m_hSprite2 = gHUD.GetSprite( HUD_flash_full );
m_hBeam = gHUD.GetSprite( HUD_flash_beam );
m_prc1 = &gHUD.GetSpriteRect( HUD_flash_empty );
m_prc2 = &gHUD.GetSpriteRect( HUD_flash_full );
9 years ago
m_prcBeam = &gHUD.GetSpriteRect(HUD_flash_beam);
m_iWidth = m_prc2->right - m_prc2->left;
return 1;
}
9 years ago
9 years ago
int CHudFlashlight::MsgFunc_FlashBat( const char *pszName, int iSize, void *pbuf )
9 years ago
{
BEGIN_READ( pbuf, iSize );
int x = READ_BYTE();
m_iBat = x;
m_flBat = ( (float)x ) / 100.0f;
9 years ago
return 1;
}
9 years ago
int CHudFlashlight::MsgFunc_Flashlight( const char *pszName, int iSize, void *pbuf )
9 years ago
{
BEGIN_READ( pbuf, iSize );
m_fOn = READ_BYTE();
int x = READ_BYTE();
m_iBat = x;
m_flBat = ( (float)x ) / 100.0f;
9 years ago
return 1;
}
9 years ago
int CHudFlashlight::Draw( float flTime )
9 years ago
{
// modif de Julien
m_iFlags &= ~HUD_ACTIVE;
/*
static bool show = ( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) );
if( show != !( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) ) )
{
show = !( gHUD.m_iHideHUDDisplay & ( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) );
if( gMobileEngfuncs )
{
gMobileEngfuncs->pfnTouchHideButtons( "flashlight", !show );
}
}
9 years ago
if( !show )
9 years ago
return 1;
int r, g, b, x, y, a;
wrect_t rc;
if( gEngfuncs.IsSpectateOnly() )
return 1;
9 years ago
if( !( gHUD.m_iWeaponBits & ( 1 << ( WEAPON_SUIT ) ) ) )
9 years ago
return 1;
9 years ago
if( m_fOn )
9 years ago
a = 225;
else
a = MIN_ALPHA;
if( m_flBat < 0.20f )
9 years ago
UnpackRGB( r,g,b, RGB_REDISH );
9 years ago
else
9 years ago
UnpackRGB( r,g,b, RGB_YELLOWISH );
9 years ago
9 years ago
ScaleColors( r, g, b, a );
9 years ago
9 years ago
y = ( m_prc1->bottom - m_prc2->top ) / 2;
x = ScreenWidth - m_iWidth - m_iWidth / 2 ;
9 years ago
// Draw the flashlight casing
9 years ago
SPR_Set( m_hSprite1, r, g, b );
SPR_DrawAdditive( 0, x, y, m_prc1 );
9 years ago
9 years ago
if( m_fOn )
{
// draw the flashlight beam
x = ScreenWidth - m_iWidth / 2;
9 years ago
SPR_Set( m_hBeam, r, g, b );
SPR_DrawAdditive( 0, x, y, m_prcBeam );
}
// draw the flashlight energy level
9 years ago
x = ScreenWidth - m_iWidth - m_iWidth / 2;
int iOffset = m_iWidth * ( 1.0f - m_flBat );
9 years ago
if( iOffset < m_iWidth )
9 years ago
{
rc = *m_prc2;
rc.left += iOffset;
9 years ago
SPR_Set( m_hSprite2, r, g, b );
SPR_DrawAdditive( 0, x + iOffset, y, &rc );
}*/
9 years ago
return 1;
}