2
0
mirror of https://github.com/FWGS/hlsdk-xash3d synced 2024-11-25 03:09:24 +01:00
hlsdk-xash3d/cl_dll/status_icons.cpp

165 lines
3.9 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.
*
****/
//
// status_icons.cpp
//
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
#include "hud.h"
#include "cl_util.h"
#include "const.h"
#include "entity_state.h"
#include "cl_entity.h"
#include <string.h>
#include <stdio.h>
#include "parsemsg.h"
#include "event_api.h"
2016-06-25 20:21:01 +02:00
DECLARE_MESSAGE( m_StatusIcons, StatusIcon )
2016-06-04 15:24:23 +02:00
int CHudStatusIcons::Init( void )
{
HOOK_MESSAGE( StatusIcon );
gHUD.AddHudElem( this );
Reset();
return 1;
}
int CHudStatusIcons::VidInit( void )
{
return 1;
}
void CHudStatusIcons::Reset( void )
{
memset( m_IconList, 0, sizeof m_IconList );
m_iFlags &= ~HUD_ACTIVE;
}
// Draw status icons along the left-hand side of the screen
int CHudStatusIcons::Draw( float flTime )
{
2016-07-03 15:39:55 +02:00
if( gEngfuncs.IsSpectateOnly() )
2016-06-04 15:24:23 +02:00
return 1;
// find starting position to draw from, along right-hand side of screen
int x = 5;
int y = ScreenHeight / 2;
// loop through icon list, and draw any valid icons drawing up from the middle of screen
2016-07-03 15:39:55 +02:00
for( int i = 0; i < MAX_ICONSPRITES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
if( m_IconList[i].spr )
2016-06-04 15:24:23 +02:00
{
y -= ( m_IconList[i].rc.bottom - m_IconList[i].rc.top ) + 5;
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
SPR_Set( m_IconList[i].spr, m_IconList[i].r, m_IconList[i].g, m_IconList[i].b );
SPR_DrawAdditive( 0, x, y, &m_IconList[i].rc );
}
}
2016-07-03 15:39:55 +02:00
2016-06-04 15:24:23 +02:00
return 1;
}
// Message handler for StatusIcon message
// accepts five values:
// byte : TRUE = ENABLE icon, FALSE = DISABLE icon
// string : the sprite name to display
// byte : red
// byte : green
// byte : blue
int CHudStatusIcons::MsgFunc_StatusIcon( const char *pszName, int iSize, void *pbuf )
{
BEGIN_READ( pbuf, iSize );
int ShouldEnable = READ_BYTE();
char *pszIconName = READ_STRING();
2016-07-03 15:39:55 +02:00
if( ShouldEnable )
2016-06-04 15:24:23 +02:00
{
int r = READ_BYTE();
int g = READ_BYTE();
int b = READ_BYTE();
EnableIcon( pszIconName, r, g, b );
m_iFlags |= HUD_ACTIVE;
}
else
{
DisableIcon( pszIconName );
}
return 1;
}
// add the icon to the icon list, and set it's drawing color
2017-06-29 15:56:03 +02:00
void CHudStatusIcons::EnableIcon( const char *pszIconName, unsigned char red, unsigned char green, unsigned char blue )
2016-06-04 15:24:23 +02:00
{
2016-04-17 22:30:05 +02:00
int i;
2016-06-04 15:24:23 +02:00
// check to see if the sprite is in the current list
2016-07-03 15:39:55 +02:00
for( i = 0; i < MAX_ICONSPRITES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
if( !stricmp( m_IconList[i].szSpriteName, pszIconName ) )
2016-06-04 15:24:23 +02:00
break;
}
2016-07-03 15:39:55 +02:00
if( i == MAX_ICONSPRITES )
2016-06-04 15:24:23 +02:00
{
// icon not in list, so find an empty slot to add to
2016-07-03 15:39:55 +02:00
for( i = 0; i < MAX_ICONSPRITES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
if( !m_IconList[i].spr )
2016-06-04 15:24:23 +02:00
break;
}
}
// if we've run out of space in the list, overwrite the first icon
2016-07-03 15:39:55 +02:00
if( i == MAX_ICONSPRITES )
2016-06-04 15:24:23 +02:00
{
i = 0;
}
// Load the sprite and add it to the list
// the sprite must be listed in hud.txt
int spr_index = gHUD.GetSpriteIndex( pszIconName );
m_IconList[i].spr = gHUD.GetSprite( spr_index );
m_IconList[i].rc = gHUD.GetSpriteRect( spr_index );
m_IconList[i].r = red;
m_IconList[i].g = green;
m_IconList[i].b = blue;
strcpy( m_IconList[i].szSpriteName, pszIconName );
// Hack: Play Timer sound when a grenade icon is played (in 0.8 seconds)
2016-07-03 15:39:55 +02:00
if( strstr(m_IconList[i].szSpriteName, "grenade") )
2016-06-04 15:24:23 +02:00
{
cl_entity_t *pthisplayer = gEngfuncs.GetLocalPlayer();
gEngfuncs.pEventAPI->EV_PlaySound( pthisplayer->index, pthisplayer->origin, CHAN_STATIC, "weapons/timer.wav", 1.0, ATTN_NORM, 0, PITCH_NORM );
}
}
2017-06-29 15:56:03 +02:00
void CHudStatusIcons::DisableIcon( const char *pszIconName )
2016-06-04 15:24:23 +02:00
{
// find the sprite is in the current list
2016-07-03 15:39:55 +02:00
for( int i = 0; i < MAX_ICONSPRITES; i++ )
2016-06-04 15:24:23 +02:00
{
2016-07-03 15:39:55 +02:00
if( !stricmp( m_IconList[i].szSpriteName, pszIconName ) )
2016-06-04 15:24:23 +02:00
{
// clear the item from the list
2016-07-03 15:39:55 +02:00
memset( &m_IconList[i], 0, sizeof(icon_sprite_t) );
2016-06-04 15:24:23 +02:00
return;
}
}
}