Fix nick completion

This commit is contained in:
PilzAdam 2013-03-25 19:13:25 +01:00
parent 76b86c0368
commit b0e6806077
7 changed files with 21 additions and 18 deletions

View 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: // Two cases:
// (a) m_nick_completion_start == m_nick_completion_end == 0 // (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 // find all names that start with the selected prefix
std::vector<std::wstring> completions; std::vector<std::wstring> completions;
for (std::list<std::wstring>::const_iterator for (std::list<std::string>::const_iterator
i = names.begin(); i = names.begin();
i != names.end(); ++i) 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) if (prefix_start == 0)
completion += L":"; completion += L":";
completions.push_back(completion); completions.push_back(completion);

View File

@ -160,7 +160,7 @@ public:
void historyNext(); void historyNext();
// Nick completion // 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 // Update console size and reformat the visible portion of the prompt
void reformat(u32 cols); void reformat(u32 cols);

View File

@ -2501,18 +2501,9 @@ void Client::printDebugInfo(std::ostream &os)
<<std::endl;*/ <<std::endl;*/
} }
std::list<std::wstring> Client::getConnectedPlayerNames() std::list<std::string> Client::getConnectedPlayerNames()
{ {
std::list<Player*> players = m_env.getPlayers(true); return m_env.getPlayerNames();
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;
} }
float Client::getAnimationTime() float Client::getAnimationTime()

View File

@ -315,7 +315,7 @@ public:
// Prints a line or two of info // Prints a line or two of info
void printDebugInfo(std::ostream &os); void printDebugInfo(std::ostream &os);
std::list<std::wstring> getConnectedPlayerNames(); std::list<std::string> getConnectedPlayerNames();
float getAnimationTime(); float getAnimationTime();

View File

@ -708,11 +708,15 @@ public:
if(player && player->isLocal()){ if(player && player->isLocal()){
m_is_local_player = true; m_is_local_player = true;
} }
m_env->addPlayerName(m_name.c_str());
} }
} }
~GenericCAO() ~GenericCAO()
{ {
if(m_is_player){
m_env->removePlayerName(m_name.c_str());
}
} }
static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env) static ClientActiveObject* create(IGameDef *gamedef, ClientEnvironment *env)

View File

@ -471,6 +471,13 @@ public:
std::vector<core::vector2d<int> > attachment_list; // X is child ID, Y is parent ID 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: private:
ClientMap *m_map; ClientMap *m_map;
scene::ISceneManager *m_smgr; scene::ISceneManager *m_smgr;
@ -482,6 +489,7 @@ private:
Queue<ClientEnvEvent> m_client_event_queue; Queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval; IntervalLimiter m_active_object_light_update_interval;
IntervalLimiter m_lava_hurt_interval; IntervalLimiter m_lava_hurt_interval;
std::list<std::string> m_player_names;
}; };
#endif #endif

View File

@ -535,7 +535,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
{ {
// Tab or Shift-Tab pressed // Tab or Shift-Tab pressed
// Nick completion // Nick completion
std::list<std::wstring> names = m_client->getConnectedPlayerNames(); std::list<std::string> names = m_client->getConnectedPlayerNames();
bool backwards = event.KeyInput.Shift; bool backwards = event.KeyInput.Shift;
m_chat_backend->getPrompt().nickCompletion(names, backwards); m_chat_backend->getPrompt().nickCompletion(names, backwards);
return true; return true;