Team Fortress 2 Source Code as on 22/4/2020
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.

197 lines
5.6 KiB

  1. //========= Copyright 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. #ifdef VOICE_VOX_ENABLE
  18. extern ConVar voice_vox;
  19. #endif // VOICE_VOX_ENABLE
  20. class CVoiceStatus;
  21. class IMaterial;
  22. class BitmapImage;
  23. // Voice Panel
  24. class CVoicePanel : public vgui::Panel
  25. {
  26. public:
  27. CVoicePanel( );
  28. ~CVoicePanel();
  29. virtual void Paint( void );
  30. virtual void setImage( BitmapImage *pImage );
  31. private:
  32. BitmapImage *m_pImage;
  33. };
  34. class CVoiceLabel
  35. {
  36. public:
  37. vgui::Label *m_pLabel;
  38. vgui::Label *m_pBackground;
  39. CVoicePanel *m_pIcon; // Voice icon next to player name.
  40. int m_clientindex; // Client index of the speaker. -1 if this label isn't being used.
  41. };
  42. // This is provided by each mod to access data that may not be the same across mods.
  43. abstract_class IVoiceStatusHelper
  44. {
  45. public:
  46. virtual ~IVoiceStatusHelper() {}
  47. // Get RGB color for voice status text about this player.
  48. virtual void GetPlayerTextColor(int entindex, int color[3]) = 0;
  49. // Force it to update the cursor state.
  50. virtual void UpdateCursorState() = 0;
  51. // Return true if the voice manager is allowed to show speaker labels
  52. // (mods usually return false when the scoreboard is up).
  53. virtual bool CanShowSpeakerLabels() = 0;
  54. };
  55. class CVoiceStatus /*: public vgui::CDefaultInputSignal*/
  56. {
  57. public:
  58. CVoiceStatus();
  59. virtual ~CVoiceStatus();
  60. // CHudBase overrides.
  61. public:
  62. // Initialize the cl_dll's voice manager.
  63. virtual int Init(
  64. IVoiceStatusHelper *m_pHelper,
  65. vgui::VPANEL pParentPanel);
  66. // ackPosition is the bottom position of where CVoiceStatus will draw the voice acknowledgement labels.
  67. virtual void VidInit();
  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. void UpdateSpeakerStatus(int entindex, bool bTalking);
  76. // Call from the HUD_CreateEntities function so it can add sprites above player heads.
  77. void DrawHeadLabels();
  78. void SetHeadLabelOffset( float offset );
  79. float GetHeadLabelOffset( void ) const;
  80. void SetHeadLabelsDisabled( bool bDisabled ) { m_bHeadLabelsDisabled = bDisabled; }
  81. // Called when the server registers a change to who this client can hear.
  82. void HandleVoiceMaskMsg(bf_read &msg);
  83. // The server sends this message initially to tell the client to send their state.
  84. void HandleReqStateMsg(bf_read &msg);
  85. // Squelch mode functions.
  86. public:
  87. // When you enter squelch mode, pass in
  88. void StartSquelchMode();
  89. void StopSquelchMode();
  90. bool IsInSquelchMode();
  91. // returns true if the target client has been banned
  92. // playerIndex is of range 1..maxplayers
  93. bool IsPlayerBlocked(int iPlayerIndex);
  94. // returns false if the player can't hear the other client due to game rules (eg. the other team)
  95. bool IsPlayerAudible(int iPlayerIndex);
  96. // returns true if the player is currently speaking
  97. bool IsPlayerSpeaking(int iPlayerIndex);
  98. // returns true if the local player is attempting to speak
  99. bool IsLocalPlayerSpeaking( void );
  100. // blocks the target client from being heard
  101. void SetPlayerBlockedState(int iPlayerIndex, bool blocked);
  102. void SetHeadLabelMaterial( const char *pszMaterial );
  103. IMaterial *GetHeadLabelMaterial( void ) { return m_pHeadLabelMaterial; }
  104. private:
  105. void UpdateServerState(bool bForce);
  106. // Update the button artwork to reflect the client's current state.
  107. void UpdateBanButton(int iClient);
  108. private:
  109. float m_LastUpdateServerState; // Last time we called this function.
  110. int m_bServerModEnable; // What we've sent to the server about our "voice_modenable" cvar.
  111. vgui::VPANEL m_pParentPanel;
  112. CPlayerBitVec m_VoicePlayers; // Who is currently talking. Indexed by client index.
  113. // This is the gamerules-defined list of players that you can hear. It is based on what teams people are on
  114. // and is totally separate from the ban list. Indexed by client index.
  115. CPlayerBitVec m_AudiblePlayers;
  116. // Players who have spoken at least once in the game so far
  117. CPlayerBitVec m_VoiceEnabledPlayers;
  118. // This is who the server THINKS we have banned (it can become incorrect when a new player arrives on the server).
  119. // It is checked periodically, and the server is told to squelch or unsquelch the appropriate players.
  120. CPlayerBitVec m_ServerBannedPlayers;
  121. IVoiceStatusHelper *m_pHelper; // Each mod provides an implementation of this.
  122. // Squelch mode stuff.
  123. bool m_bInSquelchMode;
  124. bool m_bTalking; // Set to true when the client thinks it's talking.
  125. bool m_bServerAcked; // Set to true when the server knows the client is talking.
  126. public:
  127. CVoiceBanMgr m_BanMgr; // Tracks which users we have squelched and don't want to hear.
  128. private:
  129. IMaterial *m_pHeadLabelMaterial; // For labels above players' heads.
  130. bool m_bBanMgrInitialized;
  131. int m_nControlSize;
  132. bool m_bHeadLabelsDisabled;
  133. #ifdef VOICE_VOX_ENABLE
  134. CountdownTimer m_bAboveThresholdTimer;
  135. #endif // VOICE_VOX_ENABLE
  136. };
  137. // Get the (global) voice manager.
  138. CVoiceStatus* GetClientVoiceMgr();
  139. void ClientVoiceMgr_Init();
  140. void ClientVoiceMgr_Shutdown();
  141. #endif // VOICE_STATUS_H