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.

244 lines
6.3 KiB

  1. // RadialMenu.h
  2. // Copyright (c) 2006 Turtle Rock Studios, Inc.
  3. #ifndef RADIALMENU_H
  4. #define RADIALMENU_H
  5. #ifdef _WIN32
  6. #pragma once
  7. #endif
  8. #include "viewport_panel_names.h"
  9. #include <vgui_controls/frame.h>
  10. #include <game/client/iviewport.h>
  11. #include <vgui_controls/EditablePanel.h>
  12. #include "hudelement.h"
  13. class CRadialButton;
  14. class C_Portal_Player;
  15. enum RadialMenuTypes_t
  16. {
  17. MENU_PING = 0,
  18. MENU_TAUNT,
  19. MENU_PLAYTEST,
  20. MENU_COUNT
  21. };
  22. //--------------------------------------------------------------------------------------------------------
  23. /**
  24. * Helper class for managing our list of possible menus. This means we can load RadialMenu.txt,
  25. * and add in additional menus from other text files (UserRadialMenu.txt?)
  26. */
  27. class ClientMenuManager
  28. {
  29. public:
  30. ClientMenuManager()
  31. {
  32. m_menuKeys = NULL;
  33. }
  34. virtual ~ClientMenuManager()
  35. {
  36. Reset();
  37. }
  38. void AddMenuFile( const char *filename );
  39. virtual KeyValues *FindMenu( const char *menuName );
  40. virtual void Flush( void );
  41. void PrintStats( void )
  42. {
  43. DevMsg( "Client menus:\n" );
  44. for ( KeyValues *pKey = m_menuKeys->GetFirstTrueSubKey(); pKey; pKey = pKey->GetNextTrueSubKey() )
  45. {
  46. DevMsg( "\t%s\n", pKey->GetName() );
  47. }
  48. }
  49. protected:
  50. void Reset( void )
  51. {
  52. if ( m_menuKeys )
  53. {
  54. m_menuKeys->deleteThis();
  55. }
  56. m_menuKeys = NULL;
  57. }
  58. KeyValues *m_menuKeys;
  59. };
  60. class ClientMenuManagerPlaytest : public ClientMenuManager
  61. {
  62. public:
  63. ClientMenuManagerPlaytest() {}
  64. virtual ~ClientMenuManagerPlaytest() {}
  65. virtual KeyValues *FindMenu( const char *menuName );
  66. virtual void Flush( void );
  67. };
  68. class CRadialMenuPanel : public vgui::Frame, public IViewPortPanel
  69. {
  70. private:
  71. DECLARE_CLASS_SIMPLE( CRadialMenuPanel, vgui::Frame );
  72. public:
  73. CRadialMenuPanel(IViewPort *pViewPort);
  74. virtual ~CRadialMenuPanel() {}
  75. virtual const char *GetName( void ) { return PANEL_RADIAL_MENU; }
  76. virtual void SetData(KeyValues *data) {};
  77. virtual void Reset() {}
  78. virtual void Update() {}
  79. virtual bool NeedsUpdate( void ) { return false; }
  80. virtual bool HasInputElements( void ) { return true; }
  81. virtual void ShowPanel( bool bShow );
  82. virtual bool WantsBackgroundBlurred( void ) { return false; }
  83. // both vgui::Frame and IViewPortPanel define these, so explicitly define them here as passthroughs to vgui
  84. vgui::VPANEL GetVPanel( void ) { return BaseClass::GetVPanel(); }
  85. virtual bool IsVisible() { return BaseClass::IsVisible(); }
  86. virtual void SetParent( vgui::VPANEL parent )
  87. {
  88. BaseClass::SetParent( parent );
  89. }
  90. protected:
  91. IViewPort *m_pViewPort;
  92. };
  93. //--------------------------------------------------------------------------------------------------------
  94. /**
  95. * Viewport panel that gives us a simple rosetta menu
  96. */
  97. class CRadialMenu : public CHudElement, public vgui::EditablePanel
  98. {
  99. public:
  100. DECLARE_CLASS_SIMPLE( CRadialMenu, vgui::EditablePanel );
  101. CRadialMenu( const char *pElementName );
  102. virtual ~CRadialMenu();
  103. enum ButtonDir
  104. {
  105. CENTER = 0,
  106. NORTH,
  107. NORTH_EAST,
  108. EAST,
  109. SOUTH_EAST,
  110. SOUTH,
  111. SOUTH_WEST,
  112. WEST,
  113. NORTH_WEST,
  114. NUM_BUTTON_DIRS
  115. };
  116. virtual void SetData( KeyValues *data );
  117. //virtual KeyValues *GetData( void ) { return NULL; }
  118. bool IsFading( void ) { return IsVisible() && m_fading; }
  119. void StartFade( void );
  120. void ChooseArmedButton();
  121. void SetArmedButtonDir( ButtonDir dir );
  122. void OnRadialMenuOpen( void );
  123. virtual bool ShouldDraw() { return m_bEnabled; }
  124. virtual void ShowPanel( bool bShow );
  125. virtual void OnMousePressed( vgui::MouseCode code );
  126. virtual void OnMouseReleased( vgui::MouseCode code );
  127. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  128. virtual void PerformLayout( void );
  129. virtual void PaintBackground( void );
  130. virtual void Paint( void );
  131. virtual void OnCommand( const char *command );
  132. virtual vgui::Panel *CreateControlByName( const char *controlName );
  133. virtual void OnThink( void );
  134. virtual void OnTick( void );
  135. virtual int KeyInput( int down, ButtonCode_t keynum, const char *pszCurrentBinding );
  136. void OnCursorEnteredButton( int x, int y, CRadialButton *button );
  137. // For loading our internal data while using this menu
  138. void SetTargetEntity( EHANDLE hTargetEntity ) { m_hTargetEntity = hTargetEntity; }
  139. void SetTraceData( const Vector &vPosition, const Vector &vNormal ) { m_vPosition = vPosition; m_vNormal = vNormal; }
  140. void SetRadialType( RadialMenuTypes_t menuType ) { m_menuType = menuType; }
  141. void SetFadeInTime( float fFadeInTime ) { m_fFadeInTime = fFadeInTime; }
  142. void ClearLockInTime( void ) { m_fSelectionLockInTime = 0.0f; }
  143. void SetDemoCursorPos( int cursorX, int cursorY ) { m_demoCursorX = cursorX; m_demoCursorY = cursorY; }
  144. ButtonDir GetArmedDir( void ) const { return m_armedButtonDir; }
  145. bool m_bFirstCentering;
  146. static float m_fLastPingTime[ MAX_SPLITSCREEN_PLAYERS ][ 2 ];
  147. static int m_nNumPings[ MAX_SPLITSCREEN_PLAYERS ][ 2 ];
  148. void SetRadialMenuEnabled( bool bEnable ) { m_bEnabled = bEnable; }
  149. void SetQuickPingForceClose( bool bEnable ) { m_bQuickPingForceClose = bEnable; }
  150. protected:
  151. void ClearGlowEntity( void );
  152. void SendCommand( const char *commandStr );
  153. const char *ButtonNameFromDir( ButtonDir dir );
  154. ButtonDir DirFromButtonName( const char * name );
  155. CRadialButton *m_buttons[NUM_BUTTON_DIRS]; // same order as vgui::Label::Alignment
  156. ButtonDir m_armedButtonDir;
  157. void UpdateButtonBounds( void );
  158. void HandleControlSettings();
  159. void StartDrag( void );
  160. void EndDrag( void );
  161. CPanelAnimationVar( vgui::HFont, m_hCustomizeFont, "CustomizeFont", "Default" );
  162. bool m_fading;
  163. float m_fadeStart;
  164. Color m_lineColor;
  165. KeyValues *m_resource;
  166. KeyValues *m_menuData;
  167. int m_nArrowTexture;
  168. int m_minButtonX;
  169. int m_minButtonY;
  170. int m_maxButtonX;
  171. int m_maxButtonY;
  172. // Internal data for holding our polling information
  173. Vector m_vPosition;
  174. Vector m_vNormal;
  175. EHANDLE m_hTargetEntity;
  176. int m_nEntityGlowIndex;
  177. RadialMenuTypes_t m_menuType;
  178. bool m_bEditing;
  179. bool m_bDragging;
  180. int m_nDraggingTaunt;
  181. float m_fFadeInTime;
  182. float m_fSelectionLockInTime;
  183. bool m_bEnabled;
  184. int m_cursorX;
  185. int m_cursorY;
  186. int m_demoCursorX;
  187. int m_demoCursorY;
  188. bool m_bQuickPingForceClose;
  189. };
  190. bool IsRadialMenuOpen( void );
  191. #endif // RADIALMENU_H