2016-03-05 20:29:55 +01: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.
|
|
|
|
*
|
|
|
|
****/
|
|
|
|
//
|
|
|
|
// hud.cpp
|
|
|
|
//
|
|
|
|
// implementation of CHud class
|
|
|
|
//
|
|
|
|
|
2016-10-16 01:07:43 +02:00
|
|
|
#include <new>
|
|
|
|
|
2016-03-05 20:29:55 +01:00
|
|
|
#include "hud.h"
|
|
|
|
#include "cl_util.h"
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include "parsemsg.h"
|
|
|
|
|
|
|
|
#include "demo.h"
|
|
|
|
#include "demo_api.h"
|
|
|
|
#include "vgui_parser.h"
|
|
|
|
#include "rain.h"
|
|
|
|
|
2016-03-20 18:42:55 +01:00
|
|
|
#include "camera.h"
|
2016-03-05 20:29:55 +01:00
|
|
|
|
2016-07-03 20:43:32 +02:00
|
|
|
|
2016-03-05 20:29:55 +01:00
|
|
|
extern client_sprite_t *GetSpriteList(client_sprite_t *pList, const char *psz, int iRes, int iCount);
|
|
|
|
|
|
|
|
wrect_t nullrc = { 0, 0, 0, 0 };
|
2016-07-22 14:11:35 +02:00
|
|
|
float g_lastFOV = 0.0;
|
2016-03-12 21:10:18 +01:00
|
|
|
const char *sPlayerModelFiles[12] =
|
2016-03-05 20:29:55 +01:00
|
|
|
{
|
|
|
|
"models/player.mdl",
|
|
|
|
"models/player/leet/leet.mdl", // t
|
|
|
|
"models/player/gign/gign.mdl", // ct
|
|
|
|
"models/player/vip/vip.mdl", //ct
|
|
|
|
"models/player/gsg9/gsg9.mdl", // ct
|
|
|
|
"models/player/guerilla/guerilla.mdl", // t
|
|
|
|
"models/player/arctic/arctic.mdl", // t
|
|
|
|
"models/player/sas/sas.mdl", // ct
|
|
|
|
"models/player/terror/terror.mdl", // t
|
|
|
|
"models/player/urban/urban.mdl", // ct
|
|
|
|
"models/player/spetsnaz/spetsnaz.mdl", // ct
|
|
|
|
"models/player/militia/militia.mdl" // t
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GHUD_DECLARE_MESSAGE(x) int __MsgFunc_##x(const char *pszName, int iSize, void *pbuf ) { return gHUD.MsgFunc_##x(pszName, iSize, pbuf); }
|
|
|
|
|
|
|
|
GHUD_DECLARE_MESSAGE(Logo)
|
|
|
|
GHUD_DECLARE_MESSAGE(SetFOV)
|
|
|
|
GHUD_DECLARE_MESSAGE(InitHUD)
|
|
|
|
GHUD_DECLARE_MESSAGE(Concuss)
|
|
|
|
GHUD_DECLARE_MESSAGE(ResetHUD)
|
|
|
|
GHUD_DECLARE_MESSAGE(ViewMode)
|
|
|
|
GHUD_DECLARE_MESSAGE(GameMode)
|
|
|
|
GHUD_DECLARE_MESSAGE(ShadowIdx)
|
|
|
|
|
|
|
|
void __CmdFunc_InputCommandSpecial()
|
|
|
|
{
|
2016-04-16 21:02:14 +02:00
|
|
|
#ifdef _CS16CLIENT_ALLOW_SPECIAL_SCRIPTING
|
2016-03-05 20:29:55 +01:00
|
|
|
gEngfuncs.pfnClientCmd("_special");
|
|
|
|
#endif
|
2016-04-16 21:02:14 +02:00
|
|
|
}
|
2016-03-05 20:29:55 +01:00
|
|
|
|
2016-10-26 20:13:23 +02:00
|
|
|
void __CmdFunc_GunSmoke()
|
|
|
|
{
|
|
|
|
if( gHUD.cl_gunsmoke->value )
|
|
|
|
gEngfuncs.Cvar_SetValue( "cl_gunsmoke", 0 );
|
|
|
|
else
|
|
|
|
gEngfuncs.Cvar_SetValue( "cl_gunsmoke", 1 );
|
|
|
|
}
|
|
|
|
|
2016-10-10 20:13:44 +02:00
|
|
|
#define XASH_GENERATE_BUILDNUM
|
|
|
|
|
|
|
|
#if defined(XASH_GENERATE_BUILDNUM)
|
|
|
|
static const char *date = __DATE__;
|
|
|
|
static const char *mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
|
|
|
|
static char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
char *Q_buildnum( void )
|
|
|
|
{
|
|
|
|
// do not touch this! Only author of Xash3D can increase buildnumbers!
|
|
|
|
// Xash3D SDL: HAHAHA! I TOUCHED THIS!
|
|
|
|
int m = 0, d = 0, y = 0;
|
|
|
|
static int b = 0;
|
|
|
|
static char buildnum[16];
|
|
|
|
|
|
|
|
if( b != 0 )
|
|
|
|
return buildnum;
|
|
|
|
|
|
|
|
for( m = 0; m < 11; m++ )
|
|
|
|
{
|
|
|
|
if( !strncasecmp( &date[0], mon[m], 3 ))
|
|
|
|
break;
|
|
|
|
d += mond[m];
|
|
|
|
}
|
|
|
|
|
|
|
|
d += atoi( &date[4] ) - 1;
|
|
|
|
y = atoi( &date[7] ) - 1900;
|
|
|
|
b = d + (int)((y - 1) * 365.25f );
|
|
|
|
|
|
|
|
if((( y % 4 ) == 0 ) && m > 1 )
|
|
|
|
{
|
|
|
|
b += 1;
|
|
|
|
}
|
|
|
|
//b -= 38752; // Feb 13 2007
|
|
|
|
b -= 41940; // Oct 29 2015.
|
|
|
|
// Happy birthday, cs16client! :)
|
|
|
|
|
|
|
|
snprintf( buildnum, sizeof(buildnum), "%i", b );
|
|
|
|
|
|
|
|
return buildnum;
|
|
|
|
}
|
|
|
|
|
2016-10-29 00:12:37 +02:00
|
|
|
int __MsgFunc_ADStop( const char *name, int size, void *buf ) { return 1; }
|
|
|
|
int __MsgFunc_ItemStatus( const char *name, int size, void *buf ) { return 1; }
|
|
|
|
int __MsgFunc_ReqState( const char *name, int size, void *buf ) { return 1; }
|
|
|
|
int __MsgFunc_ForceCam( const char *name, int size, void *buf ) { return 1; }
|
|
|
|
int __MsgFunc_Spectator( const char *name, int size, void *buf ) { return 1; }
|
|
|
|
int __MsgFunc_ServerName( const char *name, int size, void *buf )
|
|
|
|
{
|
|
|
|
BufferReader reader( name, buf, size );
|
|
|
|
strncpy( gHUD.m_szServerName, reader.ReadString(), 64 );
|
|
|
|
return 1;
|
|
|
|
}
|
2016-10-10 20:13:44 +02:00
|
|
|
|
2016-12-09 21:40:09 +01:00
|
|
|
#ifdef __ANDROID__
|
2016-12-09 22:56:58 +01:00
|
|
|
bool evdev_open = false;
|
|
|
|
void __CmdFunc_MouseSucksOpen( void ) { evdev_open = true; }
|
|
|
|
void __CmdFunc_MouseSucksClose( void ) { evdev_open = false; }
|
2016-12-09 21:40:09 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2016-03-05 20:29:55 +01:00
|
|
|
// This is called every time the DLL is loaded
|
|
|
|
void CHud :: Init( void )
|
|
|
|
{
|
|
|
|
HOOK_COMMAND( "special", InputCommandSpecial );
|
2016-10-26 20:13:23 +02:00
|
|
|
//HOOK_COMMAND( "gunsmoke", GunSmoke );
|
2016-03-05 20:29:55 +01:00
|
|
|
|
2016-12-09 21:40:09 +01:00
|
|
|
#ifdef __ANDROID__
|
2016-12-09 22:56:58 +01:00
|
|
|
HOOK_COMMAND( "evdev_mouseopen", MouseSucksOpen );
|
|
|
|
HOOK_COMMAND( "evdev_mouseclose", MouseSucksClose );
|
2016-12-09 21:40:09 +01:00
|
|
|
#endif
|
|
|
|
|
2016-03-05 20:29:55 +01:00
|
|
|
HOOK_MESSAGE( Logo );
|
|
|
|
HOOK_MESSAGE( ResetHUD );
|
|
|
|
HOOK_MESSAGE( GameMode );
|
|
|
|
HOOK_MESSAGE( InitHUD );
|
|
|
|
HOOK_MESSAGE( ViewMode );
|
|
|
|
HOOK_MESSAGE( SetFOV );
|
|
|
|
HOOK_MESSAGE( Concuss );
|
|
|
|
|
2016-10-29 00:12:37 +02:00
|
|
|
HOOK_MESSAGE( ADStop );
|
|
|
|
HOOK_MESSAGE( ItemStatus );
|
|
|
|
HOOK_MESSAGE( ReqState );
|
|
|
|
HOOK_MESSAGE( ForceCam );
|
|
|
|
HOOK_MESSAGE( Spectator ); // ignored due to touch menus
|
|
|
|
HOOK_MESSAGE( ServerName );
|
|
|
|
|
|
|
|
|
2016-03-05 20:29:55 +01:00
|
|
|
HOOK_MESSAGE( ShadowIdx );
|
|
|
|
|
2016-03-20 18:42:55 +01:00
|
|
|
CVAR_CREATE( "_vgui_menus", "1", FCVAR_ARCHIVE | FCVAR_USERINFO );
|
2016-03-05 20:29:55 +01:00
|
|
|
CVAR_CREATE( "_cl_autowepswitch", "1", FCVAR_ARCHIVE | FCVAR_USERINFO );
|
2016-03-20 18:42:55 +01:00
|
|
|
CVAR_CREATE( "_ah", "0", FCVAR_ARCHIVE | FCVAR_USERINFO );
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
hud_textmode = CVAR_CREATE( "hud_textmode", "0", FCVAR_ARCHIVE );
|
2016-10-11 23:43:50 +02:00
|
|
|
hud_colored = CVAR_CREATE( "hud_colored", "0", FCVAR_ARCHIVE );
|
2016-03-05 20:29:55 +01:00
|
|
|
cl_righthand = CVAR_CREATE( "hand", "1", FCVAR_ARCHIVE );
|
2016-03-20 18:42:55 +01:00
|
|
|
cl_weather = CVAR_CREATE( "cl_weather", "1", FCVAR_ARCHIVE );
|
2016-04-16 21:02:14 +02:00
|
|
|
cl_minmodels = CVAR_CREATE( "cl_minmodels", "0", FCVAR_ARCHIVE );
|
2016-03-05 20:29:55 +01:00
|
|
|
cl_min_t = CVAR_CREATE( "cl_min_t", "1", FCVAR_ARCHIVE );
|
2016-04-16 21:02:14 +02:00
|
|
|
cl_min_ct = CVAR_CREATE( "cl_min_ct", "2", FCVAR_ARCHIVE );
|
2016-03-05 20:29:55 +01:00
|
|
|
cl_lw = gEngfuncs.pfnGetCvarPointer( "cl_lw" );
|
2016-04-18 17:00:45 +02:00
|
|
|
cl_predict = gEngfuncs.pfnGetCvarPointer( "cl_predict" );
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
cl_android_force_defaults = CVAR_CREATE( "cl_android_force_defaults", "1", FCVAR_ARCHIVE );
|
|
|
|
#endif
|
2016-03-05 20:29:55 +01:00
|
|
|
cl_shadows = CVAR_CREATE( "cl_shadows", "1", FCVAR_ARCHIVE );
|
|
|
|
default_fov = CVAR_CREATE( "default_fov", "90", 0 );
|
|
|
|
m_pCvarDraw = CVAR_CREATE( "hud_draw", "1", FCVAR_ARCHIVE );
|
2016-04-16 21:02:14 +02:00
|
|
|
fastsprites = CVAR_CREATE( "fastsprites", "0", FCVAR_ARCHIVE );
|
2016-10-26 20:13:23 +02:00
|
|
|
cl_gunsmoke = CVAR_CREATE( "cl_gunsmoke", "0", FCVAR_ARCHIVE );
|
2016-06-11 22:03:57 +02:00
|
|
|
cl_weapon_sparks = CVAR_CREATE( "cl_weapon_sparks", "1", FCVAR_ARCHIVE );
|
|
|
|
cl_weapon_wallpuff = CVAR_CREATE( "cl_weapon_wallpuff", "1", FCVAR_ARCHIVE );
|
2016-07-03 20:43:32 +02:00
|
|
|
zoom_sens_ratio = CVAR_CREATE( "zoom_sensitivity_ratio", "1.2", 0 );
|
2016-10-26 23:42:28 +02:00
|
|
|
sv_skipshield = gEngfuncs.pfnGetCvarPointer( "sv_skipshield" );
|
2016-10-26 20:13:23 +02:00
|
|
|
|
2016-10-10 20:13:44 +02:00
|
|
|
CVAR_CREATE( "cscl_ver", Q_buildnum(), 1<<14 | FCVAR_USERINFO ); // init and userinfo
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
m_iLogo = 0;
|
|
|
|
m_iFOV = 0;
|
|
|
|
|
|
|
|
m_pSpriteList = NULL;
|
|
|
|
|
|
|
|
// Clear any old HUD list
|
2016-07-03 20:43:32 +02:00
|
|
|
for( HUDLIST *pList = m_pHudList; pList; pList = m_pHudList )
|
2016-03-05 20:29:55 +01:00
|
|
|
{
|
2016-07-03 20:43:32 +02:00
|
|
|
m_pHudList = m_pHudList->pNext;
|
|
|
|
delete pList;
|
2016-03-05 20:29:55 +01:00
|
|
|
}
|
2016-07-03 20:43:32 +02:00
|
|
|
m_pHudList = NULL;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
// In case we get messages before the first update -- time will be valid
|
|
|
|
m_flTime = 1.0;
|
|
|
|
m_iNoConsolePrint = 0;
|
2016-10-29 00:12:37 +02:00
|
|
|
m_szServerName[0] = 0;
|
2016-03-20 00:40:36 +01:00
|
|
|
|
|
|
|
Localize_Init();
|
|
|
|
|
2016-03-05 20:29:55 +01:00
|
|
|
// fullscreen overlays
|
|
|
|
m_SniperScope.Init();
|
|
|
|
m_NVG.Init();
|
2016-03-16 18:44:51 +01:00
|
|
|
m_SpectatorGui.Init();
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
// Game HUD things
|
|
|
|
m_Ammo.Init();
|
|
|
|
m_Health.Init();
|
|
|
|
m_Radio.Init();
|
|
|
|
m_Timer.Init();
|
|
|
|
m_Money.Init();
|
|
|
|
m_AmmoSecondary.Init();
|
|
|
|
m_Train.Init();
|
|
|
|
m_Battery.Init();
|
|
|
|
m_StatusIcons.Init();
|
|
|
|
m_Radar.Init();
|
|
|
|
|
|
|
|
// chat, death notice, status bars and other
|
|
|
|
m_SayText.Init();
|
|
|
|
m_Spectator.Init();
|
|
|
|
m_Geiger.Init();
|
|
|
|
m_Flash.Init();
|
|
|
|
m_Message.Init();
|
|
|
|
m_StatusBar.Init();
|
|
|
|
m_DeathNotice.Init();
|
|
|
|
m_TextMessage.Init();
|
|
|
|
m_MOTD.Init();
|
|
|
|
|
|
|
|
// all things that have own background and must be drawn last
|
|
|
|
m_ProgressBar.Init();
|
|
|
|
m_Menu.Init();
|
|
|
|
m_Scoreboard.Init();
|
|
|
|
|
|
|
|
InitRain();
|
|
|
|
|
|
|
|
//ServersInit();
|
|
|
|
|
2016-04-16 21:02:14 +02:00
|
|
|
gEngfuncs.Cvar_SetValue( "hand", 1 );
|
|
|
|
gEngfuncs.Cvar_SetValue( "sv_skipshield", 1.0f );
|
|
|
|
#ifdef __ANDROID__
|
|
|
|
gEngfuncs.Cvar_SetValue( "hud_fastswitch", 1 );
|
|
|
|
#endif
|
|
|
|
|
2016-03-05 20:29:55 +01:00
|
|
|
MsgFunc_ResetHUD(0, 0, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHud destructor
|
|
|
|
// cleans up memory allocated for m_rg* arrays
|
|
|
|
CHud :: ~CHud()
|
|
|
|
{
|
|
|
|
delete [] m_rghSprites;
|
|
|
|
delete [] m_rgrcRects;
|
|
|
|
delete [] m_rgszSpriteNames;
|
|
|
|
|
2016-07-03 20:43:32 +02:00
|
|
|
// Clear any old HUD list
|
|
|
|
for( HUDLIST *pList = m_pHudList; pList; pList = m_pHudList )
|
2016-03-05 20:29:55 +01:00
|
|
|
{
|
2016-07-03 20:43:32 +02:00
|
|
|
m_pHudList = m_pHudList->pNext;
|
|
|
|
delete pList;
|
2016-03-05 20:29:55 +01:00
|
|
|
}
|
2016-07-03 20:43:32 +02:00
|
|
|
m_pHudList = NULL;
|
2016-03-05 20:29:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CHud :: VidInit( void )
|
|
|
|
{
|
2016-12-09 23:39:49 +01:00
|
|
|
static bool firstinit = true;
|
2016-10-26 14:39:09 +02:00
|
|
|
m_scrinfo.iSize = sizeof( m_scrinfo );
|
|
|
|
GetScreenInfo( &m_scrinfo );
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
m_truescrinfo.iWidth = CVAR_GET_FLOAT("width");
|
|
|
|
m_truescrinfo.iHeight = CVAR_GET_FLOAT("height");
|
|
|
|
|
|
|
|
// ----------
|
|
|
|
// Load Sprites
|
|
|
|
// ---------
|
|
|
|
// m_hsprFont = LoadSprite("sprites/%d_font.spr");
|
|
|
|
|
|
|
|
m_hsprLogo = 0;
|
|
|
|
|
2016-11-17 14:45:54 +01:00
|
|
|
// assume cs16-client is launched in landscape mode
|
|
|
|
// must be only TrueWidth, but due to bug game may sometime rotate to portait mode
|
|
|
|
// calc scale depending on max side
|
|
|
|
float maxScale = (float)max( TrueWidth, TrueHeight ) / 640.0f;
|
|
|
|
|
|
|
|
// REMOVE LATER
|
|
|
|
float currentScale = CVAR_GET_FLOAT("hud_scale");
|
2016-12-09 21:40:09 +01:00
|
|
|
float invalidScale = (float)min( TrueWidth, TrueHeight ) / 640.0f;
|
2016-11-17 14:45:54 +01:00
|
|
|
// REMOVE LATER
|
|
|
|
|
2016-12-09 21:40:09 +01:00
|
|
|
if( currentScale > maxScale ||
|
|
|
|
( currentScale == invalidScale &&
|
|
|
|
currentScale != 1.0f &&
|
|
|
|
currentScale != 0.0f &&
|
|
|
|
invalidScale < 1.0f ) )
|
2016-03-17 23:45:34 +01:00
|
|
|
{
|
2016-10-26 14:39:09 +02:00
|
|
|
gEngfuncs.Cvar_SetValue( "hud_scale", maxScale );
|
|
|
|
gEngfuncs.Con_Printf("^3Maximum scale factor reached. Reset: %f\n", maxScale );
|
|
|
|
GetScreenInfo( &m_scrinfo );
|
2016-03-17 23:45:34 +01:00
|
|
|
}
|
2016-10-18 16:59:12 +02:00
|
|
|
|
|
|
|
m_flScale = CVAR_GET_FLOAT( "hud_scale" );
|
2016-10-11 21:55:27 +02:00
|
|
|
|
|
|
|
// give a real values to other code. It's not anymore an actual CVar value
|
|
|
|
if( m_flScale == 0.0f )
|
|
|
|
m_flScale = 1.0f;
|
|
|
|
|
2016-03-17 23:45:34 +01:00
|
|
|
m_iRes = 640;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
// Only load this once
|
2016-10-26 23:42:28 +02:00
|
|
|
if( !m_pSpriteList )
|
2016-03-05 20:29:55 +01:00
|
|
|
{
|
|
|
|
// we need to load the hud.txt, and all sprites within
|
|
|
|
m_pSpriteList = SPR_GetList("sprites/hud.txt", &m_iSpriteCountAllRes);
|
|
|
|
|
2016-10-26 23:42:28 +02:00
|
|
|
if( m_pSpriteList )
|
2016-03-05 20:29:55 +01:00
|
|
|
{
|
|
|
|
// count the number of sprites of the appropriate res
|
|
|
|
m_iSpriteCount = 0;
|
|
|
|
client_sprite_t *p = m_pSpriteList;
|
2016-10-26 23:42:28 +02:00
|
|
|
for ( int j = 0; j < m_iSpriteCountAllRes; j++ )
|
2016-03-05 20:29:55 +01:00
|
|
|
{
|
|
|
|
if ( p->iRes == m_iRes )
|
|
|
|
m_iSpriteCount++;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocated memory for sprite handle arrays
|
2016-10-26 23:42:28 +02:00
|
|
|
m_rghSprites = new(std::nothrow) HSPRITE[m_iSpriteCount];
|
|
|
|
m_rgrcRects = new(std::nothrow) wrect_t[m_iSpriteCount];
|
|
|
|
m_rgszSpriteNames = new(std::nothrow) char[m_iSpriteCount * MAX_SPRITE_NAME_LENGTH];;
|
|
|
|
|
|
|
|
if( !m_rghSprites || !m_rgrcRects || !m_rgszSpriteNames )
|
|
|
|
{
|
|
|
|
gEngfuncs.pfnConsolePrint("CHud::VidInit(): Cannot allocate memory");
|
|
|
|
if( g_iXash )
|
|
|
|
gRenderAPI.Host_Error("CHud::VidInit(): Cannot allocate memory");
|
|
|
|
}
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
p = m_pSpriteList;
|
2016-10-26 23:42:28 +02:00
|
|
|
for ( int index = 0, j = 0; j < m_iSpriteCountAllRes; j++ )
|
2016-03-05 20:29:55 +01:00
|
|
|
{
|
|
|
|
if ( p->iRes == m_iRes )
|
|
|
|
{
|
|
|
|
char sz[256];
|
|
|
|
sprintf(sz, "sprites/%s.spr", p->szSprite);
|
|
|
|
m_rghSprites[index] = SPR_Load(sz);
|
|
|
|
m_rgrcRects[index] = p->rc;
|
|
|
|
strncpy( &m_rgszSpriteNames[index * MAX_SPRITE_NAME_LENGTH], p->szName, MAX_SPRITE_NAME_LENGTH );
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// we have already have loaded the sprite reference from hud.txt, but
|
|
|
|
// we need to make sure all the sprites have been loaded (we've gone through a transition, or loaded a save game)
|
|
|
|
client_sprite_t *p = m_pSpriteList;
|
|
|
|
int index = 0;
|
|
|
|
for ( int j = 0; j < m_iSpriteCountAllRes; j++ )
|
|
|
|
{
|
|
|
|
if ( p->iRes == m_iRes )
|
|
|
|
{
|
|
|
|
char sz[256];
|
|
|
|
sprintf( sz, "sprites/%s.spr", p->szSprite );
|
|
|
|
m_rghSprites[index] = SPR_Load(sz);
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// assumption: number_1, number_2, etc, are all listed and loaded sequentially
|
|
|
|
m_HUD_number_0 = GetSpriteIndex( "number_0" );
|
|
|
|
|
2016-10-26 23:42:28 +02:00
|
|
|
if( m_HUD_number_0 == -1 && g_iXash )
|
|
|
|
{
|
|
|
|
gRenderAPI.Host_Error( "Failed to get number_0 sprite index. Check your game data!" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_iFontHeight = GetSpriteRect(m_HUD_number_0).bottom - GetSpriteRect(m_HUD_number_0).top;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
2016-04-15 22:50:47 +02:00
|
|
|
m_hGasPuff = SPR_Load("sprites/gas_puff_01.spr");
|
|
|
|
|
2016-10-26 23:42:28 +02:00
|
|
|
|
|
|
|
/*m_Ammo.VidInit();
|
2016-03-05 20:29:55 +01:00
|
|
|
m_Health.VidInit();
|
|
|
|
m_Spectator.VidInit();
|
|
|
|
m_Geiger.VidInit();
|
|
|
|
m_Train.VidInit();
|
|
|
|
m_Battery.VidInit();
|
|
|
|
m_Flash.VidInit();
|
|
|
|
m_Message.VidInit();
|
|
|
|
m_StatusBar.VidInit();
|
|
|
|
m_DeathNotice.VidInit();
|
|
|
|
m_SayText.VidInit();
|
|
|
|
m_Menu.VidInit();
|
|
|
|
m_AmmoSecondary.VidInit();
|
|
|
|
m_TextMessage.VidInit();
|
|
|
|
m_StatusIcons.VidInit();
|
|
|
|
m_Scoreboard.VidInit();
|
|
|
|
m_MOTD.VidInit();
|
|
|
|
m_Timer.VidInit();
|
|
|
|
m_Money.VidInit();
|
|
|
|
m_ProgressBar.VidInit();
|
|
|
|
m_SniperScope.VidInit();
|
|
|
|
m_Radar.VidInit();
|
2016-10-26 23:42:28 +02:00
|
|
|
m_SpectatorGui.VidInit();*/
|
|
|
|
|
|
|
|
for( HUDLIST *pList = m_pHudList; pList; pList = pList->pNext )
|
|
|
|
pList->p->VidInit();
|
2016-12-09 23:39:49 +01:00
|
|
|
|
|
|
|
if( firstinit && gEngfuncs.CheckParm( "-firsttime", NULL ) )
|
|
|
|
{
|
|
|
|
ConsolePrint( "firstrun\n" );
|
|
|
|
|
|
|
|
ClientCmd( "exec touch_presets/phone_ahsim" );
|
|
|
|
gEngfuncs.Cvar_Set( "touch_config_file", "touch_presets/phone_ahsim.cfg" );
|
|
|
|
}
|
|
|
|
|
|
|
|
firstinit = false;
|
2016-03-05 20:29:55 +01:00
|
|
|
}
|
|
|
|
|
2016-09-16 21:23:18 +02:00
|
|
|
void CHud::Shutdown( void )
|
|
|
|
{
|
2016-09-19 15:20:15 +02:00
|
|
|
for( HUDLIST *pList = m_pHudList; pList; pList = pList->pNext )
|
2016-09-16 21:23:18 +02:00
|
|
|
{
|
|
|
|
pList->p->Shutdown();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-05 20:29:55 +01:00
|
|
|
int CHud::MsgFunc_Logo(const char *pszName, int iSize, void *pbuf)
|
|
|
|
{
|
2016-07-22 14:11:35 +02:00
|
|
|
BufferReader reader( pszName, pbuf, iSize );
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
// update Train data
|
2016-07-07 19:37:15 +02:00
|
|
|
m_iLogo = reader.ReadByte();
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
============
|
|
|
|
COM_FileBase
|
|
|
|
============
|
|
|
|
*/
|
|
|
|
// Extracts the base name of a file (no path, no extension, assumes '/' as path separator)
|
|
|
|
void COM_FileBase ( const char *in, char *out)
|
|
|
|
{
|
|
|
|
int len, start, end;
|
|
|
|
|
|
|
|
len = strlen( in );
|
|
|
|
|
|
|
|
// scan backward for '.'
|
|
|
|
end = len - 1;
|
|
|
|
while ( end && in[end] != '.' && in[end] != '/' && in[end] != '\\' )
|
|
|
|
end--;
|
|
|
|
|
|
|
|
if ( in[end] != '.' ) // no '.', copy to end
|
|
|
|
end = len-1;
|
|
|
|
else
|
|
|
|
end--; // Found ',', copy to left of '.'
|
|
|
|
|
|
|
|
|
|
|
|
// Scan backward for '/'
|
|
|
|
start = len-1;
|
|
|
|
while ( start >= 0 && in[start] != '/' && in[start] != '\\' )
|
|
|
|
start--;
|
|
|
|
|
|
|
|
if ( in[start] != '/' && in[start] != '\\' )
|
|
|
|
start = 0;
|
|
|
|
else
|
|
|
|
start++;
|
|
|
|
|
|
|
|
// Length of new sting
|
|
|
|
len = end - start + 1;
|
|
|
|
|
|
|
|
// Copy partial string
|
|
|
|
strncpy( out, &in[start], len );
|
|
|
|
// Terminate it
|
|
|
|
out[len] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
HUD_IsGame
|
|
|
|
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
int HUD_IsGame( const char *game )
|
|
|
|
{
|
|
|
|
const char *gamedir;
|
|
|
|
char gd[ 1024 ];
|
|
|
|
|
|
|
|
gamedir = gEngfuncs.pfnGetGameDirectory();
|
|
|
|
if ( gamedir && gamedir[0] )
|
|
|
|
{
|
|
|
|
COM_FileBase( gamedir, gd );
|
|
|
|
if ( !stricmp( gd, game ) )
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=====================
|
|
|
|
HUD_GetFOV
|
|
|
|
|
|
|
|
Returns last FOV
|
|
|
|
=====================
|
|
|
|
*/
|
|
|
|
float HUD_GetFOV( void )
|
|
|
|
{
|
|
|
|
if ( gEngfuncs.pDemoAPI->IsRecording() )
|
|
|
|
{
|
|
|
|
// Write it
|
2016-07-03 20:43:32 +02:00
|
|
|
unsigned char buf[ sizeof(float) ];
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
// Active
|
2016-07-03 20:43:32 +02:00
|
|
|
*( float * )&buf = g_lastFOV;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
2016-07-03 20:43:32 +02:00
|
|
|
Demo_WriteBuffer( TYPE_ZOOM, sizeof(float), buf );
|
2016-03-05 20:29:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( gEngfuncs.pDemoAPI->IsPlayingback() )
|
|
|
|
{
|
|
|
|
g_lastFOV = g_demozoom;
|
|
|
|
}
|
|
|
|
return g_lastFOV;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CHud::MsgFunc_SetFOV(const char *pszName, int iSize, void *pbuf)
|
|
|
|
{
|
|
|
|
//Weapon prediction already takes care of changing the fog. ( g_lastFOV ).
|
2016-07-22 14:11:35 +02:00
|
|
|
#if 0 // VALVEWHY: original client checks for "tfc" here.
|
2016-03-05 20:29:55 +01:00
|
|
|
if ( cl_lw && cl_lw->value )
|
|
|
|
return 1;
|
2016-07-22 14:11:35 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
BufferReader reader( pszName, pbuf, iSize );
|
|
|
|
|
|
|
|
int newfov = reader.ReadByte();
|
|
|
|
int def_fov = default_fov->value;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
g_lastFOV = newfov;
|
2016-07-03 20:43:32 +02:00
|
|
|
m_iFOV = newfov ? newfov : def_fov;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
// the clients fov is actually set in the client data update section of the hud
|
|
|
|
|
2016-07-03 20:43:32 +02:00
|
|
|
if ( m_iFOV == def_fov ) // reset to saved sensitivity
|
2016-03-05 20:29:55 +01:00
|
|
|
m_flMouseSensitivity = 0;
|
2016-07-03 20:43:32 +02:00
|
|
|
else // set a new sensitivity that is proportional to the change from the FOV default
|
|
|
|
m_flMouseSensitivity = sensitivity->value * ((float)newfov / (float)def_fov) * zoom_sens_ratio->value;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHud::AddHudElem(CHudBase *phudelem)
|
|
|
|
{
|
2016-07-03 20:43:32 +02:00
|
|
|
assert( phudelem );
|
2016-03-05 20:29:55 +01:00
|
|
|
|
2016-07-03 20:43:32 +02:00
|
|
|
HUDLIST *pdl, *ptemp;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
2016-07-03 20:43:32 +02:00
|
|
|
pdl = new(std::nothrow) HUDLIST;
|
|
|
|
if( !pdl )
|
|
|
|
{
|
|
|
|
ConsolePrint( "Cannot allocate memory!\n" );
|
2016-03-05 20:29:55 +01:00
|
|
|
return;
|
2016-07-03 20:43:32 +02:00
|
|
|
}
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
pdl->p = phudelem;
|
2016-07-03 20:43:32 +02:00
|
|
|
pdl->pNext = NULL;
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
if (!m_pHudList)
|
|
|
|
{
|
|
|
|
m_pHudList = pdl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-03 20:43:32 +02:00
|
|
|
// find last
|
|
|
|
for( ptemp = m_pHudList; ptemp->pNext; ptemp = ptemp->pNext );
|
2016-03-05 20:29:55 +01:00
|
|
|
|
|
|
|
ptemp->pNext = pdl;
|
|
|
|
}
|