コード例 #1
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
//
// Draws the ammo bar on the hud
//
int CHudAmmo::DrawBar(int x, int y, int width, int height, float f)
{
	int r, g, b;

	if (f < 0)
		f = 0;
	if (f > 1)
		f = 1;

	if (f)
	{
		int w = f * width;

		// Always show at least one pixel if we have ammo.
		if (w <= 0)
			w = 1;
		const auto& barColor = GetHud().GetAmmoBarColor();

		FillRGBA(x, y, w, height, barColor.r(), barColor.g(), barColor.b(), 255);
		x += w;
		width -= w;
	}

	GetHud().GetPrimaryColor().UnpackRGB(r, g, b);

	FillRGBA(x, y, width, height, r, g, b, 128);

	return (x + width);
}
コード例 #2
0
ファイル: hud.cpp プロジェクト: Cre3per/hl2sdk-csgo
//-----------------------------------------------------------------------------
// Purpose: Stop obscuring other elements in this group
//-----------------------------------------------------------------------------
void CHudElement::UnhideLowerPriorityHudElementsInGroup( const char *pszGroupName )
{	
	// look up the render group
	int iGroupIndex = GetHud().LookupRenderGroupIndexByName( pszGroupName );

	// unlock the group
	GetHud().UnlockRenderGroup( iGroupIndex, this );
}
コード例 #3
0
/*
========================
idMenuHandler_HUD::Update
========================
*/
void idMenuHandler_HUD::Update()
{

	if( gui == NULL || !gui->IsActive() )
	{
		return;
	}
	
	if( nextScreen != activeScreen )
	{
	
		if( activeScreen > HUD_AREA_INVALID && activeScreen < HUD_NUM_AREAS && menuScreens[ activeScreen ] != NULL )
		{
			menuScreens[ activeScreen ]->HideScreen( static_cast<mainMenuTransition_t>( transition ) );
		}
		
		if( nextScreen > HUD_AREA_INVALID && nextScreen < HUD_NUM_AREAS && menuScreens[ nextScreen ] != NULL )
		{
			menuScreens[ nextScreen ]->ShowScreen( static_cast<mainMenuTransition_t>( transition ) );
		}
		
		transition = MENU_TRANSITION_INVALID;
		activeScreen = nextScreen;
	}
	
	idPlayer* player = gameLocal.GetLocalPlayer();
	if( player != NULL )
	{
		if( player->IsTipVisible() && autoHideTip && !hiding )
		{
			if( gameLocal.time >= tipStartTime + TIP_DISPLAY_TIME )
			{
				player->HideTip();
			}
		}
		
		if( player->IsSoundChannelPlaying( SND_CHANNEL_PDA_AUDIO ) && GetHud() != NULL )
		{
			GetHud()->UpdateAudioLog( true );
		}
		else
		{
			GetHud()->UpdateAudioLog( false );
		}
		
		if( radioMessage )
		{
			GetHud()->UpdateCommunication( true, player );
		}
		else
		{
			GetHud()->UpdateCommunication( false, player );
		}
		
	}
	
	idMenuHandler::Update();
}
コード例 #4
0
ファイル: CHudBattery.cpp プロジェクト: oskarlh/HLEnhanced
void CHudBattery::VidInit()
{
	int HUD_suit_empty = GetHud().GetSpriteIndex( "suit_empty" );
	int HUD_suit_full = GetHud().GetSpriteIndex( "suit_full" );

	m_hSprite1 = m_hSprite2 = 0;  // delaying get sprite handles until we know the sprites are loaded
	m_prc1 = &GetHud().GetSpriteRect( HUD_suit_empty );
	m_prc2 = &GetHud().GetSpriteRect( HUD_suit_full );
	m_iHeight = m_prc2->bottom - m_prc1->top;
	m_fFade = 0;
}
コード例 #5
0
ファイル: CHudFlashlight.cpp プロジェクト: oskarlh/HLEnhanced
bool CHudFlashlight::Draw(float flTime)
{
	if ( GetHud().GetHideHudBits().Any( HIDEHUD_FLASHLIGHT | HIDEHUD_ALL ) )
		return true;

	int r, g, b, x, y, a;
	wrect_t rc;

	if (!( Hud().GetWeaponBits() & (1<<(WEAPON_SUIT)) ))
		return true;

	if (m_fOn)
		a = 225;
	else
		a = MIN_ALPHA;

	if (m_flBat < 0.20)
		GetHud().GetEmptyItemColor().UnpackRGB(r,g,b);
	else
		GetHud().GetPrimaryColor().UnpackRGB(r,g,b);

	ScaleColors(r, g, b, a);

	y = (m_prc1->bottom - m_prc2->top)/2;
	x = ScreenWidth - m_iWidth - m_iWidth/2 ;

	// Draw the flashlight casing
	SPR_Set(m_hSprite1, r, g, b );
	SPR_DrawAdditive( 0,  x, y, m_prc1);

	if ( m_fOn )
	{  // draw the flashlight beam
		x = ScreenWidth - m_iWidth/2;

		SPR_Set( m_hBeam, r, g, b );
		SPR_DrawAdditive( 0, x, y, m_prcBeam );
	}

	// draw the flashlight energy level
	x = ScreenWidth - m_iWidth - m_iWidth/2 ;
	int iOffset = m_iWidth * (1.0 - m_flBat);
	if (iOffset < m_iWidth)
	{
		rc = *m_prc2;
		rc.left += iOffset;

		SPR_Set(m_hSprite2, r, g, b );
		SPR_DrawAdditive( 0, x + iOffset, y, &rc);
	}


	return true;
}
コード例 #6
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
void CHudAmmo::VidInit()
{
	// Load sprites for buckets (top row of weapon menu)
	m_HUD_bucket0 = GetHud().GetSpriteIndex( "bucket1" );
	m_HUD_selection = GetHud().GetSpriteIndex( "selection" );

	//TODO: get the sprite once instead of fetching it over and over - Solokiller
	m_hsprBuckets = GetHud().GetSprite(m_HUD_bucket0);
	m_iBucketWidth = GetHud().GetSpriteRect(m_HUD_bucket0).right - GetHud().GetSpriteRect(m_HUD_bucket0).left;
	m_iBucketHeight = GetHud().GetSpriteRect(m_HUD_bucket0).bottom - GetHud().GetSpriteRect(m_HUD_bucket0).top;

	gHR.iHistoryGap = max( gHR.iHistoryGap, GetHud().GetSpriteRect(m_HUD_bucket0).bottom - GetHud().GetSpriteRect(m_HUD_bucket0).top);

	if (ScreenWidth >= 640)
	{
		m_iABWidth = 20;
		m_iABHeight = 4;
	}
	else
	{
		m_iABWidth = 10;
		m_iABHeight = 2;
	}

	m_pWeapon = nullptr;
}
コード例 #7
0
ファイル: hud.cpp プロジェクト: Cre3per/hl2sdk-csgo
//-----------------------------------------------------------------------------
// Purpose: Remove this hud element from the global list in CHUD
//-----------------------------------------------------------------------------
CHudElement::~CHudElement()
{
	if ( m_bNeedsRemove )
	{
		GetHud().RemoveHudElement( this );
	}
}
コード例 #8
0
	virtual void ApplySchemeSettings( vgui::IScheme *pScheme )
	{
		BaseClass::ApplySchemeSettings( pScheme );

		GetHud().InitColors( pScheme );

		SetPaintBackgroundEnabled( false );
	}
