15 #define GETTEXT_DOMAIN "wesnoth-lib" 43 #define DBG_LB LOG_STREAM(debug, log_lobby) 44 #define LOG_LB LOG_STREAM(info, log_lobby) 45 #define ERR_LB LOG_STREAM(err, log_lobby) 47 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__ 48 #define LOG_HEADER LOG_SCOPE_HEADER + ':' 59 , roomlistbox_(
nullptr)
60 , chat_log_container_(
nullptr)
61 , chat_input_(
nullptr)
63 , active_window_changed_callback_()
72 connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
78 roomlistbox_ = find_widget<listbox>(
this,
"room_list",
false,
true);
87 chat_input_ = find_widget<text_box>(
this,
"chat_input",
false,
true);
95 for(
const auto& l : log) {
96 const bool is_lobby = l.first ==
"lobby";
98 if(!show_lobby && is_lobby && !l.second.whisper) {
153 case SDLK_KP_ENTER: {
154 if(input[0] ==
'/') {
158 chat_handler::do_speak(input);
182 std::vector<std::string> matches;
183 for(
const auto& ui : li->users()) {
185 matches.push_back(ui.name);
191 if(matches.empty()) {
195 if(matches.size() == 1) {
196 input.append(line_start ?
": " :
" ");
198 std::string completion_list =
utils::join(matches,
" ");
225 const std::string before_message = log.
get_label().
empty() ?
"" :
"\n";
232 if(
log_ !=
nullptr) {
235 log_->at(room_name).log = new_text;
236 }
catch(
const std::out_of_range&) {
240 if(chatbox_at_end || force_scroll) {
271 const std::string& speaker,
281 if(message.compare(0, 4,
"/me ") == 0) {
318 }
else if(can_go_to_active) {
322 LOG_LB <<
"Ignoring whisper from " << sender;
330 LOG_LB <<
"Cannot add sent message to ui for room " << room <<
", player not in the room";
342 const std::string& speaker,
356 if(speaker ==
"server") {
364 do_notify(notify_mode, speaker, message);
388 VGETTEXT(
"Started private message with <i>$name</i>. " 389 "If you do not want to receive messages from this player, type <i>/ignore $name</i>", { {
"name", name } }));
395 const bool allow_close,
396 const std::string& initial_text)
399 if(
t.name == name &&
t.whisper == whisper) {
408 open_windows_.emplace_back(name, whisper);
414 item[
"use_markup"] =
"true";
415 item[
"label"] = initial_text;
418 if(
log_ !=
nullptr) {
433 item[
"label"] =
"<" + name +
">";
436 data.emplace(
"room", item);
443 button& close_button = find_widget<button>(&row_grid,
"close_window",
false);
452 return &open_windows_.back();
463 handled = halt =
true;
474 ++
t->pending_messages;
476 if(
t->pending_messages == 1) {
488 ++
t->pending_messages;
490 if(
t->pending_messages == 1) {
493 DBG_LB <<
"do room pending mark row " << idx <<
" with " <<
t->name;
505 ERR_LB <<
"Whisper window not open in add_whisper_window_whisper for " << sender;
515 const bool force_scroll)
525 DBG_LB <<
"Close window " << idx <<
" - " << t.
name;
539 if(
log_ !=
nullptr) {
557 const std::string& sender,
562 ERR_LB <<
"Room window not open in add_room_window_message for " << room;
572 const bool force_scroll)
580 std::string sender = data[
"sender"];
581 DBG_LB <<
"process message from " << sender <<
" " << (whisper ?
"(w)" :
"")
582 <<
", len " << data[
"message"].str().size();
588 const std::string&
message = data[
"message"];
596 std::string room = data[
"room"];
600 LOG_LB <<
"Message without a room from " << sender <<
", falling back to active window";
606 LOG_LB <<
"Message without a room from " << sender <<
", assuming lobby";
610 if(
log_ !=
nullptr && data[
"type"].str() ==
"motd") {
611 if(
log_->at(
"lobby").received_motd == message) {
612 LOG_LB <<
"Ignoring repeated motd";
615 log_->at(
"lobby").received_motd = message;
624 plugin_data[
"whisper"] = whisper;
630 if(
const auto message = data.optional_child(
"message")) {
632 }
else if(
const auto whisper = data.optional_child(
"whisper")) {
650 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);
virtual std::unique_ptr< widget > build() const override
bool is_composing() const
void switch_to_window(lobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
void active_window_changed()
Base class of a resolution, contains the common keys for a resolution.
void keyboard_capture(widget *widget)
void increment_waiting_messages(const std::string &room)
Mark the room window for "room" as having one more pending message.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
multi_page * chat_log_container_
std::vector< state_definition > state
bool room_window_active(const std::string &room)
ui_event
The event sent to the dispatcher.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
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 signal_handler_receive_keyboard_focus(const event::ui_event event)
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Main class to show messages to the user.
chatbox_definition(const config &cfg)
std::string get_value() const
std::map< std::string, chatroom_log > * log_
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
void save_to_history()
Saves the text in the widget to the history.
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.
std::vector< lobby_chat_window > open_windows_
void send_to_server(const ::config &cfg) override
int get_selected_row() const
Returns the first selected row.
bool whisper_window_active(const std::string &name)
std::size_t active_window_
static std::string _(const char *str)
resolution(const config &cfg)
std::string dsgettext(const char *domainname, const char *msgid)
bool whisper_friends_only()
bool select_row(const unsigned row, const bool select=true)
Selects a row.
void process_message(const ::config &data, bool whisper=false)
void do_notify(notify_mode mode, const std::string &sender, const std::string &message)
bool auto_open_whisper_windows()
std::map< std::string, t_string > widget_item
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.
virtual void send_whisper(const std::string &receiver, const std::string &message)
void close_window_button_callback(std::string room_name, bool &handled, bool &halt)
bool is_friend(const std::string &nick)
#define VALIDATE(cond, message)
The macro to use for the validation of WML.
This file contains the settings handling of the widget library.
const grid & page_grid(const unsigned page) const
Returns the grid for the page.
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...
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
std::function< void(void)> active_window_changed_callback_
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 load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
bool is_ignored(const std::string &nick)
void process_network_data(const ::config &data)
static lg::log_domain log_lobby("lobby")
virtual void user_relation_changed(const std::string &name) override
Inherited form chat_handler.
std::string escape_text(const std::string &text)
Escapes the pango markup characters in a text.
void increment_waiting_whispers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
void chat_input_keypress_callback(const SDL_Keycode key)
virtual void add_whisper_received(const std::string &sender, const std::string &message) override
Inherited form chat_handler.
void select_page(const unsigned page, const bool select=true)
Selects a page.
grid & add_page(const widget_item &item)
Adds single page to the grid.
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.
A generic container base class.
std::string get_chat_timestamp(const std::time_t &t)
virtual void add_chat_room_message_received(const std::string &room, const std::string &speaker, const std::string &message) override
Inherited form chat_handler.
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
void append_to_chatbox(const std::string &text, const bool force_scroll=false)
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message) override
Inherited form chat_handler.
virtual void clear_messages() override
Standard logging facilities (interface).
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard &signal)
Connects the signal for 'snooping' on the keypress.
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
lobby_info * get_lobby_info()
Returns the lobby_info object for the given session.
std::map< std::string, widget_item > widget_data
void send_to_server(const config &data)
Attempts to send given data to server if a connection is open.
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".
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 add_whisper_sent(const std::string &receiver, const std::string &message) override
Inherited form chat_handler.
A config object defines a single node in a WML file, with access to child nodes.
void notify_event(const std::string &name, const config &data)
void finalize_setup()
Initializes the internal sub-widget pointers.
virtual void send_chat_room_message(const std::string &room, const std::string &message)
bool word_completion(std::string &text, std::vector< std::string > &wordlist)
Try to complete the last word of 'text' with the 'wordlist'.
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...
Contains the implementation details for lexical_cast and shouldn't be used directly.
static plugins_manager * get()
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
std::pair< std::string, unsigned > item
bool word_match(const std::string &message, const std::string &word)
Check if a message contains a word.
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.