The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
lobby.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Tomasz Sniatowski <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 #ifndef GUI_DIALOGS_LOBBY_HPP_INCLUDED
16 #define GUI_DIALOGS_LOBBY_HPP_INCLUDED
17 
18 #include "gui/dialogs/dialog.hpp"
20 #include "chat_events.hpp"
22 
23 #include <boost/scoped_ptr.hpp>
24 
25 class display;
26 
27 #ifdef GUI2_EXPERIMENTAL_LISTBOX
28 #include "gui/widgets/list.hpp"
29 #endif
31 namespace gui2
32 {
33 
34 class tgrid;
35 class tlabel;
36 #ifndef GUI2_EXPERIMENTAL_LISTBOX
37 class tlistbox;
38 #endif
39 class ttext_box;
40 class twindow;
41 class tmulti_page;
42 class ttoggle_button;
43 
45 {
47  : name(name), whisper(whisper), pending_messages(0)
48  {
49  }
51  bool whisper;
53 };
54 
55 struct tplayer_list;
56 
58 {
59  void init(twindow& w, const std::string& id);
60  void show_toggle_callback(twidget& widget);
61  void auto_hide();
68 };
69 
71 {
72  void init(twindow& w);
73  void update_sort_icons();
78 
81 
83 };
84 
85 class tlobby_main : public tdialog, private events::chat_handler
86 {
87 public:
88  tlobby_main(const config& game_config, lobby_info& info, CVideo& video, twesnothd_connection &wesnothd_connection);
89 
90  ~tlobby_main();
91 
92  /**
93  * Set the callback used to show the preferences.
94  */
95  void set_preferences_callback(std::function<void()> f);
96 
97  void update_gamelist();
98 
99  void send_to_server(const config& cfg) override;
100 
101 protected:
102  void update_gamelist_header();
103 
104  void update_gamelist_diff();
105 
106  void update_gamelist_filter();
107 
108  std::map<std::string, string_map> make_game_row_data(const game_info& game);
109 
110  void adjust_game_row_contents(const game_info& game, int idx, tgrid* grid);
111 
112 public:
113  void update_playerlist();
114 
121  };
122 
124  {
125  return legacy_result_;
126  }
127 
140  };
141 
142  void do_notify(t_notify_mode mode) { do_notify(mode, "", ""); }
143  void do_notify(t_notify_mode mode, const std::string & sender, const std::string & message);
144 
145 protected:
146  /** inherited form chat_handler */
147  virtual void send_chat_message(const std::string& message,
148  bool /*allies_only*/);
149 
150  virtual void user_relation_changed(const std::string& name);
151 
152  /** inherited form chat_handler */
153  virtual void add_chat_message(const time_t& time,
154  const std::string& speaker,
155  int side,
156  const std::string& message,
159 
160  /** inherited form chat_handler */
161  virtual void add_whisper_sent(const std::string& receiver,
162  const std::string& message);
163 
164  /** inherited form chat_handler */
165  virtual void add_whisper_received(const std::string& sender,
166  const std::string& message);
167 
168  /** inherited form chat_handler */
169  virtual void add_chat_room_message_sent(const std::string& room,
170  const std::string& message);
171 
172  /** inherited form chat_handler */
173  virtual void add_chat_room_message_received(const std::string& room,
174  const std::string& speaker,
175  const std::string& message);
176 
177 private:
178  void update_selected_game();
179 
180  /**
181  * Append some text to the active chat log
182  */
183  void append_to_chatbox(const std::string& text, const bool force_scroll = false);
184 
185  /**
186  * Append some text to the chat log for window "id"
187  */
188  void append_to_chatbox(const std::string& text, size_t id, const bool force_scroll = false);
189 
190  /**
191  * Result flag for interfacing with other MP dialogs
192  */
194 
195  /**
196  * Get the room* corresponding to the currently active window, or nullptr
197  * if a whisper window is active at the moment
198  */
200 
201  /**
202  * Check if a room window for "room" is open, if open_new is true
203  * then it will be created if not found.
204  * @return valid ptr if the window was found or added, null otherwise
205  */
207  bool open_new);
208 
209  /**
210  * Check if a whisper window for user "name" is open, if open_new is true
211  * then it will be created if not found.
212  * @return valid ptr if the window was found or added, null otherwise
213  */
215  bool open_new);
216 
217  /**
218  * Helper function to find and open a new window, used by *_window_open
219  */
221  search_create_window(const std::string& name, bool whisper, bool open_new);
222 
223  /**
224  * @return true if the whisper window for "name" is the active window
225  */
227 
228  /**
229  * @return true if the room window for "room" is the active window
230  */
231  bool room_window_active(const std::string& room);
232 
233  /**
234  * Mark the whisper window for "name" as having one more pending message
235  */
237 
238  /**
239  * Mark the room window for "room" as having one more pending message
240  */
241  void increment_waiting_messages(const std::string& room);
242 
243  /**
244  * Add a whisper message to the whisper window
245  */
246  void add_whisper_window_whisper(const std::string& sender,
247  const std::string& message);
248 
249  /**
250  * Add a whisper message to the current window which is not the whisper
251  * window
252  * for "name".
253  */
254  void add_active_window_whisper(const std::string& sender,
255  const std::string& message,
256  const bool force_scroll = false);
257 
258  /**
259  * Add a message to the window for room "room"
260  */
261  void add_room_window_message(const std::string& room,
262  const std::string& sender,
263  const std::string& message);
264 
265  /**
266  * Add a message to the window for room "room"
267  */
268  void add_active_window_message(const std::string& sender,
269  const std::string& message,
270  const bool force_scroll = false);
271 
272  /**
273  * Switch to the window given by a valid pointer (e.g. received from a call
274  * to *_window_open)
275  */
277 
278  void switch_to_window(size_t id);
279 
280  void active_window_changed();
281 
282  void close_active_window();
283 
284  void close_window(size_t idx);
285 
286 
287  /**
288  * Network polling callback
289  */
290  void network_handler();
291 
292  void process_network_data(const config& data);
293 
294  void process_message(const config& data, bool whisper = false);
295 
296  void process_gamelist(const config& data);
297 
298  void process_gamelist_diff(const config& data);
299 
300  void process_room_join(const config& data);
301 
302  void process_room_part(const config& data);
303 
305 
306  void join_button_callback(twindow& window);
307 
308  void observe_button_callback(twindow& window);
309 
310  void join_global_button_callback(twindow& window);
311 
313 
314  void join_or_observe(int index);
315 
316  /**
317  * Assemble and send a game join request. Ask for password if the game
318  * requires one.
319  * @return true iff the request was actually sent, false if not for some
320  * reason like user canceled the password dialog or idx was invalid.
321  */
322  bool do_game_join(int idx, bool observe);
323 
325 
327 
328  void close_window_button_callback(size_t idx);
329 
330  void create_button_callback(twindow& window);
331 
333 
334  void refresh_button_callback(twindow& window);
335 
336  void quit_button_callback(twindow& window);
337 
338  void room_switch_callback(twindow& window);
339 
340  void chat_input_keypress_callback(bool& handled,
341  bool& halt,
342  const SDLKey key,
343  twindow& window);
344 
345  void game_filter_reload();
346 
347  void game_filter_change_callback(twidget& widget);
348 
349  void game_filter_keypress_callback(const SDLKey key);
350 
351  void gamelist_change_callback(twindow& window);
352 
353  void player_filter_callback(twidget& widget);
354 
355  void user_dialog_callback(user_info* info);
356 
358 
359  /** Inherited from tdialog, implemented by REGISTER_DIALOG. */
360  virtual const std::string& window_id() const;
361 
362  /** Inherited from tdialog. */
363  virtual void post_build(twindow& window);
364 
365  /** Inherited from tdialog. */
366  void pre_show(twindow& window);
367 
368  /** Inherited from tdialog. */
369  void post_show(twindow& window);
370 
372 
374 
376 
378 
380 
382 
384 
386 
387  std::function<void()> preferences_callback_;
388 
389  /**
390  * This represents the open chat windows (rooms and whispers at the moment)
391  * with 1 to 1 correspondence to what the user sees in the interface
392  */
393  std::vector<tlobby_chat_window> open_windows_;
394 
396 
398 
400 
402 
404 
406 
408 
410 
412 
414 
416 
418 
420 
422 
423  /** Timer for updating the lobby. */
425 
426  /** Wrapper for the preferences hotkey. */
427  std::function<void()> preferences_wrapper_;
428 
429  std::vector<int> gamelist_id_at_row_;
430 
432 
434 
436 };
437 
438 } // namespace gui2
439 
440 #endif
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: lobby.cpp:1170
tplayer_list player_list_
Definition: lobby.hpp:409
room_info * active_window_room()
Get the room* corresponding to the currently active window, or nullptr if a whisper window is active ...
Definition: lobby.cpp:1040
tlistbox * list
Definition: lobby.hpp:65
void close_active_window()
Definition: lobby.cpp:1235
bool room_window_active(const std::string &room)
Definition: lobby.cpp:1113
std::function< void()> preferences_wrapper_
Wrapper for the preferences hotkey.
Definition: lobby.hpp:427
void observe_global_button_callback(twindow &window)
Definition: lobby.cpp:1498
This class represents the information a client has about a room.
Definition: data.hpp:65
bool player_list_dirty_
Definition: lobby.hpp:411
void update_gamelist_filter()
Definition: lobby.cpp:752
ttoggle_button * sort_by_name
Definition: lobby.hpp:79
void update_gamelist()
Definition: lobby.cpp:494
void close_window(size_t idx)
Definition: lobby.cpp:1241
virtual void add_whisper_received(const std::string &sender, const std::string &message)
inherited form chat_handler
Definition: lobby.cpp:216
void quit_button_callback(twindow &window)
size_t active_window_
Definition: lobby.hpp:395
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
bool do_game_join(int idx, bool observe)
Assemble and send a game join request.
Definition: lobby.cpp:1525
void set_preferences_callback(std::function< void()> f)
Set the callback used to show the preferences.
Definition: lobby.cpp:388
void active_window_changed()
Definition: lobby.cpp:1218
logger & info()
Definition: log.cpp:91
void adjust_game_row_contents(const game_info &game, int idx, tgrid *grid)
Definition: lobby.cpp:699
Definition: video.hpp:58
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: lobby.cpp:1180
bool delay_gamelist_update_
Definition: lobby.hpp:433
void increment_waiting_whsipers(const std::string &name)
Mark the whisper window for "name" as having one more pending message.
Definition: lobby.cpp:1119
Base container class.
Definition: grid.hpp:29
ttoggle_button * filter_slots_
Definition: lobby.hpp:401
GLenum GLenum GLenum input
Definition: glew.h:10668
This class represents the collective information the client has about the players and games on the se...
Definition: info.hpp:25
void process_gamelist(const config &data)
Definition: lobby.cpp:1349
std::map< std::string, string_map > make_game_row_data(const game_info &game)
Definition: lobby.cpp:636
ttoggle_button * show_toggle
Definition: lobby.hpp:64
void send_to_server(const config &cfg) override
Definition: lobby.cpp:1768
void update_gamelist_header()
Definition: lobby.cpp:621
virtual void add_whisper_sent(const std::string &receiver, const std::string &message)
inherited form chat_handler
Definition: lobby.cpp:197
void process_gamelist_diff(const config &data)
Definition: lobby.cpp:1357
void skip_replay_changed_callback(twidget &w)
Definition: lobby.cpp:1763
void process_room_join(const config &data)
Definition: lobby.cpp:1376
void pre_show(twindow &window)
Inherited from tdialog.
Definition: lobby.cpp:903
Class for a single line text area.
Definition: text_box.hpp:118
Label showing a text.
Definition: label.hpp:29
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
GLenum mode
Definition: glew.h:2390
tlobby_chat_window * search_create_window(const std::string &name, bool whisper, bool open_new)
Helper function to find and open a new window, used by *_window_open.
Definition: lobby.cpp:1060
tlistbox * gamelistbox_
Definition: lobby.hpp:373
GLdouble GLdouble t
Definition: glew.h:1366
void init(twindow &w)
Definition: lobby.cpp:136
This class represents the information a client has about another player.
Definition: data.hpp:102
#define SDLKey
Definition: compat.hpp:29
void process_network_data(const config &data)
Definition: lobby.cpp:1306
void join_button_callback(twindow &window)
Definition: lobby.cpp:1486
void update_sort_icons()
Definition: lobby.cpp:153
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
bool gamelist_diff_update_
Definition: lobby.hpp:417
virtual void add_chat_room_message_sent(const std::string &room, const std::string &message)
inherited form chat_handler
Definition: lobby.cpp:241
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
void increment_waiting_messages(const std::string &room)
Mark the room window for "room" as having one more pending message.
Definition: lobby.cpp:1137
void send_message_button_callback(twindow &window)
Definition: lobby.cpp:1566
std::string name
Definition: lobby.hpp:50
legacy_result legacy_result_
Result flag for interfacing with other MP dialogs.
Definition: lobby.hpp:193
std::vector< int > gamelist_id_at_row_
Definition: lobby.hpp:429
ttoggle_button * filter_friends_
Definition: lobby.hpp:397
A class that represents a TCP/IP connection to the wesnothd server.
void process_message(const config &data, bool whisper=false)
Definition: lobby.cpp:1327
void join_global_button_callback(twindow &window)
Definition: lobby.cpp:1507
Abstract base class for all dialogs.
Definition: dialog.hpp:121
void init(twindow &w, const std::string &id)
Definition: lobby.cpp:76
void update_selected_game()
Definition: lobby.cpp:883
void post_show(twindow &window)
Inherited from tdialog.
Definition: lobby.cpp:1033
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
void send_message_to_active_window(const std::string &input)
Definition: lobby.cpp:1584
ttoggle_button * sort_by_relation
Definition: lobby.hpp:80
virtual void send_chat_message(const std::string &message, bool)
inherited form chat_handler
Definition: lobby.cpp:166
void process_room_part(const config &data)
Definition: lobby.cpp:1424
const config & game_config_
Definition: lobby.hpp:371
bool delay_playerlist_update_
Definition: lobby.hpp:431
virtual void user_relation_changed(const std::string &name)
Called when a processed command results in a relation (friend/ignore) change for a user whose name is...
Definition: lobby.cpp:179
The multi page class.
Definition: multi_page.hpp:37
int selected_game_id_
Definition: lobby.hpp:407
std::vector< tlobby_chat_window > open_windows_
This represents the open chat windows (rooms and whispers at the moment) with 1 to 1 correspondence t...
Definition: lobby.hpp:393
void switch_to_window(tlobby_chat_window *t)
Switch to the window given by a valid pointer (e.g.
Definition: lobby.cpp:1204
void room_switch_callback(twindow &window)
Definition: lobby.cpp:1629
tsub_player_list active_room
Definition: lobby.hpp:75
ttext_box * chat_input_
Definition: lobby.hpp:381
std::function< void()> preferences_callback_
Definition: lobby.hpp:387
void show_preferences_button_callback(twindow &window)
Definition: lobby.cpp:1613
void chat_input_keypress_callback(bool &handled, bool &halt, const SDLKey key, twindow &window)
Definition: lobby.cpp:1634
tsub_player_list other_rooms
Definition: lobby.hpp:76
ttoggle_button * filter_invert_
Definition: lobby.hpp:403
void refresh_button_callback(twindow &window)
Definition: lobby.cpp:1607
void observe_button_callback(twindow &window)
Definition: lobby.cpp:1492
tlobby_chat_window(const std::string &name, bool whisper)
Definition: lobby.hpp:46
void game_filter_reload()
Definition: lobby.cpp:1672
bool whisper_window_active(const std::string &name)
Definition: lobby.cpp:1107
lobby_info & lobby_info_
Definition: lobby.hpp:385
void close_window_button_callback(size_t idx)
Definition: lobby.cpp:1596
bool gamelist_dirty_
Definition: lobby.hpp:413
Game configuration data as global variables.
Definition: build_info.cpp:38
size_t lobby_update_timer_
Timer for updating the lobby.
Definition: lobby.hpp:424
virtual void add_chat_room_message_received(const std::string &room, const std::string &speaker, const std::string &message)
inherited form chat_handler
Definition: lobby.cpp:260
GLuint index
Definition: glew.h:1782
void network_handler()
Network polling callback.
Definition: lobby.cpp:1275
The listbox class.
Definition: listbox.hpp:39
void update_gamelist_diff()
Definition: lobby.cpp:526
virtual const std::string & window_id() const
Inherited from tdialog, implemented by REGISTER_DIALOG.
tlabel * tree_label
Definition: lobby.hpp:67
virtual void post_build(twindow &window)
Inherited from tdialog.
Definition: lobby.cpp:408
twindow * window_
Definition: lobby.hpp:383
CVideo & video_
Definition: lobby.hpp:419
void game_filter_keypress_callback(const SDLKey key)
Definition: lobby.cpp:1698
tlobby_main(const config &game_config, lobby_info &info, CVideo &video, twesnothd_connection &wesnothd_connection)
Definition: lobby.cpp:339
tlobby_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: lobby.cpp:1054
void create_button_callback(twindow &window)
Definition: lobby.cpp:1601
GLuint const GLchar * name
Definition: glew.h:1782
void update_playerlist()
Definition: lobby.cpp:763
void game_filter_change_callback(twidget &widget)
Definition: lobby.cpp:1706
This class represents the info a client has about a game on the server.
Definition: data.hpp:136
void do_notify(t_notify_mode mode)
Definition: lobby.hpp:142
tsub_player_list other_games
Definition: lobby.hpp:77
Base class for all widgets.
Definition: widget.hpp:49
tmulti_page * chat_log_container_
Definition: lobby.hpp:379
ttree_view * tree
Definition: lobby.hpp:82
void player_filter_callback(twidget &widget)
Definition: lobby.cpp:1717
void show_toggle_callback(twidget &widget)
Definition: lobby.cpp:101
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
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: lobby.cpp:1195
void add_whisper_window_whisper(const std::string &sender, const std::string &message)
Add a whisper message to the whisper window.
Definition: lobby.cpp:1156
void process_room_query_response(const config &data)
Definition: lobby.cpp:1446
ttext_box * filter_text_
Definition: lobby.hpp:405
ttoggle_button * filter_ignored_
Definition: lobby.hpp:399
tlobby_chat_window * room_window_open(const std::string &room, bool open_new)
Check if a room window for "room" is open, if open_new is true then it will be created if not found...
Definition: lobby.cpp:1048
void gamelist_change_callback(twindow &window)
Definition: lobby.cpp:1712
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
tlistbox * roomlistbox_
Definition: lobby.hpp:377
ttree_view_node * tree
Definition: lobby.hpp:66
void join_or_observe(int index)
Definition: lobby.cpp:1516
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void append_to_chatbox(const std::string &text, const bool force_scroll=false)
Append some text to the active chat log.
Definition: lobby.cpp:289
virtual void add_chat_message(const time_t &time, const std::string &speaker, int side, const std::string &message, events::chat_handler::MESSAGE_TYPE type=events::chat_handler::MESSAGE_PRIVATE)
inherited form chat_handler
Definition: lobby.cpp:184
void user_dialog_callback(user_info *info)
Definition: lobby.cpp:1728
tsub_player_list active_game
Definition: lobby.hpp:74
twesnothd_connection & wesnothd_connection_
Definition: lobby.hpp:421
unsigned last_gamelist_update_
Definition: lobby.hpp:415
tlistbox * userlistbox_
Definition: lobby.hpp:375
GLclampf f
Definition: glew.h:3024
legacy_result get_legacy_result() const
Definition: lobby.hpp:123