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.

220 lines
5.6 KiB

  1. //--------------------------------------------------------------------------------------------------------
  2. //========= Copyright Valve Corporation, All rights reserved. ============//
  3. #ifndef NAVUI_H
  4. #define NAVUI_H
  5. #ifdef SERVER_USES_VGUI
  6. #include "KeyValues.h"
  7. #include <vgui_controls/ImagePanel.h>
  8. #include <vgui_controls/Button.h>
  9. #include <vgui_controls/Frame.h>
  10. #include <vgui_controls/ComboBox.h>
  11. #include <vgui_controls/TextEntry.h>
  12. #include <vgui_controls/CheckButton.h>
  13. #include <vgui/ILocalize.h>
  14. #include "vgui/ISurface.h"
  15. #include "vgui/IVGui.h"
  16. #include "fmtstr.h"
  17. #include <vgui_controls/CheckButton.h>
  18. //--------------------------------------------------------------------------------------------------------
  19. void GetNavUIEditVectors( Vector *pos, Vector *forward );
  20. //--------------------------------------------------------------------------------------------------------
  21. class CNavUIButton : public vgui::Button
  22. {
  23. DECLARE_CLASS_SIMPLE( CNavUIButton, vgui::Button );
  24. public:
  25. CNavUIButton( Panel *parent, const char *name ) : vgui::Button( parent, name, "" )
  26. {
  27. m_hideKey = BUTTON_CODE_INVALID;
  28. }
  29. virtual void OnKeyCodePressed( vgui::KeyCode code );
  30. virtual void OnKeyCodeReleased( vgui::KeyCode code );
  31. private:
  32. void LookupKey( void );
  33. ButtonCode_t m_hideKey;
  34. IntervalTimer m_hidePressedTimer;
  35. };
  36. //--------------------------------------------------------------------------------------------------------
  37. class CNavUITextEntry : public vgui::TextEntry
  38. {
  39. DECLARE_CLASS_SIMPLE( CNavUIButton, vgui::TextEntry );
  40. public:
  41. CNavUITextEntry( Panel *parent, const char *name ) : vgui::TextEntry( parent, name )
  42. {
  43. m_hideKey = BUTTON_CODE_INVALID;
  44. }
  45. virtual void OnKeyCodePressed( vgui::KeyCode code );
  46. virtual void OnKeyCodeReleased( vgui::KeyCode code );
  47. private:
  48. void LookupKey( void );
  49. ButtonCode_t m_hideKey;
  50. IntervalTimer m_hidePressedTimer;
  51. };
  52. //--------------------------------------------------------------------------------------------------------
  53. class CNavUIComboBox : public vgui::ComboBox
  54. {
  55. DECLARE_CLASS_SIMPLE( CNavUIComboBox, vgui::ComboBox );
  56. public:
  57. CNavUIComboBox( Panel *parent, const char *name, int numLines, bool editable ) : vgui::ComboBox( parent, name, numLines, editable )
  58. {
  59. m_hideKey = BUTTON_CODE_INVALID;
  60. }
  61. virtual void OnKeyCodePressed( vgui::KeyCode code );
  62. virtual void OnKeyCodeReleased( vgui::KeyCode code );
  63. private:
  64. void LookupKey( void );
  65. ButtonCode_t m_hideKey;
  66. IntervalTimer m_hidePressedTimer;
  67. };
  68. //--------------------------------------------------------------------------------------------------------
  69. class CNavUICheckButton : public vgui::CheckButton
  70. {
  71. DECLARE_CLASS_SIMPLE( CNavUICheckButton, vgui::CheckButton );
  72. public:
  73. CNavUICheckButton( Panel *parent, const char *name, const char *text ) : vgui::CheckButton( parent, name, text )
  74. {
  75. m_hideKey = BUTTON_CODE_INVALID;
  76. }
  77. virtual void OnKeyCodePressed( vgui::KeyCode code );
  78. virtual void OnKeyCodeReleased( vgui::KeyCode code );
  79. private:
  80. void LookupKey( void );
  81. ButtonCode_t m_hideKey;
  82. IntervalTimer m_hidePressedTimer;
  83. };
  84. //--------------------------------------------------------------------------------------------------------
  85. class CNavUIToolPanel : public vgui::EditablePanel
  86. {
  87. DECLARE_CLASS_SIMPLE( CNavUIToolPanel, vgui::EditablePanel );
  88. public:
  89. CNavUIToolPanel( vgui::Panel *parent, const char *toolName ) : vgui::EditablePanel( parent, toolName )
  90. {
  91. }
  92. virtual void Init( void )
  93. {
  94. }
  95. virtual void Shutdown( void )
  96. {
  97. }
  98. virtual vgui::Panel *CreateControlByName( const char *controlName );
  99. virtual void StartLeftClickAction( const char *actionName )
  100. {
  101. }
  102. virtual void FinishLeftClickAction( const char *actionName )
  103. {
  104. }
  105. virtual void StartRightClickAction( const char *actionName )
  106. {
  107. }
  108. protected:
  109. bool IsCheckButtonChecked( const char *name );
  110. };
  111. //--------------------------------------------------------------------------------------------------------
  112. class CNavUIBasePanel : public vgui::Frame
  113. {
  114. DECLARE_CLASS_SIMPLE( CNavUIBasePanel, vgui::Frame );
  115. public:
  116. CNavUIBasePanel();
  117. virtual ~CNavUIBasePanel();
  118. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  119. virtual void OnCommand( const char *command );
  120. virtual void PerformLayout( void );
  121. virtual void PaintBackground( void );
  122. // GameUI panels are always visible by default, so here we hide ourselves if the GameUI is up.
  123. virtual void OnTick( void );
  124. void ToggleVisibility( void );
  125. virtual Panel *CreateControlByName( const char *controlName );
  126. virtual void OnKeyCodePressed( vgui::KeyCode code );
  127. virtual void OnKeyCodeReleased( vgui::KeyCode code );
  128. virtual void OnMousePressed( vgui::MouseCode code );
  129. virtual void OnCursorMoved( int x, int y );
  130. virtual void OnCursorEntered( void );
  131. virtual void OnCursorExited( void );
  132. virtual void OnMouseReleased( vgui::MouseCode code );
  133. void SetLeftClickAction( const char *action, const char *text );
  134. const char *GetLeftClickAction( void ) const
  135. {
  136. return m_leftClickAction;
  137. }
  138. void PlaySound( const char *sound );
  139. protected:
  140. const char *ActiveToolName( void ) const;
  141. void ActivateTool( const char *toolName );
  142. virtual CNavUIToolPanel *CreateTool( const char *toolName, vgui::Panel *toolParent );
  143. private:
  144. bool m_hidden;
  145. bool m_dragSelecting;
  146. bool m_dragUnselecting;
  147. CNavUIToolPanel *m_toolPanel;
  148. CNavUIToolPanel *m_selectionPanel;
  149. void LookupKey( void );
  150. ButtonCode_t m_hideKey;
  151. IntervalTimer m_hidePressedTimer;
  152. CountdownTimer m_audioTimer;
  153. char m_leftClickAction[ 64 ];
  154. bool m_performingLeftClickAction;
  155. };
  156. extern CNavUIBasePanel *CreateNavUI( void );
  157. extern CNavUIBasePanel *TheNavUI( void );
  158. #endif // SERVER_USES_VGUI
  159. #endif // NAVUI_H