hlsdk-portable/cl_dll/flashlight.cpp

99 lines
2.1 KiB
C++
Raw Normal View History

2016-06-04 13:24:23 +00: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.
*
****/
//
// flashlight.cpp
//
// implementation of CHudFlashlight class
//
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include <string.h>
#include <stdio.h>
2016-07-03 13:39:55 +00:00
DECLARE_MESSAGE( m_Flash, FlashBat )
DECLARE_MESSAGE( m_Flash, Flashlight )
2016-06-04 13:24:23 +00:00
#define BAT_NAME "sprites/%d_Flashlight.spr"
2016-07-03 13:39:55 +00:00
int CHudFlashlight::Init( void )
2016-06-04 13:24:23 +00:00
{
m_fFade = 0;
m_fOn = 0;
2016-07-03 13:39:55 +00:00
HOOK_MESSAGE( Flashlight );
HOOK_MESSAGE( FlashBat );
2016-06-04 13:24:23 +00:00
m_iFlags |= HUD_ACTIVE;
2016-07-03 13:39:55 +00:00
gHUD.AddHudElem( this );
2016-06-04 13:24:23 +00:00
return 1;
}
2016-06-04 13:24:23 +00:00
2016-07-03 13:39:55 +00:00
void CHudFlashlight::Reset( void )
2016-06-04 13:24:23 +00:00
{
m_fFade = 0;
m_fOn = 0;
m_iBat = 100;
m_flBat = 1.0;
2016-06-04 13:24:23 +00:00
}
2016-07-03 13:39:55 +00:00
int CHudFlashlight::VidInit( void )
2016-06-04 13:24:23 +00:00
{
int HUD_flash_empty = gHUD.GetSpriteIndex( "flash_empty" );
int HUD_flash_full = gHUD.GetSpriteIndex( "flash_full" );
int HUD_flash_beam = gHUD.GetSpriteIndex( "flash_beam" );
2016-07-03 13:39:55 +00:00
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 );
2016-06-04 13:24:23 +00:00
m_prcBeam = &gHUD.GetSpriteRect(HUD_flash_beam);
m_iWidth = m_prc2->right - m_prc2->left;
return 1;
}
2016-06-04 13:24:23 +00:00
2016-07-03 13:39:55 +00:00
int CHudFlashlight::MsgFunc_FlashBat( const char *pszName, int iSize, void *pbuf )
2016-06-04 13:24:23 +00:00
{
BEGIN_READ( pbuf, iSize );
int x = READ_BYTE();
m_iBat = x;
2016-07-03 13:39:55 +00:00
m_flBat = ( (float)x ) / 100.0;
2016-06-04 13:24:23 +00:00
return 1;
}
2016-07-03 13:39:55 +00:00
int CHudFlashlight::MsgFunc_Flashlight( const char *pszName, int iSize, void *pbuf )
2016-06-04 13:24:23 +00:00
{
BEGIN_READ( pbuf, iSize );
m_fOn = READ_BYTE();
int x = READ_BYTE();
m_iBat = x;
2016-07-03 13:39:55 +00:00
m_flBat = ( (float)x ) / 100.0;
2016-06-04 13:24:23 +00:00
return 1;
}
2016-07-03 13:39:55 +00:00
int CHudFlashlight::Draw( float flTime )
2016-06-04 13:24:23 +00:00
{
2018-10-25 03:06:16 +00:00
gMobileEngfuncs->pfnTouchHideButtons( "flashlight", 1 );
2016-06-04 13:24:23 +00:00
return 1;
}