Skip to content

Commit 9b763a9

Browse files
committed
Patch for ID 0008734 + togglable
Nickname Autocomplete with the wish to make it togglable
1 parent ba2817f commit 9b763a9

File tree

9 files changed

+128
-2
lines changed

9 files changed

+128
-2
lines changed

MTA10/core/CChat.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ void CChat::LoadCVars ( void )
124124
CVARS_GET ( "chat_line_life", (unsigned int &)m_ulChatLineLife );
125125
CVARS_GET ( "chat_line_fade_out", (unsigned int &)m_ulChatLineFadeOut );
126126
CVARS_GET ( "chat_font", (unsigned int &)Font ); SetChatFont ( (eChatFont)Font );
127+
CVARS_GET ( "chat_autocomplete", m_bAutocomplete );
127128

128129
// Modify default chat box to be like 'Transparent' preset
129130
SString strFlags;
@@ -596,9 +597,104 @@ bool CChat::CharacterKeyHandler ( CGUIKeyEventArgs KeyboardArgs )
596597
m_fSmoothScrollResetTime = GetSecondCount ();
597598
break;
598599
}
600+
case VK_TAB:
601+
{
602+
603+
if ( m_bAutocomplete && m_strInputText.size () > 0 )
604+
{
605+
bool bSuccess = false;
606+
607+
SString strCurrentInput = GetInputText ();
608+
609+
std::vector<SString> vChatParts;
610+
strCurrentInput.Split ( " ", vChatParts );
611+
SString strPlayerNamePart = vChatParts.back ();
612+
if ( strPlayerNamePart.size () == 0 )
613+
break;
614+
615+
CModManager* pModManager = CModManager::GetSingletonPtr ();
616+
if ( pModManager && pModManager->GetCurrentMod () )
617+
{
618+
//Create vector and get playernames from deathmatch module
619+
std::vector<SString> vPlayerNames;
620+
pModManager->GetCurrentMod ()->GetPlayerNames ( vPlayerNames );
621+
622+
for ( std::vector<SString>::iterator iter = vPlayerNames.begin ();
623+
iter != vPlayerNames.end ();
624+
++iter )
625+
{
626+
SString strPlayerName = *iter;
627+
628+
// Check if there is another player after our last result
629+
if ( m_strLastPlayerName.size () != 0 )
630+
{
631+
if ( strPlayerName.CompareI ( m_strLastPlayerName ) ) {
632+
m_strLastPlayerName.clear ();
633+
if ( *iter == vPlayerNames.back () )
634+
{
635+
CharacterKeyHandler ( KeyboardArgs );
636+
return true;
637+
}
638+
}
639+
continue;
640+
}
641+
642+
// Already a part?
643+
if ( m_strLastPlayerNamePart.size () != 0 )
644+
{
645+
strPlayerNamePart = m_strLastPlayerNamePart;
646+
}
647+
648+
// Check namepart
649+
if ( !strPlayerName.BeginsWith ( strPlayerNamePart ) )
650+
continue;
651+
else
652+
{
653+
//Remove last part
654+
vChatParts.pop_back ();
655+
656+
//Turn back into string
657+
SString strTmp;
658+
for ( std::vector<SString>::iterator _iter = vChatParts.begin ();
659+
_iter != vChatParts.end ();
660+
_iter++ )
661+
{
662+
strTmp += *_iter + " ";
663+
}
664+
665+
//Check size if it's ok, then output
666+
SString strOutput = strTmp + strPlayerName;
667+
if ( MbUTF8ToUTF16 ( strOutput ).size () < CHAT_MAX_CHAT_LENGTH )
668+
{
669+
bSuccess = true;
670+
m_strLastPlayerNamePart = strPlayerNamePart;
671+
m_strLastPlayerName = strPlayerName;
672+
SetInputText ( strOutput );
673+
}
674+
675+
break;
676+
}
677+
}
678+
679+
// No success? Try again!
680+
if ( !bSuccess )
681+
m_strLastPlayerName.clear ();
682+
}
683+
684+
}
685+
break;
686+
}
599687

