Custom crosshair are now possible
This commit is contained in:
parent
097e18db87
commit
a841c7a02c
1 changed files with 135 additions and 62 deletions
|
@ -23,6 +23,13 @@
|
|||
#include "hud_crosshair.h"
|
||||
#include "c_te_effect_dispatch.h"
|
||||
#include "c_te_legacytempents.h"
|
||||
#include "iviewrender.h"
|
||||
#include "view_scene.h"
|
||||
#include "materialsystem/imaterialproxy.h"
|
||||
#include "materialsystem/imaterialvar.h"
|
||||
#include "materialsystem/imaterial.h"
|
||||
#include "materialsystem/imesh.h"
|
||||
#include "materialsystem/itexture.h"
|
||||
|
||||
extern IVModelInfoClient* modelinfo;
|
||||
|
||||
|
@ -329,6 +336,7 @@ LINK_ENTITY_TO_CLASS( weapon_cs_base, CWeaponCSBase );
|
|||
ConVar cl_crosshaircolor_r( "cl_crosshaircolor_r", "50", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
|
||||
ConVar cl_crosshaircolor_g( "cl_crosshaircolor_g", "250", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
|
||||
ConVar cl_crosshaircolor_b( "cl_crosshaircolor_b", "50", FCVAR_CLIENTDLL | FCVAR_ARCHIVE );
|
||||
ConVar cl_crosshair_picture( "cl_crosshair_picture", "1" );
|
||||
|
||||
#if ALLOW_WEAPON_SPREAD_DISPLAY
|
||||
ConVar weapon_debug_spread_show( "weapon_debug_spread_show", "0", FCVAR_CLIENTDLL, "Enables display of weapon accuracy; 1: show accuracy box, 2: show box with recoil offset" );
|
||||
|
@ -1200,6 +1208,68 @@ void CWeaponCSBase::DefaultTouch(CBaseEntity *pOther)
|
|||
int iCenterY = ScreenHeight() / 2;
|
||||
|
||||
if ( bCrosshairVisible )
|
||||
{
|
||||
if ( cl_crosshair_picture.GetBool() )
|
||||
{
|
||||
static auto pCrosshairMaterial = materials->FindMaterial( "crosshair/crosshair", TEXTURE_GROUP_OTHER );
|
||||
static auto pCrosshairHitMaterial = materials->FindMaterial( "crosshair/crosshair_hit", TEXTURE_GROUP_OTHER );
|
||||
|
||||
CMatRenderContextPtr pRenderContext( materials );
|
||||
|
||||
CMaterialReference refCrosshair;
|
||||
refCrosshair.Init( pCrosshairMaterial );
|
||||
|
||||
int nViewportX, nViewportY, nViewportWidth, nViewportHeight;
|
||||
pRenderContext->GetViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight );
|
||||
|
||||
pRenderContext->DrawScreenSpaceRectangle( refCrosshair,
|
||||
nViewportWidth / 2
|
||||
- pCrosshairMaterial->GetMappingWidth() / 2,
|
||||
nViewportHeight / 2
|
||||
- pCrosshairMaterial->GetMappingHeight() / 2,
|
||||
pCrosshairMaterial->GetMappingWidth(),
|
||||
pCrosshairMaterial->GetMappingHeight(),
|
||||
nViewportX,
|
||||
nViewportY,
|
||||
nViewportX + nViewportWidth - 1,
|
||||
nViewportY + nViewportHeight - 1,
|
||||
nViewportWidth,
|
||||
nViewportHeight );
|
||||
|
||||
static float flDisplayCurrentTime = 0.0f;
|
||||
static float flDisplayTime = 1.0F;
|
||||
|
||||
if ( pPlayer->m_bHasHitPlayer )
|
||||
{
|
||||
flDisplayCurrentTime = gpGlobals->curtime + flDisplayTime;
|
||||
pPlayer->m_bHasHitPlayer = false;
|
||||
}
|
||||
|
||||
if ( flDisplayCurrentTime >= gpGlobals->curtime && pCrosshairHitMaterial )
|
||||
{
|
||||
float flAlpha = ( flDisplayCurrentTime - gpGlobals->curtime ) / flDisplayTime;
|
||||
|
||||
CMaterialReference refCrosshairHit;
|
||||
refCrosshairHit.Init( pCrosshairHitMaterial );
|
||||
|
||||
refCrosshairHit->AlphaModulate( flAlpha );
|
||||
|
||||
pRenderContext->DrawScreenSpaceRectangle( refCrosshairHit,
|
||||
nViewportWidth / 2
|
||||
- pCrosshairHitMaterial->GetMappingWidth() / 2,
|
||||
nViewportHeight / 2
|
||||
- pCrosshairHitMaterial->GetMappingHeight() / 2,
|
||||
pCrosshairHitMaterial->GetMappingWidth(),
|
||||
pCrosshairHitMaterial->GetMappingHeight(),
|
||||
nViewportX,
|
||||
nViewportY,
|
||||
nViewportX + nViewportWidth - 1,
|
||||
nViewportY + nViewportHeight - 1,
|
||||
nViewportWidth,
|
||||
nViewportHeight );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// draw horizontal crosshair lines
|
||||
int iInnerLeft = iCenterX - iCrosshairDistance - iBarThickness / 2;
|
||||
|
@ -1243,34 +1313,37 @@ void CWeaponCSBase::DefaultTouch(CBaseEntity *pOther)
|
|||
if ( flDisplayCurrentTime >= gpGlobals->curtime )
|
||||
{
|
||||
float flAlpha = ( flDisplayCurrentTime - gpGlobals->curtime ) / flDisplayTime;
|
||||
int tocenter = 10;
|
||||
int initpos = 16;
|
||||
int tocenter = 15;
|
||||
int initpos = 25;
|
||||
|
||||
initpos += iCrosshairDistance * 2;
|
||||
tocenter += iCrosshairDistance * 2;
|
||||
initpos += iBarSize * 2;
|
||||
tocenter += iBarSize * 2;
|
||||
|
||||
float oldAlphaMultiplier = vgui::surface()->DrawGetAlphaMultiplier();
|
||||
|
||||
vgui::surface()->DrawSetColor( r, g, b, int( flAlpha * 255.0f ) );
|
||||
|
||||
for ( int i = -2; i < 2; i++ )
|
||||
for ( int i = -1; i < 2; i++ )
|
||||
{
|
||||
vgui::surface()->DrawLine( iCenterX - initpos - i,
|
||||
iCenterY - initpos - i,
|
||||
iCenterX - tocenter - i,
|
||||
iCenterY - tocenter - i );
|
||||
vgui::surface()->DrawLine( iCenterX + initpos + i,
|
||||
iCenterY + initpos + i,
|
||||
iCenterX + tocenter + i,
|
||||
iCenterY + tocenter + i );
|
||||
vgui::surface()->DrawLine( iCenterX + initpos + i,
|
||||
iCenterY - initpos - i,
|
||||
iCenterX + tocenter + i,
|
||||
iCenterY - tocenter - i );
|
||||
vgui::surface()->DrawLine( iCenterX - initpos - i,
|
||||
iCenterY + initpos + i,
|
||||
iCenterX - tocenter - i,
|
||||
iCenterY + tocenter + i );
|
||||
tocenter += i;
|
||||
initpos += i;
|
||||
vgui::surface()->DrawLine( iCenterX - initpos,
|
||||
iCenterY - initpos,
|
||||
iCenterX - tocenter,
|
||||
iCenterY - tocenter );
|
||||
vgui::surface()->DrawLine( iCenterX + initpos,
|
||||
iCenterY + initpos,
|
||||
iCenterX + tocenter,
|
||||
iCenterY + tocenter );
|
||||
vgui::surface()->DrawLine( iCenterX - initpos,
|
||||
iCenterY + initpos,
|
||||
iCenterX - tocenter,
|
||||
iCenterY + tocenter );
|
||||
vgui::surface()->DrawLine( iCenterX + initpos,
|
||||
iCenterY - initpos,
|
||||
iCenterX + tocenter,
|
||||
iCenterY - tocenter );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue