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.

174 lines
4.8 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "hl2mptextwindow.h"
  9. #include "backgroundpanel.h"
  10. #include <cdll_client_int.h>
  11. #include <vgui/IScheme.h>
  12. #include <vgui/ILocalize.h>
  13. #include <vgui/ISurface.h>
  14. #include <filesystem.h>
  15. #include <KeyValues.h>
  16. #include <convar.h>
  17. #include <vgui_controls/ImageList.h>
  18. #include <vgui_controls/TextEntry.h>
  19. #include <vgui_controls/Button.h>
  20. #include <vgui_controls/BuildGroup.h>
  21. #include "IGameUIFuncs.h" // for key bindings
  22. #include <igameresources.h>
  23. extern IGameUIFuncs *gameuifuncs; // for key binding details
  24. #include <game/client/iviewport.h>
  25. // memdbgon must be the last include file in a .cpp file!!!
  26. #include "tier0/memdbgon.h"
  27. using namespace vgui;
  28. //-----------------------------------------------------------------------------
  29. // Purpose: Constructor
  30. //-----------------------------------------------------------------------------
  31. CHL2MPTextWindow::CHL2MPTextWindow(IViewPort *pViewPort) : CTextWindow( pViewPort )
  32. {
  33. SetProportional( true );
  34. m_iScoreBoardKey = BUTTON_CODE_INVALID; // this is looked up in Activate()
  35. CreateBackground( this );
  36. m_backgroundLayoutFinished = false;
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Purpose: Destructor
  40. //-----------------------------------------------------------------------------
  41. CHL2MPTextWindow::~CHL2MPTextWindow()
  42. {
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose:
  46. //-----------------------------------------------------------------------------
  47. void CHL2MPTextWindow::Update()
  48. {
  49. BaseClass::Update();
  50. m_pOK->RequestFocus();
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. void CHL2MPTextWindow::SetVisible(bool state)
  56. {
  57. BaseClass::SetVisible(state);
  58. if ( state )
  59. {
  60. m_pOK->RequestFocus();
  61. }
  62. }
  63. //-----------------------------------------------------------------------------
  64. // Purpose: shows the text window
  65. //-----------------------------------------------------------------------------
  66. void CHL2MPTextWindow::ShowPanel(bool bShow)
  67. {
  68. if ( bShow )
  69. {
  70. // get key binding if shown
  71. if ( m_iScoreBoardKey == BUTTON_CODE_INVALID ) // you need to lookup the jump key AFTER the engine has loaded
  72. {
  73. m_iScoreBoardKey = gameuifuncs->GetButtonCodeForBind( "showscores" );
  74. }
  75. }
  76. BaseClass::ShowPanel( bShow );
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose:
  80. //-----------------------------------------------------------------------------
  81. void CHL2MPTextWindow::OnKeyCodePressed(KeyCode code)
  82. {
  83. if ( m_iScoreBoardKey != BUTTON_CODE_INVALID && m_iScoreBoardKey == code )
  84. {
  85. gViewPortInterface->ShowPanel( PANEL_SCOREBOARD, true );
  86. gViewPortInterface->PostMessageToPanel( PANEL_SCOREBOARD, new KeyValues( "PollHideCode", "code", code ) );
  87. }
  88. else
  89. {
  90. BaseClass::OnKeyCodePressed( code );
  91. }
  92. }
  93. //-----------------------------------------------------------------------------
  94. // Purpose: The CS background is painted by image panels, so we should do nothing
  95. //-----------------------------------------------------------------------------
  96. void CHL2MPTextWindow::PaintBackground()
  97. {
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose: Scale / center the window
  101. //-----------------------------------------------------------------------------
  102. void CHL2MPTextWindow::PerformLayout()
  103. {
  104. BaseClass::PerformLayout();
  105. // stretch the window to fullscreen
  106. if ( !m_backgroundLayoutFinished )
  107. LayoutBackgroundPanel( this );
  108. m_backgroundLayoutFinished = true;
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose:
  112. //-----------------------------------------------------------------------------
  113. void CHL2MPTextWindow::ApplySchemeSettings( vgui::IScheme *pScheme )
  114. {
  115. BaseClass::ApplySchemeSettings( pScheme );
  116. ApplyBackgroundSchemeSettings( this, pScheme );
  117. }
  118. CHL2MPSpectatorGUI::CHL2MPSpectatorGUI(IViewPort *pViewPort) : CSpectatorGUI(pViewPort)
  119. {
  120. }
  121. bool CHL2MPSpectatorGUI::NeedsUpdate( void )
  122. {
  123. if ( !C_BasePlayer::GetLocalPlayer() )
  124. return false;
  125. if ( m_nLastSpecMode != C_BasePlayer::GetLocalPlayer()->GetObserverMode() )
  126. return true;
  127. if ( m_nLastSpecTarget != C_BasePlayer::GetLocalPlayer()->GetObserverTarget() )
  128. return true;
  129. return BaseClass::NeedsUpdate();
  130. }
  131. void CHL2MPSpectatorGUI::Update()
  132. {
  133. BaseClass::Update();
  134. C_BasePlayer *pLocalPlayer = C_BasePlayer::GetLocalPlayer();
  135. if( pLocalPlayer )
  136. {
  137. m_nLastSpecMode = pLocalPlayer->GetObserverMode();
  138. m_nLastSpecTarget = pLocalPlayer->GetObserverTarget();
  139. }
  140. }