15 #define GETTEXT_DOMAIN "wesnoth-lib"
40 #define DBG_LB LOG_STREAM(debug, log_lobby)
41 #define LOG_LB LOG_STREAM(info, log_lobby)
42 #define ERR_LB LOG_STREAM(err, log_lobby)
44 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
45 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
56 , roomlistbox_(
nullptr)
57 , chat_log_container_(
nullptr)
58 , chat_input_(
nullptr)
60 , active_window_changed_callback_()
69 connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
75 roomlistbox_ = find_widget<listbox>(
"room_list",
false,
true);
84 chat_input_ = find_widget<text_box>(
"chat_input",
false,
true);
98 const bool is_lobby = l.first ==
"lobby";
100 if(!show_lobby && is_lobby && !l.second.whisper) {
104 const std::size_t new_tip_index = l.second.log.find(new_tip);
106 if(new_tip_index != std::string::npos) {
107 l.second.log.replace(new_tip_index, new_tip.length(),
"");
123 t.pending_messages = 0;
160 case SDLK_KP_ENTER: {
161 if(input[0] ==
'/') {
165 chat_handler::do_speak(input);
188 std::vector<std::string> matches;
189 for(
const auto& ui : li->users()) {
191 matches.push_back(ui.name);
197 if(matches.empty()) {
201 if(matches.size() == 1) {
202 input.append(line_start ?
": " :
" ");
204 std::string completion_list =
utils::join(matches,
" ");
231 const std::string before_message = log.
get_value().empty() ?
"" :
"\n";
238 if(
log_ !=
nullptr) {
241 log_->at(room_name).log = new_text;
242 }
catch(
const std::out_of_range&) {
246 if(chatbox_at_end || force_scroll) {
277 const std::string& speaker,
283 if(
message.compare(0, 4,
"/me ") == 0) {
320 }
else if(can_go_to_active) {
324 LOG_LB <<
"Ignoring whisper from " << sender;
332 LOG_LB <<
"Cannot add sent message to ui for room " << room <<
", player not in the room";
344 const std::string& speaker,
358 if(speaker ==
"server") {
372 return t.name == name &&
t.whisper ==
true;
378 return t.name == room &&
t.whisper ==
false;
390 VGETTEXT(
"Started private message with <i>$name</i>. "
391 "If you do not want to receive messages from this player, type <i>/ignore $name</i>", { {
"name", name } }));
397 const bool allow_close,
398 const std::string& initial_text)
401 if(
t.name == name &&
t.whisper == whisper) {
416 item[
"use_markup"] =
"true";
417 item[
"label"] = initial_text;
420 if(
log_ !=
nullptr) {
435 item[
"label"] =
"<" + name +
">";
438 data.emplace(
"room", item);
465 handled = halt =
true;
476 ++
t->pending_messages;
478 if(
t->pending_messages == 1) {
490 ++
t->pending_messages;
492 if(
t->pending_messages == 1) {
495 DBG_LB <<
"do room pending mark row " << idx <<
" with " <<
t->name;
507 ERR_LB <<
"Whisper window not open in add_whisper_window_whisper for " << sender;
517 const bool force_scroll)
527 DBG_LB <<
"Close window " << idx <<
" - " <<
t.name;
530 if((
t.name ==
"lobby" &&
t.whisper ==
false) ||
open_windows_.size() == 1) {
541 if(
log_ !=
nullptr) {
559 const std::string& sender,
564 ERR_LB <<
"Room window not open in add_room_window_message for " << room;
574 const bool force_scroll)
582 std::string sender =
data[
"sender"];
583 DBG_LB <<
"process message from " << sender <<
" " << (whisper ?
"(w)" :
"")
584 <<
", len " <<
data[
"message"].str().size();
598 std::string room =
data[
"room"];
602 LOG_LB <<
"Message without a room from " << sender <<
", falling back to active window";
608 LOG_LB <<
"Message without a room from " << sender <<
", assuming lobby";
612 if(
log_ !=
nullptr &&
data[
"type"].str() ==
"motd") {
614 LOG_LB <<
"Ignoring repeated motd";
626 plugin_data[
"whisper"] = whisper;
632 if(
const auto message =
data.optional_child(
"message")) {
634 }
else if(
const auto whisper =
data.optional_child(
"whisper")) {
652 load_resolutions<resolution>(cfg);
662 grid = std::make_shared<builder_grid>(child);
669 builder_chatbox::builder_chatbox(
const config& cfg)
676 auto widget = std::make_unique<chatbox>(*
this);
678 DBG_GUI_G <<
"Window builder: placed unit preview pane '" <<
id
679 <<
"' with definition '" <<
definition <<
"'.";
684 widget->init_grid(*conf->grid);
static lg::log_domain log_lobby("lobby")
A config object defines a single node in a WML file, with access to child nodes.
virtual void send_chat_room_message(const std::string &room, const std::string &message)
virtual void send_whisper(const std::string &receiver, const std::string &message)
std::map< std::string, chatroom_log > * log_
bool room_window_active(const std::string &room)
lobby_chat_window * room_window_open(const std::string &room, const bool open_new, const bool allow_close=true)
Check if a room window for "room" is open, if open_new is true then it will be created if not found.
lobby_chat_window * find_or_create_window(const std::string &name, const bool whisper, const bool open_new, const bool allow_close, const std::string &initial_text)
Helper function to find and open a new window, used by *_window_open.
virtual void clear_messages() override
void add_active_window_whisper(const std::string &sender, const std::string &message, const bool force_scroll=false)
Add a whisper message to the current window which is not the whisper window for "name".
void append_to_chatbox(const std::string &text, const bool force_scroll=false)
virtual void user_relation_changed(const std::string &name) override
Inherited form chat_handler.
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
void add_active_window_message(const std::string &sender, const std::string &message, const bool force_scroll=false)
Add a message to the window for room "room".
void close_window(std::size_t idx)
void add_whisper_window_whisper(const std::string &sender, const std::string &message)
Add a whisper message to the whisper window.
void close_window_button_callback(std::string room_name, bool &handled, bool &halt)
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message) override
Inherited form chat_handler.
multi_page * chat_log_container_
void process_message(const ::config &data, bool whisper=false)
lobby_chat_window * whisper_window_open(const std::string &name, bool open_new)
Check if a whisper window for user "name" is open, if open_new is true then it will be created if not...
void switch_to_window(lobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
std::size_t active_window_
virtual void add_whisper_sent(const std::string &receiver, const std::string &message) override
Inherited form chat_handler.
virtual void add_chat_message(const std::time_t &time, const std::string &speaker, int side, const std::string &message, events::chat_handler::MESSAGE_TYPE type=events::chat_handler::MESSAGE_PRIVATE) override
Inherited form chat_handler.
void process_network_data(const ::config &data)
void increment_waiting_whispers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
std::function< void(void)> active_window_changed_callback_
void increment_waiting_messages(const std::string &room)
Mark the room window for "room" as having one more pending message.
void signal_handler_receive_keyboard_focus(const event::ui_event event)
void send_to_server(const ::config &cfg) override
virtual void add_chat_room_message_received(const std::string &room, const std::string &speaker, const std::string &message) override
Inherited form chat_handler.
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
virtual void add_whisper_received(const std::string &sender, const std::string &message) override
Inherited form chat_handler.
void finalize_setup()
Initializes the internal sub-widget pointers.
void chat_input_keypress_callback(const SDL_Keycode key)
void add_room_window_message(const std::string &room, const std::string &sender, const std::string &message)
Add a message to the window for room "room".
void active_window_changed()
std::vector< lobby_chat_window > open_windows_
bool whisper_window_active(const std::string &name)
A generic container base class.
Main class to show messages to the user.
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
bool select_row(const unsigned row, const bool select=true)
Selects a row.
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
int get_selected_row() const
Returns the first selected row.
const grid & page_grid(const unsigned page) const
Returns the grid for the page.
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
grid & add_page(const widget_item &item)
Adds single page to the grid.
void select_page(const unsigned page, const bool select=true)
Selects a page.
virtual void set_label(const t_string &label) override
void set_value(const t_string &label)
std::string get_value() const
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
bool is_composing() const
void save_to_history()
Saves the text in the widget to the history.
void keyboard_capture(widget *widget)
void notify_event(const std::string &name, const config &data)
static plugins_manager * get()
bool is_ignored(const std::string &nick)
bool is_friend(const std::string &nick)
bool auto_open_whisper_windows()
static std::string _(const char *str)
Standard logging facilities (interface).
std::string escape_text(std::string_view text)
Escapes the pango markup characters in a text.
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard &signal)
Connects the signal for 'snooping' on the keypress.
ui_event
The event sent to the dispatcher.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
Functions to load and save images from/to disk.
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::string italic(Args &&... data)
std::string bold(Args &&... data)
std::string span_color(const color_t &color, Args &&... data)
lobby_info * get_lobby_info()
Returns the lobby_info object for the given session.
void do_notify(notify_mode mode, const std::string &sender, const std::string &message)
void send_to_server(const config &data)
Attempts to send given data to server if a connection is open.
std::string dsgettext(const char *domainname, const char *msgid)
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.
bool word_completion(std::string &text, std::vector< std::string > &wordlist)
Try to complete the last word of 'text' with the 'wordlist'.
resolution(const config &cfg)
chatbox_definition(const config &cfg)
virtual std::unique_ptr< widget > build() const override
std::vector< state_definition > state
std::string missing_mandatory_wml_tag(const std::string §ion, const std::string &tag)
Returns a standard message for a missing wml child (tag).
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE_WML_CHILD(cfg, key, message)