The Battle for Wesnoth  1.15.5+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:
68 
69  ~mp_lobby();
70 
71  int get_joined_game_id() const { return joined_game_id_; }
72 
73  void update_gamelist();
74 
75 protected:
76  void update_gamelist_header();
77 
78  void update_gamelist_diff();
79 
80  void update_gamelist_filter();
81 
82  std::map<std::string, string_map> make_game_row_data(const mp::game_info& game);
83 
84  void adjust_game_row_contents(const mp::game_info& game, grid* grid, bool add_callbacks = true);
85 
86 public:
87  void update_playerlist();
88 
89  enum lobby_result {
94  RELOAD_CONFIG
95  };
96 
97 protected:
98 
99 private:
100  void update_selected_game();
101 
102  /**
103  * Network polling callback
104  */
105  void network_handler();
106 
107  void process_network_data(const config& data);
108 
109  void process_gamelist(const config& data);
110 
111  void process_gamelist_diff(const config& data);
112 
113  enum JOIN_MODE { DO_JOIN, DO_OBSERVE, DO_EITHER };
114 
115  /**
116  * Exits the lobby and enters the given game.
117  *
118  * This assembles the game request for the server and handles any applicable
119  * pre-join actions, such as prompting the player for the game's password or
120  * informing them additional content needs installing.
121  *
122  * The lobby window will be closed on completion, assuming an error wasn't
123  * encountered.
124  *
125  * @param game Info on the game we're attempting to join.
126  * @param mode Whether joining as player, observer or whichever works.
127  */
128  void enter_game(const mp::game_info& game, JOIN_MODE mode);
129 
130  /** Entry wrapper for @ref enter_game, where game is located by index. */
131  void enter_game_by_index(const int index, JOIN_MODE mode);
132 
133  /** Entry wrapper for @ref enter_game, where game is located by game id. */
134  void enter_game_by_id(const int game_id, JOIN_MODE mode);
135 
136  /** Enter game by index, where index is the selected game listbox row. */
137  void enter_selected_game(JOIN_MODE mode);
138 
139  void show_preferences_button_callback(window& window);
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(window& window);
158 
159  bool exit_hook(window& window);
160 
161  static bool logout_prompt();
162 
163  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
164  virtual const std::string& window_id() const override;
165 
166  /** Inherited from modal_dialog. */
167  virtual void post_build(window& window) override;
168 
169  /** Inherited from modal_dialog. */
170  virtual void pre_show(window& window) override;
171 
172  /** Inherited from modal_dialog. */
173  virtual void post_show(window& window) override;
174 
176 
178 
180 
182 
184 
186 
188 
190 
192 
194 
196 
198 
200 
202 
204 
206 
207  /** Timer for updating the lobby. */
208  std::size_t lobby_update_timer_;
209 
210  std::vector<int> gamelist_id_at_row_;
211 
213 
215 
217 
219 
222 };
223 
224 } // namespace dialogs
225 } // namespace gui2
int get_joined_game_id() const
Definition: lobby.hpp:71
static std::string announcements_
Definition: lobby.hpp:221
std::vector< int > gamelist_id_at_row_
Definition: lobby.hpp:210
void init(window &w, const std::string &label, const bool unfolded=false)
Definition: lobby.cpp:67
std::size_t lobby_update_timer_
Timer for updating the lobby.
Definition: lobby.hpp:208
text_box * filter_text_
Definition: lobby.hpp:191
sub_player_list active_room
Definition: lobby.hpp:57
logger & info()
Definition: log.cpp:90
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:138
static std::string server_information_
Definition: lobby.hpp:220
This class represents the collective information the client has about the players and games on the se...
Definition: lobby_info.hpp:30
Label showing a text.
Definition: label.hpp:32
const game_config_view & game_config_
Definition: lobby.hpp:175
Class for a single line text area.
Definition: text_box.hpp:121
Generic file dialog.
Definition: field-fwd.hpp:22
sub_player_list other_rooms
Definition: lobby.hpp:58
The listbox class.
Definition: listbox.hpp:40
Base container class.
Definition: grid.hpp:30
listbox * gamelistbox_
Definition: lobby.hpp:177
Implements a quit confirmation dialog.
A class that represents a TCP/IP connection to the wesnothd server.
Various uncategorised dialogs.
Game configuration data as global variables.
Definition: build_info.cpp:55
toggle_button * filter_invert_
Definition: lobby.hpp:189
int w
sub_player_list other_games
Definition: lobby.hpp:59
unsigned last_lobby_update_
Definition: lobby.hpp:201
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:195
-file mapgen.hpp
bool grid()
Definition: general.cpp:506
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
Abstract base class for all modal dialogs.
wesnothd_connection & network_connection_
Definition: lobby.hpp:205
mp::lobby_info & lobby_info_
Definition: lobby.hpp:179
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
toggle_button * filter_ignored_
Definition: lobby.hpp:185
Class for a toggle button.
toggle_button * filter_friends_
Definition: lobby.hpp:183
toggle_button * filter_slots_
Definition: lobby.hpp:187