The Battle for Wesnoth  1.17.0-dev
mp_create_game.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Mark de Wever <koraq@xs4all.nl>
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 
21 
24 #include "mp_game_settings.hpp"
25 
26 class config;
27 
28 namespace gui2
29 {
30 class toggle_button;
31 class listbox;
32 class menu_button;
33 
34 namespace dialogs
35 {
36 
38 {
39  typedef std::pair<ng::level::TYPE, std::string> level_type_info;
40 
41 public:
42  mp_create_game(saved_game& state, bool local_mode);
43 
44  /** The execute function. See @ref modal_dialog for more information. */
46 
47 private:
48  virtual const std::string& window_id() const override;
49 
50  virtual void pre_show(window& window) override;
51 
52  virtual void post_show(window& window) override;
53 
55  std::unique_ptr<ng::configure_engine> config_engine_;
56  std::unique_ptr<mp_options_helper> options_manager_;
57 
60 
61  std::vector<level_type_info> level_types_;
62 
63  /* We keep and work with a vector of the RFM types since it's the easiest way to get a value for the
64  * config_engine and preferences setters, since menu_buttons aren't supported by field. Even if they
65  * were, the above functions take a RANDOM_FACTION_MODE value, not an index. Even if we try to keep a
66  * copy of the selected RFM type index in a int value and update it every time you perform a selection,
67  * there's still the problem of getting an initial value from preferences, which again is provided as a
68  * RANDOM_FACTION_MODE value. Comparing strings between the (translated) menu_button values in the WML and
69  * the hardcoded (non-translated) RANDOM_FACTION_MODE string values stored in preferences is a horrible
70  * way to do it and would break in any language other than English. Instead, we'll keep a vector and use
71  * std::find to get the initial index. This method should also allow the values to eventually be translated,
72  * since the string values don't come into consideration at all, save for populating the menu_button.
73  *
74  * - vultraz, 2016-08-21
75  */
76  std::vector<mp_game_settings::RANDOM_FACTION_MODE> rfm_types_;
77 
78  void update_games_list();
79  void display_games_of_type(ng::level::TYPE type, const std::string& level);
80 
82  void regenerate_random_map();
83 
84  /**
85  * All fields are also in the normal field vector, but they need to be
86  * manually controlled as well so add the pointers here as well.
87  */
88 
98 
107 
110 
112 
113  template<typename widget>
114  void on_filter_change(const std::string& id, bool do_select);
115 
116  void on_game_select();
117  void on_tab_select();
118  void on_era_select();
119  void on_mod_toggle(const int index, toggle_button* sender);
121 
122  std::vector<std::string> get_active_mods();
123  void set_active_mods(const std::vector<std::string>& val);
124 
125  void sync_with_depcheck();
126 
127  void show_description(const std::string& new_description);
128 
129  void update_details();
130  void update_map_settings();
131 
132  /**
133  * Dialog exit hook to bring up the difficulty dialog when starting a campaign.
134  * This only fires when the retval is OK (ie, creating a game), meaning it does not fire
135  * when loading a saved game.
136  */
137  bool dialog_exit_hook(window&);
138 
139  int convert_to_game_filtered_index(const unsigned int initial_index);
140 
141  void load_game_callback();
142 
144 };
145 
146 } // namespace dialogs
147 } // namespace gui2
TYPE
Used to specify the rendering format of images.
Definition: picture.hpp:229
mp_create_game(saved_game &state, bool local_mode)
A menu_button is a styled_widget to choose an element from a list of elements.
Definition: menu_button.hpp:61
std::vector< mp_game_settings::RANDOM_FACTION_MODE > rfm_types_
Specialized field class for boolean.
Definition: field.hpp:545
std::vector< level_type_info > level_types_
void display_games_of_type(ng::level::TYPE type, const std::string &level)
void on_mod_toggle(const int index, toggle_button *sender)
Generic file dialog.
Definition: field-fwd.hpp:23
std::vector< std::string > get_active_mods()
The listbox class.
Definition: listbox.hpp:43
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...
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
ng::create_engine create_engine_
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
void set_active_mods(const std::vector< std::string > &val)
Various uncategorised dialogs.
std::pair< ng::level::TYPE, std::string > level_type_info
DEFINE_SIMPLE_EXECUTE_WRAPPER(mp_create_game)
The execute function.
void on_filter_change(const std::string &id, bool do_select)
std::unique_ptr< mp_options_helper > options_manager_
int convert_to_game_filtered_index(const unsigned int initial_index)
virtual const std::string & window_id() const override
The id of the window to build.
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:72
Abstract base class for all modal dialogs.
std::unique_ptr< ng::configure_engine > config_engine_
bool dialog_exit_hook(window &)
Dialog exit hook to bring up the difficulty dialog when starting a campaign.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
void show_description(const std::string &new_description)
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
Template class to implement the generic field implementation.
Definition: field-fwd.hpp:36
Class for a toggle button.