15 #define GETTEXT_DOMAIN "wesnoth-lib"
44 #define DBG_LB LOG_STREAM(debug, log_lobby)
45 #define LOG_LB LOG_STREAM(info, log_lobby)
46 #define ERR_LB LOG_STREAM(err, log_lobby)
48 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
49 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
60 , roomlistbox_(
nullptr)
61 , chat_log_container_(
nullptr)
62 , chat_input_(
nullptr)
64 , active_window_changed_callback_()
73 connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
79 roomlistbox_ = find_widget<listbox>(
this,
"room_list",
false,
true);
88 chat_input_ = find_widget<text_box>(
this,
"chat_input",
false,
true);
96 for(
const auto& l : log) {
97 const bool is_lobby = l.first ==
"lobby";
99 if(!show_lobby && is_lobby && !l.second.whisper) {
117 t.pending_messages = 0;
154 case SDLK_KP_ENTER: {
155 if(input[0] ==
'/') {
159 chat_handler::do_speak(input);
183 std::vector<std::string> matches;
184 for(
const auto& ui : li->users()) {
186 matches.push_back(ui.name);
192 if(matches.empty()) {
196 if(matches.size() == 1) {
197 input.append(line_start ?
": " :
" ");
199 std::string completion_list =
utils::join(matches,
" ");
226 const std::string before_message = log.
get_label().
empty() ?
"" :
"\n";
233 if(
log_ !=
nullptr) {
236 log_->at(room_name).log = new_text;
237 }
catch(
const std::out_of_range&) {
241 if(chatbox_at_end || force_scroll) {
272 const std::string& speaker,
282 if(
message.compare(0, 4,
"/me ") == 0) {
319 }
else if(can_go_to_active) {
323 LOG_LB <<
"Ignoring whisper from " << sender;
331 LOG_LB <<
"Cannot add sent message to ui for room " << room <<
", player not in the room";
343 const std::string& speaker,
357 if(speaker ==
"server") {
371 return t.name == name &&
t.whisper ==
true;
377 return t.name == room &&
t.whisper ==
false;
389 VGETTEXT(
"Started private message with <i>$name</i>. "
390 "If you do not want to receive messages from this player, type <i>/ignore $name</i>", { {
"name", name } }));
396 const bool allow_close,
397 const std::string& initial_text)
400 if(
t.name == name &&
t.whisper == whisper) {
415 item[
"use_markup"] =
"true";
416 item[
"label"] = initial_text;
419 if(
log_ !=
nullptr) {
434 item[
"label"] =
"<" + name +
">";
444 button& close_button = find_widget<button>(&row_grid,
"close_window",
false);
464 handled = halt =
true;
475 ++
t->pending_messages;
477 if(
t->pending_messages == 1) {
489 ++
t->pending_messages;
491 if(
t->pending_messages == 1) {
494 DBG_LB <<
"do room pending mark row " << idx <<
" with " <<
t->name;
506 ERR_LB <<
"Whisper window not open in add_whisper_window_whisper for " << sender;
516 const bool force_scroll)
526 DBG_LB <<
"Close window " << idx <<
" - " <<
t.name;
529 if((
t.name ==
"lobby" &&
t.whisper ==
false) ||
open_windows_.size() == 1) {
540 if(
log_ !=
nullptr) {
558 const std::string& sender,
563 ERR_LB <<
"Room window not open in add_room_window_message for " << room;
573 const bool force_scroll)
581 std::string sender =
data[
"sender"];
582 DBG_LB <<
"process message from " << sender <<
" " << (whisper ?
"(w)" :
"")
583 <<
", len " <<
data[
"message"].str().size();
597 std::string room =
data[
"room"];
601 LOG_LB <<
"Message without a room from " << sender <<
", falling back to active window";
607 LOG_LB <<
"Message without a room from " << sender <<
", assuming lobby";
611 if(
log_ !=
nullptr &&
data[
"type"].str() ==
"motd") {
613 LOG_LB <<
"Ignoring repeated motd";
625 plugin_data[
"whisper"] = whisper;
631 if(
const auto message =
data.optional_child(
"message")) {
633 }
else if(
const auto whisper =
data.optional_child(
"whisper")) {
651 load_resolutions<resolution>(cfg);
661 grid = std::make_shared<builder_grid>(child);
668 builder_chatbox::builder_chatbox(
const config& cfg)
675 auto widget = std::make_unique<chatbox>(*
this);
677 DBG_GUI_G <<
"Window builder: placed unit preview pane '" <<
id
678 <<
"' with definition '" <<
definition <<
"'.";
683 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.
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()
static std::string _(const char *str)
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
std::pair< std::string, unsigned > item
Contains the implementation details for lexical_cast and shouldn't be used directly.
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.
bool is_ignored(const std::string &nick)
bool whisper_friends_only()
std::string get_chat_timestamp(const std::time_t &t)
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
bool is_friend(const std::string &nick)
bool auto_open_whisper_windows()
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'.
This file contains the settings handling of the widget library.
resolution(const config &cfg)
chatbox_definition(const config &cfg)
virtual std::unique_ptr< widget > build() const override
Base class of a resolution, contains the common keys for a resolution.
std::vector< state_definition > state
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)