Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
7.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements the big scary boom-boom machine Antlions fear.
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "EnvMessage.h"
  8. #include "fmtstr.h"
  9. #include "vguiscreen.h"
  10. #include "filesystem.h"
  11. struct SlideKeywordList_t
  12. {
  13. char szSlideKeyword[64];
  14. };
  15. class CNeurotoxinCountdown : public CBaseEntity
  16. {
  17. public:
  18. DECLARE_CLASS( CNeurotoxinCountdown, CBaseEntity );
  19. DECLARE_DATADESC();
  20. DECLARE_SERVERCLASS();
  21. virtual ~CNeurotoxinCountdown();
  22. virtual bool KeyValue( const char *szKeyName, const char *szValue );
  23. virtual int UpdateTransmitState();
  24. virtual void SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways );
  25. virtual void Spawn( void );
  26. virtual void Precache( void );
  27. virtual void OnRestore( void );
  28. void ScreenVisible( bool bVisible );
  29. void Disable( void );
  30. void Enable( void );
  31. void InputDisable( inputdata_t &inputdata );
  32. void InputEnable( inputdata_t &inputdata );
  33. private:
  34. // Control panel
  35. void GetControlPanelInfo( int nPanelIndex, const char *&pPanelName );
  36. void GetControlPanelClassName( int nPanelIndex, const char *&pPanelName );
  37. void SpawnControlPanels( void );
  38. void RestoreControlPanels( void );
  39. private:
  40. CNetworkVar( bool, m_bEnabled );
  41. int m_iScreenWidth;
  42. int m_iScreenHeight;
  43. typedef CHandle<CVGuiScreen> ScreenHandle_t;
  44. CUtlVector<ScreenHandle_t> m_hScreens;
  45. };
  46. LINK_ENTITY_TO_CLASS( vgui_neurotoxin_countdown, CNeurotoxinCountdown );
  47. //-----------------------------------------------------------------------------
  48. // Save/load
  49. //-----------------------------------------------------------------------------
  50. BEGIN_DATADESC( CNeurotoxinCountdown )
  51. DEFINE_FIELD( m_bEnabled, FIELD_BOOLEAN ),
  52. DEFINE_KEYFIELD( m_iScreenWidth, FIELD_INTEGER, "width" ),
  53. DEFINE_KEYFIELD( m_iScreenHeight, FIELD_INTEGER, "height" ),
  54. //DEFINE_UTLVECTOR( m_hScreens, FIELD_EHANDLE ),
  55. DEFINE_INPUTFUNC( FIELD_VOID, "Disable", InputDisable ),
  56. DEFINE_INPUTFUNC( FIELD_VOID, "Enable", InputEnable ),
  57. END_DATADESC()
  58. IMPLEMENT_SERVERCLASS_ST( CNeurotoxinCountdown, DT_NeurotoxinCountdown )
  59. SendPropBool( SENDINFO(m_bEnabled) ),
  60. END_SEND_TABLE()
  61. CNeurotoxinCountdown::~CNeurotoxinCountdown()
  62. {
  63. int i;
  64. // Kill the control panels
  65. for ( i = m_hScreens.Count(); --i >= 0; )
  66. {
  67. DestroyVGuiScreen( m_hScreens[i].Get() );
  68. }
  69. m_hScreens.RemoveAll();
  70. }
  71. //-----------------------------------------------------------------------------
  72. // Read in worldcraft data...
  73. //-----------------------------------------------------------------------------
  74. bool CNeurotoxinCountdown::KeyValue( const char *szKeyName, const char *szValue )
  75. {
  76. //!! temp hack, until worldcraft is fixed
  77. // strip the # tokens from (duplicate) key names
  78. char *s = (char *)strchr( szKeyName, '#' );
  79. if ( s )
  80. {
  81. *s = '\0';
  82. }
  83. // NOTE: Have to do these separate because they set two values instead of one
  84. if( FStrEq( szKeyName, "angles" ) )
  85. {
  86. Assert( GetMoveParent() == NULL );
  87. QAngle angles;
  88. UTIL_StringToVector( angles.Base(), szValue );
  89. // Because the vgui screen basis is strange (z is front, y is up, x is right)
  90. // we need to rotate the typical basis before applying it
  91. VMatrix mat, rotation, tmp;
  92. MatrixFromAngles( angles, mat );
  93. MatrixBuildRotationAboutAxis( rotation, Vector( 0, 1, 0 ), 90 );
  94. MatrixMultiply( mat, rotation, tmp );
  95. MatrixBuildRotateZ( rotation, 90 );
  96. MatrixMultiply( tmp, rotation, mat );
  97. MatrixToAngles( mat, angles );
  98. SetAbsAngles( angles );
  99. return true;
  100. }
  101. return BaseClass::KeyValue( szKeyName, szValue );
  102. }
  103. int CNeurotoxinCountdown::UpdateTransmitState()
  104. {
  105. return SetTransmitState( FL_EDICT_FULLCHECK );
  106. }
  107. void CNeurotoxinCountdown::SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
  108. {
  109. // Are we already marked for transmission?
  110. if ( pInfo->m_pTransmitEdict->Get( entindex() ) )
  111. return;
  112. BaseClass::SetTransmit( pInfo, bAlways );
  113. // Force our screens to be sent too.
  114. for ( int i=0; i < m_hScreens.Count(); i++ )
  115. {
  116. CVGuiScreen *pScreen = m_hScreens[i].Get();
  117. pScreen->SetTransmit( pInfo, bAlways );
  118. }
  119. }
  120. void CNeurotoxinCountdown::Spawn( void )
  121. {
  122. Precache();
  123. BaseClass::Spawn();
  124. m_bEnabled = false;
  125. SpawnControlPanels();
  126. ScreenVisible( m_bEnabled );
  127. }
  128. void CNeurotoxinCountdown::Precache( void )
  129. {
  130. BaseClass::Precache();
  131. PrecacheVGuiScreen( "neurotoxin_countdown_screen" );
  132. }
  133. void CNeurotoxinCountdown::OnRestore( void )
  134. {
  135. BaseClass::OnRestore();
  136. RestoreControlPanels();
  137. ScreenVisible( m_bEnabled );
  138. }
  139. void CNeurotoxinCountdown::ScreenVisible( bool bVisible )
  140. {
  141. for ( int iScreen = 0; iScreen < m_hScreens.Count(); ++iScreen )
  142. {
  143. CVGuiScreen *pScreen = m_hScreens[ iScreen ].Get();
  144. if ( bVisible )
  145. pScreen->RemoveEffects( EF_NODRAW );
  146. else
  147. pScreen->AddEffects( EF_NODRAW );
  148. }
  149. }
  150. void CNeurotoxinCountdown::Disable( void )
  151. {
  152. if ( !m_bEnabled )
  153. return;
  154. m_bEnabled = false;
  155. ScreenVisible( false );
  156. }
  157. void CNeurotoxinCountdown::Enable( void )
  158. {
  159. if ( m_bEnabled )
  160. return;
  161. m_bEnabled = true;
  162. ScreenVisible( true );
  163. }
  164. void CNeurotoxinCountdown::InputDisable( inputdata_t &inputdata )
  165. {
  166. Disable();
  167. }
  168. void CNeurotoxinCountdown::InputEnable( inputdata_t &inputdata )
  169. {
  170. Enable();
  171. }
  172. void CNeurotoxinCountdown::GetControlPanelInfo( int nPanelIndex, const char *&pPanelName )
  173. {
  174. pPanelName = "neurotoxin_countdown_screen";
  175. }
  176. void CNeurotoxinCountdown::GetControlPanelClassName( int nPanelIndex, const char *&pPanelName )
  177. {
  178. pPanelName = "vgui_screen";
  179. }
  180. //-----------------------------------------------------------------------------
  181. // This is called by the base object when it's time to spawn the control panels
  182. //-----------------------------------------------------------------------------
  183. void CNeurotoxinCountdown::SpawnControlPanels()
  184. {
  185. int nPanel;
  186. for ( nPanel = 0; true; ++nPanel )
  187. {
  188. const char *pScreenName;
  189. GetControlPanelInfo( nPanel, pScreenName );
  190. if (!pScreenName)
  191. continue;
  192. const char *pScreenClassname;
  193. GetControlPanelClassName( nPanel, pScreenClassname );
  194. if ( !pScreenClassname )
  195. continue;
  196. float flWidth = m_iScreenWidth;
  197. float flHeight = m_iScreenHeight;
  198. CVGuiScreen *pScreen = CreateVGuiScreen( pScreenClassname, pScreenName, this, this, -1 );
  199. pScreen->ChangeTeam( GetTeamNumber() );
  200. pScreen->SetActualSize( flWidth, flHeight );
  201. pScreen->SetActive( true );
  202. pScreen->MakeVisibleOnlyToTeammates( false );
  203. pScreen->SetTransparency( true );
  204. int nScreen = m_hScreens.AddToTail( );
  205. m_hScreens[nScreen].Set( pScreen );
  206. return;
  207. }
  208. }
  209. void CNeurotoxinCountdown::RestoreControlPanels( void )
  210. {
  211. int nPanel;
  212. for ( nPanel = 0; true; ++nPanel )
  213. {
  214. const char *pScreenName;
  215. GetControlPanelInfo( nPanel, pScreenName );
  216. if (!pScreenName)
  217. continue;
  218. const char *pScreenClassname;
  219. GetControlPanelClassName( nPanel, pScreenClassname );
  220. if ( !pScreenClassname )
  221. continue;
  222. CVGuiScreen *pScreen = (CVGuiScreen *)gEntList.FindEntityByClassname( NULL, pScreenClassname );
  223. while ( ( pScreen && pScreen->GetOwnerEntity() != this ) || Q_strcmp( pScreen->GetPanelName(), pScreenName ) != 0 )
  224. {
  225. pScreen = (CVGuiScreen *)gEntList.FindEntityByClassname( pScreen, pScreenClassname );
  226. }
  227. if ( pScreen )
  228. {
  229. int nScreen = m_hScreens.AddToTail( );
  230. m_hScreens[nScreen].Set( pScreen );
  231. pScreen->SetActive( true );
  232. }
  233. return;
  234. }
  235. }