Skip to content

Commit 2b4f8ed

Browse files
authored
Merge pull request ReactiveDrop#1047 from anf3is/rf/chat-h-to-cpp
Refactor basechat: remove trailing whitespace and move method definitions to .cpp
2 parents 153348e + 46efb3e commit 2b4f8ed

2 files changed

Lines changed: 114 additions & 108 deletions

File tree

src/game/client/hud_basechat.cpp

Lines changed: 100 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Color g_ColorGrey( 204, 204, 204, 255 );
5555
Color g_ColorPurple( 160, 115, 205, 255 );
5656

5757
static const char *gBugPriorityTable[] = {
58-
"TODAY",
59-
"ASAP",
58+
"TODAY",
59+
"ASAP",
6060
"NONE",
6161
NULL
6262
};
@@ -65,7 +65,7 @@ static const char *gBugTokenTable[] = {
6565
"re", "regression",
6666
"today", "showstopper",
6767
"asap", "showstopper",
68-
"ss", "showstopper",
68+
"ss", "showstopper",
6969
"show", "showstopper",
7070
// "high", "high",
7171
"med", "medium",
@@ -210,15 +210,15 @@ static CUtlLinkedList<const char *> *ParseTokens(char *szString)
210210
CUtlLinkedList<const char *> *tokens = new CUtlLinkedList<const char *>();
211211
// ensure that the defaults are reset
212212
// later tokens should override these values
213-
tokens->AddToHead("NONE");
214-
tokens->AddToHead("High");
215-
tokens->AddToHead("triage");
213+
tokens->AddToHead("NONE");
214+
tokens->AddToHead("High");
215+
tokens->AddToHead("triage");
216216

217217
char *pEnd = szString + V_strlen(szString) - 1;
218218
while ( pEnd >= szString && (*pEnd == ')' || *pEnd == ' ') )
219219
{
220220
if (*pEnd == ')')
221-
{
221+
{
222222
char *pToken = NULL;
223223

224224
// skip any spaces
@@ -233,7 +233,7 @@ static CUtlLinkedList<const char *> *ParseTokens(char *szString)
233233
// skip back to the open paren (if there is one)
234234
char *pStart = pEnd;
235235
while (pStart > szString && *pStart != '(') pStart--;
236-
if (pStart >= szString)
236+
if (pStart >= szString)
237237
{
238238
*pStart = '\0';
239239
pToken = pStart+1;
@@ -292,7 +292,7 @@ wchar_t* ReadChatTextString( bf_read &msg, wchar_t *pOut, int outSize, bool stri
292292
// Input : *parent -
293293
// *panelName -
294294
//-----------------------------------------------------------------------------
295-
CBaseHudChatLine::CBaseHudChatLine( vgui::Panel *parent, const char *panelName ) :
295+
CBaseHudChatLine::CBaseHudChatLine( vgui::Panel *parent, const char *panelName ) :
296296
vgui::MultiFontRichText( parent, panelName )
297297
{
298298
m_hFont = m_hFontMarlett = 0;
@@ -358,7 +358,7 @@ void CBaseHudChatLine::PerformFadeout( void )
358358
r = r + ( 255 - r ) * frac;
359359
g = g + ( 255 - g ) * frac;
360360
b = b + ( 255 - b ) * frac;
361-
361+
362362
// Draw a right facing triangle in red, faded out over time
363363
int alpha = 63 + 192 * (1.0f - frac1 );
364364
alpha = clamp( alpha, 0, 255 );
@@ -460,11 +460,11 @@ void CBaseHudChatLine::Expire( void )
460460
//-----------------------------------------------------------------------------
461461
// Purpose: The prompt and text entry area for chat messages
462462
//-----------------------------------------------------------------------------
463-
CBaseHudChatInputLine::CBaseHudChatInputLine( CBaseHudChat *parent, char const *panelName ) :
463+
CBaseHudChatInputLine::CBaseHudChatInputLine( CBaseHudChat *parent, char const *panelName ) :
464464
vgui::Panel( parent, panelName )
465465
{
466466
m_pPrompt = new vgui::Label( this, "ChatInputPrompt", L"Enter text:" );
467-
m_pInput = new CBaseHudChatEntry( this, "ChatInput", parent );
467+
m_pInput = new CBaseHudChatEntry( this, "ChatInput", parent );
468468
m_pInput->SetMaximumCharCount( 127 );
469469
// Send converts text to utf-8
470470
m_pInput->m_iMaxByteCount = 127;
@@ -473,7 +473,7 @@ CBaseHudChatInputLine::CBaseHudChatInputLine( CBaseHudChat *parent, char const *
473473
void CBaseHudChatInputLine::ApplySchemeSettings(vgui::IScheme *pScheme)
474474
{
475475
BaseClass::ApplySchemeSettings(pScheme);
476-
476+
477477
// FIXME: Outline
478478
vgui::HFont hFont = pScheme->GetFont( "ChatFont" );
479479

@@ -527,7 +527,7 @@ void CBaseHudChatInputLine::PerformLayout()
527527
GetSize( wide, tall );
528528

529529
int w,h;
530-
m_pPrompt->GetContentSize( w, h);
530+
m_pPrompt->GetContentSize( w, h);
531531
m_pPrompt->SetBounds( 0, 0, w, tall );
532532

533533
m_pInput->SetBounds( w + 2, 0, wide - w - 2 , tall );
@@ -538,12 +538,12 @@ vgui::Panel *CBaseHudChatInputLine::GetInputPanel( void )
538538
return m_pInput;
539539
}
540540

541-
CHudChatFilterButton::CHudChatFilterButton( vgui::Panel *pParent, const char *pName, const char *pText ) :
541+
CHudChatFilterButton::CHudChatFilterButton( vgui::Panel *pParent, const char *pName, const char *pText ) :
542542
BaseClass( pParent, pName, pText )
543543
{
544544
}
545545

546-
CHudChatFilterCheckButton::CHudChatFilterCheckButton( vgui::Panel *pParent, const char *pName, const char *pText, int iFlag ) :
546+
CHudChatFilterCheckButton::CHudChatFilterCheckButton( vgui::Panel *pParent, const char *pName, const char *pText, int iFlag ) :
547547
BaseClass( pParent, pName, pText )
548548
{
549549
m_iFlag = iFlag;
@@ -793,7 +793,7 @@ void CBaseHudChat::CreateChatInputLine( void )
793793
void CBaseHudChat::CreateChatLines( void )
794794
{
795795
m_ChatLine = new CBaseHudChatLine( this, "ChatLine1" );
796-
m_ChatLine->SetVisible( false );
796+
m_ChatLine->SetVisible( false );
797797
}
798798

799799

@@ -902,7 +902,7 @@ void CBaseHudChat::MsgFunc_SayText( bf_read &msg )
902902

903903
int CBaseHudChat::GetFilterForString( const char *pString )
904904
{
905-
if ( !Q_stricmp( pString, "#HL_Name_Change" ) )
905+
if ( !Q_stricmp( pString, "#HL_Name_Change" ) )
906906
{
907907
return CHAT_FILTER_NAMECHANGE;
908908
}
@@ -1109,7 +1109,7 @@ void CBaseHudChat::MsgFunc_VoiceSubtitle( bf_read &msg )
11091109

11101110
const wchar_t *pVoicePrefix = g_pVGuiLocalize->Find( "#Voice" );
11111111
g_pVGuiLocalize->ConvertUnicodeToANSI( pVoicePrefix, szPrefix, sizeof(szPrefix) );
1112-
1112+
11131113
ChatPrintf( client, CHAT_FILTER_NONE, "%c(%s) %s%c: %s", COLOR_PLAYERNAME, szPrefix, GetDisplayedSubtitlePlayerName( client ), COLOR_NORMAL, ConvertCRtoNL( szString ) );
11141114

11151115
SetVoiceSubtitleState( false );
@@ -1274,15 +1274,15 @@ void CBaseHudChat::Printf( int iFilter, const char *fmt, ... )
12741274
//-----------------------------------------------------------------------------
12751275
void CBaseHudChat::StartMessageMode( int iMessageModeType )
12761276
{
1277-
// reactivedrop: #iss-nohud-hanging if asw_draw_hud is 0 we don't
1278-
// show chat input box, because this leads to input being stuck and
1277+
// reactivedrop: #iss-nohud-hanging if asw_draw_hud is 0 we don't
1278+
// show chat input box, because this leads to input being stuck and
12791279
// inability of client to open Esc menu or console
12801280
#ifdef INFESTED_DLL
12811281
extern ConVar asw_draw_hud;
12821282
if (!asw_draw_hud.GetBool())
12831283
return;
12841284
#endif // INFESTED_DLL
1285-
1285+
12861286
m_nMessageMode = iMessageModeType;
12871287
cl_chat_active.SetValue( m_nMessageMode );
12881288

@@ -1292,7 +1292,7 @@ void CBaseHudChat::StartMessageMode( int iMessageModeType )
12921292

12931293
m_pChatInput->ClearEntry();
12941294
SetChatPrompt( iMessageModeType );
1295-
1295+
12961296
if ( GetChatHistory() )
12971297
{
12981298
// TERROR: hack to get ChatFont back
@@ -1312,7 +1312,7 @@ void CBaseHudChat::StartMessageMode( int iMessageModeType )
13121312
SetMouseInputEnabled( true );
13131313
m_pChatInput->SetVisible( true );
13141314
vgui::surface()->CalculateMouseVisible();
1315-
m_pChatInput->SetPaintBorderEnabled( true );
1315+
m_pChatInput->SetPaintBorderEnabled( true );
13161316
m_pChatInput->RequestFocus();
13171317

13181318
#ifndef INFESTED_DLL
@@ -1354,7 +1354,7 @@ void CBaseHudChat::StopMessageMode( bool bFade )
13541354
{
13551355
SetKeyBoardInputEnabled( false );
13561356
SetMouseInputEnabled( false );
1357-
1357+
13581358
if ( GetChatHistory() )
13591359
{
13601360
GetChatHistory()->SetPaintBorderEnabled( false );
@@ -1394,7 +1394,7 @@ void CBaseHudChat::FadeChatHistory( void )
13941394
{
13951395
return;
13961396
}
1397-
1397+
13981398
float frac = ( m_flHistoryFadeTime - gpGlobals->curtime ) * CHAT_HISTORY_ONE_OVER_FADE_TIME;
13991399
int alpha = frac * CHAT_HISTORY_ALPHA;
14001400
alpha = clamp( alpha, 0, CHAT_HISTORY_ALPHA );
@@ -1451,7 +1451,7 @@ Color CBaseHudChat::GetTextColorForClient( TextColor colorNum, int clientIndex )
14511451

14521452
case COLOR_ACHIEVEMENT:
14531453
{
1454-
vgui::IScheme *pSourceScheme = vgui::scheme()->GetIScheme( vgui::scheme()->GetScheme( "SourceScheme" ) );
1454+
vgui::IScheme *pSourceScheme = vgui::scheme()->GetIScheme( vgui::scheme()->GetScheme( "SourceScheme" ) );
14551455
if ( pSourceScheme )
14561456
{
14571457
c = pSourceScheme->GetColor( "SteamLightGreen", GetBgColor() );
@@ -1512,7 +1512,7 @@ int CBaseHudChatLine::TranslateChannelRange(byte inputval)
15121512

15131513
//pass float modifier into range 0 - 255
15141514
outputMod *= 255.0f;
1515-
1515+
15161516
return outputMod;
15171517
}
15181518

@@ -1584,9 +1584,9 @@ void CBaseHudChatLine::InsertAndColorizeText( wchar_t *buf, int clientIndex )
15841584
endIndexPos = diffResult;
15851585
}
15861586

1587-
15881587

1589-
1588+
1589+
15901590
if (endIndexPos > 0)
15911591
{
15921592
// save this start
@@ -2192,7 +2192,7 @@ void CBaseHudChatLine::Colorize( int alpha )
21922192
CBaseHudChat *pChat = dynamic_cast<CBaseHudChat*>(GetParent() );
21932193

21942194
if ( pChat && pChat->GetChatHistory() )
2195-
{
2195+
{
21962196
pChat->GetChatHistory()->InsertString( "\n" );
21972197
}
21982198

@@ -2218,7 +2218,7 @@ void CBaseHudChatLine::Colorize( int alpha )
22182218
ConColorMsg( color, "%s", szText );
22192219

22202220
if ( pChat && pChat->GetChatHistory() )
2221-
{
2221+
{
22222222
pChat->GetChatHistory()->InsertColorChange( color );
22232223
pChat->GetChatHistory()->InsertFontChange( m_hFont );
22242224
pChat->GetChatHistory()->InsertString( wText );
@@ -2257,7 +2257,7 @@ void CBaseHudChat::Send( void )
22572257

22582258
wchar_t szTextbuf[1024];
22592259
m_pChatInput->GetMessageText( szTextbuf, sizeof( szTextbuf ) );
2260-
2260+
22612261
char ansi[1024];
22622262
g_pVGuiLocalize->ConvertUnicodeToANSI( szTextbuf, ansi, sizeof( ansi ) );
22632263
int len = Q_strlen(ansi);
@@ -2276,7 +2276,7 @@ void CBaseHudChat::Send( void )
22762276

22772277
engine->ClientCmd_Unrestricted(szbuf);
22782278
}
2279-
2279+
22802280
m_pChatInput->ClearEntry();
22812281
m_nMessageMode = MM_NONE; // TERROR
22822282
cl_chat_active.SetValue( m_nMessageMode );
@@ -2461,12 +2461,12 @@ void CBaseHudChat::ChatPrintf( int iPlayerIndex, int iFilter, const char *fmt, .
24612461
if ( iPlayerIndex == 0 )
24622462
{
24632463
Q_memset( &sPlayerInfo, 0, sizeof(player_info_t) );
2464-
Q_strncpy( sPlayerInfo.name, "Console", sizeof(sPlayerInfo.name) );
2464+
Q_strncpy( sPlayerInfo.name, "Console", sizeof(sPlayerInfo.name) );
24652465
}
24662466
else
24672467
{
24682468
engine->GetPlayerInfo( iPlayerIndex, &sPlayerInfo );
2469-
}
2469+
}
24702470

24712471
int bufSize = (strlen( pmsg ) + 1 ) * sizeof(wchar_t);
24722472
wchar_t *wbuf = static_cast<wchar_t *>( _alloca( bufSize ) );
@@ -2517,11 +2517,45 @@ void CBaseHudChat::FireGameEvent( IGameEvent *event )
25172517

25182518
if ( !player )
25192519
return;
2520-
2520+
25212521
ChatPrintf( player->entindex(), CHAT_FILTER_NONE, "(SourceTV) %s", event->GetString( "text" ) );
25222522
}
25232523
}
25242524

2525+
void CBaseHudChat::OnKeyCodeTyped(vgui::KeyCode code)
2526+
{
2527+
if (code == KEY_ENTER || code == KEY_PAD_ENTER || code == KEY_ESCAPE)
2528+
{
2529+
if (code != KEY_ESCAPE)
2530+
{
2531+
Send();
2532+
}
2533+
2534+
// End message mode.
2535+
StopMessageMode();
2536+
}
2537+
else
2538+
{
2539+
BaseClass::OnKeyCodeTyped(code);
2540+
}
2541+
}
2542+
2543+
CBaseHudChatEntry::CBaseHudChatEntry( vgui::Panel *parent, char const *panelName, CBaseHudChat *pChat )
2544+
: BaseClass( parent, panelName )
2545+
{
2546+
SetCatchEnterKey( true );
2547+
SetAllowNonAsciiCharacters( true );
2548+
SetDrawLanguageIDAtLeft( true );
2549+
m_pHudChat = pChat;
2550+
}
2551+
2552+
void CBaseHudChatEntry::ApplySchemeSettings( vgui::IScheme *pScheme )
2553+
{
2554+
BaseClass::ApplySchemeSettings(pScheme);
2555+
2556+
SetPaintBorderEnabled( false );
2557+
}
2558+
25252559
// Prevent player from inserting text over utf-8 byte limit
25262560
void CBaseHudChatEntry::InsertChar(wchar_t ch)
25272561
{
@@ -2577,3 +2611,32 @@ void CBaseHudChatEntry::InsertChar(wchar_t ch)
25772611

25782612
return; // do not insert anything
25792613
}
2614+
2615+
void CBaseHudChatEntry::OnKeyCodeTyped(vgui::KeyCode code)
2616+
{
2617+
if ( code == KEY_ENTER || code == KEY_PAD_ENTER || code == KEY_ESCAPE )
2618+
{
2619+
if ( code != KEY_ESCAPE )
2620+
{
2621+
if ( m_pHudChat )
2622+
{
2623+
m_pHudChat->Send();
2624+
}
2625+
}
2626+
2627+
// End message mode.
2628+
if ( m_pHudChat )
2629+
{
2630+
m_pHudChat->StopMessageMode();
2631+
}
2632+
}
2633+
else if ( code == KEY_TAB )
2634+
{
2635+
// Ignore tab, otherwise vgui will screw up the focus.
2636+
return;
2637+
}
2638+
else
2639+
{
2640+
BaseClass::OnKeyCodeTyped( code );
2641+
}
2642+
}

0 commit comments

Comments
 (0)