2015-10-31 01:35:03 +03:00
|
|
|
#include "stdio.h"
|
|
|
|
#include "stdlib.h"
|
|
|
|
#include "math.h"
|
|
|
|
|
|
|
|
#include "hud.h"
|
|
|
|
#include "cl_util.h"
|
|
|
|
#include "parsemsg.h"
|
2016-02-17 13:35:40 +03:00
|
|
|
#include "vgui_parser.h"
|
2015-10-31 01:35:03 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
DECLARE_MESSAGE( m_Timer, RoundTime )
|
|
|
|
DECLARE_MESSAGE( m_Timer, ShowTimer )
|
|
|
|
|
|
|
|
int CHudTimer::Init()
|
|
|
|
{
|
|
|
|
HOOK_MESSAGE( RoundTime );
|
|
|
|
HOOK_MESSAGE( ShowTimer );
|
2015-11-07 18:58:27 +03:00
|
|
|
m_iFlags = 0;
|
2015-11-08 01:25:23 +03:00
|
|
|
m_bPanicColorChange = false;
|
2015-10-31 01:35:03 +03:00
|
|
|
gHUD.AddHudElem(this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHudTimer::VidInit()
|
|
|
|
{
|
|
|
|
m_HUD_timer = gHUD.GetSpriteIndex( "stopwatch" );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHudTimer::Draw( float fTime )
|
|
|
|
{
|
2015-11-07 18:58:27 +03:00
|
|
|
if ( ( gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH ) )
|
2015-10-31 01:35:03 +03:00
|
|
|
return 1;
|
2015-11-07 18:58:27 +03:00
|
|
|
|
|
|
|
if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) ))
|
|
|
|
return 1;
|
2015-10-31 01:35:03 +03:00
|
|
|
int r, g, b;
|
2015-11-08 01:25:23 +03:00
|
|
|
// time must be positive
|
|
|
|
int minutes = max( 0, (int)( m_iTime + m_fStartTime - gHUD.m_flTime ) / 60);
|
|
|
|
int seconds = max( 0, (int)( m_iTime + m_fStartTime - gHUD.m_flTime ) - (minutes * 60));
|
|
|
|
|
2015-12-28 22:08:34 +03:00
|
|
|
if( minutes * 60 + seconds > 20 )
|
2015-11-08 01:25:23 +03:00
|
|
|
{
|
2016-02-23 20:14:24 +03:00
|
|
|
DrawUtils::UnpackRGB(r,g,b, RGB_YELLOWISH );
|
2015-11-08 01:25:23 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_flPanicTime += gHUD.m_flTimeDelta;
|
2016-02-17 12:13:27 +03:00
|
|
|
// add 0.1 sec, so it's not flicker fast
|
|
|
|
if( m_flPanicTime > ((float)seconds / 40.0f) + 0.1f)
|
2015-11-08 01:25:23 +03:00
|
|
|
{
|
|
|
|
m_flPanicTime = 0;
|
|
|
|
m_bPanicColorChange = !m_bPanicColorChange;
|
|
|
|
}
|
2016-02-23 20:14:24 +03:00
|
|
|
DrawUtils::UnpackRGB( r, g, b, m_bPanicColorChange ? RGB_YELLOWISH : RGB_REDISH );
|
2015-11-08 01:25:23 +03:00
|
|
|
}
|
|
|
|
|
2016-02-23 20:14:24 +03:00
|
|
|
DrawUtils::ScaleColors( r, g, b, MIN_ALPHA );
|
2015-12-28 22:08:34 +03:00
|
|
|
|
2015-10-31 01:35:03 +03:00
|
|
|
|
|
|
|
int iWatchWidth = gHUD.GetSpriteRect(m_HUD_timer).right - gHUD.GetSpriteRect(m_HUD_timer).left;
|
|
|
|
|
|
|
|
int x = ScreenWidth/2;
|
2015-11-07 18:58:27 +03:00
|
|
|
int y = ScreenHeight - 1.5 * gHUD.m_iFontHeight ;
|
2015-10-31 01:35:03 +03:00
|
|
|
|
|
|
|
SPR_Set(gHUD.GetSprite(m_HUD_timer), r, g, b);
|
|
|
|
SPR_DrawAdditive(0, x, y, &gHUD.GetSpriteRect(m_HUD_timer));
|
2015-11-08 01:25:23 +03:00
|
|
|
|
2016-02-23 20:14:24 +03:00
|
|
|
x = DrawUtils::DrawHudNumber2( x + iWatchWidth / 4, y, false, 2, minutes, r, g, b );
|
2015-12-28 22:08:34 +03:00
|
|
|
// draw :
|
2015-11-07 18:58:27 +03:00
|
|
|
FillRGBA(x + iWatchWidth / 4, y + gHUD.m_iFontHeight / 4, 2, 2, r, g, b, 100);
|
|
|
|
FillRGBA(x + iWatchWidth / 4, y + gHUD.m_iFontHeight - gHUD.m_iFontHeight / 4, 2, 2, r, g, b, 100);
|
2015-12-28 22:08:34 +03:00
|
|
|
|
2016-02-23 20:14:24 +03:00
|
|
|
DrawUtils::DrawHudNumber2( x + iWatchWidth / 2, y, true, 2, seconds, r, g, b );
|
2015-10-31 01:35:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHudTimer::MsgFunc_RoundTime(const char *pszName, int iSize, void *pbuf)
|
|
|
|
{
|
|
|
|
BEGIN_READ( pbuf, iSize );
|
2015-11-08 01:25:23 +03:00
|
|
|
m_iTime = READ_SHORT();
|
|
|
|
m_fStartTime = gHUD.m_flTime;
|
2015-11-07 18:58:27 +03:00
|
|
|
m_iFlags = HUD_ACTIVE;
|
2015-10-31 01:35:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHudTimer::MsgFunc_ShowTimer(const char *pszName, int iSize, void *pbuf)
|
|
|
|
{
|
2015-11-07 18:58:27 +03:00
|
|
|
m_iFlags = HUD_ACTIVE;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-11-22 20:09:42 +03:00
|
|
|
#define UPDATE_BOTPROGRESS 0
|
|
|
|
#define CREATE_BOTPROGRESS 1
|
|
|
|
#define REMOVE_BOTPROGRESS 2
|
|
|
|
|
2015-11-07 18:58:27 +03:00
|
|
|
DECLARE_MESSAGE( m_ProgressBar, BarTime )
|
|
|
|
DECLARE_MESSAGE( m_ProgressBar, BarTime2 )
|
2015-11-22 20:09:42 +03:00
|
|
|
DECLARE_MESSAGE( m_ProgressBar, BotProgress )
|
2015-11-07 18:58:27 +03:00
|
|
|
|
|
|
|
int CHudProgressBar::Init()
|
|
|
|
{
|
|
|
|
HOOK_MESSAGE( BarTime );
|
|
|
|
HOOK_MESSAGE( BarTime2 );
|
2015-11-22 20:09:42 +03:00
|
|
|
HOOK_MESSAGE( BotProgress );
|
2015-11-07 18:58:27 +03:00
|
|
|
m_iFlags = 0;
|
2016-02-17 13:35:40 +03:00
|
|
|
m_szLocalizedHeader = NULL;
|
|
|
|
m_szHeader[0] = '\0';
|
|
|
|
m_fStartTime = m_fPercent = 0.0f;
|
2015-11-07 18:58:27 +03:00
|
|
|
|
|
|
|
gHUD.AddHudElem(this);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHudProgressBar::VidInit()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHudProgressBar::Draw( float flTime )
|
|
|
|
{
|
2015-11-22 20:09:42 +03:00
|
|
|
// allow only 0.0..1.0
|
|
|
|
if( (m_fPercent < 0.0f) || (m_fPercent > 1.0f) )
|
2015-11-07 18:58:27 +03:00
|
|
|
{
|
|
|
|
m_iFlags = 0;
|
2015-11-22 20:09:42 +03:00
|
|
|
m_fPercent = 0.0f;
|
2015-11-07 18:58:27 +03:00
|
|
|
return 1;
|
2015-11-22 20:09:42 +03:00
|
|
|
}
|
2016-02-17 13:35:40 +03:00
|
|
|
|
|
|
|
if( m_szLocalizedHeader && m_szLocalizedHeader[0] )
|
2015-11-22 20:09:42 +03:00
|
|
|
{
|
|
|
|
int r, g, b;
|
2016-02-23 20:14:24 +03:00
|
|
|
DrawUtils::UnpackRGB( r, g, b, RGB_YELLOWISH );
|
|
|
|
DrawUtils::DrawHudString( ScreenWidth / 4, ScreenHeight / 2, ScreenWidth, (char*)m_szLocalizedHeader, r, g, b );
|
2015-11-07 18:58:27 +03:00
|
|
|
|
2016-02-23 20:14:24 +03:00
|
|
|
DrawUtils::DrawRectangle( ScreenWidth/ 4, ScreenHeight / 2 + gHUD.m_scrinfo.iCharHeight, ScreenWidth/2, ScreenHeight/30 );
|
2016-02-17 13:35:40 +03:00
|
|
|
FillRGBA( ScreenWidth/4+2, ScreenHeight/2 + gHUD.m_scrinfo.iCharHeight + 2, m_fPercent * (ScreenWidth/2-4), ScreenHeight/30-4, 255, 140, 0, 255 );
|
2015-11-22 20:09:42 +03:00
|
|
|
return 1;
|
2015-11-07 18:58:27 +03:00
|
|
|
}
|
|
|
|
|
2015-11-22 20:09:42 +03:00
|
|
|
// prevent SIGFPE
|
|
|
|
if( m_iDuration != 0.0f )
|
|
|
|
{
|
|
|
|
m_fPercent = ((flTime - m_fStartTime) / m_iDuration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_fPercent = 0.0f;
|
|
|
|
m_iFlags = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-23 20:14:24 +03:00
|
|
|
DrawUtils::DrawRectangle( ScreenWidth/4, ScreenHeight*2/3, ScreenWidth/2, 10 );
|
2015-11-22 20:09:42 +03:00
|
|
|
FillRGBA( ScreenWidth/4+2, ScreenHeight*2/3+2, m_fPercent * (ScreenWidth/2-4), 6, 255, 140, 0, 255 );
|
2015-11-07 18:58:27 +03:00
|
|
|
|
2015-10-31 01:35:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-11-07 18:58:27 +03:00
|
|
|
int CHudProgressBar::MsgFunc_BarTime(const char *pszName, int iSize, void *pbuf)
|
2015-10-31 01:35:03 +03:00
|
|
|
{
|
2015-11-07 18:58:27 +03:00
|
|
|
BEGIN_READ( pbuf, iSize );
|
|
|
|
|
2015-11-22 20:09:42 +03:00
|
|
|
m_iDuration = READ_SHORT();
|
|
|
|
m_fPercent = 0.0f;
|
2015-11-07 18:58:27 +03:00
|
|
|
|
2015-11-22 20:09:42 +03:00
|
|
|
m_fStartTime = gHUD.m_flTime;
|
2015-11-07 18:58:27 +03:00
|
|
|
|
|
|
|
m_iFlags = HUD_ACTIVE;
|
2015-10-31 01:35:03 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-11-07 18:58:27 +03:00
|
|
|
int CHudProgressBar::MsgFunc_BarTime2(const char *pszName, int iSize, void *pbuf)
|
|
|
|
{
|
|
|
|
BEGIN_READ( pbuf, iSize );
|
|
|
|
|
2015-11-22 20:09:42 +03:00
|
|
|
m_iDuration = READ_SHORT();
|
|
|
|
m_fPercent = (float)READ_SHORT() / 100.0f;
|
2015-11-07 18:58:27 +03:00
|
|
|
|
2015-11-22 20:09:42 +03:00
|
|
|
m_fStartTime = gHUD.m_flTime;
|
|
|
|
|
|
|
|
m_iFlags = HUD_ACTIVE;
|
|
|
|
return 1;
|
|
|
|
}
|
2015-11-07 18:58:27 +03:00
|
|
|
|
2015-11-22 20:09:42 +03:00
|
|
|
int CHudProgressBar::MsgFunc_BotProgress(const char *pszName, int iSize, void *pbuf)
|
|
|
|
{
|
|
|
|
BEGIN_READ( pbuf, iSize );
|
|
|
|
m_iDuration = 0.0f; // don't update our progress bar
|
2015-11-07 18:58:27 +03:00
|
|
|
m_iFlags = HUD_ACTIVE;
|
2015-11-22 20:09:42 +03:00
|
|
|
|
2016-02-17 13:35:40 +03:00
|
|
|
float fNewPercent;
|
2015-11-22 20:09:42 +03:00
|
|
|
int flag = READ_BYTE();
|
|
|
|
switch( flag )
|
|
|
|
{
|
|
|
|
case UPDATE_BOTPROGRESS:
|
|
|
|
case CREATE_BOTPROGRESS:
|
2016-02-17 13:35:40 +03:00
|
|
|
fNewPercent = (float)READ_BYTE() / 100.0f;
|
|
|
|
// cs behavior:
|
|
|
|
// just don't decrease percent values
|
|
|
|
if( m_fPercent < fNewPercent )
|
|
|
|
{
|
|
|
|
m_fPercent = fNewPercent;
|
|
|
|
}
|
2015-11-22 20:09:42 +03:00
|
|
|
strncpy(m_szHeader, READ_STRING(), sizeof(m_szHeader));
|
2016-02-17 13:35:40 +03:00
|
|
|
m_szLocalizedHeader = Localize(m_szHeader + 1);
|
2015-11-22 20:09:42 +03:00
|
|
|
break;
|
|
|
|
case REMOVE_BOTPROGRESS:
|
2016-02-17 13:35:40 +03:00
|
|
|
default:
|
2015-11-22 20:09:42 +03:00
|
|
|
m_fPercent = 0.0f;
|
|
|
|
m_szHeader[0] = '\0';
|
|
|
|
m_iFlags = 0;
|
2016-02-17 13:35:40 +03:00
|
|
|
m_szLocalizedHeader = NULL;
|
2015-11-22 20:09:42 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-07 18:58:27 +03:00
|
|
|
return 1;
|
|
|
|
}
|