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.

148 lines
4.4 KiB

  1. //========= Copyright � 1996-2005, 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. m_pConsole = vgui::SETUP_PANEL( new CGameConsoleDialog() ); // we add text before displaying this so set it up now!
  48. // set the console to taking up most of the right-half of the screen
  49. int swide, stall;
  50. vgui::surface()->GetScreenSize(swide, stall);
  51. int offset = vgui::scheme()->GetProportionalScaledValue(16);
  52. m_pConsole->SetBounds(
  53. swide / 2 - (offset * 4),
  54. offset,
  55. (swide / 2) + (offset * 3),
  56. stall - (offset * 8));
  57. m_bInitialized = true;
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Purpose: activates the console, makes it visible and brings it to the foreground
  61. //-----------------------------------------------------------------------------
  62. void CGameConsole::Activate()
  63. {
  64. if (!m_bInitialized)
  65. return;
  66. vgui::surface()->RestrictPaintToSinglePanel(NULL);
  67. m_pConsole->Activate();
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Purpose: hides the console
  71. //-----------------------------------------------------------------------------
  72. void CGameConsole::Hide()
  73. {
  74. if (!m_bInitialized)
  75. return;
  76. m_pConsole->Hide();
  77. }
  78. //-----------------------------------------------------------------------------
  79. // Purpose: clears the console
  80. //-----------------------------------------------------------------------------
  81. void CGameConsole::Clear()
  82. {
  83. if (!m_bInitialized)
  84. return;
  85. m_pConsole->Clear();
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose: returns true if the console is currently in focus
  89. //-----------------------------------------------------------------------------
  90. bool CGameConsole::IsConsoleVisible()
  91. {
  92. if (!m_bInitialized)
  93. return false;
  94. return m_pConsole->IsVisible();
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose: activates the console after a delay
  98. //-----------------------------------------------------------------------------
  99. void CGameConsole::ActivateDelayed(float time)
  100. {
  101. if (!m_bInitialized)
  102. return;
  103. m_pConsole->PostMessage(m_pConsole, new KeyValues("Activate"), time);
  104. }
  105. void CGameConsole::SetParent( int parent )
  106. {
  107. if (!m_bInitialized)
  108. return;
  109. m_pConsole->SetParent( static_cast<vgui::VPANEL>( parent ));
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Purpose: static command handler
  113. //-----------------------------------------------------------------------------
  114. void CGameConsole::OnCmdCondump()
  115. {
  116. g_GameConsole.m_pConsole->DumpConsoleTextToFile();
  117. }
  118. CON_COMMAND( condump, "dump the text currently in the console to condumpXX.log" )
  119. {
  120. g_GameConsole.OnCmdCondump();
  121. }