The Battle for Wesnoth  1.17.0-dev
chatbox.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2021
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "gui/widgets/chatbox.hpp"
18 
21 #include "gui/widgets/button.hpp"
22 #include "gui/widgets/image.hpp"
23 #include "gui/widgets/label.hpp"
24 #include "gui/widgets/listbox.hpp"
27 #include "gui/widgets/settings.hpp"
28 #include "gui/widgets/text_box.hpp"
29 #include "gui/widgets/window.hpp"
30 
31 #include "font/pango/escape.hpp"
32 #include "formatter.hpp"
33 #include "formula/string_utils.hpp"
35 #include "gettext.hpp"
36 #include "log.hpp"
38 #include "preferences/game.hpp"
39 #include "preferences/lobby.hpp"
41 
42 static lg::log_domain log_lobby("lobby");
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)
46 
47 #define LOG_SCOPE_HEADER get_control_type() + " [" + id() + "] " + __func__
48 #define LOG_HEADER LOG_SCOPE_HEADER + ':'
49 
50 namespace gui2
51 {
52 
53 // ------------ WIDGET -----------{
54 
55 REGISTER_WIDGET(chatbox)
56 
57 chatbox::chatbox(const implementation::builder_chatbox& builder)
58  : container_base(builder, type())
59  , roomlistbox_(nullptr)
60  , chat_log_container_(nullptr)
61  , chat_input_(nullptr)
62  , active_window_(0)
63  , active_window_changed_callback_()
64  , chat_info_()
65  , log_(nullptr)
66 {
67  // We only implement a RECEIVE_KEYBOARD_FOCUS handler; LOSE_KEYBOARD_FOCUS
68  // isn't needed. This handler forwards focus to the input textbox, meaning
69  // if keyboard_focus is called on a chatbox, distributor::keyboard_focus_
70  // will immediately be set to the input textbox, which will then handle focus
71  // loss itself when applicable. Nothing else happens in the interim while
72  // keyboard_focus_ equals `this` to warrent cleanup.
73  connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
74  std::bind(&chatbox::signal_handler_receive_keyboard_focus, this, std::placeholders::_2));
75 }
76 
78 {
79  roomlistbox_ = find_widget<listbox>(this, "room_list", false, true);
80 
81  // We need to bind a lambda here since switch_to_window is overloaded.
82  // A lambda alone would be more verbose because it'd need to specify all the parameters.
84  std::bind([this]() { switch_to_window(roomlistbox_->get_selected_row()); }));
85 
86  chat_log_container_ = find_widget<multi_page>(this, "chat_log_container", false, true);
87 
88  chat_input_ = find_widget<text_box>(this, "chat_input", false, true);
89 
90  connect_signal_pre_key_press(*chat_input_,
91  std::bind(&chatbox::chat_input_keypress_callback, this, std::placeholders::_5));
92 }
93 
94 void chatbox::load_log(std::map<std::string, chatroom_log>& log, bool show_lobby)
95 {
96  for(const auto& l : log) {
97  const bool is_lobby = l.first == "lobby";
98 
99  if(!show_lobby && is_lobby && !l.second.whisper) {
100  continue;
101  }
102 
103  find_or_create_window(l.first, l.second.whisper, true, !is_lobby, l.second.log);
104  }
105 
106  log_ = &log;
107 }
108 
110 {
112 
113  // Clear pending messages notification in room listbox
115  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::hidden);
116 
117  t.pending_messages = 0;
118 
121  }
122 }
123 
125 {
127 }
128 
129 void chatbox::switch_to_window(std::size_t id)
130 {
131  active_window_ = id;
132  assert(active_window_ < open_windows_.size());
133 
136 
137  // Grab input focus
139 
141 }
142 
143 void chatbox::chat_input_keypress_callback(const SDL_Keycode key)
144 {
145  std::string input = chat_input_->get_value();
146  if(input.empty() || chat_input_->is_composing()) {
147  return;
148  }
149 
151 
152  switch(key) {
153  case SDLK_RETURN:
154  case SDLK_KP_ENTER: {
155  if(input[0] == '/') {
156  // TODO: refactor do_speak so it uses context information about
157  // opened window, so e.g. /ignore in a whisper session ignores
158  // the other party without having to specify it's nick.
159  chat_handler::do_speak(input);
160  } else {
161  if(t.whisper) {
162  send_whisper(t.name, input);
163  add_whisper_sent(t.name, input);
164  } else {
165  send_chat_room_message(t.name, input);
167  }
168  }
169 
171  chat_input_->set_value("");
172 
173  break;
174  }
175 
176  case SDLK_TAB: {
178 
179  // TODO: very inefficient! Very! D:
180  std::vector<std::string> matches;
181  for(const std::string& ui : ri->members()) {
182  if(ui != preferences::login()) {
183  matches.push_back(ui);
184  }
185  }
186 
187  const bool line_start = utils::word_completion(input, matches);
188 
189  if(matches.empty()) {
190  return;
191  }
192 
193  if(matches.size() == 1) {
194  input.append(line_start ? ": " : " ");
195  } else {
196  std::string completion_list = utils::join(matches, " ");
197  append_to_chatbox(completion_list);
198  }
199 
200  chat_input_->set_value(input);
201 
202  break;
203  }
204 
205  default:
206  break;
207  }
208 }
209 
210 void chatbox::append_to_chatbox(const std::string& text, const bool force_scroll)
211 {
212  append_to_chatbox(text, active_window_, force_scroll);
213 }
214 
215 void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const bool force_scroll)
216 {
218 
219  scroll_label& log = find_widget<scroll_label>(&grid, "log_text", false);
220  const bool chatbox_at_end = log.vertical_scrollbar_at_end();
221  const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
222 
223  const std::string new_text = formatter()
224  << log.get_label() << "\n" << "<span color='#bcb088'>" << preferences::get_chat_timestamp(std::time(0)) << text << "</span>";
225 
226  log.set_use_markup(true);
227  log.set_label(new_text);
228 
229  if(log_ != nullptr) {
230  try {
231  const std::string& room_name = open_windows_[id].name;
232  log_->at(room_name).log = new_text;
233  } catch(const std::out_of_range&) {
234  }
235  }
236 
237  if(chatbox_at_end || force_scroll) {
239  } else {
240  log.set_vertical_scrollbar_item_position(chatbox_position);
241  }
242 }
243 
244 void chatbox::send_chat_message(const std::string& message, bool /*allies_only*/)
245 {
246  add_chat_message(std::time(nullptr), preferences::login(), 0, message);
247 
248  ::config c {"message", ::config {"message", message, "sender", preferences::login()}};
249  send_to_server(c);
250 }
251 
252 void chatbox::user_relation_changed(const std::string& /*name*/)
253 {
256  }
257 }
258 
259 void chatbox::add_chat_message(const std::time_t& /*time*/,
260  const std::string& speaker,
261  int /*side*/,
262  const std::string& message,
264 {
265  std::string text;
266 
267  // FIXME: the chat_command_handler class (which handles chat commands) dispatches a
268  // message consisting of '/me insert text here' in the case the '/me' or '/emote'
269  // commands are used, so we need to do some manual preprocessing here.
270  if(message.compare(0, 4, "/me ") == 0) {
271  text = formatter() << "<i>" << speaker << " " << font::escape_text(message.substr(4)) << "</i>";
272  } else {
273  text = formatter() << "<b>" << speaker << ":</b> " << font::escape_text(message);
274  }
275 
276  append_to_chatbox(text);
277 }
278 
279 void chatbox::add_whisper_sent(const std::string& receiver, const std::string& message)
280 {
281  if(whisper_window_active(receiver)) {
286  } else {
287  add_active_window_whisper(VGETTEXT("whisper to $receiver", {{"receiver", receiver}}), message, true);
288  }
289 
291 }
292 
293 void chatbox::add_whisper_received(const std::string& sender, const std::string& message)
294 {
295  bool can_go_to_active = !preferences::whisper_friends_only() || preferences::is_friend(sender);
296  bool can_open_new = preferences::auto_open_whisper_windows() && can_go_to_active;
297 
298  chat_info_.get_whisper_log(sender).add_message(sender, message);
299 
300  if(whisper_window_open(sender, can_open_new)) {
301  if(whisper_window_active(sender)) {
302  add_active_window_message(sender, message);
303 
304  do_notify(mp::NOTIFY_WHISPER, sender, message);
305  } else {
306  add_whisper_window_whisper(sender, message);
308 
309  do_notify(mp::NOTIFY_WHISPER_OTHER_WINDOW, sender, message);
310  }
311  } else if(can_go_to_active) {
312  add_active_window_whisper(sender, message);
313  do_notify(mp::NOTIFY_WHISPER, sender, message);
314  } else {
315  LOG_LB << "Ignoring whisper from " << sender << "\n";
316  }
317 }
318 
319 void chatbox::add_chat_room_message_sent(const std::string& room, const std::string& message)
320 {
321  lobby_chat_window* t = room_window_open(room, false);
322  if(!t) {
323  LOG_LB << "Cannot add sent message to ui for room " << room << ", player not in the room\n";
324  return;
325  }
326 
327  // Do not open room window here. The player should be in the room before sending messages
328  mp::room_info* ri = chat_info_.get_room(room);
329  assert(ri);
330 
331  if(!room_window_active(room)) {
332  switch_to_window(t);
333  }
334 
335  ri->log().add_message(preferences::login(), message);
337 }
338 
339 void chatbox::add_chat_room_message_received(const std::string& room,
340  const std::string& speaker,
341  const std::string& message)
342 {
343  mp::room_info* ri = chat_info_.get_room(room);
344  if(!ri) {
345  LOG_LB << "Discarding message to room " << room << " from " << speaker << " (room not open)\n";
346  return;
347  }
348 
350  ri->log().add_message(speaker, message);
351 
352  if(room_window_active(room)) {
353  add_active_window_message(speaker, message);
354  notify_mode = mp::NOTIFY_MESSAGE;
355  } else {
356  add_room_window_message(room, speaker, message);
358  notify_mode = mp::NOTIFY_MESSAGE_OTHER_WINDOW;
359  }
360 
361  if(speaker == "server") {
362  notify_mode = mp::NOTIFY_SERVER_MESSAGE;
363  } else if (utils::word_match(message, preferences::login())) {
364  notify_mode = mp::NOTIFY_OWN_NICK;
365  } else if (preferences::is_friend(speaker)) {
366  notify_mode = mp::NOTIFY_FRIEND_MESSAGE;
367  }
368 
369  do_notify(notify_mode, speaker, message);
370 }
371 
372 bool chatbox::whisper_window_active(const std::string& name)
373 {
375  return t.name == name && t.whisper == true;
376 }
377 
378 bool chatbox::room_window_active(const std::string& room)
379 {
381  return t.name == room && t.whisper == false;
382 }
383 
384 lobby_chat_window* chatbox::room_window_open(const std::string& room, const bool open_new, const bool allow_close)
385 {
386  return find_or_create_window(room, false, open_new, allow_close,
387  VGETTEXT("Joined <i>$name</i>", { { "name", translation::dsgettext("wesnoth-lib", room.c_str()) } }));
388 }
389 
390 lobby_chat_window* chatbox::whisper_window_open(const std::string& name, bool open_new)
391 {
392  return find_or_create_window(name, true, open_new, true,
393  VGETTEXT("Started private message with <i>$name</i>. "
394  "If you do not want to receive messages from this player, type <i>/ignore $name</i>", { { "name", name } }));
395 }
396 
398  const bool whisper,
399  const bool open_new,
400  const bool allow_close,
401  const std::string& initial_text)
402 {
403  for(auto& t : open_windows_) {
404  if(t.name == name && t.whisper == whisper) {
405  return &t;
406  }
407  }
408 
409  if(!open_new) {
410  return nullptr;
411  }
412 
413  open_windows_.emplace_back(name, whisper);
414 
415  //
416  // Add a new chat log page.
417  //
419  item["use_markup"] = "true";
420  item["label"] = initial_text;
421  std::map<std::string, string_map> data{{"log_text", item}};
422 
423  if(!whisper) {
424  chat_info_.open_room(name);
425  }
426 
427  if(log_ != nullptr) {
428  log_->emplace(name, chatroom_log{item["label"], whisper});
429  }
430 
432 
433  //
434  // Add a new room window tab.
435  //
436  data.clear();
437  item.clear();
438 
439  if(!whisper) {
440  item["label"] = translation::dsgettext("wesnoth-lib", name.c_str());
441  } else {
442  item["label"] = "<" + name + ">";
443  }
444 
445  data.emplace("room", item);
446 
447  grid& row_grid = roomlistbox_->add_row(data);
448 
449  //
450  // Set up the Close Window button.
451  //
452  button& close_button = find_widget<button>(&row_grid, "close_window", false);
453 
454  if(!allow_close) {
456  } else {
457  connect_signal_mouse_left_click(close_button,
458  std::bind(&chatbox::close_window_button_callback, this, open_windows_.back().name, std::placeholders::_3, std::placeholders::_4));
459  }
460 
461  return &open_windows_.back();
462 }
463 
464 void chatbox::close_window_button_callback(std::string room_name, bool& handled, bool& halt)
465 {
466  const int index = std::distance(open_windows_.begin(), std::find_if(open_windows_.begin(), open_windows_.end(),
467  [&room_name](const lobby_chat_window& room) { return room.name == room_name; }
468  ));
469 
470  close_window(index);
471 
472  handled = halt = true;
473 }
474 
475 void chatbox::send_to_server(const ::config& cfg)
476 {
477  mp::yeet_to_server(cfg);
478 }
479 
480 void chatbox::increment_waiting_whispers(const std::string& name)
481 {
482  if(lobby_chat_window* t = whisper_window_open(name, false)) {
483  ++t->pending_messages;
484 
485  if(t->pending_messages == 1) {
486  DBG_LB << "do whisper pending mark row " << (t - &open_windows_[0]) << " with " << t->name << "\n";
487 
489  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::visible);
490  }
491  }
492 }
493 
494 void chatbox::increment_waiting_messages(const std::string& room)
495 {
496  if(lobby_chat_window* t = room_window_open(room, false)) {
497  ++t->pending_messages;
498 
499  if(t->pending_messages == 1) {
500  int idx = t - &open_windows_[0];
501 
502  DBG_LB << "do room pending mark row " << idx << " with " << t->name << "\n";
503 
505  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::visible);
506  }
507  }
508 }
509 
510 void chatbox::add_whisper_window_whisper(const std::string& sender, const std::string& message)
511 {
512  lobby_chat_window* t = whisper_window_open(sender, false);
513  if(!t) {
514  ERR_LB << "Whisper window not open in add_whisper_window_whisper for " << sender << "\n";
515  return;
516  }
517 
518  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
519  append_to_chatbox(text, t - &open_windows_[0], false);
520 }
521 
522 void chatbox::add_active_window_whisper(const std::string& sender,
523  const std::string& message,
524  const bool force_scroll)
525 {
526  const std::string text = formatter() << "<b>" << "whisper: " << sender << ":</b> " << font::escape_text(message);
527  append_to_chatbox(text, force_scroll);
528 }
529 
530 void chatbox::close_window(std::size_t idx)
531 {
532  const lobby_chat_window& t = open_windows_[idx];
533 
534  DBG_LB << "Close window " << idx << " - " << t.name << "\n";
535 
536  // Can't close the lobby!
537  if((t.name == "lobby" && t.whisper == false) || open_windows_.size() == 1) {
538  return;
539  }
540 
541  // Check if we're closing the currently-active window.
542  const bool active_changed = idx == active_window_;
543 
544  if(active_window_ == open_windows_.size() - 1) {
545  --active_window_;
546  }
547 
548  if(t.whisper) {
550  } else {
552  }
553 
554  if(log_ != nullptr) {
555  log_->erase(t.name);
556  }
557 
558  open_windows_.erase(open_windows_.begin() + idx);
559 
560  roomlistbox_->remove_row(idx);
562 
565 
566  if(active_changed) {
568  }
569 }
570 
571 void chatbox::add_room_window_message(const std::string& room,
572  const std::string& sender,
573  const std::string& message)
574 {
575  lobby_chat_window* t = room_window_open(room, false);
576  if(!t) {
577  ERR_LB << "Room window not open in add_room_window_message for " << room << "\n";
578  return;
579  }
580 
581  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
582  append_to_chatbox(text, t - &open_windows_[0], false);
583 }
584 
585 void chatbox::add_active_window_message(const std::string& sender,
586  const std::string& message,
587  const bool force_scroll)
588 {
589  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
590  append_to_chatbox(text, force_scroll);
591 }
592 
594 {
596  if(t.whisper) {
597  return nullptr;
598  }
599 
600  return chat_info_.get_room(t.name);
601 }
602 
603 void chatbox::process_message(const ::config& data, bool whisper /*= false*/)
604 {
605  std::string sender = data["sender"];
606  DBG_LB << "process message from " << sender << " " << (whisper ? "(w)" : "")
607  << ", len " << data["message"].str().size() << '\n';
608 
609  if(preferences::is_ignored(sender)) {
610  return;
611  }
612 
613  const std::string& message = data["message"];
614  //preferences::parse_admin_authentication(sender, message); TODO: replace
615 
616  if(whisper) {
617  add_whisper_received(sender, message);
618  } else {
619  std::string room = data["room"];
620 
621  // Attempt to send to the currently active room first.
622  if(room.empty()) {
623  LOG_LB << "Message without a room from " << sender << ", falling back to active window\n";
624  room = open_windows_[active_window_].name;
625  }
626 
627  // If we still don't have a name, fall back to lobby.
628  if(room.empty()) {
629  LOG_LB << "Message without a room from " << sender << ", assuming lobby\n";
630  room = "lobby";
631  }
632 
633  if(log_ != nullptr && data["type"].str() == "motd") {
634  if(log_->at("lobby").received_motd == message) {
635  LOG_LB << "Ignoring repeated motd\n";
636  return;
637  } else {
638  log_->at("lobby").received_motd = message;
639  }
640  }
641 
642  add_chat_room_message_received(room, sender, message);
643  }
644 
645  // Notify plugins about the message
646  ::config plugin_data = data;
647  plugin_data["whisper"] = whisper;
648  plugins_manager::get()->notify_event("chat", plugin_data);
649 }
650 
651 void chatbox::process_network_data(const ::config& data)
652 {
653  if(const auto message = data.optional_child("message")) {
655  } else if(const auto whisper = data.optional_child("whisper")) {
656  process_message(*whisper, true);
657  }
658 }
659 
661 {
662  DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";
663 
664  // Forward focus to the input textbox.
666 }
667 
668 // }---------- DEFINITION ---------{
669 
672 {
673  load_resolutions<resolution>(cfg);
674 }
675 
677  : resolution_definition(cfg), grid()
678 {
679  state.emplace_back(cfg.child("background"));
680  state.emplace_back(cfg.child("foreground"));
681 
682  const config& child = cfg.child("grid");
683  VALIDATE(child, _("No grid defined."));
684 
685  grid = std::make_shared<builder_grid>(child);
686 }
687 // }---------- BUILDER -----------{
688 
689 namespace implementation
690 {
691 
692 builder_chatbox::builder_chatbox(const config& cfg)
693  : builder_styled_widget(cfg)
694 {
695 }
696 
698 {
699  chatbox* widget = new chatbox(*this);
700 
701  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
702  << "' with definition '" << definition << "'.\n";
703 
704  const auto conf = widget->cast_config_to<chatbox_definition>();
705  assert(conf);
706 
707  widget->init_grid(*conf->grid);
708  widget->finalize_setup();
709 
710  return widget;
711 }
712 
713 } // namespace implementation
714 
715 // }------------ END --------------
716 
717 } // namespace gui2
bool is_composing() const
void switch_to_window(lobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
Definition: chatbox.cpp:124
void active_window_changed()
Definition: chatbox.cpp:109
Base class of a resolution, contains the common keys for a resolution.
void keyboard_capture(widget *widget)
Definition: window.cpp:1276
#define LOG_HEADER
Definition: chatbox.cpp:48
void increment_waiting_messages(const std::string &room)
Mark the room window for "room" as having one more pending message.
Definition: chatbox.cpp:494
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...
Definition: config.cpp:402
void add_message(const std::time_t &timestamp, const std::string &user, const std::string &message)
Definition: lobby_data.cpp:65
multi_page * chat_log_container_
Definition: chatbox.hpp:127
std::vector< state_definition > state
virtual void set_use_markup(bool use_markup) override
See styled_widget::set_use_markup.
bool room_window_active(const std::string &room)
Definition: chatbox.cpp:378
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".
Definition: chatbox.cpp:571
void signal_handler_receive_keyboard_focus(const event::ui_event event)
Definition: chatbox.cpp:660
#define LOG_LB
Definition: chatbox.cpp:44
Main class to show messages to the user.
Definition: message.hpp:35
virtual widget * build() const override
Definition: chatbox.cpp:697
grid & add_page(const string_map &item)
Adds single page to the grid.
Definition: multi_page.cpp:44
chatbox_definition(const config &cfg)
Definition: chatbox.cpp:670
const std::string & id() const
Definition: widget.cpp:110
std::string get_value() const
This file contains the window object, this object is a top level container which has the event manage...
Base class for all widgets.
Definition: widget.hpp:49
std::map< std::string, chatroom_log > * log_
Definition: chatbox.hpp:139
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
Definition: multi_page.cpp:78
void save_to_history()
Saves the text in the widget to the history.
Definition: text_box.hpp:149
std::vector< lobby_chat_window > open_windows_
Definition: chatbox.hpp:131
void send_to_server(const ::config &cfg) override
Definition: chatbox.cpp:475
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:277
bool whisper_window_active(const std::string &name)
Definition: chatbox.cpp:372
const chat_session & log() const
Definition: lobby_data.hpp:86
std::size_t active_window_
Definition: chatbox.hpp:133
static std::string _(const char *str)
Definition: gettext.hpp:93
std::string dsgettext(const char *domainname, const char *msgid)
Definition: gettext.cpp:426
bool whisper_friends_only()
Definition: lobby.cpp:21
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:252
text_box * chat_input_
Definition: chatbox.hpp:129
mp::chat_info chat_info_
Definition: chatbox.hpp:137
virtual void set_label(const t_string &label) override
See styled_widget::set_label.
Generic file dialog.
Definition: field-fwd.hpp:23
Go to the end position.
Definition: scrollbar.hpp:61
#define DBG_LB
Definition: chatbox.cpp:43
void process_message(const ::config &data, bool whisper=false)
Definition: chatbox.cpp:603
Base container class.
Definition: grid.hpp:31
std::string definition
Parameters for the styled_widget.
void do_notify(notify_mode mode, const std::string &sender, const std::string &message)
Definition: lobby_info.cpp:62
bool auto_open_whisper_windows()
Definition: lobby.cpp:31
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.
Definition: chatbox.cpp:259
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)
Definition: chatbox.cpp:464
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:187
chat_session & get_whisper_log(const std::string &name)
Definition: lobby_info.hpp:171
#define ERR_LB
Definition: chatbox.cpp:45
bool is_friend(const std::string &nick)
Definition: game.cpp:278
#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.
Definition: multi_page.cpp:122
std::ostringstream wrapper.
Definition: formatter.hpp:39
void set_visible(const visibility visible)
Definition: widget.cpp:476
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:172
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...
Definition: chatbox.cpp:390
void init_grid(const builder_grid &grid_builder)
Initializes and builds the grid.
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
Definition: chatbox.cpp:244
std::function< void(void)> active_window_changed_callback_
Definition: chatbox.hpp:135
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".
Definition: chatbox.cpp:585
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
Definition: chatbox.cpp:94
room_info * get_room(const std::string &name)
Returns info on room with the given name, or nullptr if it doesn&#39;t exist.
Definition: lobby_info.cpp:294
Label showing a text.
void yeet_to_server(const config &data)
Attempts to send given data to server if a connection is open.
listbox * roomlistbox_
Definition: chatbox.hpp:125
bool is_ignored(const std::string &nick)
Definition: game.cpp:290
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
mp::room_info * active_window_room()
Get the room* corresponding to the currently active window, or nullptr if a whisper window is active ...
Definition: chatbox.cpp:593
void process_network_data(const ::config &data)
Definition: chatbox.cpp:651
static lg::log_domain log_lobby("lobby")
std::string login()
virtual void user_relation_changed(const std::string &name) override
Inherited form chat_handler.
Definition: chatbox.cpp:252
std::string escape_text(const std::string &text)
Escapes the pango markup characters in a text.
Definition: escape.hpp:33
#define DBG_GUI_E
Definition: log.hpp:35
std::shared_ptr< const typename T::resolution > cast_config_to() const
Casts the current resolution definition config to the respective type of a derived widget...
void increment_waiting_whispers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
Definition: chatbox.cpp:480
void set_vertical_scrollbar_item_position(const unsigned position)
Move the vertical scrollbar to a position.
void chat_input_keypress_callback(const SDL_Keycode key)
Definition: chatbox.cpp:143
virtual void add_whisper_received(const std::string &sender, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:293
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition: multi_page.cpp:107
window * get_window()
Get the parent window.
Definition: widget.cpp:117
void scroll_vertical_scrollbar(const scrollbar_base::scroll_mode scroll)
Scrolls the vertical scrollbar.
std::map< std::string, t_string > string_map
Definition: widget.hpp:26
grid & add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:68
This class represents the information a client has about a room.
Definition: lobby_data.hpp:68
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.
Definition: unicode.cpp:72
#define VGETTEXT(msgid,...)
Handy wrappers around interpolate_variables_into_string and gettext.
A generic container base class.
std::string get_chat_timestamp(const std::time_t &t)
Definition: game.cpp:877
bool grid()
Definition: general.cpp:535
virtual void add_chat_room_message_received(const std::string &room, const std::string &speaker, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:339
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:239
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
const t_string & get_label() const
void append_to_chatbox(const std::string &text, const bool force_scroll=false)
Definition: chatbox.cpp:210
The user sets the widget visible, that means:
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard_function &signal)
Connects the signal for &#39;snooping&#39; on the keypress.
Definition: dispatcher.cpp:167
double t
Definition: astarsearch.cpp:65
The user sets the widget hidden, that means:
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:319
Simple push button.
Definition: button.hpp:36
Standard logging facilities (interface).
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
Definition: listbox.cpp:88
unsigned get_vertical_scrollbar_item_position() const
Returns current position of the vertical scrollbar.
notify_mode
Definition: lobby_info.hpp:187
void close_room(const std::string &name)
Close the chat room with the given name.
Definition: lobby_info.cpp:334
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".
Definition: chatbox.cpp:522
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.
Definition: chatbox.cpp:397
virtual void add_whisper_sent(const std::string &receiver, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:279
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
void notify_event(const std::string &name, const config &data)
Definition: manager.cpp:145
mock_char c
const std::set< std::string > & members() const
Definition: lobby_data.hpp:77
void finalize_setup()
Initializes the internal sub-widget pointers.
Definition: chatbox.cpp:77
void open_room(const std::string &name)
Open a new chat room with the given name.
Definition: lobby_info.cpp:328
#define DBG_GUI_G
Definition: log.hpp:41
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 &#39;text&#39; with the &#39;wordlist&#39;.
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...
Definition: chatbox.cpp:384
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
ui_event
The event send to the dispatcher.
Definition: handler.hpp:48
static plugins_manager * get()
Definition: manager.cpp:59
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:410
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)
Definition: chatbox.cpp:530
void add_whisper_window_whisper(const std::string &sender, const std::string &message)
Add a whisper message to the whisper window.
Definition: chatbox.cpp:510