600688
default:
601689
{
690+
// Clear last namepart when pressing letter
691+
if (m_strLastPlayerNamePart.size() != 0)
692+
m_strLastPlayerNamePart.clear();
693+
694+
// Clear last name when pressing letter
695+
if (m_strLastPlayerName.size() != 0)
696+
m_strLastPlayerName.clear();
697+
602698
// If we haven't exceeded the maximum number of characters per chat message, append the char to the message and update the input control
603699
if ( MbUTF8ToUTF16(m_strInputText).size () < CHAT_MAX_CHAT_LENGTH )
604700
{

MTA10/core/CChat.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ class CChat
246246
float m_fSmoothScrollResetTime;
247247
float m_fSmoothRepeatTimer;
248248
CChatInputLine m_InputLine;
249+
SString m_strLastPlayerNamePart;
250+
SString m_strLastPlayerName;
249251

250252
CGUI* m_pManager;
251253
CGUIFont* m_pFont;
@@ -295,6 +297,8 @@ class CChat
295297
CVector2D m_RenderTargetChatSize;
296298
int m_iReportCount;
297299
CTickCount m_lastRenderTargetCreationFail;
300+
301+
bool m_bAutocomplete;
298302
};
299303

300304
#endif

MTA10/core/CClientVariables.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ void CClientVariables::LoadDefaults ( void )
285285
DEFAULT ( "chat_line_life", 12000 ); // chatbox line life time
286286
DEFAULT ( "chat_line_fade_out", 3000 ); // chatbox line fade out time
287287
DEFAULT ( "chat_use_cegui", false ); // chatbox uses cegui
288+
DEFAULT ( "chat_autocomplete", true ); // Enable autocomplete for nicknames in chatbox?
288289
DEFAULT ( "text_scale", 1.0f ); // text scale
289290
DEFAULT ( "invert_mouse", false ); // mouse inverting
290291
DEFAULT ( "fly_with_mouse", false ); // flying with mouse controls

MTA10/core/CSettings.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,11 @@ void CSettings::CreateGUI ( void )
11511151
m_pChatCssBackground->SetPosition ( CVector2D ( 10.0f, 350.0f ) );
11521152
m_pChatCssBackground->GetPosition ( vecTemp );
11531153
m_pChatCssBackground->AutoSize ( NULL, 20.0f );
1154+
1155+
m_pChatAutocomplete = reinterpret_cast < CGUICheckBox* > ( pManager->CreateCheckBox ( pTabInterface, _( "Nickname autocomplete with TAB" ) ) );
1156+
m_pChatAutocomplete->SetPosition ( CVector2D ( vecTemp.fX, vecTemp.fY + 20.0f ) );
1157+
m_pChatAutocomplete->GetPosition ( vecTemp );
1158+
m_pChatAutocomplete->AutoSize ( NULL, 20.0f );
11541159
}
11551160

11561161
/**
@@ -2976,6 +2981,7 @@ void CSettings::LoadData ( void )
29762981
CVARS_GET ( "chat_width", strVar ); m_pChatWidth->SetText ( strVar.c_str () );
29772982
CVARS_GET ( "chat_css_style_text", bVar ); m_pChatCssText->SetSelected ( bVar );
29782983
CVARS_GET ( "chat_css_style_background", bVar ); m_pChatCssBackground->SetSelected ( bVar );
2984+
CVARS_GET ( "chat_autocomplete", bVar ); m_pChatAutocomplete->SetSelected ( bVar );
29792985

29802986
{
29812987
int iVar;
@@ -3276,6 +3282,7 @@ void CSettings::SaveData ( void )
32763282
CVARS_SET ( "chat_width", m_pChatWidth->GetText () );
32773283
CVARS_SET ( "chat_css_style_text", m_pChatCssText->GetSelected () );
32783284
CVARS_SET ( "chat_css_style_background", m_pChatCssBackground->GetSelected () );
3285+
CVARS_SET ( "chat_autocomplete", m_pChatAutocomplete->GetSelected () );
32793286
CVARS_SET ( "chat_line_life", GetMilliseconds ( m_pChatLineLife ) );
32803287
CVARS_SET ( "chat_line_fade_out", GetMilliseconds ( m_pChatLineFadeout ) );
32813288

MTA10/core/CSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class CSettings
321321
CGUIEdit* m_pChatWidth;
322322

323323
CGUICheckBox* m_pChatCssBackground;
324+
CGUICheckBox* m_pChatAutocomplete;
324325
CGUICheckBox* m_pChatCssText;
325326
CGUIEdit* m_pChatLineLife;
326327
CGUIEdit* m_pChatLineFadeout;

MTA10/mods/deathmatch/CClient.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,18 @@ bool CClient::HandleException ( CExceptionInformation* pExceptionInformation )
297297
return true;
298298
#endif
299299
}
300+
301+
void CClient::GetPlayerNames ( std::vector<SString> &vPlayerNames )
302+
{
303+
if ( g_pClientGame ) {
304+
vPlayerNames.clear ();
305+
for ( std::vector<CClientPlayer*>::const_iterator iter = g_pClientGame->GetPlayerManager ()->IterBegin ();
306+
iter != g_pClientGame->GetPlayerManager ()->IterEnd ();
307+
++iter )
308+
{
309+
CClientPlayer* pClient = *iter;
310+
SString strPlayerName = pClient->GetNametagText ();
311+
vPlayerNames.push_back ( strPlayerName );
312+
}
313+
}
314+
};

MTA10/mods/deathmatch/CClient.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class CClient : public CClientBase
3737
//bool ProcessInput ( CInputMessage* pInputMessage );
3838

3939
bool HandleException ( CExceptionInformation* pExceptionInformation );
40+
void GetPlayerNames ( std::vector<SString> &vPlayerNames );
4041
};
4142

4243
#endif

MTA10/mods/shared_logic/CClientEntity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class CClientEntity : public CClientEntityBase
187187
};
188188
bool CanUpdateSync ( unsigned char ucRemote );
189189

190-
inline const char* GetName ( void ) { return m_strName; }
190+
inline SString GetName ( void ) { return m_strName; }
191191
inline void SetName ( const char* szName ) { m_strName.AssignLeft ( szName, MAX_ELEMENT_NAME_LENGTH ); }
192192

193193
inline const char* GetTypeName ( void ) { return m_strTypeName; };

MTA10/sdk/core/CClientBase.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CClientBase
3232
//virtual bool ProcessInput ( CInputMessage* pInputMessage ) = 0 *TODO*
3333

3434
virtual bool HandleException ( CExceptionInformation* pExceptionInformation ) = 0;
35+
virtual void GetPlayerNames ( std::vector<SString> &vPlayerNames ) = 0;
3536
};
3637

37-
#endif
38+
#endif

0 commit comments

Comments
 (0)