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.

170 lines
4.7 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 "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_pConsole->InvalidateLayout( false, true );
  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: skips animation and forces the immediate hiding of the panel
  80. //-----------------------------------------------------------------------------
  81. void CGameConsole::HideImmediately ( void )
  82. {
  83. if ( !m_bInitialized )
  84. return;
  85. m_pConsole->SetVisible( false );
  86. }
  87. //-----------------------------------------------------------------------------
  88. // Purpose: clears the console
  89. //-----------------------------------------------------------------------------
  90. void CGameConsole::Clear()
  91. {
  92. if (!m_bInitialized)
  93. return;
  94. m_pConsole->Clear();
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose: returns true if the console is currently in focus
  98. //-----------------------------------------------------------------------------
  99. bool CGameConsole::IsConsoleVisible()
  100. {
  101. if (!m_bInitialized)
  102. return false;
  103. return m_pConsole->IsVisible();
  104. }
  105. //-----------------------------------------------------------------------------
  106. // Purpose: activates the console after a delay
  107. //-----------------------------------------------------------------------------
  108. void CGameConsole::ActivateDelayed(float time)
  109. {
  110. if (!m_bInitialized)
  111. return;
  112. m_pConsole->PostMessage(m_pConsole, new KeyValues("Activate"), time);
  113. }
  114. void CGameConsole::SetParent( int parent )
  115. {
  116. if (!m_bInitialized)
  117. return;
  118. m_pConsole->SetParent( static_cast<vgui::VPANEL>( parent ));
  119. }
  120. void CGameConsole::Shutdown( void )
  121. {
  122. if ( m_pConsole && m_bInitialized)
  123. {
  124. HideImmediately();
  125. m_pConsole->MarkForDeletion();
  126. }
  127. }
  128. //-----------------------------------------------------------------------------
  129. // Purpose: static command handler
  130. //-----------------------------------------------------------------------------
  131. void CGameConsole::OnCmdCondump()
  132. {
  133. g_GameConsole.m_pConsole->DumpConsoleTextToFile();
  134. }
  135. CON_COMMAND( condump, "dump the text currently in the console to condumpXX.log" )
  136. {
  137. g_GameConsole.OnCmdCondump();
  138. }