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.

169 lines
4.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include <stdio.h>
  8. #include "GameConsole.h"
  9. #include "GameConsoleDialog.h"
  10. #include "LoadingDialog.h"
  11. #include "vgui/ISurface.h"
  12. #include "KeyValues.h"
  13. #include "vgui/VGUI.h"
  14. #include "vgui/IVGui.h"
  15. #include "vgui_controls/Panel.h"
  16. #include "convar.h"
  17. // memdbgon must be the last include file in a .cpp file!!!
  18. #include "tier0/memdbgon.h"
  19. static CGameConsole g_GameConsole;
  20. //-----------------------------------------------------------------------------
  21. // Purpose: singleton accessor
  22. //-----------------------------------------------------------------------------
  23. CGameConsole &GameConsole()
  24. {
  25. return g_GameConsole;
  26. }
  27. EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CGameConsole, IGameConsole, GAMECONSOLE_INTERFACE_VERSION, g_GameConsole);
  28. //-----------------------------------------------------------------------------
  29. // Purpose: Constructor
  30. //-----------------------------------------------------------------------------
  31. CGameConsole::CGameConsole()
  32. {
  33. m_bInitialized = false;
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose: Destructor
  37. //-----------------------------------------------------------------------------
  38. CGameConsole::~CGameConsole()
  39. {
  40. m_bInitialized = false;
  41. }
  42. //-----------------------------------------------------------------------------
  43. // Purpose: sets up the console for use
  44. //-----------------------------------------------------------------------------
  45. void CGameConsole::Initialize()
  46. {
  47. #ifndef _XBOX
  48. m_pConsole = vgui::SETUP_PANEL( new CGameConsoleDialog() ); // we add text before displaying this so set it up now!
  49. // set the console to taking up most of the right-half of the screen
  50. int swide, stall;
  51. vgui::surface()->GetScreenSize(swide, stall);
  52. int offsetx = vgui::scheme()->GetProportionalScaledValue(16);
  53. int offsety = vgui::scheme()->GetProportionalScaledValue(64);
  54. m_pConsole->SetBounds(
  55. swide / 2 - offsetx,
  56. offsety,
  57. swide / 2,
  58. stall - (offsety * 2));
  59. m_bInitialized = true;
  60. #endif
  61. }
  62. //-----------------------------------------------------------------------------
  63. // Purpose: activates the console, makes it visible and brings it to the foreground
  64. //-----------------------------------------------------------------------------
  65. void CGameConsole::Activate()
  66. {
  67. #ifndef _XBOX
  68. if (!m_bInitialized)
  69. return;
  70. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  71. m_pConsole->Activate();
  72. #endif
  73. }
  74. //-----------------------------------------------------------------------------
  75. // Purpose: hides the console
  76. //-----------------------------------------------------------------------------
  77. void CGameConsole::Hide()
  78. {
  79. #ifndef _XBOX
  80. if (!m_bInitialized)
  81. return;
  82. m_pConsole->Hide();
  83. #endif
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose: clears the console
  87. //-----------------------------------------------------------------------------
  88. void CGameConsole::Clear()
  89. {
  90. #ifndef _XBOX
  91. if (!m_bInitialized)
  92. return;
  93. m_pConsole->Clear();
  94. #endif
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose: returns true if the console is currently in focus
  98. //-----------------------------------------------------------------------------
  99. bool CGameConsole::IsConsoleVisible()
  100. {
  101. #ifndef _XBOX
  102. if (!m_bInitialized)
  103. return false;
  104. return m_pConsole->IsVisible();
  105. #else
  106. return false;
  107. #endif
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose: activates the console after a delay
  111. //-----------------------------------------------------------------------------
  112. void CGameConsole::ActivateDelayed(float time)
  113. {
  114. #ifndef _XBOX
  115. if (!m_bInitialized)
  116. return;
  117. m_pConsole->PostMessage(m_pConsole, new KeyValues("Activate"), time);
  118. #endif
  119. }
  120. void CGameConsole::SetParent( int parent )
  121. {
  122. #ifndef _XBOX
  123. if (!m_bInitialized)
  124. return;
  125. m_pConsole->SetParent( static_cast<vgui::VPANEL>( parent ));
  126. #endif
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose: static command handler
  130. //-----------------------------------------------------------------------------
  131. void CGameConsole::OnCmdCondump()
  132. {
  133. #ifndef _XBOX
  134. g_GameConsole.m_pConsole->DumpConsoleTextToFile();
  135. #endif
  136. }
  137. #ifndef _XBOX
  138. CON_COMMAND( condump, "dump the text currently in the console to condumpXX.log" )
  139. {
  140. g_GameConsole.OnCmdCondump();
  141. }
  142. #endif