void CHudCrosshair::Paint( void ) { if ( !m_pCrosshair ) return; if ( !IsCurrentViewAccessAllowed() ) return; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return; float x, y; bool bBehindCamera; GetDrawPosition ( &x, &y, &bBehindCamera, m_vecCrossHairOffsetAngle ); if( bBehindCamera ) return; float flWeaponScale = 1.f; int iTextureW = m_pCrosshair->Width(); int iTextureH = m_pCrosshair->Height(); C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon ) { pWeapon->GetWeaponCrosshairScale( flWeaponScale ); } float flPlayerScale = 1.0f; #ifdef TF_CLIENT_DLL Color clr( cl_crosshair_red.GetInt(), cl_crosshair_green.GetInt(), cl_crosshair_blue.GetInt(), 255 ); flPlayerScale = cl_crosshair_scale.GetFloat() / 32.0f; // the player can change the scale in the options/multiplayer tab #else Color clr = m_clrCrosshair; #endif float flWidth = flWeaponScale * flPlayerScale * (float)iTextureW; float flHeight = flWeaponScale * flPlayerScale * (float)iTextureH; int iWidth = (int)( flWidth + 0.5f ); int iHeight = (int)( flHeight + 0.5f ); int iX = (int)( x + 0.5f ); int iY = (int)( y + 0.5f ); if (pPlayer->IsInVGuiInputMode() && m_pVGUIHoverIcon) m_pVGUIHoverIcon->DrawSelf( iX - (m_pVGUIHoverIcon->Width() / 2), iY - (m_pVGUIHoverIcon->Height() / 2), m_pVGUIHoverIcon->Width(), m_pVGUIHoverIcon->Height(), Color(0, 255, 0, 255)); else { m_pCrosshair->DrawSelfCropped( iX - (iWidth / 2), iY - (iHeight + 2), 0, 0, iTextureW, iTextureH, iWidth, iHeight, clr); } }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CHudCrosshair::ShouldDraw( void ) { bool bNeedsDraw; if ( m_bHideCrosshair ) return false; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon && !pWeapon->ShouldDrawCrosshair() ) return false; #ifdef PORTAL C_Portal_Player *portalPlayer = ToPortalPlayer(pPlayer); if ( portalPlayer && portalPlayer->IsSuppressingCrosshair() ) return false; #endif // PORTAL /* disabled to avoid assuming it's an HL2 player. // suppress crosshair in zoom. if ( pPlayer->m_HL2Local.m_bZooming ) return false; */ // draw a crosshair only if alive or spectating in eye if ( IsX360() ) { bNeedsDraw = m_pCrosshair && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && ( !pPlayer->IsSuitEquipped() || g_pGameRules->IsMultiplayer() ) && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } else { bNeedsDraw = m_pCrosshair && crosshair.GetInt() && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && !pPlayer->IsInVGuiInputMode() && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } return ( bNeedsDraw && CHudElement::ShouldDraw() ); }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CDAHudCrosshair::ShouldDraw( void ) { // OnThink isn't called when the thing isn't visible so force it to update. CalculateCrosshair(); bool bNeedsDraw; if ( m_bHideCrosshair ) return false; C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; C_BaseCombatWeapon *pWeapon = pPlayer->GetActiveWeapon(); if ( pWeapon && !pWeapon->ShouldDrawCrosshair() ) return false; ConVarRef cl_observercrosshair("cl_observercrosshair"); // draw a crosshair only if alive or spectating in eye if ( IsX360() ) { bNeedsDraw = m_pCrosshair && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && ( !pPlayer->IsSuitEquipped() || g_pGameRules->IsMultiplayer() ) && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } else { bNeedsDraw = m_pCrosshair && da_crosshair.GetInt() && !engine->IsDrawingLoadingImage() && !engine->IsPaused() && g_pClientMode->ShouldDrawCrosshair() && !( pPlayer->GetFlags() & FL_FROZEN ) && ( pPlayer->entindex() == render->GetViewEntity() ) && !pPlayer->IsInVGuiInputMode() && ( pPlayer->IsAlive() || ( pPlayer->GetObserverMode() == OBS_MODE_IN_EYE ) || ( cl_observercrosshair.GetBool() && pPlayer->GetObserverMode() == OBS_MODE_ROAMING ) ); } return ( bNeedsDraw && CHudElement::ShouldDraw() ); }
//----------------------------------------------------------------------------- // Purpose: Save CPU cycles by letting the HUD system early cull // costly traversal. Called per frame, return true if thinking and // painting need to occur. //----------------------------------------------------------------------------- bool CHudVguiScreenCursor::ShouldDraw( void ) { C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return false; if ( pPlayer->IsInViewModelVGuiInputMode() ) { return false; } if ( !pPlayer->IsInVGuiInputMode() ) { return false; } return CHudElement::ShouldDraw(); }
//----------------------------------------------------------------------------- // Purpose: Think used for selection of weapon menu item. //----------------------------------------------------------------------------- void CBaseHudWeaponSelection::ProcessInput() { C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( !pPlayer ) return; // Check to see if the player is in VGUI mode... if ( pPlayer->IsInVGuiInputMode() && !pPlayer->IsInViewModelVGuiInputMode() ) { // If so, close weapon selection when they press fire if ( gHUD.m_iKeyBits & IN_ATTACK ) { if ( HUDTYPE_PLUS != hud_fastswitch.GetInt() ) { // Swallow the button gHUD.m_iKeyBits &= ~IN_ATTACK; input->ClearInputButton( IN_ATTACK ); } engine->ClientCmd( "cancelselect\n" ); } return; } // Has the player selected a weapon? if ( gHUD.m_iKeyBits & (IN_ATTACK | IN_ATTACK2) ) { if ( IsWeaponSelectable() ) { #ifndef TF_CLIENT_DLL if ( HUDTYPE_PLUS != hud_fastswitch.GetInt() ) #endif { // Swallow the button gHUD.m_iKeyBits &= ~(IN_ATTACK | IN_ATTACK2); input->ClearInputButton( IN_ATTACK ); input->ClearInputButton( IN_ATTACK2 ); } // select weapon SelectWeapon(); } } }
//----------------------------------------------------------------------------- // Purpose: Draw the weapon's crosshair //----------------------------------------------------------------------------- void C_BaseCombatWeapon::DrawCrosshair() { C_BasePlayer *player = C_BasePlayer::GetLocalPlayer(); if ( !player ) return; Color clr = gHUD.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; // Check to see if the player is in VGUI mode... if (player->IsInVGuiInputMode()) { CHudTexture *pArrow = gHUD.GetIcon( "arrow" ); crosshair->SetCrosshair( pArrow, gHUD.m_clrNormal ); return; } // Find out if this weapon's auto-aimed onto a target bool bOnTarget = ( m_iState == WEAPON_IS_ONTARGET ); 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(); } }