The Battle for Wesnoth  1.15.11+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 
60 
62 };
63 
64 class mp_lobby : public modal_dialog, public quit_confirmation, private plugin_executor
65 {
66 public:
67  mp_lobby(mp::lobby_info& info, wesnothd_connection& connection, int& joined_game);
68 
69  ~mp_lobby();
70 
71  void update_gamelist();
72 
73 protected:
74  void update_gamelist_header();
75 
76  void update_gamelist_diff();
77 
78  void update_gamelist_filter();
79 
80  std::map<std::string, string_map> make_game_row_data(const mp::game_info& game);
81 
82  void adjust_game_row_contents(const mp::game_info& game, grid* grid, bool add_callbacks = true);
83 
84 public:
85  void update_playerlist();
86 
87  enum lobby_result {
92  RELOAD_CONFIG
93  };
94 
95 protected:
96 
97 private:
98  void update_selected_game();
99 
100  /**
101  * Network polling callback
102  */
103  void network_handler();
104 
105  void process_network_data(const config& data);
106 
107  void process_gamelist(const config& data);
108 
109  void process_gamelist_diff(const config& data);
110 
111  enum JOIN_MODE { DO_JOIN, DO_OBSERVE, DO_EITHER };
112 
113  /**
114  * Exits the lobby and enters the given game.
115  *
116  * This assembles the game request for the server and handles any applicable
117  * pre-join actions, such as prompting the player for the game's password or
118  * informing them additional content needs installing.
119  *
120  * The lobby window will be closed on completion, assuming an error wasn't
121  * encountered.
122  *
123  * @param game Info on the game we're attempting to join.
124  * @param mode Whether joining as player, observer or whichever works.
125  */
126  void enter_game(const mp::game_info& game, JOIN_MODE mode);
127 
128  /** Entry wrapper for @ref enter_game, where game is located by index. */
129  void enter_game_by_index(const int index, JOIN_MODE mode);
130 
131  /** Entry wrapper for @ref enter_game, where game is located by game id. */
132  void enter_game_by_id(const int game_id, JOIN_MODE mode);
133 
134  /** Enter game by index, where index is the selected game listbox row. */
135  void enter_selected_game(JOIN_MODE mode);
136 
137  void show_help_callback();
138 
139  void show_preferences_button_callback();
140 
141  void show_server_info();
142 
143  void refresh_lobby();
144 
145  void game_filter_reload();
146 
147  void game_filter_change_callback();
148 
149  void game_filter_keypress_callback(const SDL_Keycode key);
150 
151  void gamelist_change_callback();
152 
153  void player_filter_callback();
154 
155  void user_dialog_callback(mp::user_info* info);
156 
157  void skip_replay_changed_callback();
158 
159  bool exit_hook(window& window);
160 
161  static bool logout_prompt();
162 
163  virtual const std::string& window_id() const override;
164 
165  virtual void post_build(window& window) override;
166 
167  virtual void pre_show(window& window) override;
168 
169  virtual void post_show(window& window) override;
170 
172 
174 
176 
178 
183 
185 
187 
189 
191 
193 
195 
197 
199 
200  /** Timer for updating the lobby. */
201  std::size_t lobby_update_timer_;
202 
203  std::vector<int> gamelist_id_at_row_;
204 
206 
208 
210 
212 
213  static std::string server_information_;
214  static std::string announcements_;
215 };
216 
217 } // namespace dialogs
218 } // namespace gui2
static std::string announcements_
Definition: lobby.hpp:214
field_bool * filter_invert_
Definition: lobby.hpp:182
std::vector< int > gamelist_id_at_row_
Definition: lobby.hpp:203
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:201
text_box * filter_text_
Definition: lobby.hpp:184
sub_player_list active_room
Definition: lobby.hpp:57
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:141
static std::string server_information_
Definition: lobby.hpp:213
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:171
field_bool * filter_ignored_
Definition: lobby.hpp:180
Class for a single line text area.
Definition: text_box.hpp:140
Generic file dialog.
Definition: field-fwd.hpp:22
sub_player_list other_rooms
Definition: lobby.hpp:58
The listbox class.
Definition: listbox.hpp:42
Base container class.
Definition: grid.hpp:30
listbox * gamelistbox_
Definition: lobby.hpp:173
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:59
unsigned last_lobby_update_
Definition: lobby.hpp:194
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:188
bool grid()
Definition: general.cpp:519
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:181
Abstract base class for all modal dialogs.
wesnothd_connection & network_connection_
Definition: lobby.hpp:198
field_bool * filter_friends_
Definition: lobby.hpp:179
mp::lobby_info & lobby_info_
Definition: lobby.hpp:175
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