The Battle for Wesnoth  1.17.14+dev
chatbox.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2016 - 2022
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  , log_(nullptr)
65 {
66  // We only implement a RECEIVE_KEYBOARD_FOCUS handler; LOSE_KEYBOARD_FOCUS
67  // isn't needed. This handler forwards focus to the input textbox, meaning
68  // if keyboard_focus is called on a chatbox, distributor::keyboard_focus_
69  // will immediately be set to the input textbox, which will then handle focus
70  // loss itself when applicable. Nothing else happens in the interim while
71  // keyboard_focus_ equals `this` to warrent cleanup.
72  connect_signal<event::RECEIVE_KEYBOARD_FOCUS>(
73  std::bind(&chatbox::signal_handler_receive_keyboard_focus, this, std::placeholders::_2));
74 }
75 
77 {
78  roomlistbox_ = find_widget<listbox>(this, "room_list", false, true);
79 
80  // We need to bind a lambda here since switch_to_window is overloaded.
81  // A lambda alone would be more verbose because it'd need to specify all the parameters.
83  std::bind([this]() { switch_to_window(roomlistbox_->get_selected_row()); }));
84 
85  chat_log_container_ = find_widget<multi_page>(this, "chat_log_container", false, true);
86 
87  chat_input_ = find_widget<text_box>(this, "chat_input", false, true);
88 
89  connect_signal_pre_key_press(*chat_input_,
90  std::bind(&chatbox::chat_input_keypress_callback, this, std::placeholders::_5));
91 }
92 
93 void chatbox::load_log(std::map<std::string, chatroom_log>& log, bool show_lobby)
94 {
95  for(const auto& l : log) {
96  const bool is_lobby = l.first == "lobby";
97 
98  if(!show_lobby && is_lobby && !l.second.whisper) {
99  continue;
100  }
101 
102  find_or_create_window(l.first, l.second.whisper, true, !is_lobby, l.second.log);
103  }
104 
105  log_ = &log;
106 }
107 
109 {
111 
112  // Clear pending messages notification in room listbox
114  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::hidden);
115 
116  t.pending_messages = 0;
117 
120  }
121 }
122 
124 {
126 }
127 
128 void chatbox::switch_to_window(std::size_t id)
129 {
130  active_window_ = id;
131  assert(active_window_ < open_windows_.size());
132 
135 
136  // Grab input focus
138 
140 }
141 
142 void chatbox::chat_input_keypress_callback(const SDL_Keycode key)
143 {
144  std::string input = chat_input_->get_value();
145  if(input.empty() || chat_input_->is_composing()) {
146  return;
147  }
148 
150 
151  switch(key) {
152  case SDLK_RETURN:
153  case SDLK_KP_ENTER: {
154  if(input[0] == '/') {
155  // TODO: refactor do_speak so it uses context information about
156  // opened window, so e.g. /ignore in a whisper session ignores
157  // the other party without having to specify it's nick.
158  chat_handler::do_speak(input);
159  } else {
160  if(t.whisper) {
161  send_whisper(t.name, input);
162  add_whisper_sent(t.name, input);
163  } else {
164  send_chat_room_message(t.name, input);
166  }
167  }
168 
170  chat_input_->set_value("");
171 
172  break;
173  }
174 
175  case SDLK_TAB: {
176  auto* li = mp::get_lobby_info();
177  if(!li) {
178  break;
179  }
180 
181  // TODO: very inefficient! Very! D:
182  std::vector<std::string> matches;
183  for(const auto& ui : li->users()) {
184  if(ui.name != preferences::login()) {
185  matches.push_back(ui.name);
186  }
187  }
188 
189  const bool line_start = utils::word_completion(input, matches);
190 
191  if(matches.empty()) {
192  return;
193  }
194 
195  if(matches.size() == 1) {
196  input.append(line_start ? ": " : " ");
197  } else {
198  std::string completion_list = utils::join(matches, " ");
199  append_to_chatbox(completion_list);
200  }
201 
202  chat_input_->set_value(input);
203 
204  break;
205  }
206 
207  default:
208  break;
209  }
210 }
211 
212 void chatbox::append_to_chatbox(const std::string& text, const bool force_scroll)
213 {
214  append_to_chatbox(text, active_window_, force_scroll);
215 }
216 
217 void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const bool force_scroll)
218 {
220 
221  scroll_label& log = find_widget<scroll_label>(&grid, "log_text", false);
222  const bool chatbox_at_end = log.vertical_scrollbar_at_end();
223  const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
224 
225  const std::string before_message = log.get_label().empty() ? "" : "\n";
226  const std::string new_text = formatter()
227  << log.get_label() << before_message << "<span color='#bcb088'>" << preferences::get_chat_timestamp(std::time(0)) << text << "</span>";
228 
229  log.set_use_markup(true);
230  log.set_label(new_text);
231 
232  if(log_ != nullptr) {
233  try {
234  const std::string& room_name = open_windows_[id].name;
235  log_->at(room_name).log = new_text;
236  } catch(const std::out_of_range&) {
237  }
238  }
239 
240  if(chatbox_at_end || force_scroll) {
242  } else {
243  log.set_vertical_scrollbar_item_position(chatbox_position);
244  }
245 }
246 
247 void chatbox::send_chat_message(const std::string& message, bool /*allies_only*/)
248 {
249  add_chat_message(std::time(nullptr), preferences::login(), 0, message);
250 
251  ::config c {"message", ::config {"message", message, "sender", preferences::login()}};
252  send_to_server(c);
253 }
254 
256 {
257  const auto id = active_window_;
259  scroll_label& log = find_widget<scroll_label>(&grid, "log_text", false);
260  log.set_label("");
261 }
262 
263 void chatbox::user_relation_changed(const std::string& /*name*/)
264 {
267  }
268 }
269 
270 void chatbox::add_chat_message(const std::time_t& /*time*/,
271  const std::string& speaker,
272  int /*side*/,
273  const std::string& message,
275 {
276  std::string text;
277 
278  // FIXME: the chat_command_handler class (which handles chat commands) dispatches a
279  // message consisting of '/me insert text here' in the case the '/me' or '/emote'
280  // commands are used, so we need to do some manual preprocessing here.
281  if(message.compare(0, 4, "/me ") == 0) {
282  text = formatter() << "<i>" << speaker << " " << font::escape_text(message.substr(4)) << "</i>";
283  } else {
284  text = formatter() << "<b>" << speaker << ":</b> " << font::escape_text(message);
285  }
286 
287  append_to_chatbox(text);
288 }
289 
290 void chatbox::add_whisper_sent(const std::string& receiver, const std::string& message)
291 {
292  if(whisper_window_active(receiver)) {
297  } else {
298  add_active_window_whisper(VGETTEXT("whisper to $receiver", {{"receiver", receiver}}), message, true);
299  }
300 }
301 
302 void chatbox::add_whisper_received(const std::string& sender, const std::string& message)
303 {
304  bool can_go_to_active = !preferences::whisper_friends_only() || preferences::is_friend(sender);
305  bool can_open_new = preferences::auto_open_whisper_windows() && can_go_to_active;
306 
307  if(whisper_window_open(sender, can_open_new)) {
308  if(whisper_window_active(sender)) {
309  add_active_window_message(sender, message);
310 
311  do_notify(mp::notify_mode::whisper, sender, message);
312  } else {
313  add_whisper_window_whisper(sender, message);
315 
317  }
318  } else if(can_go_to_active) {
319  add_active_window_whisper(sender, message);
320  do_notify(mp::notify_mode::whisper, sender, message);
321  } else {
322  LOG_LB << "Ignoring whisper from " << sender;
323  }
324 }
325 
326 void chatbox::add_chat_room_message_sent(const std::string& room, const std::string& message)
327 {
328  lobby_chat_window* t = room_window_open(room, false);
329  if(!t) {
330  LOG_LB << "Cannot add sent message to ui for room " << room << ", player not in the room";
331  return;
332  }
333 
334  if(!room_window_active(room)) {
335  switch_to_window(t);
336  }
337 
339 }
340 
341 void chatbox::add_chat_room_message_received(const std::string& room,
342  const std::string& speaker,
343  const std::string& message)
344 {
346 
347  if(room_window_active(room)) {
348  add_active_window_message(speaker, message);
349  notify_mode = mp::notify_mode::message;
350  } else {
351  add_room_window_message(room, speaker, message);
354  }
355 
356  if(speaker == "server") {
357  notify_mode = mp::notify_mode::server_message;
358  } else if (utils::word_match(message, preferences::login())) {
359  notify_mode = mp::notify_mode::own_nick;
360  } else if (preferences::is_friend(speaker)) {
361  notify_mode = mp::notify_mode::friend_message;
362  }
363 
364  do_notify(notify_mode, speaker, message);
365 }
366 
367 bool chatbox::whisper_window_active(const std::string& name)
368 {
370  return t.name == name && t.whisper == true;
371 }
372 
373 bool chatbox::room_window_active(const std::string& room)
374 {
376  return t.name == room && t.whisper == false;
377 }
378 
379 lobby_chat_window* chatbox::room_window_open(const std::string& room, const bool open_new, const bool allow_close)
380 {
381  return find_or_create_window(room, false, open_new, allow_close,
382  VGETTEXT("Joined <i>$name</i>", { { "name", translation::dsgettext("wesnoth-lib", room.c_str()) } }));
383 }
384 
385 lobby_chat_window* chatbox::whisper_window_open(const std::string& name, bool open_new)
386 {
387  return find_or_create_window(name, true, open_new, true,
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 } }));
390 }
391 
393  const bool whisper,
394  const bool open_new,
395  const bool allow_close,
396  const std::string& initial_text)
397 {
398  for(auto& t : open_windows_) {
399  if(t.name == name && t.whisper == whisper) {
400  return &t;
401  }
402  }
403 
404  if(!open_new) {
405  return nullptr;
406  }
407 
408  open_windows_.emplace_back(name, whisper);
409 
410  //
411  // Add a new chat log page.
412  //
414  item["use_markup"] = "true";
415  item["label"] = initial_text;
416  widget_data data{{"log_text", item}};
417 
418  if(log_ != nullptr) {
419  log_->emplace(name, chatroom_log{item["label"], whisper});
420  }
421 
423 
424  //
425  // Add a new room window tab.
426  //
427  data.clear();
428  item.clear();
429 
430  if(!whisper) {
431  item["label"] = translation::dsgettext("wesnoth-lib", name.c_str());
432  } else {
433  item["label"] = "<" + name + ">";
434  }
435 
436  data.emplace("room", item);
437 
438  grid& row_grid = roomlistbox_->add_row(data);
439 
440  //
441  // Set up the Close Window button.
442  //
443  button& close_button = find_widget<button>(&row_grid, "close_window", false);
444 
445  if(!allow_close) {
447  } else {
448  connect_signal_mouse_left_click(close_button,
449  std::bind(&chatbox::close_window_button_callback, this, open_windows_.back().name, std::placeholders::_3, std::placeholders::_4));
450  }
451 
452  return &open_windows_.back();
453 }
454 
455 void chatbox::close_window_button_callback(std::string room_name, bool& handled, bool& halt)
456 {
457  const int index = std::distance(open_windows_.begin(), std::find_if(open_windows_.begin(), open_windows_.end(),
458  [&room_name](const lobby_chat_window& room) { return room.name == room_name; }
459  ));
460 
461  close_window(index);
462 
463  handled = halt = true;
464 }
465 
466 void chatbox::send_to_server(const ::config& cfg)
467 {
468  mp::send_to_server(cfg);
469 }
470 
471 void chatbox::increment_waiting_whispers(const std::string& name)
472 {
473  if(lobby_chat_window* t = whisper_window_open(name, false)) {
474  ++t->pending_messages;
475 
476  if(t->pending_messages == 1) {
477  DBG_LB << "do whisper pending mark row " << (t - &open_windows_[0]) << " with " << t->name;
478 
480  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::visible);
481  }
482  }
483 }
484 
485 void chatbox::increment_waiting_messages(const std::string& room)
486 {
487  if(lobby_chat_window* t = room_window_open(room, false)) {
488  ++t->pending_messages;
489 
490  if(t->pending_messages == 1) {
491  int idx = t - &open_windows_[0];
492 
493  DBG_LB << "do room pending mark row " << idx << " with " << t->name;
494 
496  find_widget<image>(grid, "pending_messages", false).set_visible(widget::visibility::visible);
497  }
498  }
499 }
500 
501 void chatbox::add_whisper_window_whisper(const std::string& sender, const std::string& message)
502 {
503  lobby_chat_window* t = whisper_window_open(sender, false);
504  if(!t) {
505  ERR_LB << "Whisper window not open in add_whisper_window_whisper for " << sender;
506  return;
507  }
508 
509  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
510  append_to_chatbox(text, t - &open_windows_[0], false);
511 }
512 
513 void chatbox::add_active_window_whisper(const std::string& sender,
514  const std::string& message,
515  const bool force_scroll)
516 {
517  const std::string text = formatter() << "<b>" << "whisper: " << sender << ":</b> " << font::escape_text(message);
518  append_to_chatbox(text, force_scroll);
519 }
520 
521 void chatbox::close_window(std::size_t idx)
522 {
523  const lobby_chat_window& t = open_windows_[idx];
524 
525  DBG_LB << "Close window " << idx << " - " << t.name;
526 
527  // Can't close the lobby!
528  if((t.name == "lobby" && t.whisper == false) || open_windows_.size() == 1) {
529  return;
530  }
531 
532  // Check if we're closing the currently-active window.
533  const bool active_changed = idx == active_window_;
534 
535  if(active_window_ == open_windows_.size() - 1) {
536  --active_window_;
537  }
538 
539  if(log_ != nullptr) {
540  log_->erase(t.name);
541  }
542 
543  open_windows_.erase(open_windows_.begin() + idx);
544 
545  roomlistbox_->remove_row(idx);
547 
550 
551  if(active_changed) {
553  }
554 }
555 
556 void chatbox::add_room_window_message(const std::string& room,
557  const std::string& sender,
558  const std::string& message)
559 {
560  lobby_chat_window* t = room_window_open(room, false);
561  if(!t) {
562  ERR_LB << "Room window not open in add_room_window_message for " << room;
563  return;
564  }
565 
566  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
567  append_to_chatbox(text, t - &open_windows_[0], false);
568 }
569 
570 void chatbox::add_active_window_message(const std::string& sender,
571  const std::string& message,
572  const bool force_scroll)
573 {
574  const std::string text = formatter() << "<b>" << sender << ":</b> " << font::escape_text(message);
575  append_to_chatbox(text, force_scroll);
576 }
577 
578 void chatbox::process_message(const ::config& data, bool whisper /*= false*/)
579 {
580  std::string sender = data["sender"];
581  DBG_LB << "process message from " << sender << " " << (whisper ? "(w)" : "")
582  << ", len " << data["message"].str().size();
583 
584  if(preferences::is_ignored(sender)) {
585  return;
586  }
587 
588  const std::string& message = data["message"];
589  //preferences::parse_admin_authentication(sender, message); TODO: replace
590 
591  if(whisper) {
592  add_whisper_received(sender, message);
593  } else {
594  if (!preferences::parse_should_show_lobby_join(sender, message)) return;
595 
596  std::string room = data["room"];
597 
598  // Attempt to send to the currently active room first.
599  if(room.empty()) {
600  LOG_LB << "Message without a room from " << sender << ", falling back to active window";
601  room = open_windows_[active_window_].name;
602  }
603 
604  // If we still don't have a name, fall back to lobby.
605  if(room.empty()) {
606  LOG_LB << "Message without a room from " << sender << ", assuming lobby";
607  room = "lobby";
608  }
609 
610  if(log_ != nullptr && data["type"].str() == "motd") {
611  if(log_->at("lobby").received_motd == message) {
612  LOG_LB << "Ignoring repeated motd";
613  return;
614  } else {
615  log_->at("lobby").received_motd = message;
616  }
617  }
618 
619  add_chat_room_message_received(room, sender, message);
620  }
621 
622  // Notify plugins about the message
623  ::config plugin_data = data;
624  plugin_data["whisper"] = whisper;
625  plugins_manager::get()->notify_event("chat", plugin_data);
626 }
627 
628 void chatbox::process_network_data(const ::config& data)
629 {
630  if(const auto message = data.optional_child("message")) {
632  } else if(const auto whisper = data.optional_child("whisper")) {
633  process_message(*whisper, true);
634  }
635 }
636 
638 {
639  DBG_GUI_E << LOG_HEADER << ' ' << event << ".";
640 
641  // Forward focus to the input textbox.
643 }
644 
645 // }---------- DEFINITION ---------{
646 
649 {
650  load_resolutions<resolution>(cfg);
651 }
652 
654  : resolution_definition(cfg), grid()
655 {
656  state.emplace_back(cfg.child("background"));
657  state.emplace_back(cfg.child("foreground"));
658 
659  const config& child = cfg.child("grid");
660  VALIDATE(child, _("No grid defined."));
661 
662  grid = std::make_shared<builder_grid>(child);
663 }
664 // }---------- BUILDER -----------{
665 
666 namespace implementation
667 {
668 
669 builder_chatbox::builder_chatbox(const config& cfg)
670  : builder_styled_widget(cfg)
671 {
672 }
673 
674 std::unique_ptr<widget> builder_chatbox::build() const
675 {
676  auto widget = std::make_unique<chatbox>(*this);
677 
678  DBG_GUI_G << "Window builder: placed unit preview pane '" << id
679  << "' with definition '" << definition << "'.";
680 
681  const auto conf = widget->cast_config_to<chatbox_definition>();
682  assert(conf);
683 
684  widget->init_grid(*conf->grid);
685  widget->finalize_setup();
686 
687  return widget;
688 }
689 
690 } // namespace implementation
691 
692 // }------------ END --------------
693 
694 } // namespace gui2
virtual std::unique_ptr< widget > build() const override
Definition: chatbox.cpp:674
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:123
void active_window_changed()
Definition: chatbox.cpp:108
Base class of a resolution, contains the common keys for a resolution.
void keyboard_capture(widget *widget)
Definition: window.cpp:1130
#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:485
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
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:373
ui_event
The event sent to the dispatcher.
Definition: handler.hpp:115
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:556
void signal_handler_receive_keyboard_focus(const event::ui_event event)
Definition: chatbox.cpp:637
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:179
#define LOG_LB
Definition: chatbox.cpp:44
Main class to show messages to the user.
Definition: message.hpp:35
chatbox_definition(const config &cfg)
Definition: chatbox.cpp:647
const std::string & id() const
Definition: widget.cpp:111
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:53
std::map< std::string, chatroom_log > * log_
Definition: chatbox.hpp:137
std::string_view data
Definition: picture.cpp:206
void remove_page(const unsigned page, unsigned count=1)
Removes a page in the multi page.
Definition: multi_page.cpp:76
void save_to_history()
Saves the text in the widget to the history.
Definition: text_box.hpp:149
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.
Definition: listbox.cpp:61
std::vector< lobby_chat_window > open_windows_
Definition: chatbox.hpp:131
void send_to_server(const ::config &cfg) override
Definition: chatbox.cpp:466
int get_selected_row() const
Returns the first selected row.
Definition: listbox.cpp:270
bool whisper_window_active(const std::string &name)
Definition: chatbox.cpp:367
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:432
bool whisper_friends_only()
Definition: lobby.cpp:21
bool select_row(const unsigned row, const bool select=true)
Selects a row.
Definition: listbox.cpp:245
text_box * chat_input_
Definition: chatbox.hpp:129
virtual void set_label(const t_string &label) override
See styled_widget::set_label.
Generic file dialog.
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:578
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
std::map< std::string, t_string > widget_item
Definition: widget.hpp:32
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:270
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:455
#define ERR_LB
Definition: chatbox.cpp:45
bool is_friend(const std::string &nick)
Definition: game.cpp:264
#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:120
std::ostringstream wrapper.
Definition: formatter.hpp:39
void set_visible(const visibility visible)
Definition: widget.cpp:456
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:385
virtual void send_chat_message(const std::string &message, bool allies_only) override
Inherited form chat_handler.
Definition: chatbox.cpp:247
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:570
void load_log(std::map< std::string, chatroom_log > &log, bool show_lobby)
Definition: chatbox.cpp:93
Label showing a text.
listbox * roomlistbox_
Definition: chatbox.hpp:125
bool is_ignored(const std::string &nick)
Definition: game.cpp:276
#define REGISTER_WIDGET(id)
Wrapper for REGISTER_WIDGET3.
void process_network_data(const ::config &data)
Definition: chatbox.cpp:628
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:263
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
void increment_waiting_whispers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
Definition: chatbox.cpp:471
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:142
virtual void add_whisper_received(const std::string &sender, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:302
void select_page(const unsigned page, const bool select=true)
Selects a page.
Definition: multi_page.cpp:105
window * get_window()
Get the parent window.
Definition: widget.cpp:118
void scroll_vertical_scrollbar(const scrollbar_base::scroll_mode scroll)
Scrolls the vertical scrollbar.
grid & add_page(const widget_item &item)
Adds single page to the grid.
Definition: multi_page.cpp:44
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:863
bool grid()
Definition: general.cpp:565
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:341
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:232
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:212
bool empty() const
Definition: tstring.hpp:187
The user sets the widget visible, that means:
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:326
virtual void clear_messages() override
Definition: chatbox.cpp:255
Simple push button.
Definition: button.hpp:36
Standard logging facilities (interface).
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard &signal)
Connects the signal for &#39;snooping&#39; on the keypress.
Definition: dispatcher.cpp:174
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
Definition: listbox.cpp:81
unsigned get_vertical_scrollbar_item_position() const
Returns current position of the vertical scrollbar.
bool parse_should_show_lobby_join(const std::string &sender, const std::string &message)
Definition: game.cpp:304
lobby_info * get_lobby_info()
Returns the lobby_info object for the given session.
notify_mode
Definition: lobby_info.hpp:155
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:35
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".
Definition: chatbox.cpp:513
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:392
virtual void add_whisper_sent(const std::string &receiver, const std::string &message) override
Inherited form chat_handler.
Definition: chatbox.cpp:290
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:60
void notify_event(const std::string &name, const config &data)
Definition: manager.cpp:145
mock_char c
void finalize_setup()
Initializes the internal sub-widget pointers.
Definition: chatbox.cpp:76
#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:379
Contains the implementation details for lexical_cast and shouldn&#39;t be used directly.
static plugins_manager * get()
Definition: manager.cpp:59
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
Definition: dispatcher.cpp:205
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:414
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:521
void add_whisper_window_whisper(const std::string &sender, const std::string &message)
Add a whisper message to the whisper window.
Definition: chatbox.cpp:501