Advertisement
Audifire

Chatbox Nick Completation

Aug 28th, 2014
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 8.33 KB | None | 0 0
  1. Index: MTA10/core/CChat.cpp
  2. ===================================================================
  3. --- MTA10/core/CChat.cpp    (revision 6832)
  4. +++ MTA10/core/CChat.cpp    (working copy)
  5. @@ -596,9 +596,103 @@
  6.                  m_fSmoothScrollResetTime = GetSecondCount ();
  7.                  break;
  8.              }
  9. +            case VK_TAB:
  10. +            {
  11. +                if (m_strInputText.size() > 0)
  12. +                {
  13. +                    bool bSuccess = false;
  14. +
  15. +                    SString strCurrentInput = GetInputText();
  16. +
  17. +                    std::vector<SString> vChatParts;
  18. +                    strCurrentInput.Split( " ", vChatParts );
  19. +                    SString strPlayerNamePart = vChatParts.back( );
  20. +                    if (strPlayerNamePart.size() == 0)
  21. +                        break;
  22. +
  23. +                    CModManager* pModManager = CModManager::GetSingletonPtr();
  24. +                    if (pModManager && pModManager->GetCurrentMod( ))
  25. +                    {
  26. +                        //Create vector and get playernames from deathmatch module
  27. +                        std::vector<SString> vPlayerNames;
  28. +                        pModManager->GetCurrentMod( )->GetPlayerNames( vPlayerNames );
  29. +
  30. +                        for (std::vector<SString>::iterator iter = vPlayerNames.begin( );
  31. +                            iter != vPlayerNames.end( );
  32. +                                ++iter)
  33. +                        {
  34. +                            SString strPlayerName = *iter;
  35. +
  36. +                            // Check if there is another player after our last result
  37. +                            if (m_strLastPlayerName.size() != 0)
  38. +                            {
  39. +                                if (strPlayerName.CompareI( m_strLastPlayerName )) {
  40. +                                    m_strLastPlayerName.clear( );
  41. +                                    if (*iter == vPlayerNames.back( ))
  42. +                                    {
  43. +                                        CharacterKeyHandler( KeyboardArgs );
  44. +                                        return true;
  45. +                                    }
  46. +                                }
  47. +                                continue;
  48. +                            }
  49. +                            
  50. +                            // Already a part?
  51. +                            if (m_strLastPlayerNamePart.size( ) != 0)
  52. +                            {
  53. +                                strPlayerNamePart = m_strLastPlayerNamePart;
  54. +                            }
  55. +
  56. +                            // Check namepart
  57. +                            if (!strPlayerName.BeginsWith( strPlayerNamePart ))
  58. +                                continue;
  59. +                            else
  60. +                            {
  61. +                                //Remove last part
  62. +                                vChatParts.pop_back( );
  63. +
  64. +                                //Turn back into string
  65. +                                SString strTmp;
  66. +                                for (std::vector<SString>::iterator _iter = vChatParts.begin( );
  67. +                                    _iter != vChatParts.end( );
  68. +                                    _iter++)
  69. +                                {
  70. +                                    strTmp += *_iter + " ";
  71. +                                }
  72. +                                
  73. +                                //Check size if it's ok, then output
  74. +                                SString strOutput = strTmp + strPlayerName;
  75. +                                if (MbUTF8ToUTF16( strOutput ).size() < CHAT_MAX_CHAT_LENGTH)
  76. +                                {
  77. +                                    bSuccess = true;
  78. +                                    m_strLastPlayerNamePart = strPlayerNamePart;
  79. +                                    m_strLastPlayerName = strPlayerName;
  80. +                                    SetInputText( strOutput );
  81. +                                }
  82. +                                    
  83. +                                break;
  84. +                            }
  85. +                        }
  86. +
  87. +                        // No success? Try again!
  88. +                        if (!bSuccess)
  89. +                            m_strLastPlayerName.clear( );
  90. +                    }
  91. +                  
  92. +                }
  93. +                break;
  94. +            }
  95.              
  96.              default:
  97.              {
  98. +                // Clear last namepart when pressing letter
  99. +                if (m_strLastPlayerNamePart.size() != 0)
  100. +                    m_strLastPlayerNamePart.clear();
  101. +
  102. +                // Clear last name when pressing letter
  103. +                if (m_strLastPlayerName.size() != 0)
  104. +                    m_strLastPlayerName.clear();
  105. +
  106.                  // If we haven't exceeded the maximum number of characters per chat message, append the char to the message and update the input control
  107.                  if ( MbUTF8ToUTF16(m_strInputText).size () < CHAT_MAX_CHAT_LENGTH )
  108.                  {                    
  109. Index: MTA10/core/CChat.h
  110. ===================================================================
  111. --- MTA10/core/CChat.h  (revision 6832)
  112. +++ MTA10/core/CChat.h  (working copy)
  113. @@ -246,6 +246,8 @@
  114.      float                       m_fSmoothScrollResetTime;
  115.      float                       m_fSmoothRepeatTimer;
  116.      CChatInputLine              m_InputLine;
  117. +    SString                     m_strLastPlayerNamePart;
  118. +    SString                     m_strLastPlayerName;
  119.  
  120.      CGUI*                       m_pManager;
  121.      CGUIFont*                   m_pFont;
  122. Index: MTA10/mods/deathmatch/CClient.cpp
  123. ===================================================================
  124. --- MTA10/mods/deathmatch/CClient.cpp   (revision 6832)
  125. +++ MTA10/mods/deathmatch/CClient.cpp   (working copy)
  126. @@ -288,3 +288,18 @@
  127.          return true;
  128.      #endif
  129.  }
  130. +
  131. +void CClient::GetPlayerNames( std::vector<SString> &vPlayerNames )
  132. +{
  133. +    if (g_pClientGame) {
  134. +        vPlayerNames.clear( );
  135. +        for ( std::vector<CClientPlayer*>::const_iterator iter = g_pClientGame->GetPlayerManager( )->IterBegin( );
  136. +                iter != g_pClientGame->GetPlayerManager( )->IterEnd( );
  137. +                ++iter )
  138. +        {
  139. +            CClientPlayer* pClient = *iter;
  140. +            SString strPlayerName = pClient->GetNametagText( );
  141. +            vPlayerNames.push_back( strPlayerName );
  142. +        }
  143. +    }    
  144. +};
  145. \ No newline at end of file
  146. Index: MTA10/mods/deathmatch/CClient.h
  147. ===================================================================
  148. --- MTA10/mods/deathmatch/CClient.h (revision 6832)
  149. +++ MTA10/mods/deathmatch/CClient.h (working copy)
  150. @@ -35,6 +35,7 @@
  151.      //bool        ProcessInput                    ( CInputMessage* pInputMessage );
  152.  
  153.      bool        HandleException                 ( CExceptionInformation* pExceptionInformation );
  154. +    void        GetPlayerNames                  ( std::vector<SString> &vPlayerNames );
  155.  };
  156.  
  157.  #endif
  158. \ No newline at end of file
  159. Index: MTA10/mods/shared_logic/CClientEntity.h
  160. ===================================================================
  161. --- MTA10/mods/shared_logic/CClientEntity.h (revision 6832)
  162. +++ MTA10/mods/shared_logic/CClientEntity.h (working copy)
  163. @@ -183,7 +183,7 @@
  164.      };
  165.      bool                                        CanUpdateSync           ( unsigned char ucRemote );
  166.  
  167. -    inline const char*                          GetName                 ( void )                    { return m_strName; }
  168. +    inline SString                              GetName                 ( void )                    { return m_strName; }
  169.      inline void                                 SetName                 ( const char* szName )      { m_strName.AssignLeft ( szName, MAX_ELEMENT_NAME_LENGTH ); }
  170.  
  171.      inline const char*                          GetTypeName             ( void )                    { return m_strTypeName; };
  172. Index: MTA10/sdk/core/CClientBase.h
  173. ===================================================================
  174. --- MTA10/sdk/core/CClientBase.h    (revision 6832)
  175. +++ MTA10/sdk/core/CClientBase.h    (working copy)
  176. @@ -30,6 +30,7 @@
  177.      //virtual bool    ProcessInput                ( CInputMessage* pInputMessage ) = 0  *TODO*
  178.  
  179.      virtual bool    HandleException             ( CExceptionInformation* pExceptionInformation ) = 0;
  180. +    virtual void    GetPlayerNames              ( std::vector<SString> &vPlayerNames ) = 0;
  181.  };
  182.  
  183.  #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement