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.

184 lines
5.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef HUD_CLOSECAPTION_H
  8. #define HUD_CLOSECAPTION_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "hudelement.h"
  13. #include <vgui_controls/Panel.h>
  14. #include "closedcaptions.h"
  15. #include "usermessages.h"
  16. class CSentence;
  17. class C_BaseFlex;
  18. class CCloseCaptionItem;
  19. struct WorkUnitParams;
  20. class CAsyncCaption;
  21. struct AsyncCaptionData_t;
  22. //-----------------------------------------------------------------------------
  23. // Purpose:
  24. //-----------------------------------------------------------------------------
  25. class CHudCloseCaption : public CHudElement, public vgui::Panel
  26. {
  27. DECLARE_CLASS_SIMPLE( CHudCloseCaption, vgui::Panel );
  28. public:
  29. DECLARE_MULTIPLY_INHERITED();
  30. explicit CHudCloseCaption( const char *pElementName );
  31. virtual ~CHudCloseCaption();
  32. // Expire lingering items
  33. virtual void OnTick( void );
  34. virtual void LevelInit( void );
  35. virtual void LevelShutdown( void )
  36. {
  37. m_bLevelShutDown = true;
  38. Reset();
  39. m_bLevelShutDown = false;
  40. }
  41. // Painting methods
  42. virtual void Paint();
  43. virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
  44. bool MsgFunc_CloseCaption(const CCSUsrMsg_CloseCaption &msg);
  45. bool MsgFunc_CloseCaptionDirect(const CCSUsrMsg_CloseCaptionDirect &msg);
  46. // Clear all CC data
  47. void Reset( void );
  48. void Process( const wchar_t *stream, float duration, bool fromplayer, bool direct = false );
  49. bool ProcessCaption( char const *tokenname, float duration, bool fromplayer = false, bool direct = false );
  50. bool ProcessCaptionByHash( unsigned int hash, float duration, bool fromplayer, bool direct = false );
  51. void ProcessCaptionDirect( char const *tokenname, float duration, bool fromplayer = false );
  52. void ProcessSentenceCaptionStream( char const *tokenstream );
  53. void PlayRandomCaption();
  54. void InitCaptionDictionary( char const *language, bool bForce = false );
  55. bool AddFileToCaptionDictionary( const char *filename );
  56. void OnFinishAsyncLoad( int nFileIndex, int nBlockNum, AsyncCaptionData_t *pData );
  57. void Flush();
  58. void TogglePaintDebug();
  59. enum
  60. {
  61. CCFONT_NORMAL = 0,
  62. CCFONT_ITALIC,
  63. CCFONT_BOLD,
  64. CCFONT_ITALICBOLD,
  65. CCFONT_CONSOLE,
  66. CCFONT_MAX
  67. };
  68. static int GetFontNumber( bool bold, bool italic );
  69. void Lock( void );
  70. void Unlock( void );
  71. void FindSound( char const *pchANSI );
  72. void ClearCurrentLanguage();
  73. struct CaptionRepeat
  74. {
  75. CaptionRepeat() :
  76. m_nTokenIndex( 0 ),
  77. m_flLastEmitTime( 0 ),
  78. m_flInterval( 0 ),
  79. m_nLastEmitTick( 0 )
  80. {
  81. }
  82. int m_nTokenIndex;
  83. int m_nLastEmitTick;
  84. float m_flLastEmitTime;
  85. float m_flInterval;
  86. };
  87. CUserMessageBinder m_UMCMsgCloseCaption;
  88. CUserMessageBinder m_UMCMsgCloseCaptionDirect;
  89. private:
  90. void ClearAsyncWork();
  91. void ProcessAsyncWork();
  92. bool AddAsyncWork( char const *tokenstream, bool bIsStream, float duration, bool fromplayer, bool direct = false );
  93. bool AddAsyncWorkByHash( unsigned int hash, float duration, bool fromplayer, bool direct = false );
  94. void _ProcessSentenceCaptionStream( int wordCount, char const *tokenstream, const wchar_t *caption_full );
  95. void _ProcessCaption( const wchar_t *caption, unsigned int hash, float duration, bool fromplayer, bool direct = false );
  96. CUtlLinkedList< CAsyncCaption *, unsigned short > m_AsyncWork;
  97. CUtlRBTree< CaptionRepeat, int > m_CloseCaptionRepeats;
  98. static bool CaptionTokenLessFunc( const CaptionRepeat &lhs, const CaptionRepeat &rhs );
  99. void DrawStream( wrect_t& rect, wrect_t &rcWindow, CCloseCaptionItem *item, int iFadeLine, float flFadeLineAlpha );
  100. void ComputeStreamWork( int available_width, CCloseCaptionItem *item );
  101. bool SplitCommand( wchar_t const **ppIn, wchar_t *cmd, wchar_t *args ) const;
  102. bool StreamHasCommand( const wchar_t *stream, const wchar_t *findcmd ) const;
  103. bool GetFloatCommandValue( const wchar_t *stream, const wchar_t *findcmd, float& value ) const;
  104. bool GetNoRepeatValue( const wchar_t *caption, float &retval );
  105. void ParseCloseCaptionStream( const wchar_t *in, int available_width );
  106. bool StreamHasCommand( const wchar_t *stream, const wchar_t *search );
  107. void DumpWork( CCloseCaptionItem *item );
  108. void AddWorkUnit( CCloseCaptionItem *item, WorkUnitParams& params );
  109. void CreateFonts( void );
  110. void LoadColorMap( const char *pFilename );
  111. bool FindColorForTag( wchar_t *pTag, Color &tagColor );
  112. CUtlVector< CCloseCaptionItem * > m_Items;
  113. void SetUseAsianWordWrapping();
  114. vgui::HFont m_hFonts[CCFONT_MAX];
  115. int m_nLineHeight;
  116. int m_nGoalHeight;
  117. int m_nCurrentHeight;
  118. float m_flGoalAlpha;
  119. float m_flCurrentAlpha;
  120. float m_flGoalHeightStartTime;
  121. float m_flGoalHeightFinishTime;
  122. CPanelAnimationVar( float, m_flBackgroundAlpha, "BgAlpha", "192" );
  123. CPanelAnimationVar( float, m_flGrowTime, "GrowTime", "0.25" );
  124. CPanelAnimationVar( float, m_flItemHiddenTime, "ItemHiddenTime", "0.2" );
  125. CPanelAnimationVar( float, m_flItemFadeInTime, "ItemFadeInTime", "0.15" );
  126. CPanelAnimationVar( float, m_flItemFadeOutTime, "ItemFadeOutTime", "0.3" );
  127. CPanelAnimationVar( int, m_nTopOffset, "topoffset", "40" );
  128. CUtlVector< AsyncCaption_t > m_AsyncCaptions;
  129. bool m_bLocked;
  130. bool m_bVisibleDueToDirect;
  131. bool m_bPaintDebugInfo;
  132. CUtlSymbol m_CurrentLanguage;
  133. CUtlDict< Color, int > m_ColorMap;
  134. bool m_bLevelShutDown;
  135. bool m_bUseAsianWordWrapping;
  136. };
  137. #endif // HUD_CLOSECAPTION_H