コード例 #9
0
ファイル: CHudFlashlight.cpp プロジェクト: oskarlh/HLEnhanced
void CHudFlashlight::VidInit()
{
	int HUD_flash_empty = GetHud().GetSpriteIndex( "flash_empty" );
	int HUD_flash_full = GetHud().GetSpriteIndex( "flash_full" );
	int HUD_flash_beam = GetHud().GetSpriteIndex( "flash_beam" );

	m_hSprite1 = GetHud().GetSprite(HUD_flash_empty);
	m_hSprite2 = GetHud().GetSprite(HUD_flash_full);
	m_hBeam = GetHud().GetSprite(HUD_flash_beam);
	m_prc1 = &GetHud().GetSpriteRect(HUD_flash_empty);
	m_prc2 = &GetHud().GetSpriteRect(HUD_flash_full);
	m_prcBeam = &GetHud().GetSpriteRect(HUD_flash_beam);
	m_iWidth = m_prc2->right - m_prc2->left;
}
コード例 #10
0
/*
========================
idMenuHandler_HUD::HideTip
========================
*/
void idMenuHandler_HUD::HideTip()
{
	idMenuScreen_HUD* screen = GetHud();
	if( screen != NULL && !hiding )
	{
		screen->HideTip();
	}
	hiding = true;
}
コード例 #11
0
ファイル: hud.cpp プロジェクト: Cre3per/hl2sdk-csgo
//-----------------------------------------------------------------------------
// Purpose: We can register to be affected by multiple hud render groups
//-----------------------------------------------------------------------------
void CHudElement::RegisterForRenderGroup( const char *pszGroupName )
{
	int iGroupIndex = GetHud().RegisterForRenderGroup( pszGroupName );

	// add group index to our list of registered groups
	if ( m_HudRenderGroups.Find( iGroupIndex ) == m_HudRenderGroups.InvalidIndex() )
	{
		m_HudRenderGroups.AddToTail( iGroupIndex );
	}
}
コード例 #12
0
ファイル: hud.cpp プロジェクト: Cre3per/hl2sdk-csgo
//-----------------------------------------------------------------------------
// Purpose: Allows HUD to modify input data
//-----------------------------------------------------------------------------
void CHud::ProcessInput( bool bActive )
{
	if ( bActive )
	{
		m_iKeyBits = input->GetButtonBits( false );

		// Weaponbits need to be sent down as a UserMsg now.
		GetHud().Think();
	}
}
コード例 #13
0
/*
========================
idMenuHandler_HUD::ShowTip
========================
*/
void idMenuHandler_HUD::ShowTip( const char* title, const char* tip, bool autoHide )
{
	autoHideTip = autoHideTip;
	tipStartTime = gameLocal.time;
	hiding = false;
	idMenuScreen_HUD* screen = GetHud();
	if( screen != NULL )
	{
		screen->ShowTip( title, tip );
	}
}
コード例 #14
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
// Selects the next item in the weapon menu
void CHudAmmo::UserCmd_NextWeapon(void)
{
	if ( m_bPlayerDead || GetHud().GetHideHudBits().Any( HIDEHUD_WEAPONS | HIDEHUD_ALL ) )
		return;

	if ( !m_pActiveSel || m_pActiveSel == ( CBasePlayerWeapon*)1 )
		m_pActiveSel = m_pWeapon;

	int slot = 0;

	CBasePlayerWeapon* pWeapon = nullptr;

	if ( m_pActiveSel )
	{
		slot = m_pActiveSel->GetWeaponInfo()->GetBucket();
		pWeapon = m_pActiveSel->m_pNext;

		if( !pWeapon )
		{
			if( slot == ( MAX_WEAPON_SLOTS - 1 ) )
				slot = 0;
			else
				++slot;
		}
	}

	CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer();

	for ( int loop = 0; loop <= 1; loop++ )
	{
		for ( ; slot < MAX_WEAPON_SLOTS; slot++ )
		{
			if( !pWeapon )
				pWeapon = pPlayer->m_rgpPlayerItems[ slot ];

			for ( ; pWeapon; pWeapon = pWeapon->m_pNext )
			{
				if ( pWeapon && pPlayer->HasAmmo( pWeapon ) )
				{
					m_pActiveSel = pWeapon;
					return;
				}
			}

			pWeapon = nullptr;
		}

		slot = 0;  // start looking from the first slot again
	}

	m_pActiveSel = nullptr;
}
コード例 #15
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
void CHudAmmo::MsgFunc_HideWeapon( const char *pszName, int iSize, void *pbuf )
{
	CBufferReader reader( pbuf, iSize );
	
	GetHud().GetHideHudBits() = reader.ReadByte();

	if (gEngfuncs.IsSpectateOnly())
		return;

	if ( GetHud().GetHideHudBits().Any( HIDEHUD_WEAPONS | HIDEHUD_ALL ) )
	{
		wrect_t nullrc = {};
		m_pActiveSel = nullptr;
		SetCrosshair( 0, nullrc, 0, 0, 0 );
	}
	else
	{
		if ( m_pWeapon )
		{
			const auto& crosshair = m_pWeapon->GetWeaponInfo()->GetHUDInfo()->GetCrosshair();
			SetCrosshair( crosshair.hSprite, crosshair.rect, 255, 255, 255 );
		}
	}
}
コード例 #16
0
ファイル: hud.cpp プロジェクト: Cre3per/hl2sdk-csgo
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
bool CHudElement::ShouldDraw( void )
{
	bool bShouldDraw = m_pHud && !m_pHud->IsHidden( m_iHiddenBits );
	if ( bShouldDraw )
	{
		// for each render group
		int iNumGroups = m_HudRenderGroups.Count();
		for ( int iGroupIndex = 0; iGroupIndex < iNumGroups; iGroupIndex++ )
		{
			if ( GetHud().IsRenderGroupLockedFor( this, m_HudRenderGroups.Element(iGroupIndex ) ) )
				return false;
		}
	}

	return bShouldDraw;
}
コード例 #17
0
void OpenVoiceMenu( int index )
{
	// do not show the menu if the player is dead or is an observer
	C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer();
	if ( !pPlayer )
		return;

	if ( !pPlayer->IsAlive() || pPlayer->IsObserver() )
		return;

	CHudMenu *pMenu = (CHudMenu *) GetHud().FindElement( "CHudMenu" );
	if ( !pMenu )
		return;

	// if they hit the key again, close the menu
	if ( g_ActiveVoiceMenu == index )
	{
		pMenu->HideMenu();
		g_ActiveVoiceMenu = 0;
		return;
	}

	if ( index > 0 && index < 9 )
	{
		KeyValues *pKV = new KeyValues( "MenuItems" );

		CMultiplayRules *pRules = dynamic_cast< CMultiplayRules * >( GameRules() );
		if ( pRules )
		{			
			if ( !pRules->GetVoiceMenuLabels( index-1, pKV ) )
			{ 
				pKV->deleteThis();
				return;
			}
		}

		pMenu->ShowMenu_KeyValueItems( pKV );

		pKV->deleteThis();

		g_ActiveVoiceMenu = index;
	}
	else
	{
		g_ActiveVoiceMenu = 0;
	}
}
コード例 #18
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
void CHudAmmo::Reset()
{
	m_fFade = 0;
	GetFlags() |= HUD_ACTIVE; //!!!

	m_pActiveSel = nullptr;
	GetHud().GetHideHudBits() = 0;

	if( CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer() )
	{
		pPlayer->GetWeapons().ClearAll();
	}

	m_pWeapon = nullptr;

	gHR.Reset();
}
コード例 #19
0
ファイル: in_mouse.cpp プロジェクト: Au-heppa/swarm-sdk
//-----------------------------------------------------------------------------
// Purpose: Multiplies mouse values by sensitivity.  Note that for windows mouse settings
//  the input x,y offsets are already scaled based on that.  The custom acceleration, therefore,
//  is totally engine-specific and applies as a post-process to allow more user tuning.
// Input  : *x - 
//			*y - 
//-----------------------------------------------------------------------------
void CInput::ScaleMouse( int nSlot, float *x, float *y )
{
	float mx = *x;
	float my = *y;

	float flHudSensitivity = GetHud( nSlot ).GetSensitivity();

	float mouse_senstivity = ( flHudSensitivity != 0 ) ? flHudSensitivity : sensitivity.GetFloat();

	if ( m_customaccel.GetBool() ) 
	{ 
		float raw_mouse_movement_distance = sqrt( mx * mx + my * my );
		float acceleration_scale = m_customaccel_scale.GetFloat();
		float accelerated_sensitivity_max = m_customaccel_max.GetFloat();
		float accelerated_sensitivity_exponent = m_customaccel_exponent.GetFloat();
		float accelerated_sensitivity = ( (float)pow( raw_mouse_movement_distance, accelerated_sensitivity_exponent ) * acceleration_scale + mouse_senstivity );

		if ( accelerated_sensitivity_max > 0.0001f && 
			accelerated_sensitivity > accelerated_sensitivity_max )
		{
			accelerated_sensitivity = accelerated_sensitivity_max;
		}

		*x *= accelerated_sensitivity; 
		*y *= accelerated_sensitivity; 

		// Further re-scale by yaw and pitch magnitude if user requests alternate mode 2
		// This means that they will need to up their value for m_customaccel_scale greatly (>40x) since m_pitch/yaw default
		//  to 0.022
		if ( m_customaccel.GetInt() == 2 )
		{ 
			*x *= m_yaw.GetFloat(); 
			*y *= m_pitch->GetFloat(); 
		} 
	}
	else
	{ 
		*x *= mouse_senstivity;
		*y *= mouse_senstivity;
	}
}
コード例 #20
0
//-----------------------------------------------------------------------------
// Purpose: Static class creation factory
//  Searches list of registered factories for a match and then instances the 
//  requested technology by name
// Input  : *name - 
// Output : CBaseTFTechnology
//-----------------------------------------------------------------------------
void CHudElementHelper::CreateAllElements( void )
{
	// Start of list
	CHudElementHelper *p = m_sHelpers;
	while ( p )
	{
		// only create this element in slot 0
		if ( ( p->m_iFlags & HUDELEMENT_SS_FULLSCREEN_ONLY ) && ( GET_ACTIVE_SPLITSCREEN_SLOT() != 0 ) )
		{
			p = p->m_pNext;
			continue;
		}

		// Dispatch creation function directly
		CHudElement *( *fCreate )( void ) = p->m_pfnCreate;
		CHudElement *newElement = (fCreate)();
		if ( newElement )
		{
			GetHud().AddHudElement( newElement );				
		}
		p = p->GetNext();
	}
}
コード例 #21
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
void CHudAmmo::SelectSlot( int iSlot, const bool fAdvance, int iDirection )
{
	if( auto pMenu = GETHUDCLASS( CHudMenu ) )
	{
		if ( pMenu->m_fMenuDisplayed && !fAdvance && (iDirection == 1) )
		{ // menu is overriding slot use commands
			pMenu->SelectMenuItem( iSlot + 1 );  // slots are one off the key numbers
			return;
		}
	}

	if ( iSlot > MAX_WEAPON_SLOTS )
		return;

	if ( m_bPlayerDead || GetHud().GetHideHudBits().Any( HIDEHUD_WEAPONS | HIDEHUD_ALL ) )
		return;

	if (!( Hud().GetWeaponBits() & (1<<(WEAPON_SUIT)) ))
		return;

	if ( ! ( Hud().GetWeaponBits() & ~(1<<(WEAPON_SUIT)) ))
		return;

	CBasePlayerWeapon *p = NULL;
	bool fastSwitch = CVAR_GET_FLOAT( "hud_fastswitch" ) != 0;

	CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer();

	if ( ( m_pActiveSel == NULL) || ( m_pActiveSel == ( CBasePlayerWeapon *)1) || (iSlot != m_pActiveSel->GetWeaponInfo()->GetBucket()) )
	{
		PlaySound( "common/wpn_hudon.wav", 1 );
		p = pPlayer->GetFirstPos( iSlot );

		if ( p && fastSwitch ) // check for fast weapon switch mode
		{
			// if fast weapon switch is on, then weapons can be selected in a single keypress
			// but only if there is only one item in the bucket
			CBasePlayerWeapon *p2 = pPlayer->GetNextActivePos( p->GetWeaponInfo()->GetBucket(), p->GetWeaponInfo()->GetPosition() );
			if ( !p2 )
			{	// only one active item in bucket, so change directly to weapon
				ServerCmd( p->GetWeaponInfo()->GetWeaponName() );
				g_weaponselect = p->GetWeaponInfo()->GetID();
				return;
			}
		}
	}
	else
	{
		PlaySound("common/wpn_moveselect.wav", 1);
		if ( m_pActiveSel )
			p = pPlayer->GetNextActivePos( m_pActiveSel->GetWeaponInfo()->GetBucket(), m_pActiveSel->GetWeaponInfo()->GetPosition() );
		if ( !p )
			p = pPlayer->GetFirstPos( iSlot );
	}

	
	if ( !p )  // no selection found
	{
		// just display the weapon list, unless fastswitch is on just ignore it
		if ( !fastSwitch )
			m_pActiveSel = ( CBasePlayerWeapon *)1;
		else
			m_pActiveSel = nullptr;
	}
	else 
		m_pActiveSel = p;
}
コード例 #22
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
// Selects the previous item in the menu
void CHudAmmo::UserCmd_PrevWeapon(void)
{
	if ( m_bPlayerDead || GetHud().GetHideHudBits().Any( HIDEHUD_WEAPONS | HIDEHUD_ALL ) )
		return;

	if ( !m_pActiveSel || m_pActiveSel == ( CBasePlayerWeapon*)1 )
		m_pActiveSel = m_pWeapon;

	CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer();

	CBasePlayerWeapon* pWeapon = nullptr;
	int slot = MAX_WEAPON_SLOTS-1;

	if ( m_pActiveSel )
	{
		slot = m_pActiveSel->GetWeaponInfo()->GetBucket();
		for( CBasePlayerWeapon* pWpn = pPlayer->m_rgpPlayerItems[ slot ], * pPrev = nullptr; pWpn; pPrev = pWpn, pWpn = pWpn->m_pNext )
		{
			if( pWpn == m_pActiveSel )
			{
				pWeapon = pPrev;
				break;
			}
		}

		if( !pWeapon )
		{
			if( slot == 0 )
				slot = MAX_WEAPON_SLOTS - 1;
			else
				--slot;
		}
	}
	
	for ( int loop = 0; loop <= 1; loop++ )
	{
		for ( ; slot >= 0; slot-- )
		{
			//TODO: consider making the weapon list a double linked list, or turn the weapon list into a single array of pointers. - Solokiller
			if( !pWeapon )
			{
				pWeapon = pPlayer->m_rgpPlayerItems[ slot ];

				while( pWeapon && pWeapon->m_pNext )
					pWeapon = pWeapon->m_pNext;
			}

			while( pWeapon )
			{
				if( pPlayer->HasAmmo( pWeapon ) )
				{
					m_pActiveSel = pWeapon;
					return;
				}

				auto pWpn = pPlayer->m_rgpPlayerItems[ slot ];

				while( pWpn && pWpn->m_pNext && pWpn != pWeapon && pWpn->m_pNext != pWeapon )
					pWpn = pWpn->m_pNext;

				if( pWpn != pWeapon )
					pWeapon = pWpn;
				else
					pWeapon = nullptr;
			}
		}
		
		slot = MAX_WEAPON_SLOTS-1;
	}

	m_pActiveSel = nullptr;
}
コード例 #23
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
bool CHudAmmo::Draw(float flTime)
{
	int a, x, y, r, g, b;
	int AmmoWidth;

	if (!( Hud().GetWeaponBits() & (1<<(WEAPON_SUIT)) ))
		return true;

	if ( GetHud().GetHideHudBits().Any( HIDEHUD_WEAPONS | HIDEHUD_ALL ) )
		return true;

	// Draw Weapon Menu
	DrawWList(flTime);

	// Draw ammo pickup history
	gHR.DrawAmmoHistory( flTime );

	if (!( GetFlags() & HUD_ACTIVE))
		return false;

	if (!m_pWeapon)
		return false;

	if( m_pCrosshair->value != 0 && m_hCrosshair != INVALID_HSPRITE )
	{
		float flScale;

		switch( static_cast<int>( m_pCrosshairMode->value ) )
		{
		default:
		case CROSS_NATIVESCALE:
			flScale = 1;
			break;

		case CROSS_RESSCALE:
			flScale = max( ( ScreenWidth / 640.0 ) * 0.75, 1.0 );
			break;

		case CROSS_USERSCALE:
			flScale = fabs( m_pCrosshairScale->value );
			break;
		}

		class CCrosshairTriCallback : public ITriCoordFallback
		{
		public:
			void Calculate( HSPRITE hSprite, const int frame, const wrect_t& rect, const float flScale, int& x, int& y ) override
			{
				x = ( ScreenWidth - ( ( rect.right - rect.left ) ) ) / 2;
				y = ( ScreenHeight - ( ( rect.bottom - rect.top ) ) ) / 2;
			}
		};

		CCrosshairTriCallback callback;

		Tri_DrawScaledSprite( m_hCrosshair, 0, m_iR, m_iG, m_iB, 255, kRenderTransTexture, flScale, callback, &m_CrosshairRC );
	}

	CBasePlayerWeapon *pw = m_pWeapon; // shorthand

	// SPR_Draw Ammo
	if( !pw->GetWeaponInfo()->GetPrimaryAmmo() && !pw->GetWeaponInfo()->GetSecondaryAmmo() )
		return false;

	int iFlags = DHN_DRAWZERO; // draw 0 values

	AmmoWidth = GetHud().GetSpriteRect( GetHud().GetHudNumber0Index() ).right - GetHud().GetSpriteRect( GetHud().GetHudNumber0Index() ).left;

	a = (int) max( static_cast<float>( MIN_ALPHA ), m_fFade );

	if (m_fFade > 0)
		m_fFade -= ( Hud().GetTimeDelta() * 20 );

	GetHud().GetPrimaryColor().UnpackRGB(r,g,b);

	ScaleColors(r, g, b, a );

	// Does this weapon have a clip?
	y = ScreenHeight - GetHud().GetFontHeight() - GetHud().GetFontHeight() /2;

	CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer();

	// Does weapon have any ammo at all?
	if ( auto pAmmo = pw->GetWeaponInfo()->GetPrimaryAmmo() )
	{
		const auto& ammo = m_pWeapon->GetWeaponInfo()->GetHUDInfo()->GetPrimaryAmmo();

		int iIconWidth = ammo.rect.right - ammo.rect.left;
		
		if (pw->m_iClientClip >= 0)
		{
			// room for the number and the '|' and the current ammo
			
			x = ScreenWidth - (8 * AmmoWidth) - iIconWidth;
			x = GetHud().DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pw->m_iClientClip, r, g, b);

			int iBarWidth =  AmmoWidth/10;

			x += AmmoWidth/2;

			GetHud().GetPrimaryColor().UnpackRGB(r,g,b);

			// draw the | bar
			FillRGBA(x, y, iBarWidth, GetHud().GetFontHeight(), r, g, b, a);

			x += iBarWidth + AmmoWidth/2;

			// GL Seems to need this
			ScaleColors(r, g, b, a );
			x = GetHud().DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pPlayer->CountAmmo( pAmmo->GetID() ), r, g, b);


		}
		else
		{
			// SPR_Draw a bullets only line
			x = ScreenWidth - 4 * AmmoWidth - iIconWidth;
			x = GetHud().DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pPlayer->CountAmmo( pAmmo->GetID() ), r, g, b);
		}

		// Draw the ammo Icon
		int iOffset = ( ammo.rect.bottom - ammo.rect.top)/8;
		SPR_Set( ammo.hSprite, r, g, b);
		SPR_DrawAdditive(0, x, y - iOffset, &ammo.rect );
	}

	// Does weapon have seconday ammo?
	if ( auto pAmmo = pw->GetWeaponInfo()->GetSecondaryAmmo() )
	{
		const auto& ammo2 = m_pWeapon->GetWeaponInfo()->GetHUDInfo()->GetSecondaryAmmo();

		int iIconWidth = ammo2.rect.right - ammo2.rect.left;

		// Do we have secondary ammo?
		if ( pPlayer->CountAmmo( pAmmo->GetID() ) > 0 )
		{
			y -= GetHud().GetFontHeight() + GetHud().GetFontHeight() /4;
			x = ScreenWidth - 4 * AmmoWidth - iIconWidth;
			x = GetHud().DrawHudNumber(x, y, iFlags|DHN_3DIGITS, pPlayer->CountAmmo( pAmmo->GetID() ), r, g, b);

			// Draw the ammo Icon
			SPR_Set( ammo2.hSprite, r, g, b);
			int iOffset = ( ammo2.rect.bottom - ammo2.rect.top)/8;
			SPR_DrawAdditive(0, x, y - iOffset, &ammo2.rect );
		}
	}
	return true;
}
コード例 #24
0
ファイル: hud.cpp プロジェクト: Cre3per/hl2sdk-csgo
void CHudElement::UnregisterForRenderGroup( const char *pszGroupName )
{
	int iGroupIndex = GetHud().RegisterForRenderGroup( pszGroupName );

	m_HudRenderGroups.FindAndRemove( iGroupIndex );
}
コード例 #25
0
ファイル: CHudAmmo.cpp プロジェクト: oskarlh/HLEnhanced
//
// Draw Weapon Menu
//
int CHudAmmo::DrawWList(float flTime)
{
	int r,g,b,x,y,a,i;

	if ( !m_pActiveSel )
		return 0;

	int iActiveSlot;

	if ( m_pActiveSel == ( CBasePlayerWeapon *)1 )
		iActiveSlot = -1;	// current slot has no weapons
	else 
		iActiveSlot = m_pActiveSel->GetWeaponInfo()->GetBucket();

	x = 10; //!!!
	y = 10; //!!!
	
	CBasePlayer* pPlayer = g_Prediction.GetLocalPlayer();

	// Ensure that there are available choices in the active slot
	if ( iActiveSlot > 0 )
	{
		if ( !pPlayer->GetFirstPos( iActiveSlot ) )
		{
			m_pActiveSel = ( CBasePlayerWeapon *)1;
			iActiveSlot = -1;
		}
	}

	// Shepard : determine how many buckets we should draw
	int iBucketsToDraw = 0;
	for ( i = 0; i < MAX_WEAPON_SLOTS; i++ )
	{
		for ( int j = 0; j < MAX_WEAPONS; j++ )
		{
			CBasePlayerWeapon *pWeapon = pPlayer->GetWeapon( i, j );
			if ( pWeapon && pWeapon->GetWeaponInfo() && pWeapon->GetWeaponInfo()->GetBucket() > iBucketsToDraw )
				iBucketsToDraw = pWeapon->GetWeaponInfo()->GetBucket();
		}
	}
	iBucketsToDraw++;

	// Draw top line
	for ( i = 0; i < iBucketsToDraw; i++ )
	{
		int iWidth;

		GetHud().GetPrimaryColor().UnpackRGB(r,g,b);
	
		if ( iActiveSlot == i )
			a = 255;
		else
			a = 192;

		ScaleColors(r, g, b, 255);
		SPR_Set( GetHud().GetSprite(m_HUD_bucket0 + i), r, g, b );

		// make active slot wide enough to accomodate gun pictures
		if ( i == iActiveSlot )
		{
			CBasePlayerWeapon *p = pPlayer->GetFirstPos(iActiveSlot);
			if ( p )
				iWidth = p->GetWeaponInfo()->GetHUDInfo()->GetActive().rect.right - p->GetWeaponInfo()->GetHUDInfo()->GetActive().rect.left;
			else
				iWidth = m_iBucketWidth;
		}
		else
			iWidth = m_iBucketWidth;

		SPR_DrawAdditive(0, x, y, &GetHud().GetSpriteRect(m_HUD_bucket0 + i));
		
		x += iWidth + 5;
	}


	a = 128; //!!!
	x = 10;

	// Draw all of the buckets
	for (i = 0; i < iBucketsToDraw; i++)
	{
		y = m_iBucketHeight + 10;

		// If this is the active slot, draw the bigger pictures,
		// otherwise just draw boxes
		if ( i == iActiveSlot )
		{
			CBasePlayerWeapon *p = pPlayer->m_rgpPlayerItems[ i ];
			int iWidth = m_iBucketWidth;
			if ( p )
				iWidth = p->GetWeaponInfo()->GetHUDInfo()->GetActive().rect.right - p->GetWeaponInfo()->GetHUDInfo()->GetActive().rect.left;

			for( ; p; p = p->m_pNext )
			{
				if ( !p->GetWeaponInfo() )
					continue;

				auto pHUDInfo = p->GetWeaponInfo()->GetHUDInfo();

				GetHud().GetPrimaryColor().UnpackRGB( r,g,b );
			
				// if active, then we must have ammo.

				if ( m_pActiveSel == p )
				{
					SPR_Set( pHUDInfo->GetActive().hSprite, r, g, b );
					SPR_DrawAdditive(0, x, y, &pHUDInfo->GetActive().rect );

					SPR_Set( GetHud().GetSprite(m_HUD_selection), r, g, b );
					SPR_DrawAdditive(0, x, y, &GetHud().GetSpriteRect(m_HUD_selection));
				}
				else
				{
					// Draw Weapon if Red if no ammo

					if ( pPlayer->HasAmmo(p) )
						ScaleColors(r, g, b, 192);
					else
					{
						GetHud().GetEmptyItemColor().UnpackRGB(r,g,b);
						ScaleColors(r, g, b, 128);
					}

					SPR_Set( pHUDInfo->GetInactive().hSprite, r, g, b );
					SPR_DrawAdditive( 0, x, y, &pHUDInfo->GetInactive().rect );
				}

				// Draw Ammo Bar

				DrawAmmoBar(p, x + m_iABWidth/2, y, m_iABWidth, m_iABHeight);
				
				y += pHUDInfo->GetActive().rect.bottom - pHUDInfo->GetActive().rect.top + 5;
			}

			x += iWidth + 5;

		}
		else
		{
			// Draw Row of weapons.

			GetHud().GetPrimaryColor().UnpackRGB(r,g,b);

			for ( CBasePlayerWeapon* p = pPlayer->m_rgpPlayerItems[ i ]; p; p = p->m_pNext )
			{
				if ( !p->GetWeaponInfo() )
					continue;

				if ( pPlayer->HasAmmo(p) )
				{
					GetHud().GetPrimaryColor().UnpackRGB(r,g,b);
					a = 128;
				}
				else
				{
					GetHud().GetEmptyItemColor().UnpackRGB(r,g,b);
					a = 96;
				}

				FillRGBA( x, y, m_iBucketWidth, m_iBucketHeight, r, g, b, a );

				y += m_iBucketHeight + 5;
			}

			x += m_iBucketWidth + 5;
		}
	}	

	return 1;

}
コード例 #26
0
ファイル: CHudBattery.cpp プロジェクト: oskarlh/HLEnhanced
bool CHudBattery::Draw(float flTime)
{
	if ( GetHud().GetHideHudBits().Any( HIDEHUD_HEALTH ) )
		return true;

	wrect_t rc;

	rc = *m_prc2;

#if defined( _TFC )
	float fScale = 0.0;
	
	if ( m_iBatMax > 0 )
		fScale = 1.0 / (float)m_iBatMax;

	rc.top  += m_iHeight * ((float)(m_iBatMax-(min(m_iBatMax,m_iBat))) * fScale); // battery can go from 0 to m_iBatMax so * fScale goes from 0 to 1
#else
	rc.top  += m_iHeight * ((float)(100-(min(100,m_iBat))) * 0.01);	// battery can go from 0 to 100 so * 0.01 goes from 0 to 1
#endif

	if (!( Hud().GetWeaponBits() & (1<<(WEAPON_SUIT)) ))
		return true;

	int r, g, b, x, y, a = MIN_ALPHA;

	GetHud().GetPrimaryColor().UnpackRGB( r, g, b );

	// Has health changed? Flash the health #
	if (m_fFade)
	{
		if (m_fFade > FADE_TIME)
			m_fFade = FADE_TIME;

		m_fFade -= ( Hud().GetTimeDelta() * 20);
		if (m_fFade <= 0)
		{
			m_fFade = 0;
		}

		// Fade the health number back to dim

		a += ( m_fFade / FADE_TIME ) * 128;

	}

	ScaleColors(r, g, b, a );
	
	int iOffset = (m_prc1->bottom - m_prc1->top)/6;

	y = ScreenHeight - GetHud().GetFontHeight() - GetHud().GetFontHeight() / 2;
	x = ScreenWidth/5;

	// make sure we have the right sprite handles
	if ( !m_hSprite1 )
		m_hSprite1 = GetHud().GetSprite( GetHud().GetSpriteIndex( "suit_empty" ) );
	if ( !m_hSprite2 )
		m_hSprite2 = GetHud().GetSprite( GetHud().GetSpriteIndex( "suit_full" ) );

	SPR_Set(m_hSprite1, r, g, b );
	SPR_DrawAdditive( 0,  x, y - iOffset, m_prc1);

	if (rc.bottom > rc.top)
	{
		SPR_Set(m_hSprite2, r, g, b );
		SPR_DrawAdditive( 0, x, y - iOffset + (rc.top - m_prc2->top), &rc);
	}

	x += (m_prc1->right - m_prc1->left);
	x = GetHud().DrawHudNumber(x, y, DHN_3DIGITS | DHN_DRAWZERO, m_iBat, r, g, b);

	return true;
}
コード例 #27
0
ファイル: view.cpp プロジェクト: Randdalf/bliink
// This is called by cdll_client_int to setup view model origins. This has to be done before
// simulation so entities can access attachment points on view models during simulation.
void CViewRender::OnRenderStart()
{
	VPROF_("CViewRender::OnRenderStart", 2, VPROF_BUDGETGROUP_OTHER_UNACCOUNTED, false, 0);
	IterateRemoteSplitScreenViewSlots_Push( true );
	FOR_EACH_VALID_SPLITSCREEN_PLAYER( hh )
	{
		ACTIVE_SPLITSCREEN_PLAYER_GUARD_VGUI( hh );

		// This will fill in one of the m_UserView[ hh ] slots
		SetUpView();

		// Adjust mouse sensitivity based upon the current FOV
		C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
		if ( player )
		{
			default_fov.SetValue( player->m_iDefaultFOV );

			//Update our FOV, including any zooms going on
			int iDefaultFOV = default_fov.GetInt();
			int	localFOV	= player->GetFOV();
			int min_fov		= player->GetMinFOV();

			// Don't let it go too low
			localFOV = MAX( min_fov, localFOV );

			GetHud().m_flFOVSensitivityAdjust = 1.0f;
	#ifndef _XBOX
			if ( GetHud().m_flMouseSensitivityFactor )
			{
				GetHud().m_flMouseSensitivity = sensitivity.GetFloat() * GetHud().m_flMouseSensitivityFactor;
			}
			else
	#endif
			{
				// No override, don't use huge sensitivity
				if ( localFOV == iDefaultFOV )
				{
	#ifndef _XBOX
					// reset to saved sensitivity
					GetHud().m_flMouseSensitivity = 0;
	#endif
				}
				else
				{  
					// Set a new sensitivity that is proportional to the change from the FOV default and scaled
					//  by a separate compensating factor
					if ( iDefaultFOV == 0 )
					{
						Assert(0); // would divide by zero, something is broken with iDefatulFOV
						iDefaultFOV = 1;
					}
					GetHud().m_flFOVSensitivityAdjust = 
						((float)localFOV / (float)iDefaultFOV) * // linear fov downscale
						zoom_sensitivity_ratio.GetFloat(); // sensitivity scale factor
	#ifndef _XBOX
					GetHud().m_flMouseSensitivity = GetHud().m_flFOVSensitivityAdjust * sensitivity.GetFloat(); // regular sensitivity
	#endif
				}
			}
		}
	}

	// Setup the frustum cache for this frame.
	m_bAllowViewAccess = true;
	FOR_EACH_VALID_SPLITSCREEN_PLAYER( iSlot )
	{
		const CViewSetup &view = GetView( iSlot );
		FrustumCache()->Add( &view, iSlot );
	}
	FrustumCache()->SetUpdated();
	m_bAllowViewAccess = false;

	IterateRemoteSplitScreenViewSlots_Pop();
}
コード例 #28
0
//-----------------------------------------------------------------------------
// Purpose: Draw the weapon's crosshair
//-----------------------------------------------------------------------------
void C_BaseCombatWeapon::DrawCrosshair()
{
#ifndef INFESTED_DLL
	C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
	if ( !player )
		return;

	Color clr = GetHud().m_clrNormal;
/*

	// TEST: if the thing under your crosshair is on a different team, light the crosshair with a different color.
	Vector vShootPos, vShootAngles;
	GetShootPosition( vShootPos, vShootAngles );

	Vector vForward;
	AngleVectors( vShootAngles, &vForward );
	
	
	// Change the color depending on if we're looking at a friend or an enemy.
	CPartitionFilterListMask filter( PARTITION_ALL_CLIENT_EDICTS );	
	trace_t tr;
	traceline->TraceLine( vShootPos, vShootPos + vForward * 10000, COLLISION_GROUP_NONE, MASK_SHOT, &tr, true, ~0, &filter );

	if ( tr.index != 0 && tr.index != INVALID_CLIENTENTITY_HANDLE )
	{
		C_BaseEntity *pEnt = ClientEntityList().GetBaseEntityFromHandle( tr.index );
		if ( pEnt )
		{
			if ( pEnt->GetTeamNumber() != player->GetTeamNumber() )
			{
				g = b = 0;
			}
		}
	}		 
*/

	CHudCrosshair *crosshair = GET_HUDELEMENT( CHudCrosshair );
	if ( !crosshair )
		return;

	// Find out if this weapon's auto-aimed onto a target
	bool bOnTarget = ( m_iState == WEAPON_IS_ACTIVE ) && player->m_fOnTarget;
	
	if ( player->GetFOV() >= 90 )
	{ 
		// normal crosshairs
		if ( bOnTarget && GetWpnData().iconAutoaim )
		{
			clr[3] = 255;

			crosshair->SetCrosshair( GetWpnData().iconAutoaim, clr );
		}
		else if ( GetWpnData().iconCrosshair )
		{
			clr[3] = 255;
			crosshair->SetCrosshair( GetWpnData().iconCrosshair, clr );
		}
		else
		{
			crosshair->ResetCrosshair();
		}
	}
	else
	{ 
		Color white( 255, 255, 255, 255 );

		// zoomed crosshairs
		if (bOnTarget && GetWpnData().iconZoomedAutoaim)
			crosshair->SetCrosshair(GetWpnData().iconZoomedAutoaim, white);
		else if ( GetWpnData().iconZoomedCrosshair )
			crosshair->SetCrosshair( GetWpnData().iconZoomedCrosshair, white );
		else
			crosshair->ResetCrosshair();
	}
	#endif
}