@@ -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 {
0 commit comments