The Battle for Wesnoth  1.19.12+dev
lobby.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2025
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 
23 #include "quit_confirmation.hpp"
24 
26 
27 namespace gui2
28 {
29 class grid;
30 class listbox;
31 class text_box;
32 class window;
33 class chatbox;
34 
35 namespace dialogs
36 {
37 class mp_lobby : public modal_dialog, public quit_confirmation, private plugin_executor
38 {
39 public:
40  mp_lobby(mp::lobby_info& info, wesnothd_connection& connection, int& joined_game);
41 
42  ~mp_lobby();
43 
44  void update_gamelist();
45 
46 protected:
47  void update_visible_games();
48 
49  void update_gamelist_diff();
50 
52 
54 
55  void adjust_game_row_contents(const mp::game_info& game, grid* grid, bool add_callbacks = true);
56 
57 public:
58  void update_playerlist();
59 
60  enum lobby_result {
64  CREATE, /** player clicked the Create button */
66  CREATE_PRESET /** player clicked Join button on an [mp_queue] game, but there was no existing game to join */
67  };
68 
69  const std::string queue_game_scenario_id() const { return queue_game_scenario_id_; }
71  int queue_id() const { return queue_id_; }
72 
73 private:
74  void update_selected_game();
75 
76  /**
77  * Network polling callback
78  */
79  void network_handler();
80 
81  void process_network_data(const config& data);
82 
83  void process_gamelist(const config& data);
84 
85  void process_gamelist_diff(const config& data);
86 
88 
89  /**
90  * Exits the lobby and enters the given game.
91  *
92  * This assembles the game request for the server and handles any applicable
93  * pre-join actions, such as prompting the player for the game's password or
94  * informing them additional content needs installing.
95  *
96  * The lobby window will be closed on completion, assuming an error wasn't
97  * encountered.
98  *
99  * @param game Info on the game we're attempting to join.
100  * @param mode Whether joining as player, observer or whichever works.
101  */
103 
104  /** Entry wrapper for @ref enter_game, where game is located by index. */
105  void enter_game_by_index(const int index, JOIN_MODE mode);
106 
107  /** Entry wrapper for @ref enter_game, where game is located by game id. */
108  void enter_game_by_id(const int game_id, JOIN_MODE mode);
109 
110  /** Enter game by index, where index is the selected game listbox row. */
112 
114 
115  void show_server_info();
116 
117  void open_profile_url();
118 
119  void join_queue();
120 
121  void leave_queue();
122 
123  void update_queue_list();
124 
125  void open_match_history();
126 
127  void tab_switch_callback();
128 
129  void refresh_lobby();
130 
131  void game_filter_init();
132 
133  void game_filter_keypress_callback(const SDL_Keycode key);
134 
136 
138 
139  static bool logout_prompt();
140 
141  virtual const std::string& window_id() const override;
142 
143  virtual void pre_show() override;
144 
145  virtual void post_show() override;
146 
148 
150 
152 
158 
160 
162 
164 
166 
168 
169  std::chrono::steady_clock::time_point last_lobby_update_;
170 
172 
174 
175  /** Timer for updating the lobby. */
176  std::size_t lobby_update_timer_;
177 
178  std::vector<int> gamelist_id_at_row_;
179 
181 
183 
185 
189 
191 
192  static inline std::string server_information_ = "";
193  static inline std::string announcements_ = "";
194 };
195 
196 } // namespace dialogs
197 } // namespace gui2
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:158
Abstract base class for all modal dialogs.
void enter_selected_game(JOIN_MODE mode)
Enter game by index, where index is the selected game listbox row.
Definition: lobby.cpp:1022
void process_gamelist(const config &data)
Definition: lobby.cpp:879
field_bool * filter_slots_
Definition: lobby.hpp:155
void update_visible_games()
Definition: lobby.cpp:366
void update_selected_game()
Definition: lobby.cpp:537
const std::string queue_game_scenario_id() const
Definition: lobby.hpp:69
virtual void post_show() override
Actions to be taken after the window has been shown.
Definition: lobby.cpp:737
mp::lobby_info & lobby_info_
Definition: lobby.hpp:149
text_box * filter_text_
Definition: lobby.hpp:159
lobby_player_list_helper player_list_
Definition: lobby.hpp:163
void skip_replay_changed_callback()
Definition: lobby.cpp:1111
static std::string announcements_
Definition: lobby.hpp:193
virtual const std::string & window_id() const override
The ID of the window to build.
wesnothd_connection & network_connection_
Definition: lobby.hpp:173
void update_gamelist_filter()
Definition: lobby.cpp:513
field_bool * filter_friends_
Definition: lobby.hpp:153
listbox * gamelistbox_
Definition: lobby.hpp:147
void process_network_data(const config &data)
Definition: lobby.cpp:813
widget_data make_game_row_data(const mp::game_info &game)
Definition: lobby.cpp:378
field_bool * filter_ignored_
Definition: lobby.hpp:154
void game_filter_keypress_callback(const SDL_Keycode key)
Definition: lobby.cpp:1081
field_bool * filter_invert_
Definition: lobby.hpp:156
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:1010
void update_gamelist_diff()
Definition: lobby.cpp:259
void show_preferences_button_callback()
Definition: lobby.cpp:1032
static std::string server_information_
Definition: lobby.hpp:192
void enter_game(const mp::game_info &game, JOIN_MODE mode)
Exits the lobby and enters the given game.
Definition: lobby.cpp:911
std::string queue_game_scenario_id_
Definition: lobby.hpp:186
static bool logout_prompt()
Definition: lobby.cpp:63
void user_dialog_callback(const mp::user_info *info)
Definition: lobby.cpp:1088
void tab_switch_callback()
Definition: lobby.cpp:691
mp_lobby(mp::lobby_info &info, wesnothd_connection &connection, int &joined_game)
Definition: lobby.cpp:68
void process_gamelist_diff(const config &data)
Definition: lobby.cpp:889
int queue_id() const
Definition: lobby.hpp:71
std::size_t lobby_update_timer_
Timer for updating the lobby.
Definition: lobby.hpp:176
config queue_game_server_preset_
Definition: lobby.hpp:187
virtual void pre_show() override
Actions to be taken before showing the window.
Definition: lobby.cpp:557
void adjust_game_row_contents(const mp::game_info &game, grid *grid, bool add_callbacks=true)
Definition: lobby.cpp:407
const config queue_game_server_preset() const
Definition: lobby.hpp:70
std::vector< int > gamelist_id_at_row_
Definition: lobby.hpp:178
std::chrono::steady_clock::time_point last_lobby_update_
Definition: lobby.hpp:169
void network_handler()
Network polling callback.
Definition: lobby.cpp:752
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:999
@ RELOAD_CONFIG
player clicked the Create button
Definition: lobby.hpp:65
@ CREATE_PRESET
player clicked Join button on an [mp_queue] game, but there was no existing game to join
Definition: lobby.hpp:66
Specialized field class for boolean.
Definition: field.hpp:488
Base container class.
Definition: grid.hpp:32
The listbox class.
Definition: listbox.hpp:41
A widget that allows the user to input text in single line.
Definition: text_box.hpp:125
show_mode mode() const
Returns the dialog mode for this window.
Definition: window.hpp:695
This class represents the collective information the client has about the players and games on the se...
Definition: lobby_info.hpp:31
Implements a quit confirmation dialog.
A class that represents a TCP/IP connection to the wesnothd server.
Various uncategorised dialogs.
Generic file dialog.
std::map< std::string, widget_item > widget_data
Definition: widget.hpp:36
logger & info()
Definition: log.cpp:318
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:70
std::string_view data
Definition: picture.cpp:188
This class represents the info a client has about a game on the server.
Definition: lobby_data.hpp:62
This class represents the information a client has about another player.
Definition: lobby_data.hpp:29