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.

191 lines
7.6 KiB

  1. //====== Copyright � 1996-2008, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: Add entities to this system, and the Locator will maintain an arrow
  4. // on the HUD that points to the entities when they are offscreen.
  5. //
  6. //=============================================================================
  7. #ifndef L4D_HUD_LOCATOR_H
  8. #define L4D_HUD_LOCATOR_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "vgui_controls/PHandle.h"
  13. #define MAX_LOCATOR_BINDINGS_SHOWN 8
  14. #define MAX_LOCATOR_TARGETS 10
  15. #define LOCATOR_FLAGS_NONE 0x00000000
  16. #define LOCATOR_ICON_FX_NONE 0x00000000
  17. #define LOCATOR_ICON_FX_PULSE_SLOW 0x00000001
  18. #define LOCATOR_ICON_FX_PULSE_FAST 0x00000002
  19. #define LOCATOR_ICON_FX_PULSE_URGENT 0x00000004
  20. #define LOCATOR_ICON_FX_ALPHA_SLOW 0x00000008
  21. #define LOCATOR_ICON_FX_ALPHA_FAST 0x00000010
  22. #define LOCATOR_ICON_FX_ALPHA_URGENT 0x00000020
  23. #define LOCATOR_ICON_FX_SHAKE_NARROW 0x00000040
  24. #define LOCATOR_ICON_FX_SHAKE_WIDE 0x00000080
  25. #define LOCATOR_ICON_FX_STATIC 0x00000100 // This icon draws at a fixed location on the HUD.
  26. #define LOCATOR_ICON_FX_NO_OFFSCREEN 0x00000200
  27. #define LOCATOR_ICON_FX_FORCE_CAPTION 0x00000400 // Always draw the caption, even when the icon is occluded.
  28. #define LOCATOR_ICON_FX_FADE_OUT 0x00000800 // Set when deactivated so it can smoothly vanish
  29. #define LOCATOR_ICON_FX_FADE_IN 0x00001000 // Set when activated so it can smoothly appear
  30. #define LOCATOR_ICON_FX_SCALE_BY_DIST 0x00002000 // Scales the icon in the world by how far away it is
  31. #define LOCATOR_ICON_FX_SCALE_LARGE 0x00004000 // Scales the icon triple the normal size
  32. #include "tier1/utlsymbol.h"
  33. // See comments in UtlSymbol on why this is useful
  34. DECLARE_PRIVATE_SYMBOLTYPE( CGameInstructorSymbol );
  35. //-----------------------------------------------------------------------------
  36. // This class represents a single target to be tracked by the locator
  37. //-----------------------------------------------------------------------------
  38. class CLocatorTarget
  39. {
  40. public:
  41. bool m_bOriginInScreenspace;
  42. Vector m_vecOrigin; // The location in the world to draw on the locator
  43. // ONLY the locator panel should fiddle with these fields.
  44. bool m_isActive;
  45. int m_serialNumber;
  46. int m_frameLastUpdated;
  47. bool m_bOnscreen;
  48. bool m_bOccluded;
  49. bool m_bVisible;
  50. bool m_bIsDrawing;
  51. bool m_bIconNoTarget;
  52. float m_distFromPlayer;
  53. CHudTexture *m_pIcon_onscreen;
  54. CHudTexture *m_pIcon_offscreen;
  55. int m_iBindingTick;
  56. float m_flNextBindingTick;
  57. float m_flNextOcclusionTest;
  58. int m_iBindingChoicesCount;
  59. const char *(m_pchBindingChoices[ MAX_LOCATOR_BINDINGS_SHOWN ]);
  60. int m_iBindChoicesOriginalToken[ MAX_LOCATOR_BINDINGS_SHOWN ];
  61. // Fields for drawing
  62. int m_targetX; // screen X position of the actual target
  63. int m_targetY; // screen Y position of the actual target
  64. int m_iconX; // screen X position (top)
  65. int m_iconY; // screen Y position (left)
  66. int m_centerX; // screen X position (center)
  67. int m_centerY; // screen Y position (center)
  68. int m_wide; // draw width of icon (may be different from frame to frame as the icon's size animates, for instance)
  69. int m_tall; // draw height of icon '' ''
  70. float m_widthScale_onscreen; // for icons that are wider than standard
  71. int m_alpha; //
  72. float m_fadeStart; // time stamp when fade out started
  73. float m_lerpStart; // time stamp when lerping started
  74. float m_pulseStart; // time stamp when pulsing started
  75. int m_declutterIndex; // sort order from the declutterer
  76. int m_lastDeclutterIndex; // last sort order from the declutterer
  77. bool m_bDrawArrow; // Whether to draw an arrow indicating this target is off-screen
  78. float m_fDrawArrowAngle; // Direction of the offscreen arrow (up, left, etc.)
  79. int m_captionWide; // How wide (pixels) my caption is.
  80. bool m_bDrawControllerButton;
  81. bool m_bDrawControllerButtonOffscreen;
  82. int m_offsetX; // User-specified X offset which is applied in screenspace
  83. int m_offsetY; // User-specified Y offset which is applied in screenspace
  84. // Fields for interpolating icon position
  85. float m_flTimeLerpDone; // How much time left before this icon arrives where it is supposed to be.
  86. int m_lastXPos; // screen X position last frame
  87. int m_lastYPos; // '' Y
  88. CLocatorTarget( void );
  89. void Activate( int serialNumber );
  90. void Deactivate( bool bNoFade = false );
  91. void Update();
  92. int GetIconX( void );
  93. int GetIconY( void );
  94. int GetIconCenterX( void );
  95. int GetIconCenterY( void );
  96. int GetIconWidth( void );
  97. int GetIconHeight( void );
  98. void AddIconEffects( int add ) { m_iEffectsFlags |= add; }
  99. void RemoveIconEffects( int remove ) { m_iEffectsFlags &= ~remove; }
  100. int GetIconEffectsFlags() { return m_iEffectsFlags; }
  101. void SetIconColor( Color color ) { m_rgbaIconColor = color; }
  102. Color GetIconColor( void ) const { return m_rgbaIconColor; }
  103. void SetCaptionColor( Color col ) { m_captionColor = col; }
  104. void SetCaptionColor( const char *pszCaptionColor );
  105. bool IsStatic();
  106. bool IsPresenting();
  107. void StartTimedLerp();
  108. void StartPresent();
  109. void EndPresent();
  110. void UpdateVguiTarget( void );
  111. vgui::Panel *GetVguiTarget( void );
  112. void SetVguiTargetName( const char *pchVguiTargetName );
  113. const char *GetVguiTargetName( void ) { return m_szVguiTargetName.String(); }
  114. void SetVguiTargetLookup( const char *pchVguiTargetLookup );
  115. const char *GetVguiTargetLookup( void ) { return m_szVguiTargetLookup.String(); }
  116. void SetVguiTargetEdge( int nVguiEdge );
  117. int GetVguiTargetEdge( void ) const { return m_nVguiTargetEdge; }
  118. void SetOnscreenIconTextureName( const char *pszTexture );
  119. void SetOffscreenIconTextureName( const char *pszTexture );
  120. void SetBinding( const char *pszBinding );
  121. void SetSteamControllerBindingToOrigin( EControllerActionOrigin *pOrigins, int nOriginalToken, const char *pszActionName );
  122. const char *UseBindingImage( char *pchIconTextureName, size_t bufSize );
  123. void SetIconNoTarget( bool bIconNoTarget ) { m_bIconNoTarget = bIconNoTarget; }
  124. const char *GetOnscreenIconTextureName() { return m_szOnscreenTexture.String(); }
  125. const char *GetOffscreenIconTextureName() { return m_szOffscreenTexture.String(); }
  126. const char *GetBinding() { return m_szBinding.String(); }
  127. void SetVisible( bool bVisible );
  128. bool IsVisible( void );
  129. void SetCaptionText( const char *pszText, const char *pszParam );
  130. const wchar_t *GetCaptionText( void ) { return (const wchar_t *)m_wszCaption.Base(); }
  131. bool HasCaptionText( void ) { return m_wszCaption.Count() > 1; }
  132. void DrawBindingName( const char *pchDrawName ) { m_pchDrawBindingName = pchDrawName; }
  133. void DrawBindingNameOffscreen( const char *pchDrawName ) { m_pchDrawBindingNameOffscreen = pchDrawName; }
  134. const char *DrawBindingName( void ) { return m_pchDrawBindingName; }
  135. const char *DrawBindingNameOffscreen( void ) { return m_pchDrawBindingNameOffscreen; }
  136. bool IsOnScreen() { return m_bOnscreen; }
  137. bool IsOccluded() { return m_bOccluded; }
  138. private:
  139. CGameInstructorSymbol m_szVguiTargetName;
  140. CGameInstructorSymbol m_szVguiTargetLookup;
  141. vgui::DHANDLE<vgui::Panel> m_hVguiTarget;
  142. int m_nVguiTargetEdge;
  143. CGameInstructorSymbol m_szOnscreenTexture;
  144. CGameInstructorSymbol m_szOffscreenTexture;
  145. CGameInstructorSymbol m_szBinding;
  146. bool m_bWasControllerLast;
  147. bool m_bWasSteamControllerLast;
  148. const char *m_pchDrawBindingName;
  149. const char *m_pchDrawBindingNameOffscreen;
  150. int m_iEffectsFlags;
  151. Color m_rgbaIconColor;
  152. CUtlVector< wchar_t > m_wszCaption;
  153. public:
  154. Color m_captionColor;
  155. };
  156. extern int Locator_AddTarget();
  157. extern void Locator_RemoveTarget( int hTarget );
  158. CLocatorTarget *Locator_GetTargetFromHandle( int hTarget );
  159. void Locator_ComputeTargetIconPositionFromHandle( int hTarget );
  160. #endif // L4D_HUD_LOCATOR_H