2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
# ifndef GAME_CLIENT_COMPONENTS_CHAT_H
# define GAME_CLIENT_COMPONENTS_CHAT_H
2020-10-13 20:08:52 +00:00
# include <engine/shared/config.h>
2011-03-20 15:17:06 +00:00
# include <engine/shared/ringbuffer.h>
2010-05-29 07:25:38 +00:00
# include <game/client/component.h>
# include <game/client/lineinput.h>
2021-07-12 09:29:59 +00:00
# include <game/client/skin.h>
2010-05-29 07:25:38 +00:00
class CChat : public CComponent
{
CLineInput m_Input ;
2011-04-13 18:37:12 +00:00
2020-10-30 18:51:59 +00:00
static constexpr float CHAT_WIDTH = 200.0f ;
static constexpr float CHAT_HEIGHT_FULL = 200.0f ;
static constexpr float CHAT_HEIGHT_MIN = 50.0f ;
2020-10-13 20:08:52 +00:00
2011-04-13 18:37:12 +00:00
enum
2010-05-29 07:25:38 +00:00
{
2020-10-13 20:08:52 +00:00
MAX_LINES = 25
2010-05-29 07:25:38 +00:00
} ;
struct CLine
{
2021-06-23 05:05:49 +00:00
int64_t m_Time ;
2020-11-01 03:48:10 +00:00
float m_YOffset [ 2 ] ;
2011-02-12 10:40:36 +00:00
int m_ClientID ;
2021-03-08 00:08:38 +00:00
bool m_Team ;
bool m_Whisper ;
2010-05-29 07:25:38 +00:00
int m_NameColor ;
char m_aName [ 64 ] ;
char m_aText [ 512 ] ;
2017-03-10 17:49:39 +00:00
bool m_Friend ;
2010-12-16 01:31:12 +00:00
bool m_Highlighted ;
2018-03-13 20:50:49 +00:00
int m_TextContainerIndex ;
2020-10-13 20:08:52 +00:00
int m_QuadContainerIndex ;
char m_aSkinName [ sizeof ( g_Config . m_ClPlayerSkin ) / sizeof ( g_Config . m_ClPlayerSkin [ 0 ] ) ] ;
CSkin : : SSkinTextures m_RenderSkin ;
2020-11-08 05:39:16 +00:00
CSkin : : SSkinMetrics m_RenderSkinMetrics ;
2020-10-13 20:08:52 +00:00
bool m_CustomColoredSkin ;
ColorRGBA m_ColorBody ;
ColorRGBA m_ColorFeet ;
bool m_HasRenderTee ;
2018-03-13 20:50:49 +00:00
float m_TextYOffset ;
2020-09-20 15:25:27 +00:00
int m_TimesRepeated ;
2010-05-29 07:25:38 +00:00
} ;
2020-11-01 03:48:10 +00:00
bool m_PrevScoreBoardShowed ;
2018-03-13 20:50:49 +00:00
bool m_PrevShowChat ;
2010-05-29 07:25:38 +00:00
CLine m_aLines [ MAX_LINES ] ;
int m_CurrentLine ;
// chat
enum
{
2020-09-22 16:02:03 +00:00
MODE_NONE = 0 ,
2010-05-29 07:25:38 +00:00
MODE_ALL ,
MODE_TEAM ,
2012-01-06 18:47:49 +00:00
2020-09-22 16:02:03 +00:00
CHAT_SERVER = 0 ,
2012-01-06 18:47:49 +00:00
CHAT_HIGHLIGHT ,
CHAT_CLIENT ,
CHAT_NUM ,
2010-05-29 07:25:38 +00:00
} ;
int m_Mode ;
2010-05-30 12:01:11 +00:00
bool m_Show ;
2010-10-11 00:29:30 +00:00
bool m_InputUpdate ;
int m_ChatStringOffset ;
2010-10-11 10:31:45 +00:00
int m_OldChatStringLength ;
2021-09-14 11:15:09 +00:00
bool m_CompletionUsed ;
2010-12-16 01:31:12 +00:00
int m_CompletionChosen ;
char m_aCompletionBuffer [ 256 ] ;
int m_PlaceholderOffset ;
int m_PlaceholderLength ;
2014-10-06 11:02:55 +00:00
2019-03-19 09:26:30 +00:00
struct CCommand
{
const char * pName ;
const char * pParams ;
2020-09-22 16:02:03 +00:00
bool operator < ( const CCommand & Other ) const { return str_comp ( pName , Other . pName ) < 0 ; }
bool operator < = ( const CCommand & Other ) const { return str_comp ( pName , Other . pName ) < = 0 ; }
bool operator = = ( const CCommand & Other ) const { return str_comp ( pName , Other . pName ) = = 0 ; }
2019-03-19 09:26:30 +00:00
} ;
sorted_array < CCommand > m_Commands ;
2014-10-06 11:02:55 +00:00
bool m_ReverseTAB ;
2012-01-09 22:13:51 +00:00
struct CHistoryEntry
{
int m_Team ;
char m_aText [ 1 ] ;
} ;
CHistoryEntry * m_pHistoryEntry ;
2020-10-27 17:57:14 +00:00
CStaticRingBuffer < CHistoryEntry , 64 * 1024 , CRingBufferBase : : FLAG_RECYCLE > m_History ;
2012-01-09 22:13:51 +00:00
int m_PendingChatCounter ;
2021-06-23 05:05:49 +00:00
int64_t m_LastChatSend ;
int64_t m_aLastSoundPlayed [ CHAT_NUM ] ;
2011-04-13 18:37:12 +00:00
2010-05-29 07:25:38 +00:00
static void ConSay ( IConsole : : IResult * pResult , void * pUserData ) ;
static void ConSayTeam ( IConsole : : IResult * pResult , void * pUserData ) ;
static void ConChat ( IConsole : : IResult * pResult , void * pUserData ) ;
2010-05-30 12:01:11 +00:00
static void ConShowChat ( IConsole : : IResult * pResult , void * pUserData ) ;
2017-01-05 23:17:41 +00:00
static void ConEcho ( IConsole : : IResult * pResult , void * pUserData ) ;
2011-04-13 18:37:12 +00:00
2020-12-22 18:24:48 +00:00
static void ConchainChatOld ( IConsole : : IResult * pResult , void * pUserData , IConsole : : FCommandCallback pfnCallback , void * pCallbackUserData ) ;
2020-10-13 20:08:52 +00:00
2015-07-22 13:37:00 +00:00
bool LineShouldHighlight ( const char * pLine , const char * pName ) ;
2020-06-20 13:55:52 +00:00
void StoreSave ( const char * pText ) ;
2020-07-07 09:57:57 +00:00
void Reset ( ) ;
2015-07-22 13:37:00 +00:00
2010-05-29 07:25:38 +00:00
public :
CChat ( ) ;
2020-10-29 00:55:01 +00:00
static constexpr float MESSAGE_PADDING_X = 5.0f ;
2020-10-30 19:18:47 +00:00
static constexpr float MESSAGE_TEE_SIZE = 7.0f ;
2020-10-29 00:55:01 +00:00
static constexpr float MESSAGE_TEE_PADDING_RIGHT = 0.5f ;
static constexpr float FONT_SIZE = 6.0f ;
2020-10-30 19:18:47 +00:00
static constexpr float MESSAGE_PADDING_Y = 1.0f ;
static constexpr float MESSAGE_ROUNDING = 3.0f ;
static_assert ( FONT_SIZE + MESSAGE_PADDING_Y > = MESSAGE_ROUNDING * 2.0f , " Corners for background chat are too huge for this combination of font size and message padding. " ) ;
2020-10-29 00:55:01 +00:00
2010-05-29 07:25:38 +00:00
bool IsActive ( ) const { return m_Mode ! = MODE_NONE ; }
2011-02-12 10:40:36 +00:00
void AddLine ( int ClientID , int Team , const char * pLine ) ;
2010-05-29 07:25:38 +00:00
void EnableMode ( int Team ) ;
2020-09-22 16:01:13 +00:00
void DisableMode ( ) ;
2010-05-29 07:25:38 +00:00
void Say ( int Team , const char * pLine ) ;
2015-08-25 12:24:46 +00:00
void SayChat ( const char * pLine ) ;
2019-03-19 09:26:30 +00:00
void RegisterCommand ( const char * pName , const char * pParams , int flags , const char * pHelp ) ;
2019-06-05 17:17:55 +00:00
void Echo ( const char * pString ) ;
2015-08-25 12:24:46 +00:00
2018-03-21 14:53:29 +00:00
virtual void OnWindowResize ( ) ;
2010-05-29 07:25:38 +00:00
virtual void OnConsoleInit ( ) ;
virtual void OnStateChange ( int NewState , int OldState ) ;
virtual void OnRender ( ) ;
2020-10-13 20:08:52 +00:00
virtual void RefindSkins ( ) ;
2018-03-13 20:50:49 +00:00
virtual void OnPrepareLines ( ) ;
2010-09-12 10:43:03 +00:00
virtual void OnRelease ( ) ;
2010-05-29 07:25:38 +00:00
virtual void OnMessage ( int MsgType , void * pRawMsg ) ;
virtual bool OnInput ( IInput : : CEvent Event ) ;
2020-10-13 20:08:52 +00:00
void RebuildChat ( ) ;
2010-05-29 07:25:38 +00:00
} ;
# endif