cs16-client-legacy/cl_dll/timer.cpp

136 lines
3.0 KiB
C++

#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "hud.h"
#include "cl_util.h"
#include "parsemsg.h"
#include <string.h>
DECLARE_MESSAGE( m_Timer, RoundTime )
DECLARE_MESSAGE( m_Timer, ShowTimer )
int CHudTimer::Init()
{
HOOK_MESSAGE( RoundTime );
HOOK_MESSAGE( ShowTimer );
m_iFlags = 0;
gHUD.AddHudElem(this);
return 1;
}
int CHudTimer::VidInit()
{
m_HUD_timer = gHUD.GetSpriteIndex( "stopwatch" );
return 1;
}
int CHudTimer::Draw( float fTime )
{
if ( ( gHUD.m_iHideHUDDisplay & HIDEHUD_HEALTH ) )
return 1;
if (!(gHUD.m_iWeaponBits & (1<<(WEAPON_SUIT)) ))
return 1;
int r, g, b;
UnpackRGB(r,g,b, RGB_YELLOWISH);
int iWatchWidth = gHUD.GetSpriteRect(m_HUD_timer).right - gHUD.GetSpriteRect(m_HUD_timer).left;
int x = ScreenWidth/2;
int y = ScreenHeight - 1.5 * gHUD.m_iFontHeight ;
SPR_Set(gHUD.GetSprite(m_HUD_timer), r, g, b);
SPR_DrawAdditive(0, x, y, &gHUD.GetSpriteRect(m_HUD_timer));
int minutes = (int)( Time + StartTime - gHUD.m_flTime ) / 60;
int seconds = (int)( Time + StartTime - gHUD.m_flTime ) - (minutes * 60);
if( minutes < 0 )
minutes = 0;
if( seconds < 0 )
seconds = 0;
x = gHUD.DrawHudNumber2( x + iWatchWidth, y, false, 2, minutes, r, g, b );
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);
gHUD.DrawHudNumber2( x + iWatchWidth / 2, y, true, 2, seconds, r, g, b );
return 1;
}
int CHudTimer::MsgFunc_RoundTime(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ( pbuf, iSize );
Time = READ_SHORT();
StartTime = gHUD.m_flTime;
m_iFlags = HUD_ACTIVE;
return 1;
}
int CHudTimer::MsgFunc_ShowTimer(const char *pszName, int iSize, void *pbuf)
{
m_iFlags = HUD_ACTIVE;
return 1;
}
DECLARE_MESSAGE( m_ProgressBar, BarTime )
DECLARE_MESSAGE( m_ProgressBar, BarTime2 )
int CHudProgressBar::Init()
{
HOOK_MESSAGE( BarTime );
HOOK_MESSAGE( BarTime2 );
m_iFlags = 0;
gHUD.AddHudElem(this);
return 1;
}
int CHudProgressBar::VidInit()
{
return 1;
}
int CHudProgressBar::Draw( float flTime )
{
if( Percent >= 1.0f )
{
m_iFlags = 0;
return 1;
}
Percent = ((flTime - StartTime) / Duration);
gHUD.DrawDarkRectangle( ScreenWidth/4, ScreenHeight*2/3, ScreenWidth/2, ScreenHeight/30 );
FillRGBA( ScreenWidth/4+2, ScreenHeight*2/3+2, Percent * (ScreenWidth/2-4), ScreenHeight/30-4, 255, 140, 0, 255 );
return 1;
}
int CHudProgressBar::MsgFunc_BarTime(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ( pbuf, iSize );
Duration = READ_SHORT();
Percent = 0.0f;
StartTime = gHUD.m_flTime;
m_iFlags = HUD_ACTIVE;
return 1;
}
int CHudProgressBar::MsgFunc_BarTime2(const char *pszName, int iSize, void *pbuf)
{
BEGIN_READ( pbuf, iSize );
Duration = READ_SHORT();
Percent = (float)READ_SHORT() / 100.0f;
StartTime = gHUD.m_flTime;
m_iFlags = HUD_ACTIVE;
return 1;
}