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.

161 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "dodtextwindow.h"
  9. #include <cdll_client_int.h>
  10. #include <vgui/IScheme.h>
  11. #include <vgui/ILocalize.h>
  12. #include <vgui/ISurface.h>
  13. #include <filesystem.h>
  14. #include <KeyValues.h>
  15. #include <convar.h>
  16. #include <vgui_controls/ImageList.h>
  17. #include <vgui_controls/TextEntry.h>
  18. #include <vgui_controls/Button.h>
  19. #include <vgui_controls/BuildGroup.h>
  20. #include "dodbutton.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. CDODTextWindow::CDODTextWindow(IViewPort *pViewPort) : CTextWindow( pViewPort )
  32. {
  33. SetProportional( true );
  34. m_iScoreBoardKey = BUTTON_CODE_INVALID;
  35. m_pBackground = SETUP_PANEL( new CDODMenuBackground( this ) );
  36. // Do this again ( base class already does it )
  37. // If we don't, custom controls that we catch in our CreateControlByName
  38. // will not go to the CDODTextWindow version as we haven't instantiated
  39. // ourselves as a CDODTextWindow yet.
  40. LoadControlSettings("Resource/UI/TextWindow.res");
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose: Destructor
  44. //-----------------------------------------------------------------------------
  45. CDODTextWindow::~CDODTextWindow()
  46. {
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose:
  50. //-----------------------------------------------------------------------------
  51. void CDODTextWindow::Update()
  52. {
  53. BaseClass::Update();
  54. Panel *ok = FindChildByName("okbutton");
  55. if (ok)
  56. {
  57. ok->RequestFocus();
  58. }
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. //-----------------------------------------------------------------------------
  63. void CDODTextWindow::SetVisible(bool state)
  64. {
  65. BaseClass::SetVisible(state);
  66. if ( state )
  67. {
  68. Panel *ok = FindChildByName("okbutton");
  69. if (ok)
  70. {
  71. ok->RequestFocus();
  72. }
  73. }
  74. }
  75. //-----------------------------------------------------------------------------
  76. // Purpose: shows the text window
  77. //-----------------------------------------------------------------------------
  78. void CDODTextWindow::ShowPanel(bool bShow)
  79. {
  80. if ( bShow )
  81. {
  82. // get key binding if shown
  83. if ( m_iScoreBoardKey == BUTTON_CODE_INVALID ) // you need to lookup the jump key AFTER the engine has loaded
  84. {
  85. m_iScoreBoardKey = gameuifuncs->GetButtonCodeForBind( "showscores" );
  86. }
  87. }
  88. BaseClass::ShowPanel( bShow );
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. //-----------------------------------------------------------------------------
  93. void CDODTextWindow::OnKeyCodePressed(KeyCode code)
  94. {
  95. if ( m_iScoreBoardKey != BUTTON_CODE_INVALID && m_iScoreBoardKey == code )
  96. {
  97. gViewPortInterface->ShowPanel( PANEL_SCOREBOARD, true );
  98. gViewPortInterface->PostMessageToPanel( PANEL_SCOREBOARD, new KeyValues( "PollHideCode", "code", code ) );
  99. }
  100. else
  101. {
  102. BaseClass::OnKeyCodePressed( code );
  103. }
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose: The background is painted elsewhere, so we should do nothing
  107. //-----------------------------------------------------------------------------
  108. void CDODTextWindow::PaintBackground()
  109. {
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose: Scale / center the window
  113. //-----------------------------------------------------------------------------
  114. void CDODTextWindow::PerformLayout()
  115. {
  116. BaseClass::PerformLayout();
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose:
  120. //-----------------------------------------------------------------------------
  121. void CDODTextWindow::ApplySchemeSettings( vgui::IScheme *pScheme )
  122. {
  123. BaseClass::ApplySchemeSettings( pScheme );
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose:
  127. //-----------------------------------------------------------------------------
  128. Panel *CDODTextWindow::CreateControlByName( const char *controlName )
  129. {
  130. if( !Q_stricmp( "DODButton", controlName ) )
  131. {
  132. return new CDODButton(this);
  133. }
  134. else
  135. {
  136. return BaseClass::CreateControlByName( controlName );
  137. }
  138. }