summaryrefslogtreecommitdiff
path: root/game/client/dod/dod_hud_playerstatus_stamina.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/dod/dod_hud_playerstatus_stamina.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/client/dod/dod_hud_playerstatus_stamina.cpp')
-rw-r--r--game/client/dod/dod_hud_playerstatus_stamina.cpp172
1 files changed, 172 insertions, 0 deletions
diff --git a/game/client/dod/dod_hud_playerstatus_stamina.cpp b/game/client/dod/dod_hud_playerstatus_stamina.cpp
new file mode 100644
index 0000000..7edbed7
--- /dev/null
+++ b/game/client/dod/dod_hud_playerstatus_stamina.cpp
@@ -0,0 +1,172 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+//=============================================================================//
+
+#include "cbase.h"
+#include <KeyValues.h>
+#include <vgui/IScheme.h>
+#include <vgui/ISurface.h>
+#include <vgui/ISystem.h>
+#include <vgui_controls/AnimationController.h>
+#include <vgui_controls/EditablePanel.h>
+#include <vgui_controls/ImagePanel.h>
+
+#include <vgui/ISurface.h>
+
+#include "c_dod_team.h"
+#include "c_dod_playerresource.h"
+#include "c_dod_player.h"
+
+#include "dodcornercutpanel.h"
+#include "dod_hud_playerstatus_stamina.h"
+
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CDoDHudStaminaProgressBar::ApplySchemeSettings( vgui::IScheme *pScheme )
+{
+ BaseClass::ApplySchemeSettings( pScheme );
+
+ m_clrActive = pScheme->GetColor( "HudStaminaBar.Active", GetFgColor() );
+ m_clrActiveLow = pScheme->GetColor( "HudStaminaBar.ActiveLow", GetFgColor() );
+ m_clrInactive = pScheme->GetColor( "HudStaminaBar.InActive", GetFgColor() );
+ m_clrInactiveLow = pScheme->GetColor( "HudStaminaBar.InActiveLow", GetFgColor() );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CDoDHudStaminaProgressBar::Paint()
+{
+ BaseClass::Paint();
+
+ int xpos = 0, ypos = 0;
+ int x, y, w, t;
+ GetBounds( x, y, w, t );
+
+ if ( m_flPercentage < m_flWarningLevel )
+ {
+ vgui::surface()->DrawSetColor( m_clrActiveLow );
+ }
+ else
+ {
+ vgui::surface()->DrawSetColor( m_clrActive );
+ }
+
+ int nActiveLimit = w * m_flPercentage;
+
+ while ( xpos + m_flSliceWidth < w )
+ {
+ if ( xpos + m_flSliceWidth > nActiveLimit )
+ {
+ if ( m_flPercentage < m_flWarningLevel )
+ {
+ vgui::surface()->DrawSetColor( m_clrInactiveLow );
+ }
+ else
+ {
+ vgui::surface()->DrawSetColor( m_clrInactive );
+ }
+ }
+
+ vgui::surface()->DrawFilledRect( xpos, ypos, xpos + m_flSliceWidth, ypos + t );
+ xpos += m_flSliceWidth + m_flSliceSpacer;
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CDoDHudStaminaIcon::CDoDHudStaminaIcon( vgui::Panel *parent, const char *name ) : vgui::ImagePanel( parent, name )
+{
+ m_icon = NULL;
+ memset( m_szIcon, 0, sizeof( m_szIcon ) );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CDoDHudStaminaIcon::ApplySettings( KeyValues *inResourceData )
+{
+ BaseClass::ApplySettings( inResourceData );
+
+ Q_strncpy( m_szIcon, inResourceData->GetString( "stamina_icon", "stamina_icon" ), sizeof( m_szIcon ) );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CDoDHudStaminaIcon::ApplySchemeSettings( vgui::IScheme *pScheme )
+{
+ BaseClass::ApplySchemeSettings( pScheme );
+
+ m_clrActive = pScheme->GetColor( "HudStaminaIcon.Active", GetFgColor() );
+ m_clrActiveLow = pScheme->GetColor( "HudStaminaIcon.ActiveLow", GetFgColor() );
+
+ if ( !m_icon )
+ {
+ m_icon = gHUD.GetIcon( m_szIcon );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CDoDHudStaminaIcon::Paint()
+{
+ int x, y, w, t;
+ GetBounds( x, y, w, t );
+
+ if ( m_icon )
+ {
+ m_icon->DrawSelf( 0, -3, w, t, ( m_flPercentage < m_flWarningLevel ) ? m_clrActiveLow : m_clrActive );
+ }
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+CDoDHudStamina::CDoDHudStamina( vgui::Panel *parent, const char *name ) : vgui::EditablePanel( parent, name )
+{
+ m_pBackground = new CDoDCutEditablePanel( this, "StaminaBackground" );
+ m_pIcon = new CDoDHudStaminaIcon( this, "StaminaIcon" );
+ m_pProgressBar = new CDoDHudStaminaProgressBar( this, "StaminaProgressBar" );
+
+ // load control settings...
+ LoadControlSettings( "resource/UI/HudPlayerStatusStamina.res" );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CDoDHudStamina::OnScreenSizeChanged( int iOldWide, int iOldTall )
+{
+ LoadControlSettings( "resource/UI/HudPlayerStatusStamina.res" );
+}
+
+//-----------------------------------------------------------------------------
+// Purpose:
+//-----------------------------------------------------------------------------
+void CDoDHudStamina::OnThink()
+{
+ BaseClass::OnThink();
+
+ C_DODPlayer *pPlayer = C_DODPlayer::GetLocalDODPlayer();
+ if ( pPlayer )
+ {
+ float flPercentage = (float)( pPlayer->m_Shared.GetStamina() ) / 100.0f;
+
+ if ( m_pProgressBar )
+ {
+ m_pProgressBar->SetPercentage( flPercentage );
+ }
+
+ if ( m_pIcon )
+ {
+ m_pIcon->SetPercentage( flPercentage );
+ }
+ }
+}