@@ -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,94 @@ 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+ size_t iFound;
609+ iFound = strCurrentInput.find_last_of ( " " );
610+ if ( iFound == std::string::npos )
611+ iFound = 0 ;
612+ else
613+ ++iFound;
614+
615+ SString strPlayerNamePart = strCurrentInput.substr ( iFound );
616+
617+ CModManager* pModManager = CModManager::GetSingletonPtr ();
618+ if ( pModManager && pModManager->GetCurrentMod () )
619+ {
620+ // Create vector and get playernames from deathmatch module
621+ std::vector<SString> vPlayerNames;
622+ pModManager->GetCurrentMod ()->GetPlayerNames ( vPlayerNames );
623+
624+ for ( std::vector<SString>::iterator iter = vPlayerNames.begin ();
625+ iter != vPlayerNames.end ();
626+ ++iter )
627+ {
628+ SString strPlayerName = *iter;
629+
630+ // Check if there is another player after our last result
631+ if ( m_strLastPlayerName.size () != 0 )
632+ {
633+ if ( strPlayerName.CompareI ( m_strLastPlayerName ) ) {
634+ m_strLastPlayerName.clear ();
635+ if ( *iter == vPlayerNames.back () )
636+ {
637+ CharacterKeyHandler ( KeyboardArgs );
638+ return true ;
639+ }
640+ }
641+ continue ;
642+ }
643+
644+ // Already a part?
645+ if ( m_strLastPlayerNamePart.size () != 0 )
646+ {
647+ strPlayerNamePart = m_strLastPlayerNamePart;
648+ }
649+
650+ // Check namepart
651+ if ( !strPlayerName.BeginsWith ( strPlayerNamePart ) )
652+ continue ;
653+ else
654+ {
655+ // Check size if it's ok, then output
656+ SString strOutput = strCurrentInput.replace ( iFound, std::string::npos, strPlayerName );
657+ if ( MbUTF8ToUTF16 ( strOutput ).size () < CHAT_MAX_CHAT_LENGTH )
658+ {
659+ bSuccess = true ;
660+ m_strLastPlayerNamePart = strPlayerNamePart;
661+ m_strLastPlayerName = strPlayerName;
662+ SetInputText ( strOutput );
663+ }
664+
665+ break ;
666+ }
667+ }
668+
669+ // No success? Try again!
670+ if ( !bSuccess )
671+ m_strLastPlayerName.clear ();
672+ }
673+
674+ }
675+ break ;
676+ }
599677
600678 default :
601679 {
680+ // Clear last namepart when pressing letter
681+ if (m_strLastPlayerNamePart.size () != 0 )
682+ m_strLastPlayerNamePart.clear ();
683+
684+ // Clear last name when pressing letter
685+ if (m_strLastPlayerName.size () != 0 )
686+ m_strLastPlayerName.clear ();
687+
602688 // If we haven't exceeded the maximum number of characters per chat message, append the char to the message and update the input control
603689 if ( MbUTF8ToUTF16 (m_strInputText).size () < CHAT_MAX_CHAT_LENGTH )
604690 {
0 commit comments