mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-14 12:35:47 +00:00
Add tab completion to the lobby,
...API translation from existing code in multiplayer_ui.cpp
This commit is contained in:
parent
c003995924
commit
c806608b2b
@ -1682,6 +1682,28 @@ bool tlobby_main::chat_input_keypress_callback(twidget* widget, SDLKey key,
|
|||||||
if (key == SDLK_RETURN || key == SDLK_KP_ENTER) {
|
if (key == SDLK_RETURN || key == SDLK_KP_ENTER) {
|
||||||
send_message_button_callback(*widget->get_window());
|
send_message_button_callback(*widget->get_window());
|
||||||
return true;
|
return true;
|
||||||
|
} else if(key == SDLK_TAB) {
|
||||||
|
std::string text = chat_input_->get_value();
|
||||||
|
const std::vector<user_info>& match_infos = lobby_info_.users();
|
||||||
|
std::vector<std::string> matches;
|
||||||
|
|
||||||
|
foreach(const user_info& ui, match_infos) {
|
||||||
|
if(ui.name != preferences::login()) {
|
||||||
|
matches.push_back(ui.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const bool line_start = utils::word_completion(text, matches);
|
||||||
|
|
||||||
|
if (matches.empty()) return false;
|
||||||
|
|
||||||
|
if (matches.size() == 1) {
|
||||||
|
text.append(line_start ? ": " : " ");
|
||||||
|
} else {
|
||||||
|
std::string completion_list = utils::join(matches, ' ');
|
||||||
|
append_to_chatbox(completion_list);
|
||||||
|
}
|
||||||
|
chat_input_->set_value(text);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user