Counter Strike : Global Offensive Source Code
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.

147 lines
4.2 KiB

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