From b0e68060777dfb7daefc81c169e1ed4d95c4a2d6 Mon Sep 17 00:00:00 2001 From: PilzAdam Date: Mon, 25 Mar 2013 19:13:25 +0100 Subject: [PATCH] Fix nick completion --- src/chat.cpp | 8 ++++---- src/chat.h | 2 +- src/client.cpp | 13 ++----------- src/client.h | 2 +- src/content_cao.cpp | 4 ++++ src/environment.h | 8 ++++++++ src/guiChatConsole.cpp | 2 +- 7 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/chat.cpp b/src/chat.cpp index 1135ccdf7..3102e194a 100644 --- a/src/chat.cpp +++ b/src/chat.cpp @@ -464,7 +464,7 @@ void ChatPrompt::historyNext() } } -void ChatPrompt::nickCompletion(const std::list& names, bool backwards) +void ChatPrompt::nickCompletion(const std::list& 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& names, bool backw // find all names that start with the selected prefix std::vector completions; - for (std::list::const_iterator + for (std::list::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); diff --git a/src/chat.h b/src/chat.h index 8a40c7ccf..19b48456e 100644 --- a/src/chat.h +++ b/src/chat.h @@ -160,7 +160,7 @@ public: void historyNext(); // Nick completion - void nickCompletion(const std::list& names, bool backwards); + void nickCompletion(const std::list& names, bool backwards); // Update console size and reformat the visible portion of the prompt void reformat(u32 cols); diff --git a/src/client.cpp b/src/client.cpp index f27f95d98..1d5f8f472 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -2501,18 +2501,9 @@ void Client::printDebugInfo(std::ostream &os) < Client::getConnectedPlayerNames() +std::list Client::getConnectedPlayerNames() { - std::list players = m_env.getPlayers(true); - std::list playerNames; - for(std::list::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() diff --git a/src/client.h b/src/client.h index d476a1d51..16cdc237f 100644 --- a/src/client.h +++ b/src/client.h @@ -315,7 +315,7 @@ public: // Prints a line or two of info void printDebugInfo(std::ostream &os); - std::list getConnectedPlayerNames(); + std::list getConnectedPlayerNames(); float getAnimationTime(); diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 0a1a92271..8bec67c8c 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -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) diff --git a/src/environment.h b/src/environment.h index 02301e5d3..7f73a5461 100644 --- a/src/environment.h +++ b/src/environment.h @@ -470,6 +470,13 @@ public: ClientEnvEvent getClientEvent(); std::vector > attachment_list; // X is child ID, Y is parent ID + + std::list 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 m_client_event_queue; IntervalLimiter m_active_object_light_update_interval; IntervalLimiter m_lava_hurt_interval; + std::list m_player_names; }; #endif diff --git a/src/guiChatConsole.cpp b/src/guiChatConsole.cpp index 5fc576cf8..ec23648f8 100644 --- a/src/guiChatConsole.cpp +++ b/src/guiChatConsole.cpp @@ -535,7 +535,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event) { // Tab or Shift-Tab pressed // Nick completion - std::list names = m_client->getConnectedPlayerNames(); + std::list names = m_client->getConnectedPlayerNames(); bool backwards = event.KeyInput.Shift; m_chat_backend->getPrompt().nickCompletion(names, backwards); return true;