summaryrefslogtreecommitdiff
path: root/game/client/hl2/c_info_teleporter_countdown.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/hl2/c_info_teleporter_countdown.cpp
downloadarchived-source-engine-2018-hl2-src-master.tar.xz
archived-source-engine-2018-hl2-src-master.zip
Diffstat (limited to 'game/client/hl2/c_info_teleporter_countdown.cpp')
-rw-r--r--game/client/hl2/c_info_teleporter_countdown.cpp194
1 files changed, 194 insertions, 0 deletions
diff --git a/game/client/hl2/c_info_teleporter_countdown.cpp b/game/client/hl2/c_info_teleporter_countdown.cpp
new file mode 100644
index 0000000..e99277c
--- /dev/null
+++ b/game/client/hl2/c_info_teleporter_countdown.cpp
@@ -0,0 +1,194 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//=============================================================================//
+#include "cbase.h"
+
+#include "c_vguiscreen.h"
+#include <vgui/IVGui.h>
+#include <vgui_controls/Controls.h>
+#include <vgui_controls/Label.h>
+#include "clientmode_hlnormal.h"
+#include "tier1/utllinkedlist.h"
+
+// memdbgon must be the last include file in a .cpp file!!!
+#include "tier0/memdbgon.h"
+
+
+//-----------------------------------------------------------------------------
+// Amount of time before breen teleports away
+//-----------------------------------------------------------------------------
+class C_InfoTeleporterCountdown : public C_BaseEntity
+{
+public:
+ DECLARE_CLASS( C_InfoTeleporterCountdown, C_BaseEntity );
+ DECLARE_CLIENTCLASS();
+
+public:
+ C_InfoTeleporterCountdown();
+ ~C_InfoTeleporterCountdown();
+
+ virtual bool ShouldDraw() { return false; }
+
+private:
+ bool m_bCountdownStarted;
+ bool m_bDisabled;
+ float m_flStartTime;
+ float m_flTimeRemaining;
+
+ friend class CTeleportCountdownScreen;
+};
+
+
+//-----------------------------------------------------------------------------
+// Global list of teleporters
+//-----------------------------------------------------------------------------
+CUtlFixedLinkedList<C_InfoTeleporterCountdown *> g_InfoTeleporterCountdownList;
+
+
+//-----------------------------------------------------------------------------
+// Networking
+//-----------------------------------------------------------------------------
+IMPLEMENT_CLIENTCLASS_DT( C_InfoTeleporterCountdown, DT_InfoTeleporterCountdown, CInfoTeleporterCountdown )
+ RecvPropInt( RECVINFO( m_bCountdownStarted ) ),
+ RecvPropInt( RECVINFO( m_bDisabled ) ),
+ RecvPropTime( RECVINFO( m_flStartTime ) ),
+ RecvPropFloat( RECVINFO( m_flTimeRemaining ) ),
+END_RECV_TABLE()
+
+
+//-----------------------------------------------------------------------------
+// Constructor, destructor
+//-----------------------------------------------------------------------------
+C_InfoTeleporterCountdown::C_InfoTeleporterCountdown()
+{
+ g_InfoTeleporterCountdownList.AddToTail( this );
+}
+
+C_InfoTeleporterCountdown::~C_InfoTeleporterCountdown()
+{
+ g_InfoTeleporterCountdownList.FindAndRemove( this );
+}
+
+
+//-----------------------------------------------------------------------------
+//
+// In-game vgui panel which shows the teleporter countdown
+//
+//-----------------------------------------------------------------------------
+class CTeleportCountdownScreen : public CVGuiScreenPanel
+{
+ DECLARE_CLASS( CTeleportCountdownScreen, CVGuiScreenPanel );
+
+public:
+ CTeleportCountdownScreen( vgui::Panel *parent, const char *panelName );
+
+ virtual bool Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData );
+ virtual void OnTick();
+
+private:
+ vgui::Label *m_pTimeRemainingTitleLabel;
+ vgui::Label *m_pTimeRemainingLabel;
+ vgui::Label *m_pMalfunctionLabel;
+};
+
+
+//-----------------------------------------------------------------------------
+// Standard VGUI panel for objects
+//-----------------------------------------------------------------------------
+DECLARE_VGUI_SCREEN_FACTORY( CTeleportCountdownScreen, "teleport_countdown_screen" );
+
+
+//-----------------------------------------------------------------------------
+// Constructor:
+//-----------------------------------------------------------------------------
+CTeleportCountdownScreen::CTeleportCountdownScreen( vgui::Panel *parent, const char *panelName )
+ : BaseClass( parent, panelName, g_hVGuiCombineScheme )
+{
+}
+
+
+//-----------------------------------------------------------------------------
+// Initialization
+//-----------------------------------------------------------------------------
+bool CTeleportCountdownScreen::Init( KeyValues* pKeyValues, VGuiScreenInitData_t* pInitData )
+{
+ // Load all of the controls in
+ if ( !BaseClass::Init(pKeyValues, pInitData) )
+ return false;
+
+ // Make sure we get ticked...
+ vgui::ivgui()->AddTickSignal( GetVPanel() );
+
+ // Grab ahold of certain well-known controls
+ // NOTE: it is valid for these controls to not exist!
+ m_pTimeRemainingTitleLabel = dynamic_cast<vgui::Label*>(FindChildByName( "TimeRemainingTitle" ));
+ m_pTimeRemainingLabel = dynamic_cast<vgui::Label*>(FindChildByName( "TimeRemaining" ));
+ m_pMalfunctionLabel = dynamic_cast<vgui::Label*>( FindChildByName( "MalfunctionLabel" ) );
+
+ return true;
+}
+
+
+//-----------------------------------------------------------------------------
+// Frame-based update
+//-----------------------------------------------------------------------------
+void CTeleportCountdownScreen::OnTick()
+{
+ BaseClass::OnTick();
+
+ // Find the active info teleporter countdown
+ C_InfoTeleporterCountdown *pActiveCountdown = NULL;
+ for ( int i = g_InfoTeleporterCountdownList.Head(); i != g_InfoTeleporterCountdownList.InvalidIndex();
+ i = g_InfoTeleporterCountdownList.Next(i) )
+ {
+ if ( g_InfoTeleporterCountdownList[i]->m_bCountdownStarted )
+ {
+ pActiveCountdown = g_InfoTeleporterCountdownList[i];
+ break;
+ }
+ }
+
+ if ( !GetEntity() || !pActiveCountdown )
+ {
+ m_pTimeRemainingTitleLabel->SetVisible( false );
+ m_pTimeRemainingLabel->SetVisible( false );
+ m_pMalfunctionLabel->SetVisible( false );
+
+ return;
+ }
+
+ // Make the appropriate labels visible
+ bool bMalfunction = pActiveCountdown->m_bDisabled;
+ m_pTimeRemainingTitleLabel->SetVisible( !bMalfunction );
+ m_pTimeRemainingLabel->SetVisible( !bMalfunction );
+
+ // This will make it flash
+ m_pMalfunctionLabel->SetVisible( bMalfunction && (((int)(gpGlobals->curtime) & 0x1) == 0x1) );
+
+ // Update the time remaining
+ if ( !bMalfunction )
+ {
+ char buf[32];
+ if (m_pTimeRemainingLabel)
+ {
+ float dt = gpGlobals->curtime - pActiveCountdown->m_flStartTime;
+ if ( dt < 0.0f )
+ {
+ dt = 0.0f;
+ }
+
+ int nTimeRemaining = (int)(pActiveCountdown->m_flTimeRemaining - dt + 0.5f);
+ if ( nTimeRemaining < 0 )
+ {
+ nTimeRemaining = 0;
+ }
+
+ Q_snprintf( buf, sizeof( buf ), "%d", nTimeRemaining );
+ m_pTimeRemainingLabel->SetText( buf );
+ }
+ }
+}
+