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.

389 lines
11 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef HUD_CONTROLPOINTICONS_H
  7. #define HUD_CONTROLPOINTICONS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "cbase.h"
  12. #include "hudelement.h"
  13. #include <vgui_controls/Panel.h>
  14. #include <vgui_controls/Label.h>
  15. #include <vgui_controls/ImagePanel.h>
  16. #include "vgui_controls/EditablePanel.h"
  17. #include "vgui_controls/AnimationController.h"
  18. #include "vgui_controls/circularprogressbar.h"
  19. #include <vgui/isurface.h>
  20. #include "iconpanel.h"
  21. #define PULSE_TIME_PER_ICON 1.5f
  22. #define PULSE_RAMP_TIME 0.5
  23. #define PULSE_REMAP_SIZE 6.0
  24. #define FAKE_CAPTURE_TIME 5.0
  25. #define FAKE_CAPTURE_POST_PAUSE 2.0
  26. extern ConVar mp_capstyle;
  27. extern ConVar mp_blockstyle;
  28. #define STARTCAPANIM_SWOOP_LENGTH 0.4
  29. #define STARTCAPANIM_ICON_SWITCH 0.15
  30. #define FINISHCAPANIM_SWOOP_LENGTH 0.2
  31. #define CAP_BOX_INDENT_X XRES(2)
  32. #define CAP_BOX_INDENT_Y YRES(2)
  33. class CControlPointIcon;
  34. // Options for how the cap progress teardrop positions itself around the cap point icon
  35. enum
  36. {
  37. CP_DIR_N,
  38. CP_DIR_NW,
  39. CP_DIR_NE,
  40. };
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. class CControlPointProgressBar : public vgui::EditablePanel
  45. {
  46. DECLARE_CLASS_SIMPLE( CControlPointProgressBar, vgui::EditablePanel );
  47. public:
  48. explicit CControlPointProgressBar(Panel *parent);
  49. virtual void ApplySchemeSettings( IScheme *pScheme );
  50. virtual void PerformLayout( void );
  51. virtual void Paint( void );
  52. virtual bool IsVisible( void );
  53. virtual void Reset( void );
  54. void SetupForPoint( CControlPointIcon *pIcon );
  55. void UpdateBarText( void );
  56. private:
  57. CControlPointIcon *m_pAttachedToIcon;
  58. vgui::CircularProgressBar *m_pBar;
  59. vgui::Label *m_pBarText;
  60. CIconPanel *m_pTeardrop;
  61. CIconPanel *m_pTeardropSide;
  62. CIconPanel *m_pBlocked;
  63. int m_iOrgHeight;
  64. int m_iMidGroupIndex;
  65. };
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. class CControlPointIconSwoop : public vgui::ImagePanel, public CGameEventListener
  70. {
  71. DECLARE_CLASS_SIMPLE( CControlPointIconSwoop, vgui::ImagePanel );
  72. public:
  73. CControlPointIconSwoop(Panel *parent, const char *name) : vgui::ImagePanel( parent, name )
  74. {
  75. SetImage( "../sprites/obj_icons/capture_highlight" );
  76. SetShouldScaleImage( true );
  77. ListenForGameEvent( "localplayer_changeteam" );
  78. }
  79. virtual void PaintBackground( void )
  80. {
  81. float flElapsedTime = (gpGlobals->curtime - m_flStartCapAnimStart);
  82. if (GetImage())
  83. {
  84. surface()->DrawSetColor(255, 255, 255, 255);
  85. int iYPos = RemapValClamped( flElapsedTime, 0, STARTCAPANIM_SWOOP_LENGTH, 0, GetTall() );
  86. GetImage()->SetPos( 0, iYPos );
  87. GetImage()->Paint();
  88. }
  89. // Once we've finished the swoop, go away
  90. if ( flElapsedTime >= STARTCAPANIM_SWOOP_LENGTH )
  91. {
  92. SetVisible( false );
  93. }
  94. }
  95. virtual bool IsVisible( void )
  96. {
  97. if ( IsInFreezeCam() == true )
  98. return false;
  99. return BaseClass::IsVisible();
  100. }
  101. void StartSwoop( void )
  102. {
  103. m_flStartCapAnimStart = gpGlobals->curtime;
  104. }
  105. void FireGameEvent( IGameEvent * event )
  106. {
  107. if ( vgui::ipanel()->GetMessageContextId( GetVPanel() ) != event->GetInt( "splitscreenplayer" ) )
  108. return;
  109. if ( FStrEq( "localplayer_changeteam", event->GetName() ) )
  110. {
  111. SetVisible( false );
  112. }
  113. }
  114. private:
  115. float m_flStartCapAnimStart;
  116. };
  117. //-----------------------------------------------------------------------------
  118. // Purpose:
  119. //-----------------------------------------------------------------------------
  120. class CControlPointIconCapArrow : public vgui::Panel
  121. {
  122. DECLARE_CLASS_SIMPLE( CControlPointIconCapArrow, vgui::Panel );
  123. public:
  124. CControlPointIconCapArrow( CControlPointIcon *pIcon, Panel *parent, const char *name);
  125. virtual void Paint( void );
  126. virtual bool IsVisible( void );
  127. void SetImage( const char *pszImage )
  128. {
  129. m_pArrowMaterial = materials->FindMaterial( pszImage, TEXTURE_GROUP_VGUI );
  130. }
  131. private:
  132. IMaterial *m_pArrowMaterial;
  133. CControlPointIcon *m_pAttachedToIcon;
  134. };
  135. //-----------------------------------------------------------------------------
  136. // Purpose:
  137. //-----------------------------------------------------------------------------
  138. class CControlPointIconCapturePulse : public vgui::ImagePanel
  139. {
  140. DECLARE_CLASS_SIMPLE( CControlPointIconCapturePulse, vgui::ImagePanel );
  141. public:
  142. CControlPointIconCapturePulse(Panel *parent, const char *name) : vgui::ImagePanel( parent, name )
  143. {
  144. SetImage( "../sprites/obj_icons/icon_obj_white" );
  145. SetShouldScaleImage( true );
  146. }
  147. virtual void PaintBackground( void )
  148. {
  149. if ( m_flFinishCapAnimStart && gpGlobals->curtime > m_flFinishCapAnimStart )
  150. {
  151. float flElapsedTime = MAX( 0, (gpGlobals->curtime - m_flFinishCapAnimStart) );
  152. if (GetImage())
  153. {
  154. surface()->DrawSetColor(255, 255, 255, 255);
  155. int iSize = RemapValClamped( flElapsedTime, 0, FINISHCAPANIM_SWOOP_LENGTH, GetWide(), m_iShrinkSize );
  156. GetImage()->SetPos( (GetWide() - iSize)*0.5, (GetTall() - iSize)*0.5 );
  157. GetImage()->SetSize( iSize, iSize );
  158. GetImage()->Paint();
  159. }
  160. // Once we've finished the swoop, go away
  161. if ( flElapsedTime >= FINISHCAPANIM_SWOOP_LENGTH )
  162. {
  163. SetVisible( false );
  164. }
  165. }
  166. }
  167. void StartPulse( float flTime, int iShrinkSize )
  168. {
  169. m_flFinishCapAnimStart = flTime;
  170. m_iShrinkSize = iShrinkSize;
  171. if ( GetWide() < m_iShrinkSize )
  172. {
  173. SetWide( m_iShrinkSize );
  174. }
  175. }
  176. virtual bool IsVisible( void )
  177. {
  178. if ( IsInFreezeCam() == true )
  179. return false;
  180. return BaseClass::IsVisible();
  181. }
  182. private:
  183. float m_flFinishCapAnimStart;
  184. int m_iShrinkSize;
  185. };
  186. //-----------------------------------------------------------------------------
  187. // Purpose: The base image in the cap point icons that pulses.
  188. //-----------------------------------------------------------------------------
  189. class CControlPointIconPulseable : public vgui::ImagePanel
  190. {
  191. DECLARE_CLASS_SIMPLE( CControlPointIconPulseable, vgui::ImagePanel );
  192. public:
  193. CControlPointIconPulseable(Panel *parent, const char *name, int iIndex) : vgui::ImagePanel( parent, name )
  194. {
  195. SetShouldScaleImage( true );
  196. m_pPulseImage = NULL;
  197. m_iCPIndex = iIndex;
  198. }
  199. virtual void ApplySchemeSettings( IScheme *pScheme );
  200. virtual void OnSizeChanged(int newWide, int newTall);
  201. virtual void PaintBackground( void );
  202. void StartPulsing( float flDelay, float flPulseTime, bool bAccelerate );
  203. void StopPulsing( void );
  204. virtual bool IsVisible( void )
  205. {
  206. if ( IsInFreezeCam() == true )
  207. return false;
  208. return BaseClass::IsVisible();
  209. }
  210. private:
  211. int m_iCPIndex;
  212. float m_flStartCapAnimStart;
  213. float m_flPulseTime;
  214. bool m_bAccelerateOverCapture;
  215. IImage *m_pPulseImage;
  216. };
  217. //-----------------------------------------------------------------------------
  218. // Purpose: A single icon that shows the state of one control point
  219. //-----------------------------------------------------------------------------
  220. class CControlPointIcon : public vgui::EditablePanel, public CHudElement
  221. {
  222. DECLARE_CLASS_SIMPLE( CControlPointIcon, vgui::EditablePanel );
  223. public:
  224. CControlPointIcon( Panel *parent, const char *pName, int iIndex );
  225. ~CControlPointIcon( void );
  226. virtual void ApplySchemeSettings( IScheme *scheme );
  227. virtual void PerformLayout( void );
  228. void UpdateImage( void );
  229. void UpdateCapImage( void );
  230. bool IsPointLocked( void );
  231. int GetCapIndex( void ) { return m_iCPIndex; }
  232. void SetSwipeUp( bool bUp ) { m_bSwipeUp = bUp; }
  233. bool ShouldSwipeUp( void ) { return m_bSwipeUp; }
  234. int GetCapProgressDir( void ) { return m_iCapProgressDir; }
  235. void SetCapProgressDir( int iDir ) { m_iCapProgressDir = iDir; }
  236. void FakePulse( float flTime );
  237. bool IsVisible( void );
  238. virtual void Paint( void );
  239. private:
  240. int m_iCPIndex;
  241. vgui::ImagePanel *m_pOverlayImage;
  242. CControlPointIconPulseable *m_pBaseImage;
  243. CControlPointIconCapArrow *m_pCapImage;
  244. CControlPointIconSwoop *m_pCapHighlightImage;
  245. CControlPointIconCapturePulse *m_pCapPulseImage;
  246. vgui::ImagePanel *m_pCapPlayerImage;
  247. vgui::Label *m_pCapNumPlayers;
  248. bool m_bSwipeUp;
  249. float m_flStartCapAnimStart;
  250. int m_iCapProgressDir;
  251. int m_iPrevCappers;
  252. bool m_bCachedLockedState;
  253. };
  254. //-----------------------------------------------------------------------------
  255. // Purpose:
  256. //-----------------------------------------------------------------------------
  257. class CHudControlPointIcons : public CHudElement, public vgui::Panel
  258. {
  259. public:
  260. DECLARE_CLASS_SIMPLE( CHudControlPointIcons, vgui::Panel );
  261. explicit CHudControlPointIcons( const char *pName );
  262. virtual ~CHudControlPointIcons( void );
  263. virtual void ApplySchemeSettings( IScheme *scheme );
  264. virtual void PerformLayout( void );
  265. virtual void Paint();
  266. virtual void Init();
  267. virtual void Reset();
  268. virtual bool IsVisible( void );
  269. virtual void LevelShutdown( void );
  270. virtual bool ShouldDraw( void )
  271. {
  272. return IsVisible();
  273. }
  274. virtual void FireGameEvent( IGameEvent *event );
  275. void UpdateProgressBarFor( int iIndex );
  276. void InitIcons();
  277. void ShutdownIcons();
  278. void DrawBackgroundBox( int xpos, int ypos, int nBoxWidth, int nBoxHeight, bool bCutCorner );
  279. bool PaintTeamBaseIcon( int index, float flXPos, float flYPos, float flIconSize );
  280. bool IsFakingCapture( int index = -1, bool *bMult = NULL, float *flFakeTime = NULL )
  281. {
  282. if ( m_bFakingCapture && m_flFakeCaptureTime < gpGlobals->curtime )
  283. {
  284. m_iCurrentCP = -1;
  285. m_bFakingCapture = false;
  286. m_bFakingCaptureMult = false;
  287. }
  288. if ( bMult) *bMult = m_bFakingCaptureMult;
  289. if ( flFakeTime ) *flFakeTime = m_flFakeCaptureTime;
  290. return (m_bFakingCapture && (index == -1 || index == m_iCurrentCP));
  291. }
  292. private:
  293. int m_iCPTextures[8];
  294. int m_iCPCappingTextures[8];
  295. struct TeamBaseTexture_t
  296. {
  297. TeamBaseTexture_t() : m_nMaterialIndex( INT_MAX ), m_nTextureId( -1 ) {}
  298. int m_nMaterialIndex;
  299. int m_nTextureId;
  300. };
  301. TeamBaseTexture_t m_iTeamBaseTextures[MAX_TEAMS];
  302. int m_iBackgroundTexture;
  303. Color m_clrBackground;
  304. Color m_clrBorder;
  305. int m_iCurrentCP; // the index of the control point the local is currently in
  306. int m_iLastCP; // the index of the control point the local player was last in
  307. // Capture faking for Intros
  308. float m_flPulseTime;
  309. bool m_bFakingCapture;
  310. bool m_bFakingCaptureMult;
  311. float m_flFakeCaptureTime;
  312. CPanelAnimationVar( vgui::HFont, m_hTextFont, "ChatFont", "Default" );
  313. CPanelAnimationVarAliasType( int, m_nCornerCutSize, "CornerCutSize", "5", "proportional_int" );
  314. CPanelAnimationVarAliasType( int, m_nBackgroundOverlap, "BackgroundOverlap", "5", "proportional_int" );
  315. CPanelAnimationVarAliasType( int, m_iIconStartX, "icon_start_x", "10", "proportional_int" );
  316. CPanelAnimationVarAliasType( int, m_iIconStartY, "icon_start_y", "10", "proportional_int" );
  317. CPanelAnimationVarAliasType( float, m_flIconExpand, "icon_expand", "0", "proportional_float" );
  318. CPanelAnimationVarAliasType( int, m_iIconSize, "iconsize", "24", "proportional_int" );
  319. CPanelAnimationVarAliasType( int, m_iIconGapWidth, "separator_width", "7", "proportional_int" );
  320. CPanelAnimationVarAliasType( int, m_iIconGapHeight, "separator_height", "9", "proportional_int" );
  321. CPanelAnimationVarAliasType( int, m_nHeightOffset, "height_offset", "0", "proportional_int" );
  322. CUtlVector<CControlPointIcon *> m_Icons;
  323. };
  324. #endif // HUD_CONTROLPOINTICONS_H