Counter Strike : Global Offensive Source Code
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.

487 lines
13 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "ivmodemanager.h"
  10. #include "clientmode_hlnormal.h"
  11. #include "panelmetaclassmgr.h"
  12. #include "c_playerresource.h"
  13. #include "c_portal_player.h"
  14. #include "clientmode_portal.h"
  15. #include "usermessages.h"
  16. #include "prediction.h"
  17. #include "portal2/vgui/portalclientscoreboard.h"
  18. #include "portal2/vgui/surveypanel.h"
  19. #include "hud_macros.h"
  20. #include "radialmenu.h"
  21. #include "glow_outline_effect.h"
  22. #include "portal2/portal_grabcontroller_shared.h"
  23. #include "viewpostprocess.h"
  24. #include "radialmenu.h"
  25. #include "fmtstr.h"
  26. #include "ivieweffects.h"
  27. // memdbgon must be the last include file in a .cpp file!!!
  28. #include "tier0/memdbgon.h"
  29. // default FOV for HL2
  30. ConVar default_fov( "default_fov", "75", FCVAR_CHEAT );
  31. ConVar fov_desired( "fov_desired", "75", FCVAR_ARCHIVE | FCVAR_USERINFO, "Sets the base field-of-view.", true, 75.0, true, 90.0 );
  32. extern ConVar hide_gun_when_holding;
  33. extern ConVar v_viewmodel_fov;
  34. ConVar cl_viewmodelfov( "cl_viewmodelfov", "50", FCVAR_DEVELOPMENTONLY );
  35. ConVar cl_finale_completed( "cl_finale_completed", "0", FCVAR_HIDDEN );
  36. #define DEATH_CC_LOOKUP_FILENAME "materials/correction/cc_death.raw"
  37. #define DEATH_CC_FADE_SPEED 0.05f
  38. // The current client mode. Always ClientModeNormal in HL.
  39. static IClientMode *g_pClientMode[ MAX_SPLITSCREEN_PLAYERS ];
  40. IClientMode *GetClientMode()
  41. {
  42. ASSERT_LOCAL_PLAYER_RESOLVABLE();
  43. return g_pClientMode[ GET_ACTIVE_SPLITSCREEN_SLOT() ];
  44. }
  45. //extern EHANDLE g_eKillTarget1;
  46. //extern EHANDLE g_eKillTarget2;
  47. vgui::HScheme g_hVGuiCombineScheme = 0;
  48. #define SCREEN_FILE "scripts/vgui_screens.txt"
  49. // Voice data
  50. void VoxCallback( IConVar *var, const char *oldString, float oldFloat )
  51. {
  52. if ( engine && engine->IsConnected() )
  53. {
  54. ConVarRef voice_vox( var->GetName() );
  55. if ( voice_vox.GetBool() /*&& voice_modenable.GetBool()*/ )
  56. {
  57. engine->ClientCmd( "voicerecord_toggle on\n" );
  58. }
  59. else
  60. {
  61. engine->ClientCmd( "voicerecord_toggle off\n" );
  62. }
  63. }
  64. }
  65. ConVar voice_vox( "voice_vox", "1", FCVAR_ARCHIVE, "Voice chat uses a vox-style always on", false, 0, true, 1, VoxCallback );
  66. //--------------------------------------------------------------------------------------------------------
  67. class CVoxManager : public CAutoGameSystem
  68. {
  69. public:
  70. CVoxManager() : CAutoGameSystem( "VoxManager" ) { }
  71. virtual void LevelInitPostEntity( void )
  72. {
  73. if ( voice_vox.GetBool() /*&& voice_modenable.GetBool()*/ )
  74. {
  75. engine->ClientCmd( "voicerecord_toggle on\n" );
  76. }
  77. }
  78. virtual void LevelShutdownPreEntity( void )
  79. {
  80. if ( voice_vox.GetBool() )
  81. {
  82. engine->ClientCmd( "voicerecord_toggle off\n" );
  83. }
  84. }
  85. };
  86. //--------------------------------------------------------------------------------------------------------
  87. static CVoxManager s_VoxManager;
  88. //-----------------------------------------------------------------------------
  89. // Purpose: this is the viewport that contains all the hud elements
  90. //-----------------------------------------------------------------------------
  91. class CHudViewport : public CBaseViewport
  92. {
  93. private:
  94. DECLARE_CLASS_SIMPLE( CHudViewport, CBaseViewport );
  95. protected:
  96. virtual void ApplySchemeSettings( vgui::IScheme *pScheme )
  97. {
  98. BaseClass::ApplySchemeSettings( pScheme );
  99. GetHud().InitColors( pScheme );
  100. SetPaintBackgroundEnabled( false );
  101. }
  102. virtual IViewPortPanel *CreatePanelByName( const char *szPanelName );
  103. };
  104. IViewPortPanel* CHudViewport::CreatePanelByName( const char *szPanelName )
  105. {
  106. IViewPortPanel* newpanel = NULL;
  107. if ( Q_strcmp( PANEL_SCOREBOARD, szPanelName) == 0 )
  108. {
  109. newpanel = new CPortalClientScoreBoardDialog( this );
  110. return newpanel;
  111. }
  112. else if ( Q_strcmp( PANEL_SURVEY, szPanelName) == 0 )
  113. {
  114. newpanel = new CSurveyPanel( this );
  115. return newpanel;
  116. }
  117. /*else if ( Q_strcmp(PANEL_INFO, szPanelName) == 0 )
  118. {
  119. newpanel = new CHL2MPTextWindow( this );
  120. return newpanel;
  121. }*/
  122. return BaseClass::CreatePanelByName( szPanelName );
  123. }
  124. class CHLModeManager : public IVModeManager
  125. {
  126. public:
  127. CHLModeManager( void );
  128. virtual ~CHLModeManager( void );
  129. virtual void Init( void );
  130. virtual void SwitchMode( bool commander, bool force );
  131. virtual void OverrideView( CViewSetup *pSetup );
  132. virtual void CreateMove( float flInputSampleTime, CUserCmd *cmd );
  133. virtual void LevelInit( const char *newmap );
  134. virtual void LevelShutdown( void );
  135. };
  136. CHLModeManager::CHLModeManager( void )
  137. {
  138. }
  139. CHLModeManager::~CHLModeManager( void )
  140. {
  141. }
  142. void CHLModeManager::Init( void )
  143. {
  144. for( int i = 0; i < MAX_SPLITSCREEN_PLAYERS; ++i )
  145. {
  146. ACTIVE_SPLITSCREEN_PLAYER_GUARD( i );
  147. g_pClientMode[ i ] = GetClientModeNormal();
  148. }
  149. PanelMetaClassMgr()->LoadMetaClassDefinitionFile( SCREEN_FILE );
  150. }
  151. void CHLModeManager::SwitchMode( bool commander, bool force )
  152. {
  153. }
  154. void CHLModeManager::OverrideView( CViewSetup *pSetup )
  155. {
  156. }
  157. void CHLModeManager::CreateMove( float flInputSampleTime, CUserCmd *cmd )
  158. {
  159. }
  160. void CHLModeManager::LevelInit( const char *newmap )
  161. {
  162. for( int i = 0; i < MAX_SPLITSCREEN_PLAYERS; ++i )
  163. {
  164. ACTIVE_SPLITSCREEN_PLAYER_GUARD( i );
  165. GetClientMode()->LevelInit( newmap );
  166. }
  167. if ( g_nKillCamMode > OBS_MODE_NONE )
  168. {
  169. g_bForceCLPredictOff = false;
  170. }
  171. g_nKillCamMode = OBS_MODE_NONE;
  172. }
  173. void CHLModeManager::LevelShutdown( void )
  174. {
  175. for( int i = 0; i < MAX_SPLITSCREEN_PLAYERS; ++i )
  176. {
  177. ACTIVE_SPLITSCREEN_PLAYER_GUARD( i );
  178. GetClientMode()->LevelShutdown();
  179. }
  180. }
  181. //--------------------------------------------------------------------------------------------------------
  182. static void __MsgFunc_TransitionFade( bf_read &msg )
  183. {
  184. float flFadeTime = msg.ReadFloat();
  185. GetClientModePortalNormal()->StartTransitionFade( flFadeTime );
  186. }
  187. //-----------------------------------------------------------------------------
  188. // Purpose:
  189. //-----------------------------------------------------------------------------
  190. ClientModePortalNormal::ClientModePortalNormal()
  191. {
  192. m_BlurFadeScale = 0;
  193. m_pRadialMenu = NULL;
  194. }
  195. //-----------------------------------------------------------------------------
  196. // Purpose: If you don't know what a destructor is by now, you are probably going to get fired
  197. //-----------------------------------------------------------------------------
  198. ClientModePortalNormal::~ClientModePortalNormal()
  199. {
  200. }
  201. void ClientModePortalNormal::Init()
  202. {
  203. BaseClass::Init();
  204. HOOK_MESSAGE( TransitionFade );
  205. InitRadialMenuHudElement();
  206. }
  207. void ClientModePortalNormal::InitViewport()
  208. {
  209. m_pViewport = new CHudViewport();
  210. m_pViewport->Start( gameuifuncs, gameeventmanager );
  211. }
  212. CEG_NOINLINE void ClientModePortalNormal::LevelInit( const char *newmap )
  213. {
  214. CEG_PROTECT_VIRTUAL_FUNCTION( ClientModePortalNormal_LevelInit );
  215. // Load color correction lookup for the death effect
  216. /*
  217. m_CCDeathHandle = g_pColorCorrectionMgr->AddColorCorrection( DEATH_CC_LOOKUP_FILENAME );
  218. if ( m_CCDeathHandle != INVALID_CLIENT_CCHANDLE )
  219. {
  220. g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCDeathHandle, 0.0f );
  221. }
  222. m_flDeathCCWeight = 0.0f;
  223. */
  224. m_hCurrentColorCorrection = NULL;
  225. m_BlurFadeScale = 0;
  226. return BaseClass::LevelInit( newmap );
  227. }
  228. void ClientModePortalNormal::LevelShutdown( void )
  229. {
  230. // g_pColorCorrectionMgr->RemoveColorCorrection( m_CCDeathHandle );
  231. // m_CCDeathHandle = INVALID_CLIENT_CCHANDLE;
  232. return BaseClass::LevelShutdown();
  233. }
  234. void ClientModePortalNormal::OnColorCorrectionWeightsReset( void )
  235. {
  236. BaseClass::OnColorCorrectionWeightsReset();
  237. C_Portal_Player *pPlayer = C_Portal_Player::GetLocalPortalPlayer();
  238. /*
  239. // if the player is dead, fade in the death color correction
  240. if ( m_CCDeathHandle != INVALID_CLIENT_CCHANDLE && ( pPlayer != NULL ) )
  241. {
  242. if ( pPlayer->m_lifeState != LIFE_ALIVE )
  243. {
  244. if ( m_flDeathCCWeight < 1.0f )
  245. {
  246. m_flDeathCCWeight += DEATH_CC_FADE_SPEED;
  247. clamp( m_flDeathCCWeight, 0.0f, 1.0f );
  248. }
  249. // Player is dead, fade out the environmental color correction
  250. if ( m_hCurrentColorCorrection )
  251. {
  252. m_hCurrentColorCorrection->EnableOnClient( false );
  253. m_hCurrentColorCorrection = NULL;
  254. }
  255. }
  256. else
  257. {
  258. m_flDeathCCWeight = 0.0f;
  259. }
  260. g_pColorCorrectionMgr->SetColorCorrectionWeight( m_CCDeathHandle, m_flDeathCCWeight );
  261. }
  262. // Only blend between environmental color corrections if there is no death-induced color correction
  263. if ( m_flDeathCCWeight == 0.0f )
  264. */
  265. {
  266. C_ColorCorrection *pNewColorCorrection = pPlayer ? pPlayer->GetActiveColorCorrection() : NULL;
  267. C_ColorCorrection *pOldColorCorrection = m_hCurrentColorCorrection;
  268. if ( pNewColorCorrection != pOldColorCorrection )
  269. {
  270. if ( pOldColorCorrection )
  271. {
  272. pOldColorCorrection->EnableOnClient( false );
  273. }
  274. if ( pNewColorCorrection )
  275. {
  276. pNewColorCorrection->EnableOnClient( true, pOldColorCorrection == NULL );
  277. }
  278. m_hCurrentColorCorrection = pNewColorCorrection;
  279. }
  280. }
  281. }
  282. //-----------------------------------------------------------------------------
  283. // Purpose:
  284. //-----------------------------------------------------------------------------
  285. bool ClientModePortalNormal::ShouldDrawCrosshair( void )
  286. {
  287. // If we're using the radial menu, don't show the crosshair
  288. // if ( IsRadialMenuOpen() )
  289. // return false;
  290. // See if a player is holding
  291. C_Portal_Player *pPlayer = C_Portal_Player::GetLocalPortalPlayer();
  292. if ( pPlayer && pPlayer->IsHoldingSomething() )
  293. return false;
  294. return BaseClass::ShouldDrawCrosshair();
  295. }
  296. void ClientModePortalNormal::SetBlurFade( float scale )
  297. {
  298. m_BlurFadeScale = scale;
  299. }
  300. //--------------------------------------------------------------------------------------------------------
  301. void ClientModePortalNormal::StartTransitionFade( float flFadeTime )
  302. {
  303. STEAMWORKS_SELFCHECK();
  304. // Screen fade to black
  305. ScreenFade_t sf;
  306. memset( &sf, 0, sizeof( sf ) );
  307. sf.a = 255;
  308. sf.r = 0;
  309. sf.g = 0;
  310. sf.b = 0;
  311. sf.duration = (float)(1<<SCREENFADE_FRACBITS) * flFadeTime;
  312. sf.holdTime = 0.f;
  313. sf.fadeFlags = FFADE_OUT|FFADE_STAYOUT;
  314. GetViewEffects()->Fade( sf );
  315. // Sound fade to zero
  316. engine->ClientCmd( CFmtStr( "soundfade 100 5 %f %f\n", flFadeTime, flFadeTime ) );
  317. }
  318. extern ConVar building_cubemaps;
  319. void ClientModePortalNormal::DoPostScreenSpaceEffects( const CViewSetup *pSetup )
  320. {
  321. if ( building_cubemaps.GetBool() )
  322. return;
  323. MDLCACHE_CRITICAL_SECTION();
  324. g_GlowObjectManager.RenderGlowEffects( pSetup, GetSplitScreenPlayerSlot() );
  325. if ( m_BlurFadeScale )
  326. {
  327. CMatRenderContextPtr pRenderContext( materials );
  328. int xl, yl, dest_width, dest_height;
  329. pRenderContext->GetViewport( xl, yl, dest_width, dest_height );
  330. DoBlurFade( m_BlurFadeScale, 1.0f, xl, yl, dest_width, dest_height );
  331. }
  332. }
  333. void ClientModePortalNormal::InitRadialMenuHudElement( void )
  334. {
  335. m_pRadialMenu = GET_HUDELEMENT( CRadialMenu );
  336. Assert( m_pRadialMenu );
  337. }
  338. int ClientModePortalNormal::HudElementKeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBinding )
  339. {
  340. /*if ( GetFullscreenClientMode() && GetFullscreenClientMode() != this &&
  341. !GetFullscreenClientMode()->HudElementKeyInput( down, keynum, pszCurrentBinding ) )
  342. return 0;*/
  343. if ( m_pRadialMenu )
  344. {
  345. if ( !m_pRadialMenu->KeyInput( down, keynum, pszCurrentBinding ) )
  346. {
  347. return 0;
  348. }
  349. }
  350. return 1;
  351. }
  352. // Override the viewmodelfov for splitscreen support. This variable is set via the splitscreen_config.txt file.
  353. // FIXME: Use this method for all games? Are there other features that we need to support to use this?
  354. float ClientModePortalNormal::GetViewModelFOV( void )
  355. {
  356. return cl_viewmodelfov.GetFloat();
  357. }
  358. ClientModePortalNormal g_ClientModeNormal[ MAX_SPLITSCREEN_PLAYERS ];
  359. IClientMode *GetClientModeNormal()
  360. {
  361. ASSERT_LOCAL_PLAYER_RESOLVABLE();
  362. return &g_ClientModeNormal[ GET_ACTIVE_SPLITSCREEN_SLOT() ];
  363. }
  364. //--------------------------------------------------------------------------------------------------------
  365. class FullscreenPortalViewport : public CHudViewport
  366. {
  367. private:
  368. DECLARE_CLASS_SIMPLE( FullscreenPortalViewport, CHudViewport );
  369. private:
  370. virtual void InitViewportSingletons( void )
  371. {
  372. SetAsFullscreenViewportInterface();
  373. }
  374. };
  375. class ClientModePortalNormalFullscreen : public ClientModePortalNormal
  376. {
  377. DECLARE_CLASS_SIMPLE( ClientModePortalNormalFullscreen, ClientModePortalNormal );
  378. public:
  379. virtual void InitViewport()
  380. {
  381. // Skip over BaseClass!!!
  382. BaseClass::ClientModeShared::InitViewport();
  383. m_pViewport = new FullscreenPortalViewport();
  384. m_pViewport->Start( gameuifuncs, gameeventmanager );
  385. }
  386. };
  387. //--------------------------------------------------------------------------------------------------------
  388. static ClientModePortalNormalFullscreen g_FullscreenClientMode;
  389. IClientMode *GetFullscreenClientMode( void )
  390. {
  391. return &g_FullscreenClientMode;
  392. }
  393. ClientModePortalNormal* GetClientModePortalNormal()
  394. {
  395. Assert( dynamic_cast< ClientModePortalNormal* >( GetClientModeNormal() ) );
  396. return static_cast< ClientModePortalNormal* >( GetClientModeNormal() );
  397. }
  398. static CHLModeManager g_HLModeManager;
  399. IVModeManager *modemanager = &g_HLModeManager;