15 #define GETTEXT_DOMAIN "wesnoth-lib"
35 : create_engine_(create_engine)
42 for(
const auto [
_, cfg] :
prefs::get().options().all_children_view()) {
43 for(
const auto& saved_option : cfg.child_range(
"option")) {
44 options_data_[cfg[
"id"]][saved_option[
"id"].str()] = saved_option[
"value"];
84 static const std::string
type =
"era";
95 static const std::string
type =
"modification";
119 data = &node_data_map_iter->second;
125 int& position =
data->position;
128 for(
auto i = type_node_vector.rbegin();
i != type_node_vector.rend();
i++) {
132 type_node_vector.clear();
168 }
else if(source.
level_type ==
"modification") {
182 T*
widget =
dynamic_cast<T*
>(node.
find(
id,
true));
185 const std::string widget_id = cfg[
"id"];
188 if(!option_config.has_attribute(widget_id) || option_config[widget_id].empty()) {
189 option_config[widget_id] = cfg[
"default"];
193 widget->set_tooltip(cfg[
"description"]);
195 return {
widget, option_config[widget_id]};
215 for(
const auto& options : cfg.
child_range(
"options")) {
219 item[
"label"] = cfg[
"name"];
220 data.emplace(
"tree_view_node_label", item);
223 type_node_vector.push_back(&option_node);
225 for(
const auto [option_key, option_cfg] : options.all_children_view()) {
231 if(option_key ==
"checkbox") {
232 item[
"label"] = option_cfg[
"name"];
233 data.emplace(
"option_checkbox", item);
236 std::tie(checkbox, val) = add_node_and_get_widget<toggle_button>(option_node,
"option_checkbox",
data, option_cfg);
241 std::bind(&mp_options_helper::update_options_data_map<toggle_button>,
this, checkbox,
visible_options_.back()));
243 }
else if(option_key ==
"spacer") {
244 option_node.
add_child(
"options_spacer_node", empty_map);
246 }
else if(option_key ==
"choice") {
247 if(!option_cfg.has_child(
"item")) {
251 item[
"label"] = option_cfg[
"name"];
252 data.emplace(
"menu_button_label", item);
254 std::vector<config> combo_items;
255 std::vector<std::string> combo_values;
257 for(
auto i : option_cfg.child_range(
"item")) {
259 i[
"label"] =
i[
"name"];
261 combo_items.push_back(
i);
262 combo_values.push_back(
i[
"value"]);
266 std::tie(menu, val) = add_node_and_get_widget<menu_button>(option_node,
"option_menu_button",
data, option_cfg);
271 auto iter =
std::find(combo_values.begin(), combo_values.end(), val.
str());
273 if(iter != combo_values.end()) {
274 menu->
set_selected(std::distance(combo_values.begin(), iter));
280 }
else if(option_key ==
"slider") {
281 item[
"label"] = option_cfg[
"name"];
282 data.emplace(
"slider_label", item);
285 std::tie(slide, val) = add_node_and_get_widget<slider>(option_node,
"option_slider",
data, option_cfg);
287 slide->
set_value_range(option_cfg[
"min"].to_int(), option_cfg[
"max"].to_int());
292 std::bind(&mp_options_helper::update_options_data_map<slider>,
this, slide,
visible_options_.back()));
294 }
else if(option_key ==
"entry") {
295 item[
"label"] = option_cfg[
"name"];
296 data.emplace(
"text_entry_label", item);
299 std::tie(textbox, val) = add_node_and_get_widget<text_box>(option_node,
"option_text_entry",
data, option_cfg);
303 std::bind(&mp_options_helper::update_options_data_map<text_box>,
this, textbox,
visible_options_.back()));
312 std::placeholders::_3, std::placeholders::_4));
321 mod[
"id"] = source.id;
326 for(
const auto& [key, value] :
options_data_[source.id].attribute_range()) {
Variant for storing WML attributes.
std::string str(const std::string &fallback="") const
int to_int(int def=0) const
bool to_bool(bool def=false) const
A config object defines a single node in a WML file, with access to child nodes.
bool has_child(config_key_type key) const
Determine whether a config has a child or not.
child_itors child_range(config_key_type key)
config & add_child(config_key_type key)
std::map< std::string, config > options_data_
ng::create_engine & create_engine_
void update_status_label()
void update_mod_options()
void reset_options_data(const option_source &source, bool &handled, bool &halt)
mp_options_helper(window &window, ng::create_engine &create_engine)
styled_widget & no_options_notice_
void update_options_data_map_menu_button(menu_button *widget, const option_source &source, const config &cfg)
void display_custom_options(const std::string &type, int node_position, const config &data)
void update_era_options()
std::map< std::string, type_node_data > node_data_map_
std::vector< tree_view_node * > node_vector
config get_options_config()
std::pair< T *, config::attribute_value > add_node_and_get_widget(tree_view_node &option_node, const std::string &id, data_map &data, const config &cfg)
void update_game_options()
std::vector< option_source > visible_options_
int remove_nodes_for_type(const std::string &type)
tree_view & options_tree_
void update_all_options()
void update_options_data_map(T *widget, const option_source &source)
void set_step_size(int step_size)
virtual void set_value(int value) override
Inherited from integer_selector.
void set_value_range(int min_value, int max_value)
virtual void set_value(const std::string &text)
The set_value is virtual for the password_box class.
void set_text_changed_callback(std::function< void(text_box_base *textbox, const std::string text)> cb)
Set the text_changed callback.
A widget that allows the user to input text in single line.
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
tree_view_node & add_child(const std::string &id, const widget_data &data, const int index=-1)
Constructs a new child node.
tree_view_node & add_node(const std::string &id, const widget_data &data, const int index=-1)
std::pair< std::shared_ptr< tree_view_node >, int > remove_node(tree_view_node *node)
Removes the given node as a child of its parent node.
base class of top level items, the only item which needs to store the final canvases to draw on.
const config & curent_era_cfg() const
std::vector< extras_metadata_ptr > active_mods_data()
bool is_campaign() const
Wrapper to simplify the is-type-campaign-or-sp-campaign check.
level & current_level() const
const config & data() const
static std::string _(const char *str)
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
t_string missing_widget(const std::string &id)
Returns a default error message if a mandatory widget is omitted.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
void erase_if(Container &container, const Predicate &predicate)
Convenience wrapper for using std::remove_if on a container.
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.