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.

336 lines
10 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "hudelement.h"
  8. #include "iclientmode.h"
  9. #include <KeyValues.h>
  10. #include <vgui/IScheme.h>
  11. #include <vgui/ISurface.h>
  12. #include <vgui/ISystem.h>
  13. #include <vgui_controls/AnimationController.h>
  14. #include <vgui_controls/EditablePanel.h>
  15. #include <vgui_controls/ImagePanel.h>
  16. #include <vgui/ISurface.h>
  17. #include <vgui/IImage.h>
  18. #include <vgui_controls/Label.h>
  19. #include "c_playerresource.h"
  20. #include "teamplay_round_timer.h"
  21. #include "utlvector.h"
  22. #include "entity_capture_flag.h"
  23. #include "c_tf_player.h"
  24. #include "c_team.h"
  25. #include "c_tf_team.h"
  26. #include "c_team_objectiveresource.h"
  27. #include "tf_hud_flagstatus.h"
  28. #include "tf_hud_objectivestatus.h"
  29. #include "tf_spectatorgui.h"
  30. #include "teamplayroundbased_gamerules.h"
  31. #include "tf_gamerules.h"
  32. #include "tf_hud_arena_player_count.h"
  33. #include "c_tf_playerresource.h"
  34. #include "tf_hud_robot_destruction_status.h"
  35. #include "tf_hud_passtime.h"
  36. #include "c_tf_passtime_logic.h"
  37. void AddSubKeyNamed( KeyValues *pKeys, const char *pszName );
  38. ConVar tf_hud_show_servertimelimit( "tf_hud_show_servertimelimit", "0", FCVAR_ARCHIVE, "Display time left before the current map ends." );
  39. extern ConVar tf_arena_round_time;
  40. using namespace vgui;
  41. DECLARE_HUDELEMENT( CTFHudObjectiveStatus );
  42. //-----------------------------------------------------------------------------
  43. // Purpose:
  44. //-----------------------------------------------------------------------------
  45. CTFHudObjectiveStatus::CTFHudObjectiveStatus( const char *pElementName )
  46. : CHudElement( pElementName )
  47. , BaseClass( NULL, "HudObjectiveStatus" )
  48. , m_pFlagPanel( NULL )
  49. , m_pControlPointIconsPanel( NULL )
  50. , m_pControlPointProgressBar( NULL )
  51. , m_pEscortPanel( NULL )
  52. , m_pMultipleEscortPanel( NULL )
  53. , m_pTrainingPanel( NULL )
  54. , m_pRobotDestructionPanel( NULL )
  55. {
  56. Panel *pParent = g_pClientMode->GetViewport();
  57. SetParent( pParent );
  58. m_pFlagPanel = new CTFHudFlagObjectives( this, "ObjectiveStatusFlagPanel" );
  59. m_pControlPointIconsPanel = NULL;
  60. m_pControlPointProgressBar = new CControlPointProgressBar( this );
  61. m_pEscortPanel = new CTFHudEscort( this, "ObjectiveStatusEscort" );
  62. m_pMultipleEscortPanel = new CTFHudMultipleEscort( this, "ObjectiveStatusMultipleEscort" );
  63. m_pTrainingPanel = new CTFHudTraining(this, "ObjectiveStatusTraining" );
  64. m_pRobotDestructionPanel = new CTFHUDRobotDestruction( this, "ObjectiveStatusRobotDestruction" );
  65. m_pHudPasstime = new CTFHudPasstime( this );
  66. SetHiddenBits( 0 );
  67. RegisterForRenderGroup( "mid" );
  68. RegisterForRenderGroup( "commentary" );
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose:
  72. //-----------------------------------------------------------------------------
  73. void CTFHudObjectiveStatus::ApplySchemeSettings( IScheme *pScheme )
  74. {
  75. // load control settings...
  76. LoadControlSettings( "resource/UI/HudObjectiveStatus.res" );
  77. if ( !m_pControlPointIconsPanel )
  78. {
  79. m_pControlPointIconsPanel = GET_HUDELEMENT( CHudControlPointIcons );
  80. m_pControlPointIconsPanel->SetParent( this );
  81. }
  82. if ( m_pControlPointProgressBar )
  83. {
  84. m_pControlPointProgressBar->InvalidateLayout( true, true );
  85. }
  86. BaseClass::ApplySchemeSettings( pScheme );
  87. }
  88. //-----------------------------------------------------------------------------
  89. // Purpose:
  90. //-----------------------------------------------------------------------------
  91. void CTFHudObjectiveStatus::Reset()
  92. {
  93. if ( m_pFlagPanel )
  94. {
  95. m_pFlagPanel->Reset();
  96. }
  97. if ( m_pEscortPanel )
  98. {
  99. m_pEscortPanel->Reset();
  100. }
  101. if ( m_pMultipleEscortPanel )
  102. {
  103. m_pMultipleEscortPanel->Reset();
  104. }
  105. if ( m_pControlPointProgressBar )
  106. {
  107. m_pControlPointProgressBar->Reset();
  108. }
  109. if ( m_pRobotDestructionPanel )
  110. {
  111. m_pRobotDestructionPanel->Reset();
  112. }
  113. if ( m_pHudPasstime )
  114. {
  115. m_pHudPasstime->Reset();
  116. }
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose:
  120. //-----------------------------------------------------------------------------
  121. CControlPointProgressBar *CTFHudObjectiveStatus::GetControlPointProgressBar( void )
  122. {
  123. return m_pControlPointProgressBar;
  124. }
  125. //=============================================================================
  126. // HPE_BEGIN
  127. // [msmith] Functions for training stuff.
  128. //=============================================================================
  129. //-----------------------------------------------------------------------------
  130. // Purpose:
  131. //-----------------------------------------------------------------------------
  132. void CTFHudObjectiveStatus::SetTrainingText( char *text )
  133. {
  134. if ( NULL == m_pTrainingPanel )
  135. return;
  136. m_pTrainingPanel->SetTrainingText( text );
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. //-----------------------------------------------------------------------------
  141. void CTFHudObjectiveStatus::SetTrainingObjective( char *text )
  142. {
  143. if ( NULL == m_pTrainingPanel )
  144. return;
  145. m_pTrainingPanel->SetTrainingObjective( text );
  146. }
  147. //=============================================================================
  148. // HPE_END
  149. //=============================================================================
  150. //-----------------------------------------------------------------------------
  151. // Purpose:
  152. //-----------------------------------------------------------------------------
  153. void CTFHudObjectiveStatus::SetVisiblePanels( void )
  154. {
  155. if ( !TFGameRules() )
  156. return;
  157. //=============================================================================
  158. // HPE_BEGIN
  159. // [msmith] Added stuff related to showing different HUDs for training.
  160. //=============================================================================
  161. int iGameType = TFGameRules()->GetGameType();
  162. int iHudType = TFGameRules()->GetHUDType();
  163. bool bIsPlayingRobotDestruction = TFGameRules()->IsPlayingRobotDestructionMode();
  164. if ( m_pRobotDestructionPanel && m_pRobotDestructionPanel->IsVisible() != bIsPlayingRobotDestruction )
  165. {
  166. m_pRobotDestructionPanel->SetVisible( bIsPlayingRobotDestruction );
  167. }
  168. bool bCTFVisible = TFGameRules()->IsPlayingHybrid_CTF_CP();
  169. if ( !bCTFVisible )
  170. {
  171. bCTFVisible = ( iGameType == TF_GAMETYPE_CTF || iHudType == TF_HUDTYPE_CTF ) && ( iHudType != TF_HUDTYPE_CP ) && ( iHudType != TF_HUDTYPE_ESCORT );
  172. }
  173. if ( TFGameRules()->IsMannVsMachineMode() )
  174. {
  175. bCTFVisible = ( ( TFGameRules()->State_Get() != GR_STATE_BETWEEN_RNDS )
  176. && ( TFGameRules()->State_Get() != GR_STATE_TEAM_WIN )
  177. && ( TFGameRules()->State_Get() != GR_STATE_GAME_OVER ) );
  178. }
  179. //First check to see if we have an override HUD for the training simulation.
  180. //If we do, ignore any other game play hud displays.
  181. if ( iHudType == TF_HUDTYPE_TRAINING )
  182. {
  183. m_pTrainingPanel->SetVisible(true);
  184. if ( m_pFlagPanel )
  185. {
  186. m_pFlagPanel->SetVisible( false );
  187. }
  188. if ( m_pControlPointIconsPanel )
  189. {
  190. m_pControlPointIconsPanel->SetVisible( false );
  191. }
  192. if ( m_pEscortPanel )
  193. {
  194. m_pEscortPanel->SetVisible( false );
  195. }
  196. if ( m_pMultipleEscortPanel )
  197. {
  198. m_pMultipleEscortPanel->SetVisible( false );
  199. }
  200. if ( m_pHudPasstime )
  201. {
  202. m_pHudPasstime->SetVisible( false );
  203. m_pHudPasstime->SetEnabled( false );
  204. }
  205. return;
  206. }
  207. m_pTrainingPanel->SetVisible( TFGameRules()->IsTrainingHUDVisible() );
  208. if ( m_pFlagPanel && m_pFlagPanel->IsVisible() != bCTFVisible )
  209. {
  210. m_pFlagPanel->SetVisible( bCTFVisible );
  211. }
  212. bool bCPVisible = TFGameRules()->IsPlayingHybrid_CTF_CP();
  213. if ( !bCPVisible )
  214. {
  215. bCPVisible = ( iGameType == TF_GAMETYPE_CP || iGameType == TF_GAMETYPE_ARENA || iHudType == TF_HUDTYPE_CP || iGameType == TF_GAMETYPE_MVM ) && ( iHudType != TF_HUDTYPE_CTF ) && ( iHudType != TF_HUDTYPE_ESCORT ) && !TFGameRules()->IsPlayingHybrid_CTF_CP();
  216. }
  217. if ( m_pControlPointIconsPanel && m_pControlPointIconsPanel->IsVisible() != bCPVisible )
  218. {
  219. m_pControlPointIconsPanel->SetVisible( bCPVisible );
  220. }
  221. bool bEscortVisible = ( iGameType == TF_GAMETYPE_ESCORT || iHudType == TF_HUDTYPE_ESCORT ) && ( iHudType != TF_HUDTYPE_CTF ) && ( iHudType != TF_HUDTYPE_CP ) && !TFGameRules()->IsPlayingHybrid_CTF_CP();
  222. if ( bEscortVisible )
  223. {
  224. bool bMultipleTrains = TFGameRules()->HasMultipleTrains();
  225. if ( m_pEscortPanel && m_pEscortPanel->EditablePanel::IsVisible() != !bMultipleTrains ) // intentionally skipping EscortPanel version of IsVisible() to bypass the !m_bHaveValidPointPositions check
  226. {
  227. m_pEscortPanel->SetVisible( !bMultipleTrains );
  228. }
  229. // Hide the panel while players are fighting in Helltower's hell
  230. if ( TFGameRules()->IsHalloweenScenario( CTFGameRules::HALLOWEEN_SCENARIO_HIGHTOWER ) && ( TFGameRules()->ArePlayersInHell() == true ) )
  231. {
  232. bMultipleTrains = false;
  233. }
  234. if ( m_pMultipleEscortPanel && m_pMultipleEscortPanel->EditablePanel::IsVisible() != bMultipleTrains ) // intentionally skipping EscortPanel version of IsVisible() to bypass the !m_bHaveValidPointPositions check
  235. {
  236. m_pMultipleEscortPanel->SetVisible( bMultipleTrains );
  237. }
  238. }
  239. else
  240. {
  241. if ( m_pEscortPanel && m_pEscortPanel->EditablePanel::IsVisible() ) // intentionally skipping EscortPanel version of IsVisible() to bypass the !m_bHaveValidPointPositions check
  242. {
  243. m_pEscortPanel->SetVisible( false );
  244. }
  245. if ( m_pMultipleEscortPanel && m_pMultipleEscortPanel->EditablePanel::IsVisible() ) // intentionally skipping EscortPanel version of IsVisible() to bypass the !m_bHaveValidPointPositions check
  246. {
  247. m_pMultipleEscortPanel->SetVisible( false );
  248. }
  249. }
  250. if ( m_pHudPasstime )
  251. {
  252. bool bIsPasstime = iGameType == TF_GAMETYPE_PASSTIME;
  253. m_pHudPasstime->SetVisible( bIsPasstime );
  254. m_pHudPasstime->SetEnabled( bIsPasstime );
  255. }
  256. //=============================================================================
  257. // HPE_END
  258. //=============================================================================
  259. }
  260. //-----------------------------------------------------------------------------
  261. // Purpose:
  262. //-----------------------------------------------------------------------------
  263. void CTFHudObjectiveStatus::Think()
  264. {
  265. if ( !TeamplayRoundBasedRules() || !TFGameRules() )
  266. return;
  267. SetVisiblePanels();
  268. }
  269. //-----------------------------------------------------------------------------
  270. // Purpose:
  271. //-----------------------------------------------------------------------------
  272. bool CTFHudObjectiveStatus::ShouldDraw()
  273. {
  274. C_TFPlayer *pPlayer = C_TFPlayer::GetLocalTFPlayer();
  275. if ( pPlayer && pPlayer->m_Shared.InCond( TF_COND_HALLOWEEN_KART ) )
  276. {
  277. return false;
  278. }
  279. if ( TFGameRules() && TFGameRules()->ShowMatchSummary() )
  280. return false;
  281. return CHudElement::ShouldDraw();
  282. }