The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
multiplayer_lobby.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2007 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://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 /** @file multiplayer_lobby.hpp */
16 
17 #ifndef MULTIPLAYER_LOBBY_HPP_INCLUDED
18 #define MULTIPLAYER_LOBBY_HPP_INCLUDED
19 
20 #include "multiplayer_ui.hpp"
21 #include "game_preferences.hpp"
22 #include "image.hpp"
24 
25 class config;
26 class video;
27 class CVideo;
28 
29 /**
30  * This module controls the multiplayer lobby.
31  *
32  * A section on the server which allows players to chat, create games, and join
33  * games.
34  */
35 namespace mp {
36 
38 
43 };
44 
45 class gamebrowser : public gui::menu {
46 public:
47  struct game_item {
48 
50  mini_map(),
51  id(),
52  map_data(),
53  name(),
54  map_info(),
55  map_info_size(),
57  gold(),
58  xp(),
59  vision(),
60  status(),
61  time_limit(),
62  vacant_slots(0),
63  current_turn(0),
64  reloaded(false),
65  started(false),
66  fog(false),
67  shroud(false),
68  observers(false),
69  shuffle_sides(false),
70  use_map_settings(false),
71  verified(false),
72  password_required(false),
73  have_scenario(false),
74  have_era(false),
75  have_all_mods(false),
76  addons(),
78  {
79  }
80 
93  size_t vacant_slots;
94  unsigned int current_turn;
95  bool reloaded;
96  bool started;
97  bool fog;
98  bool shroud;
99  bool observers;
103  bool verified;
106  bool have_era;
108  std::vector<required_addon> addons;
110  };
111  gamebrowser(CVideo& video, const config &map_hashes);
112  void scroll(unsigned int pos);
113  void handle_event(const SDL_Event& event);
114  void set_inner_location(const SDL_Rect& rect);
115  void set_item_height(unsigned int height);
116 
117  void populate_game_item(game_item &, const config &, const config &, const std::vector<std::string> &);
118  void populate_game_item_campaign_or_scenario_info(game_item &, const config &, const config &, bool &);
119  void populate_game_item_map_info(game_item &, const config &, const config &, bool &);
120  void populate_game_item_era_info(game_item &, const config &, const config &, bool &);
121  void populate_game_item_mod_info(game_item &, const config &, const config &, bool &);
122  void populate_game_item_addons_installed(game_item &, const config &, const std::vector<std::string> &);
123 
124  void set_game_items(const config& cfg, const config& game_config, const std::vector<std::string> & installed_addons);
125  void draw();
126  void draw_contents();
127  void draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type);
128  SDL_Rect get_item_rect(size_t index) const;
129  bool empty() const { return games_.empty(); }
135  { return empty() ? false : !games_[selected_].have_era ||
136  !games_[selected_].have_all_mods ||
137  !games_[selected_].have_scenario; }
139  { return empty() ? false : (games_[selected_].addons_outcome != SATISFIED); }
141  { return empty() ? false : (games_[selected_].vacant_slots > 0 && !games_[selected_].started); }
142  // Moderators may observe any game.
144  { return empty() ? false : (games_[selected_].observers || preferences::is_authenticated()); }
145 
147  { return empty() ? SATISFIED : games_[selected_].addons_outcome; }
148  const std::vector<required_addon> * selection_addon_requirements() const
149  { return empty() ? nullptr : &games_[selected_].addons; }
150  bool selected() const { return double_clicked_ && !empty(); }
151  void reset_selection() { double_clicked_ = false; }
152  int selection() const { return selected_; }
154  void select_game(const std::string& id);
155  bool game_matches_filter(const game_item& i, const config& cfg);
156 
157 protected:
158  unsigned int row_height() const { return item_height_ + (2 * style_->get_thickness()); }
159 private:
168 
170 
171  unsigned int item_height_;
172  int margin_;
177  size_t selected_;
178  std::pair<size_t, size_t> visible_range_;
179  std::vector<game_item> games_;
180  std::vector<size_t> redraw_items_;
181  std::vector<int> widths_;
185 };
186 
187 class lobby : public ui
188 {
189 public:
190  lobby(CVideo& v, twesnothd_connection* wesnothd_connection, const config& cfg, chat& c, config& gamelist, const std::vector<std::string> & installed_addons);
191 
192  virtual void process_event();
193 
195 protected:
196  virtual void hide_children(bool hide=true);
197  virtual void layout_children(const SDL_Rect& rect);
198  virtual void process_network_data(const config& data);
199 
200  virtual void gamelist_updated(bool silent=true);
201 private:
202 
204  {
205  const config& cfg_;
206 
207  bool column_sortable(int column) const;
208  bool less(int column, const gui::menu::item& row1, const gui::menu::item& row2) const;
209 
210  enum { MAP_COLUMN = 0, STATUS_COLUMN = 2};
211  public:
212  lobby_sorter(const config& cfg);
213  };
214 
215  std::vector<bool> game_vacant_slots_;
216  std::vector<bool> game_observers_;
217 
224 
231 
233 
236 
237  std::map<std::string,std::string> minimaps_;
238 
240 
241  const std::vector<std::string> & installed_addons_;
242 
244  bool join;
245  bool observe;
246  bool create;
247  bool quit;
248 
250  : join(false), observe(false), create(false), quit(false)
251  {}
252 
253  process_event_data(bool j, bool o, bool c, bool q)
254  : join(j), observe(o), create(c), quit(q)
255  {}
256  };
257 
258  // This is added to make it easier for plugins to trigger events, and to separate some of the "controller" from the internal logic
259  void process_event_impl(const process_event_data &);
260  bool plugin_event_helper(const process_event_data &);
261 };
262 
263 } // end namespace mp
264 
265 #endif
void populate_game_item_campaign_or_scenario_info(game_item &, const config &, const config &, bool &)
image::locator time_limit_icon_locator_
gui::label filter_label_
virtual void process_event()
image::locator shuffle_sides_icon_locator_
unsigned int row_height() const
bool plugin_event_helper(const process_event_data &)
std::string search_string_
const GLfloat * c
Definition: glew.h:12741
int pos
Definition: formula.cpp:800
std::vector< bool > game_observers_
void set_inner_location(const SDL_Rect &rect)
std::vector< size_t > redraw_items_
void set_item_height(unsigned int height)
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1221
void populate_game_item(game_item &, const config &, const config &, const std::vector< std::string > &)
Definition: video.hpp:58
std::vector< game_item > games_
gui::button friends_in_game_
ROW_TYPE
Definition: menu.hpp:32
std::vector< bool > game_vacant_slots_
CVideo & video() const
Definition: widget.hpp:83
bool selection_in_observable_state() const
void draw_row(const size_t row_index, const SDL_Rect &rect, ROW_TYPE type)
gui::button observe_game_
lobby_sorter sorter_
const std::vector< required_addon > * selection_addon_requirements() const
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
bool selected() const
void process_event_impl(const process_event_data &)
game_item selected_game()
lobby_sorter(const config &cfg)
std::vector< required_addon > addons
GLdouble GLdouble GLdouble GLdouble q
Definition: glew.h:1382
This module controls the multiplayer lobby.
bool selection_is_joinable() const
gui::button join_game_
void set_game_items(const config &cfg, const config &game_config, const std::vector< std::string > &installed_addons)
A class that represents a TCP/IP connection to the wesnothd server.
image::locator xp_icon_locator_
GLuint id
Definition: glew.h:1647
const std::vector< std::string > & installed_addons_
virtual void hide(bool value=true)
Definition: widget.cpp:162
const GLdouble * v
Definition: glew.h:1359
virtual void hide_children(bool hide=true)
Hides or shows all gui::widget children of this widget.
process_event_data(bool j, bool o, bool c, bool q)
size_t get_thickness() const
Definition: menu_style.cpp:62
bool selection_is_observable() const
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
Definition: manager.cpp:150
unsigned int item_height_
void handle_event(const SDL_Event &event)
void scroll(unsigned int pos)
bool selection_needs_content() const
gui::button create_game_
image::locator vision_icon_locator_
int selection() const
gui::button apply_filter_
gamebrowser games_menu_
gui::button quit_game_
bool less(int column, const gui::menu::item &row1, const gui::menu::item &row2) const
GLenum GLenum GLvoid GLvoid * column
Definition: glew.h:3805
std::map< std::string, std::string > minimaps_
gui::button game_preferences_
gui::combo replay_options_
lobby(CVideo &v, twesnothd_connection *wesnothd_connection, const config &cfg, chat &c, config &gamelist, const std::vector< std::string > &installed_addons)
image::locator map_size_icon_locator_
std::pair< size_t, size_t > visible_range_
Game configuration data as global variables.
Definition: build_info.cpp:38
GLuint index
Definition: glew.h:1782
ADDON_REQ selection_addon_outcome() const
config & gamelist()
Returns the current gamelist.
bool selection_needs_addons() const
size_t i
Definition: function.cpp:1057
std::vector< int > widths_
gui::button vacant_slots_
void populate_game_item_era_info(game_item &, const config &, const config &, bool &)
void populate_game_item_map_info(game_item &, const config &, const config &, bool &)
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
GLuint const GLchar * name
Definition: glew.h:1782
gui::button invert_filter_
gamebrowser(CVideo &video, const config &map_hashes)
image::locator observer_icon_locator_
SDL_Rect get_item_rect(size_t index) const
image::locator gold_icon_locator_
cl_event event
Definition: glew.h:3070
bool column_sortable(int column) const
virtual void process_network_data(const config &data)
Processes any pending network data.
image::locator no_observer_icon_locator_
bool game_matches_filter(const game_item &i, const config &cfg)
this class memorizes a chat session.
bool selection_in_joinable_state() const
void select_game(const std::string &id)
void populate_game_item_addons_installed(game_item &, const config &, const std::vector< std::string > &)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
virtual void gamelist_updated(bool silent=true)
Called each time the gamelist_ variable is updated.
GLsizei const GLcharARB ** string
Definition: glew.h:4503
const config & map_hashes_
virtual void layout_children(const SDL_Rect &rect)
Lays the children out.
style * style_
Definition: menu.hpp:232
a base class for the different multiplayer base dialogs: game list, create game, wait game...
void populate_game_item_mod_info(game_item &, const config &, const config &, bool &)
gui::textbox filter_text_