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);
92 for(
const auto& l : log) {
93 const bool is_lobby = l.first ==
"lobby";
95 if(!show_lobby && is_lobby && !l.second.whisper) {
113 t.pending_messages = 0;
150 case SDLK_KP_ENTER: {
151 if(input[0] ==
'/') {
155 chat_handler::do_speak(input);
178 std::vector<std::string> matches;
179 for(
const auto& ui : li->users()) {
181 matches.push_back(ui.name);
187 if(matches.empty()) {
191 if(matches.size() == 1) {
192 input.append(line_start ?
": " :
" ");
194 std::string completion_list =
utils::join(matches,
" ");
221 const std::string before_message = log.
get_value().empty() ?
"" :
"\n";
228 if(
log_ !=
nullptr) {
231 log_->at(room_name).log = new_text;
232 }
catch(
const std::out_of_range&) {
236 if(chatbox_at_end || force_scroll) {
267 const std::string& speaker,
273 if(
message.compare(0, 4,
"/me ") == 0) {
310 }
else if(can_go_to_active) {
314 LOG_LB <<
"Ignoring whisper from " << sender;
322 LOG_LB <<
"Cannot add sent message to ui for room " << room <<
", player not in the room";
334 const std::string& speaker,
348 if(speaker ==
"server") {
362 return t.name == name &&
t.whisper ==
true;
368 return t.name == room &&
t.whisper ==
false;
380 VGETTEXT(
"Started private message with <i>$name</i>. "
381 "If you do not want to receive messages from this player, type <i>/ignore $name</i>", { {
"name", name } }));
387 const bool allow_close,
388 const std::string& initial_text)
391 if(
t.name == name &&
t.whisper == whisper) {
406 item[
"use_markup"] =
"true";
407 item[
"label"] = initial_text;
410 if(
log_ !=
nullptr) {
425 item[
"label"] =
"<" + name +
">";
428 data.emplace(
"room", item);
455 handled = halt =
true;
466 ++
t->pending_messages;
468 if(
t->pending_messages == 1) {
480 ++
t->pending_messages;
482 if(
t->pending_messages == 1) {
485 DBG_LB <<
"do room pending mark row " << idx <<
" with " <<
t->name;
497 ERR_LB <<
"Whisper window not open in add_whisper_window_whisper for " << sender;
507 const bool force_scroll)
517 DBG_LB <<
"Close window " << idx <<
" - " <<
t.name;
520 if((
t.name ==
"lobby" &&
t.whisper ==
false) ||
open_windows_.size() == 1) {
531 if(
log_ !=
nullptr) {
549 const std::string& sender,
554 ERR_LB <<
"Room window not open in add_room_window_message for " << room;
564 const bool force_scroll)
572 std::string sender =
data[
"sender"];
573 DBG_LB <<
"process message from " << sender <<
" " << (whisper ?
"(w)" :
"")
574 <<
", len " <<
data[
"message"].str().size();
588 std::string room =
data[
"room"];
592 LOG_LB <<
"Message without a room from " << sender <<
", falling back to active window";
598 LOG_LB <<
"Message without a room from " << sender <<
", assuming lobby";
602 if(
log_ !=
nullptr &&
data[
"type"].str() ==
"motd") {
604 LOG_LB <<
"Ignoring repeated motd";
616 plugin_data[
"whisper"] = whisper;
622 if(
const auto message =
data.optional_child(
"message")) {
624 }
else if(
const auto whisper =
data.optional_child(
"whisper")) {
642 load_resolutions<resolution>(cfg);
652 grid = std::make_shared<builder_grid>(child);
659 builder_chatbox::builder_chatbox(
const config& cfg)
666 auto widget = std::make_unique<chatbox>(*
this);
668 DBG_GUI_G <<
"Window builder: placed unit preview pane '" <<
id
669 <<
"' with definition '" <<
definition <<
"'.";
674 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()
Standard logging facilities (interface).
std::string escape_text(const std::string &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(const std::string &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)