summaryrefslogtreecommitdiff
path: root/game/client/vgui_imagehealthpanel.cpp
diff options
context:
space:
mode:
authorFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
committerFluorescentCIAAfricanAmerican <[email protected]>2020-04-22 12:56:21 -0400
commit3bf9df6b2785fa6d951086978a3e66f49427166a (patch)
tree2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /game/client/vgui_imagehealthpanel.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/client/vgui_imagehealthpanel.cpp')
-rw-r--r--game/client/vgui_imagehealthpanel.cpp181
1 files changed, 181 insertions, 0 deletions
diff --git a/game/client/vgui_imagehealthpanel.cpp b/game/client/vgui_imagehealthpanel.cpp
new file mode 100644
index 0000000..69119cb
--- /dev/null
+++ b/game/client/vgui_imagehealthpanel.cpp
@@ -0,0 +1,181 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose: This is a panel which is rendered image on top of an entity
+//
+// $Revision: $
+// $NoKeywords: $
+//=============================================================================//
+#include "cbase.h"
+#include "vgui_imagehealthpanel.h"
+#include "commanderoverlay.h"
+#include <KeyValues.h>
+#include "mapdata.h"
+
+bool IsLocalPlayerInTactical( void );
+
+//-----------------------------------------------------------------------------
+// Class factory
+//-----------------------------------------------------------------------------
+
+DECLARE_OVERLAY_FACTORY( CEntityImageHealthPanel, "image_health" );
+
+
+//-----------------------------------------------------------------------------
+// Constructor
+//-----------------------------------------------------------------------------
+CEntityImageHealthPanel::CEntityImageHealthPanel( vgui::Panel *parent, const char *panelName )
+: BaseClass( parent, "CEntityImageHealthPanel" )
+{
+ SetPaintBackgroundEnabled( false );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CEntityImageHealthPanel::~CEntityImageHealthPanel()
+{
+ if ( m_pImagePanel )
+ {
+ delete m_pImagePanel;
+ m_pImagePanel = NULL;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// initialization
+//-----------------------------------------------------------------------------
+bool CEntityImageHealthPanel::Init( KeyValues* pInitData, C_BaseEntity* pEntity )
+{
+ if ( !pInitData )
+ return false;
+ if ( !BaseClass::Init( pInitData, pEntity ) )
+ return false;
+
+ m_CommanderHealthBar = NULL;
+ m_NormalHealthBar = NULL;
+ m_ResourceLevelBar = NULL;
+ m_pImagePanel = NULL;
+
+ // Health bar when we're in commander view
+ KeyValues *pHealth = pInitData->FindKey("health_commander");
+ if ( pHealth )
+ {
+ m_CommanderHealthBar = new CHealthBarPanel();
+ if (!m_CommanderHealthBar->Init( pHealth ))
+ return false;
+ m_CommanderHealthBar->SetParent( this );
+ }
+
+ // Health bar when we're in normal view
+ pHealth = pInitData->FindKey("health_normal");
+ if ( pHealth )
+ {
+ m_NormalHealthBar = new CHealthBarPanel();
+ if (!m_NormalHealthBar->Init( pHealth ))
+ return false;
+ m_NormalHealthBar->SetParent( this );
+ }
+
+ // Resource bar for collectors
+ KeyValues *pResources = pInitData->FindKey("resource_level");
+ if ( pResources )
+ {
+ m_ResourceLevelBar = new CHealthBarPanel();
+ if (!m_ResourceLevelBar->Init( pResources ))
+ return false;
+ m_ResourceLevelBar->SetParent( this );
+ }
+
+ KeyValues *pImage = pInitData->FindKey("Image");
+ if ( pImage )
+ {
+ m_pImagePanel = new CEntityTeamImagePanel( this, "CEntityTeamImagePanel" );
+ if ( !m_pImagePanel->Init( pImage, GetEntity() ) )
+ return false;
+ }
+
+ return true;
+}
+
+//-----------------------------------------------------------------------------
+// Should we draw?.
+//-----------------------------------------------------------------------------
+bool CEntityImageHealthPanel::ShouldDraw( void )
+{
+ // Always draw health
+ return true;
+}
+
+//-----------------------------------------------------------------------------
+// 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: Compute the size of the panel based upon the commander's zoom level
+//-----------------------------------------------------------------------------
+void CEntityImageHealthPanel::ComputeAndSetSize( void )
+{
+ BaseClass::ComputeAndSetSize();
+
+ // Now update the bars
+ if ( m_CommanderHealthBar )
+ m_CommanderHealthBar->SetSize( GetWide(), m_CommanderHealthBar->GetTall() );
+ if ( m_NormalHealthBar )
+ m_NormalHealthBar->SetSize( GetWide(), m_CommanderHealthBar->GetTall() );
+ if ( m_ResourceLevelBar )
+ m_ResourceLevelBar->SetSize( GetWide(), m_CommanderHealthBar->GetTall() );
+}