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.

201 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "cstriketeammenu.h"
  9. #include "backgroundpanel.h"
  10. #include <convar.h>
  11. #include "hud.h" // for gEngfuncs
  12. #include "c_cs_player.h"
  13. #include "cs_gamerules.h"
  14. using namespace vgui;
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Constructor
  17. //-----------------------------------------------------------------------------
  18. CCSTeamMenu::CCSTeamMenu(IViewPort *pViewPort) : CTeamMenu(pViewPort)
  19. {
  20. CreateBackground( this );
  21. m_backgroundLayoutFinished = false;
  22. }
  23. //-----------------------------------------------------------------------------
  24. // Purpose: Destructor
  25. //-----------------------------------------------------------------------------
  26. CCSTeamMenu::~CCSTeamMenu()
  27. {
  28. }
  29. void CCSTeamMenu::ShowPanel(bool bShow)
  30. {
  31. if ( bShow )
  32. {
  33. engine->CheckPoint( "TeamMenu" );
  34. }
  35. BaseClass::ShowPanel( bShow );
  36. }
  37. //-----------------------------------------------------------------------------
  38. // Purpose: called to update the menu with new information
  39. //-----------------------------------------------------------------------------
  40. void CCSTeamMenu::Update( void )
  41. {
  42. BaseClass::Update();
  43. const ConVar *allowspecs = cvar->FindVar( "mp_allowspectators" );
  44. C_CSPlayer *pPlayer = C_CSPlayer::GetLocalCSPlayer();
  45. if ( !pPlayer || !CSGameRules() )
  46. return;
  47. if ( allowspecs && allowspecs->GetBool() )
  48. {
  49. // if we're not already a CT or T...or the freeze time isn't over yet...or we're dead
  50. if ( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED ||
  51. CSGameRules()->IsFreezePeriod() ||
  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. m_bVIPMap = false;
  66. char mapName[MAX_MAP_NAME];
  67. Q_FileBase( engine->GetLevelName(), mapName, sizeof(mapName) );
  68. if ( !Q_strncmp( mapName, "maps/as_", 8 ) )
  69. {
  70. m_bVIPMap = true;
  71. }
  72. // if this isn't a VIP map or we're a spectator/terrorist, then disable the VIP button
  73. if ( !CSGameRules()->IsVIPMap() || ( pPlayer->GetTeamNumber() != TEAM_CT ) )
  74. {
  75. SetVisibleButton("vipbutton", false);
  76. }
  77. else // this must be a VIP map and we must already be a CT
  78. {
  79. SetVisibleButton("vipbutton", true);
  80. }
  81. if( pPlayer->GetTeamNumber() == TEAM_UNASSIGNED ) // we aren't on a team yet
  82. {
  83. SetVisibleButton("CancelButton", false);
  84. }
  85. else
  86. {
  87. SetVisibleButton("CancelButton", true);
  88. }
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. //-----------------------------------------------------------------------------
  93. void CCSTeamMenu::SetVisible(bool state)
  94. {
  95. BaseClass::SetVisible(state);
  96. if ( state )
  97. {
  98. Button *pAutoButton = dynamic_cast< Button* >( FindChildByName( "autobutton" ) );
  99. if ( pAutoButton )
  100. {
  101. pAutoButton->RequestFocus();
  102. pAutoButton->SetArmed( true );
  103. }
  104. }
  105. }
  106. //-----------------------------------------------------------------------------
  107. // Purpose: When a team button is pressed it triggers this function to
  108. // cause the player to join a team
  109. //-----------------------------------------------------------------------------
  110. void CCSTeamMenu::OnCommand( const char *command )
  111. {
  112. if ( Q_stricmp( command, "vguicancel" ) )
  113. {
  114. engine->ClientCmd( command );
  115. }
  116. BaseClass::OnCommand(command);
  117. gViewPortInterface->ShowBackGround( false );
  118. OnClose();
  119. }
  120. void CCSTeamMenu::OnKeyCodePressed( vgui::KeyCode code )
  121. {
  122. if ( code == KEY_ENTER )
  123. {
  124. Button *pAutoButton = dynamic_cast< Button* >( FindChildByName( "autobutton" ) );
  125. if ( pAutoButton )
  126. {
  127. pAutoButton->DoClick();
  128. }
  129. }
  130. else
  131. {
  132. BaseClass::OnKeyCodePressed( code );
  133. }
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Purpose: Sets the visibility of a button by name
  137. //-----------------------------------------------------------------------------
  138. void CCSTeamMenu::SetVisibleButton(const char *textEntryName, bool state)
  139. {
  140. Button *entry = dynamic_cast<Button *>(FindChildByName(textEntryName));
  141. if (entry)
  142. {
  143. entry->SetVisible(state);
  144. }
  145. }
  146. //-----------------------------------------------------------------------------
  147. // Purpose: The CS background is painted by image panels, so we should do nothing
  148. //-----------------------------------------------------------------------------
  149. void CCSTeamMenu::PaintBackground()
  150. {
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Purpose: Scale / center the window
  154. //-----------------------------------------------------------------------------
  155. void CCSTeamMenu::PerformLayout()
  156. {
  157. BaseClass::PerformLayout();
  158. // stretch the window to fullscreen
  159. if ( !m_backgroundLayoutFinished )
  160. LayoutBackgroundPanel( this );
  161. m_backgroundLayoutFinished = true;
  162. }
  163. //-----------------------------------------------------------------------------
  164. // Purpose:
  165. //-----------------------------------------------------------------------------
  166. void CCSTeamMenu::ApplySchemeSettings( vgui::IScheme *pScheme )
  167. {
  168. BaseClass::ApplySchemeSettings( pScheme );
  169. ApplyBackgroundSchemeSettings( this, pScheme );
  170. }