The Battle for Wesnoth  1.15.1+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 namespace gui2
27 {
28 
29 class grid;
30 class label;
31 class listbox;
32 class text_box;
33 class window;
34 class multi_page;
35 class toggle_button;
36 class chatbox;
37 
38 namespace dialogs
39 {
40 
42 {
43  void init(window& w, const std::string& label, const bool unfolded = false);
46  label* tree_label;
48 };
49 
51 {
52  void init(window& w);
53 
58 
60 };
61 
62 class mp_lobby : public modal_dialog, public quit_confirmation, private plugin_executor
63 {
64 public:
66 
67  ~mp_lobby();
68 
69  int get_joined_game_id() const { return joined_game_id_; }
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_preferences_button_callback(window& window);
138 
139  void refresh_lobby();
140 
141  void game_filter_reload();
142 
143  void game_filter_change_callback();
144 
145  void game_filter_keypress_callback(const SDL_Keycode key);
146 
147  void gamelist_change_callback();
148 
149  void player_filter_callback();
150 
151  void user_dialog_callback(mp::user_info* info);
152 
153  void skip_replay_changed_callback(window& window);
154 
155  bool exit_hook(window& window);
156 
157  static bool logout_prompt();
158 
159  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
160  virtual const std::string& window_id() const override;
161 
162  /** Inherited from modal_dialog. */
163  virtual void post_build(window& window) override;
164 
165  /** Inherited from modal_dialog. */
166  virtual void pre_show(window& window) override;
167 
168  /** Inherited from modal_dialog. */
169  virtual void post_show(window& window) override;
170 
172 
174 
176 
178 
180 
182 
184 
186 
188 
190 
192 
194 
196 
198 
200 
202 
203  /** Timer for updating the lobby. */
204  std::size_t lobby_update_timer_;
205 
206  std::vector<int> gamelist_id_at_row_;
207 
209 
211 
213 
215 };
216 
217 } // namespace dialogs
218 } // namespace gui2
int get_joined_game_id() const
Definition: lobby.hpp:69
std::vector< int > gamelist_id_at_row_
Definition: lobby.hpp:206
void init(window &w, const std::string &label, const bool unfolded=false)
Definition: lobby.cpp:65
std::size_t lobby_update_timer_
Timer for updating the lobby.
Definition: lobby.hpp:204
text_box * filter_text_
Definition: lobby.hpp:187
sub_player_list active_room
Definition: lobby.hpp:55
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
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
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:56
The listbox class.
Definition: listbox.hpp:40
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.
Various uncategorised dialogs.
Game configuration data as global variables.
Definition: build_info.cpp:49
toggle_button * filter_invert_
Definition: lobby.hpp:185
int w
sub_player_list other_games
Definition: lobby.hpp:57
unsigned last_lobby_update_
Definition: lobby.hpp:197
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:191
-file mapgen.hpp
bool grid()
Definition: general.cpp:505
This class represents the information a client has about another player.
Definition: lobby_data.hpp:104
tree_view_node * tree
Definition: lobby.hpp:45
sub_player_list active_game
Definition: lobby.hpp:54
Abstract base class for all modal dialogs.
wesnothd_connection & network_connection_
Definition: lobby.hpp:201
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:92
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63
toggle_button * filter_ignored_
Definition: lobby.hpp:181
Class for a toggle button.
toggle_button * filter_friends_
Definition: lobby.hpp:179
const config & game_config_
Definition: lobby.hpp:171
toggle_button * filter_slots_
Definition: lobby.hpp:183