The Battle for Wesnoth  1.15.12+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 
23 #include "mp_game_settings.hpp"
24 
25 class config;
26 
27 namespace gui2
28 {
29 class toggle_button;
30 class listbox;
31 class menu_button;
32 
33 namespace dialogs
34 {
35 
37 {
38  typedef std::pair<ng::level::TYPE, std::string> level_type_info;
39 
40 public:
41  mp_create_game(saved_game& state, bool local_mode);
42 
43  /** The execute function. See @ref modal_dialog for more information. */
45 
46 private:
47  virtual const std::string& window_id() const override;
48 
49  virtual void pre_show(window& window) override;
50 
51  virtual void post_show(window& window) override;
52 
54  std::unique_ptr<ng::configure_engine> config_engine_;
55  std::unique_ptr<mp_options_helper> options_manager_;
56 
59 
60  std::vector<level_type_info> level_types_;
61 
62  /* We keep and work with a vector of the RFM types since it's the easiest way to get a value for the
63  * config_engine and preferences setters, since menu_buttons aren't supported by field. Even if they
64  * were, the above functions take a RANDOM_FACTION_MODE value, not an index. Even if we try to keep a
65  * copy of the selected RFM type index in a int value and update it every time you perform a selection,
66  * there's still the problem of getting an initial value from preferences, which again is provided as a
67  * RANDOM_FACTION_MODE value. Comparing strings between the (translated) menu_button values in the WML and
68  * the hardcoded (non-translated) RANDOM_FACTION_MODE string values stored in preferences is a horrible
69  * way to do it and would break in any language other than English. Instead, we'll keep a vector and use
70  * std::find to get the initial index. This method should also allow the values to eventually be translated,
71  * since the string values don't come into consideration at all, save for populating the menu_button.
72  *
73  * - vultraz, 2016-08-21
74  */
75  std::vector<mp_game_settings::RANDOM_FACTION_MODE> rfm_types_;
76 
77  void update_games_list();
78  void display_games_of_type(ng::level::TYPE type, const std::string& level);
79 
81  void regenerate_random_map();
82 
83  /**
84  * All fields are also in the normal field vector, but they need to be
85  * manually controlled as well so add the pointers here as well.
86  */
87 
97 
106 
109 
111 
112  template<typename widget>
113  void on_filter_change(const std::string& id, bool do_select);
114 
115  void on_game_select();
116  void on_tab_select();
117  void on_era_select();
118  void on_mod_toggle(const int index, toggle_button* sender);
120 
121  std::vector<std::string> get_active_mods();
122  void set_active_mods(const std::vector<std::string>& val);
123 
124  void sync_with_depcheck();
125 
126  void show_description(const std::string& new_description);
127 
128  void update_details();
129  void update_map_settings();
130 
131  /**
132  * Dialog exit hook to bring up the difficulty dialog when starting a campaign.
133  * This only fires when the retval is OK (ie, creating a game), meaning it does not fire
134  * when loading a saved game.
135  */
136  bool dialog_exit_hook(window&);
137 
138  int convert_to_game_filtered_index(const unsigned int initial_index);
139 
140  void load_game_callback();
141 
143 };
144 
145 } // namespace dialogs
146 } // namespace gui2
TYPE
Used to specify the rendering format of images.
Definition: picture.hpp:228
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:60
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_
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:22
std::vector< std::string > get_active_mods()
The listbox class.
Definition: listbox.hpp:42
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:71
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:59
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:64
Template class to implement the generic field implementation.
Definition: field-fwd.hpp:35
Class for a toggle button.