//----------------------------------------------------------------------------- // Purpose: Compute the size of the panel based upon the commander's zoom level //----------------------------------------------------------------------------- void CEntityPanel::ComputeAndSetSize( void ) { m_flScale = 1.0; // Scale the image // Use different scales in tactical / normal if ( IsLocalPlayerInTactical() ) { CClientModeCommander *commander = ( CClientModeCommander * )ClientModeCommander(); Assert( commander ); float flZoom = commander->GetCommanderOverlayPanel()->GetZoom(); // Scale our size m_flScale = 0.75 + (0.25 * (1.0 - flZoom)); // 1/2 size at max zoomed out, full size by half zoomed in } else if ( m_pBaseEntity ) { // Get distance to entity float flDistance = (m_pBaseEntity->GetRenderOrigin() - MainViewOrigin()).Length(); flDistance *= 2; m_flScale = 0.25 + MAX( 0, 2.0 - (flDistance / 2048) ); } // Update the size int w = m_iOrgWidth * m_flScale; int h = m_iOrgHeight * m_flScale; SetSize( w,h ); // Update the offsets too m_OffsetX = m_iOrgOffsetX * m_flScale; m_OffsetY = m_iOrgOffsetY * m_flScale; }
//----------------------------------------------------------------------------- // called when we're ticked... //----------------------------------------------------------------------------- void CEntityImageHealthPanel::OnTick() { // tick the entity panel BaseClass::OnTick(); C_BaseEntity* pBaseEntity = GetEntity(); if (!pBaseEntity) return; // Don't draw if I'm not visible in the tactical map if ( MapData().IsEntityVisibleToTactical( pBaseEntity ) == false ) return; if ( m_CommanderHealthBar ) m_CommanderHealthBar->SetHealth( (float)pBaseEntity->GetHealth() / (float)pBaseEntity->GetMaxHealth() ); if ( m_NormalHealthBar ) m_NormalHealthBar->SetHealth( (float)pBaseEntity->GetHealth() / (float)pBaseEntity->GetMaxHealth() ); // Hide the health bar we don't want to see C_BasePlayer *pPlayer = C_BasePlayer::GetLocalPlayer(); if ( pPlayer && (pBaseEntity->GetTeamNumber() != pPlayer->GetTeamNumber()) ) { if ( m_CommanderHealthBar ) m_CommanderHealthBar->SetVisible( false ); if ( m_NormalHealthBar ) m_NormalHealthBar->SetVisible( false ); if ( m_ResourceLevelBar ) m_ResourceLevelBar->SetVisible( false ); if ( m_pImagePanel ) m_pImagePanel->SetVisible( false ); } else if ( IsLocalPlayerInTactical() ) { if ( m_CommanderHealthBar ) m_CommanderHealthBar->SetVisible( true ); if ( m_NormalHealthBar ) m_NormalHealthBar->SetVisible( false ); if ( m_ResourceLevelBar ) m_ResourceLevelBar->SetVisible( true ); if ( m_pImagePanel ) m_pImagePanel->SetVisible( true ); } else { if ( m_CommanderHealthBar ) m_CommanderHealthBar->SetVisible( false ); if ( m_NormalHealthBar ) m_NormalHealthBar->SetVisible( true ); if ( m_ResourceLevelBar ) m_ResourceLevelBar->SetVisible( true ); if ( m_pImagePanel ) m_pImagePanel->SetVisible( false ); } }
//----------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------- void CEntityPanel::ComputeParent( void ) { vgui::VPANEL parent = NULL; if ( IsLocalPlayerInTactical() || !m_bShowInNormal ) { CClientModeCommander *commander = ( CClientModeCommander * )ClientModeCommander(); Assert( commander ); parent = commander->GetCommanderOverlayPanel()->GetVPanel(); } else { parent = enginevgui->GetPanel( PANEL_CLIENTDLL ); } if ( !GetParent() || ( GetParent()->GetVPanel() != parent ) ) { SetParent( parent ); } }
//----------------------------------------------------------------------------- // Should we draw?. //----------------------------------------------------------------------------- bool CEntityPanel::ShouldDraw() { return ( ( IsLocalPlayerInTactical() && ClientModeCommander()->ShouldDrawEntity( m_pBaseEntity ) ) || ( !IsLocalPlayerInTactical() && m_bShowInNormal) ); }
//----------------------------------------------------------------------------- // Should we draw?. //----------------------------------------------------------------------------- bool CEntityImagePanel::ShouldDraw() { return ( IsLocalPlayerInTactical() || m_bShowInNormal ); }
void CHudPlayerOverlay::OnTick( ) { BaseClass::OnTick(); if (!IsLocalPlayerInTactical() || !engine->IsInGame()) { Hide(); return; } // Don't draw if I'm not visible in the tactical map if ( MapData().IsEntityVisibleToTactical( GetEntity() ) == false ) { Hide(); return; } // Don't draw it if I'm on team 0 (haven't decided on a team) C_BaseTFPlayer *pPlayer = m_hPlayer.Get(); if (!pPlayer || (pPlayer->GetTeamNumber() == 0) || (pPlayer->GetClass() == TFCLASS_UNDECIDED)) { Hide(); return; } SetVisible( true ); char *pName = g_PR->Get_Name( m_PlayerNum ); if ( pName ) { m_pName->SetName( pName ); } else { Hide(); return; } Vector pos, screen; C_BaseTFPlayer *tf2player = dynamic_cast<C_BaseTFPlayer *>( GetEntity() ); int iteam = 0; int iclass = 0; if ( tf2player ) { iteam = tf2player->GetTeamNumber(); iclass = tf2player->PlayerClass(); // FIXME: Get max health for player m_pHealth->SetHealth( (float)tf2player->GetHealth() / (float)100.0f ); } m_pClass->SetImage( 0 ); if ( iteam != 0 && iclass != TFCLASS_UNDECIDED ) m_pClass->SetTeamAndClass( iteam, iclass ); // Update our position on screen int sx, sy; GetEntityPosition( sx, sy ); // Set the position SetPos( (int)(sx + m_OffsetX + 0.5f), (int)(sy + m_OffsetY + 0.5f)); // Add it in m_pHealth->SetVisible( true ); m_pName->SetVisible( true ); m_pClass->SetVisible( true ); if ( MapData().m_Players[ m_PlayerNum - 1 ].m_bSelected ) { m_pSelected->SetVisible( true ); } else { m_pSelected->SetVisible( false ); } if ( MapData().m_Players[ m_PlayerNum - 1 ].m_nSquadNumber != 0 ) { char sz[ 32 ]; Q_snprintf( sz, sizeof( sz ), "%i", MapData().m_Players[ m_PlayerNum - 1 ].m_nSquadNumber ); m_pSquad->SetSquad( sz ); m_pSquad->SetVisible( true ); } else { m_pSquad->SetVisible( false ); } // Hide details if it's an enemy if ( ArePlayersOnSameTeam( engine->GetPlayer(), m_PlayerNum ) == false ) { m_pHealth->SetVisible( false ); m_pName->SetVisible( false ); m_pSelected->SetVisible( false ); m_pSquad->SetVisible( false ); // Only show class icon m_pClass->SetVisible( true ); } }