Chatbox: partially fixed buggy nick autocompletion (fixes #6263)

I don't really like this solution, since as mentioned in #3729, while this works for players
in the lobby, since lobby_info.users isn't updated while a player is in staging/join, anyone
who joins the lobby (or your game) after your create or join a game won't get included in the
autocomplete list. BEeides, I don't like the idea of exposing the full lobby_info object here
just for the user list, but it at least gets ac working and not crashing.
This commit is contained in:
Charles Dang 2021-11-07 19:26:58 -05:00
parent 2cfa7d4dd5
commit 7b06daa5b2
3 changed files with 15 additions and 4 deletions

View file

@ -68,6 +68,7 @@ class mp_manager
public:
// Declare this as a friend to allow direct access to enter_create_mode
friend void mp::start_local_game();
friend lobby_info* mp::get_lobby_info();
mp_manager(const std::optional<std::string> host);
@ -828,4 +829,9 @@ std::string get_profile_link(int user_id)
return "";
}
lobby_info* get_lobby_info()
{
return manager ? &manager->lobby_info : nullptr;
}
} // end namespace mp

View file

@ -67,4 +67,6 @@ bool logged_in_as_moderator();
/** Gets the forum profile link for the given user. */
std::string get_profile_link(int user_id);
/** Returns the lobby_info object for the given session. */
class lobby_info* get_lobby_info();
}

View file

@ -176,13 +176,16 @@ void chatbox::chat_input_keypress_callback(const SDL_Keycode key)
}
case SDLK_TAB: {
mp::room_info* ri = chat_info_.get_room(t.name);
auto* li = mp::get_lobby_info();
if(!li) {
break;
}
// TODO: very inefficient! Very! D:
std::vector<std::string> matches;
for(const std::string& ui : ri->members()) {
if(ui != preferences::login()) {
matches.push_back(ui);
for(const auto& ui : li->users()) {
if(ui.name != preferences::login()) {
matches.push_back(ui.name);
}
}