The Battle for Wesnoth  1.15.1+dev
mp_create_game.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Mark de Wever <koraq@xs4all.nl>
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 
20 
24 #include "mp_game_settings.hpp"
25 
26 class config;
27 
28 namespace mp
29 {
30 struct user_info;
31 }
32 
33 namespace gui2
34 {
35 class toggle_button;
36 class listbox;
37 class menu_button;
38 
39 namespace dialogs
40 {
41 
43 {
44  typedef std::pair<ng::level::TYPE, std::string> level_type_info;
45 
46 public:
47  mp_create_game(const config& cfg, saved_game& state, bool local_mode, mp::user_info* host_info = nullptr);
48 
49 private:
50  /** Inherited from modal_dialog, implemented by REGISTER_DIALOG. */
51  virtual const std::string& window_id() const override;
52 
53  /** Inherited from modal_dialog. */
54  virtual void pre_show(window& window) override;
55 
56  /** Inherited from modal_dialog. */
57  virtual void post_show(window& window) override;
58 
59  const config& cfg_;
60 
62  std::unique_ptr<ng::configure_engine> config_engine_;
63  std::unique_ptr<mp_options_helper> options_manager_;
64 
67 
68  std::vector<level_type_info> level_types_;
69 
70  /* We keep and work with a vector of the RFM types since it's the easiest way to get a value for the
71  * config_engine and preferences setters, since menu_buttons aren't supported by field. Even if they
72  * were, the above functions take a RANDOM_FACTION_MODE value, not an index. Even if we try to keep a
73  * copy of the selected RFM type index in a int value and update it every time you perform a selection,
74  * there's still the problem of getting an initial value from preferences, which again is provided as a
75  * RANDOM_FACTION_MODE value. Comparing strings between the (translated) menu_button values in the WML and
76  * the hardcoded (non-translated) RANDOM_FACTION_MODE string values stored in preferences is a horrible
77  * way to do it and would break in any language other than English. Instead, we'll keep a vector and use
78  * std::find to get the initial index. This method should also allow the values to eventually be translated,
79  * since the string values don't come into consideration at all, save for populating the menu_button.
80  *
81  * - vultraz, 2016-08-21
82  */
83  std::vector<mp_game_settings::RANDOM_FACTION_MODE> rfm_types_;
84 
85  void update_games_list(window& window);
86  void display_games_of_type(window& window, ng::level::TYPE type, const std::string& level);
87 
88  void show_generator_settings(window& window);
89  void regenerate_random_map(window& window);
90 
91  /**
92  * All fields are also in the normal field vector, but they need to be
93  * manually controlled as well so add the pointers here as well.
94  */
95 
105 
114 
117 
119 
121 
122  template<typename widget>
123  void on_filter_change(window& window, const std::string& id, bool do_select);
124 
125  void on_game_select(window& window);
126  void on_tab_select(window& window);
127  void on_era_select(window& window);
128  void on_mod_toggle(window& window, const int index, toggle_button* sender);
129  void on_random_faction_mode_select(window& window);
130 
131  std::vector<std::string> get_active_mods();
132  void set_active_mods(const std::vector<std::string>& val);
133 
134  void sync_with_depcheck(window& window);
135 
136  void show_description(window& window, const std::string& new_description);
137 
138  void update_details(window& window);
139  void update_map_settings();
140 
141  /**
142  * Dialog exit hook to bring up the difficulty dialog when starting a campaign.
143  * This only fires when the retval is OK (ie, creating a game), meaning it does not fire
144  * when loading a saved game.
145  */
146  bool dialog_exit_hook(window&);
147 
148  int convert_to_game_filtered_index(const unsigned int initial_index);
149 
150  void load_game_callback(window& window);
151 
152  enum tab { TAB_GENERAL, TAB_OPTIONS, TAB_SETTINGS };
153 };
154 
155 } // namespace dialogs
156 } // namespace gui2
TYPE
UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM :...
Definition: picture.hpp:185
Simple push button.
Definition: menu_button.hpp:41
std::vector< mp_game_settings::RANDOM_FACTION_MODE > rfm_types_
Specialized field class for boolean.
Definition: field.hpp:544
std::vector< level_type_info > level_types_
Generic file dialog.
Definition: field-fwd.hpp:22
Pubic entry points for the MP workflow.
Definition: lobby_data.cpp:49
The listbox class.
Definition: listbox.hpp:40
field_bool * use_map_settings_
All fields are also in the normal field vector, but they need to be manually controlled as well so ad...
ng::create_engine create_engine_
Various uncategorised dialogs.
std::pair< ng::level::TYPE, std::string > level_type_info
std::unique_ptr< mp_options_helper > options_manager_
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
-file mapgen.hpp
This class represents the information a client has about another player.
Definition: lobby_data.hpp:104
Abstract base class for all modal dialogs.
std::unique_ptr< ng::configure_engine > config_engine_
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
Template class to implement the generic field implementation.
Definition: field-fwd.hpp:35
Class for a toggle button.