The Battle for Wesnoth  1.17.0-dev
lobby.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Tomasz Sniatowski <kailoran@gmail.com>
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 #pragma once
16 
19 #include "chat_events.hpp"
23 #include "quit_confirmation.hpp"
24 
26 class game_config_view;
27 
28 namespace gui2
29 {
30 
31 class grid;
32 class label;
33 class listbox;
34 class text_box;
35 class window;
36 class multi_page;
37 class toggle_button;
38 class chatbox;
39 
40 namespace dialogs
41 {
42 
44 {
45  void init(window& w, const std::string& label, const bool unfolded = false);
48  label* tree_label;
50 };
51 
53 {
54  void init(window& w);
55 
59 
61 };
62 
63 class mp_lobby : public modal_dialog, public quit_confirmation, private plugin_executor
64 {
65 public:
66  mp_lobby(mp::lobby_info& info, wesnothd_connection& connection, int& joined_game);
67 
68  ~mp_lobby();
69 
70  void update_gamelist();
71 
72 protected:
73  void update_gamelist_header();
74 
75  void update_gamelist_diff();
76 
77  void update_gamelist_filter();
78 
79  std::map<std::string, string_map> make_game_row_data(const mp::game_info& game);
80 
81  void adjust_game_row_contents(const mp::game_info& game, grid* grid, bool add_callbacks = true);
82 
83 public:
84  void update_playerlist();
85 
86  enum lobby_result {
91  RELOAD_CONFIG
92  };
93 
94 protected:
95 
96 private:
97  void update_selected_game();
98 
99  /**
100  * Network polling callback
101  */
102  void network_handler();
103 
104  void process_network_data(const config& data);
105 
106  void process_gamelist(const config& data);
107 
108  void process_gamelist_diff(const config& data);
109 
110  enum JOIN_MODE { DO_JOIN, DO_OBSERVE, DO_EITHER };
111 
112  /**
113  * Exits the lobby and enters the given game.
114  *
115  * This assembles the game request for the server and handles any applicable
116  * pre-join actions, such as prompting the player for the game's password or
117  * informing them additional content needs installing.
118  *
119  * The lobby window will be closed on completion, assuming an error wasn't
120  * encountered.
121  *
122  * @param game Info on the game we're attempting to join.
123  * @param mode Whether joining as player, observer or whichever works.
124  */
125  void enter_game(const mp::game_info& game, JOIN_MODE mode);
126 
127  /** Entry wrapper for @ref enter_game, where game is located by index. */
128  void enter_game_by_index(const int index, JOIN_MODE mode);
129 
130  /** Entry wrapper for @ref enter_game, where game is located by game id. */
131  void enter_game_by_id(const int game_id, JOIN_MODE mode);
132 
133  /** Enter game by index, where index is the selected game listbox row. */
134  void enter_selected_game(JOIN_MODE mode);
135 
136  void show_help_callback();
137 
138  void show_preferences_button_callback();
139 
140  void show_server_info();
141 
142  void refresh_lobby();
143 
144  void game_filter_reload();
145 
146  void game_filter_change_callback();
147 
148  void game_filter_keypress_callback(const SDL_Keycode key);
149 
150  void gamelist_change_callback();
151 
152  void player_filter_callback();
153 
154  void user_dialog_callback(mp::user_info* info);
155 
156  void skip_replay_changed_callback();
157 
158  bool exit_hook(window& window);
159 
160  static bool logout_prompt();
161 
162  virtual const std::string& window_id() const override;
163 
164  virtual void post_build(window& window) override;
165 
166  virtual void pre_show(window& window) override;
167 
168  virtual void post_show(window& window) override;
169 
171 
173 
175 
177 
182 
184 
186 
188 
190 
192 
194 
196 
198 
199  /** Timer for updating the lobby. */
200  std::size_t lobby_update_timer_;
201 
202  std::vector<int> gamelist_id_at_row_;
203 
205 
207 
209 
211 
212  static std::string server_information_;
213  static std::string announcements_;
214 };
215 
216 } // namespace dialogs
217 } // namespace gui2
static std::string announcements_
Definition: lobby.hpp:213
field_bool * filter_invert_
Definition: lobby.hpp:181
std::vector< int > gamelist_id_at_row_
Definition: lobby.hpp:202
void init(window &w, const std::string &label, const bool unfolded=false)
Definition: lobby.cpp:69
std::size_t lobby_update_timer_
Timer for updating the lobby.
Definition: lobby.hpp:200
text_box * filter_text_
Definition: lobby.hpp:183
Specialized field class for boolean.
Definition: field.hpp:544
logger & info()
Definition: log.cpp:88
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:140
static std::string server_information_
Definition: lobby.hpp:212
This class represents the collective information the client has about the players and games on the se...
Definition: lobby_info.hpp:30
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
const game_config_view & game_config_
Definition: lobby.hpp:170
field_bool * filter_ignored_
Definition: lobby.hpp:179
Class for a single line text area.
Definition: text_box.hpp:140
Generic file dialog.
Definition: field-fwd.hpp:22
The listbox class.
Definition: listbox.hpp:42
Base container class.
Definition: grid.hpp:30
listbox * gamelistbox_
Definition: lobby.hpp:172
sub_player_list lobby_players
Definition: lobby.hpp:57
std::string label
What to show in the filter&#39;s drop-down list.
Definition: manager.cpp:216
Implements a quit confirmation dialog.
A class that represents a TCP/IP connection to the wesnothd server.
A tree view is a control that holds several items of the same or different types. ...
Definition: tree_view.hpp:59
Various uncategorised dialogs.
int w
sub_player_list other_games
Definition: lobby.hpp:58
unsigned last_lobby_update_
Definition: lobby.hpp:193
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:71
player_list player_list_
Definition: lobby.hpp:187
bool grid()
Definition: general.cpp:524
This class represents the information a client has about another player.
Definition: lobby_data.hpp:104
tree_view_node * tree
Definition: lobby.hpp:47
sub_player_list active_game
Definition: lobby.hpp:56
field_bool * filter_slots_
Definition: lobby.hpp:180
Abstract base class for all modal dialogs.
wesnothd_connection & network_connection_
Definition: lobby.hpp:197
field_bool * filter_friends_
Definition: lobby.hpp:178
mp::lobby_info & lobby_info_
Definition: lobby.hpp:174
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:64