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.

171 lines
4.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef CONSOLEDIALOG_H
  8. #define CONSOLEDIALOG_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <Color.h>
  13. #include "tier1/utlvector.h"
  14. #include "vgui_controls/EditablePanel.h"
  15. #include "vgui_controls/Frame.h"
  16. #include "icvar.h"
  17. class ConCommandBase;
  18. namespace vgui
  19. {
  20. // Things the user typed in and hit submit/return with
  21. class CHistoryItem
  22. {
  23. public:
  24. CHistoryItem( void );
  25. CHistoryItem( const char *text, const char *extra = NULL );
  26. CHistoryItem( const CHistoryItem& src );
  27. ~CHistoryItem( void );
  28. const char *GetText() const;
  29. const char *GetExtra() const;
  30. void SetText( const char *text, const char *extra );
  31. bool HasExtra() { return m_bHasExtra; }
  32. private:
  33. char *m_text;
  34. char *m_extraText;
  35. bool m_bHasExtra;
  36. };
  37. //-----------------------------------------------------------------------------
  38. // Purpose: Game/dev console dialog
  39. //-----------------------------------------------------------------------------
  40. class CConsolePanel : public vgui::EditablePanel, public IConsoleDisplayFunc
  41. {
  42. DECLARE_CLASS_SIMPLE( CConsolePanel, vgui::EditablePanel );
  43. public:
  44. CConsolePanel( Panel *pParent, const char *pName, bool bStatusVersion );
  45. ~CConsolePanel();
  46. // Inherited from IConsoleDisplayFunc
  47. virtual void ColorPrint( const Color& clr, const char *pMessage );
  48. virtual void Print( const char *pMessage );
  49. virtual void DPrint( const char *pMessage );
  50. virtual void GetConsoleText( char *pchText, size_t bufSize ) const;
  51. // clears the console
  52. void Clear();
  53. // writes console to a file
  54. void DumpConsoleTextToFile();
  55. // Hides the console
  56. void Hide();
  57. bool TextEntryHasFocus() const;
  58. void TextEntryRequestFocus();
  59. private:
  60. enum
  61. {
  62. MAX_HISTORY_ITEMS = 100,
  63. };
  64. class CompletionItem
  65. {
  66. public:
  67. CompletionItem( void );
  68. CompletionItem( const CompletionItem& src );
  69. CompletionItem& operator =( const CompletionItem& src );
  70. ~CompletionItem( void );
  71. const char *GetItemText( void );
  72. const char *GetCommand( void ) const;
  73. const char *GetName() const;
  74. bool m_bIsCommand;
  75. ConCommandBase *m_pCommand;
  76. CHistoryItem *m_pText;
  77. };
  78. protected:
  79. // methods
  80. void OnAutoComplete(bool reverse);
  81. MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel );
  82. void RebuildCompletionList(const char *partialText);
  83. void UpdateCompletionListPosition();
  84. MESSAGE_FUNC( CloseCompletionList, "CloseCompletionList" );
  85. MESSAGE_FUNC_CHARPTR( OnMenuItemSelected, "CompletionCommand", command );
  86. void ClearCompletionList();
  87. void AddToHistory( const char *commandText, const char *extraText );
  88. // vgui overrides
  89. virtual void PerformLayout();
  90. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  91. virtual void OnCommand(const char *command);
  92. virtual void OnKeyCodeTyped(vgui::KeyCode code);
  93. virtual void OnThink();
  94. vgui::RichText *m_pHistory;
  95. vgui::TextEntry *m_pEntry;
  96. vgui::Button *m_pSubmit;
  97. vgui::Menu *m_pCompletionList;
  98. Color m_PrintColor;
  99. Color m_DPrintColor;
  100. int m_iNextCompletion; // the completion that we'll next go to
  101. char m_szPartialText[256];
  102. char m_szPreviousPartialText[256];
  103. bool m_bAutoCompleteMode; // true if the user is currently tabbing through completion options
  104. bool m_bWasBackspacing;
  105. bool m_bStatusVersion;
  106. CUtlVector< CompletionItem * > m_CompletionList;
  107. CUtlVector< CHistoryItem > m_CommandHistory;
  108. friend class CConsoleDialog;
  109. };
  110. class CConsoleDialog : public vgui::Frame
  111. {
  112. DECLARE_CLASS_SIMPLE( CConsoleDialog, vgui::Frame );
  113. public:
  114. CConsoleDialog( vgui::Panel *pParent, const char *pName, bool bStatusVersion );
  115. virtual void OnScreenSizeChanged( int iOldWide, int iOldTall );
  116. virtual void Close();
  117. virtual void PerformLayout();
  118. // brings dialog to the fore
  119. MESSAGE_FUNC( Activate, "Activate" );
  120. MESSAGE_FUNC_CHARPTR( OnCommandSubmitted, "CommandSubmitted", command );
  121. // hides the console
  122. void Hide();
  123. // Chain to the page
  124. void Print( const char *msg );
  125. void DPrint( const char *msg );
  126. void ColorPrint( const Color& clr, const char *msg );
  127. void Clear();
  128. void DumpConsoleTextToFile();
  129. virtual void OnKeyCodePressed( vgui::KeyCode code );
  130. protected:
  131. CConsolePanel *m_pConsolePanel;
  132. };
  133. } // end namespace vgui
  134. #endif // CONSOLEDIALOG_H