Fix nick completion
authorPilzAdam <pilzadam@minetest.net>
Mon, 25 Mar 2013 18:13:25 +0000 (19:13 +0100)
committerPilzAdam <pilzadam@minetest.net>
Fri, 5 Apr 2013 00:31:58 +0000 (02:31 +0200)
src/chat.cpp
src/chat.h
src/client.cpp
src/client.h
src/content_cao.cpp
src/environment.h
src/guiChatConsole.cpp

index 1135ccdf7486be295043e659a1d0685edcd241ea..3102e194a0851d5c48f840c08ee141fac1ad464b 100644 (file)
@@ -464,7 +464,7 @@ void ChatPrompt::historyNext()
        }
 }
 
-void ChatPrompt::nickCompletion(const std::list<std::wstring>& names, bool backwards)
+void ChatPrompt::nickCompletion(const std::list<std::string>& names, bool backwards)
 {
        // Two cases:
        // (a) m_nick_completion_start == m_nick_completion_end == 0
@@ -493,13 +493,13 @@ void ChatPrompt::nickCompletion(const std::list<std::wstring>& names, bool backw
 
        // find all names that start with the selected prefix
        std::vector<std::wstring> completions;
-       for (std::list<std::wstring>::const_iterator
+       for (std::list<std::string>::const_iterator
                        i = names.begin();
                        i != names.end(); ++i)
        {
-               if (str_starts_with(*i, prefix, true))
+               if (str_starts_with(narrow_to_wide(*i), prefix, true))
                {
-                       std::wstring completion = *i;
+                       std::wstring completion = narrow_to_wide(*i);
                        if (prefix_start == 0)
                                completion += L":";
                        completions.push_back(completion);
index 8a40c7ccf58c37840249f004ddd2166c155132ef..19b48456ec7dd013b1c2aba40fdde360488ef360 100644 (file)
@@ -160,7 +160,7 @@ public:
        void historyNext();
 
        // Nick completion
-       void nickCompletion(const std::list<std::wstring>& names, bool backwards);
+       void nickCompletion(const std::list<std::string>& names, bool backwards);
 
        // Update console size and reformat the visible portion of the prompt
        void reformat(u32 cols);
index f27f95d98c2d939d7c8e010e28344f78ec67e90f..1d5f8f472ee25f124161a07eb1a45833d67a6466 100644 (file)
@@ -2501,18 +2501,9 @@ void Client::printDebugInfo(std::ostream &os)
                <<std::endl;*/
 }
 
-std::list<std::wstring> Client::getConnectedPlayerNames()
+std::list<std::string> Client::getConnectedPlayerNames()
 {
-       std::list<Player*> players = m_env.getPlayers(true);
-       std::list<std::wstring> playerNames;
-       for(std::list<Player*>::iterator
-                       i = players.begin();
-                       i != players.end(); ++i)
-       {
-               Player *player = *i;
-               playerNames.push_back(narrow_to_wide(player->getName()));
-       }
-       return playerNames;
+       return m_env.getPlayerNames();
 }
 
 float Client::getAnimationTime()
index d476a1d5189b7174ab9e93f6fc3b5835c0dffd85..16cdc237f4bd20e64b7f274090bed8f705132398 100644 (file)
@@ -315,7 +315,7 @@ public:
        // Prints a line or two of info
        void printDebugInfo(std::ostream &os);
 
-       std::list<std::wstring> getConnectedPlayerNames();
+       std::list<std::string> getConnectedPlayerNames();
 
        float getAnimationTime();
 
index 0a1a92271e721fb41b9b96a30cedab84f15b3c3d..8bec67c8c46dcd10aa99eab01bcf16fc6f5afba9 100644 (file)
@@ -708,11 +708,15 @@ public:
                        if(player && player->isLocal()){
                                m_is_local_player = true;
                        }
+                       m_env->addPlayerName(m_name.c_str());
                }
        }
 
        ~GenericCAO()
        {
+               if(m_is_player){
+                       m_env->removePlayerName(m_name.c_str());
+               }
        }
 
        static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)
index 02301e5d3027b07f74997b5cbf91170e2b22ba1f..7f73a5461a3aed96a3db3d6266494f8cc62efc09 100644 (file)
@@ -470,6 +470,13 @@ public:
        ClientEnvEvent getClientEvent();
 
        std::vector<core::vector2d<int> > attachment_list; // X is child ID, Y is parent ID
+
+       std::list<std::string> getPlayerNames()
+       { return m_player_names; }
+       void addPlayerName(std::string name)
+       { m_player_names.push_back(name); }
+       void removePlayerName(std::string name)
+       { m_player_names.remove(name); }
        
 private:
        ClientMap *m_map;
@@ -482,6 +489,7 @@ private:
        Queue<ClientEnvEvent> m_client_event_queue;
        IntervalLimiter m_active_object_light_update_interval;
        IntervalLimiter m_lava_hurt_interval;
+       std::list<std::string> m_player_names;
 };
 
 #endif
index 5fc576cf8315f83c8a5b6268a83b79c507c43660..ec23648f86cad4d155d76eda76ed672fc39c6ba7 100644 (file)
@@ -535,7 +535,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
                {
                        // Tab or Shift-Tab pressed
                        // Nick completion
-                       std::list<std::wstring> names = m_client->getConnectedPlayerNames();
+                       std::list<std::string> names = m_client->getConnectedPlayerNames();
                        bool backwards = event.KeyInput.Shift;
                        m_chat_backend->getPrompt().nickCompletion(names, backwards);
                        return true;