Add spec crosshair

- Fix readyroom crosshairs not applying after leaving a team
This commit is contained in:
pierow 2024-05-04 04:38:57 -04:00
parent 4f32271532
commit e24041c64a
6 changed files with 92 additions and 33 deletions

View file

@ -43,6 +43,7 @@ WeaponsResource gWR;
int g_weaponselect = 0;
extern bool gCanMove;
extern cvar_t* cl_weaponcfgs;
void IN_AttackDownForced(void);
void IN_AttackUpForced(void);
@ -87,6 +88,9 @@ void WeaponsResource::Reset( void )
iOldWeaponBits = 0;
memset( rgSlots, 0, sizeof(WEAPON*)*MAX_WEAPON_SLOTS*MAX_WEAPON_POSITIONS );
memset( riAmmo, 0, sizeof(int)*MAX_AMMO_TYPES );
crossLastWeapId = 0;
lastSpecXhair = 0;
lastPlayMode = 0;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -588,6 +592,64 @@ void WeaponsResource :: SelectSlot( int iSlot, int fAdvance, int iDirection )
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void WeaponsResource::SetWeaponConfig (WEAPON* weapon, int specXhair)
{
int newPlayMode = gHUD.GetPlayMode();
if (gHUD.GetCurrentWeaponID() != crossLastWeapId || (newPlayMode == PLAYMODE_READYROOM && newPlayMode != lastPlayMode) || (specXhair != lastSpecXhair && !weapon))
{
crossLastWeapId = gHUD.GetCurrentWeaponID();
lastPlayMode = newPlayMode;
lastSpecXhair = specXhair;
gEngfuncs.Con_Printf("changing weapon cfg\n");
char weapCfg[128];
if (cl_weaponcfgs->value == 1.0f)
{
ClientCmd("exec weaponcfgs/default.cfg");
if (!weapon || newPlayMode == PLAYMODE_READYROOM)
{
if (specXhair == 1)
{
ClientCmd("exec weaponcfgs/spectate.cfg");
}
else
{
ClientCmd("exec weaponcfgs/noweapon.cfg");
}
}
else
{
snprintf(weapCfg, 128, "exec weaponcfgs/%s.cfg", weapon->szName);
ClientCmd(weapCfg);
}
}
else if (cl_weaponcfgs->value == 2.0f)
{
if (!weapon || newPlayMode == PLAYMODE_READYROOM)
{
if (specXhair == 1)
{
ClientCmd("exec weaponcfgs/nsdefaults/spectate.cfg");
}
else
{
ClientCmd("exec weaponcfgs/nsdefaults/noweapon.cfg");
}
}
else
{
snprintf(weapCfg, 128, "exec weaponcfgs/nsdefaults/%s.cfg", weapon->szName);
ClientCmd(weapCfg);
}
}
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int giBucketHeight, giBucketWidth, giABHeight, giABWidth; // Ammo Bar width and height
cvar_t* hud_ammo_x;
cvar_t* hud_ammo_y;
@ -765,38 +827,7 @@ void CHudAmmo::Think(void)
}
}
if (gHUD.GetCurrentWeaponID() != m_crossLastWeapId)
{
m_crossLastWeapId = gHUD.GetCurrentWeaponID();
const float wCfgCvar = CVAR_GET_FLOAT("cl_weaponcfgs");
char weapCfg[128];
if (wCfgCvar == 1.0f)
{
ClientCmd("exec weaponcfgs/default.cfg");
if (!currentWeapon)
{
ClientCmd("exec weaponcfgs/noweapon.cfg");
}
else
{
snprintf(weapCfg, 128, "exec weaponcfgs/%s.cfg", currentWeapon->szName);
ClientCmd(weapCfg);
}
}
else if (wCfgCvar == 2.0f)
{
if (!currentWeapon)
{
ClientCmd("exec weaponcfgs/nsdefaults/noweapon.cfg");
}
else
{
snprintf(weapCfg, 128, "exec weaponcfgs/nsdefaults/%s.cfg", currentWeapon->szName);
ClientCmd(weapCfg);
}
}
}
gWR.SetWeaponConfig(currentWeapon, false);
if (!gpActiveSel)
return;

View file

@ -67,6 +67,7 @@ public:
void SetValidWeapon( void );
void SetCurrentWeapon( WEAPON* wp );
void SelectSlot( int iSlot, int fAdvance, int iDirection );
void SetWeaponConfig(WEAPON* weapon, int specXhair = 0);
friend CHudAmmo; //for iOldWeaponBits access
private:
@ -78,6 +79,9 @@ private:
int riAmmo[MAX_AMMO_TYPES]; // current ammo counts
int iOldWeaponBits;
int crossLastWeapId;
int lastSpecXhair;
int lastPlayMode;
};
extern WeaponsResource gWR;

View file

@ -122,7 +122,6 @@ private:
int m_HUD_bucket0;
int m_HUD_selection;
int m_customCrosshair;
int m_crossLastWeapId;
};

View file

@ -12,6 +12,7 @@
#include "vgui_TeamFortressViewport.h"
#include "vgui_SpectatorPanel.h"
#include "common/hltv.h"
#include "ammohistory.h"
#include "pm_shared/pm_shared.h"
#include "pm_shared/pm_defs.h"
@ -1117,11 +1118,15 @@ void CHudSpectator::SetMode(int iNewMainMode)
m_crosshairRect.bottom = 24;
gHUD.SetCurrentCrosshair( m_hCrosshair, m_crosshairRect, 255, 255, 255 );
gWR.SetWeaponConfig(nullptr, 1);
}
else
{
memset( &m_crosshairRect,0,sizeof(m_crosshairRect) );
gHUD.SetCurrentCrosshair( 0, m_crosshairRect, 0, 0, 0 );
gWR.SetWeaponConfig(nullptr, -1);
}
//char string[128];
@ -1885,11 +1890,15 @@ void CHudSpectator::CheckSettings()
m_crosshairRect.bottom = 24;
gHUD.SetCurrentCrosshair( m_hCrosshair, m_crosshairRect, 255, 255, 255 );
gWR.SetWeaponConfig(nullptr, 1);
}
else
{
memset( &m_crosshairRect,0,sizeof(m_crosshairRect) );
gHUD.SetCurrentCrosshair( 0, m_crosshairRect, 0, 0, 0 );
gWR.SetWeaponConfig(nullptr, -1);
}
// Removed by mmcguire.

View file

@ -0,0 +1,15 @@
// Enter commands to be executed when in first person spectate.
cl_cross_color "255 255 255"
cl_cross_alpha "255"
cl_cross_thickness "2"
cl_cross_size "4"
cl_cross_gap "4"
cl_cross_outline "0.75"
cl_cross_outline_alpha ""
cl_cross_outline_inner "0"
cl_cross_line_top "1"
cl_cross_line_bottom "1"
cl_cross_line_left "1"
cl_cross_line_right "1"
cl_cross_dot_size "0"
cl_cross_circle_radius "0"

View file

@ -0,0 +1 @@
// Enter commands to be executed when in first person spectate.