The Battle for Wesnoth  1.17.0-dev
lobby.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
3  by Tomasz Sniatowski <kailoran@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "chat_events.hpp"
25 #include "quit_confirmation.hpp"
26 
28 
29 namespace gui2
30 {
31 class grid;
32 class listbox;
33 class text_box;
34 class window;
35 class chatbox;
36 
37 namespace dialogs
38 {
39 class mp_lobby : public modal_dialog, public quit_confirmation, private plugin_executor
40 {
41 public:
42  mp_lobby(mp::lobby_info& info, wesnothd_connection& connection, int& joined_game);
43 
44  ~mp_lobby();
45 
46  void update_gamelist();
47 
48 protected:
50 
51  void update_gamelist_diff();
52 
54 
55  std::map<std::string, string_map> make_game_row_data(const mp::game_info& game);
56 
57  void adjust_game_row_contents(const mp::game_info& game, grid* grid, bool add_callbacks = true);
58 
59 public:
60  void update_playerlist();
61 
62  enum lobby_result {
68  };
69 
70 private:
71  void update_selected_game();
72 
73  /**
74  * Network polling callback
75  */
76  void network_handler();
77 
78  void process_network_data(const config& data);
79 
80  void process_gamelist(const config& data);
81 
82  void process_gamelist_diff(const config& data);
83 
85 
86  /**
87  * Exits the lobby and enters the given game.
88  *
89  * This assembles the game request for the server and handles any applicable
90  * pre-join actions, such as prompting the player for the game's password or
91  * informing them additional content needs installing.
92  *
93  * The lobby window will be closed on completion, assuming an error wasn't
94  * encountered.
95  *
96  * @param game Info on the game we're attempting to join.
97  * @param mode Whether joining as player, observer or whichever works.
98  */
99  void enter_game(const mp::game_info& game, JOIN_MODE mode);
100 
101  /** Entry wrapper for @ref enter_game, where game is located by index. */
102  void enter_game_by_index(const int index, JOIN_MODE mode);
103 
104  /** Entry wrapper for @ref enter_game, where game is located by game id. */
105  void enter_game_by_id(const int game_id, JOIN_MODE mode);
106 
107  /** Enter game by index, where index is the selected game listbox row. */
108  void enter_selected_game(JOIN_MODE mode);
109 
110  void show_help_callback();
111 
113 
114  void show_server_info();
115 
116  void refresh_lobby();
117 
118  void game_filter_init();
119 
121 
122  void game_filter_keypress_callback(const SDL_Keycode key);
123 
125 
126  void player_filter_callback();
127 
129 
131 
132  bool exit_hook(window& window);
133 
134  static bool logout_prompt();
135 
136  virtual const std::string& window_id() const override;
137 
138  virtual void post_build(window& window) override;
139 
140  virtual void pre_show(window& window) override;
141 
142  virtual void post_show(window& window) override;
143 
145 
147 
149 
154 
156 
158 
160 
162 
164 
166 
168 
170 
171  /** Timer for updating the lobby. */
172  std::size_t lobby_update_timer_;
173 
174  std::vector<int> gamelist_id_at_row_;
175 
177 
179 
181 
183 
184  static inline std::string server_information_ = "";
185  static inline std::string announcements_ = "";
186 };
187 
188 } // namespace dialogs
189 } // namespace gui2
void game_filter_keypress_callback(const SDL_Keycode key)
Definition: lobby.cpp:966
static std::string announcements_
Definition: lobby.hpp:185
void skip_replay_changed_callback()
Definition: lobby.cpp:1012
field_bool * filter_invert_
Definition: lobby.hpp:153
std::vector< int > gamelist_id_at_row_
Definition: lobby.hpp:174
void enter_game_by_index(const int index, JOIN_MODE mode)
Entry wrapper for enter_game, where game is located by index.
Definition: lobby.cpp:864
std::size_t lobby_update_timer_
Timer for updating the lobby.
Definition: lobby.hpp:172
text_box * filter_text_
Definition: lobby.hpp:155
Specialized field class for boolean.
Definition: field.hpp:545
logger & info()
Definition: log.cpp:89
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:141
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
Definition: lobby.cpp:568
static std::string server_information_
Definition: lobby.hpp:184
This class represents the collective information the client has about the players and games on the se...
Definition: lobby_info.hpp:31
virtual const std::string & window_id() const override
The id of the window to build.
void user_dialog_callback(mp::user_info *info)
Definition: lobby.cpp:989
void adjust_game_row_contents(const mp::game_info &game, grid *grid, bool add_callbacks=true)
Definition: lobby.cpp:411
static bool logout_prompt()
Definition: lobby.cpp:67
void process_network_data(const config &data)
Definition: lobby.cpp:736
void update_selected_game()
Definition: lobby.cpp:543
void enter_selected_game(JOIN_MODE mode)
Enter game by index, where index is the selected game listbox row.
Definition: lobby.cpp:887
field_bool * filter_ignored_
Definition: lobby.hpp:151
Class for a single line text area.
Definition: text_box.hpp:141
void update_gamelist_header()
Definition: lobby.cpp:372
Generic file dialog.
Definition: field-fwd.hpp:23
void gamelist_change_callback()
Definition: lobby.cpp:978
The listbox class.
Definition: listbox.hpp:43
Base container class.
Definition: grid.hpp:31
listbox * gamelistbox_
Definition: lobby.hpp:144
void enter_game_by_id(const int game_id, JOIN_MODE mode)
Entry wrapper for enter_game, where game is located by game id.
Definition: lobby.cpp:875
Implements a quit confirmation dialog.
void show_preferences_button_callback()
Definition: lobby.cpp:902
A class that represents a TCP/IP connection to the wesnothd server.
void update_gamelist_filter()
Definition: lobby.cpp:517
void player_filter_callback()
Definition: lobby.cpp:983
void process_gamelist_diff(const config &data)
Definition: lobby.cpp:767
void update_gamelist_diff()
Definition: lobby.cpp:264
std::map< std::string, string_map > make_game_row_data(const mp::game_info &game)
Definition: lobby.cpp:382
lobby_player_list_helper player_list_
Definition: lobby.hpp:159
Various uncategorised dialogs.
void network_handler()
Network polling callback.
Definition: lobby.cpp:700
void enter_game(const mp::game_info &game, JOIN_MODE mode)
Exits the lobby and enters the given game.
Definition: lobby.cpp:789
void game_filter_change_callback()
Definition: lobby.cpp:973
unsigned last_lobby_update_
Definition: lobby.hpp:165
mp_lobby(mp::lobby_info &info, wesnothd_connection &connection, int &joined_game)
Definition: lobby.cpp:72
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
void process_gamelist(const config &data)
Definition: lobby.cpp:757
bool grid()
Definition: general.cpp:535
This class represents the information a client has about another player.
Definition: lobby_data.hpp:105
virtual void post_build(window &window) override
Actions to be taken directly after the window is build.
Definition: lobby.cpp:137
field_bool * filter_slots_
Definition: lobby.hpp:152
Abstract base class for all modal dialogs.
wesnothd_connection & network_connection_
Definition: lobby.hpp:169
field_bool * filter_friends_
Definition: lobby.hpp:150
mp::lobby_info & lobby_info_
Definition: lobby.hpp:146
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
Definition: lobby.cpp:693
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
bool exit_hook(window &window)
Definition: lobby.cpp:563