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.

98 lines
3.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: HUD Target ID element
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tf_hud_minigame.h"
  9. #include "iclientmode.h"
  10. #include "tf_gamerules.h"
  11. #include <filesystem.h>
  12. #include <vgui/IVGui.h>
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. DECLARE_HUDELEMENT( CHudMiniGame );
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. //-----------------------------------------------------------------------------
  19. CHudMiniGame::CHudMiniGame( const char *pElementName ) :
  20. CHudElement( pElementName ), BaseClass( NULL, "HudMiniGame" )
  21. {
  22. vgui::Panel *pParent = g_pClientMode->GetViewport();
  23. SetParent( pParent );
  24. m_pActiveMinigame = NULL;
  25. V_strcpy_safe( m_szResFilename, "resource/UI/HudMiniGame_Base.res" );
  26. SetHiddenBits( 0 );
  27. vgui::ivgui()->AddTickSignal( GetVPanel(), 100 );
  28. }
  29. //-----------------------------------------------------------------------------
  30. // Purpose:
  31. //-----------------------------------------------------------------------------
  32. void CHudMiniGame::ApplySchemeSettings( vgui::IScheme *scheme )
  33. {
  34. // load control settings...
  35. LoadControlSettings( m_szResFilename );
  36. BaseClass::ApplySchemeSettings( scheme );
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose:
  40. //-----------------------------------------------------------------------------
  41. bool CHudMiniGame::ShouldDraw( void )
  42. {
  43. if ( !CHudElement::ShouldDraw() )
  44. return false;
  45. if ( !CTFMinigameLogic::GetMinigameLogic() || !CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame() )
  46. return false;
  47. if ( TFGameRules() && ( TFGameRules()->State_Get() != GR_STATE_RND_RUNNING ) )
  48. return false;
  49. return true;
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. //-----------------------------------------------------------------------------
  54. void CHudMiniGame::OnTick()
  55. {
  56. if ( CTFMinigameLogic::GetMinigameLogic() )
  57. {
  58. const char *pszResFilename = NULL;
  59. CTFMiniGame *pActiveMinigame = CTFMinigameLogic::GetMinigameLogic()->GetActiveMinigame();
  60. if ( pActiveMinigame )
  61. {
  62. pszResFilename = pActiveMinigame->GetResFile();
  63. }
  64. if ( pActiveMinigame != m_pActiveMinigame )
  65. {
  66. m_pActiveMinigame = pActiveMinigame;
  67. }
  68. if ( pszResFilename && pszResFilename[0] && m_szResFilename && m_szResFilename[0] )
  69. {
  70. if ( !FStrEq( pszResFilename, m_szResFilename + sizeof( "resource/UI/" ) - 1 ) )
  71. {
  72. V_sprintf_safe( m_szResFilename, "resource/UI/%s", pszResFilename );
  73. InvalidateLayout( false, true );
  74. }
  75. }
  76. if ( m_pActiveMinigame )
  77. {
  78. SetDialogVariable( "redscore", m_pActiveMinigame->GetScoreForTeam( TF_TEAM_RED ) );
  79. SetDialogVariable( "bluescore", m_pActiveMinigame->GetScoreForTeam( TF_TEAM_BLUE ) );
  80. SetDialogVariable( "rounds", m_pActiveMinigame->GetMaxScore() );
  81. }
  82. }
  83. }