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.

118 lines
3.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "tfcteammenu.h"
  9. #include <convar.h>
  10. #include "hud.h" // for gEngfuncs
  11. #include "c_tfc_player.h"
  12. #include "tfc_gamerules.h"
  13. using namespace vgui;
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Constructor
  16. //-----------------------------------------------------------------------------
  17. CTFCTeamMenu::CTFCTeamMenu(IViewPort *pViewPort) : CTeamMenu(pViewPort)
  18. {
  19. }
  20. //-----------------------------------------------------------------------------
  21. // Purpose: Destructor
  22. //-----------------------------------------------------------------------------
  23. CTFCTeamMenu::~CTFCTeamMenu()
  24. {
  25. }
  26. void CTFCTeamMenu::ApplySettings(KeyValues *inResourceData)
  27. {
  28. BaseClass::ApplySettings( inResourceData );
  29. }
  30. void CTFCTeamMenu::ShowPanel(bool bShow)
  31. {
  32. if ( bShow )
  33. {
  34. engine->CheckPoint( "TeamMenu" );
  35. }
  36. BaseClass::ShowPanel( bShow );
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose: called to update the menu with new information
  40. //-----------------------------------------------------------------------------
  41. void CTFCTeamMenu::Update( void )
  42. {
  43. BaseClass::Update();
  44. const ConVar *allowspecs = cvar->FindVar( "mp_allowspectators" );
  45. if ( allowspecs && allowspecs->GetBool() )
  46. {
  47. C_TFCPlayer *pPlayer = C_TFCPlayer::GetLocalTFCPlayer();
  48. if ( !pPlayer || !TFCGameRules() )
  49. return;
  50. // if we're not already a CT or T...or the freeze time isn't over yet...or we're dead
  51. if ( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED ||
  52. ( pPlayer && pPlayer->IsPlayerDead() ) )
  53. {
  54. SetVisibleButton("specbutton", true);
  55. }
  56. else
  57. {
  58. SetVisibleButton("specbutton", false);
  59. }
  60. }
  61. else
  62. {
  63. SetVisibleButton("specbutton", false );
  64. }
  65. char mapName[MAX_MAP_NAME];
  66. Q_FileBase( engine->GetLevelName(), mapName, sizeof(mapName) );
  67. if( C_TFCPlayer::GetLocalTFCPlayer()->GetTeamNumber() == TEAM_UNASSIGNED ) // we aren't on a team yet
  68. {
  69. SetVisibleButton("CancelButton", false);
  70. }
  71. else
  72. {
  73. SetVisibleButton("CancelButton", true);
  74. }
  75. }
  76. //-----------------------------------------------------------------------------
  77. // Purpose: When a team button is pressed it triggers this function to
  78. // cause the player to join a team
  79. //-----------------------------------------------------------------------------
  80. void CTFCTeamMenu::OnCommand( const char *command )
  81. {
  82. if ( Q_stricmp( command, "vguicancel" ) )
  83. {
  84. engine->ClientCmd( command );
  85. }
  86. BaseClass::OnCommand(command);
  87. gViewPortInterface->ShowBackGround( false );
  88. OnClose();
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose: Sets the visibility of a button by name
  92. //-----------------------------------------------------------------------------
  93. void CTFCTeamMenu::SetVisibleButton(const char *textEntryName, bool state)
  94. {
  95. Button *entry = dynamic_cast<Button *>(FindChildByName(textEntryName));
  96. if (entry)
  97. {
  98. entry->SetVisible(state);
  99. }
  100. }