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.

146 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "cstriketextwindow.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. CCSTextWindow::CCSTextWindow(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. CCSTextWindow::~CCSTextWindow()
  42. {
  43. }
  44. //-----------------------------------------------------------------------------
  45. // Purpose:
  46. //-----------------------------------------------------------------------------
  47. void CCSTextWindow::Update()
  48. {
  49. BaseClass::Update();
  50. m_pOK->RequestFocus();
  51. }
  52. //-----------------------------------------------------------------------------
  53. // Purpose:
  54. //-----------------------------------------------------------------------------
  55. void CCSTextWindow::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 CCSTextWindow::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 CCSTextWindow::OnKeyCodePressed( KeyCode code )
  82. {
  83. //We manually intercept the ENTER key so in case the button loses focus
  84. //ENTER still moves you through the MOTD screen.
  85. if ( code == KEY_ENTER || code == KEY_XBUTTON_A || code == KEY_XBUTTON_B )
  86. {
  87. m_pOK->DoClick();
  88. }
  89. else if ( m_iScoreBoardKey != BUTTON_CODE_INVALID && m_iScoreBoardKey == code )
  90. {
  91. gViewPortInterface->ShowPanel( PANEL_SCOREBOARD, true );
  92. gViewPortInterface->PostMessageToPanel( PANEL_SCOREBOARD, new KeyValues( "PollHideCode", "code", code ) );
  93. }
  94. else
  95. {
  96. BaseClass::OnKeyCodePressed( code );
  97. }
  98. }
  99. //-----------------------------------------------------------------------------
  100. // Purpose: The CS background is painted by image panels, so we should do nothing
  101. //-----------------------------------------------------------------------------
  102. void CCSTextWindow::PaintBackground()
  103. {
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose: Scale / center the window
  107. //-----------------------------------------------------------------------------
  108. void CCSTextWindow::PerformLayout()
  109. {
  110. BaseClass::PerformLayout();
  111. // stretch the window to fullscreen
  112. if ( !m_backgroundLayoutFinished )
  113. LayoutBackgroundPanel( this );
  114. m_backgroundLayoutFinished = true;
  115. }
  116. //-----------------------------------------------------------------------------
  117. // Purpose:
  118. //-----------------------------------------------------------------------------
  119. void CCSTextWindow::ApplySchemeSettings( vgui::IScheme *pScheme )
  120. {
  121. BaseClass::ApplySchemeSettings( pScheme );
  122. ApplyBackgroundSchemeSettings( this, pScheme );
  123. }