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.

245 lines
8.2 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef VOICE_STATUS_H
  8. #define VOICE_STATUS_H
  9. #pragma once
  10. #include <vgui_controls/Label.h>
  11. //#include "VGUI_Bitmap.h"
  12. #include <vgui_controls/Button.h>
  13. #include <vgui_controls/Image.h>
  14. #include "voice_common.h"
  15. #include "voice_banmgr.h"
  16. #include "hudelement.h"
  17. #include "usermessages.h"
  18. class CVoiceStatus;
  19. class IMaterial;
  20. class BitmapImage;
  21. // Voice Panel
  22. class CVoicePanel : public vgui::Panel
  23. {
  24. public:
  25. CVoicePanel( );
  26. ~CVoicePanel();
  27. virtual void Paint( void );
  28. virtual void setImage( BitmapImage *pImage );
  29. private:
  30. BitmapImage *m_pImage;
  31. };
  32. class CVoiceLabel
  33. {
  34. public:
  35. vgui::Label *m_pLabel;
  36. vgui::Label *m_pBackground;
  37. CVoicePanel *m_pIcon; // Voice icon next to player name.
  38. int m_clientindex; // Client index of the speaker. -1 if this label isn't being used.
  39. };
  40. // This is provided by each mod to access data that may not be the same across mods.
  41. abstract_class IVoiceStatusHelper
  42. {
  43. public:
  44. virtual ~IVoiceStatusHelper() {}
  45. // Get RGB color for voice status text about this player.
  46. virtual void GetPlayerTextColor(int entindex, int color[3]) = 0;
  47. // Force it to update the cursor state.
  48. virtual void UpdateCursorState() = 0;
  49. // Return true if the voice manager is allowed to show speaker labels
  50. // (mods usually return false when the scoreboard is up).
  51. virtual bool CanShowSpeakerLabels() = 0;
  52. };
  53. class CVoiceStatus /*: public vgui::CDefaultInputSignal*/
  54. {
  55. public:
  56. CVoiceStatus();
  57. virtual ~CVoiceStatus();
  58. // CHudBase overrides.
  59. public:
  60. // Initialize the cl_dll's voice manager.
  61. virtual int Init(
  62. IVoiceStatusHelper *m_pHelper,
  63. vgui::VPANEL pParentPanel);
  64. // ackPosition is the bottom position of where CVoiceStatus will draw the voice acknowledgement labels.
  65. virtual void VidInit();
  66. void LevelInit( void );
  67. void LevelShutdown( void );
  68. public:
  69. // Call from HUD_Frame each frame.
  70. void Frame(double frametime);
  71. // Called when a player starts or stops talking.
  72. // entindex is -1 to represent the local client talking (before the data comes back from the server).
  73. // When the server acknowledges that the local client is talking, then entindex will be gEngfuncs.GetLocalPlayer().
  74. // entindex is -2 to represent the local client's voice being acked by the server.
  75. // For local client iSsSlot will always be set >= 0 and designate a valid Splitscreen slot
  76. // for world-entities and context of local client as "in world" iSsSlot will always be negative
  77. void UpdateSpeakerStatus(int entindex, int iSsSlot, bool bTalking);
  78. // Call from the HUD_CreateEntities function so it can add sprites above player heads.
  79. void DrawHeadLabels();
  80. float GetHeadLabelOffset( void ) const;
  81. void SetHeadLabelsDisabled( bool bDisabled ) { m_bHeadLabelsDisabled = bDisabled; }
  82. // Called when the server registers a change to who this client can hear.
  83. bool HandleVoiceMaskMsg(const CCSUsrMsg_VoiceMask &msg);
  84. // The server sends this message initially to tell the client to send their state.
  85. bool HandleReqStateMsg(const CCSUsrMsg_RequestState &msg);
  86. // Squelch mode functions.
  87. public:
  88. // When you enter squelch mode, pass in
  89. void StartSquelchMode();
  90. void StopSquelchMode();
  91. bool IsInSquelchMode();
  92. // returns true if the target client has been banned
  93. // playerIndex is of range 1..maxplayers
  94. bool IsPlayerBlocked(int iPlayerIndex);
  95. // If individual game settings require us to prevent communication from this player.
  96. // Different concept from 'blocking', which persists from session to session or from 'audible' which
  97. // are gamerules that apply to all users and doesn't apply to all forms of communication (eg text chat to whole server).
  98. bool ShouldHideCommunicationFromPlayer( int iPlayerIndex );
  99. // returns false if the player can't hear the other client due to game rules (eg. the other team)
  100. bool IsPlayerAudible(int iPlayerIndex);
  101. // returns true if the player is currently speaking
  102. bool IsPlayerSpeaking(int iPlayerIndex);
  103. // returns true if the local player is attempting to speak
  104. bool IsLocalPlayerSpeaking( int iSsSlot );
  105. // returns true if the local player is attempting to speak, and is above the volume threshold
  106. bool IsLocalPlayerSpeakingAboveThreshold( int iSsSlot );
  107. // blocks the target client from being heard
  108. void SetPlayerBlockedState( int iPlayerIndex );
  109. void SetHeadLabelMaterial( const char *pszMaterial );
  110. IMaterial *GetHeadLabelMaterial( void ) { return m_pHeadLabelMaterial; }
  111. CUserMessageBinder m_UMCMsgVoiceMask;
  112. CUserMessageBinder m_UMCMsgRequestState;
  113. private:
  114. void UpdateServerState(bool bForce);
  115. // Update the button artwork to reflect the client's current state.
  116. void UpdateBanButton(int iClient);
  117. private:
  118. float m_LastUpdateServerState; // Last time we called this function.
  119. int m_bServerModEnable; // What we've sent to the server about our "voice_modenable" cvar.
  120. vgui::VPANEL m_pParentPanel;
  121. CPlayerBitVec m_VoicePlayers; // Who is currently talking. Indexed by client index.
  122. // This is the gamerules-defined list of players that you can hear. It is based on what teams people are on
  123. // and is totally separate from the ban list. Indexed by client index.
  124. CPlayerBitVec m_AudiblePlayers;
  125. // Players who have spoken at least once in the game so far
  126. CPlayerBitVec m_VoiceEnabledPlayers;
  127. // This is who the server THINKS we have banned (it can become incorrect when a new player arrives on the server).
  128. // It is checked periodically, and the server is told to squelch or unsquelch the appropriate players.
  129. CPlayerBitVec m_ServerBannedPlayers;
  130. IVoiceStatusHelper *m_pHelper; // Each mod provides an implementation of this.
  131. // Squelch mode stuff.
  132. bool m_bInSquelchMode;
  133. bool m_bTalking[ MAX_SPLITSCREEN_CLIENTS ]; // Set to true when the client thinks it's talking.
  134. bool m_bAboveThreshold[ MAX_SPLITSCREEN_CLIENTS ]; // Set to true when the client thinks it's voice is above the threshold to send to the server
  135. bool m_bServerAcked[ MAX_SPLITSCREEN_CLIENTS ]; // Set to true when the server knows the client is talking.
  136. public:
  137. CVoiceBanMgr m_BanMgr; // Tracks which users we have squelched and don't want to hear.
  138. private:
  139. IMaterial *m_pHeadLabelMaterial; // For labels above players' heads.
  140. bool m_bBanMgrInitialized;
  141. int m_nControlSize;
  142. bool m_bHeadLabelsDisabled;
  143. CountdownTimer m_bAboveThresholdTimer[ MAX_SPLITSCREEN_CLIENTS ];
  144. float m_flTalkTime[ VOICE_MAX_PLAYERS ];
  145. float m_flTimeLastUpdate[ VOICE_MAX_PLAYERS ];
  146. };
  147. //-----------------------------------------------------------------------------
  148. // returns true if the player is currently speaking
  149. //-----------------------------------------------------------------------------
  150. FORCEINLINE bool CVoiceStatus::IsPlayerSpeaking(int iPlayerIndex)
  151. {
  152. return m_VoicePlayers[iPlayerIndex-1] != 0;
  153. }
  154. //-----------------------------------------------------------------------------
  155. // Purpose: returns true if the player can't hear the other client due to game rules (eg. the other team)
  156. // Input : playerID -
  157. // Output : Returns true on success, false on failure.
  158. //-----------------------------------------------------------------------------
  159. FORCEINLINE bool CVoiceStatus::IsPlayerAudible(int iPlayer)
  160. {
  161. return !!m_AudiblePlayers[iPlayer-1];
  162. }
  163. //-----------------------------------------------------------------------------
  164. // returns true if the local player is attempting to speak
  165. //-----------------------------------------------------------------------------
  166. FORCEINLINE bool CVoiceStatus::IsLocalPlayerSpeaking( int iSsSlot )
  167. {
  168. return m_bTalking[ iSsSlot ];
  169. }
  170. //-----------------------------------------------------------------------------
  171. // returns true if the local player is attempting to speak, and is above the volume threshold
  172. //-----------------------------------------------------------------------------
  173. FORCEINLINE bool CVoiceStatus::IsLocalPlayerSpeakingAboveThreshold( int iSsSlot )
  174. {
  175. return m_bTalking[ iSsSlot ] && !m_bAboveThresholdTimer[ iSsSlot ].IsElapsed();
  176. }
  177. // Get the (global) voice manager.
  178. CVoiceStatus* GetClientVoiceMgr();
  179. void ClientVoiceMgr_Init();
  180. void ClientVoiceMgr_Shutdown();
  181. void ClientVoiceMgr_LevelInit();
  182. void ClientVoiceMgr_LevelShutdown();
  183. #endif // VOICE_STATUS_H