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.

182 lines
4.7 KiB

  1. //===== Copyright � 1996-2005, 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. private:
  44. enum
  45. {
  46. MAX_HISTORY_ITEMS = 100,
  47. };
  48. enum eCompletionType
  49. {
  50. COMPLETE_TYPE_FORWARD,
  51. COMPLETE_TYPE_REVERSE,
  52. COMPLETE_TYPE_COMMON_STRING,
  53. };
  54. class CompletionItem
  55. {
  56. public:
  57. CompletionItem( void );
  58. CompletionItem( const CompletionItem& src );
  59. CompletionItem& operator =( const CompletionItem& src );
  60. ~CompletionItem( void );
  61. const char *GetItemText( void );
  62. const char *GetCommand( void ) const;
  63. const char *GetName() const;
  64. bool m_bIsCommand;
  65. ConCommandBase *m_pCommand;
  66. CHistoryItem *m_pText;
  67. };
  68. public:
  69. CConsolePanel( Panel *pParent, const char *pName, bool bStatusVersion );
  70. ~CConsolePanel();
  71. // Inherited from IConsoleDisplayFunc
  72. virtual void ColorPrint( const Color& clr, const char *pMessage );
  73. virtual void Print( const char *pMessage );
  74. virtual void DPrint( const char *pMessage );
  75. virtual void GetConsoleText( char *pchText, size_t bufSize ) const;
  76. // clears the console
  77. void Clear();
  78. // writes console to a file
  79. void DumpConsoleTextToFile();
  80. // Hides the console
  81. void Hide();
  82. bool TextEntryHasFocus() const;
  83. void TextEntryRequestFocus();
  84. static int __cdecl CompletionItemCompare( CompletionItem * const *i1, CompletionItem * const *i2 )
  85. {
  86. return strcmp( (*i1)->GetName(), (*i2)->GetName() );
  87. }
  88. protected:
  89. // methods
  90. void OnAutoComplete(eCompletionType completionType);
  91. MESSAGE_FUNC_PTR( OnTextChanged, "TextChanged", panel );
  92. void RebuildCompletionList(const char *partialText);
  93. void UpdateCompletionListPosition();
  94. bool GetCompletionItemText(char *pDest, int completionIndex, int maxLen);
  95. MESSAGE_FUNC( CloseCompletionList, "CloseCompletionList" );
  96. MESSAGE_FUNC_CHARPTR( OnMenuItemSelected, "CompletionCommand", command );
  97. void ClearCompletionList();
  98. void AddToHistory( const char *commandText, const char *extraText );
  99. void UpdateEntryStyle();
  100. bool CommandMatchesText(const char *command, const char *text, bool bCheckSubstrings);
  101. // vgui overrides
  102. virtual void PerformLayout();
  103. virtual void ApplySchemeSettings(vgui::IScheme *pScheme);
  104. virtual void OnCommand(const char *command);
  105. virtual void OnKeyCodeTyped(vgui::KeyCode code);
  106. virtual void OnThink();
  107. vgui::RichText *m_pHistory;
  108. vgui::TextEntry *m_pEntry;
  109. vgui::Button *m_pSubmit;
  110. vgui::Menu *m_pCompletionList;
  111. Color m_PrintColor;
  112. Color m_DPrintColor;
  113. int m_iNextCompletion; // the completion that we'll next go to
  114. char m_szPartialText[256];
  115. char m_szPreviousPartialText[256];
  116. bool m_bAutoCompleteMode; // true if the user is currently tabbing through completion options
  117. bool m_bWasBackspacing;
  118. bool m_bStatusVersion;
  119. CUtlVector< CompletionItem * > m_CompletionList;
  120. CUtlVector< CHistoryItem > m_CommandHistory;
  121. friend class CConsoleDialog;
  122. };
  123. class CConsoleDialog : public vgui::Frame
  124. {
  125. DECLARE_CLASS_SIMPLE( CConsoleDialog, vgui::Frame );
  126. public:
  127. CConsoleDialog( vgui::Panel *pParent, const char *pName, bool bStatusVersion );
  128. virtual void OnScreenSizeChanged( int iOldWide, int iOldTall );
  129. virtual void Close();
  130. virtual void PerformLayout();
  131. // brings dialog to the fore
  132. MESSAGE_FUNC( Activate, "Activate" );
  133. MESSAGE_FUNC_CHARPTR( OnCommandSubmitted, "CommandSubmitted", command );
  134. // hides the console
  135. void Hide();
  136. // Chain to the page
  137. void Print( const char *msg );
  138. void DPrint( const char *msg );
  139. void ColorPrint( const Color& clr, const char *msg );
  140. void Clear();
  141. void DumpConsoleTextToFile();
  142. protected:
  143. CConsolePanel *m_pConsolePanel;
  144. };
  145. } // end namespace vgui
  146. #endif // CONSOLEDIALOG_H